title: Vertex attributes - using short instead of float for vertex positions
body: <p>Currently I have following setup which is working fine for far.</p>
  
  <pre><code>struct Vertex {
      glm::vec3 position;
      glm::vec3 normal;
      glm::vec2 texCoord;
  }
  std::vector&lt;Vertex&gt; vertices;
  </code></pre>
  
  <p>The Vertex-Attributes:</p>
  
  <pre><code>glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex, Vertex::position)); 
  glEnableVertexAttribArray(1);
  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex, Vertex::normal));
  glEnableVertexAttribArray(2);
  glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex, Vertex::texCoord));
  </code></pre>
  
  <p>Now I want to increase my performance by changing the vertex attributes to from float to short.
  I tried to start with the vertex positions.</p>
  
  <p><a href="https://www.opengl.org/wiki/Vertex_Specification_Best_Practices" rel="nofollow noreferrer">OpenGL's Vertex Specification Best Practices</a> tells me this:</p>
  
  <blockquote>
    <p><strong>Positions</strong> [...]
    To do this, you rearrange your model space data so that all positions are packed in a [-1, 1] box around the origin. You do that by finding the min/max values in XYZ among all positions. Then you subtract the center point of the min/max box from all vertex positions; followed by scaling all of the positions by half the width/height/depth of the min/max box. You need to keep the center point and scaling factors around.
    When you build your model-to-view matrix (or model-to-whatever matrix), you need to apply the center point offset and scale at the top of the transform stack (so at the end, right before you draw).</p>
  </blockquote>
  
  <p>I also read this <a href="https://stackoverflow.com/questions/11678986/using-glshort-instead-of-glfloat-for-vertices">Thread</a>.</p>
  
  <p>That's why I added this preprocessing step mapping all vertices to [-1,1]</p>
  
  <pre><code>for (auto&amp; v : vertices) {
      v.position = (v.position - center) * halfAxisLengths;
  }
  </code></pre>
  
  <p>and recale it in the vertex-shader</p>
  
  <pre><code>vec4 rescaledPos = vec4(in_pos, 1.0) * vec4(halfAxisLengths, 1.0) + vec4(center, 0.0);
  gl_Position = P * V * M * rescaledPos;
  </code></pre>
  
  <p>My vertex attribute using <code>GL_SHORT</code> instead of <code>GL_FLOAT</code>, and normalize set to <code>GL_TRUE</code>:</p>
  
  <pre><code>glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 3, GL_SHORT, GL_TRUE, sizeof(Vertex), (void*) offsetof(Vertex, Vertex::position));
  </code></pre>
  
  <p>As result I just get a chaos of triangles, but not my model with increased fps.</p>
  
  <p>Is this the correct way to set vertex attributes to short?</p>
  
  <p>Or do I have to change my complete Vertex structure?
  If yes, what's the best way to do this (glm vectors with shorts?).</p>
  
  <p>An working example would be great, I couldn't find any.</p>