PDA

View Full Version : GL_EXT_gpu_program_parameters not working :(



AndreyOGL/D3D
01-09-2009, 04:38 AM
Hello!
I use glProgramLocalParameter4fvARB for send shader constants in shaders(GL_ARB_vertex_program/GL_ARB_fragment_program this). This
work.
code:


inline void OpenGLShader::SetMatrix4x4(unsigned int startIndex, const float *Matrix) const
{
assert(Matrix && "NULL Pointer");
glProgramLocalParameter4fvARB(programType, startIndex, &Matrix[0]);
glProgramLocalParameter4fvARB(programType, startIndex + 1, &Matrix[4]);
glProgramLocalParameter4fvARB(programType, startIndex + 2, &Matrix[8]);
glProgramLocalParameter4fvARB(programType, startIndex + 3, &Matrix[12]);
}
inline void OpenGLShader::SetMatrix4x3(unsigned int startIndex, const float *Matrix) const
{
assert(Matrix && "NULL Pointer");
glProgramLocalParameter4fvARB(programType, startIndex, &Matrix[0]);
glProgramLocalParameter4fvARB(programType, startIndex + 1, &Matrix[4]);
glProgramLocalParameter4fvARB(programType, startIndex + 2, &Matrix[8]);
}
...
// for each parameters
for(; afIt != autoFloatconstants.end(); ++afIt) {
// type of shader parameters
switch(afIt->constantType) {
case ShaderParameters::WORLD_VIEWPROJ_MATRIX:
// view * projection
case ShaderParameters::VIEWPROJ_MATRIX:
// world
case ShaderParameters::WORLD_MATRIX: {
// texture matrix
case ShaderParameters::SHADOW_MAP_TEXTURE_MATRIX:
// light viewproj matrix
case ShaderParameters::SHADOW_MAP_LIGHT_VIEWPROJ_MATRIX : {

SetMatrix4x4(static_cast<GLuint>(afIt->startIndex), &amp;afIt->constantData[0]);
}
break;
case ShaderParameters::CAMERA_DIRECTION:
...
glProgramLocalParameter4fvARB(programType, static_cast<GLuint>(afIt->startIndex), &amp;afIt->constantData[0]);
}
break;
// bone Matrix 4x3
case ShaderParameters::BONE_MATRIXS4x3: {
size_t numMatrixs = afIt->elementCount / 4;
for(size_t i = 0; i < numMatrixs; i += 3) {
SetMatrix4x3(static_cast<GLuint>(afIt->startIndex + i), &amp;afIt->constantData[i * 4]);
}
}
break;
}
}
}

shader constants store in std::vector<float> - constant pool
afIt->constantData - this pointer on corresponding to part of array
in Direct3D i use following code:


pDevice->SetVertexShaderConstantF(0, shaderParameters.GetFloatConstantData(), shaderParameters.GetNumFloatConstant());

shaderParameters.GetNumFloatConstant() this std::vector.size()/4
After, i try use GL_EXT_gpu_program_parameters - this send constants analog in Direct3D.


if (shaderParameters.GetNumFloatConstants()) {
glProgramLocalParameters4fvEXT(programType, 0, static_cast<GLsizei>(shaderParameters.GetNumFloatConstants()), shaderParameters.GetFloatConstantData());
}

example Shader:


!!ARBvp1.0
# cgc version 2.1.0016, build date Nov 20 2008
# command line args: -q -profile arbvp1 -entry vsMain -fastprecision -fastmath -O3 NumTemps=40 MaxInstructions=256 MaxAddressRegs=1 MaxLocalParams=512
#vendor NVIDIA Corporation
#version 2.1.0.16
#profile arbvp1
#program vsMain
#semantic ModelViewProjection : C0
#semantic time_0_X : C4
#semantic objPosition : C5
#semantic MatTexture : C6
#var float4 position : $vin.POSITION : POSITION : 0 : 1
#var float2 uv0 : $vin.TEXCOORD0 : TEXCOORD0 : 1 : 1
#var sampler2D DiffSampler : TEXUNIT0 : : -1 : 0
#var sampler2D ShadowMap : TEXUNIT2 : : -1 : 0
#var float4x4 ModelViewProjection : C0 : c[0], 4 : -1 : 1
#var float time_0_X : C4 : c[4] : -1 : 1
#var float3 objPosition : C5 : c[5] : -1 : 1
#var float4x4 MatTexture : C6 : c[6], 4 : -1 : 1
#var float4 vsMain.position : $vout.POSITION : HPOS : -1 : 1
#var float2 vsMain.uv0 : $vout.TEXCOORD0 : TEX0 : -1 : 1
#var float4 vsMain.shadowCrd : $vout.TEXCOORD1 : TEX1 : -1 : 1
#const c[10] = 1 0.15915491 0.25 -1
#const c[11] = 0 0.5 1 1.1
#const c[12] = 24.980801 -24.980801 -60.145809 60.145809
#const c[13] = 85.453789 -85.453789 -64.939346 64.939346
#const c[14] = 19.73921 -19.73921 -9 0.75
PARAM c[15] = { program.local[0..9],
{ 1, 0.15915491, 0.25, -1 },
{ 0, 0.5, 1, 1.1 },
{ 24.980801, -24.980801, -60.145809, 60.145809 },
{ 85.453789, -85.453789, -64.939346, 64.939346 },
{ 19.73921, -19.73921, -9, 0.75 } };
TEMP R0;
TEMP R1;
TEMP R2;
MOV R0.x, c[5];
ADD R0.x, R0, c[4];
ADD R0.x, R0, c[5].z;
ADD R0.x, vertex.position, R0;
ADD R0.x, vertex.position.y, R0;
MAD R0.x, R0, c[10].y, -c[10].z;
FRC R0.w, R0.x;
ADD R0.xyz, -R0.w, c[11];
MUL R0.xyz, R0, R0;
MAD R1.xyz, R0, c[12].xyxw, c[12].zwzw;
MAD R1.xyz, R1, R0, c[13].xyxw;
MAD R1.xyz, R1, R0, c[13].zwzw;
MAD R1.xyz, R1, R0, c[14].xyxw;
MAD R1.xyz, R1, R0, c[10].wxww;
SLT R2.x, R0.w, c[10].z;
SGE R2.yz, R0.w, c[14].xzww;
MOV R0.xz, R2;
DP3 R0.y, R2, c[10].wxww;
DP3 R0.y, R1, -R0;
ADD R0.x, -vertex.texcoord[0].y, c[10];
MUL R2.x, R0, R0.y;
MAD R2.y, R2.x, c[11].w, vertex.position.x;
MUL R1, vertex.position.y, c[7];
MUL R0, vertex.position.y, c[1];
MAD R2.x, R2, c[11].w, vertex.position.z;
MAD R1, R2.y, c[6], R1;
MAD R0, R2.y, c[0], R0;
MAD R0, R2.x, c[2], R0;
MAD R1, R2.x, c[8], R1;
MAD result.position, vertex.position.w, c[3], R0;
MAD result.texcoord[1], vertex.position.w, c[9], R1;
MOV result.texcoord[0].xy, vertex.texcoord[0];
END
# 32 instructions, 3 R-regs

if use GL_EXT_gpu_program_parameters This not work!,
if use glProgramLocalParameter4fvARB - this work.
That I do not so?
Thank you beforehand.
Andrey.

Ilian Dinev
01-10-2009, 04:32 PM
I've been using glProgramLocalParameters4fvEXT all the time, and it works.