Sign in to follow this  
iishan

how to reload the glsl shader?

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.
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. ;)


Share this post


Link to post
Share on other sites
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()

Share this post


Link to post
Share on other sites
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()


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this