Sie sind auf Seite 1von 18

Outline

Display List
Vertex Array
: glDrawArrays
: glDrawElements
Vertex Buffer Object (VBO)

Callback Function

2014/12/18


glBegin(GL_TRIANGLES);
for(int i = 0; i < nTriangles; ++i)
{
glNormal3fv(triArray[i].n);
glVertex3fv(triArray[i].a);
glVertex3fv(triArray[i].b);
glVertex3fv(triArray[i].c);
}
glEnd();

2014/12/18

Display List

Gluint _DisplayList = glGenLists(1);


glNewList(_DisplayList, GL_COMPILE);

(OpenGL)
glEndList();

glCallList(_DisplayList);

glDeleteLists(_DisplayList, 1);

2014/12/18

Display List

Display ListOpenGL

2014/12/18

Display List
Display List
glNewList(A);
glCallList(B);
glTranslatef(1.0, 0.0, 0.0);
glCallList(C);
glTranslatef(1.0, 0.0, 0.0);
glCallList(C);
glEndList();
glNewList/glEndList
glNewList/glEndListglCallList
64OpenGL

glGetIntegerv(GL_MAX_LIST_NESTING, GLint
*data);

2014/12/18

Vertex Array

OpenGL
/

glEnableClintState(Glenum array);
glDisableClientState(Glenum array);

GL_VERTEX_ARRAYGL_NORMAL_ARRAY

Array

glVertexPointer(GLint size, GLenum type,

GLsizei stride, const GLvoid *pointer);

size:234
type:(GL_SHORTGL_INT)
stride:
pointer:

2014/12/18

Vertex Array-

glArrayElement
glDrawElements
glMultiDrawElements
glDrawRangeElements

2014/12/18

glDrawArrays
glMultiDrawArrays

Vertex Array

2014/12/18

Vertex Array (conti.)

2014/12/18

10

Vertex Array-

glArrayElement
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_INT, 0, data);
glBegin(GL_TRIANGLES)
glArrayElement(2);
glArrayElement(5);
glArrayElement(8);
glEnd();

glDrawElements
glDrawElements(mode, count,
type, index);

glBegin(GL_TRIANGLES)
glVertex2iv(data+(2*2));
glVertex2iv(data+(5*2));
glVertex2iv(data+(8*2));
glEnd();

glBegin(mode)
for(i=0; i<count; i++)
glArrayElement(index[i]);
glEnd();

glMultiDrawElements
for(i=0; i<primcount; i++)
if(count[i]>0)
glDrawElements(mode, count[i], type, index[i]);

2014/12/18

11

Vertex Array-

glDrawArrays
glDrawArrays(mode, first,
count);

glBegin(mode)
for(i=0; i<count; i++)
glArrayElement(first+i);
glEnd();

glMultiDrawArrays
for(i=0; i<primcount; i++)
if(count[i])
glDrawArrays(mode, first[i], count[i]);

2014/12/18

12

Vertex Buffer Object (VBO)


VBOOpenGL
vertex data(position, normal
vector, color, etc.)

vertex data
render

OpenGL 1.5

2014/12/18

13

Vertex Buffer Object

Buffer Object
GLuint _VBO[2];
glGenBuffers(2, _VBO);

Buffer Object
glBindBuffer(GLenum target, GLuint buffer);

VertexBuffer Object
glBufferData(...);

Buffer Object
glBufferSubData(...);
glMapBuffer(...)glUnmapBuffer(...)

Buffer Object
glDeleteBuffers(GLsizei n, GLuint *buffer);

2014/12/18

14

Vertex Buffer Object Bind Buffer

glBindBuffer(GLenum target, GLuint buffer);


target: GL_ARRAY_BUFFER

GL_ELEMENT_ARRAY_BUFFER
buffer:Buffer Object (:_VBO[0])

glBindBuffer
bufferUINT
Buffer Object buffer Buffer

Object
Buffer Object
Buffer ObjectActive
buffer
OpenGLBuffer Object

2014/12/18

15

Vertex Buffer Object Buffer Data

glBufferData(GLenum target, GLsizeiptr


size, const GLvoid *data, GLenum usage)

size(byte)OpenGL Device Memory

target:

GL_ARRAY_BUFFER()
GL_ELEMENT_ARRAY_BUFFER()
GL_PIXEL_UNPACK_BUFFER(OpenGL)
GL_PIXEL_PACK_BUFFER(OpenGL)

size:()
data:(Buffer Object)
usage:GL_STATIC_DRAWGL_DYNAMIC_READGL_STREAM_COPY
STATIC:VBO()
DYNAMIC:()
STREAM:Frame()
DRAW:GPU(GL)
READ:(GL )
PBO or FBO
COPY:DRAWREAD(GL GL)

2014/12/18

16

Vertex Buffer Object Update Buffer

void glBufferSubData(GLenum target, GLintptr


offset, GLsizeiptr size, const GLvoid* data);
datatargetoffset

sizebyte

void *glMapBuffer(GLenum target, GLenum


access);
GLboolean glUnmapBuffer(GLenum target);
glMapBufferbuffer
buffer

glUnmapBufferOpenGL

2014/12/18

17

Callback Function

2014/12/18

18