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.
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.
|
|
| specifies the parameter to be returned. Can be one of |
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.
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.
|
|
|
|
|
|
specifies the implementation-specific parameter to be queried | |
| 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 |
---|---|---|---|
| Current size of the viewport |
| |
| Current depth range values | (0, 1) |
|
| Current line width | 1.0 |
|
| Current face mode for polygon culling |
|
|
| Current vertex ordering for specifying a front-facing polygon |
|
|
| Current polygon offset factor value | 0 |
|
| Current polygon offset units value | 0 |
|
| Current multisample coverage value | 1 |
|
| Current value of multisample inversion flag |
|
|
| Current color buffer writemask value |
|
|
| Current depth buffer writemask value |
|
|
| Current stencil buffer writemask value | 1s |
|
| Current back stencil buffer writemask value | 1s |
|
| Current color buffer clear value | (0, 0, 0, 0) |
|
| Current depth buffer clear value | 1 |
|
| Current stencil buffer clear value | 0 |
|
| Number of subpixel bits supported | 4 |
|
| Maximum size of a texture | 64 |
|
| Maximum dimension of a cubemap texture | 16 |
|
| Dimensions of the maximum supported viewport size |
| |
| Range of aliased point sizes | 1, 1 |
|
| Range of aliased line width sizes | 1, 1 |
|
| Number of compressed texture formats supported |
| |
| Compressed texture formats supported |
| |
| Number of red bits in current color buffer |
| |
| Number of green bits in current color buffer |
| |
| Number of blue bits in current color buffer |
| |
| Number of alpha bits in current color buffer |
| |
| Number of bits in the current depth buffer | 16 |
|
| Number of stencil bits in current stencil buffer | 8 |
|
| Data type for pixel components for pixel read operations |
| |
| Pixel format for pixel read operations |
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 |
---|---|---|---|
| Currently bound vertex attribute array binding | 0 |
|
| Currently bound element array binding | 0 |
|
| Current face culling mode |
|
|
| Current front-facing vertex winding mode |
|
|
| Current value specified for multisampling sample coverage value | 1 |
|
| Current multisampling coverage value inversion setting |
|
|
| Current 2D texture binding | 0 |
|
| Current cubemap texture binding | 0 |
|
| Current texture unit | 0 |
|
| Color buffer writable |
|
|
| Depth buffer writable |
|
|
| Current write mask for front-facing polygons | 1 |
|
| Current write mask for back-facing polygons | 1 |
|
| Current color buffer clear value | 0, 0, 0, 0 |
|
| Current depth buffer clear value | 1 |
|
| Current stencil buffer clear value | 0 |
|
| Current offset and dimensions of the scissor box | 0, 0, w, h |
|
| #Current stencil test operator function |
|
|
| Current stencil test value mask | 1s |
|
| Current stencil test reference value | 0 |
|
| Current operation for stencil test failure |
|
|
| Current operation for when the stencil test passes, but the depth test fails |
|
|
| Current operation when both the stencil and depth tests pass |
|
|
| Current back-facing stencil test operator function |
|
|
| Current back-facing stencil test value mask | 1s |
|
| Current back-facing stencil test reference value | 0 |
|
| Current operation for back-facing stencil test failure |
|
|
| Current operation for when the back-facing stencil test passes, but the depth test fails |
|
|
| Current operation when both the back-facing stencil and depth tests pass |
|
|
| Current depth test comparison function |
|
|
| Current source RGB blending coefficient |
|
|
| Current source alpha blending coefficient |
|
|
| Current destination RGB blending coefficient |
|
|
| Current destination alpha blending coefficient |
|
|
| Current blend equation operator |
|
|
| Current RGB blend equation operator |
|
|
| Current alpha blend equation operator |
|
|
| Current blend color | 0, 0, 0, 0 |
|
| Current byte boundary alignment for pixel unpacking | 4 |
|
| Current byte boundary alignment for pixel packing | 4 |
|
| Currently bound shader program | 0 |
|
| Currently bound renderbuffer | 0 |
|
| Currently bound framebuffer | 0 |
|
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.
| |
| specifies the hint to be set, and must be either |
| |
| |
| specifies the operational mode the feature should use. Valid values are |
The current value of any hint can be retrieved by calling glGetIntegerv
using the appropriate hint enumerated value.
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.
|
|
|
|
|
|
|
|
|
|
|
|
| specify the name of the respective entity to determine if the name is in use |
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.
|
|
| specifies the feature that should be turned on and affects all rendering until the feature is turned off |
|
|
| specifies the feature that should be turned off |
Additionally, you can determine if a feature is in use by calling the following.
|
|
| 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 |
---|---|
| Discard polygons whose vertex winding order is opposite of the specified front-facing mode ( |
| Offset the depth value of a fragment to aid in rendering coplanar geometry |
| Further restrict rendering to the scissor box |
| Use a fragment’s computed coverage value in multisampling operations |
| Use a fragment’s alpha value as its coverage value in multisampling operations |
| Enable the stencil test |
| Enable the depth test |
| Enable blending |
| Enable dithering |
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.
|
|
| Specifies the program to query to determine the attached shaders |
| the maximum number of shader names to be returned |
| the actual number of shader names returned |
| an array of length maxcount used for storing the returned shader names |
To retrieve the source code for a shader, call the following.
|
|
| specifies the shader to query |
| the number of bytes available in the array source for returning the shader’s source |
| the length of the returned shader string |
| 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.
|
|
|
|
| the program to query to retrieve the uniform’s value |
| the uniform location associated with program to retrieve the values for |
| 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.
|
|
specifies the type of shader, and must be either | |
| |
| specifies the precision qualifier type, and must be one of |
| is a two-element array that returns the minimum and maximum value for |
| returns the precision for |
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.
|
|
| specifies index of the generic vertex attribute array |
| specifies the parameter to be retrieved, and must be |
| 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.
|
|
|
|
specifies the index of generic vertex attribute array | |
| specifies the parameter to be retrieved, and must be one of |
| specifies an array of the appropriate type for storing the returned parameter values |
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.
|
|
|
|
| specifies the texture target, and can either be |
| specifies the texture filter parameter to be retrieved, and may be |
| specifies an array of the appropriate type for storing the returned parameter values |
Vertex buffer objects have associated state describing the state and usage of the buffer. Those parameters can be retrieved by calling the following.
|
|
| specifies the buffer of the currently bound vertex buffer, and must be one of |
| specifies the buffer parameter to be retrieved, and must be one of |
| 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.
|
|
| specifies the buffer of the currently bound vertex buffer, and must be one of |
| specifies the parameter to retrieve, which must be |
| specifies a pointer for storing the returned address |
Characteristics of an allocated renderbuffer can be retrieved by calling the following.
| |
| specifies the target for the currently bound renderbuffer, and must be |
| specifies the renderbuffer parameter to retrieve, and must be one of |
| specifies an integer array for storing the returned parameter values |
Likewise, the current attachments to a framebuffer can be queried by calling the following.
|
|
| specifies the framebuffer target, and must be set to |
| specifies which attachement point to query, and must be one of |
| specifies |
| specifies an integer array for storing the returned parameter values |