def rightJustify(self, lines, fontStyle, mode=None): """Right-justify a list of lines (wrapper to do in child matrix)""" doinchildmatrix.doInChildMatrix( self._rightJustify, lines, fontStyle, mode, )
def centerJustify(self, lines, fontStyle, mode=None): """Center-justify a list of lines (wrapper to do in child matrix)""" doinchildmatrix.doInChildMatrix( self._centerJustify, lines, fontStyle, mode, )
def SceneGraph( self, node ): """Render lights for a scenegraph""" def tryLight( lightPath, ID, visitor): """Try to enable a light, returns either None or the ID used during enabling.""" lightPath.transform() return lightPath[-1].Light( ID, visitor ) if self.lighting: doinchildmatrix.doInChildMatrix( tryLight, self.currentLight, self.lightID, self )
def SceneGraph(self, node): """Render lights for a scenegraph""" def tryLight(lightPath, ID, visitor): """Try to enable a light, returns either None or the ID used during enabling.""" lightPath.transform() return lightPath[-1].Light(ID, visitor) if self.lighting: doinchildmatrix.doInChildMatrix(tryLight, self.currentLight, self.lightID, self)
def SceneGraph( self, node ): """Render lights for a scenegraph""" def tryLight( lightPath, ID, visitor): """Try to enable a light, returns either None or the ID used during enabling.""" lightPath.transform() return lightPath[-1].Light( ID, visitor ) if self.lighting: doinchildmatrix.doInChildMatrix( tryLight, self.currentLight, self.lightID, self ) if not self.frustum: self.frustum = frustum.Frustum.fromViewingMatrix(normalize = 1) else: log.warn( """SceneGraphCamera called twice for the same rendering pass %s""", self)
def SceneGraph(self, node): """Render lights for a scenegraph""" def tryLight(lightPath, ID, visitor): """Try to enable a light, returns either None or the ID used during enabling.""" lightPath.transform() return lightPath[-1].Light(ID, visitor) if self.lighting: doinchildmatrix.doInChildMatrix(tryLight, self.currentLight, self.lightID, self) if not self.frustum: self.frustum = frustum.Frustum.fromViewingMatrix(normalize=1) else: log.warn( """SceneGraphCamera called twice for the same rendering pass %s""", self)
def occlusionVisible(self, mode=None): """Render this bounding volume for an occlusion test Requires one of: OpenGL 2.x ARB_occlusion_query GL_HP_occlusion_test """ if (False and glGenQueries): query = self.query if not self.query: self.query = query = glGenQueries(1) glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) try: glDepthMask(GL_FALSE) glBeginQuery(GL_SAMPLES_PASSED, query) doinchildmatrix.doInChildMatrix(self._occlusionRender) finally: glEndQuery(GL_SAMPLES_PASSED) # TODO: need to actually retrieve the value, be we want to # finish all child queries at this level before checking that # this particular query passed fragments or not... else: # This code is not OpenGL 3.1 compatible glDepthMask(GL_FALSE) try: try: glDisable(GL_LIGHTING) try: glEnable(occlusion_test.GL_OCCLUSION_TEST_HP) try: doinchildmatrix.doInChildMatrix( self._occlusionRender) finally: glDisable(occlusion_test.GL_OCCLUSION_TEST_HP) finally: glEnable(GL_LIGHTING) finally: glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) finally: glDepthMask(GL_TRUE) result = glGetBooleanv(occlusion_test.GL_OCCLUSION_TEST_RESULT_HP) return result
def SceneGraphLights( self, node ): """Render lights for a scenegraph The default implementation limits you to eight active lights, despite the fact that many OpenGL renderers support more than this. There have been problems with support for calculating light IDs beyond eight, so I have limited the set for now. This method relies on the pre-scanning pass implemented by the renderpass.OverallPass object. That is not a particularly desirable dependency, but eliminating it will likely be quite messy. """ if self.lighting: # Enable lighting calculations enabledLights = [] IDs = [ GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7, ] glEnable(GL_LIGHTING); lightPaths = self.lightPaths[:] def tryLight( lightPath, IDs, visitor): """Try to enable a light, returns either None or the ID used during enabling.""" lightPath.transform() return lightPath[-1].Light( ID, visitor ) if lightPaths: while IDs and lightPaths: lightPath = lightPaths[0] del lightPaths[0] ID = IDs[0] used = doinchildmatrix.doInChildMatrix( tryLight, lightPath, ID, self ) if used: enabledLights.append( IDs.pop(0) ) if lightPaths and not IDs: log.warn( """Unable to render all lights in scene, more than 8 active lights, %s skipped"""%(len(lightPaths))) else: # create a default light self.SceneGraphDefaultlight( IDs[0] ) del IDs[0] # disable the remaining lights for ID in IDs: glDisable(ID); return enabledLights elif self.lighting: glEnable(GL_LIGHTING); self.SceneGraphDefaultlight( GL_LIGHT0 ) return None
def SceneGraphBackground(self, node): """Render background for a scenegraph The background paths found by the OverallPass are used to transform the individual background objects to their appropriate positions in the scene. In general, only the rotation of the path will affect a background node, as they are rendered around the viewpoint, rather than around a particular object-space position. This method relies on the pre-scanning pass implemented by the renderpass.OverallPass object. That is not a particularly desirable dependency, but eliminating it will likely be quite messy. """ if self.passCount == 0: current = None for background in self.backgroundPaths: if background[-1].bound: current = background break if not current: if self.backgroundPaths: current = self.backgroundPaths[0] current[-1].bound = 1 def doBackground(path, visitor): """Render the background""" glLoadIdentity() ### XXX ick! this is horribly fragile! x, y, z, r = visitor.context.platform.quaternion.XYZR() glRotate(r * RADTODEG, x, y, z) path.transform(visitor, translate=0, scale=0, rotate=1) return path[-1].Render(visitor) if current: return doinchildmatrix.doInChildMatrix(doBackground, current, self) else: ### default VRML background is black glClearColor(0.0, 0.0, 0.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
def SceneGraphBackground( self, node ): """Render background for a scenegraph The background paths found by the OverallPass are used to transform the individual background objects to their appropriate positions in the scene. In general, only the rotation of the path will affect a background node, as they are rendered around the viewpoint, rather than around a particular object-space position. This method relies on the pre-scanning pass implemented by the renderpass.OverallPass object. That is not a particularly desirable dependency, but eliminating it will likely be quite messy. """ if self.passCount == 0: current = None for background in self.backgroundPaths: if background[-1].bound: current = background break if not current: if self.backgroundPaths: current = self.backgroundPaths[0] current[-1].bound = 1 def doBackground( path, visitor ): """Render the background""" glLoadIdentity() ### XXX ick! this is horribly fragile! x,y,z,r = visitor.context.platform.quaternion.XYZR() glRotate( r*RADTODEG, x,y,z ) path.transform(visitor, translate=0,scale=0, rotate=1 ) return path[-1].Render( visitor ) if current: return doinchildmatrix.doInChildMatrix( doBackground, current, self ) else: ### default VRML background is black glClearColor(0.0,0.0,0.0,1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
def occlusionRender(self): """Render this box to screen""" doinchildmatrix.doInChildMatrix(self._occlusionRender)
def rightJustify( self, lines, fontStyle, mode=None ): """Right-justify a list of lines (wrapper to do in child matrix)""" doinchildmatrix.doInChildMatrix( self._rightJustify, lines, fontStyle, mode, )
def centerJustify( self, lines, fontStyle, mode=None ): """Center-justify a list of lines (wrapper to do in child matrix)""" doinchildmatrix.doInChildMatrix( self._centerJustify, lines, fontStyle, mode, )
def SceneGraphLights(self, node): """Render lights for a scenegraph The default implementation limits you to eight active lights, despite the fact that many OpenGL renderers support more than this. There have been problems with support for calculating light IDs beyond eight, so I have limited the set for now. This method relies on the pre-scanning pass implemented by the renderpass.OverallPass object. That is not a particularly desirable dependency, but eliminating it will likely be quite messy. """ if self.lighting: # Enable lighting calculations enabledLights = [] IDs = [ GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7, ] glEnable(GL_LIGHTING) lightPaths = self.lightPaths[:] def tryLight(lightPath, IDs, visitor): """Try to enable a light, returns either None or the ID used during enabling.""" lightPath.transform() return lightPath[-1].Light(ID, visitor) if lightPaths: while IDs and lightPaths: lightPath = lightPaths[0] del lightPaths[0] ID = IDs[0] used = doinchildmatrix.doInChildMatrix( tryLight, lightPath, ID, self) if used: enabledLights.append(IDs.pop(0)) if lightPaths and not IDs: log.warn( """Unable to render all lights in scene, more than 8 active lights, %s skipped""" % (len(lightPaths))) else: # create a default light self.SceneGraphDefaultlight(IDs[0]) del IDs[0] # disable the remaining lights for ID in IDs: glDisable(ID) return enabledLights elif self.lighting: glEnable(GL_LIGHTING) self.SceneGraphDefaultlight(GL_LIGHT0) return None