Getting constants definition name in C++

Problems building or running the engine, queries about how to use features etc.
Post Reply
Ludobaka
Gnoblar
Posts: 7
Joined: Wed Dec 17, 2014 4:20 pm

Getting constants definition name in C++

Post by Ludobaka »

Hello !

I am trying to get the name of constant definitions I have set in a material file in my C++ code.

First, here is my .material script :

Code: Select all

vertex_program myVertexShader glsl
{
  source Diffuse_VP.glsl
}

fragment_program myFragmentShader glsl
{
  source Diffuse_FP.glsl
}

// Template material for diffuse lightning
material Diffuse
{
    // Default technique
    technique
    {
        pass
        {
            ambient 0.5 0.5 0.5
            diffuse 1.0 1.0 1.0

	    vertex_program_ref myVertexShader
            {
                param_named_auto u_worldViewProj worldviewproj_matrix
                param_named_auto u_cameraPos camera_position
            }

            fragment_program_ref myFragmentShader
            {
                param_named_auto u_lightDir light_direction 0

                param_named defaultParam float 0
            }
        }
    }
}
Here is the corresponding fragment GLSL file :

Code: Select all

// requires OpenGL >= 3.2
#version 150

uniform float defaultParam;
uniform vec3 u_lightDir;

in vec3 oPosition_WS;
in vec3 oNormal_WS;
in vec3 cameraPos_WS;

out vec4 fragColor;

void main(void)
{
    vec3 lightDir = -u_lightDir;
    float fLitDiffuse = clamp( dot( normalize(oNormal_WS), lightDir ), 0, 1 );

    fragColor = vec4(defaultParam, 1.0, 0.0, 1.0) * fLitDiffuse;
}
My goal is to get only defaultParam, which is my constant, and not the others auto constants like u_lightDir.

I succeed to get this constants by checking the physical index of my constants in this two containers and removing the one corresponding to the auto constants :

Code: Select all

::Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
::Ogre::GpuConstantDefinitionIterator constantsDefinitionIt = params->getConstantDefinitionIterator(); // Contains all of this sahder's constants
::Ogre::GpuProgramParameters::AutoConstantIterator autoConstantsDefinitionIt = params->getAutoConstantIterator(); // Contains only this shader's autoConstants
// Create the map constantsDefinitionIt - autoConstantsDefinitionIt substract by physicalIndex
Now I'm stuck in an other problem : each parameter seems to be defined as the whole object and it's buffer :

Code: Select all

// definitionName / constType / physicalIndex / logicalIndex / elementSize / arraySize
Param for : fp
Constant definitions
defaultParam/1/0/0/1/1
defaultParam[0]/1/0/0/1/1
The only way to get my constant names is to remove definitions containing "]", but it look's really bad code...

Can someone help me to get my constants names in a better way?

Thanks
Ludobaka
Gnoblar
Posts: 7
Joined: Wed Dec 17, 2014 4:20 pm

Re: Getting constants definition name in C++

Post by Ludobaka »

Do I need to give more details in order to help you to solve the problem?
Post Reply