From 51d8daf762a0e174bf7e07f21586a69124e1373d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 8 Oct 2014 19:36:59 -0700 Subject: [PATCH] Fixed constant buffer allocation logic. --- src/renderer_d3d11.cpp | 12 +++++++++--- src/renderer_d3d9.cpp | 12 +++++++++--- src/renderer_gl.cpp | 13 ++++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index a094a82a..d98960d5 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -2218,8 +2218,6 @@ RENDERDOC_IMPORT if (0 < count) { - m_constantBuffer = ConstantBuffer::create(1024); - for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize; @@ -2258,6 +2256,11 @@ RENDERDOC_IMPORT if (NULL != info) { + if (NULL == m_constantBuffer) + { + m_constantBuffer = ConstantBuffer::create(1024); + } + kind = "user"; m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount); } @@ -2274,7 +2277,10 @@ RENDERDOC_IMPORT BX_UNUSED(kind); } - m_constantBuffer->finish(); + if (NULL != m_constantBuffer) + { + m_constantBuffer->finish(); + } } uint16_t shaderSize; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 45d7456e..923f53a0 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -1916,8 +1916,6 @@ namespace bgfx if (0 < count) { - m_constantBuffer = ConstantBuffer::create(1024); - for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize; @@ -1956,6 +1954,11 @@ namespace bgfx BX_CHECK(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); if (NULL != info) { + if (NULL == m_constantBuffer) + { + m_constantBuffer = ConstantBuffer::create(1024); + } + kind = "user"; m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount); } @@ -1972,7 +1975,10 @@ namespace bgfx BX_UNUSED(kind); } - m_constantBuffer->finish(); + if (NULL != m_constantBuffer) + { + m_constantBuffer->finish(); + } } uint16_t shaderSize; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 895c86b8..39624436 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2555,7 +2555,6 @@ namespace bgfx } m_numPredefined = 0; - m_constantBuffer = ConstantBuffer::create(1024); m_numSamplers = 0; struct VariableInfo @@ -2653,6 +2652,11 @@ namespace bgfx const UniformInfo* info = s_renderGL->m_uniformReg.find(name); if (NULL != info) { + if (NULL == m_constantBuffer) + { + m_constantBuffer = ConstantBuffer::create(1024); + } + UniformType::Enum type = convertGlType(gltype); m_constantBuffer->writeUniformHandle(type, 0, info->m_handle, num); m_constantBuffer->write(loc); @@ -2671,6 +2675,11 @@ namespace bgfx BX_UNUSED(offset); } + if (NULL != m_constantBuffer) + { + m_constantBuffer->finish(); + } + if (s_extension[Extension::ARB_program_interface_query].m_supported || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 31) ) { @@ -2710,8 +2719,6 @@ namespace bgfx } } - m_constantBuffer->finish(); - memset(m_attributes, 0xff, sizeof(m_attributes) ); uint32_t used = 0; for (uint32_t ii = 0; ii < Attrib::Count; ++ii)