OZone3D OpenGL Vertex Buffer Objects 3/3

翻译 2012年03月21日 14:06:04
3 - References

3.1. Buffers Usage

  STREAM1 DYNAMIC1 STATIC1
DRAW1 GL_STREAM_DRAW GL_DYNAMIC_DRAW GL_STATIC_DRAW
READ2 GL_STREAM_READ GL_DYNAMIC_READ GL_STATIC_ READ
COPY2 GL_STREAM_COPY GL_DYNAMIC_COPY GL_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

相关文章推荐

OZone3D OpenGL Vertex Buffer Objects 1/3

原文地址http://www.ozone3d.net/tutorials/opengl_vbo.php OpenGL Vertex Buffer Objects By Christ...

OZone3D OpenGL Vertex Buffer Objects 2/3

2 - Practice For each sub-part of the practice part, there is an associated class in the sample...

《基于MFC的OpenGL编程》Part3 Drawing Simple 3D objects

《基于MFC的OpenGL编程》Part 3 Drawing Simple 3D objects 视见体 Viewing Volume is nothing but the region of 3D...

OpenGL ES2.0 Programming Guide - chapter 6:Vertex attributes, vertex array and buffer objects

chapter 6:Vertex attributes, vertex array and buffer objects

Android Lesson Seven: An Introduction to Vertex Buffer Objects (VBOs)

原文链接地址:http://www.learnopengles.com/android-lesson-seven-an-introduction-to-vertex-buffer-objects-vb...
  • incanus
  • incanus
  • 2012年06月02日 13:23
  • 1708

android opengles 3.0 学习(一):顶点绘制法 VBOs(Vertex Buffer Objects)

本文主要介绍android中opengl es 3.0的开发,通过一个例子介绍VBO顶点缓存法绘制图形,适合入门的同学。目前只有android系统中只有android 4.3或以上支持opengles...
  • lvjing2
  • lvjing2
  • 2013年09月21日 19:33
  • 2831

OpenGL.Project.3 Bezier in 3d Space

OpenGL project

opengl在mfc环境下 读取3dmax文件画3d

  • 2010年06月01日 11:42
  • 1.89MB
  • 下载

OpenGL Programming Guide- Red Book 例子程序库 -系列- 3-Chapter 2Drawing Geometric Objects-Part1

Example 2-1 : Using Line Stipple Patterns: lines.c 原始程序
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:OZone3D OpenGL Vertex Buffer Objects 3/3
举报原因:
原因补充:

(最多只允许输入30个字)