You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include "vertexbuffer.h"
#include "utils.h"
void VertexBuffer::SetSize(int vertexCount) { mVertexCount = vertexCount; mVertexes = new Vertex[mVertexCount]; memset(mVertexes, 0, sizeof(Vertex)*mVertexCount);
//����һ��vbo�������Դ�����һ���ռ�
mVBO = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(Vertex)*mVertexCount, GL_STATIC_DRAW, nullptr); } void VertexBuffer::SetPosition(int index, float x, float y, float z, float w) { mVertexes[index].Position[0] = x; mVertexes[index].Position[1] = y; mVertexes[index].Position[2] = z; mVertexes[index].Position[3] = w; } void VertexBuffer::SetColor(int index, float r, float g, float b, float a) { mVertexes[index].Color[0] = r; mVertexes[index].Color[1] = g; mVertexes[index].Color[2] = b; mVertexes[index].Color[3] = a; } void VertexBuffer::SetTexcoord(int index, float x, float y) { mVertexes[index].Texcoord[0] = x; mVertexes[index].Texcoord[1] = y; } void VertexBuffer::SetNormal(int index, float x, float y, float z) { mVertexes[index].Normal[0] = x; mVertexes[index].Normal[1] = y; mVertexes[index].Normal[2] = z; mVertexes[index].Normal[3] = 1.0; } void VertexBuffer::Bind() { glBindBuffer(GL_ARRAY_BUFFER, mVBO); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex)*mVertexCount, mVertexes);//������д���Դ�
} void VertexBuffer::Unbind() { glBindBuffer(GL_ARRAY_BUFFER, 0); } Vertex& VertexBuffer::Get(int index) { return mVertexes[index]; }
|