what is the drawing context (Rendering contexts)
Beginner OpenGL, open Red Book, will tell you that OpenGL is a state machine, OpenGL uses the client-server model, then felt good abstraction, until later understand the drawing context to connect these. We can assume that each hardware GPU is a server, each drawing context corresponds to a client of the request, a client maintains a set of state machines, and if two windows correspond to two different drawing contexts, two windows are independent of each other. Application drawing context, means the application of system resources, each drawing context still need a lot of resources, remember once tried in Chrome tab page constantly loading WebGL page, because WebGL uses OpenGL ES, also need to draw context, when loading more than 30 pages, Chrome is crashing all over.
All OpenGL calls need to specify the context in which the call is to be invoked. In different contexts, the same resource IDs may correspond to different types of resources in their respective contexts.
Different operating systems have their own drawing context to create, and the API to set the current drawing context.
How to create a drawing context
We usually do the demo program, will use glut, so many people may not have created the drawing context themselves. Glut's function Glutcreatewindow, in addition to creating a window, also creates a drawing context and sets the drawing context that is created to the current drawing context. For the Windows platform, you first create a device CONTEXT,DC, and with DC as input, you can create a drawing context. After creating the drawing context, call Makecurrent and set the created context to the current drawing context.
After creating the drawing context and setting it to the current context, you cannot use the latest OpenGL feature, and the API after calling OpenGL 1.1 will still crash. In general, we use the Glew library to call Glewinit () to get the function entry address of the new feature that OpenGL publishes with the graphics driver.
drawing contexts and Threads
Two threads makecurrent to the same drawing context at the same time can cause the program to crash. The general practice of a large program is to request a thread that is dedicated to drawing, requesting a drawing context for the drawing thread when the thread is created, and always as the current context. All drawing-related operations are done in the drawing thread.
resource sharing between contexts
One context per window, the advantage is that the state machine does not affect each other. However, multiple windows need to use the same texture, how to avoid duplicate resource requests? The answer is that a graphical resource between contexts can be shared, a context A is created first, and a is entered to create context B, and b accesses a texture resource created under a context. Resources such as textures, shader, and Buffer can be shared, but container objects such as Frame Buffer object (FBO), Vertex Array object (VAO) are not shareable, but shared textures and Vbo are bound to the container object of their context.
About the drawing context of OpenGL