Hi all, I'm new here... I hope you can help!
I've been tasked with making an OpenGL framework use DirectX. I'm limited to DirectX9 and v2.0 of the shaders.
Although each version (DX or GL) of the framework will have their own shaders, I'm trying to make portable functions and methods to DEAL with the shaders (i.e. a portable CompileShader, a portable SetUniform, etc).
So the issue I'm running into is, I'm not able to retrieve a handle to the shader variables in DirectX. If I use them as registers, I can do it that way, but for compatibility with GL, I would like to fetch them by name.
Here is my vertex shader code (very simple shader, just trying to figure out what's what right now):
float4x4 gMyMatrix;
struct VS_OUTPUT
{
float4 xyz : POSITION;
float4 diffuse : COLOR0;
float2 uv : TEXCOORD0;
};
VS_OUTPUT main(in float4 xyz : POSITION, in float4 diffuse : COLOR0, in float2 uv : TEXCOORD0)
{
VS_OUTPUT Output;
Output.xyz = mul(xyz,gMyMatrix);
Output.diffuse=diffuse;
Output.uv=uv;
return Output;
}
I'm compiling the shader like this, to get the Constants table:
LPD3DXBUFFER aVShaderCode=NULL;
ID3DXConstantTable* aConstants=NULL;
LPD3DXBUFFER aErrorList=NULL;
D3DXCompileShader(ShaderString,strlen(ShaderString),NULL,NULL,"main","vs_2_0",&aVShaderCode,&aErrors,&aConstants);
It compiles okay... but I want to get a handle to gMyMatrix in the same way you'd get a handle to a uniform variable in OpenGL... so I tried this:
D3DXHANDLE aHandle=aConstants->GetConstantByName(NULL,"gMyMatrix");
My problem is, the handle always returns a null handle, no matter what I do. Can anyone see anything what I'm doing wrong here? Some improper initialization? Some way of tagging that variable so that it's accessible through the constant table?
Any help or suggestions appreciated!