source: src/models/Axis.pym @ 1314:cc01d2ca3729

Revision 1314:cc01d2ca3729, 4.1 KB checked in by Arc Riley <arcriley@…>, 6 years ago (diff)

Ticket #963 :

  • moved the temporary arrays to local variables
  • added structs for convience
  • folded create buffer code into _render (slightly faster)
Line 
1# PySoy's models.Axis class
2#
3# Copyright (C) 2006,2007,2008 PySoy Group
4#
5#  This program is free software; you can redistribute it and/or modify
6#  it under the terms of the GNU Affero General Public License as published
7#  by the Free Software Foundation, either version 3 of the License, or
8#  (at your option) any later version.
9#
10#  This program is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY; without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#  GNU Affero General Public License for more details.
14#
15#  You should have received a copy of the GNU Affero General Public License
16#  along with this program; if not, see http://www.gnu.org/licenses
17#
18# $Id: Axis.pym 1360 2008-09-11 05:39:22Z ArcRiley $
19
20cdef class Axis (Model) :
21  '''soy.models.Axis
22
23    This L{models class<soy.models>} renders a "XYZ axis" oriented to each
24    body it's attached to.  This is useful for debugging.
25  '''
26
27  ############################################################################
28  #
29  # WindowLoop Functions
30  #
31
32  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
35    #
36    # This should be upgraded to use VBO.  Test for buffer ID here.
37    #
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)
44      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementBuffer)
45      #
46    else:
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
89    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color arrays
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)
93    #gl.glPushMatrix()
94    gl.glDisable(gl.GL_CULL_FACE)
95    gl.glDisable(gl.GL_DEPTH_TEST)
96    gl.glDisable(gl.GL_LIGHTING)
97    gl.glDrawElements(gl.GL_LINES, 2, gl.GL_UNSIGNED_BYTE, <gl.GLvoid *> 0)
98    gl.glEnable(gl.GL_LIGHTING)
99    gl.glEnable(gl.GL_DEPTH_TEST)
100    gl.glEnable(gl.GL_CULL_FACE)
101    #gl.glPopMatrix()
102    gl.glDisableClientState(gl.GL_COLOR_ARRAY)
103    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
104    gl.glEnableClientState(gl.GL_NORMAL_ARRAY)
Note: See TracBrowser for help on using the repository browser.