OpenGL

文章目录

OpenGL深入探索——像素缓冲区对象 (PBO)

https://blog.csdn.net/panda1234lee/article/details/51546502

http://www.songho.ca/opengl/gl_pbo.html


https://www.jianshu.com/p/d483cae905a8

https://blog.csdn.net/flycatdeng/article/details/82588903

 

OpenGL Overview

OpenGL uses the prefix gl for core OpenGL commands and glu for commands in OpenGL Utility Library. Similarly, OpenGL constants begin with GL_ and use all capital letters. OpenGL also uses suffix to specify the number of arguments and data type passed to a OpenGL call.

 

 

Last thing to do in Primitive Assembly is culling test if culling is enabled.

不同几种剔除(Culling)在渲染流程中的使用总结

antialiasing抗锯齿

clamping

OpenGL坐标系解析(顶点从对象坐标系到屏幕坐标系的计算流程)

https://www.jianshu.com/p/ebe8907aa07b

 

glViewport() command is used to define the rectangle of the rendering area where the final image is mapped. And, glDepthRange() is used to determine the z value of the window coordinates. The window coordinates are computed with the given parameters of the above 2 functions;

 

GL context

GL的坐标系

OpenGL的坐标系是所谓的右手坐标系

shader

fragment shader
vertex shader
Model View Projection

    glSurfaceView.setEGLContextClientVersion(2)//使用OpenGL ES 2.0
    glSurfaceView.setRenderer(PointsRender)
    glSurfaceView.renderMode = GLSurfaceView.RENDERMODE_CONTINUOUSLY//设置一个Renderer实例,渲染模式(render mode)分为两种,一个是GLSurfaceView主动刷新(continuously),不停的回调Renderer的onDrawFrame,另外一种叫做被动刷新(when dirty),就是当请求刷新时才调一次onDrawFrame。
    
         GLES20.glClearColor(0f, 0f, 0f, 1f)//让OpenGL把背景,或者画布画成黑色,不透明。用参数指定的(r, g, b, a)这个颜色来初始化颜色缓冲区(color buffer)

        val vsh = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER)
        GLES20.glShaderSource(vsh, VERTEX_SHADER)
        GLES20.glCompileShader(vsh)

        val fsh = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER)
        GLES20.glShaderSource(fsh, FRAGMENT_SHADER)
        GLES20.glCompileShader(fsh)
        GLES20.glShaderSource(vsh, VERTEX_SHADER) // 告诉OpenGL,这一坨字串里面是vertex shader的源码。
        GLES20.glCompileShader(vsh) // 编译vertex shader
        
        mGLProgram = GLES20.glCreateProgram()
        GLES20.glAttachShader(mGLProgram, vsh)
        GLES20.glAttachShader(mGLProgram, fsh)
        GLES20.glLinkProgram(mGLProgram)

        GLES20.glValidateProgram(mGLProgram)

        val status = IntArray(1)
        GLES20.glGetProgramiv(mGLProgram, GLES20.GL_VALIDATE_STATUS, status, 0)
        Log.d(TAG, "validate shader program: " + GLES20.glGetProgramInfoLog(mGLProgram))
        mGLProgram = GLES20.glCreateProgram() // 创建shader program句柄
        GLES20.glAttachShader(mGLProgram, vsh) // 把vertex shader添加到program
        GLES20.glAttachShader(mGLProgram, fsh) // 把fragment shader添加到program
        GLES20.glLinkProgram(mGLProgram) // 做链接,可以理解为把两种shader进行融合,做好投入使用的最后准备工作
        GLES20.glValidateProgram(mGLProgram) // 让OpenGL来验证一下我们的shader program,并获取验证的状态
        val status = IntArray(1)
        GLES20.glGetProgramiv(mGLProgram, GLES20.GL_VALIDATE_STATUS, status, 0) // 获取验证的状态
        Log.d(TAG, "validate shader program: " + GLES20.glGetProgramInfoLog(mGLProgram))

glCreateProgram

glCreateProgram creates an empty program object and returns a non-zero
value by which it can be referenced. A program object is an object to
which shader objects can be attached. This provides a mechanism to
specify the shader objects that will be linked to create a program. It
also provides a means for checking the compatibility of the shaders
that will be used to create a program (for instance, checking the
compatibility between a vertex shader and a fragment shader). When no
longer needed as part of a program object, shader objects can be
detached.

One or more executables are created in a program object by
successfully attaching shader objects to it with glAttachShader,
successfully compiling the shader objects with glCompileShader, and
successfully linking the program object with glLinkProgram. These
executables are made part of current state when glUseProgram is
called. Program objects can be deleted by calling glDeleteProgram. The
memory associated with the program object will be deleted when it is
no longer part of current rendering state for any context.

GLES20.glVertexAttribPointer();

https://www.cnblogs.com/Vulkan/archive/2012/11/17/7530213.html

Description

glVertexAttribPointer specifies the location and data format of the
array of generic vertex attributes at index index to use when
rendering. size specifies the number of components per attribute and
must be 1, 2, 3, or 4. type specifies the data type of each component,
and stride specifies the byte stride from one attribute to the next,
allowing vertices and attributes to be packed into a single array or
stored in separate arrays. If set to GL_TRUE, normalized indicates
that values stored in an integer format are to be mapped to the range
[-1,1] (for signed values) or [0,1] (for unsigned values) when they
are accessed and converted to floating point. Otherwise, values will
be converted to floats directly without normalization.

If a non-zero named buffer object is bound to the GL_ARRAY_BUFFER
target (see glBindBuffer) while a generic vertex attribute array is
specified, pointer is treated as a byte offset into the buffer
object’s data store. Also, the buffer object binding
(GL_ARRAY_BUFFER_BINDING) is saved as generic vertex attribute array
client-side state (GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) for index
index.

When a generic vertex attribute array is specified, size, type,
normalized, stride, and pointer are saved as client-side state, in
addition to the current vertex array buffer object binding.

To enable and disable a generic vertex attribute array, call
glEnableVertexAttribArray and glDisableVertexAttribArray with index.
If enabled, the generic vertex attribute array is used when
glDrawArrays or glDrawElements is called.

GLES20.glEnableVertexAttribArray();

void glDisableVertexAttribArray( GLuint index); Parameters

index

Specifies the index of the generic vertex attribute to be enabled or disabled.

Description

glEnableVertexAttribArray enables the generic vertex attribute array
specified by index. glDisableVertexAttribArray disables the generic
vertex attribute array specified by index. By default, all client-side
capabilities are disabled, including all generic vertex attribute
arrays. If enabled, the values in the generic vertex attribute array
will be accessed and used for rendering when calls are made to vertex
array commands such as glDrawArrays or glDrawElements.

GLES20.glActiveTexture();

Parameters

texture

Specifies which texture unit to make active. The number of texture units is implementation dependent, but must be at least 8. texture

must be one of GL_TEXTUREi, where i ranges from 0 to
(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1). The initial value is
GL_TEXTURE0.

Description

glActiveTexture selects which texture unit subsequent texture state
calls will affect. The number of texture units an implementation
supports is implementation dependent, but must be at least 8.

GLES20.glBindTexture()

glBindTexture — bind a named texture to a texturing target C
Specification void glBindTexture( GLenum target, GLuint texture);
Parameters

target

Specifies the target of the active texture unit to which the texture is bound. Must be either GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.

texture

Specifies the name of a texture. 

Description

glBindTexture lets you create or use a named texture. Calling
glBindTexture with target set to GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP
and texture set to the name of the new texture binds the texture name
to the target of the current active texture unit. When a texture is
bound to a target, the previous binding for that target is
automatically broken.

Texture names are unsigned integers. The value zero is reserved to
represent the default texture for each texture target. Texture names
and the corresponding texture contents are local to the shared object
space of the current GL rendering context.

You may use glGenTextures to generate a set of new texture names.

When a texture is first bound, it assumes the specified target: A
texture first bound to GL_TEXTURE_2D becomes a two-dimensional texture
and a texture first bound to GL_TEXTURE_CUBE_MAP becomes a cube-mapped
texture. The state of a two-dimensional texture immediately after it
is first bound is equivalent to the state of the default GL_TEXTURE_2D
at GL initialization, and similarly for cube-mapped textures.

While a texture is bound, GL operations on the target to which it is
bound affect the bound texture, and queries of the target to which it
is bound return state from the bound texture. In effect, the texture
targets become aliases for the textures currently bound to them, and
the texture name zero refers to the default textures that were bound
to them at initialization.

A texture binding created with glBindTexture remains active until a
different texture is bound to the same target, or until the bound
texture is deleted with glDeleteTextures.

Once created, a named texture may be re-bound to its same original
target as often as needed. It is usually much faster to use
glBindTexture to bind an existing named texture to one of the texture
targets than it is to reload the texture image using glTexImage2D.

GLES20.glUniformli()

通过使用glUniformli设置采样器,告诉openGL每个uniform采样器属于哪个纹理单元,设置一次即可,所以把这个放在循环渲染的前边。

GLES20.glBindFramebuffer()

bind a named framebuffer object
C Specification
void glBindFramebuffer(    GLenum target,     GLuint framebuffer);
 
Parameters

target

    Specifies the target to which the framebuffer object is bound. The symbolic constant must be GL_FRAMEBUFFER.
framebuffer

    Specifies the name of a framebuffer object.

Description

glBindFramebuffer lets you create or use a named framebuffer object. Calling glBindFramebuffer with target set to GL_FRAMEBUFFER and framebuffer set to the name of the new framebuffer object binds the framebuffer object name. When a framebuffer object is bound, the previous binding is automatically broken.

Framebuffer object names are unsigned integers. The value zero is reserved to represent the default framebuffer provided by the windowing system. Framebuffer object names and the corresponding framebuffer object contents are local to the shared object space of the current GL rendering context.

You may use glGenFramebuffers to generate a set of new framebuffer object names.

The state of a framebuffer object immediately after it is first bound is three attachment points (GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, and GL_STENCIL_ATTACHMENT) each with GL_NONE as the object type.

While a non-zero framebuffer object name is bound, GL operations on target GL_FRAMEBUFFER affect the bound framebuffer object, and queries of target GL_FRAMEBUFFER or of framebuffer details such as GL_DEPTH_BITS return state from the bound framebuffer object. While framebuffer object name zero is bound, as in the initial state, attempts to modify or query state on target GL_FRAMEBUFFER generates an GL_INVALID_OPERATION error.

While a non-zero framebuffer object name is bound, all rendering to the framebuffer (with glDrawArrays and glDrawElements) and reading from the framebuffer (with glReadPixels, glCopyTexImage2D, or glCopyTexSubImage2D) use the images attached to the application-created framebuffer object rather than the default window-system-provided framebuffer.

Application created framebuffer objects (i.e. those with a non-zero name) differ from the default window-system-provided framebuffer in a few important ways. First, they have modifiable attachment points for a color buffer, a depth buffer, and a stencil buffer to which framebuffer attachable images may be attached and detached. Second, the size and format of the attached images are controlled entirely within the GL and are not affected by window-system events, such as pixel format selection, window resizes, and display mode changes. Third, when rendering to or reading from an application created framebuffer object, the pixel ownership test always succeeds (i.e. they own all their pixels). Fourth, there are no visible color buffer bitplanes, only a single "off-screen" color image attachment, so there is no sense of front and back buffers or swapping. Finally, there is no multisample buffer, so the value of the implementation-dependent state variables GL_SAMPLES and GL_SAMPLE_BUFFERS are both zero for application created framebuffer objects.

A framebuffer object binding created with glBindFramebuffer remains active until a different framebuffer object name is bound, or until the bound framebuffer object is deleted with glDeleteFramebuffers.
Notes

Queries of implementation-dependent pixel depths and related state are derived from the currently bound framebuffer object. These include GL_RED_BITS, GL_GREEN_BITS, GL_BLUE_BITS, GL_ALPHA_BITS, GL_DEPTH_BITS, GL_STENCIL_BITS, GL_IMPLEMENTATION_COLOR_READ_TYPE, GL_IMPLEMENTATION_COLOR_READ_FORMAT, GL_SAMPLES, and GL_SAMPLE_BUFFERS.

GLES20.glViewport()

Name

glViewport — set the viewport
C Specification
void glViewport(    GLint x,
     GLint y,
     GLsizei width,
     GLsizei height);
 
Parameters

x, y

    Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0).
width, height

    Specify the width and height of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.

Description

glViewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let x nd y nd be normalized device coordinates. Then the window coordinates x w y w are computed as follows:

x w = x nd + 1 ⁢ width 2 + x

y w = y nd + 1 ⁢ height 2 + y

Viewport width and height are silently clamped to a range that depends on the implementation. To query this range, call glGet with argument GL_MAX_VIEWPORT_DIMS.
Errors

GL_INVALID_VALUE is generated if either w

glViewport指定x和y从标准化设备坐标到窗口坐标的一个仿射变化。设(Xnd,Ynd)是标准化设备坐标(-1.0~1.0,0.0在设备中间),则窗口坐标(Xw,Yw)可以由以下公式推出:

视口宽高会被默认限制到一定的范围内,视具体实现而定,可以通过glGet变量GL_MAX_VIEWPORT_DIMS得到。

idth or height is negative.


Associated Gets

glGet with argument GL_VIEWPORT

glGet with argument GL_MAX_VIEWPORT_DIMS


GLES20.glDrawArrays()

Name

glDrawArrays — render primitives from array data
C Specification
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.

Description

glDrawArrays specifies multiple geometric primitives with very few subroutine calls. Instead of calling a GL procedure to pass each individual vertex attribute, you can use glVertexAttribPointer to prespecify separate arrays of vertices, normals, and colors and use them to construct a sequence of primitives with a single call to glDrawArrays.

When glDrawArrays is called, it uses count 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.

To enable and disable a generic vertex attribute array, call glEnableVertexAttribArray and glDisableVertexAttribArray.
Notes

If the current program object, as set by glUseProgram, is invalid, rendering results are undefined. However, no error is generated for this case.
 


GLES20.glDisableVertexAttribArray()

Name

glEnableVertexAttribArray — enable or disable a generic vertex attribute array
C Specification
void glEnableVertexAttribArray(    GLuint index);
 
void glDisableVertexAttribArray(    GLuint index);
 
Parameters

index

    Specifies the index of the generic vertex attribute to be enabled or disabled.

Description

glEnableVertexAttribArray enables the generic vertex attribute array specified by index. glDisableVertexAttribArray disables the generic vertex attribute array specified by index. By default, all client-side capabilities are disabled, including all generic vertex attribute arrays. If enabled, the values in the generic vertex attribute array will be accessed and used for rendering when calls are made to vertex array commands such as glDrawArrays or glDrawElements.

 


GLES20.glFramebufferTexture2D()

Name

glFramebufferTexture2D — attach a texture image to a framebuffer object
C Specification
void glFramebufferTexture2D(    GLenum target,
     GLenum attachment,
     GLenum textarget,
     GLuint texture,
     GLint level);
 
Parameters

target

    Specifies the framebuffer target. The symbolic constant must be GL_FRAMEBUFFER.
attachment

    Specifies the attachment point to which an image from texture should be attached. Must be one of the following symbolic constants: GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, or GL_STENCIL_ATTACHMENT.
textarget

    Specifies the texture target. Must be one of the following symbolic constants: GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, or GL_TEXTURE_CUBE_MAP_NEGATIVE_Z.
texture

    Specifies the texture object whose image is to be attached.
level

    Specifies the mipmap level of the texture image to be attached, which must be 0.

Description

glFramebufferTexture2D attaches the texture image specified by texture and level as one of the logical buffers of the currently bound framebuffer object. attachment specifies whether the texture image should be attached to the framebuffer object's color, depth, or stencil buffer. A texture image may not be attached to the default framebuffer object name 0.

If texture is not 0, the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE for the specified attachment point is set to GL_TEXTURE, the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME is set to texture, and the value of GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL is set to level. If texture is a cube map texture, the value of GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE is set to textarget; otherwise it is set to the default value GL_TEXTURE_CUBE_MAP_POSITIVE_X. Any previous attachment to the attachment logical buffer of the currently bound framebuffer object is broken.

If texture is 0, the current image, if any, attached to the attachment logical buffer of the currently bound framebuffer object is detached. The value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is set to GL_NONE. The value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME is set to 0. GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL and GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE are set to the default values 0 and GL_TEXTURE_CUBE_MAP_POSITIVE_X, respectively.
Notes

Special precautions need to be taken to avoid attaching a texture image to the currently bound framebuffer while the texture object is currently bound and potentially sampled by the current vertex or fragment shader. Doing so could lead to the creation of a "feedback loop" between the writing of pixels by rendering operations and the simultaneous reading of those same pixels when used as texels in the currently bound texture. In this scenario, the framebuffer will be considered framebuffer complete, but the values of fragments rendered while in this state will be undefined. The values of texture samples may be undefined as well.

If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is as if glFramebufferTexture2D had been called with a texture of 0 for the attachment point to which this image was attached in the currently bound framebuffer object. In other words, the texture image is detached from the currently bound framebuffer. Note that the texture image is specifically not detached from any non-bound framebuffers. Detaching the image from any non-bound framebuffers is the responsibility of the application.

名称

glFramebufferTexture2D - 将纹理图像附加到帧缓冲对象

C规范

void glFramebufferTexture2D(GLenum target,

                                                          GLenum attachment,

                                                          GLenum textarget,

                                                          GLuint texture,

                                                          GLint level);

参数

target

指定帧缓冲目标。 符号常量必须是GL_FRAMEBUFFER

attachment

指定应附加纹理图像的附着点。 必须是以下符号常量之一:GL_COLOR_ATTACHMENT0GL_DEPTH_ATTACHMENTGL_STENCIL_ATTACHMENT

textarget

指定纹理目标。 必须是以下符号常量之一:GL_TEXTURE_2DGL_TEXTURE_CUBE_MAP_POSITIVE_XGL_TEXTURE_CUBE_MAP_NEGATIVE_XGL_TEXTURE_CUBE_MAP_POSITIVE_YGL_TEXTURE_CUBE_MAP_NEGATIVE_YGL_TEXTURE_CUBE_MAP_POSITIVE_ZGL_TEXTURE_CUBE_MAP_NEGATIVE_Z

texture

指定要附加图像的纹理对象。

level

指定要附加的纹理图像的mipmap级别,该级别必须为0。

描述

glFramebufferTexture2Dtexturelevel指定的纹理图像附加为当前绑定的帧缓冲区对象的逻辑缓冲区之一。 attachment指定是否应将纹理图像附加到帧缓冲对象的颜色,深度或模板缓冲区。 纹理图像不可以附加到默认(名称为0)的帧缓冲对象。

如果texture不为0,则指定附加点的GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE的值设置为GL_TEXTUREGL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME的值设置为textureGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL的值设置为level。 如果纹理是立方体贴图纹理,则GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE的值设置为textarget; 否则将其设置为默认值GL_TEXTURE_CUBE_MAP_POSITIVE_X。 先前绑定的帧缓冲区对象的附件逻辑缓冲区都将被破坏。

如果texture为0,则分离附加到当前绑定的帧缓冲区对象的附件逻辑缓冲区的当前图像(如果有的话)。 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE的值设置为GL_NONEGL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME的值设置为0. GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVELGL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE分别设置为默认值0GL_TEXTURE_CUBE_MAP_POSITIVE_X

注意

当纹理对象当前被绑定并可能被当前顶点或片段着色器采样时,需要采取特殊预防措施以避免将纹理图像附加到当前绑定的帧缓冲区。这样做可能导致在通过渲染操作写入像素和在当前绑定纹理中用作纹素时同时读取那些相同像素之间创建“反馈循环”。在这种情况下,帧缓冲区将被视为帧缓冲区完成,但在此状态下渲染的片段的值将是未定义的。纹理样本的值也可能是未定义的。

如果在将图像附加到当前绑定的帧缓冲区时删除纹理对象,这就好比使用纹理0调用glFramebufferTexture2D作为此图像附加到当前绑定的帧缓冲区对象中的附着点。换句话说,纹理图像与当前绑定的帧缓冲区分离了。请注意,纹理图像不会与任何未绑定的帧缓冲区分离。从任何非绑定帧缓冲区中分离映像是应用程序的责任。

错误

GL_INVALID_ENUM target不是GL_FRAMEBUFFER

GL_INVALID_ENUM texture不为0时textarget不是可接收的纹理target。

GL_INVALID_ENUM attachment是不可接收的附着点。

GL_INVALID_VALUE level不是0时,texture不是0。

GL_INVALID_OPERATION :如果绑定了默认的帧缓冲对象名称0。

GL_INVALID_OPERATION :如果texture既不是0也不是现有纹理对象的名称。

GL_INVALID_OPERATION :如果texture是现有二维纹理对象的名称,但textarget不是GL_TEXTURE_2D,或者texture是现有立方体贴图纹理对象的名称,但textargetGL_TEXTURE_2D

相关Gets

glGetFramebufferAttachmentParameteriv

另见

glBindFramebuffer,glBindTexture,glCheckFramebufferStatusglDeleteFramebuffersglDeleteTexturesglFramebufferRenderbufferglGenerateMipmapglGetFramebufferAttachmentParameterivglTexImage2D


GLES20.bindPixelBuffer()

https://www.jianshu.com/p/3bc4db687546


GLES20.glReadPixels()

名称

glReadPixels - 从帧缓冲区中读取一个像素块

C规范

void glReadPixels(GLint x,

                                    GLint y,

                                    GLsizei width,

                                    GLsizei height,

                                    GLenum format,

                                    GLenum type,

                                    GLvoid * data);

参数

x,y

指定从帧缓冲区读取的第一个像素的窗口坐标。 此位置是矩形像素块的左下角

width,height

指定像素矩形的尺寸。 一个宽度和高度对应于单个像素。

format

指定像素数据的格式。 接受以下符号值:GL_ALPHAGL_RGBGL_RGBA

type

指定像素数据的数据类型。 必须是GL_UNSIGNED_BYTEGL_UNSIGNED_SHORT_5_6_5GL_UNSIGNED_SHORT_4_4_4_4GL_UNSIGNED_SHORT_5_5_5_1之一。

data

返回像素数据。

描述

glReadPixels从帧缓冲区返回像素数据,从左下角位于(x,y)的像素开始,从位置data开始返回客户端内存。使用glPixelStorei命令设置的GL_PACK_ALIGNMENT参数会影响像素数据在放入客户端内存之前的处理。

glReadPixels返回每个像素的值,左下角为x + i  y + j,0 <= i <width,0 <= j <height。 该像素被称为第j行中的第i个像素。 像素按行顺序从最低行返回到最高行,每行从左到右排列。

format指定返回像素值的格式; 可接受的值是:

GL_ALPHA

GL_RGB

GL_RGBA

从颜色缓冲区读取RGBA颜色分量。 每个颜色分量都转换为浮点,使零强度映射到0.0,全强度映射到1.0。

丢弃不需要的数据。 例如,GL_ALPHA丢弃红色,绿色和蓝色组件,而GL_RGB仅丢弃alpha组件。 最终值被限制在[0 1]的范围内。

最后,组件将转换为由类型指定合适的格式,。 当类型为GL_UNSIGNED_BYTE时,每个组件乘以2^8 - 1。 当类型为GL_UNSIGNED_SHORT_5_6_5GL_UNSIGNED_SHORT_4_4_4_4GL_UNSIGNED_SHORT_5_5_5_1时,每个分量乘以2^N-1,其中N是位域中的位数。

返回值按如下方式放入内存中。 如果formatGL_ALPHA,则返回单个值,并且第j行中第i个像素的数据放置在位置j*width + i中。 GL_RGB返回三个值,GL_RGBA为每个像素返回四个值,所有值对应于占据数据中连续空间的单个像素。 由glPixelStorei设置的存储参数GL_PACK_ALIGNMENT会影响数据写入内存的方式。 有关说明,请参阅glPixelStorei

注意

如果当前绑定的帧缓冲区不是默认的帧缓冲区对象,则从附加到GL_COLOR_ATTACHMENT0附着点的彩色图像中读取颜色分量。

只有两个format/type参数对是可接受的。GL_RGBA / GL_UNSIGNED_BYTE是始终都可以接受的,另外的就需要查询了:通过查询GL_IMPLEMENTATION_COLOR_READ_FORMATGL_IMPLEMENTATION_COLOR_READ_TYPE来发现其他可接受的对。

位于连接到当前GL上下文的窗口之外的像素值是未定义的。

如果生成错误,则不会更改data内容。

错误

GL_INVALID_ENUM :如果formattype不是可接受的值。

GL_INVALID_VALUE :如果widthheight是负数

GL_INVALID_OPERATION :如果typeGL_UNSIGNED_SHORT_5_6_5且格式不是GL_RGB

GL_INVALID_OPERATION :如果typeGL_UNSIGNED_SHORT_4_4_4_4GL_UNSIGNED_SHORT_5_5_5_1且格式不是GL_RGBA

GL_INVALID_OPERATION :如果formattype分别既不是GL_RGBA又不是GL_UNSIGNED_BYTE,也不是通过查询GL_IMPLEMENTATION_COLOR_READ_FORMATGL_IMPLEMENTATION_COLOR_READ_TYPE返回的格式/类型对。

GL_INVALID_FRAMEBUFFER_OPERATION :如果当前绑定的帧缓冲区不是帧缓冲区完成状态(即glCheckFramebufferStatus的返回值不是GL_FRAMEBUFFER_COMPLETE)。

相关Gets

glGet 参数GL_IMPLEMENTATION_COLOR_READ_FORMATGL_IMPLEMENTATION_COLOR_READ_TYPE

glGet 参数GL_PACK_ALIGNMENT

另见

glCheckFramebufferStatusglPixelStorei

 

ByteBuffer.allocateDirect().order().asFloatBuffer();

asFloatBuffer()方法创建一个Float型的缓冲区,这个缓冲区基于当前的ByteBuffer实现,我们把它叫做FloatBuffer型的视图,该视图共享当前的ByteBuffer空间(不一定是全部空间)。


https://blog.csdn.net/weixin_40531919/article/details/111597991

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

seiyaaa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值