Przeglądaj źródła

Add debug logs and a const to protect passed data

Daniele Bartolini 12 lat temu
rodzic
commit
b298c6a815
2 zmienionych plików z 12 dodań i 4 usunięć
  1. 5 1
      engine/renderers/RenderContext.h
  2. 7 3
      engine/renderers/Renderer.h

+ 5 - 1
engine/renderers/RenderContext.h

@@ -32,6 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "CommandBuffer.h"
 #include "ConstantBuffer.h"
 #include "RendererTypes.h"
+#include "Log.h"
 
 namespace crown
 {
@@ -229,7 +230,7 @@ struct RenderContext
 		m_state.ib = ib;
 	}
 
-	void set_uniform(UniformId id, UniformType::Enum type, void* value, uint8_t num)
+	void set_uniform(UniformId id, UniformType::Enum type, const void* value, uint8_t num)
 	{
 		m_constants.write_constant(id, type, value, num);
 	}
@@ -242,6 +243,9 @@ struct RenderContext
 		sampler.sampler_id = texture;
 		sampler.flags |= SAMPLER_TEXTURE | flags;
 
+		Log::d("Setting texture: sampler = %d.%d, texture = %d.%d, unit = %d", sampler_uniform.id, sampler_uniform.index
+			, texture.id, texture.index, unit);
+
 		set_uniform(sampler_uniform, UniformType::INTEGER_1, &unit, 1);
 	}
 

+ 7 - 3
engine/renderers/Renderer.h

@@ -576,15 +576,19 @@ public:
 	{
 		UniformType::Enum type;
 
+		uint32_t num = 0;
+
 		while ((type = (UniformType::Enum)cbuf.read()) != UniformType::END)
 		{
 			UniformId id;
-			size_t size;
+			uint32_t size;
 
 			cbuf.read(&id, sizeof(UniformId));
-			cbuf.read(&size, sizeof(size_t));
+			cbuf.read(&size, sizeof(uint32_t));
 			const void* data = cbuf.read(size);
 
+			Log::d("Updating uniform: number = %d, ID = %d.%d, size = %d, data = %d", num, id.id, id.index, size, *((int32_t*)data));
+			num++;
 			update_uniform_impl(id, size, data);
 		}
 
@@ -616,7 +620,7 @@ public:
 		m_submit->set_index_buffer(ib);
 	}
 
-	inline void set_uniform(UniformId id, UniformType::Enum type, void* value, uint8_t num)
+	inline void set_uniform(UniformId id, UniformType::Enum type, const void* value, uint8_t num)
 	{
 		m_submit->set_uniform(id, type, value, num);
 	}