[colobot] 192/377: Optimized DrawPrimitives() in CGL21Device

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit d944a559050b7389a4c228e86c9cdc3b76685e87
Author: Tomasz Kapuściński <tomaszkax86 at gmail.com>
Date:   Thu Dec 24 00:06:58 2015 +0100

    Optimized DrawPrimitives() in CGL21Device
---
 src/graphics/opengl/gl21device.cpp | 77 ++++++++++++++++++++++++++++++--------
 1 file changed, 62 insertions(+), 15 deletions(-)

diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp
index 805286a..5f49eca 100644
--- a/src/graphics/opengl/gl21device.cpp
+++ b/src/graphics/opengl/gl21device.cpp
@@ -1253,34 +1253,81 @@ void CGL21Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, i
 void CGL21Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices,
     int first[], int count[], int drawCount, Color color)
 {
-    // TODO: use glMultiDrawArrays()
+    BindVBO(0);
 
-    for (int i = 0; i < drawCount; i++)
-    {
-        DrawPrimitive(type, vertices + first[i], count[i], color);
-    }
+    Vertex* vs = const_cast<Vertex*>(vertices);
+
+    glEnableClientState(GL_VERTEX_ARRAY);
+    glVertexPointer(3, GL_FLOAT, sizeof(Vertex), reinterpret_cast<GLfloat*>(&vs[0].coord));
+
+    glEnableClientState(GL_NORMAL_ARRAY);
+    glNormalPointer(GL_FLOAT, sizeof(Vertex), reinterpret_cast<GLfloat*>(&vs[0].normal));
+
+    glClientActiveTexture(GL_TEXTURE0);
+
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+    glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), reinterpret_cast<GLfloat*>(&vs[0].texCoord));
+
+    glColor4fv(color.Array());
+
+    glMultiDrawArrays(TranslateGfxPrimitive(type), first, count, drawCount);
+
+    glDisableClientState(GL_VERTEX_ARRAY);
+    glDisableClientState(GL_NORMAL_ARRAY);
+    glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE0
 }
 
 void CGL21Device::DrawPrimitives(PrimitiveType type, const VertexTex2 *vertices,
     int first[], int count[], int drawCount, Color color)
 {
-    // TODO: use glMultiDrawArrays()
+    BindVBO(0);
 
-    for (int i = 0; i < drawCount; i++)
-    {
-        DrawPrimitive(type, vertices + first[i], count[i], color);
-    }
+    VertexTex2* vs = const_cast<VertexTex2*>(vertices);
+
+    glEnableClientState(GL_VERTEX_ARRAY);
+    glVertexPointer(3, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].coord));
+
+    glEnableClientState(GL_NORMAL_ARRAY);
+    glNormalPointer(GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].normal));
+
+    glClientActiveTexture(GL_TEXTURE0);
+
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+    glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].texCoord));
+
+    glClientActiveTexture(GL_TEXTURE1);
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+    glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].texCoord2));
+
+    glColor4fv(color.Array());
+
+    glMultiDrawArrays(TranslateGfxPrimitive(type), first, count, drawCount);
+
+    glDisableClientState(GL_VERTEX_ARRAY);
+    glDisableClientState(GL_NORMAL_ARRAY);
+    glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1
+
+    glClientActiveTexture(GL_TEXTURE0);
+    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 }
 
 void CGL21Device::DrawPrimitives(PrimitiveType type, const VertexCol *vertices,
     int first[], int count[], int drawCount)
 {
-    // TODO: use glMultiDrawArrays()
+    BindVBO(0);
 
-    for (int i = 0; i < drawCount; i++)
-    {
-        DrawPrimitive(type, vertices + first[i], count[i]);
-    }
+    VertexCol* vs = const_cast<VertexCol*>(vertices);
+
+    glEnableClientState(GL_VERTEX_ARRAY);
+    glVertexPointer(3, GL_FLOAT, sizeof(VertexCol), reinterpret_cast<GLfloat*>(&vs[0].coord));
+
+    glEnableClientState(GL_COLOR_ARRAY);
+    glColorPointer(4, GL_FLOAT, sizeof(VertexCol), reinterpret_cast<GLfloat*>(&vs[0].color));
+
+    glMultiDrawArrays(TranslateGfxPrimitive(type), first, count, drawCount);
+
+    glDisableClientState(GL_VERTEX_ARRAY);
+    glDisableClientState(GL_COLOR_ARRAY);
 }
 
 unsigned int CGL21Device::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list