Does opengl render objects that are not in view?
For example if I draw a cube and turn my character around so as to face away from the cube does it use C开发者_运维问答PU/gpu processing to draw it even though it is not on screen? Do I as a programmer need to be smart enough to not make opengl draw calls if an object is not on screen or very far away?
It doesn't render them as such, but it does use resources which I believe is what you're asking. Yes, you do.
You're probably after frustum culling:
- http://www.flipcode.com/archives/Frustum_Culling.shtml
- http://cgvr.cs.uni-bremen.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/
- https://en.wikipedia.org/wiki/Hidden_surface_determination#Viewing_frustum_culling
Yes. All vertex data sent to OpenGL will consume resources, regardless of whether or not the corresponding geometry is in view. As suggested above, frustum culling is an optimization that identifies objects that will not be in the view volume and ignores/culls its vertex data. Thus, if the vertex data is never submitted to the GPU, then it will never be processed by the GPU.
You can enable the 'scissor test' to clip drawing against the scissor rectangle.
That said, this doesn't stop all the rest of your drawing code from running - so unless your scene is quite simple you usually want to look into more complex methods.
Octrees and BSP trees are a good place to start.
Yeah, GL does discard pixels which are out of view, but that still consumes resources, since it's per-pixel. Skipping the draw calls of non-visible primitives is a much better approach.
精彩评论