chiark / gitweb /
Vastly improve rendering time for complex models.
authordaid303 <daid303@gmail.com>
Thu, 4 Oct 2012 10:04:04 +0000 (12:04 +0200)
committerdaid303 <daid303@gmail.com>
Thu, 4 Oct 2012 10:04:04 +0000 (12:04 +0200)
Cura/gui/opengl.py
Cura/util/mesh.py

index fe1cf58353f53a5086ccaf6d8cb53c2023e80896..b2a6571ca70e24c6ef817a4929dc1acf14a2b4ea 100644 (file)
@@ -303,13 +303,24 @@ def DrawMesh(mesh):
        glEnableClientState(GL_NORMAL_ARRAY);\r
        glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)\r
        glNormalPointer(GL_FLOAT, 0, mesh.normal)\r
+\r
+       #Odd, drawing in batchs is a LOT faster then drawing it all at once.\r
+       batchSize = 999 #Warning, batchSize needs to be dividable by 3\r
+       extraStartPos = int(mesh.vertexCount / batchSize) * batchSize\r
+       extraCount = mesh.vertexCount - extraStartPos\r
        \r
        glCullFace(GL_BACK)\r
-       glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)\r
+       for i in xrange(0, int(mesh.vertexCount / batchSize)):\r
+               glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize)\r
+       glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)\r
        \r
        glCullFace(GL_FRONT)\r
        glNormalPointer(GL_FLOAT, 0, mesh.invNormal)\r
-       glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)\r
+       for i in xrange(0, int(mesh.vertexCount / batchSize)):\r
+               glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize)\r
+       extraStartPos = int(mesh.vertexCount / batchSize) * batchSize\r
+       extraCount = mesh.vertexCount - extraStartPos\r
+       glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)\r
        glCullFace(GL_BACK)\r
        \r
        glDisableClientState(GL_VERTEX_ARRAY)\r
index aed74b792461eada066bef6b5252792a1b535632..513f8f70136ec1fc2f6baae2ee9b071e928e424b 100644 (file)
@@ -19,8 +19,8 @@ class mesh(object):
        
        def _prepareVertexCount(self, vertexNumber):
                #Set the amount of faces before loading data in them. This way we can create the numpy arrays before we fill them.
-               self.origonalVertexes = numpy.zeros((vertexNumber, 3), float)
-               self.normal = numpy.zeros((vertexNumber, 3), float)
+               self.origonalVertexes = numpy.zeros((vertexNumber, 3), numpy.float32)
+               self.normal = numpy.zeros((vertexNumber, 3), numpy.float32)
                self.vertexCount = 0
 
        def _postProcessAfterLoad(self):
@@ -56,11 +56,11 @@ class mesh(object):
                mat10 = math.sin(rotate) * scaleX
                mat11 = math.cos(rotate) * scaleY
                
-               mat = numpy.array([[mat00,mat10,0],[mat01,mat11,0],[0,0,scaleZ]], float)
+               mat = numpy.array([[mat00,mat10,0],[mat01,mat11,0],[0,0,scaleZ]], numpy.float32)
                if swapXZ:
-                       mat = numpy.array([mat[2],mat[1],mat[0]], float)
+                       mat = numpy.array([mat[2],mat[1],mat[0]], numpy.float32)
                if swapYZ:
-                       mat = numpy.array([mat[0],mat[2],mat[1]], float)
+                       mat = numpy.array([mat[0],mat[2],mat[1]], numpy.float32)
                self.vertexes = (numpy.matrix(self.origonalVertexes, copy = False) * numpy.matrix(mat)).getA()
 
                tris = self.vertexes.reshape(self.vertexCount / 3, 3, 3)
@@ -70,7 +70,7 @@ class mesh(object):
                normals[:,1] /= lens
                normals[:,2] /= lens
                
-               n = numpy.zeros((self.vertexCount / 3, 9), float)
+               n = numpy.zeros((self.vertexCount / 3, 9), numpy.float32)
                n[:,0:3] = normals
                n[:,3:6] = normals
                n[:,6:9] = normals