OpenGLContext.context
index
p:\openglcontext\context.py

Abstract base class for all rendering contexts
 
OpenGL operates with the idea of a current context
in which OpenGL calls will operate.  This is something
a little bit more than a "window", as it includes
a number of (optional) off-screen buffers, and
a great deal of state which is manipulated by the
various OpenGL functions. (OpenGL is basically a huge
state machine).
 
The Context in OpenGLContext is your basic interface
to the context, and simple operation of OpenGLContext
(such as that you'll see in most of the test scripts)
can focus almost entirely on the Context object and
its various customization points.
 
If you wish to use the scene graph facilities of
OpenGLContext, look particularly at the abstract
function getSceneGraph, which can be overridden to
provide a particular scenegraph object to the renderer.
SceneGraph objects provide their own light, background,
and render-traversal mechanisms, which allow you to
largely ignore the Context objects.
 
The bulk of the actual rendering work is done by the
Visitor and RenderVisitor classes (or their shadow-
enabled equivalents from shadow.passes), and it is
these classes which define the rendering callbacks
which are available from the Context class.

 
Modules
            
Numeric
Queue
OpenGLContext.scenegraph.cache
vrml.node
vrml.vrml97.nodetypes
os
OpenGLContext.renderpass
OpenGLContext.texturecache
threading
OpenGLContext.visitor
weakref
 
Classes
            
Children(object)
_ContextRenderNode(Rendering, Children, Node)
Context
Node(object)
_ContextRenderNode(Rendering, Children, Node)
Rendering(object)
_ContextRenderNode(Rendering, Children, Node)
 
class Context
      Abstract base class on which all Rendering Contexts are based
 
The Context object represents a single rendering context
for use by the application.  This base class provides only
the most rudimentary of application support, but sub-classes
provide such things as navigation, and/or event handling.
 
Attributes:
 
        renderPasses -- callable object, normally an instance of
                OpenGLContext.renderpass.PassSet which implements the
                rendering algorithm for the Context
 
        alreadyDrawn -- flag which is set/checked to determine
                whether the context needs to be redrawn, see:
                        Context.triggerRedraw( ... )
                        Context.shouldRedraw( ... )
                        Context.suppressRedraw( ... )
                for the API to use to interact with this attribute.
 
        viewportDimensions -- Storage for the current viewport
                dimensions, see:
                        Context.Viewport( ... )
                        Context.getViewport( ... )
                for the API used to interact with this attribute.
                
        drawPollTimeout -- default timeout for the drawPoll method
 
        currentContext -- class attribute pointing to the currently
                rendering Context instance.  This allows code called
                during a Render-pass to access the Context object.
                
                Note: wherever possible, use the passed render-pass's
                "context" attribute, rather than this class attribute.
                If that isn't possible, use the deprecated
                getCurrentContext function in this module.
 
        allContexts -- list of weak references to all instantiated
                Context objects, mostly of use for code which wants to
                refresh all contexts when shared resources/states are
                updated
 
        drawing -- flag set to indicate that this Context is
                currently drawing, mostly used internally
 
   Methods defined here:
Background(self, mode=None)
Customization point for clearing/drawing the background.
 
The default implementation clears the color and depth
buffers, using solid white for the clear color.
 
Note: This method is only called if there is no scene graph,
and if there is no SetupBindables( mode ) method
available on the Context.
DoEventCascade(self)
Customization point for generating non-GUI event cascades
 
This method should only be called after self.lockScenegraph
has been called.  self.unlockScenegraph should then be called
 
Most Contexts will use the eventhandler mix-in's version of this
method.  That provides support for the defered-execution of
functions/method during the event cascade.
DoInit(self)
Call the OnInit method at a time when the context is valid
 
This method provides a customization point where
contexts which do not completely initialize during
their __init__ method can arrange to have the OnInit
method processed after their initialization has
completed.  The default implementation here simply
calls OnInit directly w/ appropriate setCurrent
and unsetCurrent calls.
 
Note:
        The only context currently known to require
        this customization is the wxPython-on-GTK context,
        everything else completes context initialization
        before calling Context.__init__.
Lights(self, mode=None)
Customization point for setting up global illumination parameters
Depending on the mode, should either enable or disable
lighting for all of those lights in the scene.
 
The default implementation enables lighting and light 0
if render mode is not select, disables them otherwise.
 
Note: This method is only called if there is no scene graph,
and if there is no SetupBindables( mode ) method
available on the Context.
OnDraw(self, force=1, *arguments)
Callback for the rendering/drawing mechanism
 
force -- if true, force a redraw.  If false, then only
        do a redraw if the event cascade has generated events.
 
return value is whether a visible change occured
 
This implementation does the following:
 
        * calls lockScenegraph()
                o calls DoEventCascade()
        * calls unlockScenegraph()
        * calls setCurrent()
        * calls renderPasses( self )
                See: visitor.py, rendervisitor.py, renderpass.py,
                shadow/passes.py for examples of render-pass-sets
                which can be triggered.
 
                The RenderPasses define the core of the rendering
                mechanism.  The default rendering passes will defer
                most rendering options to the scenegraph returned by
                getSceneGraph().  If that value is None (default)
                then the pass will use the Context's callbacks.
 
                You can define new RenderPasses to replace the
                rendering algorithm, override the Context's various
                callbacks to write raw OpenGL code, or work by
                customizing the scene graph library.
        * if there was a visible change (which is the return value
                from the render-pass-set), calls SwapBuffers()
        * calls unsetCurrent()
OnIdle(self, *arguments)
 Override to perform actions when the rendering loop is idle
OnInit(self)
Customization point for scene set up and initial processing
 
You override this method to do housekeeping chores such as
loading images and generating textures, loading pre-established
geometry, spawning new threads, etc.
 
This method is called after the completion of the Context.__init__
method for the rendering context.  GUI implementers:
        Wherever possible, this should be the very last function
        called in the initialization of the context to allow user
        code to use all the functionality of the context.
OnResize(self, *arguments)
Resize the window when the windowing library says to
Render(self, mode=None)
Customization point for geometry rendering
 
This method is called by the default render passes to
render the geometry for the system.  Wherever possible,
you should pay attention to the rendering modes to allow
for optimization of your geometry (for instance,
selection passes do not require lighting).
 
The default implementation merely ensures that matrix mode
is currently model view.
 
See: visitor.py, rendervisitor.py, renderpass.py,
shadow/passes.py for definitions of the properties of the
mode.
SwapBuffers(self)
Called by the rendering loop when the buffers should be swapped
 
Each GUI library needs to override this method with the appropriate
code for the library.
ViewPort(self, width, height)
Set the size of the OpenGL rendering viewport for the context
 
This implementation assumes that the context takes up the entire
underlying window (i.e. that it starts at 0,0 and that width, height
will represent the entire size of the window).
Viewpoint(self, mode=None)
Customization point for setting up the projection matrix
 
The default implementation calls glFrustrum with fairly
generic values to establish a camera similar to a 35mm.
 
Note: Most real-world contexts use a ViewPlatformMixin
sub-class of Context, which uses a ViewPlatform object to
manage the viewpoint set up, so the default implementation
is seldom used.
 
Note: This method is currently called by just about every
rendering pass set regardless of whether there is a scene
graph (the scene graph rendering code doesn't yet have
camera support, so it simply calls this method).  However,
if you define a SetupBindables( mode ) method on your
Context this customization point will not be called.
 
Eventually the scene graph may grow its own camera handling
code, at which point it will probably stop calling this
customization point.
__init__(self)
Establish the Context working environment
 
setupThreading, initializeEventManagers,
setupCallbacks, setupDefaultEventCallbacks,
adds a weakref to self to allContexts
establishes pickEvents
and then calls OnInit
addPickEvent(self, event)
Add event to list of events to be processed by selection-render-mode
 
This is a method of the Context, rather than the
rendering pass (which might seem more elegant given
that it is the rendering pass which deals with the
events being registered) because the requests to
render a pick event occur outside of the rendering
loop.  As a result, there is (almost) never an
active context when the pick-event-request comes in.
drawPoll(self, timeout=None)
Wait timeout seconds for a redraw request
 
timeout -- timeout in seconds, if None, use
        self.drawPollTimeout
 
returns 0 if timeout, 1 if true
getPickEvents(self)
Get the currently active pick-events
getSceneGraph(self)
Get the scene graph for the context (or None)
 
Overriding this method is the primary customization
point for those wishing to use the scene graph APIs
of OpenGLContext.  You must return an instance of:
 
        OpenGLContext.scenegraph.scenegraph.SceneGraph
 
Normally you would create that using either a loader
from OpenGLContext.loader:
 
        from OpenGLContext.loader import vrml97
        def OnInit( self ):
                self.sg = vrml97.load( 'c:\somefile\world.wrl' )
        def getSceneGraph( self ):
                return self.sg
 
or by using the classes in OpenGLContext.scenegraph.basenodes:
 
        from OpenGLContext.scenegraph import basenodes
        def OnInit( self ):
                self.sg = basenodes.sceneGraph(
                        children = [
                                basenodes.Transform(...)
                        ],
                )
 
to define the scenegraph in Python code.
getTTFFiles(self)
Get TrueType font-file registry object
getViewPort(self)
Method to retrieve the current dimensions of the context
 
Return value is a width, height tuple. See Context.ViewPort
for setting of this value.
initializeEventManagers(self, managerClasses=())
Customisation point for initialising event manager objects
 
See:
        OpenGLContext.eventhandlermixin.EventHandlerMixin
lockScenegraph(self, blocking=1)
Lock scenegraph locks to prevent other update/rendering actions
 
Potentially this could be called from a thread other than the
GUI thread, allowing the other thread to update structures in
the scenegraph without mucking up any active rendering pass.
renderedChildren(self, types=None)
Get the rendered children of the scenegraph
setCurrent(self, blocking=1)
Set the OpenGL focus to this context
setupCache(self)
Setup caching strutures for content
 
This includes the general compiled-geometry caches
and the texture cache
setupCallbacks(self)
Establishes GUI callbacks for asynchronous event GUI systems
 
Subclasses and applications will register events
here for those event types in which they are interested.
Most minor applications should use interactivecontext's
abstract callbacks (which translate the GUI library's
native events into a common event framework for all
interactivecontexts).
 
The default implementation does nothing.
setupDefaultEventCallbacks(self)
Setup common callbacks for the context
 
This will normally be done in the GUI-lib's sub-class of
context.  You might override it to provide other default
callbacks, but you'll normally want to call the base-class
implementation somewhere in that overridden method.
setupExtensionManager(self)
Create an extension manager for this context
setupFontProviders(self)
Load font providers for the context
 
See the OpenGLContext.scenegraph.text package for the
available font providers.
setupRedrawRequest(self)
Setup the redraw-request (threading) event
setupScenegraphLock(self)
Setup lock to protect scenegraph from updates during rendering
setupThreading(self)
Setup primitives (locks, events) for threading
shouldRedraw(self)
Return whether or not the context contents need to be redrawn
suppressRedraw(self)
Indicate to the context that there is no need to re-render
 
This method signals to the context that there are no updates
currently requiring redrawing of the context's contents.
 
See:
        Context.shouldRedraw and Context.triggerRedraw
triggerPick(self)
Trigger a selection rendering pass
 
If the context is not currently drawing, the selection render will
occur immediately, otherwise it will occur the next time the
rendering loop reaches the selection stage.
triggerRedraw(self, force=0)
Indicate to the context that it should redraw when possible
 
If force is true, the rendering will begin immediately if the
context is not already drawing.  Otherwise only the indicator flag
will be set.
unlockScenegraph(self)
Unlock scenegraph locks to allow other update/rendering actions
 
Potentially this could be called from a thread other than the
GUI thread, allowing the other thread to update structures in
the scenegraph without mucking up any active rendering pass.
unsetCurrent(self)
Give up the OpenGL focus from this context

Class methods defined here:
getApplicationName(cls) from __builtin__.class
Retrieve the application name for configuration purposes
getUserAppDataDirectory(cls) from __builtin__.class
Retrieve user-specific configuration directory
 
Default implementation gives a directory-name in the
user's (system-specific) "application data" directory
named

Data and non-method functions defined here:
APPLICATION_NAME = 'OpenGLContext'
DEF = '#Context'
PROTO = 'Context'
__doc__ = 'Abstract base class on which all Rendering Conte...s\n\t\t\tcurrently drawing, mostly used internally\n\n\t'
__module__ = 'OpenGLContext.context'
allContexts = []
alreadyDrawn = None
currentContext = None
drawPollTimeout = 0.01
drawing = None
renderPasses = [<class 'OpenGLContext.renderpass.OpaqueRenderPa...ass 'OpenGLContext.renderpass.SelectRenderPass'>]
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.
ttfFileRegistry = None
viewportDimensions = (0, 0)
 
class _ContextRenderNode(Rendering, Children, Node)
      The Context object as a RenderNode
 
Returned as the child of the Context if there
is no getSceneGraph() result.
 
  
Method resolution order:
_ContextRenderNode
Rendering
Children
Node
object

Methods defined here:
Render(self, mode)
Delegate rendering to the mode.context.Render method

Data and non-method functions defined here:
__doc__ = 'The Context object as a RenderNode\n\n\tReturned as...Context if there\n\tis no getSceneGraph() result.\n\t'
__module__ = 'OpenGLContext.context'

Data and non-method functions inherited from Rendering:
__dict__ = <dict-proxy object at 0x07221190>
__weakref__ = <member '__weakref__' of 'Rendering' objects>

Data and non-method functions inherited from Children:
sensitive = 0

Methods inherited from Node:
__init__(self, **namedarguments)
Initialise the node with appropriate named args
 
All properties/attributes must be specified with
named arguments, and the property/attribute must
exist within the Node's class/prototype.
 
This will raise AttributeError/ValueError/TypeError
if the values or the property names are inappropriate.
 
Note that all Node objects have the attribute/property
        exposedField SFString DEF ""
defined.  You may therefore specify a DEF name by
passing it as a named argument.
__repr__(self)
Get a code-like representation of the Node
 
Basically every attribute except for sub-nodes values
are returned as a full representation.
__str__(self)
Get a friendly representation of the Node
copy(self, copier=None)
Copy this node for copier
toString(self, **namedargs)
Generate a VRML 97-syntax string representing this Prototype
**namedargs -- key:value
        passed arguments for the linearisation object
see lineariser4.Lineariser

Properties inherited from Node:
DEF
exposedField SFString  DEF 
DEF getter = fget(self, client) from SFString
Get the client's value for this property
 
if notify is true send a notification event.
DEF setter = fset(self, client, value, notify=1) from SFString
Set the client's value for this property
 
if notify is true send a notification event.
DEF deleter = fdel(self, client, notify=1) from SFString
Delete the client's value for this property
 
if notify is true send a notification event.
rootSceneGraph
exposedField WeakSFNode  root NULL
rootSceneGraph getter = fget(self, client) from WeakSFNode
Get the client's value for this property
 
if notify is true send a notification event.
rootSceneGraph setter = fset(self, client, value, notify=1) from WeakSFNode
Set the client's value for this property
 
notify -- if true send a notification event
 
The SFNode tries to update the value's root
attribute to point to the root of the client
*iff* the value doesn't currently point at
a valid root.  (That is, it only updates root
if there is no current root).  This is done
without sending notify events.
rootSceneGraph deleter = fdel(self, client, notify=1) from WeakSFNode
Delete the client's value for this property
 
if notify is true send a notification event.

Data and non-method functions inherited from Node:
PROTO = ''
externalURL = ()

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
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value

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
 
Functions
            
getCurrentContext()
Get the currently-rendering context
 
This function allows code running during the render cycle
to determine the current context.  As a general rule, the
context is available as rendermode.context from the render
mode/pass which is passed to the rendering functions as an
argument.
 
Note: this function is deprecated, use the passed rendering
mode/pass's context attribute instead.
inContextThread()
Return true if the current thread is the context thread
 
Data
             ContextRenderNode = _ContextRenderNode( )
contextLock = <_RLock(None, 0)>
contextThread = None