org.xith3d.render
Class CanvasPeer

java.lang.Object
  extended by org.xith3d.render.CanvasPeer
All Implemented Interfaces:
org.jagatoo.input.render.InputSourceWindow
Direct Known Subclasses:
CanvasPeerImplBase, CanvasPeerImplBase

public abstract class CanvasPeer
extends java.lang.Object
implements org.jagatoo.input.render.InputSourceWindow

All CanvasPeer implementations must extend this class.
It offers the base methods of all implementations.


Field Summary
protected  boolean isGammaChanged
           
protected  OpenGLInfo oglInfo
           
 
Constructor Summary
CanvasPeer(DisplayMode displayMode, DisplayMode.FullscreenMode fullscreen, boolean vsync, FSAA fsaa, int depthBufferSize)
           
 
Method Summary
protected  void addDestroyableObject(SceneGraphOpenGLReference ref)
           
 void addTriangles(long num)
           
protected  void addWindowClosingListener(WindowClosingListener l)
          Adds a new WindowClosingListener to be notified, when a non-fullscreen Canvas3D's Window is to be closed by clicking the X-button.
abstract  void beforeThreadChanged()
          This method should be executed by the Thread that starts the actual rendering Thread right before it starts it.
abstract  void clear()
          Clears the screen to BLACK.
protected abstract  RenderPeer createRenderPeer()
           
 void destroy()
          Clears the screen (BLACK) and destroys the display.
protected  void destroyGLNames(boolean onlyGCed)
           
protected  void fireClosingEvent()
           
 int getBPP()
           
 float getBrightness()
           
 Canvas3D getCanvas3D()
           
 int getCanvasID()
           
abstract  java.lang.Object getComponent()
           
 float getContrast()
           
 org.jagatoo.input.render.Cursor getCursor()
           
 int getDepthBufferSize()
           
 DisplayMode getDisplayMode()
           
protected abstract  java.lang.Class<?> getExpectedNativeDisplayModeClass()
           
 int getFrequency()
           
 FSAA getFSAA()
           
protected  java.lang.Boolean getFullscreenSwitchRequest()
           
 float getGamma()
           
abstract  int getHeight()
          Gets the width in an implementation independant manner
 org.jagatoo.input.devices.InputDeviceFactory getInputDeviceFactory()
           
abstract  int getLeft()
          Gets the left-location in an implementation independant manner
 int getMaxTextureSize()
           
 int getMaxTextureUnits()
           
 int getMaxVertexAttributes()
           
abstract  org.openmali.types.twodee.Rect2i getMaxViewport()
           
 OpenGLCapabilities getOpenGLCapabilities()
           
 OpenGLInfo getOpenGLInfo()
           
abstract  long getRenderedFrames()
           
 java.lang.Object getRenderLock()
           
 RenderPeer getRenderPeer()
           
abstract  java.lang.String getTitle()
          Gets the title in an implementation independant manner
abstract  int getTop()
          Gets the top-location in an implementation independant manner
 long getTriangles()
           
abstract  OpenGLLayer getType()
           
 org.openmali.types.twodee.Rect2i getViewport()
           
abstract  int getWidth()
          Gets the width in an implementation independant manner
abstract  java.lang.Object getWindow()
           
protected abstract  java.lang.Object initRenderingImpl(View view, java.util.List<RenderPass> renderPasses, boolean layeredMode, long frameId, long nanoTime, long nanoStep, PickRequest pickRequest)
          Initializes the rendering.
protected  boolean isClosingListenerRegistered()
           
 boolean isDestroyed()
           
 boolean isFullscreen()
           
abstract  boolean isRendering()
          This flag is set by the Rendering system triggered by xith or by the CanvasPeer implementation itself (e.g when the CanvasPeer is auto-redrawn).
 boolean isUndecorated()
           
 boolean isVSyncEnabled()
           
protected  void removeWindowClosingListener(WindowClosingListener l)
          Removes a WindowClosingListener.
protected  void resetFullscreenSwitchRequest()
           
protected  void setCanvas3D(Canvas3D canvas)
           
 void setCursor(org.jagatoo.input.render.Cursor cursor)
          Sets the new Cursor for this Mouse.
protected  void setCursorImpl(org.jagatoo.input.render.Cursor cursor)
          This method is called when a NEW Cursor is applied to this Mouse.
protected  void setDepthBufferSize(int size)
           
 boolean setDisplayMode(DisplayMode displayMode)
          Sets the new DisplayMode in an implementation independant manner
protected abstract  boolean setDisplayModeImpl(DisplayMode displayMode)
          Sets the new DisplayMode in an implementation independant manner.
protected  void setDisplayModeRef(DisplayMode displayMode)
           
 boolean setFullscreen(boolean fullscreen)
          Switches this Canvas3D's fullscreen flag.
 void setGamma(float gamma, float brightness, float contrast)
          Changes the gamma-, brightness- and contrast values for this CanvasPeer.
abstract  void setIcon(java.net.URL iconResource)
          Changes the window icon.
abstract  boolean setLocation(int x, int y)
          Sets the location in an implementation independant manner.
protected  void setOpenGLCapabilities(OpenGLCapabilities caps)
           
abstract  boolean setSize(int width, int height)
          Sets the size in an implementation independant manner.
abstract  void setTitle(java.lang.String title)
          Sets the title in an implementation independant manner.
 void setTriangles(long num)
           
 void setViewport(org.openmali.types.twodee.Rect2i viewport)
          Sets this CanvasPeer's Viewport.
 void setVSyncEnabled(boolean vsync)
          Enables or disables V-Sync.
 java.io.File takeScreenshot(boolean alpha)
          Takes a screenshot of the current rendering of the first added Canvas3D.
 void takeScreenshot(java.io.File file, boolean alpha)
          Takes a screenshot of the current rendering
 java.io.File takeScreenshot(java.lang.String filenameBase, boolean alpha)
          Takes a screenshot of the current rendering
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jagatoo.input.render.InputSourceWindow
getDrawable, getInputDeviceFactory, receivesInputEvents, refreshCursor
 

Field Detail

oglInfo

protected OpenGLInfo oglInfo

isGammaChanged

protected boolean isGammaChanged
Constructor Detail

CanvasPeer

public CanvasPeer(DisplayMode displayMode,
                  DisplayMode.FullscreenMode fullscreen,
                  boolean vsync,
                  FSAA fsaa,
                  int depthBufferSize)
Method Detail

createRenderPeer

protected abstract RenderPeer createRenderPeer()

getRenderPeer

public RenderPeer getRenderPeer()

setCanvas3D

protected void setCanvas3D(Canvas3D canvas)

getCanvas3D

public Canvas3D getCanvas3D()

getType

public abstract OpenGLLayer getType()
Returns:
an element of the OpenGLLayer enum.
See Also:
OpenGLLayer

getCanvasID

public final int getCanvasID()
Returns:
unique, one-based canvas ID assigned to this instance of canvas peer. It can be used to ensure that some cached resources have been created for specific canvas, and support multiple cached resources for specific object (for example, Texture) on different canvases.

getOpenGLInfo

public final OpenGLInfo getOpenGLInfo()
Returns:
a structure holding the textual information about the OpenGLLayer

getRenderLock

public final java.lang.Object getRenderLock()

getFullscreenSwitchRequest

protected final java.lang.Boolean getFullscreenSwitchRequest()

resetFullscreenSwitchRequest

protected final void resetFullscreenSwitchRequest()

setFullscreen

public boolean setFullscreen(boolean fullscreen)
Switches this Canvas3D's fullscreen flag.
Depending on the implementation this flag may be applied on the next render-frame, but not instantly.

Parameters:
fullscreen -
Returns:
the previous fullscreen flag.

isFullscreen

public final boolean isFullscreen()
Returns:
true, if the rendering is done in fullscreen mode

isUndecorated

public final boolean isUndecorated()
Returns:
true, if this Canvas'es window is undecorated.

getExpectedNativeDisplayModeClass

protected abstract java.lang.Class<?> getExpectedNativeDisplayModeClass()

setDisplayModeImpl

protected abstract boolean setDisplayModeImpl(DisplayMode displayMode)
Sets the new DisplayMode in an implementation independant manner.

Parameters:
displayMode -

setDisplayModeRef

protected final void setDisplayModeRef(DisplayMode displayMode)

setDisplayMode

public final boolean setDisplayMode(DisplayMode displayMode)
Sets the new DisplayMode in an implementation independant manner


getDisplayMode

public final DisplayMode getDisplayMode()
Returns:
the current DisplayMode.

getBPP

public final int getBPP()
Returns:
the color depth.

getFrequency

public final int getFrequency()
Returns:
the displaymode's frequency.

setVSyncEnabled

public void setVSyncEnabled(boolean vsync)
Enables or disables V-Sync.


isVSyncEnabled

public final boolean isVSyncEnabled()
Returns:
true, if vsync has been enabled at creation time.

getFSAA

public final FSAA getFSAA()
Returns:
the full scene anti aliasing mode

setDepthBufferSize

protected void setDepthBufferSize(int size)

getDepthBufferSize

public final int getDepthBufferSize()
Returns:
the bit-depth of the depth-buffer.

isClosingListenerRegistered

protected final boolean isClosingListenerRegistered()

addWindowClosingListener

protected void addWindowClosingListener(WindowClosingListener l)
Adds a new WindowClosingListener to be notified, when a non-fullscreen Canvas3D's Window is to be closed by clicking the X-button.

Parameters:
l -

removeWindowClosingListener

protected void removeWindowClosingListener(WindowClosingListener l)
Removes a WindowClosingListener.

Parameters:
l -

fireClosingEvent

protected void fireClosingEvent()

setOpenGLCapabilities

protected final void setOpenGLCapabilities(OpenGLCapabilities caps)

getOpenGLCapabilities

public final OpenGLCapabilities getOpenGLCapabilities()

getMaxTextureSize

public final int getMaxTextureSize()
Returns:
the maximum texture size.

getMaxTextureUnits

public final int getMaxTextureUnits()
Returns:
the maximum number of texture units.

getMaxVertexAttributes

public final int getMaxVertexAttributes()
Returns:
the maximum number of vertex attributes.

setTriangles

public final void setTriangles(long num)

addTriangles

public final void addTriangles(long num)

getTriangles

public final long getTriangles()
Returns:
the number of triangles currently being rendered.

getRenderedFrames

public abstract long getRenderedFrames()
Returns:
the number of frames already rendered

getWindow

public abstract java.lang.Object getWindow()
Returns:
the Window holding the Canvas.

getComponent

public abstract java.lang.Object getComponent()
Returns:
the Component holding the Canvas.

setIcon

public abstract void setIcon(java.net.URL iconResource)
                      throws java.io.IOException
Changes the window icon.

Parameters:
iconResource - the resource of the image for the new icon
Throws:
java.io.IOException

setCursorImpl

protected void setCursorImpl(org.jagatoo.input.render.Cursor cursor)
This method is called when a NEW Cursor is applied to this Mouse.

Parameters:
cursor -

setCursor

public final void setCursor(org.jagatoo.input.render.Cursor cursor)
Sets the new Cursor for this Mouse. Use null for an invisible Cursor. Use Cursor.DEFAULT_CURSOR for the system's default Cursor.

Specified by:
setCursor in interface org.jagatoo.input.render.InputSourceWindow
Parameters:
cursor -

getCursor

public final org.jagatoo.input.render.Cursor getCursor()
Specified by:
getCursor in interface org.jagatoo.input.render.InputSourceWindow

setTitle

public abstract void setTitle(java.lang.String title)
Sets the title in an implementation independant manner.

Parameters:
title -

getTitle

public abstract java.lang.String getTitle()
Gets the title in an implementation independant manner


getInputDeviceFactory

public final org.jagatoo.input.devices.InputDeviceFactory getInputDeviceFactory()
Returns:
the InputDeviceFactory, that provides methods to retrieve InputDevices for the specified implementation.
Using this method is equal to calling:
getInputDeviceFactory( InputSystem.getInstance() );

setLocation

public abstract boolean setLocation(int x,
                                    int y)
Sets the location in an implementation independant manner.

Parameters:
x -
y -

getLeft

public abstract int getLeft()
Gets the left-location in an implementation independant manner


getTop

public abstract int getTop()
Gets the top-location in an implementation independant manner


setSize

public abstract boolean setSize(int width,
                                int height)
Sets the size in an implementation independant manner.

Parameters:
width -
height -

getWidth

public abstract int getWidth()
Gets the width in an implementation independant manner

Specified by:
getWidth in interface org.jagatoo.input.render.InputSourceWindow

getHeight

public abstract int getHeight()
Gets the width in an implementation independant manner

Specified by:
getHeight in interface org.jagatoo.input.render.InputSourceWindow

getMaxViewport

public abstract org.openmali.types.twodee.Rect2i getMaxViewport()
Returns:
the maximum size of the viewport.
The values will be invalid before the first frame is rendered.

setViewport

public void setViewport(org.openmali.types.twodee.Rect2i viewport)
Sets this CanvasPeer's Viewport.

Parameters:
viewport -

getViewport

public org.openmali.types.twodee.Rect2i getViewport()
Returns:
this CanvasPeer's Viewport

setGamma

public void setGamma(float gamma,
                     float brightness,
                     float contrast)
Changes the gamma-, brightness- and contrast values for this CanvasPeer.

Parameters:
gamma - the gamma value
brightness - the brightness value [-1.0, +1.0]
contrast - the contrast value [0, +1.0]

getGamma

public float getGamma()
Returns:
the current gamma value for this CanvasPeer.

getBrightness

public float getBrightness()
Returns:
the current brightness value for this CanvasPeer.

getContrast

public float getContrast()
Returns:
the current contrast value for this CanvasPeer.

isRendering

public abstract boolean isRendering()
This flag is set by the Rendering system triggered by xith or by the CanvasPeer implementation itself (e.g when the CanvasPeer is auto-redrawn).


beforeThreadChanged

public abstract void beforeThreadChanged()
This method should be executed by the Thread that starts the actual rendering Thread right before it starts it. (LWJGL needs this)


initRenderingImpl

protected abstract java.lang.Object initRenderingImpl(View view,
                                                      java.util.List<RenderPass> renderPasses,
                                                      boolean layeredMode,
                                                      long frameId,
                                                      long nanoTime,
                                                      long nanoStep,
                                                      PickRequest pickRequest)
Initializes the rendering. The CanvasPeer implementation may decide when to actually do.

Parameters:
view - the View used to render
renderPasses - the List of RenderPasses to iterate and render
layeredMode - if true, the RenderPasses are handled in layered mode
frameId - the current frame's id
pickRequest - null for normal rendering

clear

public abstract void clear()
Clears the screen to BLACK.


isDestroyed

public final boolean isDestroyed()

addDestroyableObject

protected void addDestroyableObject(SceneGraphOpenGLReference ref)

destroyGLNames

protected final void destroyGLNames(boolean onlyGCed)

destroy

public void destroy()
Clears the screen (BLACK) and destroys the display.


takeScreenshot

public void takeScreenshot(java.io.File file,
                           boolean alpha)
Takes a screenshot of the current rendering

Parameters:
file - the file to save the screenshot to
alpha - with alpha channel?

takeScreenshot

public final java.io.File takeScreenshot(java.lang.String filenameBase,
                                         boolean alpha)
Takes a screenshot of the current rendering

Parameters:
filenameBase - the filenameBase to save the screenshot to (e.g. "screens/shot") The current date and ".png" are appended.
alpha - with alpha channel?
Returns:
the file where the screenshot has been saved

takeScreenshot

public final java.io.File takeScreenshot(boolean alpha)
Takes a screenshot of the current rendering of the first added Canvas3D.

Parameters:
alpha - with alpha channel?
Returns:
the file where the screenshot has been saved