Changeset 1360

Show
Ignore:
Timestamp:
09/11/08 01:39:22 (3 months ago)
Author:
ArcRiley
Message:

Ticket #963 :

  • moved the temporary arrays to local variables
  • added structs for convience
  • folded create buffer code into _render (slightly faster)
Location:
trunk/pysoy
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pysoy/include/soy.models.pxd

    r1358 r1360  
    4949# 
    5050############################################################################## 
     51 
     52# Structs 
     53 
     54 
     55cdef : 
     56  struct Line : 
     57    unsigned char a 
     58    unsigned char b 
     59 
     60  struct Face : 
     61    unsigned short a 
     62    unsigned short b 
     63    unsigned short c 
     64 
     65  struct VertPC : 
     66    float px 
     67    float py 
     68    float pz 
     69    float cr 
     70    float cg 
     71    float cb 
    5172 
    5273 
     
    101122 
    102123cdef class Axis (Model) : 
    103   cdef gl.GLuint                    _vertexBuffer# VBO ids 
    104   cdef gl.GLuint                    _elementBuffer 
    105   cdef float                        _axis[12] # contains both vertex and color data 
    106   cdef char                         _elements[2] # contains infomation to render the above vertex data in order 
    107   cdef void                         _createBuffer  ( self ) 
     124  cdef gl.GLuint                    _vertBuffer 
     125  cdef gl.GLuint                    _elmtBuffer 
    108126   
    109127 
    110  
  • trunk/pysoy/src/models/Axis.pym

    r1359 r1360  
    2424    body it's attached to.  This is useful for debugging. 
    2525  ''' 
    26   def __cinit__( self ) : 
    27     #self._axis = <gl.GLfloat *> ( 0,0,0,      1,0,0, # format XYZRGB 
    28     #              1,0,0,      1,0,0 ) 
    29     #              # 1.,0.3,0.   1,0,0 
    30     self._axis[0] =  0    # Vertex 1 PX 
    31     self._axis[1] = 0     #py 
    32     self._axis[2] = 0     #pz 
    33     self._axis[3] = 1     #Vertex 1 Color R 
    34     self._axis[4] = 0     #G 
    35     self._axis[5] = 0     #B 
    36     self._axis[6] = 1     #Vertex 2 PX 
    37     self._axis[7] = 0     #PY 
    38     self._axis[8] = 0     #PZ 
    39     self._axis[9] = 1     #R 
    40     self._axis[10] = 0    #G 
    41     self._axis[11] = 0    #B 
    42     self._elements[0] = <char>0#Start at vertex 1 
    43     self._elements[1] = <char>1#End at vertex 2 
    44     self._vertexBuffer  = 0 # BufferIDs 
    45     self._elementBuffer = 0 
    46     # Generate Buffers 
    47  
    48   cdef void _createBuffer(self) : 
    49     gl.glGenBuffersARB(1, <gl.GLuint*> &self._vertexBuffer); 
    50     gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertexBuffer); 
    51     gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB,sizeof(self._axis) , self._axis, gl.GL_STATIC_DRAW_ARB); 
    52     gl.glGenBuffersARB(1, <gl.GLuint*> &self._elementBuffer); 
    53     gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elementBuffer); 
    54     gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(self._elements), self._elements, gl.GL_STATIC_DRAW_ARB); 
    5526 
    5627  ############################################################################ 
     
    6031 
    6132  cdef void _render(self, soy.bodies.Body _body) : 
     33    cdef VertPC _vert[2]    # contains both vertex position and color data 
     34    cdef Line   _elmt[1]    # contains indices to verts to render lines 
    6235    # 
    6336    # This should be upgraded to use VBO.  Test for buffer ID here. 
    6437    # 
    65     if self._vertexBuffer : 
    66       gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, <gl.GLuint> self._vertexBuffer) # Bind to buffer for rendering below 
     38    if self._vertBuffer : 
     39      # 
     40      # Since we already setup the buffers during the first _render, now we 
     41      # just need to re-bind them to render again 
     42      # 
     43      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertBuffer) 
    6744      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementBuffer)  
     45      # 
    6846    else: 
    69       self._createBuffer() # No buffer, so create it 
    70     gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); # No Texture Coords.. 
    71     gl.glDisableClientState(gl.GL_NORMAL_ARRAY);        # or Normals either. 
     47      # 
     48      # This is the first render pass, so we need to setup the VBO 
     49      # 
     50      # First we'll populate _vert 
     51      # 
     52      self._vert[0].px = 0.00          # \ 
     53      self._vert[0].py = 0.00          #  } (0.0, 0.0, 0.0) 
     54      self._vert[0].pz = 0.00          # / 
     55      self._vert[0].cr = 1.00          # \ 
     56      self._vert[0].cg = 0.00          #  } Red 
     57      self._vert[0].cb = 0.00          # /___________________________ 
     58      self._vert[1].px = 1.00          # \ 
     59      self._vert[1].py = 0.00          #  } (1.0, 0.0, 0.0) 
     60      self._vert[1].pz = 0.00          # / 
     61      self._vert[1].cr = 1.00          # \ 
     62      self._vert[1].cg = 0.00          #  } Red 
     63      self._vert[1].cb = 0.00          # /___________________________ 
     64      # 
     65      # Next populate _elmt 
     66      # 
     67      self._elmt[0].a = 0              # Line 0: 0-1 
     68      self._elmt[0].b = 1              # ____________________________ 
     69      # 
     70      # Create new vertex buffer and send _vert 
     71      # 
     72      gl.glGenBuffersARB(1, &self._vertBuffer) 
     73      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertBuffer) 
     74      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_vert), _vert,  
     75                         gl.GL_STATIC_DRAW_ARB) 
     76      # 
     77      # Do the same for the element buffer 
     78      # 
     79      gl.glGenBuffersARB(1, &self._elmtBuffer) 
     80      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elmtBuffer) 
     81      gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(_elmt), _elmt, 
     82                         gl.GL_STATIC_DRAW_ARB) 
     83    # 
     84    # Disable unused pointers 
     85    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)  # No Texture Coords.. 
     86    gl.glDisableClientState(gl.GL_NORMAL_ARRAY)         # or Normals either. 
     87    # 
     88    # Enable color pointer 
    7289    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color arrays 
    73     gl.glVertexPointer(3, gl.GL_FLOAT, 0,<gl.GLvoid *> NULL); 
    74     gl.glColorPointer(3,gl.GL_FLOAT,3*sizeof(float),<gl.GLvoid *>NULL); 
     90 
     91    gl.glVertexPointer(3, gl.GL_FLOAT, 0,               <gl.GLvoid *> 0) 
     92    gl.glColorPointer (3, gl.GL_FLOAT, sizeof(float)*3, <gl.GLvoid *> 0) 
    7593    #gl.glPushMatrix() 
    7694    gl.glDisable(gl.GL_CULL_FACE) 
    7795    gl.glDisable(gl.GL_DEPTH_TEST) 
    7896    gl.glDisable(gl.GL_LIGHTING) 
    79     gl.glDrawElements(gl.GL_LINES,2,gl.GL_UNSIGNED_BYTE,<gl.GLvoid *>0) 
     97    gl.glDrawElements(gl.GL_LINES, 2, gl.GL_UNSIGNED_BYTE, <gl.GLvoid *> 0) 
    8098    gl.glEnable(gl.GL_LIGHTING) 
    8199    gl.glEnable(gl.GL_DEPTH_TEST) 
    82100    gl.glEnable(gl.GL_CULL_FACE)  
    83101    #gl.glPopMatrix() 
    84     gl.glDisableClientState(gl.GL_COLOR_ARRAY); 
    85     gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY); 
    86     gl.glEnableClientState(gl.GL_NORMAL_ARRAY); 
     102    gl.glDisableClientState(gl.GL_COLOR_ARRAY) 
     103    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) 
     104    gl.glEnableClientState(gl.GL_NORMAL_ARRAY)