Jump to content
  • Advertisement
Sign in to follow this  
iishan

how to reload the glsl shader?

This topic is 3642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
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
Quote:
but it does not work.


Are you checking for errors? Post a small project so that people can test.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!