gzz.gfx.gl
Class GL

java.lang.Object
  |
  +--gzz.gfx.gl.GL
Direct Known Subclasses:
GLRen

public class GL
extends java.lang.Object

The interface to the native OpenGL library. Note: here we must be VERY careful, as this is one of the places where foreign code is not sandboxed automatically for us. All parameters that go to C level must be checked either here or at the C level, otherwise -- BOOM.


Nested Class Summary
static class GL.ByteVector
          A vector of bytes stored in C++ space.
static class GL.DisplayList
          An OpenGL display list.
static interface GL.EventHandler
          An interface to which GL provides events.
static class GL.Font
          A (mosaic-tiled) OpenGL font.
static class GL.Image
          A buffer on the C++ side, containing a single image.
static class GL.ImageCache
           
static class GL.JavaObject
          The Java proxy for a C++ object.
static class GL.NonRenderableJavaObject
          A Java object which is not supposed to be placed on display lists.
static class GL.Program
          An OpenGL program object.
static class GL.Renderable0JavaObject
          The Java proxy representing a Renderable object.
static class GL.Renderable1JavaObject
          The Java proxy representing a Renderable object.
static class GL.Renderable2JavaObject
          The Java proxy representing a Renderable2 object.
static class GL.Renderable3JavaObject
          The Java proxy representing a Renderable2 object.
static class GL.RenderingSurface
           
static class GL.ShaderRect
          3D/2D shader image data, loaded into textures.
static class GL.TexRect
          A rectangular region of an image, loaded into a texture.
static class GL.Texture
          A texture object.
static class GL.Window
          An on-screen GLX window into which graphics can be drawn.
 
Field Summary
static int CSFLAG_ACTIVE
          Constants to bit-or with coordsys types.
static int CSFLAGS
          Constants to bit-or with coordsys types.
static boolean dbg
           
static int RENDERABLE0
          Constant for the int array to be passed to C++, or'ed together with the ID, indicating a zero-argument renderable.
static int RENDERABLE1
          See RENDERABLE0.
static int RENDERABLE2
          See RENDERABLE0.
static int RENDERABLE3
          See RENDERABLE0.
static boolean workaroundStupidBuggyAtiDrivers
          ATI drivers for the R300 family still have some serious bugs.
 
Constructor Summary
GL()
           
 
Method Summary
static void addDeletable(GLDeletable d)
          To be called from d.finalize(): set this object's deleteObject() to be called in GL thread.
static int bitsPerTexel(java.lang.String format)
          If known, return bits per texel of a given format.
static void call(java.lang.String s)
          CallGL the given string.
static void call(java.lang.String s, GL.Window w)
          CallGL the given string in the given window.
static GL.ByteVector createByteVector()
          Create a new bytevector of size 0.
static GL.ByteVector createByteVector(int size)
          Create a new bytevector of the given size.
static GL.DisplayList createDisplayList()
          Create a new, empty display list.
static GL.DisplayList createDisplayList(java.lang.String s)
          Create a new display list and compile the given string using CallGL into it.
static GL.Font createFont(java.lang.String name, int loadPt)
          Create a new font.
static GL.Image createImage(java.lang.String filename)
          Create a new image from the prescribed file.
static GL.Program createProgram()
           
static GL.Program createProgram(java.lang.String program)
           
static GL.ShaderRect createShaderRect(java.lang.String turb, java.lang.String col, java.lang.String spots, java.lang.String cell)
           
static GL.RenderingSurface createStableRenderingSurface(int w, int h)
           
static GL.TexRect createTexRect(GL.Image img)
          Create a new TexRect by loading the given image into a mosaic tile.
static GL.Texture createTexture()
          Create a new OpenGL texture object.
static GL.Window createWindow(int x, int y, int w, int h, GL.EventHandler eh)
          Create a new window.
static void eventLoop(boolean wait)
          Process native events.
static void freeQueue()
          Because objects have to be released by the same thread that obtained them, this method needs to be called every once in a while.
static int[] getAllCSAt(int ninds, int[] inds, float[] pts, int parent, float x, float y)
          Get all the activated coordinate systems in whose unit squares the given point falls..
static int getDebugVar(java.lang.String name)
           
static java.lang.String[] getDebugVarNames()
           
static float[] getGLFloat(java.lang.String name)
          Get float(s) describing the current OpenGL context.
static float[] getGLProgram(java.lang.String target, java.lang.String name)
          Get the given program parameter.
static int getGLProgrami(java.lang.String target, int progId, java.lang.String name)
           
static java.lang.String getGLString(java.lang.String name)
          Get a string describing the current OpenGL context.
static float[] getGLTexLevelParameterFloat(java.lang.String target, int tex, int level, java.lang.String name)
          Get float(s) describing the current state of the given level of the given OpenGL texture.
static float[] getGLTexParameterFloat(java.lang.String target, int tex, java.lang.String name)
          Get float(s) describing the current state of the given OpenGL texture.
static java.lang.String getGLTokenString(int value)
          Get the OpenGL token string corresponding to the given integer value.
static boolean hasExtension(java.lang.String name)
          Return a boolean showing whether the given extension is supported by the current OpenGL environment.
static void init()
          Init the library - to be called once during startup.
static void interruptEventloop()
          Interrupt the event loop.
static void loadLib()
          Load the OpenGL library.
static void render(GL.RenderingSurface win, int ninds, int[] inds1, float[] pts1, int[] interpinds, int[] inds2, float[] pts2, int[] codes, float fract, boolean standardcoords, boolean showFinal)
           
static void setDebugVar(java.lang.String name, int value)
           
static void startBackgroundImageLoader(java.lang.String uri)
           
static float timeRender(GL.RenderingSurface win, int iters, int ninds, int[] inds1, float[] pts1, int[] codes, boolean standardcoords)
           
static boolean transform(int ninds, int[] inds, float[] pts, int coordsys, boolean inverse, float[] points, float[] into)
           
static boolean transform2(int ninds, int[] inds, float[] pts, int[] interpinds, int[] inds2, float[] pts2, float fract, boolean show1, int coordsys, boolean inverse, float[] points, float[] into)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbg

public static boolean dbg

workaroundStupidBuggyAtiDrivers

public static boolean workaroundStupidBuggyAtiDrivers
ATI drivers for the R300 family still have some serious bugs. We have workarounds for some in place; this flag will enable them.

ATI: if you want to know what you're still doing wrong, just grep the source for this variable name ;)

A brief list of some of the issues:


CSFLAG_ACTIVE

public static final int CSFLAG_ACTIVE
Constants to bit-or with coordsys types.

See Also:
Constant Field Values

CSFLAGS

public static final int CSFLAGS
Constants to bit-or with coordsys types.

See Also:
Constant Field Values

RENDERABLE0

public static final int RENDERABLE0
Constant for the int array to be passed to C++, or'ed together with the ID, indicating a zero-argument renderable.

See Also:
Constant Field Values

RENDERABLE1

public static final int RENDERABLE1
See RENDERABLE0.

See Also:
Constant Field Values

RENDERABLE2

public static final int RENDERABLE2
See RENDERABLE0.

See Also:
Constant Field Values

RENDERABLE3

public static final int RENDERABLE3
See RENDERABLE0.

See Also:
Constant Field Values
Constructor Detail

GL

public GL()
Method Detail

loadLib

public static void loadLib()
Load the OpenGL library. Used to set debug variables prior to initializing (which does quite a lot of stuff and needs to be debugged sometimes).


init

public static void init()
Init the library - to be called once during startup.


freeQueue

public static void freeQueue()
Because objects have to be released by the same thread that obtained them, this method needs to be called every once in a while.


addDeletable

public static void addDeletable(GLDeletable d)
To be called from d.finalize(): set this object's deleteObject() to be called in GL thread.


createStableRenderingSurface

public static GL.RenderingSurface createStableRenderingSurface(int w,
                                                               int h)

createWindow

public static GL.Window createWindow(int x,
                                     int y,
                                     int w,
                                     int h,
                                     GL.EventHandler eh)
Create a new window.


createImage

public static GL.Image createImage(java.lang.String filename)
Create a new image from the prescribed file. THIS METHOD IS A SEVERE SECURITY HOLE AND WILL BE REMOVED OR ADJUSTED TO USE A SECURITY MANAGER OR SO. Exploit: load something that the image loader library doesn't like... Need to work out how this should properly interact with mediaserver.

This method is VERY special: it is NOT necessary to have an OpenGL context for the thread it uses since it is guaranteed not to use OpenGL.


startBackgroundImageLoader

public static void startBackgroundImageLoader(java.lang.String uri)

createTexRect

public static GL.TexRect createTexRect(GL.Image img)
Create a new TexRect by loading the given image into a mosaic tile.


createTexture

public static GL.Texture createTexture()
Create a new OpenGL texture object.


createProgram

public static GL.Program createProgram()

createProgram

public static GL.Program createProgram(java.lang.String program)

createShaderRect

public static GL.ShaderRect createShaderRect(java.lang.String turb,
                                             java.lang.String col,
                                             java.lang.String spots,
                                             java.lang.String cell)

createFont

public static GL.Font createFont(java.lang.String name,
                                 int loadPt)
Create a new font.

Parameters:
name - Filename to load the font from.
loadPt - The pixel size to load the font at.

createDisplayList

public static GL.DisplayList createDisplayList()
Create a new, empty display list.


createDisplayList

public static GL.DisplayList createDisplayList(java.lang.String s)
Create a new display list and compile the given string using CallGL into it.


createByteVector

public static GL.ByteVector createByteVector()
Create a new bytevector of size 0.


createByteVector

public static GL.ByteVector createByteVector(int size)
Create a new bytevector of the given size.


call

public static void call(java.lang.String s)
CallGL the given string. Useful for throwaway things such as setting texture parameters.


call

public static void call(java.lang.String s,
                        GL.Window w)
CallGL the given string in the given window.


render

public static void render(GL.RenderingSurface win,
                          int ninds,
                          int[] inds1,
                          float[] pts1,
                          int[] interpinds,
                          int[] inds2,
                          float[] pts2,
                          int[] codes,
                          float fract,
                          boolean standardcoords,
                          boolean showFinal)

timeRender

public static float timeRender(GL.RenderingSurface win,
                               int iters,
                               int ninds,
                               int[] inds1,
                               float[] pts1,
                               int[] codes,
                               boolean standardcoords)

transform

public static boolean transform(int ninds,
                                int[] inds,
                                float[] pts,
                                int coordsys,
                                boolean inverse,
                                float[] points,
                                float[] into)

transform2

public static boolean transform2(int ninds,
                                 int[] inds,
                                 float[] pts,
                                 int[] interpinds,
                                 int[] inds2,
                                 float[] pts2,
                                 float fract,
                                 boolean show1,
                                 int coordsys,
                                 boolean inverse,
                                 float[] points,
                                 float[] into)

getAllCSAt

public static int[] getAllCSAt(int ninds,
                               int[] inds,
                               float[] pts,
                               int parent,
                               float x,
                               float y)
Get all the activated coordinate systems in whose unit squares the given point falls..

Parameters:
parent - (currently ignored, may be used to restrict in future)

eventLoop

public static void eventLoop(boolean wait)
Process native events.

Parameters:
wait - If false, this function will return once there are no more native events to process. If true, this function will wait for the next native event.

interruptEventloop

public static void interruptEventloop()
Interrupt the event loop. Unlike most functions in GL, this can be called from other threads to interrup a waiting event loop at any time. This is useful as a response e.g. for incoming network data.


setDebugVar

public static void setDebugVar(java.lang.String name,
                               int value)

getDebugVar

public static int getDebugVar(java.lang.String name)

getDebugVarNames

public static java.lang.String[] getDebugVarNames()

getGLString

public static java.lang.String getGLString(java.lang.String name)
Get a string describing the current OpenGL context. See the manpage of glGetString(3)

Parameters:
name - The parameter to query, e.g. "VENDOR", "VERSION"

getGLFloat

public static float[] getGLFloat(java.lang.String name)
Get float(s) describing the current OpenGL context. See the manpage of glGetFloatv(3)

Parameters:
name - The parameter to query, e.g. "ALPHA_BITS"

getGLProgram

public static float[] getGLProgram(java.lang.String target,
                                   java.lang.String name)
Get the given program parameter.

Parameters:
target - The name of the program target, e.g. "VERTEX_PROGRAM_ARB"
name - The name of the parameter to return, e.g. "MAX_PROGRAM_INSTRUCTIONS_ARB"

getGLProgrami

public static int getGLProgrami(java.lang.String target,
                                int progId,
                                java.lang.String name)

getGLTexParameterFloat

public static float[] getGLTexParameterFloat(java.lang.String target,
                                             int tex,
                                             java.lang.String name)
Get float(s) describing the current state of the given OpenGL texture. See the manpage of glGetTexParameterfv(3)

Parameters:
target - The texture target to bind the given texture to for querying, e.g. "TEXTURE_2D"
tex - The OpenGL texture id
name - The parameter to query, e.g. "TEXTURE_RESIDENT"

getGLTexLevelParameterFloat

public static float[] getGLTexLevelParameterFloat(java.lang.String target,
                                                  int tex,
                                                  int level,
                                                  java.lang.String name)
Get float(s) describing the current state of the given level of the given OpenGL texture. See the manpage of glGetTexParameterfv(3)

Parameters:
target - The texture target to bind the given texture to for querying, e.g. "TEXTURE_2D"
tex - The OpenGL texture id
level - The mipmap level to query
name - The parameter to query, e.g. "TEXTURE_INTERNAL_FORMAT"

hasExtension

public static boolean hasExtension(java.lang.String name)
Return a boolean showing whether the given extension is supported by the current OpenGL environment. XXX SHould be With / without GL_!!!


getGLTokenString

public static java.lang.String getGLTokenString(int value)
Get the OpenGL token string corresponding to the given integer value. This is useful for producing human-readable output from the result of getGLFloats. For example,
        GL.getGLTokenString(
            (int)(GL.getGLTexLevelParameterFloat(
                        "TEXTURE_2D", id, 0, "TEXTURE_INTERNAL_FORMAT")[0]
                )
        )
 
yields the string representation for the internal format of the given texture id.


bitsPerTexel

public static int bitsPerTexel(java.lang.String format)
If known, return bits per texel of a given format.