Material *CurrentMaterial;void **ConstantBuffer;D3D11_MAPPED_SUBRESOURCE Buffer;Matrix *BufferData;CurrentMaterial = GraphicsMgr.GetMaterialPointer(&MaterialName);ConstantBuffer = CurrentMaterial->GetConstantBufferPointer(ENZ_SHADER_VERTEX, "cbPerObject");MapBuffer(Renderer, Interface, *ConstantBuffer, &Buffer);BufferData = static_cast<Matrix*>(Buffer.pData);BufferData[0] = *World;UnmapBuffer(Renderer, Interface, *ConstantBuffer);ConstantBuffer = CurrentMaterial->GetConstantBufferPointer(ENZ_SHADER_VERTEX, "cbPerViewport");MapBuffer(Renderer, Interface, *ConstantBuffer, &Buffer);BufferData = static_cast<Matrix*>(Buffer.pData);BufferData[0] = *View;BufferData[1] = *Projection;UnmapBuffer(Renderer, Interface, *ConstantBuffer);
where my vertex shader constants are simply:
cbuffer cbPerObject {float4x4 WorldMatrix;}; cbuffer cbPerViewport { float4x4 ViewMatrix; float4x4 ProjectionMatrix; };
So I guess my question is, what is a good approach for code that will handle all four rendering APIs? I have wrapper classes for each of the APIs, so I can certainly put any API specific code in it's own function (MapBuffer and UnmapBuffer in the given code end up in the wrapper functions, for example).
I guess DX9 requires use of the SetVertexShaderConstantF function (presuming I want to set the vertex shader constants). But then, could I use the names of the buffer (e.g. "cbPerObject") somehow, the same way as is done for the other renderers?
Anyway, as I said, I'm floundering a bit on this one, so any advice is appreciated. Even just nudges in the right direction would be very helpful.
Ron
[Edited by - RonHiler on December 4, 2010 11:35:56 AM]