Browse Source

Final check-in before I start ripping out existing GpuProgramParams

Marko Pintera 13 năm trước cách đây
mục cha
commit
b13df25243

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -26,8 +26,8 @@ using namespace CamelotEngine;
 
 int _tmain(int argc, _TCHAR* argv[])
 {
-	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
-	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();

+ 3 - 0
CamelotD3D11RenderSystem/Include/CmD3D11HardwareBufferManager.h

@@ -21,6 +21,9 @@ namespace CamelotEngine
 		 */
 		HardwareIndexBufferPtr createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, HardwareBuffer::Usage usage);
 
+		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
+		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc);
+
 	protected:     
 		/// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
 		VertexDeclarationPtr createVertexDeclarationImpl(void);

+ 6 - 0
CamelotD3D11RenderSystem/Source/CmD3D11HardwareBufferManager.cpp

@@ -3,6 +3,7 @@
 #include "CmD3D11HardwareIndexBuffer.h"
 #include "CmD3D11HardwareConstantBuffer.h"
 #include "CmD3D11VertexDeclaration.h"
+#include "CmGpuParamDesc.h"
 
 namespace CamelotEngine
 {
@@ -42,6 +43,11 @@ namespace CamelotEngine
 
 		return HardwareIndexBufferPtr(idx);
 	}
+
+	GpuParamBlockPtr D3D11HardwareBufferManagerBase::createGpuParamBlock(const GpuParamBlockDesc& blockDesc)
+	{
+		return GpuParamBlockPtr(new GpuParamBlock(blockDesc));
+	}
 
 	VertexDeclarationPtr D3D11HardwareBufferManagerBase::createVertexDeclarationImpl(void)
 	{

+ 2 - 5
CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h

@@ -58,11 +58,8 @@ namespace CamelotEngine {
 		HardwareIndexBufferPtr 
             createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, HardwareBuffer::Usage usage);
 
-		/**
-		 * @copydoc HardwareBufferManagerBase::createConstantBuffer
-		 */
-		HardwareConstantBufferPtr 
-			createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage);
+		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
+		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc);
     };
 
 	/// D3D9HardwareBufferManagerBase as a Singleton

+ 2 - 0
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -59,6 +59,8 @@ namespace CamelotEngine
 		void bindGpuProgramParameters(GpuProgramType gptype, 
 			GpuProgramParametersSharedPtr params, UINT16 variabilityMask);
 
+		void bindGpuParams(GpuProgramType gptype, GpuParamsPtr params);
+
 		void setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr);
 
 		/**

+ 4 - 4
CamelotD3D9Renderer/Source/CmD3D9HLSLProgram.cpp

@@ -85,7 +85,7 @@ namespace CamelotEngine {
 	{
 	public:
 		D3D9HLSLParamParser(LPD3DXCONSTANTTABLE constTable)
-			:mpConstTable(constTable), mCurrentBufferSize(0)
+			:mpConstTable(constTable)
 		{ }
 
 		GpuParamDesc buildParameterDescriptions();
@@ -95,7 +95,6 @@ namespace CamelotEngine {
 	private:
 		LPD3DXCONSTANTTABLE mpConstTable;
 		GpuParamDesc mParamDesc;
-		UINT32 mCurrentBufferSize;
 	};
 
 	GpuParamDesc D3D9HLSLParamParser::buildParameterDescriptions()
@@ -116,6 +115,7 @@ namespace CamelotEngine {
 		GpuParamBlockDesc& blockDesc = mParamDesc.paramBlocks[name];
 		blockDesc.name = name;
 		blockDesc.slot = 0;
+		blockDesc.blockSize = 0;
 
 		// Iterate over the constants
 		for (UINT32 i = 0; i < desc.Constants; ++i)
@@ -168,7 +168,7 @@ namespace CamelotEngine {
 			{
 				GpuParamMemberDesc memberDesc;
 				memberDesc.gpuMemOffset = desc.RegisterIndex;
-				memberDesc.cpuMemOffset = mCurrentBufferSize;
+				memberDesc.cpuMemOffset = blockDesc.blockSize;
 				memberDesc.paramBlockSlot = blockDesc.slot;
 				memberDesc.arraySize = 1;
 
@@ -178,7 +178,7 @@ namespace CamelotEngine {
 				populateParamMemberDesc(memberDesc, desc);
 				mParamDesc.params.insert(std::make_pair(name, memberDesc));
 
-				mCurrentBufferSize += memberDesc.elementSize * memberDesc.arraySize;
+				blockDesc.blockSize += memberDesc.elementSize * memberDesc.arraySize;
 			}
 
 			if(desc.Type == D3DXPT_SAMPLER1D || desc.Type == D3DXPT_SAMPLER2D || desc.Type == D3DXPT_SAMPLER3D || desc.Type == D3DXPT_SAMPLERCUBE)

+ 3 - 4
CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp

@@ -29,6 +29,7 @@ THE SOFTWARE.
 #include "CmD3D9HardwareVertexBuffer.h"
 #include "CmD3D9HardwareIndexBuffer.h"
 #include "CmD3D9VertexDeclaration.h"
+#include "CmGpuParamBlock.h"
 #include "CmException.h"
 
 namespace CamelotEngine {
@@ -70,11 +71,9 @@ namespace CamelotEngine {
             
     }
 	//-----------------------------------------------------------------------
-	HardwareConstantBufferPtr 
-		D3D9HardwareBufferManagerBase::
-		createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage)
+	GpuParamBlockPtr D3D9HardwareBufferManagerBase::createGpuParamBlock(const GpuParamBlockDesc& paramDesc)
 	{
-		CM_EXCEPT(RenderingAPIException, "Constant buffers not supported on D3D9.");
+		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
 	}
     //-----------------------------------------------------------------------
     VertexDeclarationPtr D3D9HardwareBufferManagerBase::createVertexDeclarationImpl(void)

+ 140 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -52,6 +52,9 @@ THE SOFTWARE.
 #include "CmBlendState.h"
 #include "CmRasterizerState.h"
 #include "CmDepthStencilState.h"
+#include "CmGpuParams.h"
+#include "CmGpuParamDesc.h"
+#include "CmGpuParamBlock.h"
 
 #if CM_DEBUG_MODE
 #define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
@@ -451,6 +454,143 @@ namespace CamelotEngine
 		};
 	}
 	//---------------------------------------------------------------------
+	void D3D9RenderSystem::bindGpuParams(GpuProgramType gptype, GpuParamsPtr params)
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		const GpuParamDesc& paramDesc = params->getParamDesc();
+
+		for(auto iter = paramDesc.samplers.begin(); iter != paramDesc.samplers.end(); ++iter)
+		{
+			SamplerStatePtr samplerState = params->getSamplerState(iter->second.slot);
+
+			if(samplerState == nullptr)
+				setSamplerState(iter->second.slot, SamplerState::getDefault());
+			else
+				setSamplerState(iter->second.slot, *samplerState);
+		}
+
+		for(auto iter = paramDesc.textures.begin(); iter != paramDesc.textures.end(); ++iter)
+		{
+			TextureHandle texture = params->getTexture(iter->second.slot);
+
+			if(!texture.isLoaded())
+				setTexture(iter->second.slot, false, nullptr);
+			else
+				setTexture(iter->second.slot, true, texture.getInternalPtr());
+		}
+
+		HRESULT hr;
+
+		switch(gptype)
+		{
+		case GPT_VERTEX_PROGRAM:
+			{
+				for(auto iter = paramDesc.params.begin(); iter != paramDesc.params.end(); ++iter)
+				{
+					const GpuParamMemberDesc& paramDesc = iter->second;
+
+					GpuParamBlockPtr paramBlock = params->getParamBlock(paramDesc.paramBlockSlot);
+					const UINT8* ptrData = paramBlock->getDataPtr(paramDesc.cpuMemOffset * sizeof(UINT32));
+
+					switch(paramDesc.type)
+					{
+					case GMT_FLOAT1:
+					case GMT_FLOAT2:
+					case GMT_FLOAT3:
+					case GMT_FLOAT4:
+					case GMT_MATRIX_2X2:
+					case GMT_MATRIX_2X3:
+					case GMT_MATRIX_2X4:
+					case GMT_MATRIX_3X2:
+					case GMT_MATRIX_3X3:
+					case GMT_MATRIX_3X4:
+					case GMT_MATRIX_4X2:
+					case GMT_MATRIX_4X3:
+					case GMT_MATRIX_4X4:
+						{
+							UINT32 slotCount = (paramDesc.elementSize / 4) * paramDesc.arraySize;
+							assert (paramDesc.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
+
+							if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantF(paramDesc.gpuMemOffset, (const float*)ptrData, slotCount))) 
+								CM_EXCEPT(RenderingAPIException, "Unable to upload vertex shader float parameters.");
+							break;
+						}
+					case GMT_INT1:
+					case GMT_INT2:
+					case GMT_INT3:
+					case GMT_INT4:
+						{
+							UINT32 slotCount = (paramDesc.elementSize / 4) * paramDesc.arraySize;
+							assert (paramDesc.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
+
+							if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantI(paramDesc.gpuMemOffset, (const INT32*)ptrData, slotCount))) 
+								CM_EXCEPT(RenderingAPIException, "Unable to upload vertex shader int parameters.");
+							break;
+						}
+					case GMT_BOOL:
+						if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantB(paramDesc.gpuMemOffset, (const BOOL*)ptrData, paramDesc.arraySize))) 
+							CM_EXCEPT(RenderingAPIException, "Unable to upload vertex shader bool parameters.");
+						break;
+					}
+				}
+			}
+			break;
+		case GPT_FRAGMENT_PROGRAM:
+			{
+				for(auto iter = paramDesc.params.begin(); iter != paramDesc.params.end(); ++iter)
+				{
+					const GpuParamMemberDesc& paramDesc = iter->second;
+
+					GpuParamBlockPtr paramBlock = params->getParamBlock(paramDesc.paramBlockSlot);
+					const UINT8* ptrData = paramBlock->getDataPtr(paramDesc.cpuMemOffset * sizeof(UINT32));
+
+					switch(paramDesc.type)
+					{
+					case GMT_FLOAT1:
+					case GMT_FLOAT2:
+					case GMT_FLOAT3:
+					case GMT_FLOAT4:
+					case GMT_MATRIX_2X2:
+					case GMT_MATRIX_2X3:
+					case GMT_MATRIX_2X4:
+					case GMT_MATRIX_3X2:
+					case GMT_MATRIX_3X3:
+					case GMT_MATRIX_3X4:
+					case GMT_MATRIX_4X2:
+					case GMT_MATRIX_4X3:
+					case GMT_MATRIX_4X4:
+						{
+							UINT32 slotCount = (paramDesc.elementSize / 4) * paramDesc.arraySize;
+							assert (paramDesc.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
+
+							if (FAILED(hr = getActiveD3D9Device()->SetPixelShaderConstantF(paramDesc.gpuMemOffset, (const float*)ptrData, slotCount))) 
+								CM_EXCEPT(RenderingAPIException, "Unable to upload pixel shader float parameters.");
+							break;
+						}
+					case GMT_INT1:
+					case GMT_INT2:
+					case GMT_INT3:
+					case GMT_INT4:
+						{
+							UINT32 slotCount = (paramDesc.elementSize / 4) * paramDesc.arraySize;
+							assert (paramDesc.elementSize % 4 == 0 && "Should not have any elements less than 4 wide for D3D9");
+
+							if (FAILED(hr = getActiveD3D9Device()->SetPixelShaderConstantI(paramDesc.gpuMemOffset, (const INT32*)ptrData, slotCount))) 
+								CM_EXCEPT(RenderingAPIException, "Unable to upload pixel shader int parameters.");
+							break;
+						}
+					case GMT_BOOL:
+						if (FAILED(hr = getActiveD3D9Device()->SetPixelShaderConstantB(paramDesc.gpuMemOffset, (const BOOL*)ptrData, paramDesc.arraySize))) 
+							CM_EXCEPT(RenderingAPIException, "Unable to upload pixel shader bool parameters.");
+						break;
+					}
+				}
+			}
+			break;
+		};
+	}
+	//---------------------------------------------------------------------
 	void D3D9RenderSystem::destroyRenderTarget(RenderTarget* renderTarget)
 	{		
 		THROW_IF_NOT_RENDER_THREAD;

+ 2 - 5
CamelotGLRenderer/Include/CmGLDefaultHardwareBufferManager.h

@@ -118,11 +118,8 @@ namespace CamelotEngine {
             createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, 
 				HardwareBuffer::Usage usage);
 
-		/**
-		 * @copydoc HardwareBufferManagerBase::createConstantBuffer
-		 */
-		HardwareConstantBufferPtr createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage);
-
+		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
+		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc);
     };
 
 	/// GLDefaultHardwareBufferManagerBase as a Singleton

+ 2 - 4
CamelotGLRenderer/Include/CmGLHardwareBufferManager.h

@@ -62,10 +62,8 @@ namespace CamelotEngine {
             HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, 
             HardwareBuffer::Usage usage);
 
-		/**
-		 * @copydoc HardwareBufferManagerBase::createConstantBuffer
-		 */
-		HardwareConstantBufferPtr createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage);
+		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
+		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc);
 
         /// Utility function to get the correct GL usage based on HBU's
         static GLenum getGLUsage(unsigned int usage);

+ 3 - 2
CamelotGLRenderer/Source/CmGLDefaultHardwareBufferManager.cpp

@@ -26,6 +26,7 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
 #include "CmGLDefaultHardwareBufferManager.h"
+#include "CmGpuParamBlock.h"
 #include "CmException.h"
 
 namespace CamelotEngine {
@@ -166,8 +167,8 @@ namespace CamelotEngine {
 			new GLDefaultHardwareIndexBuffer(itype, numIndexes, usage) );
 	}
 	//---------------------------------------------------------------------
-	HardwareConstantBufferPtr GLDefaultHardwareBufferManagerBase::createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage)
+	GpuParamBlockPtr GLDefaultHardwareBufferManagerBase::createGpuParamBlock(const GpuParamBlockDesc& paramDesc)
 	{
-		CM_EXCEPT(RenderingAPIException, "Support for constant buffers not implemented yet in OpenGL.");
+		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
 	}
 }

+ 2 - 2
CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp

@@ -104,9 +104,9 @@ namespace CamelotEngine {
 		return HardwareIndexBufferPtr(buf);
     }
 	//---------------------------------------------------------------------
-	HardwareConstantBufferPtr GLHardwareBufferManagerBase::createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage)
+	GpuParamBlockPtr GLHardwareBufferManagerBase::createGpuParamBlock(const GpuParamBlockDesc& paramDesc)
 	{
-		CM_EXCEPT(RenderingAPIException, "Support for constant buffers not implemented yet in OpenGL.");
+		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
 	}
     //---------------------------------------------------------------------
     GLenum GLHardwareBufferManagerBase::getGLUsage(unsigned int usage)

+ 3 - 3
CamelotRenderer/Include/CmDefaultHardwareBufferManager.h

@@ -137,9 +137,9 @@ namespace CamelotEngine {
 		HardwareIndexBufferPtr 
             createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, 
 				HardwareBuffer::Usage usage);
-		/// Create a hardware constant buffer
-		HardwareConstantBufferPtr 
-			createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage);
+
+		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
+		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc);
     };
 
 	/// DefaultHardwareBufferManager as a Singleton

+ 6 - 2
CamelotRenderer/Include/CmGpuParamBlock.h

@@ -4,16 +4,20 @@
 
 namespace CamelotEngine
 {
-	class GpuParamBlock
+	class CM_EXPORT GpuParamBlock
 	{
 	public:
-		GpuParamBlock(UINT32 size);
+		GpuParamBlock(const GpuParamBlockDesc& desc);
 		~GpuParamBlock();
 
 		void write(UINT32 offset, const void* data, UINT32 size);
 		void zeroOut(UINT32 offset, UINT32 size);
 
+		const UINT8* getDataPtr(UINT32 offset) const;
+
 		virtual void updateIfDirty();
+		
+		static GpuParamBlockPtr create(const GpuParamBlockDesc& desc);
 	private:
 		bool mDirty;
 		UINT8* mData;

+ 1 - 0
CamelotRenderer/Include/CmGpuParamDesc.h

@@ -64,6 +64,7 @@ namespace CamelotEngine
 	{
 		String name;
 		UINT32 slot;
+		UINT32 blockSize;
 	};
 
 	struct GpuParamDesc

+ 8 - 3
CamelotRenderer/Include/CmGpuParams.h

@@ -4,17 +4,19 @@
 
 namespace CamelotEngine
 {
-	class GpuParams
+	class CM_EXPORT GpuParams
 	{
 	public:
 		GpuParams(GpuParamDesc& paramDesc);
 
-		GpuParamBlockPtr getParamBlock(UINT32 index) const;
+		GpuParamBlockPtr getParamBlock(UINT32 slot) const;
 		GpuParamBlockPtr getParamBlock(const String& name) const;
 
-		void setParamBlock(UINT32 index, GpuParamBlockPtr paramBlock);
+		void setParamBlock(UINT32 slot, GpuParamBlockPtr paramBlock);
 		void setParamBlock(const String& name, GpuParamBlockPtr paramBlock);
 
+		const GpuParamDesc& getParamDesc() const { return mParamDesc; }
+
 		bool hasParam(const String& name) const;
 		bool hasTexture(const String& name) const;
 		bool hasSamplerState(const String& name) const;
@@ -41,7 +43,10 @@ namespace CamelotEngine
 		void setParam(const String& name, const void* value, UINT32 sizeBytes, UINT32 arrayIndex = 0);
 
 		void setTexture(const String& name, TextureHandle val);
+		TextureHandle getTexture(UINT32 slot);
+
 		void setSamplerState(const String& name, SamplerStatePtr val);
+		SamplerStatePtr getSamplerState(UINT32 slot);
 
 		void setTransposeMatrices(bool transpose) { mTransposeMatrices = transpose; }
 

+ 15 - 0
CamelotRenderer/Include/CmHardwareBufferManager.h

@@ -34,6 +34,7 @@ THE SOFTWARE.
 #include "CmModule.h"
 #include "CmHardwareVertexBuffer.h"
 #include "CmHardwareIndexBuffer.h"
+#include "CmGpuParamBlock.h"
 
 namespace CamelotEngine {
 	/** \addtogroup Core
@@ -123,6 +124,14 @@ namespace CamelotEngine {
             createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, 
 			HardwareBuffer::Usage usage) = 0;
 
+		/**
+		 * @brief	Creates an GPU parameter block that you can use for setting parameters
+		 * 			for GPU programs.
+		 *
+		 * @return	The new GPU parameter block.
+		 */
+		virtual GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc) = 0;
+
         /** Creates a new vertex declaration. */
         virtual VertexDeclarationPtr createVertexDeclaration(void);
 
@@ -157,6 +166,12 @@ namespace CamelotEngine {
 			return mImpl->createIndexBuffer(itype, numIndexes, usage);
 		}
 
+		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
+		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc)
+		{
+			return mImpl->createGpuParamBlock(paramDesc);
+		}
+
 		/** @copydoc HardwareBufferManagerInterface::createVertexDeclaration */
 		virtual VertexDeclarationPtr createVertexDeclaration(void)
 		{

+ 3 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -116,8 +116,10 @@ namespace CamelotEngine {
 	class RasterizerState;
 	class BlendState;
 	class GpuParamBlock;
+	class GpuParams;
 	struct GpuParamDesc;
 	struct GpuParamMemberDesc;
+	struct GpuParamBlockDesc;
 	// Asset import
 	class SpecificImporter;
 	class Importer;
@@ -175,6 +177,7 @@ namespace CamelotEngine
 	typedef std::shared_ptr<DepthStencilBuffer> DepthStencilBufferPtr;
 	typedef std::shared_ptr<MultiRenderTexture> MultiRenderTexturePtr;
 	typedef std::shared_ptr<GpuParamBlock> GpuParamBlockPtr;
+	typedef std::shared_ptr<GpuParams> GpuParamsPtr;
 }
 
 // All type IDs used for RTTI

+ 2 - 4
CamelotRenderer/Source/CmDefaultHardwareBufferManager.cpp

@@ -215,10 +215,8 @@ namespace CamelotEngine {
 		return HardwareIndexBufferPtr(ib);
 	}
 	//-----------------------------------------------------------------------
-	HardwareConstantBufferPtr 
-		DefaultHardwareBufferManagerBase::createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage)
+	GpuParamBlockPtr DefaultHardwareBufferManagerBase::createGpuParamBlock(const GpuParamBlockDesc& paramDesc)
 	{
-		DefaultHardwareConstantBuffer* ib = new DefaultHardwareConstantBuffer(this, sizeBytes, usage);
-		return HardwareConstantBufferPtr(ib);
+		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
 	}
 }

+ 29 - 4
CamelotRenderer/Source/CmGpuParamBlock.cpp

@@ -1,13 +1,15 @@
 #include "CmGpuParamBlock.h"
+#include "CmGpuParamDesc.h"
+#include "CmHardwareBufferManager.h"
 #include "CmException.h"
 
 namespace CamelotEngine
 {
-	GpuParamBlock::GpuParamBlock(UINT32 size)
-		:mSize(size), mDirty(true)
+	GpuParamBlock::GpuParamBlock(const GpuParamBlockDesc& desc)
+		:mSize(desc.blockSize), mDirty(true)
 	{
-		mData = new UINT8[size];
-		memset(mData, 0, size);
+		mData = new UINT8[desc.blockSize];
+		memset(mData, 0, desc.blockSize);
 	}
 
 	GpuParamBlock::~GpuParamBlock()
@@ -17,12 +19,14 @@ namespace CamelotEngine
 
 	void GpuParamBlock::write(UINT32 offset, const void* data, UINT32 size)
 	{
+#if CM_DEBUG_MODE
 		if(offset < 0 || (offset + size) >= mSize)
 		{
 			CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
 				"Available range: 0 .. " + toString(mSize) + ". " \
 				"Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
 		}
+#endif
 
 		memcpy(mData + offset, data, size);
 
@@ -31,20 +35,41 @@ namespace CamelotEngine
 
 	void GpuParamBlock::zeroOut(UINT32 offset, UINT32 size)
 	{
+#if CM_DEBUG_MODE
 		if(offset < 0 || (offset + size) >= mSize)
 		{
 			CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
 				"Available range: 0 .. " + toString(mSize) + ". " \
 				"Wanted range: " + toString(offset) + " .. " + toString(offset + size) + ".");
 		}
+#endif
 
 		memset(mData + offset, 0, size);
 
 		mDirty = true;
 	}
 
+	const UINT8* GpuParamBlock::getDataPtr(UINT32 offset) const
+	{
+#if CM_DEBUG_MODE
+		if(offset < 0 || offset >= mSize)
+		{
+			CM_EXCEPT(InvalidParametersException, "Wanted range is out of buffer bounds. " \
+				"Available range: 0 .. " + toString(mSize) + ". " \
+				"Wanted range: " + toString(offset) + " .. " + toString(offset) + ".");
+		}
+#endif
+
+		return &mData[offset];
+	}
+
 	void GpuParamBlock::updateIfDirty()
 	{
 		// Do nothing
 	}
+
+	GpuParamBlockPtr GpuParamBlock::create(const GpuParamBlockDesc& desc)
+	{
+		return HardwareBufferManager::instance().createGpuParamBlock(desc);
+	}
 }

+ 36 - 15
CamelotRenderer/Source/CmGpuParams.cpp

@@ -19,6 +19,11 @@ namespace CamelotEngine
 
 		mParamBlocks.resize(maxParamBlockSlot + 1);
 
+		for(auto iter = mParamDesc.paramBlocks.begin(); iter != mParamDesc.paramBlocks.end(); ++iter)
+		{
+			mParamBlocks[iter->second.slot] = GpuParamBlock::create(iter->second);
+		}
+
 		UINT32 maxTextureSlot = 0;
 		for(auto iter = mParamDesc.textures.begin(); iter != mParamDesc.textures.end(); ++iter)
 		{
@@ -36,23 +41,17 @@ namespace CamelotEngine
 		}
 
 		mSamplerStates.resize(maxSamplerSlot + 1);
-
-		// TODO - Create ParamBlocks
 	}
 
-	GpuParamBlockPtr GpuParams::getParamBlock(UINT32 index) const
+	GpuParamBlockPtr GpuParams::getParamBlock(UINT32 slot) const
 	{
-		UINT32 idx = 0;
-		
-		for(auto iter = mParamBlocks.begin(); iter != mParamBlocks.end(); ++iter)
+		if(slot < 0 || slot >= (UINT32)mParamBlocks.size())
 		{
-			if(idx == index)
-				return *iter;
-
-			idx++;
+			CM_EXCEPT(InvalidParametersException, "Index out of range: Valid range: 0 .. " + 
+				toString(mParamBlocks.size() - 1) + ". Requested: " + toString(slot));
 		}
 
-		return nullptr;
+		return mParamBlocks[slot];
 	}
 
 	GpuParamBlockPtr GpuParams::getParamBlock(const String& name) const
@@ -68,15 +67,15 @@ namespace CamelotEngine
 		return mParamBlocks[iterFind->second.slot];
 	}
 
-	void GpuParams::setParamBlock(UINT32 index, GpuParamBlockPtr paramBlock)
+	void GpuParams::setParamBlock(UINT32 slot, GpuParamBlockPtr paramBlock)
 	{
-		if(index < 0 || index >= (UINT32)mParamBlocks.size())
+		if(slot < 0 || slot >= (UINT32)mParamBlocks.size())
 		{
 			CM_EXCEPT(InvalidParametersException, "Index out of range: Valid range: 0 .. " + 
-				toString(mParamBlocks.size() - 1) + ". Requested: " + toString(index));
+				toString(mParamBlocks.size() - 1) + ". Requested: " + toString(slot));
 		}
 
-		mParamBlocks[index] = paramBlock;
+		mParamBlocks[slot] = paramBlock;
 	}
 
 	void GpuParams::setParamBlock(const String& name, GpuParamBlockPtr paramBlock)
@@ -229,6 +228,17 @@ namespace CamelotEngine
 		mTextures[paramIter->second.slot] = val;
 	}
 
+	TextureHandle GpuParams::getTexture(UINT32 slot)
+	{
+		if(slot < 0 || slot >= (UINT32)mTextures.size())
+		{
+			CM_EXCEPT(InvalidParametersException, "Index out of range: Valid range: 0 .. " + 
+				toString(mTextures.size() - 1) + ". Requested: " + toString(slot));
+		}
+
+		return mTextures[slot];
+	}
+
 	void GpuParams::setSamplerState(const String& name, SamplerStatePtr val)
 	{
 		auto paramIter = mParamDesc.samplers.find(name);
@@ -241,6 +251,17 @@ namespace CamelotEngine
 		mSamplerStates[paramIter->second.slot] = val;
 	}
 
+	SamplerStatePtr GpuParams::getSamplerState(UINT32 slot)
+	{
+		if(slot < 0 || slot >= (UINT32)mSamplerStates.size())
+		{
+			CM_EXCEPT(InvalidParametersException, "Index out of range: Valid range: 0 .. " + 
+				toString(mSamplerStates.size() - 1) + ". Requested: " + toString(slot));
+		}
+
+		return mSamplerStates[slot];
+	}
+
 	GpuParamMemberDesc* GpuParams::getParamDesc(const String& name) const
 	{
 		auto paramIter = mParamDesc.params.find(name);