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

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

这篇文章是一个存根 。 你可以通过扩展来帮助OpenGL Wiki。

内容

[hide]

  • 1捕捉错误(困难的方式)

    • 1.1错误的含义
  • 2捕捉错误(简单的方法)
  • 3副作用
  • 4没有错误上下文

捕捉错误(困难的方式)

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

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

GLenum glGetError()

如果错误队列为空,它将返回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_MEMORY和GL_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.

This article is a stub. You can help the OpenGL Wiki by expanding it.

Contents

[hide]

  • 1Catching errors (the hard way)

    • 1.1Meaning of errors
  • 2Catching errors (the easy way)
  • 3Side effects
  • 4No error contexts

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_LARGE1, 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)

Main article: Debug Output

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 version 4.6
Core since version 4.6
ARB extension KHR_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.

OpenGL错误--Google搜索翻译相关推荐

  1. [乱七八糟]Google搜索使用详细

    1.GOOGLE简介 Google(www.google.com)是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年 9月发明,Google Inc. 于1 ...

  2. GOOGLE搜索秘籍

    将IE的默认搜索引擎改为GOOGLE 直接对下述注册表值进行修改即可. [HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/Main] &q ...

  3. GOOGLE搜索高级技巧大集合

    一,GOOGLE简介 Google(www.google.com)是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年9月发明,Google Inc. 于19 ...

  4. GOOGLE搜索从入门到精通v3.0 from:http://www.being.org.cn/tool/google.htm

    GOOGLE搜索从入门到精通v3.0 原文:http://www.lasg.ac.cn/docs/googlebook.html 作者:donquix 内容 1,前言 2,摘要 3,如何使用本文 4, ...

  5. [推荐]GOOGLE搜索从入门到精通v3.0

    作者:donquix (donquix@sina.com) ------------------------------ 内容 1,前言 2,摘要 3,如何使用本文 4,GOOGLE简介 5,搜索入门 ...

  6. GOOGLE搜索从入门到精通v3.0

    内容 1,前言 2,摘要 3,如何使用本文 4,GOOGLE简介 5,搜索入门 6,初阶搜索 6.1,搜索结果要求包含两个及两个以上关键字 6.2,搜索结果要求不包含某些特定信息 6.3,搜索结果至少 ...

  7. GOOGLE搜索秘籍完全公开

    一,GOOGLE简介Google(www.google.com)是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年9月发明,Google Inc. 于199 ...

  8. GOOGLE搜索攻略

    一.GOOGLE简介 Googlwww.google.com)是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年9月发明,Google Inc. 于1999 ...

  9. Google搜索秘技

    一,GOOGLE简介 Google(www.google.com) 是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年9月发明,Google Inc. 于1 ...

最新文章

  1. python timestamp转string_Python仿真区块链【含源码】
  2. 微型计算机启天A5000-B124说明,微型计算机原理及应用知识点总结
  3. 订单派送中多久能送到_美森卡派送到仓库后多久能上架呢?
  4. 计算机有关的文献检索题目,文献检索第二次计算机检索实习题目(2016.4.10).doc
  5. 虚拟器件—虚拟化技术的新利刃 | 时光机
  6. php 生产环境调错
  7. jquery for循环_前端基础入门五(掌握jQuery的常用api,实现动态效果)
  8. 步步为营-93-MVC+EF简单实例
  9. SQL case when then else end运用
  10. 开发一个Java项目的完整流程(附2600套Java项目源码+视频)
  11. HeadFirstJava——6_Java API
  12. Vs2010中文版 使用 .net 3.5 时,智能提示英文变中文
  13. nessus下载后更新插件问题新的解决方法2020
  14. mac移动硬盘未装载解决方案
  15. 维图PDMS切图软件
  16. 探秘手机距离传感器工作背后的那些事儿
  17. 1. 树莓派的基础配置
  18. TimestampType.nullSafeGet(203) - could not read column value from result set: xxx; An SQLExc
  19. SLE46C-40.K44P-M12单光速安全传感器
  20. Stata新命令-prodest:不再畏惧生产函数

热门文章

  1. Win7sp1 64位 部分软件和文档字体显示乱码2种解决方法
  2. 计算机电源端口接电容,全日系电容,用料扎实——安钛克NE650W金牌模组电源首发测评...
  3. elasticsearch 安装包百度云盘下载
  4. C#网站开发错误页面配置
  5. 用双重for循环做9*9乘法表
  6. Pnpm Workspace: 单仓库多项目(monorepo)
  7. 【智能物流】快递、云仓、新零售引领物流自动化千亿市场
  8. 2021语音识别领域最具商业合作价值企业盘点
  9. 使用GCM服务(Google Cloud Messaging)实现Android消息推送
  10. 判断两个变量的正负号不同