OpenGL“绑定"功能背后的概念 [英] Concept behind OpenGL's 'Bind' functions

查看:169
本文介绍了OpenGL“绑定"功能背后的概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从本教程中学习OpenGL. 我的问题是关于一般的规范,而不是关于特定的功能或主题. 当看到如下代码时:

I am learning OpenGL from this tutorial. My question is about the specification in general, not about a specific function or topic. When seeing code like the following:

glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

我对设置缓冲区数据前后调用绑定函数的实用程序感到困惑. 由于我对OpenGL和计算机图形学的一般经验不足,因此对我来说似乎是多余的.

I'm confused about the utility of calling the bind functions before and after setting the buffer data. It seems superfluous to me, due to my inexperience with OpenGL and Computer Graphics in general.

手册页上说:

glBindBuffer使您可以创建或使用命名的缓冲区对象.在目标设置为的情况下调用glBindBuffer GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER,GL_PIXEL_PACK_BUFFER或GL_PIXEL_UNPACK_BUFFER,并将缓冲区设置为 新缓冲区对象的名称将缓冲区对象名称绑定到目标.当缓冲区对象绑定到 目标,该目标的先前绑定会自动断开.

glBindBuffer lets you create or use a named buffer object. Calling glBindBuffer with target set to GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER or GL_PIXEL_UNPACK_BUFFER and buffer set to the name of the new buffer object binds the buffer object name to the target. When a buffer object is bound to a target, the previous binding for that target is automatically broken.

将某物绑定"到目标"的概念/效用到底是什么?

What exactly is the concept/utility of 'binding' something to a 'target' ?

推荐答案

opengl中的命令不是孤立存在的.他们假设存在上下文.想到这一点的一种方法是在后台隐藏一个opengl对象,而函数是该对象上的方法.

the commands in opengl don't exist in isolation. they assume the existence of a context. one way to think of this is that there is, hidden in the background, an opengl object, and the functions are methods on that object.

因此,当您调用函数时,它的作用取决于参数,当然也取决于opengl的内部状态-上下文/对象.

so when you call a function, what it does depends on the arguments, of course, but also on the internal state of opengl - on the context/object.

使用bind很清楚,它说将其设置为当前X".然后以后的函数将修改当前X"(例如,其中X可能是缓冲区). [更新:]就像您说的那样,要设置的对象(对象中的属性或数据成员")是要绑定的第一个参数.因此GL_ARRAY_BUFFER可以命名您要设置的特定内容.

this is very clear with bind, which says "set this as the current X". then later functions modify the "current X" (where X might be buffer, for example). [update:] and as you say, the thing that is being set (the attribute in the object, or the "data member") is the first argument to bind. so GL_ARRAY_BUFFER names a particular thing that you are setting.

并回答问题的第二部分-将其设置为0只会清除该值,因此您不会在其他地方意外更改.

and to answer the second part of the question - setting it to 0 simply clears the value so you don't accidentally make unplanned changes elsewhere.

这篇关于OpenGL“绑定"功能背后的概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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