I'm working on a graphics api that has to run on both directx9 and opengl (2.1 and no uniform buffer support) I don't want to write two versions of the shaders and need to convert between hlsl and glsl (Cg is not an option) I've solved most problems, using lua to script parts of the shader (creating dummy main on glsl to support vertex in and out structs and such) but I'm having a hard time getting the constants right. In hlsl I can write:
float4x4 WorldViewProjection : register( c0 );
float4 ColorTint : register( c5 );
float3 UVOffset_Time : register( c6 );
and then set all of these using:
SetVertexShaderConstantF( 0, pData, 6 )
Alternatively SetPixelShaderConstantF. pData points to a struct with the same setup (ie 4x4 float matrix, 4 float vector, 3 float vector)
the only solution I've come up with in glsl is:
uniform vec4 UNIFORM0[ 6 ];
#define WorldViewProjection mat4( UNIFORM0[0], UNIFORM0[1], UNIFORM0[2], UNIFORM0[3] )
#define ColorTint UNIFORM0[4]
#define UVOffset_Time vec3( UNIFORM0[5].xyz )
and then I get the location of "UNIFORM0" from opengl and set the array using glUniform4fvARB However using #defines to get my constants into the shaders is pretty ugly.
Is there a way for me to set constants in a similar way to hlsl and what extensions would I need for it?
Can I use some kind of reference/typedef/handle to do something similar to the define solution without using an actual define, ie:
const mat4 WorldViewProjection = mat4( UNIFORM0[0], UNIFORM0[1], UNIFORM0[2], UNIFORM0[3] );