When Should One Call glGetError?

后端 未结 3 1028
南方客
南方客 2021-02-01 22:41

glLoadIdentity says

GL_INVALID_OPERATION is generated if glLoadIdentity is executed between the execution of glBegin<

3条回答
  •  余生分开走
    2021-02-01 23:03

    Some philosophies of coding expect every program to check for every possible error, and appropriately handle those errors. Yet, following one of those philosophies requires a lot of extra code, and can significantly slow a program. In practice, I only use glGetError when I'm diagnosing a problem, or write some code that has a significant possibility of failing and an appropriate action after the error.

    In the first case, diagnosing a problem, I use one of two strategies. Because OpenGL doesn't record new errors until glGetError is called, I can either check for errors once each time through my main loop. That tells me the first error, which I then track down, and hopefully fix. The other strategy I use when I've narrowed down to some problematical code, but I'm not sure which call is causing the problem. After each gl... call outside a glBegin . . . glEnd block I'll call glGetError, and report any errors. This will tell me exactly which gl... call is causing the problem, and hopefully start me on the path to a fix.

    In the second case, defensively programming for a likely error, I'll call glGetError to clear the error flag, make my other gl... call(s), then call glGetError. Then I take whatever action is required to deal with whatever glGetError reports.

提交回复
热议问题