Просмотр исходного кода

Fixed constant buffer allocation logic.

Branimir Karadžić 11 лет назад
Родитель
Сommit
51d8daf762
3 измененных файлов с 28 добавлено и 9 удалено
  1. 9 3
      src/renderer_d3d11.cpp
  2. 9 3
      src/renderer_d3d9.cpp
  3. 10 3
      src/renderer_gl.cpp

+ 9 - 3
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;

+ 9 - 3
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;

+ 10 - 3
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)