opengl es shader有单缓冲吗

7被浏览303分享邀请回答06 条评论分享收藏感谢收起求教opengl es2.0 中framebufferobject的一些生成机制_百度知道
求教opengl es2.0 中framebufferobject的一些生成机制
我有更好的答案
让它成为当前渲染缓冲:
glBindRenderBufferEXT(GL_RENDERBUFFER_EXT,height)帧缓冲区对象呢又称为FBO,它允许我们把渲染从窗口的帧缓冲区转移到我们所创建的一个或者多个离屏帧缓冲区。被推荐用于数据渲染到纹理对象,
启动FBO -&
对FBO绘图 -&
将FBO当成贴图
生成一个对象,并取得一个有效的对象标识
生成一个普通的RGBA图像,大小是w*h,返回GL_FRAMEBUFFER_COMPLETE_EXT 就是指FBO准备好了 .纹理可以连接到FBO,允许直接渲染到纹理,不需要显示glCopyTexImage。3.FBO可以包含许多颜色缓冲区,这里使用了GL_DEPTH_COMPONENT,GL_COLOR_ATTACHMENTO_EXT,GL_TEXTURE_2D,img,0):
glRenderBufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT;生成一个renderbuffer后;
glGenTexture(1,&img);
glBindTexture(GL_TEXTURE_2D,img).FBO并不受窗口大小的限制, 与前面生成的渲染缓冲区的大小是一样,FBO中要求所绑定的对象有相同的高度与宽度,这时候没有数据
生成纹理之后,把这个纹理与FBO绑定在一起:除了创建新的FBO外,glBindFrameBufferEXT()也用于在FBO之间进行切换,绑定到名称0将会解除当前绑定的FBO,以便把数据渲染到纹理空间中去
glFramebufferTexture2Dext(GL_FRAMEBUFFER_EXT,如数据拷贝或者交换缓冲区等等,使用FBO技术会更高效且易于实现,使用它之前要检查GL_EXT_frmaebuffer_object扩展FBO是一个图像容器,停止FBO输出很重要,我们完成FBO的工作就要停止FBO,让图像可以再屏幕上正确输出,glBindFrameBufferEXT(GL_FRAMEBUFFER_EXT,fbname);glPushAttrib(GL_VIEWPORT_BIT);glViewPort(0,0,,wight,height);//render as normal here//output goes to the FBO and it's attached buffersglPopAttrib();glBindFrameBufferEXT(GL_FRAMEBUFFER_EXT,0);面另外三行代码glPushAttrib/glPopAttrib 及 glViewport,是用来确保在你跳出FBO渲染的时候可以返回原正常的渲染路径。glViewport在这里的调用是十分必要的,我们不要常试把数据渲染到一个大于或小于FBO大小的区域。 函数glPushAtrrib 和 glPopAttrib 是用来快速保存视口信息。这一步也是必要的,因为FBO会共享主上下文的所有信息。任何的变动,都会同时影响到FBO及主上下文,当然也就会直接影响到你的正常屏幕渲染。这里一个重要信息,你可能也注意到了,我们只是在绘制的时候绑定或解除FBO,但是我们没有重新绑定纹理或渲染缓冲区,这里因为在FBO中会一直保存了这种绑定关系,除非你要把它们分开或FBO对像被销毁了。使用已渲染出来的纹理:来到这里,我们已经把屏幕的数据渲染到了一个图像纹理上。现在我们来看一看如何来使用这张已经渲染好了的图像纹理。这个操作的本身其实是很简单的,我们只要把这张图像纹理当作普通纹理一样,绑定为当前纹理就可以了。glBindTexture(GL_TEXTURE_2D, img);以上这一函数调用完成之后,这张图像纹理就成了一个在绘图的时候用于被读取的普通纹理。根据你在初始化时所指定的不同纹理滤波方式,你也许会希望为该纹理生成多重映像(mipmap)信息。如果要建立多重映像信息,多数的人都是在上传纹理数据的时候,通过调用函数gluBuild2DMipmaps()来实现,当然有些朋友可能会知道如何使用自动生成多重映像的扩展,但是在FBO扩展中,我们增加了第三种生成映像的方法,也就是使用GenerateMipmapEXT()函数。这个函数的作用就是让OpenGL帮你自动创建多重映像信息。中间实现的过程,根据不同的显卡会有所不同,我们只关心它们最终的结果是一样就行了。值得注意的是:对于这种通过FBO渲染出来的纹理,要实现多重映像的话,只有这一种方法是正确的,这里你不可以使用自动生成函数来生成多重映像,这其中的原因有很多,如果你想深入了解的话,可以查看一下技术文档。使用这一函数使方便,你所要做的就是先把该纹理对像绑定为当前纹理,然后调用一次该函数就可以了。glGenerateMipmapEXT(GL_TEXTURE_2D);OpenGL将会自动为我们生成所需要的全部信息,到现在我们的纹理便可以正常使用了。一个重点要注意的地方:如果你打算使用多重映像(如 GL_LINEAR_MIPMAP_LINEAR),该函数glGenerateMipmapEXT()必须要在执行渲染到纹理之前调用。在创建纹理的时候,我们可以按以下代码来做。glGenTextures(1, &img);glBindTexture(GL_TEXTURE_2D, img);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);glGenerateMipmapEXT(GL_TEXTURE_2D);到现在,这张纹理和普通纹理没什么区别,我们就按处理普通纹理的方法来使用就可以了。删除FBO:glDeleteFrameBufferEXT(1,&fboname);同样的,你如果分配了渲染缓冲对像,也别忘了要把它清理掉。本实例中我们分配的是深度缓存渲染对像,我们用以下函数来清除它:glDeleteRenderbuffersEXT(1, &depthbuffer);。2。此buffer包含了color buffer,depth buffer,最后一个参数指定级为0; 启动原来的Frame Buffer -&gt:
glGenRenderBuffersEXT(1;
glGenFrameBuffersEXT(1,&fboname);对FBO进行任何操作都需要首先绑定它,GL_DEPTH_ATTACHMENT_EXT等等加入用于渲染的纹理:
到现在为止,还没有办法往FBO写入颜色信息,有两种方法实现:
把一个颜色渲染缓冲与FBO绑定或者把一个纹理与FBO绑定,要想把纹理与FBO绑定,我们首先要生成这个纹理:
GL 渲染到纹理:
当我们要把数据渲染并输出到FBO时,我们就调用glBindFrameBufferEXT();当我们要停止输出FBO,把参数设置成0即可,当然;即,我们需要把它与一些可被渲染的缓冲区绑定在一起,这样的缓冲区可以是纹理texture,其实它就是一个用来支持离屏渲染的缓冲区:
把FBO与目标绑定,stencil buffer.渲染到纹理这个技术在游戏中经常用来模拟电视机或者监视器等等的效果。1,常见的模板缓冲和深度缓冲就是这样一类对象,我们要为FBO指定一个dephtbuffer,是指我们的空间用来保存深度值,除此之外还可以用来保存普通的GL_RGB&#47,整型变量fboname用来保存FBO对象标识
glBindFrameBufferEXT(GL_FRAMEBUFFER_EXT,如GL_COLOR_ATTACHMENTi_EXT:设定好OpenGL基本环境 -&
建立FBO -& 删除FBO创建FBO;
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,可以同时从一个片段着色器写入FBO为OpenGL core API的一部分:
GLenum status=glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT),空的FBO容器里面存储的是texture(纹理)和renderbuffer(渲染缓冲区),纹理和渲染缓冲区都可以作为渲染的目标,一般不具有纹理格式,它本身并不会自动的分配内存空间,标识使用原图像
接下来测试FBO准备工作是否完,返回一个当前绑定FBO是否正确的状态信息。接下来把这个深度缓存与准备好的FBO对象绑定在一起,我们需要调用API来分配指定的内存空间。一般使用的步骤,也可以是渲染缓冲区renderbuffer,width,&dbname);绑定该缓冲区; 对Frame Buffer 画图 -&解除贴图的连接 -&gt,fboname);
要想关闭FBO,只要是fboname给0就可以:glBindFrameBufferEXT(GL_FRAMEBUFFER_EXT,0);
参数GL_COLOR_ATTACHMENTO_EXT是告诉opengl把纹理对象绑定到FBO的0号绑定点,GL_TEXTURE_2D是纹理的格式,img是保存的纹理标识,指向之前就准备好的纹理对象,纹理可以使多重映射的图像;这样就分配了一个w*h的深度缓冲区,并把渲染重新定向到窗口的帧缓冲区。加入一个深度缓存
一个FBO本身并没有多大用处,要想让他能被更有效的使用,相对于其他同类技术,NULL),dbname);GL_RFBA格式的数据或者模板缓冲的信息,height,0,GL_RGBA,GL_UNSIGEND_BYTE:
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,dbname);
一个FBO可以有多个不同的绑定点,这里是绑定在FBO的深度缓冲绑定点上,通常是帧缓冲区的一部分
资深电脑人
为您推荐:
其他类似问题
opengl的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。博客分类:
glVertexPointer
void glVertexPointer(GLint size,
GLenum type,
GLsizei stride,
const GLvoid * pointer)
Parameters
size Specifies the number of coordinates per vertex. Must be 2, 3, or 4. The
initial value is 4.
type Specifies the data type of each vertex coordinate in the array. Symbolic
constants GL_BYTE, GL_SHORT, and GL_FIXED, are accepted. However, the
initial value is GL FLOAT.
The common profile accepts the symbolic constant GL FLOAT as well.
stride Specifies the byte offset between consecutive vertices. If stride is 0, the
vertices are understood to be tightly packed in the array. The initial value
is 0.
pointer Specifies a pointer to the first coordinate of the first vertex in the array.
The initial value is 0.
参数:
size:指定了每个顶点对应的坐标个数,只能是2,3,4中的一个,默认值是4
type:指定了数组中每个顶点坐标的数据类型,可取常量:GL_BYTE, GL_SHORT,GL_FIXED,GL_FLOAT;
stride:指定了连续顶点间的字节排列方式,如果为0,数组中的顶点就会被认为是按照紧凑方式排列的,默认值为0
pointer:制订了数组中第一个顶点的首地址,默认值为0,对于我们的android,大家可以不用去管什么地址的,一般给一个IntBuffer就可以了。
Description
glVertexPointer specifies the location and data of an array of vertex coordinates
to use when rendering. size specifies the number of coordinates per vertex and type
the data type of the coordinates. stride specifies the byte stride from one vertex to
the next allowing vertices and attributes to be packed into a single array or stored
in separate arrays. (Single-array storage may be more efficient on some implementations.)
When a vertex array is specified, size, type, stride, and pointer are saved as
client-side state.
If the vertex array is enabled, it is used when glDrawArrays, or glDrawElements
is called. To enable and disable the vertex array, call glEnableClientState
and glDisableClientState with the argument GL VERTEX ARRAY. The vertex array
is initially disabled and isn’t accessed when glDrawArrays or glDrawElements is
called.
Use glDrawArrays to construct a sequence of primitives (all of the same type)
from prespecified vertex and vertex attribute arrays. Use glDrawElements to construct
a sequence of primitives by indexing vertices and vertex attributes.
If the vertex array is enabled, it is used when glDrawArrays, or glDrawElements
is called. To enable and disable the vertex array, call glEnableClientState
and glDisableClientState with the argument GL_VERTEX ARRAY. The vertex array
is initially disabled and isn’t accessed when glDrawArrays or glDrawElements is
called.
Use glDrawArrays to construct a sequence of primitives (all of the same type)
from prespecified vertex and vertex attribute arrays. Use glDrawElements to construct
a sequence of primitives by indexing vertices and vertex attributes
描述:
当开始render的时候,glVertexPointer 用一个数组指定了每个顶点的坐标,
size指定了每个顶点的坐标个数
type指定了每个坐标的数据类型,(和尚注:注意,这里不同的数据类型含义不同,如果选择GL_FIXED,那么0x10000表示单位长度,如果选择 GL_FLOAT那么1.0f表示单位度。)
stride指定了一个顶点和下一个顶点间数据的排列方式,是"单一数组"还是"分散数组",单一数组的存储方式通常是更具效率的。当一个顶点数组被指定以后,size,type,stride,pointer被存储成client- side.
当glDrawArrays或者glDrawElements被调用的时候,如果顶点数组处于可用状态,就会被使用;可以使用glEnableClientState或者glDisableClientState来激活或者禁用一个顶点数组,顶点数组默认是不可用并且是不可被glDrawArrays、glDrawElements两个函数使用的。
使用glDrawArrays函数可以根据顶点数组构建一个原始构图序列
使用glDrawElements可以根据序列化的顶点集合来创建相同的序列
Notes
glVertexPointer is typically implemented on the client side
Errors
GL_INVALID_VALUE is generated if size is not 2, 3, or 4.
GL_INVALID_ENUM is generated if type is is not an accepted value.
GL_INVALID_VALUE is generated if stride is negative.
错误:
GL_INVALID_VALUE& size 不是 2, 3, 4中的一个的时候
GL_INVALID_ENUM&& type 不是一个允许的值.
GL_INVALID_VALUE& stride是错误的
函数名:
glDrawArrays – 从数组提供原始数据
void glDrawArrays(GLenum mode, GLint first, GLsizei count)
Parameters
mode Specifies what kind of primitives to render. Symbolic constants GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN, and GL_TRIANGLES are accepted.
first Specifies the starting index in the enabled arrays.
count Specifies the number of indices to be rendered.
参数:
mode& 指定要提供的原始图形的样式,比如:GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN, GL_TRIANGLES
first 指定了被激活的数组的索引起始点,通常为0
count 取几个数,和first配合使用
Description
glDrawArrays specifies multiple geometric primitives with very few subroutine calls.
You can prespecify separate arrays of vertices, normals, colors, and texture coordinates
and use them to construct a sequence of primitives with a single call to glDrawArrays.
When glDrawArrays is called, it uses& sequential elements from each enabled
array to construct a sequence of geometric primitives, beginning with element
first. mode specifies what kind of primitives are constructed, and how the array elements
construct those primitives. If GL_VERTEX_ARRAY is not enabled, no geometric
primitives are generated.
Vertex attributes that are modified by glDrawArrays have an unspecified value
after glDrawArrays returns. For example, if GL_COLOR_ARRAY is enabled, the value of
the current color is undefined after glDrawArrays executes. Attributes that aren’t
modified remain well defined.
描述:
glDrawArrays 提供了多种基本几何样式的绘制,你可以对各种数组,比如说顶点、颜色、材质的坐标进行分割(和尚注:通过first和count参数),并且使用这些分割出来的坐标来构造一个显示队列。
当glDrawArrays 被调用的时候,它会从first参数开始,按照mode指定的样式,按照顺序使用被激活的数组中的每个元素去构造一个由基本几何单元构成的队列,如果 GL_VERTEX_ARRAY没有处于激活状态,不会有任何几何单元被创建。
在glDrawArrays 被返回后,被这个函数编辑的顶点的属性将成为一个不确定的值,例如:glDrawArrays 函数被调用以后,当前颜色将会变成一个未定义的值。没有被函数引用的顶点属性会保留与原本的属性。(和尚注:很绕口,关于这一小段的翻译,我反复修改了很多遍,意思其实很简单,如果一个顶点数组被 glDrawArrays使用,那么使用后这些顶点决定的那个几何图形的属性,比如颜色,就会丢失,不会影响到下一个glDrawArrays 的绘制,因此当你要重新用glDrawArrays 绘制一个顶点集合的话,就要重新用glColor4f来设定颜色)
Errors
GL_INVALID_ENUM is generated if mode is not an accepted value.
GL_INVALID_VALUE is generated if count is negative.
错误:
GL_INVALID_ENUM& mode不是一个被允许的值
GL_INVALID_VALUE& count不合法
Name
glTranslatef, glTranslatex – multiply the current matrix by a translation matrix
C Specification
void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
void glTranslatex(GLfixed x, GLfixed y, GLfixed z)
名称:
glTranslatef, glTranslatex& 在一个副本(和尚:不知道翻译成副本合适不合适)模型上确定一个基于某个增量的新原点(和尚注:自己明白,要想写出合适的译文真的好难& )
void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
void glTranslatex(GLfixed x, GLfixed y, GLfixed z)
Parameters
x, y, z Specify the x, y, and z coordinates of a translation vector.
参数:
x,y,z指定了一个基于某个方向的x,y,z坐标
Description
glTranslate produces a translation by (x, y, z). The current matrix (see glMatrixMode)
is multiplied by this translation matrix, with the product replacing the
current matrix, as if glMultMatrix were called with the following matrix for its
argument:
1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
If the matrix mode is either GL_MODELVIEW or GL_PROJECTION, all objects drawn after
a call to glTranslate are translated.
Use glPushMatrix and glPopMatrix to save and restore the untranslated coordinate
system.
描述:
glTranslate 根据x,y,z生成了一个副本模型,当前模型是一个基于此模型的增量模型,glMultMatrix 被调用的时候用以下模型来做参数:
1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
如果模型模式是either GL_MODELVIEW 或者 GL_PROJECTION,所有的对象都会在glTranslate 被调用以后绘制
使用glPushMatrix 和 glPopMatrix来保存和恢复未被副本化的坐标系统
(和尚注:每一个层都是基于自己的坐标系统的,关于x,y,z的含义,参看以下说明:
OpenGL屏幕中心的坐标值是X和Y轴上的0.0f点。
中心左面的坐标值是负值,右面是正值。
移向屏幕顶端是正值,移向屏幕底端是负值。
移入屏幕深处是负值,移出屏幕则是正值。
)。
Name
glClear – clear buffers to preset values
C Specification
void glClear(GLbitfield mask)
名称
glClear – 为重设数据清空缓冲区
void glClear(GLbitfield mask)
Parameters
mask Bitwise OR of masks that indicate the buffers to be cleared.
Valid masks are GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT.
参数:
掩码: 用OR连接起来的掩码,这些掩码决定了哪些缓冲区将被清除,可用的掩码有:
GL_COLOR_BUFFER_BIT
GL_DEPTH_BUFFER_BIT
GL_STENCIL_BUFFER_BIT
Description
glClear sets the bitplane area of the window to values previously selected by gl-
ClearColor, glClearDepth, and glClearStencil.
The pixel ownership test, the scissor test, dithering, and the color buffer masks
affect the operation of glClear. The scissor box bounds the cleared region. Alpha
function, blend function, logical operation, stenciling, texture mapping, and depthbuffering
are ignored by glClear.
glClear takes a single argument that is the bitwise OR of several values indicating
which buffer is to be cleared.
The values are as follows:
GL COLOR BUFFER BIT
Indicates the color buffer.
GL DEPTH BUFFER BIT
Indicates the depth buffer.
GL STENCIL BUFFER BIT
Indicates the stencil buffer.
The value to which each buffer is cleared depends on the setting of the clear value
for that buffer.
描述:
glClear把窗口的bitplane区域的值设置成您设置的ClearColor, glClearDepth, glClearStencil
ownership测试、切图测试、抖动、颜色缓冲掩码受glClear的影响(空白区域的盒子跳动)Alpha通道函数,混合函数,逻辑操作,模板操作,纹理材质操作,深度缓冲区操作将被glClear忽略。
glClear的参数用几个OR连接3个可选项来制定要清楚哪些缓冲区
关于可选项的说明:
GL COLOR BUFFER BIT
颜色缓冲区
GL DEPTH BUFFER BIT
深度缓冲区
GL STENCIL BUFFER BIT
模板缓冲区
Name
glMatrixMode – specify which matrix is the current matrix
C Specification
void glMatrixMode(GLenum mode)
名称
glMatrixMode – 选择当前模型
Parameters
mode Specifies which matrix stack is the target for subsequent matrix operations.
Three values are accepted: GL_MODELVIEW, GL_PROJECTION, and
GL_TEXTURE. The initial value is GL_MODELVIEW.
参数:
mode 指定随后的模型操作的目标是哪一个模型堆栈,可选以下三个值
GL_MODELVIEW
GL_PROJECTION
GL_TEXTURE
默认值是 GL_MODELVIEW
Description
glMatrixMode sets the current matrix mode. mode can assume one of four values:
GL MODELVIEW
Applies subsequent matrix operations to the modelview matrix stack.
GL PROJECTION
Applies subsequent matrix operations to the projection matrix stack.
GL TEXTURE
Applies subsequent matrix operations to the texture matrix stack.
描述:
glMatrixMode 函数设定当前的模型模式,mode可以选择三个中的一个:
GL_MODELVIEW
把随后的模型操作应用到 modelview的模型堆栈上
GL_PROJECTION
把随后的模型操作应用到projection 的模型堆栈上
GL_TEXTURE
把随后的模型操作应用到texture 的模型堆栈上
Errors
GL_INVALID_ENUM is generated if mode is not an accepted value.
错误:
GL_INVALID_ENUM mode选择了一个错误的值
See Also
glLoadMatrix, glPushMatrix
参看:
glLoadMatrix, glPushMatrix函数
浏览: 65977 次
来自: 上海
貌似设置了mAddButton.setFocusableInT ...
不错的资料,谢谢了,非常有用,怎么都没有人顶呢
谢谢~~~~~
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)OpenGL ES学习之四—你好三角形(顶点缓冲区对象) – 乐猫的家园}

我要回帖

更多关于 opengl es pdf 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信