现在的位置: 首页 > 综合 > 正文

opengles2.0 programming guide: attribute

2018年02月06日 ⁄ 综合 ⁄ 共 2880字 ⁄ 字号 评论关闭

Performance Hints

How to store different attributes of a vertex
We described the two most common ways of storing vertex attributes—
array of structures and structure of arrays. The question to ask is which allocation
method would be the most efficient for OpenGL ES 2.0 hardware
implementations. The answer is array of structures. The reason is that the
attribute data for each vertex can be read in sequential fashion and so will
most likely result in an efficient memory access pattern. A disadvantage of
using array of structures is when an application wants to modify specific
attributes. If a subset of vertex attribute data needs to be modified (e.g., texture
coordinates), this will result in strided updates to the vertex buffer.
When vertex buffer is supplied as a buffer object, the entire vertex attribute
buffer will need to be reloaded. One can avoid this inefficiency by storingvertex attributes that are dynamic in nature in a separate buffer
.

Which data format to use for vertex attributes
The vertex attribute data format specified by the type argument in
glVertexAttribPointer cannot only impact the graphics memory
storage requirements for vertex attribute data, but can also impact the
overall performance, which is a function of memory bandwidth required to
render the frame(s). The smaller the data footprint, the lower the memory
bandwidth required. Our recommendation is that applications should use
GL_HALF_FLOAT_OES wherever possible. Texture coordinates, normals,
binormals, tangent vectors, and so on are good candidates to be stored
using GL_HALF_FLOAT_OES for each component. Color could be stored as
GL_UNSIGNED_BYTE with four components per vertex color. We also recommend
GL_HALF_FLOAT_OES for vertex position, but recognize that this
might not be possible for quite a few cases. For such cases, the vertex position

could be stored as GL_FLOAT or GL_FIXED.

The commands glEnableVertexAttribArray and glDisableVertexAttribArray are used to enable and disable a generic vertex attribute array.
If the vertex attribute array is disabled for a generic attribute index, the constant vertex attribute data specified for that index will be used.

Vertex attributes declared as mat2,mat3, or mat4 will count as two, three, or four vec4 attributes, respectively.
Unlike uniform and varying variables, which get packed automatically by the compiler,attributes do not get packed

Each component is stored internally by the implementation as a 32-bit single precision floating-point
value. Please consider carefully when declaring vertex attributes with sizes
less than vec4, as the maximum number of vertex attributes available is a
limited resource. It might be better to pack them together into one vec4
attribute instead of declaring them as individual vertex attributes in the vertex
shader.


Missing OpenGL ES Buffer Usage Enums Supported by OpenGL
Note: The GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_READ,
GL_DYNAMIC_COPY, GL_STREAM_READ, and GL_STREAM_COPY enums
supported by OpenGL are not defined by OpenGL ES.
This is because
these enums imply that the data store contents will be specified by
reading data from the GL. OpenGL allows applications to read the
contents of the vertex buffer storage but these API calls are missing
from OpenGL ES. As there is no mechanism to read buffer data in
OpenGL ES, these enums are no longer valid and are therefore not
supported.

【上篇】
【下篇】

抱歉!评论已关闭.