OZone3D OpenGL Vertex Buffer Objects 3/3

3 - References

3.1. Buffers Usage

 STREAM1DYNAMIC1STATIC1
DRAW1GL_STREAM_DRAWGL_DYNAMIC_DRAWGL_STATIC_DRAW
READ2GL_STREAM_READGL_DYNAMIC_READGL_STATIC_ READ
COPY2GL_STREAM_COPYGL_DYNAMIC_COPYGL_STATIC_COPY

1: It is available with all OpenGL 1.5 graphics card and all the ones that support GL_ARB_vertex_buffer_object extension

2: There are none available yet; this could change with the release of nVidia G80 and ATI R600.

3.2. Rendering Functions

3.2.1. glArrayElement (deprecated)

This function is obsolete because it comes from the immediate mode.

GLvoid glArrayElement(GLint i);

Draw the ith vertex of an array and could be used in immediate mode like this:

glColorPointer(3, GL_FLOAT, 0, Colors);
glVertexPointer(3, GL_FLOAT, 0, Positions);

glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glBegin(GL_TRIANGLES);
    glArrayElement(0);
    glArrayElement(1);
    glArrayElement(2);
glEnd();

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

Witch corresponds to the following sequence of functions:

glBegin(GL_TRIANGLES);
    glColor3fv(Colors + 0 * 3);
    glVertex3fv(Positions + 0 * 3);
    glColor3fv(Colors + 1 * 3);
    glVertex3fv(Positions + 1 * 3);
    glColor3fv(Colors + 2 * 3);
    glVertex3fv(Positions + 2 * 3);
glEnd();

3.2.2. glDrawElements

Draw a set of geometric primitives according to an index array composed by count indexes.

GLvoid glDrawElements(GLenum mode, GLsizei count, GLenum type, GLvoid* indices)
{
    glBegin(mode);
    for(GLint i = 0; i < count; ++i)
        glArrayElement(indices[i]);
    glEnd();
}

3.2.3. glDrawRangeElements

Draw a set of geometric primitives according to an index array by keeping only indexes between start and end included.

GLvoid glDrawRangeElements(GLenum mode, GLuint start, GLuint end, 
GLsizei count, GLenum type, GLvoid* indices)
{
    glBegin(mode);
    for(GLint i = 0; i < count; ++i)
        if(indices[i] >= start && indices[i] <= end)
            glArrayElement(indices[i]);
    glEnd();
}

3.2.4. glDrawArrays

Draw a set of geometric primitives composed by count vertices starting by (and including) the first element.

GLvoid glDrawArrays(GLenum mode, GLint first, GLsizei count)
{
    glBegin(mode);
    for(GLint i = 0; i < count; ++i)
        glArrayElement(first + i);
    glEnd();
}

3.2.5. glMultiDrawArrays

Draw a set of geometric primitives composed by count vertices starting by (and including) the first element.

GLvoid glMultiDrawArrays(GLenum mode, GLint* first, GLsizei* count, 
GLsizei primcount)
{
    for(GLint i = 0; i < primcount; ++i)
    {
        if(count[i] > 0)
            glDrawArrays(mode, first[i], count[i]);
    }
}

3.2.6. glMultiDrawElements

Draw a set of geometric primitives describe by a set of index arrays.

GLvoid glMultiDrawElements(GLenum mode, GLsizei* count, GLenum type,
GLvoid** indices, GLsizei primcount)
{
    for(GLint i = 0; i < primcount; ++i)
    {
        if(count[i]) > 0)
            glDrawElements(mode, count[i], type, indices[i]);
    }
}

3.3. Array Types

3.3.1. Fixed pipeline types of array

Specify the fixed pipeline array that we want to enable or to disable:

GLvoid glEnableClientState(GLenum array);
GLvoid glDisableClientState(GLenum array);

Specify the fixed pipeline array that we want to enable or to disable:

  • GL_VERTEX_ARRAY
  • GL_NORMAL_ARRAY
  • GL_COLOR_ARRAY
  • GL_SECONDARY_COLOR_ARRAY
  • GL_INDEX_ARRAY
  • GL_EDGE_FLAG_ARRAY
  • GL_FOG_COORD_ARRAY
  • GL_TEXTURE_COORD_ARRAY

3.3.2. Shader pipeline types of array

Specify the shader pipeline array that we want to enable or disable:

GLvoid glEnableVertexAttribArray(GLuint index);
GLvoid glDisableVertexAttribArray(GLuint index);

index is an identifier of attribute variable.

3.4. Arrays Data

3.4.1. Description of fixed pipeline data

Since OpenGL 1.1 and GL_EXT_vertex_array and GL_ARB_vertex_buffer_object:

GLvoid glVertexPointer(GLint size, GLenum type, GLsizei stride, GLvoid* pointer);
GLvoid glNormalPointer(GLenum type, GLsizei stride, GLvoid* pointer);
GLvoid glColorPointer(GLint size, GLenum type, GLsizei stride, GLvoid* pointer);
GLvoid glEdgeFlagPointer(GLsizei stride, GLvoid* pointer);
GLvoid glTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLvoid* pointer);

The function glIndexPointer is useless with Vertex Buffer Objects.

GLvoid glIndexPointer(GLenum type, GLsizei stride, GLvoid* pointer);

Since OpenGL 1.4 and GL_EXT_secondary_color :

GLvoid glSecondaryColorPointer(GLint size, GLenum type, GLsizei stride, 
GLvoid* pointer);

Since OpenGL 1.4 and GL_EXT_fog_coord :

GLvoid glFogCoordPointer(GLenum type, GLsizei stride, GLvoid* pointer);

3.4.2. Description of the whole data (Obsolete)

The glInterleavedArrays function implicated the use of array with predefined structure which is annoying and not adapted to multitexturing or shader based rendering. It is obsolete since OpenGL 1.3 and GL_ARB_multitexture. Moreover, the VBOs solution to manage interleaved array is really better because it fixes both issues.

GLvoid glInterleavedArrays(GLenum format, GLsizei stride, GLvoid* pointer);

3.4.3. Description of shader pipeline data

All attributes defined by the fixed pipeline are available in the OpenGL vertex shaders. If the user wants to send customized attributes, he can create a new attributes variable. Then, the data will be sent to the vertex shaders by using the glVertexAttribPointer function.

GLvoid glVertexAttribPointer(GLuint index, GLint size, GLenum type, 
GLboolean normalized, GLsizei stride, const GLvoid* pointer);

OpenGL ES doesn’t support fixed pipeline attributes. Consequently, it’s necessary to use customized attributes and glVertexAttribPointer for all the attributes. This approach can be used with OpenGL as well and it seems that it will be generalized in the future especially with OpenGL LM. This method increases flexibility and code sturdiness for a whole shader design. nVidia drivers are ready but not yet the ATI ones. The CTest5 class among the examples shows that difference between ATI and nVidia.

3.5. Types of Primitive

  • GL_POINTS : Points.
  • GL_LINES : List of independent segments.
  • GL_LINE_STRIP : Single line formed by a list of segments..
  • GL_LINE_LOOP : Single line formed by a list of segments that loops.
  • GL_TRIANGLES : List of independent triangles.
  • GL_TRIANGLE_STRIP : List of triangles that forms a strip.
  • GL_TRIANGLE_FAN : Create a fan using the first vertex as reference for all triangles.
  • GL_QUADS : List of independent quadrilateral.
  • GL_QUAD_STRIP : List of quadrilateral that forms a strip.
  • GL_POLYGON : Convex polygon.


4 - Further Reading

A topic is availbale on the oZone3D.Net's forums: [TUTO] OpenGL VBO.



5 - Downloads


VBO C++ / OpenGL Code Samples / CTest Classes - (1964k)
Last update: October 6, 2006

XPGL - Mesh Twister - OpenGL / VBO / GLSL - Visual C++ 6.0 Project - (1105k)
Mise à jour: 11 Octobre 2006
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值