#
#   PyGUI - OpenGL View - Generic
#

from ClipComponents import ClipComponent
from ViewBases import ViewBase
from GLContexts import GLContext

class GLError(StandardError):
    pass

class GLView(ClipComponent, ViewBase, GLContext):
    """A GLView is a Component providing an OpenGL 3D display area.
    
    Constructors:
        GLView(share = None, config_attr = value...)
        GLView(config, share = None)
    """
    
    def __init__(self, **kwds):
        ClipComponent.__init__(self, **kwds)
        ViewBase.__init__(self)
    
    def render(self):
        """This method is called when the contents of the view needs to
        be redrawn, with the view's OpenGL context as the current context.
        After calling this method, buffers will be automatically swapped or
        drawing flushed as appropriate."""
        pass
    
    def viewport_changed(self):
        """This method is called when the view's size has changed, with
        the view's OpenGL context as the current context, and the OpenGL
        viewport set to (0, 0, width, height)."""
        pass

    def update(self):
        """Redraws the contents of the view immediately, without waiting
        for a return to the event loop."""
        self.with_context(self.render, flush = True)
