首页/文章/ 详情

OpenSceneGraph源码分析:OpenGL Object

2年前浏览2644

一、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 data, pixel 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 Wiki

https://www.khronos.org/opengl/wiki

OpenGL Object

http:// https://www.khronos.org/opengl/wiki/OpenGL_Object

————————————————



科普理论通用ECADMCAD其他软件
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2022-05-24
最近编辑:2年前
YouQuan Soft
硕士 济南友泉软件有限公司
获赞 30粉丝 7文章 12课程 0
点赞
收藏
未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈