From bc3bb5c6a40e2e8970ff8da0e4cb583422a794b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 5 Jan 2016 18:32:24 -0800 Subject: [PATCH] Fixed MRT clear color. --- src/image.cpp | 7 ++----- src/renderer_d3d9.cpp | 22 +++++++++++++--------- src/renderer_gl.cpp | 21 +++++++++++++-------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index 399eba0d..fc1b1273 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -1894,7 +1894,7 @@ namespace bgfx { KTX_RG32UI, KTX_ZERO, KTX_RG, KTX_UNSIGNED_INT, }, // RG32U { KTX_RG32F, KTX_ZERO, KTX_RG, KTX_FLOAT, }, // RG32F { KTX_RGB9_E5, KTX_ZERO, KTX_RGB, KTX_UNSIGNED_INT_5_9_9_9_REV, }, // RGB9E5F - { KTX_RGBA8, KTX_SRGB8_ALPHA8, KTX_BGRA, KTX_UNSIGNED_BYTE, }, // BGRA8 + { KTX_BGRA, KTX_SRGB8_ALPHA8, KTX_BGRA, KTX_UNSIGNED_BYTE, }, // BGRA8 { KTX_RGBA8, KTX_SRGB8_ALPHA8, KTX_RGBA, KTX_UNSIGNED_BYTE, }, // RGBA8 { KTX_RGBA8I, KTX_ZERO, KTX_RGBA, KTX_BYTE, }, // RGBA8I { KTX_RGBA8UI, KTX_ZERO, KTX_RGBA, KTX_UNSIGNED_BYTE, }, // RGBA8U @@ -2475,7 +2475,6 @@ namespace bgfx const float4_t umask = float4_ild(0xff, 0xff00, 0xff0000, 0xff000000); const float4_t wflip = float4_ild(0, 0, 0, 0x80000000); const float4_t wadd = float4_ld(0.0f, 0.0f, 0.0f, 32768.0f*65536.0f); - const float4_t linear = float4_ld(2.2f, 2.2f, 2.2f, 1.0f); for (uint32_t yy = 0, ystep = _pitch; yy < dstheight; ++yy, src += ystep) { @@ -2489,9 +2488,7 @@ namespace bgfx const float4_t abgr0c = float4_add(abgr0f, wadd); const float4_t abgr0n = float4_mul(abgr0c, unpack); - const float4_t abgr0l = float4_pow(abgr0n, linear); - - float4_st(dst, abgr0l); + float4_st(dst, abgr0n); } } } diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 38e4a7de..788cd930 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -1925,30 +1925,34 @@ namespace bgfx { namespace d3d9 device->SetVertexShader(program.m_vsh->m_vertexShader); device->SetPixelShader(program.m_fsh->m_pixelShader); + float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { - float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; for (uint32_t ii = 0; ii < numMrt; ++ii) { - uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); + uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, _clear.m_index[ii]); memcpy(mrtClear[ii], _palette[index], 16); } - - DX_CHECK(m_device->SetPixelShaderConstantF(0, mrtClear[0], numMrt) ); } else { float rgba[4] = { - _clear.m_index[0]*1.0f/255.0f, - _clear.m_index[1]*1.0f/255.0f, - _clear.m_index[2]*1.0f/255.0f, - _clear.m_index[3]*1.0f/255.0f, + _clear.m_index[0] * 1.0f / 255.0f, + _clear.m_index[1] * 1.0f / 255.0f, + _clear.m_index[2] * 1.0f / 255.0f, + _clear.m_index[3] * 1.0f / 255.0f, }; - DX_CHECK(m_device->SetPixelShaderConstantF(0, rgba, 1) ); + for (uint32_t ii = 0; ii < numMrt; ++ii) + { + memcpy(mrtClear[ii], rgba, 16); + } } + DX_CHECK(device->SetPixelShaderConstantF(0, mrtClear[0], numMrt)); + DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, stride) ); DX_CHECK(device->SetStreamSourceFreq(0, 1) ); DX_CHECK(device->SetStreamSource(1, NULL, 0, 0) ); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d7ff1a43..24d36261 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -3171,29 +3171,34 @@ namespace bgfx { namespace gl GL_CHECK(glUseProgram(program.m_id) ); program.bindAttributes(vertexDecl, 0); + float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { - float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); memcpy(mrtClear[ii], _palette[index], 16); } - - GL_CHECK(glUniform4fv(0, numMrt, mrtClear[0]) ); } else { float rgba[4] = { - _clear.m_index[0]*1.0f/255.0f, - _clear.m_index[1]*1.0f/255.0f, - _clear.m_index[2]*1.0f/255.0f, - _clear.m_index[3]*1.0f/255.0f, + _clear.m_index[0] * 1.0f / 255.0f, + _clear.m_index[1] * 1.0f / 255.0f, + _clear.m_index[2] * 1.0f / 255.0f, + _clear.m_index[3] * 1.0f / 255.0f, }; - GL_CHECK(glUniform4fv(0, 1, rgba) ); + + for (uint32_t ii = 0; ii < numMrt; ++ii) + { + memcpy(mrtClear[ii], rgba, 16); + } } + GL_CHECK(glUniform4fv(0, numMrt, mrtClear[0]) ); + GL_CHECK(glDrawArrays(GL_TRIANGLE_STRIP , 0 , 4