Author: ArcRiley
Date: 2008-09-11 01:39:22 -0400 (Thu, 11 Sep 2008)
New Revision: 1360

Modified:
   trunk/pysoy/include/soy.models.pxd
   trunk/pysoy/src/models/Axis.pym
Log:
Ticket #963 :
  * moved the temporary arrays to local variables
  * added structs for convience
  * folded create buffer code into _render (slightly faster)


Modified: trunk/pysoy/include/soy.models.pxd
===================================================================
--- trunk/pysoy/include/soy.models.pxd  2008-09-10 23:36:40 UTC (rev 1359)
+++ trunk/pysoy/include/soy.models.pxd  2008-09-11 05:39:22 UTC (rev 1360)
@@ -48,8 +48,29 @@
 cdef class soy.bodies.Body
 #
 ##############################################################################
+#  
+# Structs
+#  
 
+cdef :
+  struct Line :
+    unsigned char a
+    unsigned char b
 
+  struct Face :
+    unsigned short a
+    unsigned short b
+    unsigned short c
+
+  struct VertPC :
+    float px
+    float py
+    float pz
+    float cr
+    float cg
+    float cb
+
+
 cdef class Model :
   cdef void*                        _mutex
   #
@@ -100,11 +121,7 @@
   cdef void                         _renderBottom  ( self )
 
 cdef class Axis (Model) :
-  cdef gl.GLuint                    _vertexBuffer# VBO ids
-  cdef gl.GLuint                    _elementBuffer
-  cdef float                        _axis[12] # contains both vertex and color 
data
-  cdef char                         _elements[2] # contains infomation to 
render the above vertex data in order
-  cdef void                         _createBuffer  ( self )
+  cdef gl.GLuint                    _vertBuffer
+  cdef gl.GLuint                    _elmtBuffer
   
 
-

Modified: trunk/pysoy/src/models/Axis.pym
===================================================================
--- trunk/pysoy/src/models/Axis.pym     2008-09-10 23:36:40 UTC (rev 1359)
+++ trunk/pysoy/src/models/Axis.pym     2008-09-11 05:39:22 UTC (rev 1360)
@@ -23,35 +23,6 @@
     This L{models class<soy.models>} renders a "XYZ axis" oriented to each 
     body it's attached to.  This is useful for debugging.
   '''
-  def __cinit__( self ) :
-    #self._axis = <gl.GLfloat *> ( 0,0,0,      1,0,0, # format XYZRGB
-    #              1,0,0,      1,0,0 )
-    #              # 1.,0.3,0.   1,0,0
-    self._axis[0] =  0    # Vertex 1 PX
-    self._axis[1] = 0     #py
-    self._axis[2] = 0     #pz
-    self._axis[3] = 1     #Vertex 1 Color R
-    self._axis[4] = 0     #G
-    self._axis[5] = 0     #B
-    self._axis[6] = 1     #Vertex 2 PX
-    self._axis[7] = 0     #PY
-    self._axis[8] = 0     #PZ
-    self._axis[9] = 1     #R
-    self._axis[10] = 0    #G
-    self._axis[11] = 0    #B
-    self._elements[0] = <char>0#Start at vertex 1
-    self._elements[1] = <char>1#End at vertex 2
-    self._vertexBuffer  = 0 # BufferIDs
-    self._elementBuffer = 0
-    # Generate Buffers
-
-  cdef void _createBuffer(self) :
-    gl.glGenBuffersARB(1, <gl.GLuint*> &self._vertexBuffer);
-    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertexBuffer);
-    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB,sizeof(self._axis) , self._axis, 
gl.GL_STATIC_DRAW_ARB);
-    gl.glGenBuffersARB(1, <gl.GLuint*> &self._elementBuffer);
-    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elementBuffer);
-    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(self._elements), 
self._elements, gl.GL_STATIC_DRAW_ARB);
 
   ############################################################################
   #
@@ -59,28 +30,75 @@
   #
 
   cdef void _render(self, soy.bodies.Body _body) :
+    cdef VertPC _vert[2]    # contains both vertex position and color data
+    cdef Line   _elmt[1]    # contains indices to verts to render lines
     #
     # This should be upgraded to use VBO.  Test for buffer ID here.
-    #
-    if self._vertexBuffer :
-      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, <gl.GLuint> 
self._vertexBuffer) # Bind to buffer for rendering below
-      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementBuffer) 
-    else:
-      self._createBuffer() # No buffer, so create it
-    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); # No Texture Coords..
-    gl.glDisableClientState(gl.GL_NORMAL_ARRAY);        # or Normals either.
-    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color 
arrays
-    gl.glVertexPointer(3, gl.GL_FLOAT, 0,<gl.GLvoid *> NULL);
-    gl.glColorPointer(3,gl.GL_FLOAT,3*sizeof(float),<gl.GLvoid *>NULL);
+    #
+    if self._vertBuffer :
+      #
+      # Since we already setup the buffers during the first _render, now we
+      # just need to re-bind them to render again
+      #
+      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertBuffer)
+      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementBuffer) 
+      #
+    else:
+      #
+      # This is the first render pass, so we need to setup the VBO
+      #
+      # First we'll populate _vert
+      #
+      self._vert[0].px = 0.00          # \
+      self._vert[0].py = 0.00          #  } (0.0, 0.0, 0.0)
+      self._vert[0].pz = 0.00          # /
+      self._vert[0].cr = 1.00          # \
+      self._vert[0].cg = 0.00          #  } Red
+      self._vert[0].cb = 0.00          # /___________________________
+      self._vert[1].px = 1.00          # \
+      self._vert[1].py = 0.00          #  } (1.0, 0.0, 0.0)
+      self._vert[1].pz = 0.00          # /
+      self._vert[1].cr = 1.00          # \
+      self._vert[1].cg = 0.00          #  } Red
+      self._vert[1].cb = 0.00          # /___________________________
+      #
+      # Next populate _elmt
+      #
+      self._elmt[0].a = 0              # Line 0: 0-1
+      self._elmt[0].b = 1              # ____________________________
+      #
+      # Create new vertex buffer and send _vert
+      #
+      gl.glGenBuffersARB(1, &self._vertBuffer)
+      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertBuffer)
+      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_vert), _vert, 
+                         gl.GL_STATIC_DRAW_ARB)
+      #
+      # Do the same for the element buffer
+      #
+      gl.glGenBuffersARB(1, &self._elmtBuffer)
+      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elmtBuffer)
+      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_elmt), _elmt,
+                         gl.GL_STATIC_DRAW_ARB)
+    #
+    # Disable unused pointers
+    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)  # No Texture Coords..
+    gl.glDisableClientState(gl.GL_NORMAL_ARRAY)         # or Normals either.
+    #
+    # Enable color pointer
+    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color 
arrays
+
+    gl.glVertexPointer(3, gl.GL_FLOAT, 0,               <gl.GLvoid *> 0)
+    gl.glColorPointer (3, gl.GL_FLOAT, sizeof(float)*3, <gl.GLvoid *> 0)
     #gl.glPushMatrix()
     gl.glDisable(gl.GL_CULL_FACE)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_LIGHTING)
-    gl.glDrawElements(gl.GL_LINES,2,gl.GL_UNSIGNED_BYTE,<gl.GLvoid *>0)
+    gl.glDrawElements(gl.GL_LINES, 2, gl.GL_UNSIGNED_BYTE, <gl.GLvoid *> 0)
     gl.glEnable(gl.GL_LIGHTING)
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_CULL_FACE) 
-    #gl.glPopMatrix()
-    gl.glDisableClientState(gl.GL_COLOR_ARRAY);
-    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
-    gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+    #gl.glPopMatrix()
+    gl.glDisableClientState(gl.GL_COLOR_ARRAY)
+    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+    gl.glEnableClientState(gl.GL_NORMAL_ARRAY)

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to