| | |
- list(object)
-
- PassSet
- object
-
- OverallPass
- RenderPass
-
- TransparentRenderPass
- VisitingRenderPass(RenderPass, RenderVisitor)
-
- OpaqueRenderPass
- SelectRenderPass
class OpaqueRenderPass(VisitingRenderPass) |
| |
Opaque geometry rendering through scenegraph visitation
The opaque rendering passes is the most "normal"
of the rendering passes. It basically just uses
the RenderVisitor implementation to render the
scenegraph or Context.
The OpaqueRenderPass uses the context's shouldRedraw
and suppressRedraw methods to determine whether or not to
render itself, (and to let the context know that it has
rendered). This is not ideologically pure, as potentially
there could be another rendering pass responsible for
"visible" rendering. It is, however, practical for now.
Note:
The OpaqueRenderPass registers objects for the
TransparentRenderPass, so the TransparentRenderPass
cannot operate without a preceding OpaqueRenderPass. |
| |
- Method resolution order:
- OpaqueRenderPass
- VisitingRenderPass
- RenderPass
- RenderVisitor
- Visitor
- object
Methods defined here:
- shouldDraw(self)
- Checks the client's shouldRedraw() value, then calls suppressRedraw
Data and non-method functions defined here:
- __doc__ = 'Opaque geometry rendering through scenegraph vis...t operate without a preceding OpaqueRenderPass.\n\t'
- __module__ = 'OpenGLContext.renderpass'
- lighting = 1
- selectNames = 0
- transform = 1
- transparent = 0
- visible = 1
Methods inherited from VisitingRenderPass:
- __call__(self)
- Do the rendering pass
Visits the context and all of its children if the
shouldDraw method returns a true value.
Returns self.visible if the visiting sequence
occurred, otherwise returns 0
- children(self, node)
- Get children to visit for a node
Adds (experimental, slow, and currently incorrect)
frustum-culling check to filter out children who
are not within the frustum. Will only be enabled
if the context defines a true attribute:
USE_FRUSTUM_CULLING
Data and non-method functions inherited from VisitingRenderPass:
- frustum = None
- frustumCulling = -1
Methods inherited from RenderPass:
- OnInit(self)
- Initialization customization point
- __getattr__(self, key)
- Defer to the overall pass on attribute lookup failure
- __init__(self, overall, passCount=0)
- Initialise the per-mode render-pass object
overall -- the OverallPass instance which is driving
this RenderPass instance. Attributes of the
OverallPass are made available via the __getattr__
hook.
passCount -- the index of this pass within the
OverallPass, an integer representing the
number of passes which have come before us.
The initializer calls OnInit when it is finished
to allow for easy sub-class customization.
Data and non-method functions inherited from RenderPass:
- __dict__ = <dict-proxy object at 0x072976E0>
- __weakref__ = <member '__weakref__' of 'RenderPass' objects>
- cache = None
- lightingAmbient = 1
- lightingDiffuse = 1
- selectForced = 0
- stencil = 0
Methods inherited from RenderVisitor:
- Context(self, node)
- Render the Context object
calls:
ContextRenderSetup(node)
ContextSetupDisplay(node)
ContextSetupBindables(node)
- ContextRenderSetup(self, node)
- Set up the context for rendering prior to scene rendering
This method runs even when there is a scenegraph
It sets the rendering mode to GL_RENDER, and loads
identity matrices for the projection and model
view matrices.
- ContextSetupBindables(self, node)
- Set up the bindable objects (viewpoints, backgrounds, lights)
If the Context object has a non-null scenegraph, as
returned by getSceneGraph(), then this method will
do nothing, as the scenegraph will be responsible for
setting up the bindable nodes.
If the Context does not have the scenegraph, then we
look for a Context.SetupBindables method, and call
that with context.SetupBindables(self)
If the Context does not have a SetupBindables method
or a scenegraph, we call:
context.Viewpoint ( self )
context.Background( self )
context.Lights ( self )
- ContextSetupDisplay(self, node)
- Establishes rendering parameters for context's rendering pass
This method runs even when there is a scenegraph
(Re-)establishes common rendering parameters which
may have been left in unexpected states. If the Context
object has a SetupDisplay method, we call that. Otherwise
we enable depth testing, set the depth test to GL_LESS,
enable face-culling, and set face-culling to cull back-faces.
- Grouping(self, node)
- Render a grouping node, return a finalisation token
Grouping notes are primarily of interest during selection
rendering passes, where they push and pop names on the
OpenGL name stack. There are a number of selection-specific
attributes on the RenderPass object which determine whether
or not an individual Grouping node's name is pushed onto
the stack.
Grouping nodes also keep track of their individual
"sensitivity" (by monitoring whether or not they have a
mouse-sensor child). Sensitive Grouping nodes alter the
RenderPass's selection-specific attributes to manipulate
their children's selection-mode rendering.
- Rendering(self, node)
- Render a rendering node (Shape)
At the moment, this just calls node.Render( self )
- SceneGraph(self, node)
- Render a scenegraph object (SetupBindables)
This method is only called if the Context returns
a non-null value from getSceneGraph(), as it only
is called when a Scenegraph instance is encountered.
If a Scenegraph is active, we do not use the code in
ContextSetupBindables, so the Scenegraph is responsible
for setting up all of the bindable nodes it wishes
to have rendered.
calls:
SceneGraphCamera(node)
SceneGraphLights(node)
SceneGraphBackground(node)
- 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.
- SceneGraphCamera(self, node)
- Setup the camera/viewpoint from the scenegraph
XXX
At the moment, there is no Viewpoint support in
OpenGLContext, so this method merely calls the
Context's Viewpoint method.
- SceneGraphDefaultlight(self, lightID)
- Create the default headlight
VRML browsers generally have a default lighting scheme
where, if there are no lights in the scene, a headlight
is created pointing from the viewpoint forward into the scene.
The light paths found by the OverallPass are used to
transform the individual light objects to their appropriate
positions in the scene.
XXX
This code is not quite right, instead of creating
a headlight, it is just creating a simple light pointing
forward from 0,0,10. What we want is a light that always
points forward from the current viewpoint in the current
view direction.
- 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.
- Transform(self, node)
- Render a transform object, return a finalisation token
This method attempts to catch model-view matrix overflows
and gracefully handle them. It returns "tokens" which reset
the model-view matrix to the previous condition. This is
part of the Visitor API.
Note:
Most Transforming nodes are also Grouping nodes,
so both the Transform method and the Grouping method
will be run for those nodes.
- buildVMethods(self)
- Add scenegraph-package-specific class:method mappings
Data and non-method functions inherited from RenderVisitor:
- contextBaseClass = None
Methods inherited from Visitor:
- visit(self, node)
- Visit an individual node, dispatch to methods as necessary
The visiting algorithm is fairly involved compared
to the classic computer science Visitor algorithm.
First we call preVisit( node ), and if the
result of that is true, we continue processing.
This allows you to use preVisit to do such things
as processing every node in the scenegraph.
If we are visiting the node: (preVisit returned true)
* add the node to self.currentStack
* retrieve the "vmethods" for the node
* call each vmethod with the node as argument
o if the vmethod returns a finalization token
we store that token for finalization
* we determine the children to visit for the node
* for each child, we call visit recursively
* during finalization (after children are finished
processing)
o if we have any finalization tokens, we call
those tokens
o we call postVisit( node )
o we restore the previous self.currentStack
Note: this is the "production" version of visit
which only logs errors, not "info" level traces,
this avoids the 100's of 1000's of calls generated
by the huge number of iterations.
- vmethods(self, obj)
- Get all relevant "virtual methods" as unbound methods
Returns *all* registered vmethods for the classes in the
given object's class's __mro__
This version caches the unbound methods in a per-visitor-
class dictionary, which should make it at least a little
faster.
Class methods inherited from Visitor:
- addChildrenMethod(self, type, function) from type
- Register function for determining children for a given type
XXX
Methods are stored in the _childrenMethods dictionary,
which is currently class-static, I would rather this
were an instance variable, but that makes registration
something you need to do for every new instance, while
normally you only want to override for very special
sub-classes (I haven't yet discovered a case where I
want to do it).
Note:
This is currently a class method due to the class-
static nature!
Data and non-method functions inherited from Visitor:
- _childrenMethods = {}
Methods inherited from object:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __hash__(...)
- x.__hash__() <==> hash(x)
- __reduce__(...)
- helper for pickle
- __repr__(...)
- x.__repr__() <==> repr(x)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __str__(...)
- x.__str__() <==> str(x)
Data and non-method functions inherited from object:
- __class__ = <type 'type'>
- __new__ = <built-in method __new__ of type object at 0x1E0BD978>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
|
class OverallPass(object) |
| |
Representation of an overall rendering pass
The OverallPass object represents a collection of sub-passes
which, together, are considered a full rendering cycle. The
OverallPass stores information about the entire rendering
cycle, with the attributes of the OverallPass available to
each sub-pass (and thereby to rendering code).
Attributes:
context -- reference to the client Context object
into which this pass is being rendered
lightPaths, viewPaths, backgroundPaths, fogPaths --
nodepath objects for each active object of the given
node-types found during the initial "findBindables"
"rendering" pass which is run before any of the
regular render-passes.
See:
findBindables
RenderVisitor.SceneGraphLights
RenderVisitor.SceneGraphBackground
transparentObjects -- sequence of transparent object
records registered (normally by OpaqueRenderPass) for
processing (normally by TransparentRenderPass).
See:
addTransparent()
getTransparent()
selectable -- mapping from "name" (OpenGL integer name)
to selectable Node (an opaque object reference) used
to provide easy access to the list of selected nodes.
See:
addSelectable()
## Note: the following are not considered particularly useful
# and may disappear at some point in time
startTime -- the startTime value passed to the initializer,
or the value of time.time() during initialization if
there was no value
viewport -- glGetIntegerv( GL_VIEWPORT )
-> (x,y, width, height)
projection -- glGetDoublev( GL_PROJECTION_MATRIX )
-> 4x4 float matrix
modelView -- glGetDoublev( GL_MODELVIEW_MATRIX )
-> 4x4 float matrix |
| |
Methods defined here:
- OnInit(self)
- Initialize pass-specific functionality
- __call__(self)
- Render the pass and all sub-passes
Reports whether or not there was a visible change
- __init__(self, context=None, subPasses=(), startTime=None)
- Initialize the OverallPass object
context -- the client Context node
subPasses -- sequence of sub-pass RenderPass objects
startTime -- optional starting time value
- addSelectable(self, name, obj)
- Register a selectable node with the given name
- addTransparent(self, token, matrix=None)
- Register object for transparent rendering pass
token -- opaque pointer to an object to be rendered
during the transparent rendering pass
The current model-view matrix will be stored with
the token for use during the transparent rendering pass
- findBindables(self)
- Calculate and store nodepath(s) for active bindable and light nodes
See:
RenderVisitor.SceneGraphLights
RenderVisitor.SceneGraphBackground
- getModelView(self)
- Retrieve the base model-view matrix for the rendering pass
- getProjection(self)
- Retrieve the projection matrix for the rendering pass
- getTransparent(self)
- Retrieve current list of registered transparent objects
The list is a series of two-tuples, with each
entry composed of the opaque pointer registered with
addTransparent and the model-view matrix active
at the time of registration.
- getViewport(self)
- Retrieve the viewport parameters for the rendering pass
- setSubPasses(self, passes)
- Set the sub-passes for the meta-pass, passes is a sequence of classes
Data and non-method functions defined here:
- __dict__ = <dict-proxy object at 0x072C9FA0>
- __doc__ = 'Representation of an overall rendering pass\n\n\tTh...v( GL_MODELVIEW_MATRIX )\n\t\t\t-> 4x4 float matrix\n\t'
- __module__ = 'OpenGLContext.renderpass'
- __weakref__ = <member '__weakref__' of 'OverallPass' objects>
- backgroundPaths = None
- fogPaths = None
- lightPaths = None
- modelView = None
- projection = None
- viewPaths = None
- viewport = None
Methods inherited from object:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __hash__(...)
- x.__hash__() <==> hash(x)
- __reduce__(...)
- helper for pickle
- __repr__(...)
- x.__repr__() <==> repr(x)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __str__(...)
- x.__str__() <==> str(x)
Data and non-method functions inherited from object:
- __class__ = <type 'type'>
- __new__ = <built-in method __new__ of type object at 0x1E0BD978>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
|
class PassSet(list) |
| |
Callable list of sub-passes with associated OverallPass
The PassSet is called once per render-cycle,
and is responsible for creating the OverallPass
which does the actual rendering. It simply
creates the OverallPass with the given sub-passes
and calls the OverallPass, returning the result. |
| |
- Method resolution order:
- PassSet
- list
- object
Methods defined here:
- __call__(self, context)
- Initialize and run a render pass for context with our sub-passes
- __init__(self, overallClass, items=())
- Initialize the PassSet
overallClass -- the OverallPass class which will
be used to do the actual rendering.
items -- list of sub-passes to be passed to the
OverallPass object
Data and non-method functions defined here:
- __dict__ = <dict-proxy object at 0x072FD940>
- __doc__ = 'Callable list of sub-passes with associated Over...nd calls the OverallPass, returning the result.\n\t'
- __module__ = 'OpenGLContext.renderpass'
- __weakref__ = <member '__weakref__' of 'PassSet' objects>
Methods inherited from list:
- __add__(...)
- x.__add__(y) <==> x+y
- __contains__(...)
- x.__contains__(y) <==> y in x
- __delitem__(...)
- x.__delitem__(y) <==> del x[y]
- __delslice__(...)
- x.__delslice__(i, j) <==> del x[i:j]
Use of negative indices is not supported.
- __eq__(...)
- x.__eq__(y) <==> x==y
- __ge__(...)
- x.__ge__(y) <==> x>=y
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __getitem__(...)
- x.__getitem__(y) <==> x[y]
- __getslice__(...)
- x.__getslice__(i, j) <==> x[i:j]
Use of negative indices is not supported.
- __gt__(...)
- x.__gt__(y) <==> x>y
- __hash__(...)
- x.__hash__() <==> hash(x)
- __iadd__(...)
- x.__iadd__(y) <==> x+=y
- __imul__(...)
- x.__imul__(y) <==> x*=y
- __le__(...)
- x.__le__(y) <==> x<=y
- __len__(...)
- x.__len__() <==> len(x)
- __lt__(...)
- x.__lt__(y) <==> x<y
- __mul__(...)
- x.__mul__(n) <==> x*n
- __ne__(...)
- x.__ne__(y) <==> x!=y
- __repr__(...)
- x.__repr__() <==> repr(x)
- __rmul__(...)
- x.__rmul__(n) <==> n*x
- __setitem__(...)
- x.__setitem__(i, y) <==> x[i]=y
- __setslice__(...)
- x.__setslice__(i, j, y) <==> x[i:j]=y
Use of negative indices is not supported.
- append(...)
- L.append(object) -- append object to end
- count(...)
- L.count(value) -> integer -- return number of occurrences of value
- extend(...)
- L.extend(iterable) -- extend list by appending elements from the iterable
- index(...)
- L.index(value) -> integer -- return index of first occurrence of value
- insert(...)
- L.insert(index, object) -- insert object before index
- pop(...)
- L.pop([index]) -> item -- remove and return item at index (default last)
- remove(...)
- L.remove(value) -- remove first occurrence of value
- reverse(...)
- L.reverse() -- reverse *IN PLACE*
- sort(...)
- L.sort([cmpfunc]) -- sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
Data and non-method functions inherited from list:
- __new__ = <built-in method __new__ of type object at 0x1E0AB0F0>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
Methods inherited from object:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __reduce__(...)
- helper for pickle
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __str__(...)
- x.__str__() <==> str(x)
Data and non-method functions inherited from object:
- __class__ = <type 'type'>
|
class RenderPass(object) |
| |
A particular pass of a particular rendering mode
Most RenderPass instances are actually VisitingRenderPass
instances, with the notable exception of TransparentRenderPass
objects.
Attributes (normally class-static):
transform -- whether to do transforms, most do
visible -- whether there is any visible change to
the buffer (use textures, colours, etceteras)
transparent -- whether is a transparent-rendering pass
selectNames -- whether should push/pop selection "names"
selectForced -- whether we are currently in forced-
selection mode
stencil -- whether we are rendering into the stencil buffer
lighting -- lighting is being used (most opaque/
transparent, but not selection)
lightingAmbient -- whether ambient lighting should be used
lightingDiffuse -- whether diffuse lighting should be used
(non-ambient)
Note:
The RenderPass will look up any missing attributes
in the OverallPass object, so effectively the RenderPass
has all of the attributes of the OverallPass which
is passed to the initializer.
Note:
This class is a consolidation of the RenderPass and
RenderMode classes in OpenGLContext version 1.0 |
| |
Methods defined here:
- OnInit(self)
- Initialization customization point
- __call__(self)
- Do the rendering pass
return whether or not there has been a visible change
- __getattr__(self, key)
- Defer to the overall pass on attribute lookup failure
- __init__(self, overall, passCount=0)
- Initialise the per-mode render-pass object
overall -- the OverallPass instance which is driving
this RenderPass instance. Attributes of the
OverallPass are made available via the __getattr__
hook.
passCount -- the index of this pass within the
OverallPass, an integer representing the
number of passes which have come before us.
The initializer calls OnInit when it is finished
to allow for easy sub-class customization.
- shouldDraw(self)
- Test whether this pass should be performed,
This implementation just returns 1, subclasses
should return an intelligent value
Data and non-method functions defined here:
- __dict__ = <dict-proxy object at 0x072AC810>
- __doc__ = 'A particular pass of a particular rendering mode...RenderMode classes in OpenGLContext version 1.0\n\t'
- __module__ = 'OpenGLContext.renderpass'
- __weakref__ = <member '__weakref__' of 'RenderPass' objects>
- cache = None
- lighting = 1
- lightingAmbient = 1
- lightingDiffuse = 1
- selectForced = 0
- selectNames = 0
- stencil = 0
- transform = 1
- transparent = 0
- visible = 1
Methods inherited from object:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __hash__(...)
- x.__hash__() <==> hash(x)
- __reduce__(...)
- helper for pickle
- __repr__(...)
- x.__repr__() <==> repr(x)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __str__(...)
- x.__str__() <==> str(x)
Data and non-method functions inherited from object:
- __class__ = <type 'type'>
- __new__ = <built-in method __new__ of type object at 0x1E0BD978>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
|
class SelectRenderPass(VisitingRenderPass) |
| |
glSelectBuffer-based selection rendering mode
This is an implementation of glSelectBuffer-based
selection modes. It allows for projecting multiple
"pick" events into the scenegraph. The
implementation tries to be as general as possible.
The RenderVisitor.Grouping method takes care of
calling the Grouping nodes' pushName method to
generate the name stack which is reported by the
SelectRenderPass.
See:
OpenGLContext.events.mouseevents
OpenGLContext.context.getPickEvents
OpenGLContext.context.addPickEvent
Note:
Each pick event causes a complete render-traversal,
which, if there are a lot of pick-events, can
dramatically slowdown your frame rate! There
should be some logic to try to minimize these
events, but I haven't come up with a generalized
solution to the problem.
Note:
Pick events are registered and accessed from the
Context object. The SelectRenderPass can deal
(and it does deal only in the current implementation)
with events which were generated/registered either
by a previous render-pass, or between rendering
passes.
Attributes:
bufferSize -- the size of the Name buffer used
to store the name-stack which will be reported.
The default value, 512, is somewhat wasteful
but does allow for fairly deep scenegraph's.
matrixSize -- the pixel-size dimensions of the
pick matrix (default is 2,2) used
pickPoint -- stores the current pick-point for the
selection rendering pass. |
| |
- Method resolution order:
- SelectRenderPass
- VisitingRenderPass
- RenderPass
- RenderVisitor
- Visitor
- object
Methods defined here:
- ContextSetupDisplay(self, node)
- Customization point calls PickProjection after standard setup
- PickProjection(self)
- Setup the constrained picking matrix and result buffer
We set up the view frustum to be a
box centered around the picking point of size
self.matrixSize, projecting back into the screen
from our current viewpoint.
We then set up the selection buffer into which
our results will be saved, and then switch to
selection-mode rendering.
- __call__(self)
- Render geometry once for each pick-event to be serviced
This is the actual implementation of the glSelectBuffer-
based selection code. It is fairly standard OpenGL
selection code.
We take all of the events which have the same picking-point
and render them together (since they have the same picking
characteristics).
For each picking-point, we set up the constrained picking
matrix and results array in our ContextSetupDisplay/
PickProjection methods, which are visited by the standard
RenderVisitor algorithm.
The visiting code, particularly RenderVisitor.Grouping,
pushes the appropriate names onto the name stack during
rendering, filling the results array as appropriate.
After visiting the entire scenegraph, we retrieve the results
from the name-stack and dispatch the events to their
appropriate handlers.
XXX
Really the event handling should not be going on here,
instead the events should be added to a queue to be
processed after the RenderPass has completely finished,
and the ContextLock has been released (but the scenegraph
lock has been re-acquired).
- shouldDraw(self)
- Only draw if there are picking events pending
Data and non-method functions defined here:
- __doc__ = 'glSelectBuffer-based selection rendering mode\n\n\t...pick-point for the\n\t\t\tselection rendering pass.\n\t'
- __module__ = 'OpenGLContext.renderpass'
- bufferSize = 512
- lighting = 0
- matrixSize = (2, 2)
- pickPoint = (-1, -1)
- selectNames = 1
- transform = 1
- transparent = 0
- visible = 0
Methods inherited from VisitingRenderPass:
- children(self, node)
- Get children to visit for a node
Adds (experimental, slow, and currently incorrect)
frustum-culling check to filter out children who
are not within the frustum. Will only be enabled
if the context defines a true attribute:
USE_FRUSTUM_CULLING
Data and non-method functions inherited from VisitingRenderPass:
- frustum = None
- frustumCulling = -1
Methods inherited from RenderPass:
- OnInit(self)
- Initialization customization point
- __getattr__(self, key)
- Defer to the overall pass on attribute lookup failure
- __init__(self, overall, passCount=0)
- Initialise the per-mode render-pass object
overall -- the OverallPass instance which is driving
this RenderPass instance. Attributes of the
OverallPass are made available via the __getattr__
hook.
passCount -- the index of this pass within the
OverallPass, an integer representing the
number of passes which have come before us.
The initializer calls OnInit when it is finished
to allow for easy sub-class customization.
Data and non-method functions inherited from RenderPass:
- __dict__ = <dict-proxy object at 0x07260BF8>
- __weakref__ = <member '__weakref__' of 'RenderPass' objects>
- cache = None
- lightingAmbient = 1
- lightingDiffuse = 1
- selectForced = 0
- stencil = 0
Methods inherited from RenderVisitor:
- Context(self, node)
- Render the Context object
calls:
ContextRenderSetup(node)
ContextSetupDisplay(node)
ContextSetupBindables(node)
- ContextRenderSetup(self, node)
- Set up the context for rendering prior to scene rendering
This method runs even when there is a scenegraph
It sets the rendering mode to GL_RENDER, and loads
identity matrices for the projection and model
view matrices.
- ContextSetupBindables(self, node)
- Set up the bindable objects (viewpoints, backgrounds, lights)
If the Context object has a non-null scenegraph, as
returned by getSceneGraph(), then this method will
do nothing, as the scenegraph will be responsible for
setting up the bindable nodes.
If the Context does not have the scenegraph, then we
look for a Context.SetupBindables method, and call
that with context.SetupBindables(self)
If the Context does not have a SetupBindables method
or a scenegraph, we call:
context.Viewpoint ( self )
context.Background( self )
context.Lights ( self )
- Grouping(self, node)
- Render a grouping node, return a finalisation token
Grouping notes are primarily of interest during selection
rendering passes, where they push and pop names on the
OpenGL name stack. There are a number of selection-specific
attributes on the RenderPass object which determine whether
or not an individual Grouping node's name is pushed onto
the stack.
Grouping nodes also keep track of their individual
"sensitivity" (by monitoring whether or not they have a
mouse-sensor child). Sensitive Grouping nodes alter the
RenderPass's selection-specific attributes to manipulate
their children's selection-mode rendering.
- Rendering(self, node)
- Render a rendering node (Shape)
At the moment, this just calls node.Render( self )
- SceneGraph(self, node)
- Render a scenegraph object (SetupBindables)
This method is only called if the Context returns
a non-null value from getSceneGraph(), as it only
is called when a Scenegraph instance is encountered.
If a Scenegraph is active, we do not use the code in
ContextSetupBindables, so the Scenegraph is responsible
for setting up all of the bindable nodes it wishes
to have rendered.
calls:
SceneGraphCamera(node)
SceneGraphLights(node)
SceneGraphBackground(node)
- 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.
- SceneGraphCamera(self, node)
- Setup the camera/viewpoint from the scenegraph
XXX
At the moment, there is no Viewpoint support in
OpenGLContext, so this method merely calls the
Context's Viewpoint method.
- SceneGraphDefaultlight(self, lightID)
- Create the default headlight
VRML browsers generally have a default lighting scheme
where, if there are no lights in the scene, a headlight
is created pointing from the viewpoint forward into the scene.
The light paths found by the OverallPass are used to
transform the individual light objects to their appropriate
positions in the scene.
XXX
This code is not quite right, instead of creating
a headlight, it is just creating a simple light pointing
forward from 0,0,10. What we want is a light that always
points forward from the current viewpoint in the current
view direction.
- 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.
- Transform(self, node)
- Render a transform object, return a finalisation token
This method attempts to catch model-view matrix overflows
and gracefully handle them. It returns "tokens" which reset
the model-view matrix to the previous condition. This is
part of the Visitor API.
Note:
Most Transforming nodes are also Grouping nodes,
so both the Transform method and the Grouping method
will be run for those nodes.
- buildVMethods(self)
- Add scenegraph-package-specific class:method mappings
Data and non-method functions inherited from RenderVisitor:
- contextBaseClass = None
Methods inherited from Visitor:
- visit(self, node)
- Visit an individual node, dispatch to methods as necessary
The visiting algorithm is fairly involved compared
to the classic computer science Visitor algorithm.
First we call preVisit( node ), and if the
result of that is true, we continue processing.
This allows you to use preVisit to do such things
as processing every node in the scenegraph.
If we are visiting the node: (preVisit returned true)
* add the node to self.currentStack
* retrieve the "vmethods" for the node
* call each vmethod with the node as argument
o if the vmethod returns a finalization token
we store that token for finalization
* we determine the children to visit for the node
* for each child, we call visit recursively
* during finalization (after children are finished
processing)
o if we have any finalization tokens, we call
those tokens
o we call postVisit( node )
o we restore the previous self.currentStack
Note: this is the "production" version of visit
which only logs errors, not "info" level traces,
this avoids the 100's of 1000's of calls generated
by the huge number of iterations.
- vmethods(self, obj)
- Get all relevant "virtual methods" as unbound methods
Returns *all* registered vmethods for the classes in the
given object's class's __mro__
This version caches the unbound methods in a per-visitor-
class dictionary, which should make it at least a little
faster.
Class methods inherited from Visitor:
- addChildrenMethod(self, type, function) from type
- Register function for determining children for a given type
XXX
Methods are stored in the _childrenMethods dictionary,
which is currently class-static, I would rather this
were an instance variable, but that makes registration
something you need to do for every new instance, while
normally you only want to override for very special
sub-classes (I haven't yet discovered a case where I
want to do it).
Note:
This is currently a class method due to the class-
static nature!
Data and non-method functions inherited from Visitor:
- _childrenMethods = {}
Methods inherited from object:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __hash__(...)
- x.__hash__() <==> hash(x)
- __reduce__(...)
- helper for pickle
- __repr__(...)
- x.__repr__() <==> repr(x)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __str__(...)
- x.__str__() <==> str(x)
Data and non-method functions inherited from object:
- __class__ = <type 'type'>
- __new__ = <built-in method __new__ of type object at 0x1E0BD978>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
|
class TransparentRenderPass(RenderPass) |
| |
Blend-based transparent/translucent geometry rendering
This is an implementation of transparent geometry rendering
which, although not rigorously generalized, should provide
basic functionality.
XXX What is wrong with the implementation?
Properly done, a transparent-rendering algorithm should
sort all polygons of all transparent objects together
with each vertex of each polygon projected, and any
intersecting polygons tesselated to form polygons which
are unambiguously in front of or behind every other
polygon.
I haven't implemented that algorithm, mostly because it
is a great deal of work for a fairly minimal payback
given relatively infrequent occurrence of intersecting
transparent geometry.
There is a further problem when doing stencil-shadow
rendering, in that the multi-pass rendering does not
have proper depth information. I haven't come across
a decent explanation of how to implement support for
this, so I haven't done so. |
| |
- Method resolution order:
- TransparentRenderPass
- RenderPass
- object
Methods defined here:
- ContextRenderSetup(self, node)
- Set up the context for rendering prior to scene rendering
Note:
Although this is the same name as a customization point
for the RenderVisitor API, this object is not a
RenderVisitor. This method is called directly by the
__call__ method.
- ContextSetupDisplay(self, node)
- Establishes rendering parameters for the rendering pass
This particular transparent-geometry-rendering algorithm
uses glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA),
which requires back-to-front sorting of geometry to
produce proper results. It is one of the most
reliable methods for producing transparent geometry
effects.
Note:
Although this is the same name as a customization point
for the RenderVisitor API, this object is not a
RenderVisitor. This method is called directly by the
__call__ method.
- ContextShutdown(self)
- Clears the transparency-specific rendering parameters
Called after the entire rendering pass has completed,
this method is responsible for "cleaning up" after the
transparent-rendering pass. It also clears the list
of transparent objects build up by the OpaqueRenderPass.
Note:
Although this is the same name as a customization point
for the RenderVisitor API, this object is not a
RenderVisitor. This method is called directly by the
__call__ method.
- Render(self, node)
- Render a shape node as transparent geometry
This method knows how to render a Shape node as transparent
geometry. Basically that consists of calling the geometry's
render method with transparent = 1
Note:
Although this is the same name as a customization point
for the RenderVisitor API, this object is not a
RenderVisitor. This method is called directly by the
__call__ method.
- __call__(self)
- Render all registered transparent objects
Objects are projected into screen coordinates,
sorted according to their local origin depth,
then rendered with the model view matrix active
at transparent-object registration (during the
OpaqueRenderPass).
See:
OverallPass.addTransparent
OverallPass.getTransparent
- shouldDraw(self)
- Checks to see if there are registered transparent objects
If there are none, then the entire pass will be skipped.
Data and non-method functions defined here:
- __doc__ = "Blend-based transparent/translucent geometry ren...ement support for\n\t\tthis, so I haven't done so.\n\t"
- __module__ = 'OpenGLContext.renderpass'
- lighting = 1
- selectNames = 0
- transform = 0
- transparent = 1
- visible = 1
Methods inherited from RenderPass:
- OnInit(self)
- Initialization customization point
- __getattr__(self, key)
- Defer to the overall pass on attribute lookup failure
- __init__(self, overall, passCount=0)
- Initialise the per-mode render-pass object
overall -- the OverallPass instance which is driving
this RenderPass instance. Attributes of the
OverallPass are made available via the __getattr__
hook.
passCount -- the index of this pass within the
OverallPass, an integer representing the
number of passes which have come before us.
The initializer calls OnInit when it is finished
to allow for easy sub-class customization.
Data and non-method functions inherited from RenderPass:
- __dict__ = <dict-proxy object at 0x071EDE08>
- __weakref__ = <member '__weakref__' of 'RenderPass' objects>
- cache = None
- lightingAmbient = 1
- lightingDiffuse = 1
- selectForced = 0
- stencil = 0
Methods inherited from object:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __hash__(...)
- x.__hash__() <==> hash(x)
- __reduce__(...)
- helper for pickle
- __repr__(...)
- x.__repr__() <==> repr(x)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __str__(...)
- x.__str__() <==> str(x)
Data and non-method functions inherited from object:
- __class__ = <type 'type'>
- __new__ = <built-in method __new__ of type object at 0x1E0BD978>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
|
class VisitingRenderPass(RenderPass, RenderVisitor) |
| |
A render-pass using the (normal) scenegraph-visitor pattern
Basically, the RenderVisitor implements the rendering
algorithm and the code for common object types. The
VisitingRenderPass(es) define exceptions to the
basic algorithm. |
| |
- Method resolution order:
- VisitingRenderPass
- RenderPass
- RenderVisitor
- Visitor
- object
Methods defined here:
- __call__(self)
- Do the rendering pass
Visits the context and all of its children if the
shouldDraw method returns a true value.
Returns self.visible if the visiting sequence
occurred, otherwise returns 0
- children(self, node)
- Get children to visit for a node
Adds (experimental, slow, and currently incorrect)
frustum-culling check to filter out children who
are not within the frustum. Will only be enabled
if the context defines a true attribute:
USE_FRUSTUM_CULLING
Data and non-method functions defined here:
- __doc__ = 'A render-pass using the (normal) scenegraph-visi...(es) define exceptions to the\n\tbasic algorithm.\n\t'
- __module__ = 'OpenGLContext.renderpass'
- frustum = None
- frustumCulling = -1
Methods inherited from RenderPass:
- OnInit(self)
- Initialization customization point
- __getattr__(self, key)
- Defer to the overall pass on attribute lookup failure
- __init__(self, overall, passCount=0)
- Initialise the per-mode render-pass object
overall -- the OverallPass instance which is driving
this RenderPass instance. Attributes of the
OverallPass are made available via the __getattr__
hook.
passCount -- the index of this pass within the
OverallPass, an integer representing the
number of passes which have come before us.
The initializer calls OnInit when it is finished
to allow for easy sub-class customization.
- shouldDraw(self)
- Test whether this pass should be performed,
This implementation just returns 1, subclasses
should return an intelligent value
Data and non-method functions inherited from RenderPass:
- __dict__ = <dict-proxy object at 0x07322570>
- __weakref__ = <member '__weakref__' of 'RenderPass' objects>
- cache = None
- lighting = 1
- lightingAmbient = 1
- lightingDiffuse = 1
- selectForced = 0
- selectNames = 0
- stencil = 0
- transform = 1
- transparent = 0
- visible = 1
Methods inherited from RenderVisitor:
- Context(self, node)
- Render the Context object
calls:
ContextRenderSetup(node)
ContextSetupDisplay(node)
ContextSetupBindables(node)
- ContextRenderSetup(self, node)
- Set up the context for rendering prior to scene rendering
This method runs even when there is a scenegraph
It sets the rendering mode to GL_RENDER, and loads
identity matrices for the projection and model
view matrices.
- ContextSetupBindables(self, node)
- Set up the bindable objects (viewpoints, backgrounds, lights)
If the Context object has a non-null scenegraph, as
returned by getSceneGraph(), then this method will
do nothing, as the scenegraph will be responsible for
setting up the bindable nodes.
If the Context does not have the scenegraph, then we
look for a Context.SetupBindables method, and call
that with context.SetupBindables(self)
If the Context does not have a SetupBindables method
or a scenegraph, we call:
context.Viewpoint ( self )
context.Background( self )
context.Lights ( self )
- ContextSetupDisplay(self, node)
- Establishes rendering parameters for context's rendering pass
This method runs even when there is a scenegraph
(Re-)establishes common rendering parameters which
may have been left in unexpected states. If the Context
object has a SetupDisplay method, we call that. Otherwise
we enable depth testing, set the depth test to GL_LESS,
enable face-culling, and set face-culling to cull back-faces.
- Grouping(self, node)
- Render a grouping node, return a finalisation token
Grouping notes are primarily of interest during selection
rendering passes, where they push and pop names on the
OpenGL name stack. There are a number of selection-specific
attributes on the RenderPass object which determine whether
or not an individual Grouping node's name is pushed onto
the stack.
Grouping nodes also keep track of their individual
"sensitivity" (by monitoring whether or not they have a
mouse-sensor child). Sensitive Grouping nodes alter the
RenderPass's selection-specific attributes to manipulate
their children's selection-mode rendering.
- Rendering(self, node)
- Render a rendering node (Shape)
At the moment, this just calls node.Render( self )
- SceneGraph(self, node)
- Render a scenegraph object (SetupBindables)
This method is only called if the Context returns
a non-null value from getSceneGraph(), as it only
is called when a Scenegraph instance is encountered.
If a Scenegraph is active, we do not use the code in
ContextSetupBindables, so the Scenegraph is responsible
for setting up all of the bindable nodes it wishes
to have rendered.
calls:
SceneGraphCamera(node)
SceneGraphLights(node)
SceneGraphBackground(node)
- 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.
- SceneGraphCamera(self, node)
- Setup the camera/viewpoint from the scenegraph
XXX
At the moment, there is no Viewpoint support in
OpenGLContext, so this method merely calls the
Context's Viewpoint method.
- SceneGraphDefaultlight(self, lightID)
- Create the default headlight
VRML browsers generally have a default lighting scheme
where, if there are no lights in the scene, a headlight
is created pointing from the viewpoint forward into the scene.
The light paths found by the OverallPass are used to
transform the individual light objects to their appropriate
positions in the scene.
XXX
This code is not quite right, instead of creating
a headlight, it is just creating a simple light pointing
forward from 0,0,10. What we want is a light that always
points forward from the current viewpoint in the current
view direction.
- 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.
- Transform(self, node)
- Render a transform object, return a finalisation token
This method attempts to catch model-view matrix overflows
and gracefully handle them. It returns "tokens" which reset
the model-view matrix to the previous condition. This is
part of the Visitor API.
Note:
Most Transforming nodes are also Grouping nodes,
so both the Transform method and the Grouping method
will be run for those nodes.
- buildVMethods(self)
- Add scenegraph-package-specific class:method mappings
Data and non-method functions inherited from RenderVisitor:
- contextBaseClass = None
Methods inherited from Visitor:
- visit(self, node)
- Visit an individual node, dispatch to methods as necessary
The visiting algorithm is fairly involved compared
to the classic computer science Visitor algorithm.
First we call preVisit( node ), and if the
result of that is true, we continue processing.
This allows you to use preVisit to do such things
as processing every node in the scenegraph.
If we are visiting the node: (preVisit returned true)
* add the node to self.currentStack
* retrieve the "vmethods" for the node
* call each vmethod with the node as argument
o if the vmethod returns a finalization token
we store that token for finalization
* we determine the children to visit for the node
* for each child, we call visit recursively
* during finalization (after children are finished
processing)
o if we have any finalization tokens, we call
those tokens
o we call postVisit( node )
o we restore the previous self.currentStack
Note: this is the "production" version of visit
which only logs errors, not "info" level traces,
this avoids the 100's of 1000's of calls generated
by the huge number of iterations.
- vmethods(self, obj)
- Get all relevant "virtual methods" as unbound methods
Returns *all* registered vmethods for the classes in the
given object's class's __mro__
This version caches the unbound methods in a per-visitor-
class dictionary, which should make it at least a little
faster.
Class methods inherited from Visitor:
- addChildrenMethod(self, type, function) from type
- Register function for determining children for a given type
XXX
Methods are stored in the _childrenMethods dictionary,
which is currently class-static, I would rather this
were an instance variable, but that makes registration
something you need to do for every new instance, while
normally you only want to override for very special
sub-classes (I haven't yet discovered a case where I
want to do it).
Note:
This is currently a class method due to the class-
static nature!
Data and non-method functions inherited from Visitor:
- _childrenMethods = {}
Methods inherited from object:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __hash__(...)
- x.__hash__() <==> hash(x)
- __reduce__(...)
- helper for pickle
- __repr__(...)
- x.__repr__() <==> repr(x)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __str__(...)
- x.__str__() <==> str(x)
Data and non-method functions inherited from object:
- __class__ = <type 'type'>
- __new__ = <built-in method __new__ of type object at 0x1E0BD978>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
| |