title: Optimizing OpenGL rendering
body: <p>I ran into a poor performance problem when rendering to OpenGL using Assimp. The scene has 367727 triangles. At the same time, 298084 is a model of chess. I do not think that the problem is in shaders, because:</p>
  
  <p>128x128 window: 44 (43.7657) FPS, 22.849 ms</p>
  
  <p>256x256 window: 42 (40.9563) FPS, 24.4162 ms</p>
  
  <p>512x512 window: 35 (34.8007) FPS, 28.7351 ms</p>
  
  <p>1024x1024 window: 22 (21.084) FPS, 47.4293 ms</p>
  
  <p>But if I don’t draw chess, then in the window 1366x763: 55 (54.8424) FPS, 18.2341 ms</p>
  
  <p>Also, changing the resolution of the shadow map does not greatly affect the FPS.</p>
  
  <p>There are 2 point light sources on the scene, with FPS loss when drawing this model for each of the passes ~10 FPS (from 23 to 55). Ie, there is no difference where I draw this model: in the depth map or in the "color texture". Losses ~ are the same. I load the model with the following parameters: <code>aiProcess_Triangulate | aiProcess_CalcTangentSpace | aiProcess_JoinIdenticalVertices</code></p>
  
  <p>And render as follows:</p>
  
  <pre><code>inline void pointer(GLint location, int count, GLuint buffer) {
      glBindBuffer(GL_ARRAY_BUFFER, buffer);
      glVertexAttribPointer(
          location, // attribute location
          count,    // count (1, 2, 3 or 4)
          GL_FLOAT, // type
          GL_FALSE, // is normalized?
          0,        // step
          nullptr   // offset
      );
  }
  
  inline void pointerui(GLint location, int count, GLuint buffer) {
      glBindBuffer(GL_ARRAY_BUFFER, buffer);
      glVertexAttribIPointer(
          location, // attribute location
          count,    // count (1, 2, 3 or 4)
          GL_UNSIGNED_INT, // type
          0,        // step
          nullptr   // offset
      );
  }
  ...
  pointer(cs.inPosition, 3, model.shape-&gt;meshes[i].getVerticesBuffer());
  pointer(cs.inNormal, 3, model.shape-&gt;meshes[i].getNormalsBuffer());
  pointer(cs.inTangent, 3, model.shape-&gt;meshes[i].getTangentsBuffer());
  pointer(cs.inBitangent, 3, model.shape-&gt;meshes[i].getBitangentsBuffer());
  pointer(cs.inTexCoord, 2, model.shape-&gt;meshes[i].getTexCoordsBuffer());
  
  if (model.shape-&gt;bonesPerVertex != 0) {
      pointer(cs.inBoneWeights, 4, model.shape-&gt;meshes[i].getBoneWeightsBuffer());
      pointerui(cs.inBoneIds, 4, model.shape-&gt;meshes[i].getBoneIdsBuffer());
  }
  
  modelMatrix = &amp;model.transformation;
  updateMatrices();
  
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model.shape-&gt;meshes[i].getIndicesBuffer());
  glDrawElements(GL_TRIANGLES, model.shape-&gt;meshes[i].indices.size(), GL_UNSIGNED_INT, nullptr)
  </code></pre>
  
  <p>Here is the scene itself:
  <a href="https://i.stack.imgur.com/o0JoU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o0JoU.png" alt="scene"></a></p>
  
  <p><strong>EDIT</strong>: <a href="https://codeshare.io/50Z8Pl" rel="nofollow noreferrer">vertex_shader.glsl</a>, <a href="https://codeshare.io/5MKXwQ" rel="nofollow noreferrer">fragment_shader.glsl</a></p>
  
  <p><em>I apologize that the fragment shader is difficult to read, I have not yet fully completed work on it</em></p>
  
  <p>My GPU is NVGF 920mx</p>
  
  <p><strong>EDIT</strong>: here is <a href="https://mega.nz/#!JlURQYpa!fq_dPKzFWU3lrvaV757h5Fu4RyfQWuvaOA1ozx3dWYU" rel="nofollow noreferrer">capture</a> from renderdoc</p>