Advertisement
Guest User

Untitled

a guest
Mar 14th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. struct Vertex
  2. {
  3.     Vertex() : position( 0.0f ), texcoord( 0.0f ), color( 1.0f )
  4.     {
  5.     }
  6.  
  7.     glm::vec3 position;
  8.     glm::vec2 texcoord;
  9.     glm::vec4 color;
  10.  
  11.     static unsigned int Size();
  12. };
  13.  
  14. inline unsigned int Vertex::Size()
  15. {
  16.     return sizeof( Vertex );
  17. }
  18.  
  19. namespace VertexAttribute
  20. {
  21. const unsigned int P_LOC = 0;
  22. const unsigned int T_LOC = 1;
  23. const unsigned int C_LOC = 2;
  24.  
  25. const unsigned int P_OFFSET = offsetof( Vertex, position );
  26. const unsigned int T_OFFSET = offsetof( Vertex, texcoord );
  27. const unsigned int C_OFFSET = offsetof( Vertex, color );
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. glEnableVertexAttribArray( 0 ) // в шейдере это будет layout(location = 0) in vec3 inVertex;
  36. glVertexAttribPointer( VertexAttribute::P_LOC, sizeof( vec3 ), GL_FLOAT, GL_FALSE, Vertex::Size(), VertexAttribute:P_OFFSET );
  37.  
  38. glEnableVertexAttribArray( 1 ) // в шейдере это будет layout(location = 1) in vec2 inTexCoord;
  39. glVertexAttribPointer( VertexAttribute::T_LOC, sizeof( vec2 ), GL_FLOAT, GL_FALSE, Vertex::Size(), VertexAttribute::T_OFFSET );
  40.  
  41. glEnableVertexAttribArray( 2 ) // в шейдере это будет layout(location = 2) in vec4 inColor;
  42. glVertexAttribPointer( VertexAttribute::C_LOC, sizeof( vec4 ), GL_FLOAT, GL_FALSE, Vertex::Size(), VertexAttribute::C_OFFSET  );
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement