Chapter 14. State Queries

OpenGL ES 2.0 relies on a large collection of data and objects to render when you ask. You’ll need to compile and link shader programs, initialize vertex arrays and attribute bindings, specify uniform values, and probably load and bind texture, and that only scratches the surface.

There is also a large quantity of values that are intrinsic to OpenGL ES 2.0’s operation. You might need to determine how large of a viewport is supported, or the maximum number of texture units, for example. All of those values can be queried by your application.

This chapter describes the functions your applications can use to obtain values from OpenGL ES 2.0, and the parameters that you can query.

OpenGL ES 2.0 Implementation String Queries

One of the most fundamental queries that you will need to perform in your (well written) applications is information about the underlying OpenGL ES 2.0 implementation, like the version of OpenGL ES supported, whose implementation it is, and what extensions are available. These characteristics are all returned as ASCII strings from the glGetString function.

const GLubyte*

glGetString(GLenum name)

name

specifies the parameter to be returned. Can be one of GL_VENDOR, GL_RENDERER, GL_VERSION, GL_SHADING_LANGUAGE_VERSION, or GL_EXTENSIONS

The GL_VENDOR and GL_RENDERER queries are formatted for human consumption, and have no set format; they’re initialized with whatever the implementer felt were useful descriptions.

The GL_VERSION query will return a string starting with “OpenGL ES 2.0” for all OpenGL ES 2.0 implementations. The version string can additionally include vendor-specific information after those tokens, and will always have the format of:

OpenGL ES <version> <vendor-specific information>

with the <version> being the version number (e.g., 2.0), composed of a major release number, followed by a period and the minor release number, and optionally another period and a tertiary release value (often used by vendors to represent an OpenGL ES 2.0’s driver revision number).

Likewise, the GL_SHADING_LANGUAGE_VERSION query will always return a string starting with OpenGL ES GLSL ES 1.00. This string can also have vendor-specific information appended to it, and will take the form:

OpenGL ES GLSL ES <version> <vendor-specific information>

with a similar formatting for the <version> value.

When OpenGL ES is updated to the next version, these version numbers will change accordingly.

Finally, the GL_EXTENSIONS query will return a space-separated list of all of the extensions supported by the implementation, or the NULL string if the implementation is not extended.

Querying Implementation-Dependent Limits

Many rendering parameters depend on the underlying capabilities of the OpenGL ES implementation; for example, how many texture units are available to a shader, or what is the maximum size for a texture map or aliased point. Values of those types are queried using one of the functions shown here.

void

glGetBooleanv(GLenum pname, GLboolean* params)

void

glGetFloatv(GLenum pname, GLfloat* params)

void

glGetIntegerv(GLenum pname, GLint* params)

pname

specifies the implementation-specific parameter to be queried

params

specifies an array of values of the respective type with enough entries to hold the return values for the associated parameter

There are a number of implementation-dependent parameters that can be queried, as listed in Table 14-1.

Table 14-1. Implementation-Dependent State Queries

State Variable

Description

Minimum/Initial Value

Get Function

GL_VIEWPORT

Current size of the viewport

 

glGetIntegerv

GL_DEPTH_RANGE

Current depth range values

(0, 1)

glGetFloatv

GL_LINE_WIDTH

Current line width

1.0

glGetFloatv

GL_CULL_FACE_MODE

Current face mode for polygon culling

GL_BACK

glGetIntegerv

GL_FRONT_FACE

Current vertex ordering for specifying a front-facing polygon

GL_CCW

glGetIntegerv

GL_POLYGON_OFFSET_FACTOR

Current polygon offset factor value

0

glGetFloatv

GL_POLYGON_OFFSET_UNITS

Current polygon offset units value

0

glGetFloatv

GL_SAMPLE_COVERAGE_VALUE

Current multisample coverage value

1

glGetFloatv

GL_SAMPLE_COVERAGE_INVERT

Current value of multisample inversion flag

GL_FALSE

glGetBooleanv

GL_COLOR_WRITEMASK

Current color buffer writemask value

GL_TRUE

glGetBooleanv

GL_DEPTH_WRITEMASK

Current depth buffer writemask value

GL_TRUE

glGetBooleanv

GL_STENCIL_WRITEMASK

Current stencil buffer writemask value

1s

glGetIntegerv

GL_STENCIL_BACK_WRITEMASK

Current back stencil buffer writemask value

1s

glGetIntegerv

GL_COLOR_CLEAR_VALUE

Current color buffer clear value

(0, 0, 0, 0)

glGetFloatv

GL_DEPTH_CLEAR_VALUE

Current depth buffer clear value

1

glGetIntegerv

GL_STENCIL_CLEAR_VALUE

Current stencil buffer clear value

0

glGetIntegerv

GL_SUBPIXEL_BITS

Number of subpixel bits supported

4

glGetIntegerv

GL_MAX_TEXTURE_SIZE

Maximum size of a texture

64

glGetIntegerv

GL_MAX_CUB_MAP_TEXTURE_SIZE

Maximum dimension of a cubemap texture

16

glGetIntegerv

GL_MAX_VIEWPORT_DIMS

Dimensions of the maximum supported viewport size

 

glGetIntegerv

GL_ALIASED_POINT_SIZE_RANGE

Range of aliased point sizes

1, 1

glGetFloatv

GL_ALIASED_LINE_WIDTH_RANGE

Range of aliased line width sizes

1, 1

glGetFloatv

GL_NUM_COMPRESSED_TEXTURE_FORMATS

Number of compressed texture formats supported

 

glGetIntegerv

GL_COMPRESSED_TEXTURE_FORMATS

Compressed texture formats supported

 

glGetIntegerv

GL_RED_BITS

Number of red bits in current color buffer

 

glGetIntegerv

GL_GREEN_BITS

Number of green bits in current color buffer

 

glGetIntegerv

GL_BLUE_BITS

Number of blue bits in current color buffer

 

glGetIntegerv

GL_ALPHA_BITS

Number of alpha bits in current color buffer

 

glGetIntegerv

GL_DEPTH_BITS

Number of bits in the current depth buffer

16

glGetIntegerv

GL_STENCIL_BITS

Number of stencil bits in current stencil buffer

8

glGetIntegerv

GL_IMPLEMENTATION_READ_TYPE

Data type for pixel components for pixel read operations

 

glGetIntegerv

GL_IMPLEMENTATION_READ_FORMAT

Pixel format for pixel read operations

  

Querying OpenGL ES State

There are many parameters that your application can modify to affect OpenGL ES 2.0’s operation. Although it’s usually more efficient for an application to track these values when it modifies them, you can retrieve any of the values listed in Table 14-2 from the currently bound context. For each token, the appropriate OpenGL ES 2.0 get function is provided.

Table 14-2. Application-Modifiable OpenGL ES State Queries

State Variable

Description

Minimum/Initial Value

Get Function

GL_ARRAY_BUFFER_BINDING

Currently bound vertex attribute array binding

0

glGetIntegerv

GL_ELEMENT_ARRAY_BUFFER_BINDING

Currently bound element array binding

0

glGetIntegerv

GL_CULL_FACE_MODE

Current face culling mode

GL_BACK

glGetIntegerv

GL_FRONT_FACE

Current front-facing vertex winding mode

GL_CCW

glGetIntegerv

GL_SAMPLE_COVERAGE_VALUE

Current value specified for multisampling sample coverage value

1

glGetFloatv

GL_SAMPLE_COVERAGE_INVERT

Current multisampling coverage value inversion setting

GL_FALSE

glGetBooleanv

GL_TEXTURE_BINDING_2D

Current 2D texture binding

0

glGetIntegerv

GL_TEXTURE_BINDING_CUBE_MAP

Current cubemap texture binding

0

glGetIntegerv

GL_ACTIVE_TEXTURE

Current texture unit

0

glGetIntegerv

GL_COLOR_WRITEMASK

Color buffer writable

GL_TRUE

glGetBooleanv

GL_DEPTH_WRITEMASK

Depth buffer writable

GL_TRUE

glGetBooleanv

GL_STENCIL_WRITEMASK

Current write mask for front-facing polygons

1

glGetIntegerv

GL_STENCIL_BACK_WRITEMASK

Current write mask for back-facing polygons

1

glGetIntegerv

GL_COLOR_CLEAR_VALUE

Current color buffer clear value

0, 0, 0, 0

glGetFloatv

GL_DEPTH_CLEAR_VALUE

Current depth buffer clear value

1

glGetIntegerv

GL_STENCIL_CLEAR_VALUE

Current stencil buffer clear value

0

glGetIntegerv

GL_SCISSOR_BOX

Current offset and dimensions of the scissor box

0, 0, w, h

glGetIntegerv

GL_STENCIL_FUNC

#Current stencil test operator function

GL_ALWAYS

glGetIntegerv

GL_STENCIL_VALUE_MASK

Current stencil test value mask

1s

glGetIntegerv

GL_STENCIL_REF

Current stencil test reference value

0

glGetIntegerv

GL_STENCIL_FAIL

Current operation for stencil test failure

GL_KEEP

glGetIntegerv

GL_STENCIL_PASS_DEPTH_FAIL

Current operation for when the stencil test passes, but the depth test fails

GL_KEEP

glGetIntegerv

GL_STENCIL_PASS_DEPTH_PASS

Current operation when both the stencil and depth tests pass

GL_KEEP

glGetIntegerv

GL_STENCIL_BACK_FUNC

Current back-facing stencil test operator function

GL_ALWAYS

glGetIntegerv

GL_STENCIL_BACK_VALUE_MASK

Current back-facing stencil test value mask

1s

glGetIntegerv

GL_STENCIL_BACK_REF

Current back-facing stencil test reference value

0

glGetIntegerv

GL_STENCIL_BACK_FAIL

Current operation for back-facing stencil test failure

GL_KEEP

glGetIntegerv

GL_STENCIL_BACK_PASS_DEPTH_FAIL

Current operation for when the back-facing stencil test passes, but the depth test fails

GL_KEEP

glGetIntegerv

GL_STENCIL_BACK_PASS_DEPTH_PASS

Current operation when both the back-facing stencil and depth tests pass

GL_KEEP

glGetIntegerv

GL_DEPTH_FUNC

Current depth test comparison function

GL_LESS

glGetIntegerv

GL_BLEND_SRC_RGB

Current source RGB blending coefficient

GL_ONE

glGetIntegerv

GL_BLEND_SRC_ALPHA

Current source alpha blending coefficient

GL_ONE

glGetIntegerv

GL_BLEND_DST_RGB

Current destination RGB blending coefficient

GL_ZERO

glGetIntegerv

GL_BLEND_DST_ALPHA

Current destination alpha blending coefficient

GL_ZERO

glGetIntegerv

GL_BLEND_EQUATION

Current blend equation operator

GL_FUNC_ADD

glGetIntegerv

GL_BLEND_EQUATION_RGB

Current RGB blend equation operator

GL_FUNC_ADD

glGetIntegerv

GL_BLEND_EQUATION_ALPHA

Current alpha blend equation operator

GL_FUNC_ADD

glGetIntegerv

GL_BLEND_COLOR

Current blend color

0, 0, 0, 0

glGetFloatv

GL_UNPACK_ALIGNMENT

Current byte boundary alignment for pixel unpacking

4

glGetIntegerv

GL_PACK_ALIGNMENT

Current byte boundary alignment for pixel packing

4

glGetIntegerv

GL_CURRENT_PROGRAM

Currently bound shader program

0

glGetIntegerv

GL_RENDERBUFFER_BINDING

Currently bound renderbuffer

0

glGetIntegerv

GL_FRAMEBUFFER_BINDING

Currently bound framebuffer

0

glGetIntegerv

Hints

OpenGL ES 2.0 uses hints to modify the operation of features, allowing a bias toward either performance or quality. You can specify a preference by calling the following.

void

glHint(GLenum target, GLenum mode)

target

specifies the hint to be set, and must be either

GL_GENERATE_MIPMAP_HINT or

GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES

mode

specifies the operational mode the feature should use. Valid values are GL_FASTEST to specify performance, GL_NICEST to favor quality, or GL_DONT_CARE to reset any preferences to the implementation default

The current value of any hint can be retrieved by calling glGetIntegerv using the appropriate hint enumerated value.

Entity Name Queries

OpenGL ES 2.0 references numerous entities that you define—textures, shaders, programs, vertex buffers, framebuffers, and renderbuffers—by integer names. You can determine if a name is currently in use (and therefore a valid entity) by calling one of the following functions.

GLboolean

glIsTexture(GLuint texture)

GLboolean

glIsShader(GLuint shader)

GLboolean

glIsProgram(GLuint program)

GLboolean

glIsBuffer(GLuint buffer)

GLboolean

glIsRenderbuffer(GLuint renderbuffer)

GLboolean

glIsFramebuffer(GLunit framebuffer)

texture, shader, program, buffer, renderbuffer, framebuffer

specify the name of the respective entity to determine if the name is in use

Nonprogrammable Operations Control and Queries

Much of OpenGL ES 2.0’s rasterization functionality, like blending or back-face culling, is controlled by turning on and off the features you need. The functions controlling the various operations are the following.

void

glEnable(GLenum capability)

capability

specifies the feature that should be turned on and affects all rendering until the feature is turned off

void

glDisable(GLenum capability)

capability

specifies the feature that should be turned off

Additionally, you can determine if a feature is in use by calling the following.

GLboolean

glIsEnabled(GLenum capability)

capability

specifies which feature to determine if it’s enabled

The capabilities controlled by glEnable and glDisable are listed in Table 14-3.

Table 14-3. OpenGL ES 2.0 Capabilities Controlled by glEnable and glDisable

Capability

Description

GL_CULL_FACE

Discard polygons whose vertex winding order is opposite of the specified front-facing mode (GL_CW or GL_CCW, as specified by glFrontFace)

GL_POLYGON_OFFSET_FILL

Offset the depth value of a fragment to aid in rendering coplanar geometry

GL_SCISSOR_TEST

Further restrict rendering to the scissor box

GL_SAMPLE_COVERAGE

Use a fragment’s computed coverage value in multisampling operations

GL_SAMPLE_COVERAGE_TO_ALPHA

Use a fragment’s alpha value as its coverage value in multisampling operations

GL_STENCIL_TEST

Enable the stencil test

GL_DEPTH_TEST

Enable the depth test

GL_BLEND

Enable blending

GL_DITHER

Enable dithering

Shader and Program State Queries

OpenGL ES 2.0 shaders and programs have a considerable amount of state that you can retrieve regarding their configuration, and attributes and uniform variables used by them. There are numerous functions provided for querying the state associated with shaders. To determine the shaders attached to a program, call the following.

void

glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)

program

Specifies the program to query to determine the attached shaders

maxcount

the maximum number of shader names to be returned

count

the actual number of shader names returned

shaders

an array of length maxcount used for storing the returned shader names

To retrieve the source code for a shader, call the following.

void

glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)

shader

specifies the shader to query

bufsize

the number of bytes available in the array source for returning the shader’s source

length

the length of the returned shader string

source

specifies an array of GLchars to store the shader source to

To retrieve a value associated with a uniform variable at a particular uniform location associated with a shader program, call the following.

void

glGetUniformfv(GLuint program, GLint location, GLfloat *params)

void

glGetUniformiv(GLuint program, GLint location, GLint *params)

program

the program to query to retrieve the uniform’s value

location

the uniform location associated with program to retrieve the values for

params

an array of the appropriate type for storing the uniform variable’s values. The associated type of the uniform in the shader determines the number of values returned

Finally, to query the range and precision of OpenGL ES 2.0 shader language types, call the following.

void

glGetShaderPrecisionFormat(GLenum shaderType, GLenum precisionType, GLint *range, GLint *precision)

shaderType

specifies the type of shader, and must be either

GL_VERTEX_SHADER or GL_FRAGMENT_SHADER

precisionType

specifies the precision qualifier type, and must be one of GL_LOW_FLOAT, GL_MEDIUM_FLOAT, GL_HIGH_FLOAT, GL_LOW_INT, GL_MEDIUM_INT, or GL_HIGH_INT

range

is a two-element array that returns the minimum and maximum value for precisionType as a log base-2 number

precision

returns the precision for precisionType as a log base-2 value

Vertex Attribute Queries

State about vertex attribute arrays can also be retrieved from the current OpenGL ES 2.0 context. To obtain the pointer to the current generic vertex attributes for a specific index, call the following.

void

glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)

index

specifies index of the generic vertex attribute array

pname

specifies the parameter to be retrieved, and must be GL_VERTEX_ATTRIB_ARRAY_POINTER

pointer

returns the address of the specified vertex attribute array

The associated state for accessing the data elements in the vertex attribute array such as value type, or stride can be obtained by calling the following.

void

glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)

void

glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)

index

specifies the index of generic vertex attribute array

pname

specifies the parameter to be retrieved, and must be one of GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, GL_VERTEX_ATTRIB_ARRAY_ENABLED, GL_VERTEX_ATTRIB_ARRAY_SIZE, GL_VERTEX_ATTRIB_ARRAY_STRIDE, GL_VERTEX_ATTRIB_ARRAY_TYPE, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, or GL_CURRENT_VERTEX_ATTRIB GL_CURRENT_VERTEX_ATTRIB returns the current vertex attribute as specified by glEnableVertexAttribeArray, and the other parameters are values specified when the vertex attribute pointer is specified by calling glVertexAttribPointer

params

specifies an array of the appropriate type for storing the returned parameter values

Texture State Queries

OpenGL ES 2.0 texture objects store a texture’s image data, along with settings describing how the texels in the image should be sampled. The texture filter state, which includes the minification and magnification texture filters and texture-coordinate wrap modes are state that can be queried from the currently bound texture object. The following call retrieves the texture filter settings.

void

glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params )

void

glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)

target

specifies the texture target, and can either be GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP

pname

specifies the texture filter parameter to be retrieved, and may be GL_TEXTURE_MINIFICATION_FILTER, GL_TEXTURE_MAGNIFICATION_FILTER, GL_TEXTURE_WRAP_S, or GL_TEXTURE_WRAP_T

params

specifies an array of the appropriate type for storing the returned parameter values

Vertex Buffer Queries

Vertex buffer objects have associated state describing the state and usage of the buffer. Those parameters can be retrieved by calling the following.

void

glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)

target

specifies the buffer of the currently bound vertex buffer, and must be one of GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER

pname

specifies the buffer parameter to be retrieved, and must be one of GL_BUFFER_SIZE, GL_BUFFER_USAGE, GL_BUFFER_ACCESS, or GL_BUFFER_MAPPED

params

specifies an integer array for storing the returned parameter values

Additionally, you can retrieve the current pointer address for a mapped buffer by calling the following.

void

glGetBufferPointervOES(GLenum target, GLenum pname, void** params)

target

specifies the buffer of the currently bound vertex buffer, and must be one of GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER

pname

specifies the parameter to retrieve, which must be GL_BUFFER_MAP_POINTER_OES

params

specifies a pointer for storing the returned address

Renderbuffer and Framebuffer State Queries

Characteristics of an allocated renderbuffer can be retrieved by calling the following.

void

glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)

target

specifies the target for the currently bound renderbuffer, and must be GL_RENDERBUFFER

pname

specifies the renderbuffer parameter to retrieve, and must be one of GL_RENDERBUFFER_WIDTH, GL_RENDERBUFFER_HEIGHT, GL_RENDERBUFFER_INTERNAL_FORMAT, GL_RENDERBUFFER_RED_SIZE, GL_RENDERBUFFER_GREEN_SIZE, GL_RENDERBUFFER_BLUE_SIZE, GL_RENDERBUFFER_ALPHA_SIZE, GL_RENDERBUFFER_DEPTH_SIZE, GL_RENDERBUFFER_STENCIL_SIZE

params

specifies an integer array for storing the returned parameter values

Likewise, the current attachments to a framebuffer can be queried by calling the following.

void

glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)

target

specifies the framebuffer target, and must be set to GL_FRAMEBUFFER

attachment

specifies which attachement point to query, and must be one of GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT or GL_STENCIL_ATTACHMENT.

pname

specifies GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE

params

specifies an integer array for storing the returned parameter values

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset