Hi all,
I am currently trying to pass a series of uniform variables into a fragment shader that processes polygons drawn by a cocos2d::DrawNode.
I am doing this using a GLProgramState, initializing it in the Init function of my Layer:
m_visibilityDrawNode = cocos2d::DrawNode::create();
addChild(m_visibilityDrawNode);
cocos2d::GLProgram* lightProgram = cocos2d::GLProgram::createWithFilenames("shaders/light.vertex", "shaders/light.fragment");
cocos2d::GLProgramState* state = cocos2d::GLProgramState::getOrCreateWithGLProgram(lightProgram);
m_visibilityDrawNode->setGLProgramState(state);
Then, in my update function I try to update a uniform variable in the fragment shader:
m_visibilityDrawNode->getGLProgramState()->setUniformFloat("a", 2.f);
m_visibilityDrawNode->getGLProgramState()->applyUniforms();
I am calling applyUniforms since this is what actually calls glUniform1fv (for every updated uniform)
In my fragment shader I just check what is the value of the uniform and draw with a color accordingly:
//fragment shader
uniform float a;
void main()
{
vec4 finalColor;
if (a == 0.0)
{
finalColor = vec4(0.0,0.0,0.0,0.0);
}
else
{
finalColor = vec4(1.0,1.0,1.0,1.0);
}
gl_FragColor = finalColor;
}
However, the uniform ‘a’ never changes its value and I always get black color (it’s not a problem with the shader or any other part since I get the right thing when I invert the condition).
Finally, whenever there is a call to glUniform1fv (called by applyUniforms) I end up with a messagethat tells me:
OpenGL error 0x0502 in …\renderer\CCFrameBuffer.cpp cocos2d::experimental::FrameBuffer::applyFBO 445
I have tried several things and I’m running out of ideas. So is there something I’m doing wrong? Or is this a bug?
Note: I am using cocos2d-x 3.10 and trying it on windows
Thank you very much for your help!