Reputation: 93
Say, my application has a 3D window rendering a tin model of millions of triangles using OpenGL.
Goal: For some operations of users, there is no need to update the 3D window. The 3D view can just stay idle with previously rendered content, without repeatly calulate the rotation/translation/scaling/texture things. I assume this will save lots of CPU and GPU time.
Current design: I have a rendering while loop running all the time. If I stop the while loop, then the content is rendered once and disappear.
Question: is there a way to achieve the goal? Can anyone give a direction?
Upvotes: 3
Views: 371
Reputation: 72469
Instead of rendering in your event loop, like many OpenGL tutorials teach you, you can use OpenGL to render in response to the system's draw event. You can also invalidate your own window if you know that the contents of it changed (e.g. due to a mouse click). In fact this is the proper way to draw in your window for anything other than latency sensitive applications.
The specifics depend on the API you are using to create your window. For example,
WM_PAINT
and invalidate with InvalidateRect
.Expose
and invalidate by sending an Expose
event with XSendEvent
.QOpenGLWindow::paintGL
and invalidate with update()
.glutDisplayFunc
and invalidate with glutPostRedisplay
.... and so on. This is not OpenGL specific in any way.
Upvotes: 4