aCuria
aCuria

Reputation: 7205

What must be done after the OpenGL context is lost?

What is a good way to think about this? Are handles lost?

glCreateProgram()? glCreateShader()? glGenTextures()? glGenBuffers()?

Im wondering if I am doing what's necessary (or doing too much and leaking memory)

Upvotes: 1

Views: 1170

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473467

How do you lose a context? The OpenGL context will exist until you destroy it (or the window/HDC).

However, all OpenGL objects are bound to the context(s) that they are created in. If you destroy the context, all objects are destroyed as well (unless you have shared objects with another context. In which case, only the sharable objects will remain). So you must reload them.

For example, do I call all 3 function calls: glCreateProgram() glAttachShader() glLinkProgram() or just the last two?

If the OpenGL context is destroyed, you must call whatever OpenGL functions you need to recreate your objects. Any OpenGL objects that you got from the old context are gone. They are invalid. They are deleted pointers, and using deleted pointers is always wrong.

A new OpenGL context is new. So you must create your objects as though it were a new context. Because it is.

Upvotes: 5

Related Questions