OpenSceneGraph源码分析:OpenGL Object

11 篇文章 7 订阅
5 篇文章 2 订阅

一、OpenGL Object

OpenGL Object(以下简称GLObject)可以看作是顶点数据纹理数据帧缓存着色器OpenGL状态容器,通过将OpenGL相关状态值事先存放到GLObject中,可以减少相关状态设置函数的调用次数,方便了用户控制OpenGL渲染管线。

GLObject使用比较简单:GLObject第一绑定绑定到Graphics Context之后,调用相关API来设置GLObject状态值;后续仅需要将GLObject绑定到Graphics Context,便自动地将GLObject状态值替换Graphics Context相关状态值,。

Ref. from OpenGL Object =====================================================

An OpenGL Object is an OpenGL construct that contains some state. When they are bound to the context, the state that they contain is mapped into the context's state. Thus, changes to context state will be stored in this object, and functions that act on this context state will use the state stored in the object.

OpenGL is defined as a "state machine". The various API calls change the OpenGL state, query some part of that state, or cause OpenGL to use its current state to render something.

Objects are always containers for state. Each particular kind of object is defined by the particular state that it contains. An OpenGL object is a way to encapsulate a particular group of state and change all of it in one function call.

The functions to generate object names are of the form glGen*, where * is the object's type in plural form. All functions of this type have the same signature:

void glGen*(GLsizei n​, GLuint *objects​);

Because objects in OpenGL are defined as a collections of state, to modify objects, you must first bind them to the OpenGL context. Binding objects to the context causes the state in them to be set to be the current context's state. This means that any functions that change the state governed by that object will simply change the state within the object, thus preserving that state.

Binding a newly generated object name will create new state for that object. In some cases, the target to which it is first bound (see below) will affect properties of the newly created state for the object.

Different objects have different binding functions. They do share a naming convention and general parameters:

void glBind*(GLenum target​, GLuint object​);

Once you are finished with an object, you should delete it. The functions for this are of the form glDelete*, using the same object type as before. These functions have this signature:

void glDelete*(GLsizei n​, const GLuint *objects​);

===================================================== Ref. from OpenGL Object

1.1 Buffer Object

Buffer Object(以下简称BO)是在显卡上分配的一块存储区域,可用于存储定点数据、像素数据等。

Buffer Objects are OpenGL Objects that store an array of unformatted memory allocated by the OpenGL context (AKA the GPU). These can be used to store vertex datapixel data retrieved from images or the framebuffer, and a variety of other things.

To create a buffer object, you call glGenBuffers. Deleting them uses glDeleteBuffers

To set up its internal state, you must bind it to the context. You do this using the following API:

 void glBindBuffer(enum target, uint bufferName)

Buffer objects hold a linear array of memory of arbitrary size. This memory must be allocated before it can be uploaded to or used. There are two ways to allocate storage for buffer objects: mutable or immutable. 

参考资料

OpenGL Wikihttps://www.khronos.org/opengl/wiki

OpenGL Objecticon-default.png?t=M4ADhttp:// https://www.khronos.org/opengl/wiki/OpenGL_Object

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值