Hello,
I have a crash with my shader management which I don't understand yet. I
suspect some fundamental flaw in my setup but hope that I only forgot
something simple.
In my setup I have two different shaders managed by my scene manager and
a state variable which tells me which shader, if any, is to be used.
Both shader use the same set of uniforms.
SceneManager init:
==================
ShaderProgramChunkRecPtr spc1, spc2;
int state state_1, state_2;
spc1 = createShaderProgramChunk(str_vert_prg_1, str_frag_prg_1);
spc2 = createShaderProgramChunk(str_vert_prg_2, str_frag_prg_2);
ShaderProgramChunkTransitPtr createShaderProgramChunk(string
vert_prg_1, string vert_prg_2)
{
ShaderProgramChunkRecPtr shader = ShaderProgramChunk::create();
ShaderProgramUnrecPtr vert =
ShaderProgram::createVertexShader();
ShaderProgramUnrecPtr frag =
ShaderProgram::createFragmentShader();
vert->setProgram(str_vert_prg, VERTEX_SHADER);
frag->setProgram(str_frag_prg, FRAGMENT_SHADER);
vert->addOSGVariable("OSGWorldMatrix");
vert->addOSGVariable("OSGLight0Active");
vert->addOSGVariable("OSGLight1Active");
vert->addOSGVariable("OSGLight2Active");
vert->addOSGVariable("OSGLight3Active");
vert->addOSGVariable("OSGLight4Active");
vert->addOSGVariable("OSGLight5Active");
vert->addOSGVariable("OSGLight6Active");
vert->addOSGVariable("OSGLight7Active");
vert->addUniformVariable<MFVec4f> ("uClipPlanes", clipplanes);
vert->addUniformVariable<MFInt32> ("uClipStates", clipstate);
shader->addShader(vert);
shader->addShader(frag);
}
Given: enum state { no_shader, shader_1, shader_2 }
Next I create an object with a chunk material without any shader, but
with some extra variable chunks.
Object-Creation:
================
state = no_shader
ChunkMaterialUnrecPtr mat =
createChunkMaterial(solid_display_modes);
ShaderProgramVariableChunkUnrecPtr variableChunk =
ShaderProgramVariableChunk::create();
variableChunk->addUniformVariable("uIsTwoSidedLighting", bool_flag);
variableChunk->addUniformVariable("uMaterial.ambient", color_val);
...
variableChunk->addUniformVariable("uMaterial.shininess", float_val);
...
variableChunk->addUniformVariable("uEnvironment.cool", color_val);
variableChunk->addUniformVariable("uEnvironment.warm", color_val);
variableChunk->addUniformVariable("uEnvironment.gooch_mixin",
float_val);
mat->addChunk(variableChunk);
=> Fixed function pipeline rendering; no shader from SceneManager
added to material, only ShaderProgramVariableChunks; works, ok
Next the scene manager state for which shader should be used changes to
shader_1. An update cycle is performed for my object.
Object-Update:
==============
state = shader_1
updateChunkMaterial(mat, solid_display_modes);
ShaderProgramVariableChunkUnrecPtr variableChunk =
dynamic_cast<ShaderProgramVariableChunk*>(mat->find(ShaderProgramVariabl
eChunk::getClassType()));
bool bVal;
bool ret = variableChunk->getUniformVariable("uIsTwoSidedLighting",
bVal);
if (!ret)
variableChunk->addUniformVariable("uIsTwoSidedLighting",
bIsTwoSidedLighting);
else if (bVal != new_bIsTwoSidedLighting)
variableChunk->updateUniformVariable("uIsTwoSidedLighting",
bIsTwoSidedLighting);
...
mat->add_chunk(shader_1);
=> Shader 1 rendering active; no new variable chunks added; actually
no updateUniformVariable called at all; works, ok
Next the scene manager state for which shader should be used changes to
shader_2. An update cycle is performed for my object.
Object-Update:
==============
state = shader_2
updateChunkMaterial(mat, solid_display_modes);
ShaderProgramVariableChunkUnrecPtr variableChunk =
dynamic_cast<ShaderProgramVariableChunk*>(mat->find(ShaderProgramVariabl
eChunk::getClassType()));
...dito
ShaderProgramChunkUnrecPtr shaderProgramChunk =
dynamic_cast<ShaderProgramChunk*>(mat->find(ShaderProgramChunk::getClass
Type()));
if (!shaderProgramChunk) {
mat->addChunk(shader_2);
} else {
if (shaderProgramChunk != shader_2) {
mat->subChunk(shaderProgramChunk);
mat->addChunk(shader_2);
}
}
=> Shader 1 rendering active; no new variable chunks added; actually
no updateUniformVariable called at all; crashes with the following
glIntercept error:
glUniform1iARB(108,0) glGetError() = GL_INVALID_OPERATION
with glGetUniformLocationARB(1,"uIsTwoSidedLighting")=108
The problem is order independent. I get the same result if starting with
shader_2 and switching to shader_1.
A 'commintChanges' call was performed after each update code.
Does anyone has an idea what is wrong with my setup?
Best,
Johannes
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users