GLSL - Must I Unload shaders on mode change?

Started by
1 comment, last by SuperVGA 11 years, 6 months ago
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!
Advertisement
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


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

This topic is closed to new replies.

Advertisement