学习opengles函数之间的认识
程序运行时候,最开始时建立环境。细看之下,无非是一些相互关联。
四个关键的概念:layer, context, framebuffer, renderbuffer.
将context和layer关联:
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
将framebuffer和renderbuffer关联:
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
将context和rendererbuffer关联:
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
=============================
现在不明白framebuffer和rendererbuffer是什么,怎么用?
官方文档:
A renderbuffer object is a 2D image buffer allocated by the application. The renderbuffer can be used to allocate and store color, depth, or stencil values and can be used as a color, depth, or stencil attachment in a framebuffer object. A renderbuffer is similar to an off-screen window system provided drawable surface, such as a pbuffer. A renderbuffer, however, cannot be directly used as a GL texture.
A framebuffer object (often referred to as an FBO) is a collection of color, depth, and stencil buffer attachment points; state that describes properties such as the size and format of the color, depth, and stencil buffers attached to the FBO; and the names of the texture and renderbuffer objects attached to the FBO. Various 2D images can be attached to the color attachment point in the framebuffer object. These include a renderbuffer object that stores color values, a mip-level of a 2D texture or a cubemap face, or even a mip-level of a 2D slice in a 3D texture. Similarly, various 2D images contain- ing depth values can be attached to the depth attachment point of an FBO. These can include a renderbuffer, a mip-level of a 2D texture or a cubemap face that stores depth values. The only 2D image that can be attached to the stencil attachment point of an FBO is a renderbuffer object that stores stencil values.
英语不好的蒙了吧:(勤学英语)
renderbuffer对象是由程序申请的2D图像缓冲区。 renderbuffer可用于分配和存储颜色,深浅度或模板,并可用作帧缓冲对象中的颜色,深度或模版。 renderbuffer类似于提供可绘制表面的离屏窗口系统。然而,renderbuffer不能直接用作GL纹理。(buffer分为frame buffer和render buffer两大类,其中frame buffer相当于render buffer的管理者,frame buffer object即称为FBO,常用于做离屏渲染缓冲等。render buffer则又可分为三类,color buffer / depth buffer / stencil buffer。纹理和renderbuffer对象都是作用在frame buffer上的)
(frame buffer object)帧缓冲对象(通常称为FBO)是颜色,深度和模板缓冲区附件点的集合;描述属性的状态,例如:加到FBO的颜色,深度和模板缓冲区的大小和格式;以及加到FBO的纹理和renderbuffer对象。可以将各种2D图像加到帧缓冲器对象中的颜色附着点。这些包括存储颜色值的renderbuffer对象,2D纹理的mip级别或立方体贴图面,或甚至3D纹理中的2D切片的mip级别。类似地,包含深度值的各种2D图像可以加到FBO的深度附着点。这些可以包括renderbuffer,二维纹理的mip级别或存储深度值的立方体面。可以加到FBO的模板附件点的唯一2D图像是存储模板值的renderbuffer对象。
相关的一些使用
1. 生成frame buffer object的API函数:
glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
生成render buffer的API函数,render buffer的生成函数是一样的,buffer句柄类型只有在进行分配buffer空间的时候才会确定:glGenRenderbuffers(1, &renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
2. frame buffer仅仅是管理者,不需要分配空间;render buffer的存储空间的分配,对于不同的render buffer,使用不同的API进行分配,而只有分配空间的时候,render buffer句柄才确定其类型
(1). 最基本的是color buffer,调用EGALContext的OC方法为其分配空间
/* Attaches an EAGLDrawable as storage for the OpenGL ES renderbuffer object bound to*/
- (BOOL)renderbufferStorage:(NSUInteger)target fromDrawable:(id)drawable;
(2). 而depth buffer则可以直接调用openGL本身的API进行分配
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16, width, height);
2. 上面(1)(2)函数是用于生成render buffer的存储空间,生成空间之后,则需要将renderbuffer跟framebuffer进行绑定,调用glFramebufferRenderbuffer函数进行绑定,后面的绘制才能起作用
3. 接下来可以调用OpenGL的函数进行绘制处理,最后则需要调用EGALContext的OC方法进行最终的渲染绘制,这里渲染的是color buffer,这个方法会讲buffer渲染到CALayer上面
- (BOOL)presentRenderbuffer:(NSUInteger)target;
4. 还有一个需要注意的地方是在退出的时候,需要调用glDelegateFramebuffers或者glDeleteRenderbuffers函数删除frame
buffer或者render buffer
学习过程中做的笔记有什么不对的,或者理解不到位的地方希望大家指教,我们共同进步。
网友评论