Advertisement
Guest User

VAO

a guest
Aug 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. unsigned int offset = 0;
  2.     unsigned int multiplier = 3;
  3.     if (hasTextCoord) {
  4.         multiplier += 2;
  5.     }
  6.     if (hasNormCoord) {
  7.         multiplier += 3;
  8.     }
  9.     if (normalMapping) {
  10.         multiplier += 6;
  11.     }
  12.  
  13.     glGenVertexArrays(1, &VAO);
  14.     glGenBuffers(1, &VBO);
  15.  
  16.     glBindVertexArray(VAO);
  17.  
  18.     glBindBuffer(GL_ARRAY_BUFFER, VBO);
  19.     glBufferData(GL_ARRAY_BUFFER, meshData.amountVertices * sizeof(GLfloat), &meshData.vertices[0], GL_STATIC_DRAW);
  20.  
  21.     // set the vertices
  22.     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, multiplier * sizeof(GLfloat), (GLvoid*)offset);
  23.     glEnableVertexAttribArray(0);
  24.     offset += 3;
  25.     // set the textCoordinates
  26.     if (hasTextCoord && enableTextCoord) {
  27.         glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, multiplier * sizeof(GLfloat), (GLvoid*)(offset * sizeof(GLfloat)));
  28.         glEnableVertexAttribArray(1);
  29.         offset += 2;
  30.     }
  31.     else if (hasTextCoord && !enableTextCoord) {
  32.         offset += 2;
  33.     }
  34.     // set the normalCoordinates
  35.     if (hasNormCoord && enableNormCoord) {
  36.         glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, multiplier * sizeof(GLfloat), (GLvoid *)(offset * sizeof(GLfloat)));
  37.         glEnableVertexAttribArray(2);
  38.         offset += 3;
  39.     }
  40.     else if (hasNormCoord && !enableNormCoord) {
  41.         offset += 3;
  42.     }
  43.     if (normalMapping) {
  44.         // set the tangent
  45.         glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, multiplier * sizeof(GLfloat), (GLvoid *)(offset * sizeof(GLfloat)));
  46.         glEnableVertexAttribArray(3);
  47.         offset += 3;
  48.         // set the bitangent
  49.         glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, multiplier * sizeof(GLfloat), (GLvoid *)(offset * sizeof(GLfloat)));
  50.         glEnableVertexAttribArray(4);
  51.         offset += 3;
  52.     }
  53.     glBindVertexArray(0);
  54.     this->amountVertices = meshData.amountVertices;
  55.     delete meshData.vertices;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement