|
@@ -52,6 +52,9 @@ THE SOFTWARE.
|
|
|
#include "CmBlendState.h"
|
|
#include "CmBlendState.h"
|
|
|
#include "CmRasterizerState.h"
|
|
#include "CmRasterizerState.h"
|
|
|
#include "CmDepthStencilState.h"
|
|
#include "CmDepthStencilState.h"
|
|
|
|
|
+#include "CmGpuParams.h"
|
|
|
|
|
+#include "CmGpuParamDesc.h"
|
|
|
|
|
+#include "CmGpuParamBlock.h"
|
|
|
|
|
|
|
|
#if CM_DEBUG_MODE
|
|
#if CM_DEBUG_MODE
|
|
|
#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
|
|
#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)
|
|
void D3D9RenderSystem::destroyRenderTarget(RenderTarget* renderTarget)
|
|
|
{
|
|
{
|
|
|
THROW_IF_NOT_RENDER_THREAD;
|
|
THROW_IF_NOT_RENDER_THREAD;
|