Browse Source

render only given data instead of the whole buffer, init texture renderer instantly if wanted

Kajetan Johannes Hammerle 5 years ago
parent
commit
ef6c4ffa3f
1 changed files with 27 additions and 13 deletions
  1. 27 13
      src/me/hammerle/snuviengine/api/TextureRenderer.java

+ 27 - 13
src/me/hammerle/snuviengine/api/TextureRenderer.java

@@ -17,23 +17,37 @@ public class TextureRenderer
     
     
     private boolean built = false;
     private boolean built = false;
     
     
-    public TextureRenderer(int triangles)
+    public TextureRenderer(int triangles, boolean initDelayed)
     {
     {
         buffer = BufferUtils.createFloatBuffer(triangles * 12);
         buffer = BufferUtils.createFloatBuffer(triangles * 12);
-        Shader.addTask(() -> 
+        if(initDelayed)
+        {
+            Shader.addTask(() -> init());
+        }
+        else
         {
         {
-            vao = glGenVertexArrays();
-            vbo = glGenBuffers();
+            init();
+        }
+    }
+    
+    private void init()
+    {   
+        vao = glGenVertexArrays();
+        vbo = glGenBuffers();
 
 
-            GLHelper.glBindVertexArray(vao);
-            GLHelper.glBindBuffer(vbo);
+        GLHelper.glBindVertexArray(vao);
+        GLHelper.glBindBuffer(vbo);
 
 
-            glEnableVertexAttribArray(0);
-            glVertexAttribPointer(0, 2, GL_FLOAT, false, 16, 0);
+        glEnableVertexAttribArray(0);
+        glVertexAttribPointer(0, 2, GL_FLOAT, false, 16, 0);
 
 
-            glEnableVertexAttribArray(1);  
-            glVertexAttribPointer(1, 2, GL_FLOAT, false, 16, 8);
-        });
+        glEnableVertexAttribArray(1);  
+        glVertexAttribPointer(1, 2, GL_FLOAT, false, 16, 8);
+    }
+    
+    public TextureRenderer(int triangles)
+    {
+        this(triangles, true);
     }
     }
     
     
     public void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3, float tx1, float ty1, float tx2, float ty2, float tx3, float ty3)
     public void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3, float tx1, float ty1, float tx2, float ty2, float tx3, float ty3)
@@ -111,8 +125,8 @@ public class TextureRenderer
             throw new ShaderException("build must be called before drawing");
             throw new ShaderException("build must be called before drawing");
         }
         }
         GLHelper.glBindVertexArray(vao);
         GLHelper.glBindVertexArray(vao);
-        GLHelper.glBindBuffer(vbo);
-        glDrawArrays(GL_TRIANGLES, 0, buffer.limit() / 4);
+        GLHelper.glBindBuffer(vbo);       
+        glDrawArrays(GL_TRIANGLES, 0, triangles * 3);
     }
     }
     
     
     public void delete()
     public void delete()