Skip to content

Commit

Permalink
Improved occurences highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
live committed Mar 17, 2020
1 parent 19e466e commit 6b5fa19
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 45 deletions.
11 changes: 6 additions & 5 deletions src/TextureData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ bool TextureData::upload(GLuint *textureId,
{
if (isNull() || !textureId)
return false;
if (!format)
format = this->format();

if (isMultisampleTarget(mTarget)) {
QOpenGLFunctions_3_3_Core gl;
Expand All @@ -646,19 +648,18 @@ bool TextureData::upload(GLuint *textureId,
}

Q_ASSERT(glGetError() == GL_NO_ERROR);
const auto originalFormat = mKtxTexture->glInternalformat;
if (format)
mKtxTexture->glInternalformat = static_cast<ktx_uint32_t>(format);

#if defined(_WIN32)
initializeKtxOpenGLFunctions();
#endif

const auto originalFormat = mKtxTexture->glInternalformat;
mKtxTexture->glInternalformat = static_cast<ktx_uint32_t>(format);
auto target = static_cast<GLenum>(mTarget);
auto error = GLenum{ };
const auto result = (ktxTexture_GLUpload(
mKtxTexture.get(), textureId, &target, &error) == KTX_SUCCESS);

mKtxTexture->glInternalformat = originalFormat;

Q_ASSERT(glGetError() == GL_NO_ERROR);
return result;
}
Expand Down
14 changes: 6 additions & 8 deletions src/editors/SourceEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SourceEditor::SourceEditor(QString fileName, FindReplaceBar *findReplaceBar, QWi

updateViewportMargins();
updateExtraSelections();
updateColors();
updateColors(settings.darkTheme());
setSourceTypeFromExtension();
setPlainText(document()->toPlainText());
}
Expand Down Expand Up @@ -214,18 +214,16 @@ void SourceEditor::setSourceType(SourceType sourceType)
}
}

void SourceEditor::updateColors()
void SourceEditor::updateColors(bool darkTheme)
{
mCurrentLineFormat.setProperty(QTextFormat::FullWidthSelection, true);
mCurrentLineFormat.setBackground(palette().base().color().darker(105));
mCurrentLineFormat.setBackground(palette().base().color().lighter(darkTheme ? 110 : 95));

mOccurrencesFormat.setProperty(QTextFormat::OutlinePen,
QPen(palette().highlight().color()));
mOccurrencesFormat.setBackground(palette().base().color().darker(110));
mOccurrencesFormat.setForeground(palette().text().color().lighter(darkTheme ? 120 : 90));
mOccurrencesFormat.setBackground(palette().base().color().lighter(darkTheme ? 120 : 90));

auto window = palette().window().color();
mLineNumberColor = (window.value() < 128 ?
window.lighter(150) : window.darker(150));
mLineNumberColor = window.darker(window.value() < 128 ? 50 : 150);

updateExtraSelections();
}
Expand Down
2 changes: 1 addition & 1 deletion src/editors/SourceEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SourceEditor : public QPlainTextEdit, public IEditor
void insertCompletion(const QString &completion);
void findReplaceAction(FindReplaceBar::Action action, QString find,
QString replace, QTextDocument::FindFlags flags);
void updateColors();
void updateColors(bool darkTheme);
void updateSyntaxHighlighting();

QString mFileName;
Expand Down
54 changes: 23 additions & 31 deletions src/editors/TextureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,29 @@ class ZeroCopyContext : public QObject

private:
using ProgramKey = std::tuple<QOpenGLTexture::Target, QOpenGLTexture::TextureFormat>;
void handleDebugMessage(const QOpenGLDebugMessage &message);

QOpenGLFunctions_3_3_Core mGL;
QOpenGLDebugLogger mDebugLogger;
std::map<ProgramKey, QOpenGLShaderProgram> mPrograms;
bool mInitialized{ };

void initialize();
void handleDebugMessage(const QOpenGLDebugMessage &message);
};

ZeroCopyContext::ZeroCopyContext(QObject *parent)
: QObject(parent)
{
mGL.initializeOpenGLFunctions();

if (mDebugLogger.initialize()) {
mDebugLogger.disableMessages(QOpenGLDebugMessage::AnySource,
QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity);
QObject::connect(&mDebugLogger, &QOpenGLDebugLogger::messageLogged,
this, &ZeroCopyContext::handleDebugMessage);
mDebugLogger.startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
}

QOpenGLFunctions_3_3_Core &ZeroCopyContext::gl()
{
initialize();
return mGL;
}

Expand All @@ -184,22 +189,6 @@ QOpenGLShaderProgram *ZeroCopyContext::getProgram(QOpenGLTexture::Target target,
return &program;
}

void ZeroCopyContext::initialize()
{
if (std::exchange(mInitialized, true))
return;

mGL.initializeOpenGLFunctions();

if (mDebugLogger.initialize()) {
mDebugLogger.disableMessages(QOpenGLDebugMessage::AnySource,
QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity);
QObject::connect(&mDebugLogger, &QOpenGLDebugLogger::messageLogged,
this, &ZeroCopyContext::handleDebugMessage);
mDebugLogger.startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
}

void ZeroCopyContext::handleDebugMessage(const QOpenGLDebugMessage &message)
{
const auto text = message.message();
Expand Down Expand Up @@ -269,24 +258,27 @@ void TextureItem::paint(QPainter *painter,
2 * -(x * scale + width / 2) / width,
2 * (y * scale + height / 2) / height);

if (!mContext)
mContext.reset(new ZeroCopyContext());

if (updateTexture())
renderTexture(transform);

Q_ASSERT(glGetError() == GL_NO_ERROR);
painter->endNativePainting();
}

ZeroCopyContext &TextureItem::context()
{
if (!mContext)
mContext.reset(new ZeroCopyContext());
return *mContext;
}

bool TextureItem::updateTexture()
{
if (!mPreviewTextureId && std::exchange(mUpload, false)) {
// upload/replace texture
if (!mImage.upload(&mImageTextureId)) {
mContext->gl().glDeleteTextures(1, &mImageTextureId);
mImageTextureId = GL_NONE;
}
context().gl().glDeleteTextures(1, &mImageTextureId);
mImageTextureId = GL_NONE;
mImage.upload(&mImageTextureId);
// last version is deleted in QGraphicsView destructor
}
return (mPreviewTextureId || mImageTextureId);
Expand All @@ -295,7 +287,7 @@ bool TextureItem::updateTexture()
bool TextureItem::renderTexture(const QMatrix &transform)
{
Q_ASSERT(glGetError() == GL_NO_ERROR);
auto &gl = mContext->gl();
auto &gl = context().gl();

auto target = mImage.target();
if (mPreviewTextureId) {
Expand All @@ -317,7 +309,7 @@ bool TextureItem::renderTexture(const QMatrix &transform)
gl.glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl.glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl.glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
if (mImage.levels() > 1) {
if (mMagnifyLinear && mImage.levels() > 1) {
gl.glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl.glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
Expand All @@ -327,7 +319,7 @@ bool TextureItem::renderTexture(const QMatrix &transform)
}
}

if (auto *program = mContext->getProgram(target, mImage.format())) {
if (auto *program = context().getProgram(target, mImage.format())) {
program->bind();
program->setUniformValue("uTexture", 0);
program->setUniformValue("uTransform", transform);
Expand Down
1 change: 1 addition & 0 deletions src/editors/TextureItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TextureItem : public QGraphicsItem
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;

private:
ZeroCopyContext &context();
bool updateTexture();
bool renderTexture(const QMatrix &transform);

Expand Down

0 comments on commit 6b5fa19

Please sign in to comment.