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.

41 lines
1.4 KiB

4 years ago
  1. #include "vertexbuffer.h"
  2. #include "utils.h"
  3. void VertexBuffer::SetSize(int vertexCount) {
  4. mVertexCount = vertexCount;
  5. mVertexes = new Vertex[mVertexCount];
  6. memset(mVertexes, 0, sizeof(Vertex)*mVertexCount);
  7. //����һ��vbo�������Դ�����һ���ռ�
  8. mVBO = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(Vertex)*mVertexCount, GL_STATIC_DRAW, nullptr);
  9. }
  10. void VertexBuffer::SetPosition(int index, float x, float y, float z, float w) {
  11. mVertexes[index].Position[0] = x;
  12. mVertexes[index].Position[1] = y;
  13. mVertexes[index].Position[2] = z;
  14. mVertexes[index].Position[3] = w;
  15. }
  16. void VertexBuffer::SetColor(int index, float r, float g, float b, float a) {
  17. mVertexes[index].Color[0] = r;
  18. mVertexes[index].Color[1] = g;
  19. mVertexes[index].Color[2] = b;
  20. mVertexes[index].Color[3] = a;
  21. }
  22. void VertexBuffer::SetTexcoord(int index, float x, float y) {
  23. mVertexes[index].Texcoord[0] = x;
  24. mVertexes[index].Texcoord[1] = y;
  25. }
  26. void VertexBuffer::SetNormal(int index, float x, float y, float z) {
  27. mVertexes[index].Normal[0] = x;
  28. mVertexes[index].Normal[1] = y;
  29. mVertexes[index].Normal[2] = z;
  30. mVertexes[index].Normal[3] = 1.0;
  31. }
  32. void VertexBuffer::Bind() {
  33. glBindBuffer(GL_ARRAY_BUFFER, mVBO);
  34. glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex)*mVertexCount, mVertexes);//������д���Դ�
  35. }
  36. void VertexBuffer::Unbind() {
  37. glBindBuffer(GL_ARRAY_BUFFER, 0);
  38. }
  39. Vertex& VertexBuffer::Get(int index) {
  40. return mVertexes[index];
  41. }