C.5. State Changes and QueriesIn general, modern OpenGL graphics hardware performs optimally when processing an uninterrupted stream of geometry data. State changes interrupt this stream and cause delays in processing. In a worst-case scenario, applications make extensive state changes after every triangle, dramatically inhibiting performance. Avoid unnecessary state changes with the following tips:
Obviously, OpenGL implementations set state in the underlying graphics hardware, but they also keep a shadow copy of many state values in host RAM. Querying a state item stored in shadow state requires only a data copy and, therefore, is relatively inexpensive. glIsEnabled() is generally lightweight, because enable state is almost always shadowed in host RAM. Some OpenGL implementations keep a shadow copy of the top of the matrix stacks, so getting the matrix usually is as cheap as copying 16 GLfloats (or GLdoubles). Implementations don'tand shouldn'tshadow all state, however. For example, implementations optimally store texture maps generated from framebuffer data (using glCopyTexImage2D()) only in graphics hardware RAM. Querying OpenGL to retrieve such a texture map (using glGetTexImage()) requires a large data copy over the system bus. |