Skip to content

Commit

Permalink
Add gamma correction to simple_demo_qml example (#1019)
Browse files Browse the repository at this point in the history
Signed-off-by: Athena Z <[email protected]>
Co-authored-by: Ian Chen <[email protected]>
  • Loading branch information
athenaz2 and iche033 authored Jul 30, 2024
1 parent e48767b commit 6a2217f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
19 changes: 11 additions & 8 deletions examples/simple_demo_qml/GzRenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,20 @@ void GzRenderer::InitialiseOnMainThread()
//////////////////////////////////////////////////
void GzRenderer::Render()
{
// pre-render may regenerate textureId if the size changes
this->camera->PreRender();
this->textureId = this->camera->RenderTextureGLId();

// render to texture
this->camera->Update();

GLuint texIdSrgb = this->camera->RenderTextureGLId();

if (this->textureId != texIdSrgb)
{
glBindTexture(GL_TEXTURE_2D, texIdSrgb);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT,
GL_SKIP_DECODE_EXT);
}

this->textureId = texIdSrgb;

// Move camera
this->UpdateCamera();
}
Expand Down Expand Up @@ -276,10 +283,6 @@ void GzRenderer::InitEngine()
// quick check on sizing...
gzmsg << "imageW: " << this->camera->ImageWidth() << "\n";
gzmsg << "imageH: " << this->camera->ImageHeight() << "\n";

// pre-render will force texture creation and may update texture id
this->camera->PreRender();
this->textureId = this->camera->RenderTextureGLId();
}

//////////////////////////////////////////////////
Expand Down
9 changes: 6 additions & 3 deletions examples/simple_demo_qml/ThreadRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,25 @@ void TextureNode::NewTexture(int _id, const QSize &_size)
void TextureNode::PrepareNode()
{
this->mutex.lock();
// new render engine texture ID
int newId = this->id;
QSize size = this->size;
QSize newSize = this->size;
this->id = 0;
this->mutex.unlock();

if (newId)
{
delete this->texture;
this->texture = nullptr;
// note: include QQuickWindow::TextureHasAlphaChannel if the rendered content
// has alpha.

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
# ifndef _WIN32
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# endif
this->texture = this->window->createTextureFromId(newId, size);
this->texture = this->window->createTextureFromId(newId, newSize);
# ifndef _WIN32
# pragma GCC diagnostic pop
# endif
Expand All @@ -346,7 +349,7 @@ void TextureNode::PrepareNode()
QQuickWindow::NativeObjectTexture,
static_cast<void *>(&newId),
0,
size);
newSize);
#endif
this->setTexture(this->texture);

Expand Down

0 comments on commit 6a2217f

Please sign in to comment.