|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.grogra.imp.awt.ViewComponentAdapter de.grogra.imp3d.glsl.GLDisplay
public class GLDisplay
This class is responsible for drawing all visible objects in the GroIMP3D editor. It uses OpenGL to provide hardware accelerated drawing. To access OpenGL, the library JOGL has to be installed. JOGL is available from: https://jogl.dev.java.net/ Download the jogl.jar (contains the Java API for JOGL) and the jogl-natives-*.jar (contains the native library for your system). When starting GroIMP, make sure that the jogl.jar is in your classpath and the libraries (.dll or .so) from the jogl-natives-*.jar are in your search path for system libraries. Making thos files available can be done by calling GroIMP like this: \code (linux version) javaw -cp core.jar:jogl.jar -Djava.library.path=/usr/lib/jogl de.grogra.pf.boot.Main (windows version) javaw -cp core.jar;jogl.jar -Djava.library.path=c:\java\jogl de.grogra.pf.boot.Main \endcode OpenGL acts as a state machine. To provide a consistent state for every drawing function, some rules were created. There are state variables that are expected to have a certain value when a drawing function is entered. Those state variables are: - MatrixMode set to GL_MODELVIEW - ShadeModel set to GL_SMOOTH - GL_DEPTH_TEST enabled - GL_LIGHTING enabled - GL_TEXTURE_2D disabled - GL_CULL_FACE enabled - GL_COLOR_MATERIAL enabled - ColorMaterial is set to GL_FRONT_AND_BACK and GL_AMBIENT_AND_DIFFUSE - GL_NORMALIZE is enabled - PolygonMode is set to GL_FRONT_AND_BACK and GL_LINE - GL_ALPHA_TEST enabled - AlphaFunc set to GL_GREATER and 0.1f - GL_LIGHT_MODEL_TWO_SIDE is set to 0 If a drawing function changes some of those state variables, it has to reset them to their previous value upon return. Other state variables are not expected to have a defined value when a drawing function is called. Those state variables are: - all texture related state for TEXTURE UNIT 0 - the contents of the matrices MODELVIEW and TEXTURE All state variables not mentioned above should be reset to their default value as defined by OpenGL when they were changed. This class also provides an implementation of LOD (level of detail). For now lod is only applied to the sphere and frustum primitives. While the sphere uses the lod to select the appropriate display list, the frustum uses it to calculate the number of generated segments when drawing.
Nested Class Summary | |
---|---|
class |
GLDisplay.GLVisitor
This class is used to traverse the graph and obtain all visible objects and the lights for visualisation. |
Field Summary | |
---|---|
protected int |
curHighlight
|
protected int |
dlSphere
Display list number for spheres. |
protected int |
dlSupershape
Display list number for supershapes. |
protected Point3f |
endPoint
|
protected Color3f |
gridColor
|
protected int[] |
lineWidth
|
protected static int |
LOD_LEVELS
maximum number of levels of detail |
protected float |
optionGridColorB
|
protected float |
optionGridColorG
|
protected float |
optionGridColorR
|
protected int |
optionGridDimension
|
protected float |
optionGridSpacing
|
protected boolean |
optionShowAxes
|
protected boolean |
optionShowDisplaySize
|
protected boolean |
optionShowGrid
|
protected boolean |
optionShowPoints
|
protected PolygonizationCache |
polyCache
|
Pool |
pool
|
static Type |
RENDER_MODE
|
protected Point3f |
startPoint
|
protected boolean |
supportsVBO
If the GL context supports the ARB extension GL_ARB_vertex_buffer_object this flag is set to true in the initialization function. |
protected GLDisplay.GLVisitor |
visitor
|
Fields inherited from class de.grogra.imp.awt.ViewComponentAdapter |
---|
DISPOSED, DISPOSING, RENDERED_IMAGE, RENDERING, REPAINT_MASK |
Fields inherited from interface de.grogra.imp3d.RenderState |
---|
CURRENT_HIGHLIGHT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Fields inherited from interface de.grogra.imp.ViewComponent |
---|
ALL, CHANGED, MIN_USER_FLAG, SCENE, SELECTION, TOOLS |
Constructor Summary | |
---|---|
GLDisplay()
|
Method Summary | |
---|---|
void |
display(javax.media.opengl.GLAutoDrawable d)
|
void |
displayChanged(javax.media.opengl.GLAutoDrawable d,
boolean modeChanged,
boolean deviceChanged)
|
void |
dispose()
|
protected void |
drawAxes(javax.media.opengl.GL gl,
Camera c)
|
void |
drawBox(float halfWidth,
float halfLength,
float height,
Shader s,
int highlight,
Matrix4d t)
Draw a box from -axis to +axis using the transformation matrix t. |
protected void |
drawDisplaySize(javax.media.opengl.GL gl,
Camera c)
|
void |
drawFrustum(float length,
float baseRadius,
float topRadius,
boolean baseClosed,
boolean topClosed,
float scaleV,
Shader s,
int highlight,
Matrix4d t)
Can be used to draw cylinders and the like. |
void |
drawLine(Tuple3f origin,
Tuple3f end,
Tuple3f color,
int highlight,
Matrix4d t)
Connect the two points with a line and apply the transformation matrix. |
void |
drawParallelogram(float length,
Vector3f axis,
float scaleU,
float scaleV,
Shader s,
int highlight,
Matrix4d t)
|
void |
drawPlane(Shader s,
int highlight,
Matrix4d t)
Draw an x/y plane. |
void |
drawPoint(Tuple3f origin,
int pixelSize,
Tuple3f color,
int highlight,
Matrix4d t)
Draw a single point with the specified pixel size and color. |
void |
drawPointCloud(float[] locations,
float pointSize,
Tuple3f color,
int highlight,
Matrix4d t)
Draw a set of points. |
void |
drawPolygons(Polygonizable pz,
java.lang.Object obj,
boolean asNode,
Shader s,
int highlight,
Matrix4d t)
|
void |
drawRectangle(int x,
int y,
int w,
int h,
Tuple3f color)
Draw a rectangle from (x/y) to (x+w/y+h) with the specified color. |
void |
drawSphere(float radius,
Shader s,
int highlight,
Matrix4d t)
Draw a sphere with the specified radius around the origin (0/0/0). |
void |
drawString(int x,
int y,
java.lang.String text,
java.awt.Font font,
Tuple3f color)
Draw a string with the selected font and color at location (x/y). |
void |
drawSupershape(float a,
float b,
float m1,
float n11,
float n12,
float n13,
float m2,
float n21,
float n22,
float n23,
Shader s,
int highlight,
Matrix4d t)
Draw a supershape around the origin (0/0/0). |
int |
drawWithDisplayList(int index,
javax.media.opengl.GL gl,
de.grogra.imp3d.glsl.DisplayListRenderable dlr,
int levels,
float lod)
|
float |
estimateScaleAt(Tuple3f point)
|
float |
estimateScaleAt(Tuple3f point,
Matrix4d t)
Returns the size of an object of size 1.0 (in object coordinates) on the screen (in pixels). |
void |
fillRectangle(int x,
int y,
int w,
int h,
Tuple3f color)
Draw a filled rectangle from (x/y) to (x+w/y+h) with the specified color. |
java.lang.Object |
getComponent()
|
int |
getCurrentHighlight()
|
Shader |
getCurrentShader()
|
protected float |
getLOD(Matrix4d t,
float r)
Calculate level of detail. |
protected java.awt.image.ImageObserver |
getObserverForRenderer()
Returns an observer which receives the information about the rendered image from a Renderer . |
Pool |
getPool()
|
protected Shader |
getShader(Shader s)
|
protected Matrix4d |
getTransformation(Matrix4d t)
|
View3D |
getView3D()
|
boolean |
getWindowPos(Tuple3f origin,
Tuple2f out)
Computes the window coordinates in pixels of a location in the current object coordinates. |
boolean |
imageUpdate(java.awt.Image img,
int infoflags,
int x,
int y,
int width,
int height)
This class implements the ImageObserver interface to be notified about changes of the background image. |
void |
init(javax.media.opengl.GLAutoDrawable d)
Initialise opengl state and set default values. |
protected void |
initRender(int flags)
Performs initialization tasks in preparation for rendering. |
void |
initView(View view,
EventListener listener)
Initializes this component. |
protected void |
invokeRender(int flags)
Invoked to perform rendering. |
static boolean |
isExtensionSupported(javax.media.opengl.GL gl,
java.lang.String extension)
|
void |
makeSnapshot(ObjectConsumer<? super java.awt.image.RenderedImage> callback)
Instructs the view component to create a snapshot. |
protected void |
optionValueChanged(java.lang.String name,
java.lang.Object value)
|
protected void |
render(int flags)
Render the scene graph. |
void |
reshape(javax.media.opengl.GLAutoDrawable d,
int x,
int y,
int w,
int h)
|
Methods inherited from class de.grogra.imp.awt.ViewComponentAdapter |
---|
checkRepaint, checkRepaintWrapException, disposeRenderer, getColor, getColor, getFactory, getFontMetrics, getGlobalLOD, getIntColor, getInterruptedException, getOption, getRenderGraphState, getView, initFactory, installListeners, invokeRenderSync, render, render, renderUninterruptibly, repaint, run, toSelection, uninstallListeners |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface de.grogra.imp3d.RenderState |
---|
getFontMetrics, getRenderGraphState |
Methods inherited from interface de.grogra.pf.ui.edit.Selectable |
---|
toSelection |
Field Detail |
---|
protected int curHighlight
protected int dlSphere
protected int dlSupershape
protected final Point3f endPoint
protected final Color3f gridColor
protected final int[] lineWidth
protected static final int LOD_LEVELS
protected float optionGridColorB
protected float optionGridColorG
protected float optionGridColorR
protected int optionGridDimension
protected float optionGridSpacing
protected boolean optionShowAxes
protected boolean optionShowDisplaySize
protected boolean optionShowGrid
protected boolean optionShowPoints
protected PolygonizationCache polyCache
public final Pool pool
public static final Type RENDER_MODE
protected final Point3f startPoint
protected boolean supportsVBO
protected GLDisplay.GLVisitor visitor
Constructor Detail |
---|
public GLDisplay()
Method Detail |
---|
public void display(javax.media.opengl.GLAutoDrawable d)
display
in interface javax.media.opengl.GLEventListener
public void displayChanged(javax.media.opengl.GLAutoDrawable d, boolean modeChanged, boolean deviceChanged)
displayChanged
in interface javax.media.opengl.GLEventListener
public void dispose()
dispose
in interface Disposable
dispose
in class ViewComponentAdapter
protected void drawAxes(javax.media.opengl.GL gl, Camera c)
public void drawBox(float halfWidth, float halfLength, float height, Shader s, int highlight, Matrix4d t)
drawBox
in interface RenderState
axis
- defines size of boxprotected void drawDisplaySize(javax.media.opengl.GL gl, Camera c)
public void drawFrustum(float length, float baseRadius, float topRadius, boolean baseClosed, boolean topClosed, float scaleV, Shader s, int highlight, Matrix4d t)
drawFrustum
in interface RenderState
public void drawLine(Tuple3f origin, Tuple3f end, Tuple3f color, int highlight, Matrix4d t)
drawLine
in interface RenderState
public void drawParallelogram(float length, Vector3f axis, float scaleU, float scaleV, Shader s, int highlight, Matrix4d t)
drawParallelogram
in interface RenderState
public void drawPlane(Shader s, int highlight, Matrix4d t)
drawPlane
in interface RenderState
public void drawPoint(Tuple3f origin, int pixelSize, Tuple3f color, int highlight, Matrix4d t)
drawPoint
in interface RenderState
pixelSize
- size of point on screen in pixelspublic void drawPointCloud(float[] locations, float pointSize, Tuple3f color, int highlight, Matrix4d t)
RenderState
drawPointCloud
in interface RenderState
locations
- array containing a sequence (x,y,z) of pointspointSize
- size of the point on screencolor
- color of the pointt
- transformation of the point cloudpublic void drawPolygons(Polygonizable pz, java.lang.Object obj, boolean asNode, Shader s, int highlight, Matrix4d t)
drawPolygons
in interface RenderState
public void drawRectangle(int x, int y, int w, int h, Tuple3f color)
drawRectangle
in interface RenderState
public void drawSphere(float radius, Shader s, int highlight, Matrix4d t)
drawSphere
in interface RenderState
public void drawString(int x, int y, java.lang.String text, java.awt.Font font, Tuple3f color)
drawString
in interface RenderState
public void drawSupershape(float a, float b, float m1, float n11, float n12, float n13, float m2, float n21, float n22, float n23, Shader s, int highlight, Matrix4d t)
drawSupershape
in interface RenderState
a,
- b length of curvesm,
- n shape parametersshader
- highlight
- t
- transformation of the point cloudpublic int drawWithDisplayList(int index, javax.media.opengl.GL gl, de.grogra.imp3d.glsl.DisplayListRenderable dlr, int levels, float lod)
public float estimateScaleAt(Tuple3f point)
estimateScaleAt
in interface RenderState
public float estimateScaleAt(Tuple3f point, Matrix4d t)
point
- t
-
public void fillRectangle(int x, int y, int w, int h, Tuple3f color)
fillRectangle
in interface RenderState
public java.lang.Object getComponent()
getComponent
in interface ComponentWrapper
public int getCurrentHighlight()
getCurrentHighlight
in interface RenderState
public Shader getCurrentShader()
getCurrentShader
in interface RenderState
protected float getLOD(Matrix4d t, float r)
protected java.awt.image.ImageObserver getObserverForRenderer()
ViewComponentAdapter
Renderer
. The returned observer
has to manage the drawing of the (partially) rendered image
on the view component.
getObserverForRenderer
in class ViewComponentAdapter
null
if
this is not supported by this componentpublic Pool getPool()
getPool
in interface RenderState
protected Shader getShader(Shader s)
protected Matrix4d getTransformation(Matrix4d t)
public View3D getView3D()
public boolean getWindowPos(Tuple3f origin, Tuple2f out)
RenderState
getWindowPos
in interface RenderState
origin
- a location in local object coordinatesout
- the computed window coordinates are placed in here
true
iff the window coordinates are valid
(i.e., the location is in the clipping region)public boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
imageUpdate
in interface java.awt.image.ImageObserver
public void init(javax.media.opengl.GLAutoDrawable d)
init
in interface javax.media.opengl.GLEventListener
protected void initRender(int flags)
ViewComponentAdapter
ViewComponentAdapter.run()
in this
ViewComponent
's own thread.
initRender
in class ViewComponentAdapter
flags
- combination of bit maskspublic void initView(View view, EventListener listener)
ViewComponent
view
within which this view component is used to display the graph.
It also sets an event listener. this has to be informed of
mouse and keys events within the view component by implementations
of this method.
initView
in interface ViewComponent
initView
in class ViewComponentAdapter
view
- the containing viewlistener
- mouse and key events will be reported to this listenerprotected void invokeRender(int flags)
ViewComponentAdapter
ViewComponentAdapter.run()
in this ViewComponent
's own thread.
Its sole task is to invoke ViewComponentAdapter.invokeRenderSync(int)
in
the rendering thread (which may be this
ViewComponent
's thread, the AWT-thread, or another
thread, depending on the implementation) in a write-protected
context. The invocation has to be
synchronously, i.e., if it is in another thread, the current thread
has to wait until ViewComponentAdapter.invokeRenderSync(int)
has completed.
invokeRender
in class ViewComponentAdapter
flags
- the flags to pass to ViewComponentAdapter.invokeRenderSync(int)
public static boolean isExtensionSupported(javax.media.opengl.GL gl, java.lang.String extension)
public void makeSnapshot(ObjectConsumer<? super java.awt.image.RenderedImage> callback)
ViewComponent
callback
as an
instance of RenderedImage
. This may happen asynchronously,
i.e., in an arbitrary thread.
makeSnapshot
in interface ViewComponent
callback
- callback which asynchronously receives the snapshotprotected void optionValueChanged(java.lang.String name, java.lang.Object value)
optionValueChanged
in class ViewComponentAdapter
protected void render(int flags) throws java.lang.InterruptedException
render
in class ViewComponentAdapter
flags
- combination of bit masks
java.lang.InterruptedException
- if the rendering has been interruptedpublic void reshape(javax.media.opengl.GLAutoDrawable d, int x, int y, int w, int h)
reshape
in interface javax.media.opengl.GLEventListener
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |