Jump to content

  • Log In with Google      Sign In   
  • Create Account

GLSL - Must I Unload shaders on mode change?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 SuperVGA   Members   -  Reputation: 1118

Like
0Likes
Like

Posted 13 October 2012 - 04:25 PM

Hi guys!

I'm making great progress at my homemade editor GUI, which should use shaders for skinning.

I'm here because I suffer from bad conscience: I kindly delete my shaders and linked glsl programs with
glDeleteShader() and glDeleteProgram() respectively, as the program replaces an existing shader.
I'm satisfied with that bit; I like cleaning up after myself, and I should do so whenever I can.

Now, the gl names (1, 2, 3 ...) of the shaders and programs are invalidated on a mode change, because I basically initialize OpenGL and Glee all over again, and although calling glDeleteProgram() afterwards (when i know of the mode change) seems logical, glError will
notify me that the names are all wrong; there's nothing such as 1, 2 and 3 in the current gl context(state).

Should I feel bad for not having a display mode change -sequence that
1: Starts when the user toggles fullscreen
2: halts rendering and raises an unload flag
3: Traverses & iterates across all my reloadable objects and unloads them from the GPU.
4: Restarts OpenGL in the desired mode
5: Traverses & iterates the mentioned objects again, this time reloading them to the GPU.

Or rather; will any state of the art GPU handle these things for me, so I can disregard a sequence such as the above?
Thanks in advance guys!

Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 14232

Like
2Likes
Like

Posted 13 October 2012 - 04:34 PM

What do you mean by “restarting” OpenGL?
Why do you need to “flush” your shaders?

OpenGL is not like DirectX 9. The contexts are not lost just because the device switches to full-screen mode etc. There is generally no reason to reset all the objects under an OpenGL context unless you are developing for Android.


Deleting shaders and cleaning up after yourself is always a good thing, but what do you mean by “as the program replaces an existing shader”?
How does a shader get “replaced”? If this happens frequently and at run-time, you may need to rethink your design. If it happens between game states, this is normal.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 SuperVGA   Members   -  Reputation: 1118

Like
0Likes
Like

Posted 13 October 2012 - 04:50 PM

What do you mean by “restarting” OpenGL?

Ah, I knew that wording would come back and bite me, but it's just the glut and glee initialization, as well as glutGamemode and the setting of the gl callbacks.

Why do you need to “flush” your shaders?

I know that the program loses its references (at least, the gl names don't exist no more) to the video ram when "resetting" as described above,
so I thought I wanted to wipe them before doing so, and then reestablish them afterwards.

How does a shader get “replaced”?

if( vs != 0 ) { glDeleteShader(vs); vs = 0; }
if( fs != 0 ) { glDeleteShader(fs); fs = 0; }
vs = utility::shaders::create_glsl_shader(GL_VERTEX_SHADER, "shader_vtx.txt");
fs = utility::shaders::create_glsl_shader(GL_FRAGMENT_SHADER, "shader_frag.txt");

if( shader_program != 0 ) { glDeleteProgram(shader_program); shader_program = 0; }
shader_program = glCreateProgram();

If this happens frequently and at run-time...

You're right. It's a remainder from when changing the size of a window meant reload some places, but lately it started meaning reshape instead.
The reloading bit doesn't really happen so often, I just like spending much more time making things tidy than making things.

It's nice of you to relieve me of my paranoid memory management fears in relation to shaders. -Thanks! :D

Edited by SuperVGA, 13 October 2012 - 04:52 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS