Pro OpenGL ES for iOS

(singke) #1

324 CHAPTER 10: OpenGL ES 2, Shaders, and...^


memcpy(&startData->xyz,vtxPtr,xyzSize); //geometry
memcpy(&startData->nxyz,norPtr,nxyzSize); //normals
memcpy(&startData->rgba,colPtr,rgbaSize); //colors
memcpy(&startData->st,textPtr,textSize); //texture coords

startData++;

vtxPtr+=NUM_XYZ_ELS;
norPtr+=NUM_NXYZ_ELS;
colPtr+=NUM_RGBA_ELS;
textPtr+=NUM_ST_ELS;
}
}

-(void)createVAO
{
GLuint numBytesPerXYZ,numBytesPerNXYZ,numBytesPerRGBA;
GLuint structSize=sizeof(struct VAOInterleaved);

[self createInterleavedData];

//note that the context is set in the in the parent object

glGenVertexArraysOES(1, &m_VertexArrayName);
glBindVertexArrayOES(m_VertexArrayName);

numBytesPerXYZ=sizeof(GL_FLOAT)*NUM_XYZ_ELS;
numBytesPerNXYZ=sizeof(GL_FLOAT)*NUM_NXYZ_ELS;
numBytesPerRGBA=sizeof(GL_FLOAT)*NUM_RGBA_ELS;

glGenBuffers(1, &m_VertexBufferName);
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBufferName);
glBufferData(GL_ARRAY_BUFFER, sizeof(struct VAOInterleaved)*m_NumVertices,
m_InterleavedData, GL_STATIC_DRAW);

glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, NUM_NXYZ_ELS, GL_FLOAT, GL_FALSE,
structSize, BUFFER_OFFSET(numBytesPerXYZ));

glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, NUM_RGBA_ELS, GL_FLOAT,
GL_FALSE, structSize, BUFFER_OFFSET(numBytesPerNXYZ+numBytesPerXYZ));

glEnableVertexAttribArray(GLKVertexAttribTexCoord0);

glVertexAttribPointer(GLKVertexAttribTexCoord0,NUM_ST_ELS, GL_FLOAT, GL_FALSE,
structSize,
BUFFER_OFFSET(numBytesPerNXYZ+numBytesPerXYZ+numBytesPerRGBA));
}
Free download pdf