how to reload the glsl shader?
i want to change my fragment shader, for example: first i write gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0); when the shader is running, i want to change to gl_FragData[0] = vec4(1.0, 1.0, 1.0, 1.0), how can i do that?
i try to reload the shader, rebind, recompile, but there is no change on my rendering result.
could you give me some advice? thanks a lot!
Recompiling the shader isn't enough I guess, you'd have to also relink the program.
Using a uniform variable would be the better way to do this however. ;)
Using a uniform variable would be the better way to do this however. ;)
sorry, i want to debug the shader throughing save the output to image by binding a fbo, so i will set gl_FragData[1] to any variable in the shader. Using a uniform variable would not resolve my problem.
i also relink the program as follows:
glShaderSource(m_hGLSLVertexShader, 1, &szVShader, NULL);
glShaderSource(m_hGLSLFragmentShader, 1, &szFShader, NULL);
// Now we actually compile the shader's code
glCompileShader(m_hGLSLVertexShader);
glCompileShader(m_hGLSLFragmentShader);
// We attach each shader we just loaded to our program object
glAttachObjectARB(m_hGLSLProgramObject, m_hGLSLVertexShader);
glAttachObjectARB(m_hGLSLProgramObject, m_hGLSLFragmentShader);
// Our last init function is to link our program object with OpenGL
glLinkProgramARB(m_hGLSLProgramObject);
but it does not work.
i also relink the program as follows:
glShaderSource(m_hGLSLVertexShader, 1, &szVShader, NULL);
glShaderSource(m_hGLSLFragmentShader, 1, &szFShader, NULL);
// Now we actually compile the shader's code
glCompileShader(m_hGLSLVertexShader);
glCompileShader(m_hGLSLFragmentShader);
// We attach each shader we just loaded to our program object
glAttachObjectARB(m_hGLSLProgramObject, m_hGLSLVertexShader);
glAttachObjectARB(m_hGLSLProgramObject, m_hGLSLFragmentShader);
// Our last init function is to link our program object with OpenGL
glLinkProgramARB(m_hGLSLProgramObject);
but it does not work.
Quote:Original post by kolrabi
Recompiling the shader isn't enough I guess, you'd have to also relink the program.
Using a uniform variable would be the better way to do this however. ;)
No what he is saying is take a vec4 aka float temp[4]; upload that to GLSL with a uniform variable. And call the update each frame so you can update it. glUniform() and glGetUniformLocation()
but, i want output some interim result to debug, not the varialbe from cpu throuth a unifrom variable.
Quote:Original post by MARS_999
No what he is saying is take a vec4 aka float temp[4]; upload that to GLSL with a uniform variable. And call the update each frame so you can update it. glUniform() and glGetUniformLocation()
Quote:but it does not work.
Are you checking for errors? Post a small project so that people can test.
yeah, i have resolved it.
when i do the shader recompile, relink operation, it will return an error as "invalidation operation", because of i did not bind an opengl context. I used mfc frame, so, i should do as follows:
wglMakeCurrent(m_pDC->GetSafeHdc(),m_hRC)//m_pDC and m_hRC is my custom variable
call opengl function(reload the shader, assign, compile, attach and link)
wglMakeCurrent(NULL,NULL);
thanks for every warmhearted people
when i do the shader recompile, relink operation, it will return an error as "invalidation operation", because of i did not bind an opengl context. I used mfc frame, so, i should do as follows:
wglMakeCurrent(m_pDC->GetSafeHdc(),m_hRC)//m_pDC and m_hRC is my custom variable
call opengl function(reload the shader, assign, compile, attach and link)
wglMakeCurrent(NULL,NULL);
thanks for every warmhearted people
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement