OpenGL:INVALID_OPERATION下面的glEnableVertexAttribArray [英] OpenGL: INVALID_OPERATION following glEnableVertexAttribArray

查看:252
本文介绍了OpenGL:INVALID_OPERATION下面的glEnableVertexAttribArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个正常运行的OpenGL应用程序从Windows移植到OSX,并在调用 glEnableVertexAttribArray()后继续得到无效操作(代码1282)错误。这里是render方法:

I'm porting a functioning OpenGL app from Windows to OSX, and keep getting an "invalid operation" (code 1282) error after calling glEnableVertexAttribArray(). Here's the render method:

gl::Disable(gl::DEPTH_TEST);    
gl::Disable(gl::CULL_FACE);
gl::PolygonMode(gl::FRONT_AND_BACK,gl::FILL);

/// render full-screen quad
gl::UseProgram(m_program);

check_gl_error();

gl::BindBuffer(gl::ARRAY_BUFFER, m_vertexBuffer);
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, m_indexBuffer);

check_gl_error();
GLint positionLocation = -1;

positionLocation = gl::GetAttribLocation(m_program,"Position");
check_gl_error();

/// positionLocation now == 0

gl::EnableVertexAttribArray(positionLocation);
//// ************ ERROR RETURNED HERE **********************
//// ************ ERROR RETURNED HERE **********************
check_gl_error();

gl::VertexAttribPointer(positionLocation,3,gl::FLOAT,false,3 * sizeof(GLfloat),(const GLvoid*)0);
check_gl_error();

gl::DrawElements(gl::TRIANGLES,m_indexCount,gl::UNSIGNED_SHORT,0);

check_gl_error();

gl::BindBuffer(gl::ARRAY_BUFFER,0);
check_gl_error();

gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER,0);
check_gl_error();

check_gl_error()错误并返回其某种可读的描述。

check_gl_error() just gets the last GL error and returns a somewhat-readable description thereof.

此代码在Windows下正常工作。但是,当我快速学习,这并不一定意味着它是正确的。我验证了所有先前绑定的对象(程序,顶点缓冲区,索引缓冲区)是有效的句柄。 glGetAttribLocation() Position 属性返回有效位置(在本例中为0)。

This code works fine under Windows. But, as I'm rapidly learning, that doesn't necessarily mean that it is correct. I've verified that all of the previously-bound objects (program, vertex buffer, index buffer) are valid handles. glGetAttribLocation() returns a valid location (0 in this case) for the Position attribute.

glEnableVertexAttribArray()的失败情况是什么?是否有一些我之前没有设置的状态?

What are the failure cases for glEnableVertexAttribArray()? Is there some state that I've not set before this?

如果我注释绘制代码,窗口被清除为我的测试颜色(红色)在代码片段中未示出的方法),并且一切正常,这意味着其他一切正确的。

If I comment out the draw code, the window is cleared to my test color (red) (called from a method not shown in the code snippet) on every frame and everything else works fine, which implies that everything else is correct.

建议?

哦,对于GL状态机模拟器来说, em>它是一个无效操作。 (或参考一些神秘的,神奇的文档,描述每个gl *调用所需的输入状态。)

Oh, for a GL state machine simulator that would tell me why it is an "invalid operation." (Or a reference to some mystical, magical documentation that describes required input state for each gl* call.)

推荐答案

在OS X上看到这个错误,因为它只支持OpenGL核心配置文件,如果你使用OpenGL 3.x或更高版本。您的代码不符合Core Profile。您最有可能在Windows上使用兼容性配置文件。

You're seeing this error on OS X because it only supports the OpenGL Core Profile if you're using OpenGL 3.x or higher. Your code is not Core Profile compliant. You were most likely using the Compatibility Profile on Windows.

具体来说,Core Profile需要一个顶点数组对象(VAO)来绑定所有与顶点相关的调用。因此,在调用 glEnableVertexAttribArray()或其他类似的函数之前,您需要创建并绑定一个VAO:

Specifically, the Core Profile requires a Vertex Array Object (VAO) to be bound for all vertex related calls. So before calling glEnableVertexAttribArray(), or other similar functions, you will need to create and bind a VAO:

GLuint vaoId = 0;
glGenVertexArrays(1, &vaoId);
glBindVertexArray(vaoId);

如何找出错误条件:在这种情况下,它不是那么容易是。假设您使用GL3级别功能集。在理想的环境中,您可以访问 www.opengl.org ,拉下左上角附近的文档菜单,选择OpenGL 3.3参考页面,单击左侧窗格中的 glEnableVertexAttribArray ,并查看页面上的错误部分。然后您会看到... GL_INVALID_OPERATION 未列为可能的错误。

On how to find out the error conditions: In this case, it's not nearly as easy as it should be. Let's say you work with a GL3 level feature set. In an ideal world, you would go to www.opengl.org, pull down the "Documentation" menu close to the top-left corner, choose "OpenGL 3.3 Reference Pages", click on glEnableVertexAttribArray in the left pane, and look at the "Errors" section on the page. Then you see that... GL_INVALID_OPERATION is not listed as a possible error.

检查是否有什么更好的最新版本。您也这样做,但改为选择OpenGL 4参考页。

Next, you might want to check if there's anything better in the latest version. You do the same, but choose "OpenGL 4 Reference Pages" instead. The error condition is still not listed.

现在,你意识到,和许多人一样,这些手册页通常有错误。所以你去最终的来源:规格。这次您在文档菜单中选择OpenGL注册表。这将提供指向PDF格式的所有规范文档的链接。再次,让我们先尝试3.3。在文档中搜索EnableVertexAttribArray,但仍有没有 GL_INVALID_OPERATION 被记录为可能的错误。

By now you realize, like many before you, that these man pages are often faulty. So you go to the ultimate source: the specs. This time you choose "OpenGL Registry" in the Documentation menu. This gives you links to all the spec documents in PDF format. Again, let's try 3.3 first. Search for "EnableVertexAttribArray" in the document and there is... still no GL_INVALID_OPERATION documented as a possible error.

最后,检查最新的规范文档,这是4.4。再次寻找EnableVertexAttribArray,是时候了heureka:

Last resort, checking the very latest spec document, which is 4.4. Again looking for "EnableVertexAttribArray", it's time for a heureka:


如果没有顶点数组对象被绑定,会产生一个INVALID_OPERATION错误。 p>

An INVALID_OPERATION error is generated if no vertex array object is bound.

我确定错误也适用于GL3。虽然man页面不完整是很常见的,但是spec文档缺少的东西更加罕见。非常密切相关的 glVertexAttribPointer()调用已经在GL3中记录了此错误条件。

I'm quite certain that the error also applies to GL3. While it's reasonably common for the man pages to be incomplete, it's much rarer for the spec documents to be missing things. The very closely related glVertexAttribPointer() call has this error condition documented in GL3 already.

这篇关于OpenGL:INVALID_OPERATION下面的glEnableVertexAttribArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆