From f91addf88a62a3eb1e940762efdc107768ade6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 19 May 2014 20:31:23 -0700 Subject: [PATCH] GL: Fixed HDR example. --- examples/09-hdr/hdr.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 1ed22a9ca..3ab15879a 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -7,7 +7,6 @@ #include "bgfx_utils.h" #include "imgui/imgui.h" -static bool s_flipV = false; static float s_texelHalf = 0.0f; struct PosColorTexCoord0Vertex @@ -208,6 +207,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiCreate(data); free(data); + const bgfx::RendererType::Enum renderer = bgfx::getRendererType(); + s_texelHalf = bgfx::RendererType::Direct3D9 == renderer ? 0.5f : 0.0f; + const bool originBottomLeft = bgfx::RendererType::OpenGL == renderer || bgfx::RendererType::OpenGLES == renderer; + + uint32_t oldWidth = 0; + uint32_t oldHeight = 0; + uint32_t oldReset = reset; + float speed = 0.37f; float middleGray = 0.18f; float white = 1.1f; @@ -215,10 +222,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) int32_t scrollArea = 0; - uint32_t oldWidth = 0; - uint32_t oldHeight = 0; - uint32_t oldReset = reset; - float time = 0.0f; entry::MouseState mouseState; @@ -374,7 +377,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, fbtextures[0]); bgfx::setProgram(lumProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(128.0f, 128.0f, s_flipV); + screenSpaceQuad(128.0f, 128.0f, originBottomLeft); bgfx::submit(2); // Downscale luminance 0. @@ -382,7 +385,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[0]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(64.0f, 64.0f, s_flipV); + screenSpaceQuad(64.0f, 64.0f, originBottomLeft); bgfx::submit(3); // Downscale luminance 1. @@ -390,7 +393,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[1]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(16.0f, 16.0f, s_flipV); + screenSpaceQuad(16.0f, 16.0f, originBottomLeft); bgfx::submit(4); // Downscale luminance 2. @@ -398,7 +401,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[2]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(4.0f, 4.0f, s_flipV); + screenSpaceQuad(4.0f, 4.0f, originBottomLeft); bgfx::submit(5); // Downscale luminance 3. @@ -406,7 +409,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(0, u_texColor, lum[3]); bgfx::setProgram(lumAvgProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad(1.0f, 1.0f, s_flipV); + screenSpaceQuad(1.0f, 1.0f, originBottomLeft); bgfx::submit(6); float tonemap[4] = { middleGray, square(white), treshold, 0.0f }; @@ -418,14 +421,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(1, u_texLum, lum[4]); bgfx::setProgram(brightProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad( (float)width/2.0f, (float)height/2.0f, s_flipV); + screenSpaceQuad( (float)width/2.0f, (float)height/2.0f, originBottomLeft); bgfx::submit(7); // Blur bright pass vertically. bgfx::setTexture(0, u_texColor, bright); bgfx::setProgram(blurProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad( (float)width/8.0f, (float)height/8.0f, s_flipV); + screenSpaceQuad( (float)width/8.0f, (float)height/8.0f, originBottomLeft); bgfx::submit(8); // Blur bright pass horizontally, do tonemaping and combine. @@ -434,7 +437,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::setTexture(2, u_texBlur, blur); bgfx::setProgram(tonemapProgram); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); - screenSpaceQuad( (float)width, (float)height, s_flipV); + screenSpaceQuad( (float)width, (float)height, originBottomLeft); bgfx::submit(9); // Advance to next frame. Rendering thread will be kicked to