OpenGL错误--Google搜索翻译

如果函数调用的参数与OpenGL允许的参数集不匹配,或者与上下文中已经设置的状态没有合理交互,则会导致OpenGL错误 。 错误显示为错误代码。

对于大多数OpenGL错误和大多数OpenGL函数,发出错误的函数将不起作用。 没有OpenGL状态将被改变,不会启动渲染。 这就好像该功能尚未被调用。 一些情况并非如此。

捕捉错误(困难的方式)

OpenGL错误存储在队列中,直到实际处理错误。 因此,如果您不定期测试错误,则不会知道哪个函数调用会引发特定的错误。 因此,如果您需要知道错误来自何处,应定期进行错误测试。

要获取队列中的下一个错误(并将其从队列中移除),请调用此函数:

如果错误队列为空,它将返回GL_NO_ERROR 。 否则,它将返回下面的错误枚举器之一,并从队列中删除该错误。 因此,要获取当前队列中的所有错误,您需要循环。

V · E

一个简单的循环来提取当前的OpenGL错误:

 格林厄尔 错误 ;
 while (( err = glGetError ()) != GL_NO_ERROR 
 {
   //处理/记录错误。
 }


错误的含义

glGetError函数返回以下错误代码之一,如果没有(更多)错误可用,则返回GL_NO_ERROR 。 每个错误代码表示一类用户错误。

GL_INVALID_ENUM ,0x0500
给定一个枚举参数不是该函数的合法枚举。  这只是为了解决当地的问题。  如果规范允许枚举某些情况下,其他参数或状态决定这些情况,那么GL_INVALID_OPERATION就是结果。
GL_INVALID_VALUE ,0x0501
在给定值参数不是该函数的合法值时。  这只适用于当地的问题;  如果规范允许某些情况下的值,其他参数或状态指定这些情况,则GL_INVALID_OPERATION是结果。
GL_INVALID_OPERATION ,0x0502
给定一个命令的状态集合对于给定该命令的参数不合法。  它也给出了参数组合定义什么是合法参数的命令。
GL_STACK_OVERFLOW ,0x0503
鉴于堆栈推送操作无法完成,因为它会溢出堆栈大小的限制。
GL_STACK_UNDERFLOW ,0x0504
给定堆栈弹出操作无法完成时,因为堆栈已经处于最低点。
GL_OUT_OF_MEMORY ,0x0505
在执行可以分配内存的操作时给出,并且不能分配内存。  返回这个错误的OpenGL函数的结果是未定义的;  部分操作可以发生。
GL_INVALID_FRAMEBUFFER_OPERATION ,0x0506
在做任何尝试从不完整的帧缓冲区读取或写入/渲染的任何情况下。
GL_CONTEXT_LOST ,0x0507(使用OpenGL 4.5 或 ARB_KHR_robustness )
鉴于如果OpenGL上下文已经丢失,由于显卡重置。
GL_TABLE_TOO_LARGE 1,0x8031
ARB_imaging扩展的一部分。

1 :这些错误代码在3.0中被弃用 ,并在3.1 核心及以上版本中被删除。

OpenGL参考文档中,大多数错误都被明确列出。 但是,几乎所有的OpenGL函数都可以生成GL_OUT_OF_MEMORYGL_CONTEXT_LOST 。 并且可以根据与该特定函数调用不直接关联的原因生成它们。

捕捉错误(简单的方法)

调试输出功能为您的应用程序提供了一种简单的方法,以便在驱动程序中发生OpenGL错误(或其他有趣的事件)时通过应用程序定义的消息回调函数进行通知。 只需启用调试输出,注册回调,然后等待用DEBUG_TYPE_ERROR消息调用它。

此方法避免了在应用程序周围花费昂贵且代码混淆的glGetError()调用来捕获和本地化OpenGL错误的原因(并且需要将它们有条件地编译为调试版本以避免优化版本中的性能问题)。 该功能甚至可以确保消息回调函数在触发GL错误(或性能警告)的GL调用的相同线程和调用堆栈中被调用。

V · E

显示如何利用调试消息回调(例如,用于检测OpenGL错误)的简单示例:

 void MessageCallback  GLenum source 
                       GLenum 类型 
                       GLuint ID 
                       格林尼姆 严重性 
                       GLsizei 长度 
                       const GLchar * 消息 
                       const void * userParam 
 {
   fprintf  stderr  “GL CALLBACK:%s type = 0x%x,severity = 0x%x,message =%s \ n  
             键入 == GL_DEBUG_TYPE_ERROR  “** GL ERROR **”  “” ),
             类型  严重性  消息 );
 }

 //在init期间,启用调试输出
 glEnable  GL_DEBUG_OUTPUT );
 glDebugMessageCallback   GLDEBUGPROC  MessageCallback  0 );


副作用

在大多数情况下,生成错误的函数将会退出,而不会更改任何OpenGL状态或启动任何OpenGL操作。 它们不会修改用户传递给这些函数的任何客户端内存(即:指针参数)。 在这样的错误下,返回值为零或者同样无害。 但是,在某些情况下会发生错误,并修改OpenGL状态。

每当生成GL_OUT_OF_MEMORY错误时,OpenGL上下文和/或对象的状态都是未定义的 。

在OpenGL上下文丢失后,任何命令都会生成GL_CONTEXT_LOST错误(要求OpenGL 4.5 或 ARB_KHR_robustness )。 这些命令没有副作用,对于可能阻塞CPU的函数,有一些特殊情况例外。

多重绑定函数函数具有不同寻常的错误属性。 由于它们聚合了一次绑定多个对象的能力,如果一个对象的绑定失败并出现错误,则其他对象将按正常绑定。 只有错误的物体才会失败。 请注意,没有办法检测哪些对象无法绑定(除了查询每个绑定点的上下文)。

没有错误上下文

V · E
没有错误上下文
   
核心版本4.6
核心版本4.6
ARB扩展KHR_no_error

可以创建不报告OpenGL错误OpenGL上下文 。 如果上下文位GL_CONTEXT_FLAG_NO_ERROR_BIT设置为true,那么上下文不会报告大多数错误。 在适当的情况下,它仍会报告GL_OUT_OF_MEMORY_ERROR ,但这可能会延迟到实际发生错误的时间点。 没有其他错误会被报告。

这也意味着实现也不会检查错误。 所以如果你给一个会引发错误的函数提供不正确的参数,你会得到未定义的行为。包括应用程序终止的可能性。

上下文不能有无错误位健壮性或调试位。



以下是原文:

If the parameters of a function call do not match the set of parameters allowed by OpenGL, or do not interact reasonably with state that is already set in the context, then an OpenGL Error will result. The errors are presented as an error code.

For most OpenGL errors, and for most OpenGL functions, a function that emits an error will have no effect. No OpenGL state will be changed, no rendering will be initiated. It will be as if the function had not been called. There are a few cases where this is not the case.

Catching errors (the hard way)

OpenGL errors are stored in a queue until the error is actually handled. Therefore, if you do not regularly test for errors, you will not know necessarily which function call elicited a particular error. As such, error testing should be done regularly if you need to know where an error came from.

To fetch the next error in the queue (and to remove it from the queue), call this function:

GLenum  glGetError()

If the error queue is empty, it will return GL_NO_ERROR. Otherwise, it will return one of the error enumerators below and remove that error from the queue. So to fetch all of the errors currently in the queue, you would need to loop.

V · E

A simple loop to extract the current OpenGL errors:

GLenum err;
while((err = glGetError()) != GL_NO_ERROR)
{
  // Process/log the error.
}


Meaning of errors

The glGetError function returns one of the following error codes, or GL_NO_ERROR if no (more) errors are available. Each error code represents a category of user error.

GL_INVALID_ENUM, 0x0500
Given when an enumeration parameter is not a legal enumeration for that function. This is given only for local problems; if the spec allows the enumeration in certain circumstances, where other parameters or state dictate those circumstances, then  GL_INVALID_OPERATION is the result instead.
GL_INVALID_VALUE, 0x0501
Given when a value parameter is not a legal value for that function. This is only given for local problems; if the spec allows the value in certain circumstances, where other parameters or state dictate those circumstances, then GL_INVALID_OPERATION is the result instead.
GL_INVALID_OPERATION, 0x0502
Given when the set of state for a command is not legal for the parameters given to that command. It is also given for commands where combinations of parameters define what the legal parameters are.
GL_STACK_OVERFLOW, 0x0503
Given when a stack pushing operation cannot be done because it would overflow the limit of that stack's size.
GL_STACK_UNDERFLOW, 0x0504
Given when a stack popping operation cannot be done because the stack is already at its lowest point.
GL_OUT_OF_MEMORY, 0x0505
Given when performing an operation that can allocate memory, and the memory cannot be allocated. The results of OpenGL functions that return this error are undefined; it is allowable for partial operations to happen.
GL_INVALID_FRAMEBUFFER_OPERATION, 0x0506
Given when doing anything that would attempt to read from or write/render to a framebuffer that is  not complete.
GL_CONTEXT_LOST, 0x0507 (with OpenGL 4.5 or  ARB_KHR_robustness)
Given if the OpenGL context has been lost, due to a graphics card reset.
GL_TABLE_TOO_LARGE 1, 0x8031
Part of the  ARB_imaging extension.

1: These error codes are deprecated in 3.0 and removed in 3.1 core and above.

In the OpenGL Reference documentation, most errors are listed explicitly. However, GL_OUT_OF_MEMORY and GL_CONTEXT_LOST could be generated by virtually any OpenGL function. And they can be generated for reasons not directly associated with that particular function call.

Catching errors (the easy way)

The debug output feature provides a simple method for your application to be notified via an application-defined message callback function when an OpenGL error (or other interesting event) occurs within the driver. Simply enable debug output, register a callback, and wait for it to be called with a DEBUG_TYPE_ERROR message.

This method avoids the need to sprinkle expensive and code-obfuscating glGetError() calls around your application to catch and localize the causes of OpenGL errors (and the need to conditionally compile them into debug builds to avoid the performance hit in optimized builds). The feature can even ensure that message callback functions are invoked on the same thread and within the very same call stack as the GL call that triggered the GL error (or performance warning).

V · E

A simple example showing how to utilize debug message callbacks (e.g. for detecting OpenGL errors):

void MessageCallback( GLenum source,
                      GLenum type,
                      GLuint id,
                      GLenum severity,
                      GLsizei length,
                      const GLchar* message,
                      const void* userParam )
{
  fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
           ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
            type, severity, message );
}

// During init, enable debug output
glEnable              ( GL_DEBUG_OUTPUT );
glDebugMessageCallback( (GLDEBUGPROC) MessageCallback, 0 );


Side effects

Under most circumstances, a function that generates an error will exit without changing any OpenGL state or initiating any OpenGL operations. They will not modify any client memory passed into those functions by the user (ie: pointer arguments). Under such errors, return values are zero or something equally innocuous. However, there are certain circumstances were an error happens and OpenGL state is modified.

Whenever the GL_OUT_OF_MEMORY error is generated, the state of the OpenGL context and/or objects is undefined.

The GL_CONTEXT_LOST error is generated (which requires OpenGL 4.5 or ARB_KHR_robustness) by any commands after the OpenGL context was lost. Those commands have no side effects, with a few special-case exceptions for functions that can block the CPU.

The multi-bind functions functions have unusual error properties. Because they aggregate the ability to bind multiple objects at once, if the binding of one object fails with an error, the others will be bound as normal. Only the erronous objects will fail to bind. Note that there is no way to detect which objects failed to bind (other than querying the context for each binding point).

No error contexts

V · E
No Error Context
   
Core in version4.6
Core since version4.6
ARB extensionKHR_no_error

An OpenGL Context can be created which does not report OpenGL Errors. If the context bit GL_CONTEXT_FLAG_NO_ERROR_BIT is set to true, then the context will not report most errors. It will still report GL_OUT_OF_MEMORY_ERROR where appropriate, but this can be delayed from the point where the error actually happens. No other errors will be reported.

This also means that the implementation will not check for errors either. So if you provide incorrect parameters to a function that would have provoked an error, you will get undefined behavior instead. This includes the possibility of application termination.

Contexts cannot have the no error bit and the robustsness or debug bits.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值