From 992b456d64e6128af021067e10e485d25977bf24 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Sat, 27 Mar 2010 02:57:46 +0100 Subject: refactoring due to gluegen changes. - renamed com.sun.gluegen.runtime -> com.jogamp.gluegen.runtime. --- src/jogl/classes/javax/media/opengl/GLContext.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/jogl/classes/javax/media/opengl/GLContext.java') diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 840de4764..3ca1cd317 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -39,7 +39,6 @@ package javax.media.opengl; -import com.sun.opengl.impl.Debug; import java.util.HashMap; /** Abstraction for an OpenGL rendering context. In order to perform @@ -67,6 +66,8 @@ public abstract class GLContext { private HashMap/**/ attachedObjects = new HashMap(); + protected long context; + /** * Returns the GLDrawable to which this context may be used to * draw. -- cgit v1.2.3 From 476d1d755b6d9c5650779aedda1265917a6dec6e Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 29 Mar 2010 22:33:06 +0200 Subject: fixed a bunch of javadoc warnings. --- nbproject/project.xml | 5 ++ .../com/jogamp/opengl/util/ImmModeSink.java | 4 +- .../classes/com/jogamp/opengl/util/PMVMatrix.java | 2 +- .../classes/com/jogamp/opengl/util/TGAWriter.java | 8 ++- .../com/jogamp/opengl/util/glsl/ShaderProgram.java | 13 +++-- .../com/jogamp/opengl/util/glsl/ShaderState.java | 59 ++++++++++------------ .../opengl/util/glsl/fixedfunc/FixedFuncUtil.java | 8 +-- .../jogamp/opengl/util/glsl/sdk/CompileShader.java | 21 ++++---- .../classes/javax/media/opengl/GLArrayData.java | 10 ++-- src/jogl/classes/javax/media/opengl/GLBase.java | 2 +- src/jogl/classes/javax/media/opengl/GLContext.java | 6 +-- .../javax/media/opengl/GLDrawableFactory.java | 4 +- .../classes/javax/media/opengl/GLUniformData.java | 2 - .../javax/media/opengl/fixedfunc/GLMatrixFunc.java | 4 +- .../classes/com/jogamp/newt/opengl/GLWindow.java | 5 +- 15 files changed, 77 insertions(+), 76 deletions(-) (limited to 'src/jogl/classes/javax/media/opengl/GLContext.java') diff --git a/nbproject/project.xml b/nbproject/project.xml index 31339c907..9f8a897bd 100755 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -79,6 +79,10 @@ junit.run + + + javadoc + folder @@ -116,6 +120,7 @@ + diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index 126a303ab..ad230a415 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -35,8 +35,8 @@ public class ImmModeSink { * a ShaderState must be current, using ShaderState.glUseProgram(). * * @see #draw(GL, boolean) - * @see javax.media.opengl.glsl.ShaderState#glUseProgram(GL2ES2, boolean) - * @see javax.media.opengl.glsl.ShaderState#getCurrent() + * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean) + * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent() */ public static ImmModeSink createGLSL(GL gl, int glBufferUsage, int initialSize, int vComps, int vDataType, diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java index f6d5f1999..4ca8ff197 100755 --- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java +++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java @@ -295,7 +295,7 @@ public class PMVMatrix implements GLMatrixFunc { } /** - * @param pname GL_MODELVIEW, GL_PROJECTION or GL.GL_TEXTURE + * @param matrixName GL_MODELVIEW, GL_PROJECTION or GL.GL_TEXTURE * @return the given matrix */ public final FloatBuffer glGetMatrixf(final int matrixName) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/TGAWriter.java b/src/jogl/classes/com/jogamp/opengl/util/TGAWriter.java index c53cafdcb..b949f0e39 100755 --- a/src/jogl/classes/com/jogamp/opengl/util/TGAWriter.java +++ b/src/jogl/classes/com/jogamp/opengl/util/TGAWriter.java @@ -42,13 +42,11 @@ import java.nio.channels.*; /** * Utility class which helps take fast screenshots of OpenGL rendering - * results into Targa-format files. Used by the {@link - * com.jogamp.opengl.util.gl2.Screenshot Screenshot} class; can also be used - * in conjunction with the {@link com.jogamp.opengl.util.gl2.TileRenderer - * TileRenderer} class.

+ * results into Targa-format files. Used by the {@link com.jogamp.opengl.util.awt.Screenshot} + * class; can also be used in conjunction with the {@link com.jogamp.opengl.util.gl2.TileRenderer} class. */ - public class TGAWriter { + private static final int TARGA_HEADER_SIZE = 18; private FileChannel ch; diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java index 49a341cc6..430ed08ce 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java @@ -5,7 +5,6 @@ import javax.media.opengl.*; import java.util.HashMap; import java.util.Iterator; -import java.nio.*; import java.io.PrintStream; public class ShaderProgram { @@ -104,16 +103,20 @@ public class ShaderProgram { * Refetches all previously bin/get attribute names * and resets all attribute data as well * - * @see getAttribLocation * @param gl * @param oldShaderID the to be replace Shader * @param newShader the new ShaderCode * @param verboseOut the optional verbose outputstream * @throws GLException is the program is not linked * - * @see #glRefetchAttribLocations - * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderState#glEnableVertexAttribArray + * @see ShaderState#glDisableVertexAttribArray + * @see ShaderState#glVertexAttribPointer + * @see ShaderState#getVertexAttribPointer + * @see ShaderState#glReleaseAllVertexAttributes + * @see ShaderState#glResetAllVertexAttributes + * @see ShaderState#glResetAllVertexAttributes + * @see ShaderState#glResetAllVertexAttributes */ public synchronized boolean glReplaceShader(GL2ES2 gl, int oldShaderID, ShaderCode newShader, PrintStream verboseOut) { if(!programLinked) throw new GLException("Program is not linked"); diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java index 33f6e210b..86f9251b7 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java @@ -2,14 +2,11 @@ package com.jogamp.opengl.util.glsl; import javax.media.opengl.*; -import com.jogamp.opengl.util.*; import com.jogamp.opengl.impl.Debug; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.nio.*; -import java.io.PrintStream; import java.security.*; public class ShaderState { @@ -25,8 +22,8 @@ public class ShaderState { /** * Fetches the current shader state from the thread local storage (TLS) * - * @see javax.media.opengl.glsl.ShaderState#glUseProgram(GL2ES2, boolean) - * @see javax.media.opengl.glsl.ShaderState#getCurrent() + * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean) + * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent() */ public static synchronized ShaderState getCurrent() { GLContext current = GLContext.getCurrent(); @@ -41,8 +38,8 @@ public class ShaderState { * Puts this ShaderState to to the thread local storage (TLS), * if on is true. * - * @see javax.media.opengl.glsl.ShaderState#glUseProgram(GL2ES2, boolean) - * @see javax.media.opengl.glsl.ShaderState#getCurrent() + * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean) + * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent() */ public synchronized void glUseProgram(GL2ES2 gl, boolean on) { if(on) { @@ -178,7 +175,7 @@ public class ShaderState { * @see #glGetAttribLocation * @see javax.media.opengl.GL2ES2#glGetAttribLocation * @see #getAttribLocation - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public void glBindAttribLocation(GL2ES2 gl, int index, String name) { if(null==shaderProgram) throw new GLException("No program is attached"); @@ -203,7 +200,7 @@ public class ShaderState { * @see #glGetAttribLocation * @see javax.media.opengl.GL2ES2#glGetAttribLocation * @see #getAttribLocation - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public int glGetAttribLocation(GL2ES2 gl, String name) { if(!shaderProgram.linked()) throw new GLException("Program is not linked"); @@ -240,17 +237,17 @@ public class ShaderState { * Even if the attribute is not found in the current shader, * it is stored in this state. * - * @returns false, if the name is not found, otherwise true + * @return false, if the name is not found, otherwise true * * @throws GLException if the program is not in use * * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer - * @see #getVertexAttributePointer + * @see #getVertexAttribPointer * @see #glReleaseAllVertexAttributes * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public boolean glEnableVertexAttribArray(GL2ES2 gl, String name) { if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); @@ -281,17 +278,17 @@ public class ShaderState { * Even if the attribute is not found in the current shader, * it is removed from this state. * - * @returns false, if the name is not found, otherwise true + * @return false, if the name is not found, otherwise true * * @throws GLException if the program is not in use * * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer - * @see #getVertexAttributePointer + * @see #getVertexAttribPointer * @see #glReleaseAllVertexAttributes * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public boolean glDisableVertexAttribArray(GL2ES2 gl, String name) { if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); @@ -322,17 +319,17 @@ public class ShaderState { * it's index will be set with the attribute's location, * if found. * - * @returns false, if the name is not found, otherwise true + * @return false, if the name is not found, otherwise true * * @throws GLException if the program is not in use * * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer - * @see #getVertexAttributePointer + * @see #getVertexAttribPointer * @see #glReleaseAllVertexAttributes * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public boolean glVertexAttribPointer(GL2ES2 gl, GLArrayData data) { if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); @@ -367,15 +364,15 @@ public class ShaderState { /** * Get the vertex attribute data, previously set. * - * @returns the GLArrayData object, null if not previously set. + * @return the GLArrayData object, null if not previously set. * * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer - * @see #getVertexAttributePointer + * @see #getVertexAttribPointer * @see #glReleaseAllVertexAttributes * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public GLArrayData getVertexAttribPointer(String name) { return (GLArrayData) vertexAttribMap2Data.get(name); @@ -390,11 +387,11 @@ public class ShaderState { * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer - * @see #getVertexAttributePointer + * @see #getVertexAttribPointer * @see #glReleaseAllVertexAttributes * @see #glResetAllVertexAttributes * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public void glReleaseAllVertexAttributes(GL2ES2 gl) { if(null!=shaderProgram) { @@ -428,11 +425,11 @@ public class ShaderState { * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer - * @see #getVertexAttributePointer + * @see #getVertexAttribPointer * @see #glReleaseAllVertexAttributes * @see #glResetAllVertexAttributes * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public void glDisableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState) { if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); @@ -458,10 +455,10 @@ public class ShaderState { * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer - * @see #getVertexAttributePointer + * @see #getVertexAttribPointer * @see #glReleaseAllVertexAttributes * @see #glResetAllVertexAttributes - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public void glResetAllVertexAttributes(GL2ES2 gl) { if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); @@ -520,7 +517,7 @@ public class ShaderState { * @see #glGetUniformLocation * @see javax.media.opengl.GL2ES2#glGetUniformLocation * @see #getUniformLocation - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ protected int glGetUniformLocation(GL2ES2 gl, String name) { if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); @@ -554,14 +551,14 @@ public class ShaderState { * if found. * * - * @returns false, if the name is not found, otherwise true + * @return false, if the name is not found, otherwise true * * @throws GLException if the program is not in use * * @see #glGetUniformLocation * @see javax.media.opengl.GL2ES2#glGetUniformLocation * @see #getUniformLocation - * @see #glReplaceShader + * @see ShaderProgram#glReplaceShader */ public boolean glUniform(GL2ES2 gl, GLUniformData data) { if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); @@ -581,7 +578,7 @@ public class ShaderState { /** * Get the uniform data, previously set. * - * @returns the GLUniformData object, null if not previously set. + * @return the GLUniformData object, null if not previously set. */ public GLUniformData getUniform(String name) { return (GLUniformData) uniformMap2Data.get(name); diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java index a7042c47a..f00357bfb 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java @@ -66,25 +66,25 @@ public class FixedFuncUtil { /** * String name for - * @see javax.media.opengl.GL#GL_VERTEX_ARRAY + * @see javax.media.opengl.GL2#GL_VERTEX_ARRAY */ public static final String mgl_Vertex = FixedFuncPipeline.mgl_Vertex; /** * String name for - * @see javax.media.opengl.GL#GL_NORMAL_ARRAY + * @see javax.media.opengl.GL2#GL_NORMAL_ARRAY */ public static final String mgl_Normal = FixedFuncPipeline.mgl_Normal; /** * String name for - * @see javax.media.opengl.GL#GL_COLOR_ARRAY + * @see javax.media.opengl.GL2#GL_COLOR_ARRAY */ public static final String mgl_Color = FixedFuncPipeline.mgl_Color; /** * String name for - * @see javax.media.opengl.GL#GL_TEXTURE_COORD_ARRAY + * @see javax.media.opengl.GL2#GL_TEXTURE_COORD_ARRAY */ public static final String mgl_MultiTexCoord = FixedFuncPipeline.mgl_MultiTexCoord; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java index 9741da737..a0eed50ea 100755 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java @@ -7,16 +7,17 @@ import com.jogamp.opengl.util.glsl.*; import java.io.*; import java.net.*; -/** Precompiles a shader into a vendor binary format. Input is the - resource name of the shader, such as - "com/jogamp/opengl/impl/glsl/fixed/shader/a.fp". - Output is "com/jogamp/opengl/impl/glsl/fixed/shader/bin/nvidia/a.bfp". - - All path and suffixes are determined by the ShaderCode class, - which ensures runtime compatibility. - - @see javax.media.opengl.glsl.ShaderCode - */ +/** + * Precompiles a shader into a vendor binary format. Input is the + * resource name of the shader, such as + * "com/jogamp/opengl/impl/glsl/fixed/shader/a.fp". + * Output is "com/jogamp/opengl/impl/glsl/fixed/shader/bin/nvidia/a.bfp". + * + * All path and suffixes are determined by the ShaderCode class, + * which ensures runtime compatibility. + * + * @see com.jogamp.opengl.util.glsl.ShaderCode + */ public abstract class CompileShader { diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java index d17ee6a06..088c71bd8 100644 --- a/src/jogl/classes/javax/media/opengl/GLArrayData.java +++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java @@ -21,10 +21,10 @@ public interface GLArrayData { * The index of the predefined array index, see list below, * or -1 in case of a shader attribute array. * - * @see javax.media.opengl.GL#GL_VERTEX_ARRAY - * @see javax.media.opengl.GL#GL_NORMAL_ARRAY - * @see javax.media.opengl.GL#GL_COLOR_ARRAY - * @see javax.media.opengl.GL#GL_TEXTURE_COORD_ARRAY + * @see javax.media.opengl.GL2#GL_VERTEX_ARRAY + * @see javax.media.opengl.GL2#GL_NORMAL_ARRAY + * @see javax.media.opengl.GL2#GL_COLOR_ARRAY + * @see javax.media.opengl.GL2#GL_TEXTURE_COORD_ARRAY */ public int getIndex(); @@ -49,7 +49,7 @@ public interface GLArrayData { * Sets the determined location of the shader attribute * This is usually done within ShaderState. * - * @see javax.media.opengl.glsl.ShaderState#glVertexAttribPointer(GL2ES2, GLArrayData) + * @see com.jogamp.opengl.util.glsl.ShaderState#glVertexAttribPointer(GL2ES2, GLArrayData) */ public void setLocation(int v); diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java index be5a6dc4f..369907c22 100644 --- a/src/jogl/classes/javax/media/opengl/GLBase.java +++ b/src/jogl/classes/javax/media/opengl/GLBase.java @@ -220,7 +220,7 @@ public interface GLBase { * * @param glFunctionName the name of the OpenGL function (e.g., use * "glBindRenderbufferEXT" or "glBindRenderbuffer" to check if {@link - * #glBindRenderbuffer(int,int)} is available). + * GL#glBindRenderbuffer(int,int)} is available). */ public boolean isFunctionAvailable(String glFunctionName); diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 3ca1cd317..1e52c2a65 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -137,14 +137,14 @@ public abstract class GLContext { * copied. mask contains the bitwise OR of the same * symbolic names that are passed to the GL command {@link * GL#glPushAttrib glPushAttrib}. The single symbolic constant - * {@link GL#GL_ALL_ATTRIB_BITS GL_ALL_ATTRIB_BITS} can be used to + * {@link GL2#GL_ALL_ATTRIB_BITS GL_ALL_ATTRIB_BITS} can be used to * copy the maximum possible portion of rendering state.

* * Not all values for GL state can be copied. For example, pixel * pack and unpack state, render mode state, and select and feedback * state are not copied. The state that can be copied is exactly the * state that is manipulated by the GL command {@link - * GL#glPushAttrib glPushAttrib}.

+ * GL2#glPushAttrib glPushAttrib}.

* * On most platforms, this context may not be current to any thread, * including the calling thread, when this method is called. Some @@ -165,7 +165,7 @@ public abstract class GLContext { * If no context is current, throw an GLException * * @return the current context's GL object on this thread - * @thows GLException if no context is current + * @throws GLException if no context is current */ public static GL getCurrentGL() throws GLException { GLContext glc = getCurrent(); diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index 58a0fabbc..d61ceb1f4 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -186,10 +186,10 @@ public abstract class GLDrawableFactory { * The native platform's chosen Capabilties are referenced within the target * NativeWindow's AbstractGraphicsConfiguration.

* - * In case {@link javax.media.nativewindow.Capabilties#isOnscreen()} is true,
+ * In case {@link javax.media.nativewindow.Capabilities#isOnscreen()} is true,
* an onscreen GLDrawable will be realized. *

- * In case {@link javax.media.nativewindow.Capabilties#isOnscreen()} is false,
+ * In case {@link javax.media.nativewindow.Capabilities#isOnscreen()} is false,
* either a Pbuffer drawable is created if {@link javax.media.opengl.GLCapabilities#isPBuffer()} is true,
* or a simple offscreen drawable is creates. The latter is unlikely to be hardware accelerated.
*

diff --git a/src/jogl/classes/javax/media/opengl/GLUniformData.java b/src/jogl/classes/javax/media/opengl/GLUniformData.java index f628ce35a..9b0d5f151 100644 --- a/src/jogl/classes/javax/media/opengl/GLUniformData.java +++ b/src/jogl/classes/javax/media/opengl/GLUniformData.java @@ -10,7 +10,6 @@ public class GLUniformData { * * Number of objects is 1 * - * @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4, */ public GLUniformData(String name, int val) { init(name, 1, new Integer(val)); @@ -21,7 +20,6 @@ public class GLUniformData { * * Number of objects is 1 * - * @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4, */ public GLUniformData(String name, float val) { init(name, 1, new Float(val)); diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java index 61757abde..b899f3c0a 100644 --- a/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java @@ -6,8 +6,6 @@ package javax.media.opengl.fixedfunc; import java.nio.*; -import javax.media.opengl.*; - public interface GLMatrixFunc { public static final int GL_MATRIX_MODE = 0x0BA0; @@ -56,7 +54,7 @@ public interface GLMatrixFunc { /** * glMultMatrixf - * @param params the FloatBuffer's position remains unchanged, + * @param m the FloatBuffer's position remains unchanged, * which is the same behavior than the native JOGL GL impl */ public void glMultMatrixf(java.nio.FloatBuffer m) ; diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 800e38105..29a392f04 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -58,8 +58,9 @@ public class GLWindow extends Window implements GLAutoDrawable { private Window window; private boolean runPumpMessages; - /** Constructor. Do not call this directly -- use {@link - create()} instead. */ + /** + * Constructor. Do not call this directly -- use {@link #create()} instead. + */ protected GLWindow(Window window, boolean ownerOfWinScrDpy) { this.ownerOfWinScrDpy = ownerOfWinScrDpy; this.window = window; -- cgit v1.2.3 From bb028021be2714e66d9b1062298a3e308c649c56 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 16 Apr 2010 03:51:00 +0200 Subject: JOGL GL4 preperation: - Re-Enable GL3bc native library build, works .. - Adding all the is/get GL4/GL4bc stubs .. - Adding dummy interface GL4 and GL4bc, will be removed when done - Context creation refactoring: - Move Version information to GLContext - Determine version by creation if possible (ARB_create_context), only use the unreliable GL_VERSION string if necessary. - Offering an almost platform independent ARB_create_context path: - createContextARBImpl - platform dependent GLX calls - createContextARB - platform independent setup and version loop --- make/build-jogl.xml | 3 +- make/config/jogl/gl-common.cfg | 8 +- make/config/jogl/gl-gl3bc.cfg | 1 + make/config/jogl/gl-impl-CustomJavaCode-gl2.java | 16 + .../jogl/gl-impl-CustomJavaCode-gl2es12.java | 16 + make/config/jogl/gl-impl-CustomJavaCode-gl3.java | 16 + make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java | 16 + make/config/jogl/gl-impl-CustomJavaCode-gles1.java | 16 + make/config/jogl/gl-impl-CustomJavaCode-gles2.java | 16 + make/config/jogl/gl3ext-headers.cfg | 5 + .../opengl/impl/ExtensionAvailabilityCache.java | 221 ++------------ .../com/jogamp/opengl/impl/GLContextImpl.java | 323 ++++++++++++++++++++- .../com/jogamp/opengl/impl/egl/EGLContext.java | 12 +- .../jogamp/opengl/impl/egl/EGLExternalContext.java | 2 +- .../opengl/impl/macosx/cgl/MacOSXCGLContext.java | 12 +- .../impl/macosx/cgl/MacOSXExternalCGLContext.java | 2 +- .../impl/macosx/cgl/MacOSXPbufferCGLContext.java | 4 +- .../macosx/cgl/awt/MacOSXJava2DCGLContext.java | 2 +- .../windows/wgl/WindowsExternalWGLContext.java | 2 +- .../opengl/impl/windows/wgl/WindowsWGLContext.java | 16 +- .../opengl/impl/x11/glx/X11ExternalGLXContext.java | 2 +- .../jogamp/opengl/impl/x11/glx/X11GLXContext.java | 302 ++++++++++--------- src/jogl/classes/javax/media/opengl/GL4.java | 5 + src/jogl/classes/javax/media/opengl/GL4bc.java | 5 + src/jogl/classes/javax/media/opengl/GLBase.java | 28 ++ src/jogl/classes/javax/media/opengl/GLContext.java | 68 ++++- src/jogl/classes/javax/media/opengl/GLProfile.java | 120 ++++++-- 27 files changed, 826 insertions(+), 413 deletions(-) create mode 100755 make/config/jogl/gl3ext-headers.cfg create mode 100644 src/jogl/classes/javax/media/opengl/GL4.java create mode 100644 src/jogl/classes/javax/media/opengl/GL4bc.java (limited to 'src/jogl/classes/javax/media/opengl/GLContext.java') diff --git a/make/build-jogl.xml b/make/build-jogl.xml index 93cf7bf6f..d42b859bd 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -946,7 +946,7 @@ + diff --git a/make/config/jogl/gl-common.cfg b/make/config/jogl/gl-common.cfg index 0f6529167..8d726c4bf 100644 --- a/make/config/jogl/gl-common.cfg +++ b/make/config/jogl/gl-common.cfg @@ -388,8 +388,12 @@ ArgumentIsString glTransformFeedbackVaryings 2 # Use cached GL_EXTENSION if possible, # which also allows GL3 compatibility. # -JavaPrologue glGetString if(GL.GL_EXTENSIONS==name && _context.isExtensionCacheInitialized()) { -JavaPrologue glGetString return _context.getGLExtensions(); +JavaPrologue glGetString if(_context.isExtensionCacheInitialized()) { +JavaPrologue glGetString if(GL.GL_EXTENSIONS==name) { +JavaPrologue glGetString return _context.getGLExtensions(); +JavaPrologue glGetString } /* else if(GL.GL_VERSION==name) { +JavaPrologue glGetString return _context.getGLVersion(); +JavaPrologue glGetString } */ JavaPrologue glGetString } # diff --git a/make/config/jogl/gl-gl3bc.cfg b/make/config/jogl/gl-gl3bc.cfg index a637df941..7bba2f635 100644 --- a/make/config/jogl/gl-gl3bc.cfg +++ b/make/config/jogl/gl-gl3bc.cfg @@ -83,6 +83,7 @@ CustomJavaCode GL3bcImpl public void glDepthRangef(float zNear, float zFar) { CustomJavaCode GL3bcImpl glDepthRange((double)zNear, (double)zFar); } Include gl-headers.cfg +Include gl3ext-headers.cfg Include ../intptr.cfg IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-common.java diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl2.java b/make/config/jogl/gl-impl-CustomJavaCode-gl2.java index cd1a24459..0658b8a01 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl2.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl2.java @@ -28,6 +28,14 @@ public final boolean isGL() { return true; } +public final boolean isGL4bc() { + return false; +} + +public final boolean isGL4() { + return false; +} + public final boolean isGL3bc() { return false; } @@ -72,6 +80,14 @@ public final GL getGL() throws GLException { return this; } +public final GL4bc getGL4bc() throws GLException { + throw new GLException("Not a GL4bc implementation"); +} + +public final GL4 getGL4() throws GLException { + throw new GLException("Not a GL4 implementation"); +} + public final GL3bc getGL3bc() throws GLException { throw new GLException("Not a GL3bc implementation"); } diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java b/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java index 2eca2b6ab..54c7bd92b 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java @@ -30,6 +30,14 @@ public final boolean isGL() { return true; } +public final boolean isGL4bc() { + return false; +} + +public final boolean isGL4() { + return false; +} + public final boolean isGL3bc() { return false; } @@ -74,6 +82,14 @@ public final GL getGL() throws GLException { return this; } +public final GL4bc getGL4bc() throws GLException { + throw new GLException("Not a GL4bc implementation"); +} + +public final GL4 getGL4() throws GLException { + throw new GLException("Not a GL4 implementation"); +} + public final GL3bc getGL3bc() throws GLException { throw new GLException("Not a GL3bc implementation"); } diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl3.java b/make/config/jogl/gl-impl-CustomJavaCode-gl3.java index 16ff008cf..cff0b0f94 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl3.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl3.java @@ -27,6 +27,14 @@ public final boolean isGL() { return true; } +public final boolean isGL4bc() { + return false; +} + +public final boolean isGL4() { + return false; +} + public final boolean isGL3bc() { return false; } @@ -71,6 +79,14 @@ public final GL getGL() throws GLException { return this; } +public final GL4bc getGL4bc() throws GLException { + throw new GLException("Not a GL4bc implementation"); +} + +public final GL4 getGL4() throws GLException { + throw new GLException("Not a GL4 implementation"); +} + public final GL3bc getGL3bc() throws GLException { throw new GLException("Not a GL3bc implementation"); } diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java index 2b7f14918..2f804a218 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java @@ -28,6 +28,14 @@ public final boolean isGL() { return true; } +public final boolean isGL4bc() { + return false; +} + +public final boolean isGL4() { + return false; +} + public final boolean isGL3bc() { return true; } @@ -72,6 +80,14 @@ public final GL getGL() throws GLException { return this; } +public final GL4bc getGL4bc() throws GLException { + throw new GLException("Not a GL4bc implementation"); +} + +public final GL4 getGL4() throws GLException { + throw new GLException("Not a GL4 implementation"); +} + public final GL3bc getGL3bc() throws GLException { return this; } diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java index dfef10ec9..6fb8a32ef 100755 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java @@ -10,6 +10,14 @@ public final boolean isGL() { return true; } +public final boolean isGL4bc() { + return false; +} + +public final boolean isGL4() { + return false; +} + public final boolean isGL3bc() { return false; } @@ -54,6 +62,14 @@ public final GL getGL() throws GLException { return this; } +public final GL4bc getGL4bc() throws GLException { + throw new GLException("Not a GL4bc implementation"); +} + +public final GL4 getGL4() throws GLException { + throw new GLException("Not a GL4 implementation"); +} + public final GL3bc getGL3bc() throws GLException { throw new GLException("Not a GL3bc implementation"); } diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java index 7287408a0..8204bd1ae 100755 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java @@ -14,6 +14,14 @@ public final boolean isGL() { return true; } +public final boolean isGL4bc() { + return false; +} + +public final boolean isGL4() { + return false; +} + public final boolean isGL3bc() { return false; } @@ -58,6 +66,14 @@ public final GL getGL() throws GLException { return this; } +public final GL4bc getGL4bc() throws GLException { + throw new GLException("Not a GL4bc implementation"); +} + +public final GL4 getGL4() throws GLException { + throw new GLException("Not a GL4 implementation"); +} + public final GL3bc getGL3bc() throws GLException { throw new GLException("Not a GL3bc implementation"); } diff --git a/make/config/jogl/gl3ext-headers.cfg b/make/config/jogl/gl3ext-headers.cfg new file mode 100755 index 000000000..dfc4ea796 --- /dev/null +++ b/make/config/jogl/gl3ext-headers.cfg @@ -0,0 +1,5 @@ +CustomCCode /* Define GL_GL3EXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "gl3ext.h" are parsed. */ +CustomCCode #define GL_GL3EXT_PROTOTYPES +CustomCCode #include +CustomCCode #include diff --git a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java index f36c4f749..082f006e8 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java @@ -66,12 +66,10 @@ public final class ExtensionAvailabilityCache { public void flush() { if(DEBUG) { - System.out.println("ExtensionAvailabilityCache: Flush availability OpenGL "+majorVersion+"."+minorVersion); + System.out.println("ExtensionAvailabilityCache: Flush availability OpenGL "+context.getGLVersion()); } availableExtensionCache.clear(); initialized = false; - majorVersion = 1; - minorVersion = 0; } /** @@ -104,53 +102,23 @@ public final class ExtensionAvailabilityCache { return glExtensions; } - public int getMajorVersion() { - initAvailableExtensions(); - return majorVersion; - } - - public int getMinorVersion() { - initAvailableExtensions(); - return minorVersion; - } - private void initAvailableExtensions() { + GL gl = context.getGL(); // if hash is empty (meaning it was flushed), pre-cache it with the list // of extensions that are in the GL_EXTENSIONS string if (availableExtensionCache.isEmpty() || !initialized) { - GL gl = context.getGL(); - if (DEBUG) { - System.err.println("ExtensionAvailabilityCache: Pre-caching init "+gl+", GL_VERSION "+gl.glGetString(GL.GL_VERSION)); - } - - // Set version - Version version = new Version(gl.glGetString(GL.GL_VERSION)); - if (version.isValid()) { - majorVersion = version.getMajor(); - minorVersion = version.getMinor(); - - if( !gl.isGL3() && - ( majorVersion > 3 || - ( majorVersion == 3 && minorVersion >= 1 ) ) ) { - // downsize version to 3.0 in case we are not using GL3 (3.1) - majorVersion = 3; - minorVersion = 0; - } + System.err.println("ExtensionAvailabilityCache: Pre-caching init "+gl+", OpenGL "+context.getGLVersion()); } boolean useGetStringi = false; - if ( majorVersion > 3 || - ( majorVersion == 3 && minorVersion >= 0 ) || + if ( context.getGLVersionMajor() > 3 || + ( context.getGLVersionMajor() == 3 && context.getGLVersionMinor() >= 0 ) || gl.isGL3() ) { - if ( ! gl.isGL2GL3() ) { + if ( ! gl.isFunctionAvailable("glGetStringi") ) { if(DEBUG) { - System.err.println("ExtensionAvailabilityCache: GL >= 3.1 usage, but no GL2GL3 interface: "+gl.getClass().getName()); - } - } else if ( ! gl.isFunctionAvailable("glGetStringi") ) { - if(DEBUG) { - System.err.println("ExtensionAvailabilityCache: GL >= 3.1 usage, but no glGetStringi"); + System.err.println("GLContext: GL >= 3.1 usage, but no glGetStringi"); } } else { useGetStringi = true; @@ -158,7 +126,7 @@ public final class ExtensionAvailabilityCache { } if (DEBUG) { - System.err.println("ExtensionAvailabilityCache: Pre-caching extension availability OpenGL "+majorVersion+"."+minorVersion+ + System.err.println("ExtensionAvailabilityCache: Pre-caching extension availability OpenGL "+context.getGLVersion()+ ", use "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) ); } @@ -197,39 +165,21 @@ public final class ExtensionAvailabilityCache { } } - // Put GL version strings in the table as well - // FIXME: this needs to be adjusted when the major rev changes - // beyond the known ones - int major = majorVersion; - int minor = minorVersion; - while (major > 0) { - while (minor >= 0) { - availableExtensionCache.add("GL_VERSION_" + major + "_" + minor); - if (DEBUG) { - System.err.println("ExtensionAvailabilityCache: Added GL_VERSION_" + major + "_" + minor + " to known extensions"); - } - --minor; - } - - switch (major) { - case 3: - if(gl.isGL3()) { - // GL3 is a GL 3.1 forward compatible context, - // hence no 2.0, 1.0 - 1.5 GL versions are supported. - major=0; - } - // Restart loop at version 2.1 - minor = 1; - break; - case 2: - // Restart loop at version 1.5 - minor = 5; - break; - case 1: - break; + int major[] = new int[] { context.getGLVersionMajor() }; + int minor[] = new int[] { context.getGLVersionMinor() }; + if( !gl.isGL3() && !gl.isGL4() && + ( major[0] > 3 || + ( major[0] == 3 && minor[0] >= 1 ) ) ) { + // downsize version to 3.0 in case we are not using GL3 (>=3.1) + major[0] = 3; + minor[0] = 0; + } + while (GLProfile.isValidGLVersion(major[0], minor[0])) { + availableExtensionCache.add("GL_VERSION_" + major[0] + "_" + minor[0]); + if (DEBUG) { + System.err.println("ExtensionAvailabilityCache: Added GL_VERSION_" + major[0] + "_" + minor[0] + " to known extensions"); } - - --major; + if(!GLProfile.decrementGLVersion(major, minor)) break; } // put a dummy var in here so that the cache is no longer empty even if @@ -255,136 +205,9 @@ public final class ExtensionAvailabilityCache { // private boolean initialized = false; - private int majorVersion = 1; - private int minorVersion = 0; private String glExtensions = null; private String glXExtensions = null; private HashSet availableExtensionCache = new HashSet(50); private GLContextImpl context; - /** - * A class for storing and comparing OpenGL version numbers. - * This only works for desktop OpenGL at the moment. - */ - private static class Version implements Comparable - { - private boolean valid; - private int major, minor, sub; - public Version(int majorRev, int minorRev, int subMinorRev) - { - major = majorRev; - minor = minorRev; - sub = subMinorRev; - } - - /** - * @param versionString must be of the form "GL_VERSION_X" or - * "GL_VERSION_X_Y" or "GL_VERSION_X_Y_Z" or "X.Y", where X, Y, - * and Z are integers. - * - * @exception IllegalArgumentException if the argument is not a valid - * OpenGL version identifier - */ - public Version(String versionString) - { - try - { - if (versionString.startsWith("GL_VERSION_")) - { - StringTokenizer tok = new StringTokenizer(versionString, "_"); - - tok.nextToken(); // GL_ - tok.nextToken(); // VERSION_ - if (!tok.hasMoreTokens()) { major = 0; return; } - major = Integer.valueOf(tok.nextToken()).intValue(); - if (!tok.hasMoreTokens()) { minor = 0; return; } - minor = Integer.valueOf(tok.nextToken()).intValue(); - if (!tok.hasMoreTokens()) { sub = 0; return; } - sub = Integer.valueOf(tok.nextToken()).intValue(); - } - else - { - int radix = 10; - if (versionString.length() > 2) { - if (Character.isDigit(versionString.charAt(0)) && - versionString.charAt(1) == '.' && - Character.isDigit(versionString.charAt(2))) { - major = Character.digit(versionString.charAt(0), radix); - minor = Character.digit(versionString.charAt(2), radix); - - // See if there's version-specific information which might - // imply a more recent OpenGL version - StringTokenizer tok = new StringTokenizer(versionString, " "); - if (tok.hasMoreTokens()) { - tok.nextToken(); - if (tok.hasMoreTokens()) { - String token = tok.nextToken(); - int i = 0; - while (i < token.length() && !Character.isDigit(token.charAt(i))) { - i++; - } - if (i < token.length() - 2 && - Character.isDigit(token.charAt(i)) && - token.charAt(i+1) == '.' && - Character.isDigit(token.charAt(i+2))) { - int altMajor = Character.digit(token.charAt(i), radix); - int altMinor = Character.digit(token.charAt(i+2), radix); - // Avoid possibly confusing situations by putting some - // constraints on the upgrades we do to the major and - // minor versions - if ((altMajor == major && altMinor > minor) || - altMajor == major + 1) { - major = altMajor; - minor = altMinor; - } - } - } - } - } - } - } - valid = true; - } - catch (Exception e) - { - // FIXME: refactor desktop OpenGL dependencies and make this - // class work properly for OpenGL ES - System.err.println("ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.: "+e); - major = 1; - minor = 0; - /* - throw (IllegalArgumentException) - new IllegalArgumentException( - "Illegally formatted version identifier: \"" + versionString + "\"") - .initCause(e); - */ - } - } - - public boolean isValid() { - return valid; - } - - public int compareTo(Object o) - { - Version vo = (Version)o; - if (major > vo.major) return 1; - else if (major < vo.major) return -1; - else if (minor > vo.minor) return 1; - else if (minor < vo.minor) return -1; - else if (sub > vo.sub) return 1; - else if (sub < vo.sub) return -1; - - return 0; // they are equal - } - - public int getMajor() { - return major; - } - - public int getMinor() { - return minor; - } - - } // end class Version } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java index 7543a1084..8c5890d1e 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java @@ -44,6 +44,7 @@ import java.nio.*; import java.util.*; import javax.media.opengl.*; +import javax.media.nativewindow.*; import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.gluegen.runtime.*; import com.jogamp.gluegen.runtime.opengl.*; @@ -122,6 +123,108 @@ public abstract class GLContextImpl extends GLContext { return (GLDrawableImpl) getGLDrawable(); } + /** + * Platform dependent but harmonized implementation of the ARB_create_context + * mechanism to create a context.
+ * The implementation shall verify this context, ie issue a + * MakeCurrent call if necessary.
+ * + * @param share the shared context or null + * @param direct flag if direct is requested + * @param ctxOptionFlags ARB_create_context related, see references below + * @param major major number + * @param minor minor number + * @return the valid context if successfull, or null + * + * @see #CTX_PROFILE_COMPAT + * @see #CTX_OPTION_FORWARD + * @see #CTX_OPTION_DEBUG + */ + protected abstract long createContextARBImpl(long share, boolean direct, int ctxOptionFlags, + int major, int minor); + + private long createContextARB(long share, boolean direct, int ctxOptionFlags, + int majorMax, int minorMax, + int majorMin, int minorMin, + int major[], int minor[]) { + major[0]=majorMax; + minor[0]=minorMax; + long _context=0; + + while ( 0==_context && + GLProfile.isValidGLVersion(major[0], minor[0]) && + ( major[0]>majorMin || major[0]==majorMin && minor[0] >=minorMin ) ) { + + _context = createContextARBImpl(share, direct, ctxOptionFlags, major[0], minor[0]); + + if(0==_context) { + if(!GLProfile.decrementGLVersion(major, minor)) break; + } + } + return _context; + } + + /** + * Platform independent part of using the ARB_create_context + * mechanism to create a context.
+ */ + protected long createContextARB(long share, boolean direct, + int major[], int minor[], int ctp[]) + { + AbstractGraphicsConfiguration config = drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); + GLProfile glp = glCaps.getGLProfile(); + long _context = 0; + + ctp[0] = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE | CTX_OPTION_ANY; // default + boolean isBackwardCompatibility = glp.isGL2() || glp.isGL3bc() || glp.isGL4bc() ; + int majorMin, minorMin; + int majorMax, minorMax; + if( glp.isGL4() ) { + // ?? majorMax=GLProfile.getMaxMajor(); minorMax=GLProfile.getMaxMinor(majorMax); + majorMax=4; minorMax=GLProfile.getMaxMinor(majorMax); + majorMin=4; minorMin=0; + } else if( glp.isGL3() ) { + majorMax=3; minorMax=GLProfile.getMaxMinor(majorMax); + majorMin=3; minorMin=1; + } else /* if( glp.isGL2() ) */ { + majorMax=3; minorMax=0; + majorMin=1; minorMin=1; // our minimum desktop OpenGL runtime requirements + } + // Try the requested .. + if(isBackwardCompatibility) { + ctp[0] &= ~CTX_PROFILE_CORE ; + ctp[0] |= CTX_PROFILE_COMPAT ; + } + _context = createContextARB(share, direct, ctp[0], + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + + if(0==_context && !isBackwardCompatibility) { + ctp[0] &= ~CTX_PROFILE_COMPAT ; + ctp[0] |= CTX_PROFILE_CORE ; + ctp[0] &= ~CTX_OPTION_ANY ; + ctp[0] |= CTX_OPTION_FORWARD ; + _context = createContextARB(share, direct, ctp[0], + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + if(0==_context) { + // Try a compatible one .. even though not requested .. last resort + ctp[0] &= ~CTX_PROFILE_CORE ; + ctp[0] |= CTX_PROFILE_COMPAT ; + ctp[0] &= ~CTX_OPTION_FORWARD ; + ctp[0] |= CTX_OPTION_ANY ; + _context = createContextARB(share, direct, ctp[0], + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + } + } + return _context; + } + public int makeCurrent() throws GLException { // Support calls to makeCurrent() over and over again with // different contexts without releasing them @@ -272,7 +375,7 @@ public abstract class GLContextImpl extends GLContext { if(DEBUG) { String sgl1 = (null!=this.gl)?this.gl.getClass().toString()+", "+this.gl.toString():new String(""); String sgl2 = (null!=gl)?gl.getClass().toString()+", "+gl.toString():new String(""); - Exception e = new Exception("setGL: "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); + Exception e = new Exception("setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); e.printStackTrace(); } this.gl = gl; @@ -281,6 +384,77 @@ public abstract class GLContextImpl extends GLContext { public abstract Object getPlatformGLExtensions(); + //---------------------------------------------------------------------- + // Managing the actual OpenGL version, usually figured at creation time. + // As a last resort, the GL_VERSION string may be used .. + // + + /** + * If major > 0 || minor > 0 : Use passed values, determined at creation time + * If major==0 && minor == 0 : Use GL_VERSION + * Otherwise .. don't touch .. + */ + protected void setContextVersion(int major, int minor, int ctp) { + if(major>0 || minor>0) { + ctxMajorVersion = major; + ctxMinorVersion = minor; + ctxOptions = ctp; + ctxVersionString = getGLVersion(gl, ctxMajorVersion, ctxMinorVersion, ctxOptions, getGL().glGetString(GL.GL_VERSION)); + return; + } + + if(major==0 && minor==0) { + String versionStr = getGL().glGetString(GL.GL_VERSION); + if(null==versionStr) { + throw new GLException("GL_VERSION is NULL: "+this); + } + + // Set version + Version version = new Version(versionStr); + if (version.isValid()) { + ctxMajorVersion = version.getMajor(); + ctxMinorVersion = version.getMinor(); + + ctxVersionString = getGLVersion(gl, ctxMajorVersion, ctxMinorVersion, ctxOptions, versionStr); + return; + } + } + } + + private static boolean appendString(StringBuffer sb, String string, boolean needColon, boolean condition) { + if(condition) { + if(needColon) { + sb.append(", "); + } + sb.append(string); + needColon=true; + } + return needColon; + } + + protected static String getGLVersion(GL gl, int major, int minor, int ctp, String gl_version) { + boolean needColon = false; + StringBuffer sb = new StringBuffer(); + sb.append(major); + sb.append("."); + sb.append(minor); + sb.append(" ("); + needColon = appendString(sb, "ES", needColon, null!=gl && gl.isGLES()); + needColon = appendString(sb, "compatibility profile", needColon, 0 != ( CTX_PROFILE_COMPAT & ctp )); + needColon = appendString(sb, "core profile", needColon, 0 != ( CTX_PROFILE_CORE & ctp )); + needColon = appendString(sb, "forward compatible", needColon, 0 != ( CTX_OPTION_FORWARD & ctp )); + needColon = appendString(sb, "any", needColon, 0 != ( CTX_OPTION_ANY & ctp )); + needColon = appendString(sb, "new", needColon, 0 != ( CTX_IS_ARB_CREATED & ctp )); + needColon = appendString(sb, "old", needColon, 0 == ( CTX_IS_ARB_CREATED & ctp )); + sb.append(") - "); + if(null!=gl_version) { + sb.append(gl_version); + } else { + sb.append("n/a"); + } + return sb.toString(); + } + //---------------------------------------------------------------------- // Helpers for various context implementations // @@ -391,8 +565,10 @@ public abstract class GLContextImpl extends GLContext { * * @param force force the setting, even if is already being set. * This might be usefull if you change the OpenGL implementation. + * + * @see #setContextVersion */ - protected void setGLFunctionAvailability(boolean force) { + protected void setGLFunctionAvailability(boolean force, int major, int minor, int ctp) { if(null!=this.gl && null!=glProcAddressTable && !force) { return; // already done and not forced } @@ -400,15 +576,17 @@ public abstract class GLContextImpl extends GLContext { setGL(createGL(getGLDrawable().getGLProfile())); } - updateGLProcAddressTable(); + updateGLProcAddressTable(major, minor, ctp); } /** * Updates the cache of which GL functions are available for calling through this * context. See {@link #isFunctionAvailable(String)} for more information on * the definition of "available". + * + * @see #setContextVersion */ - protected void updateGLProcAddressTable() { + protected void updateGLProcAddressTable(int major, int minor, int ctp) { if(null==this.gl) { throw new GLException("setGLFunctionAvailability not called yet"); } @@ -422,6 +600,8 @@ public abstract class GLContextImpl extends GLContext { } resetProcAddressTable(getGLProcAddressTable()); + setContextVersion(major, minor, ctp); + extensionAvailability.reset(); } @@ -493,14 +673,6 @@ public abstract class GLContextImpl extends GLContext { return extensionAvailability.getGLExtensions(); } - public int getMajorVersion() { - return extensionAvailability.getMajorVersion(); - } - - public int getMinorVersion() { - return extensionAvailability.getMinorVersion(); - } - public boolean isExtensionCacheInitialized() { return extensionAvailability.isInitialized(); } @@ -617,4 +789,131 @@ public abstract class GLContextImpl extends GLContext { */ + /** + * A class for storing and comparing OpenGL version numbers. + * This only works for desktop OpenGL at the moment. + */ + private static class Version implements Comparable + { + private boolean valid; + private int major, minor, sub; + public Version(int majorRev, int minorRev, int subMinorRev) + { + major = majorRev; + minor = minorRev; + sub = subMinorRev; + } + + /** + * @param versionString must be of the form "GL_VERSION_X" or + * "GL_VERSION_X_Y" or "GL_VERSION_X_Y_Z" or "X.Y", where X, Y, + * and Z are integers. + * + * @exception IllegalArgumentException if the argument is not a valid + * OpenGL version identifier + */ + public Version(String versionString) + { + try + { + if (versionString.startsWith("GL_VERSION_")) + { + StringTokenizer tok = new StringTokenizer(versionString, "_"); + + tok.nextToken(); // GL_ + tok.nextToken(); // VERSION_ + if (!tok.hasMoreTokens()) { major = 0; return; } + major = Integer.valueOf(tok.nextToken()).intValue(); + if (!tok.hasMoreTokens()) { minor = 0; return; } + minor = Integer.valueOf(tok.nextToken()).intValue(); + if (!tok.hasMoreTokens()) { sub = 0; return; } + sub = Integer.valueOf(tok.nextToken()).intValue(); + } + else + { + int radix = 10; + if (versionString.length() > 2) { + if (Character.isDigit(versionString.charAt(0)) && + versionString.charAt(1) == '.' && + Character.isDigit(versionString.charAt(2))) { + major = Character.digit(versionString.charAt(0), radix); + minor = Character.digit(versionString.charAt(2), radix); + + // See if there's version-specific information which might + // imply a more recent OpenGL version + StringTokenizer tok = new StringTokenizer(versionString, " "); + if (tok.hasMoreTokens()) { + tok.nextToken(); + if (tok.hasMoreTokens()) { + String token = tok.nextToken(); + int i = 0; + while (i < token.length() && !Character.isDigit(token.charAt(i))) { + i++; + } + if (i < token.length() - 2 && + Character.isDigit(token.charAt(i)) && + token.charAt(i+1) == '.' && + Character.isDigit(token.charAt(i+2))) { + int altMajor = Character.digit(token.charAt(i), radix); + int altMinor = Character.digit(token.charAt(i+2), radix); + // Avoid possibly confusing situations by putting some + // constraints on the upgrades we do to the major and + // minor versions + if ((altMajor == major && altMinor > minor) || + altMajor == major + 1) { + major = altMajor; + minor = altMinor; + } + } + } + } + } + } + } + valid = true; + } + catch (Exception e) + { + e.printStackTrace(); + // FIXME: refactor desktop OpenGL dependencies and make this + // class work properly for OpenGL ES + System.err.println("ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.: "+e); + major = 1; + minor = 0; + /* + throw (IllegalArgumentException) + new IllegalArgumentException( + "Illegally formatted version identifier: \"" + versionString + "\"") + .initCause(e); + */ + } + } + + public boolean isValid() { + return valid; + } + + public int compareTo(Object o) + { + Version vo = (Version)o; + if (major > vo.major) return 1; + else if (major < vo.major) return -1; + else if (minor > vo.minor) return 1; + else if (minor < vo.minor) return -1; + else if (sub > vo.sub) return 1; + else if (sub < vo.sub) return -1; + + return 0; // they are equal + } + + public int getMajor() { + return major; + } + + public int getMinor() { + return minor; + } + + } // end class Version + } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java index a96736c00..31dbd46ae 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java @@ -113,7 +113,7 @@ public abstract class EGLContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, -1, -1, -1); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; @@ -150,6 +150,10 @@ public abstract class EGLContext extends GLContextImpl { } } + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + return 0; // FIXME + } + protected void create() throws GLException { long eglDisplay = ((EGLDrawable)drawable).getDisplay(); EGLGraphicsConfiguration config = ((EGLDrawable)drawable).getGraphicsConfiguration(); @@ -215,14 +219,14 @@ public abstract class EGLContext extends GLContextImpl { throw new GLException("Error making context 0x" + Long.toHexString(eglContext) + " current: error code " + EGL.eglGetError()); } - setGLFunctionAvailability(true); + setGLFunctionAvailability(true, contextAttrs[1], 0, CTX_IS_ARB_CREATED|CTX_PROFILE_CORE|CTX_OPTION_ANY); } public boolean isCreated() { return (eglContext != 0); } - protected void updateGLProcAddressTable() { + protected void updateGLProcAddressTable(int major, int minor, int ctp) { if (DEBUG) { System.err.println(getThreadName() + ": !!! Initializing EGL extension address table"); } @@ -235,7 +239,7 @@ public abstract class EGLContext extends GLContextImpl { eglExtProcAddressTable = new EGLExtProcAddressTable(); } resetProcAddressTable(getEGLExtProcAddressTable()); - super.updateGLProcAddressTable(); + super.updateGLProcAddressTable(major, minor, ctp); } public synchronized String getPlatformExtensionsString() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java index de7fd2ba4..0adede4ea 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java @@ -47,7 +47,7 @@ public class EGLExternalContext extends EGLContext { public EGLExternalContext(AbstractGraphicsScreen screen) { super(null, null); GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, 0, 0, 0); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java index d3a634792..364c2b91b 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java @@ -90,6 +90,10 @@ public abstract class MacOSXCGLContext extends GLContextImpl protected abstract boolean create(); + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + return 0; // FIXME + } + /** * Creates and initializes an appropriate OpenGl nsContext. Should only be * called by {@link makeCurrentImpl()}. @@ -150,7 +154,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl if (!CGL.makeCurrentContext(nsContext)) { throw new GLException("Error making nsContext current"); } - setGLFunctionAvailability(true); + setGLFunctionAvailability(true, 0, 0, 0); GLContextShareSet.contextCreated(this); return true; } @@ -184,7 +188,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl } if (created) { - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, -1, -1, -1); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; @@ -251,7 +255,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl } } - protected void updateGLProcAddressTable() { + protected void updateGLProcAddressTable(int major, int minor, int ctp) { if (DEBUG) { System.err.println("!!! Initializing CGL extension address table"); } @@ -261,7 +265,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl cglExtProcAddressTable = new CGLExtProcAddressTable(); } resetProcAddressTable(getCGLExtProcAddressTable()); - super.updateGLProcAddressTable(); + super.updateGLProcAddressTable(major, minor, ctp); } public String getPlatformExtensionsString() diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java index dde77cde6..248bbb4d6 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java @@ -56,7 +56,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { this.cglContext = cglContext; this.nsContext = nsContext; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, 0, 0, 0); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java index 446f457be..5844b8edd 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java @@ -73,7 +73,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { } if (created) { - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, -1, -1, -1); // Initialize render-to-texture support if requested DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); @@ -152,7 +152,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { if (!impl.makeCurrent(nsContext)) { throw new GLException("Error making nsContext current"); } - setGLFunctionAvailability(true); + setGLFunctionAvailability(true, 0, 0, 0); return true; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java index 9010d4461..9189b41f3 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java @@ -87,7 +87,7 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL } if (created) { - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, -1, -1, -1); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java index da8b70eb8..aae376a6c 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java @@ -56,7 +56,7 @@ public class WindowsExternalWGLContext extends WindowsWGLContext { System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(hglrc) + " for " + this); } GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, 0, 0, 0); cfg.updateCapabilitiesByWGL(this); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index b3f4c498c..5b6d65f62 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -122,6 +122,10 @@ public class WindowsWGLContext extends GLContextImpl { protected Map/**/ getExtensionNameMap() { return extensionNameMap; } + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + return 0; // FIXME + } + /** * Creates and initializes an appropriate OpenGL context. Should only be * called by {@link #makeCurrentImpl()}. @@ -157,7 +161,7 @@ public class WindowsWGLContext extends GLContextImpl { if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) { throw new GLException("Error making temp context current: 0x" + Integer.toHexString(WGL.GetLastError())); } - setGLFunctionAvailability(true); + setGLFunctionAvailability(true, 0, 0, 0); if( !isFunctionAvailable("wglCreateContextAttribsARB") || !isExtensionAvailable("WGL_ARB_create_context") ) { @@ -243,7 +247,7 @@ public class WindowsWGLContext extends GLContextImpl { if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { throw new GLException("Error making old context current: 0x" + Integer.toHexString(WGL.GetLastError())); } - updateGLProcAddressTable(); + updateGLProcAddressTable(0, 0, 0); if(DEBUG) { System.err.println("WindowsWGLContext.create done (old ctx < 3.0 - no 3.0) 0x"+Long.toHexString(hglrc)); } @@ -255,7 +259,7 @@ public class WindowsWGLContext extends GLContextImpl { if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { throw new GLException("Error making new context current: 0x" + Integer.toHexString(WGL.GetLastError())); } - updateGLProcAddressTable(); + updateGLProcAddressTable(0, 0, 0); if(DEBUG) { System.err.println("WindowsWGLContext.create done (new ctx >= 3.0) 0x"+Long.toHexString(hglrc)); } @@ -304,7 +308,7 @@ public class WindowsWGLContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, -1, -1, -1); WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); @@ -353,7 +357,7 @@ public class WindowsWGLContext extends GLContextImpl { } } - protected void updateGLProcAddressTable() { + protected void updateGLProcAddressTable(int major, int minor, int ctp) { if (DEBUG) { System.err.println(getThreadName() + ": !!! Initializing WGL extension address table for " + this); } @@ -369,7 +373,7 @@ public class WindowsWGLContext extends GLContextImpl { wglExtProcAddressTable = new WGLExtProcAddressTable(); } resetProcAddressTable(getWGLExtProcAddressTable()); - super.updateGLProcAddressTable(); + super.updateGLProcAddressTable(major, minor, ctp); } public String getPlatformExtensionsString() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java index 783e3278a..b8f25aad7 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java @@ -55,7 +55,7 @@ public class X11ExternalGLXContext extends X11GLXContext { super(drawable, null); this.context = context; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, 0, 0, 0); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index 142da672a..1492bfe42 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -110,6 +110,70 @@ public abstract class X11GLXContext extends GLContextImpl { */ protected abstract void create(); + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + long display = config.getScreen().getDevice().getHandle(); + GLXExt glXExt = getGLXExt(); + + boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; + boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; + boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ; + + long _context=0; + + String verstr = getGLVersion(null, major, minor, ctp, "@creation"); + + int attribs[] = { + /* 0 */ GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, major, + /* 2 */ GLX.GLX_CONTEXT_MINOR_VERSION_ARB, minor, + /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, + /* 6 */ GLX.GLX_CONTEXT_FLAGS_ARB, 0, + /* 8 */ 0, 0, + /* 10 */ 0 + }; + + if ( major > 3 || major == 3 && minor >= 2 ) { + // FIXME: Verify with a None drawable binding (default framebuffer) + attribs[8+0] = GLX.GLX_CONTEXT_PROFILE_MASK_ARB; + if( ctBwdCompat ) { + attribs[8+1] = GLX.GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + } else { + attribs[8+1] = GLX.GLX_CONTEXT_CORE_PROFILE_BIT_ARB; + } + } + + if ( major >= 3 ) { + if( !ctBwdCompat && ctFwdCompat ) { + attribs[6+1] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + } + if( ctDebug) { + attribs[6+1] |= GLX.GLX_CONTEXT_DEBUG_BIT_ARB; + } + } + + _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + if(0==_context) { + if(DEBUG) { + System.err.println("X11GLXContext.createContextARB couldn't create "+verstr+" _context"); + } + } else { + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + _context)) { + if(DEBUG) { + System.err.println("X11GLXContext.createContextARB couldn't make "+verstr+" context current"); + } + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, _context); + _context = 0; + } else if(DEBUG) { + System.err.println("X11GLXContext.createContextARB "+verstr+" available "+toHexString(_context)); + } + } + return _context; + } + /** * Creates and initializes an appropriate OpenGL context. Should only be * called by {@link create()}. @@ -133,176 +197,105 @@ public abstract class X11GLXContext extends GLContextImpl { } GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); + GLProfile glp = glCaps.getGLProfile(); isVendorATI = ((X11GLXDrawableFactory)(drawable.getFactoryImpl())).isVendorATI(); if(config.getFBConfigID()<0) { // not able to use FBConfig - if(glCaps.getGLProfile().isGL3()) { + if(glp.isGL3()) { throw new GLException("Unable to create OpenGL >= 3.1 context"); } context = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct); if (context == 0) { - throw new GLException("Unable to create OpenGL context"); + throw new GLException("Unable to create context(0)"); } if (!GLX.glXMakeContextCurrent(display, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), context)) { - throw new GLException("Error making temp context (old2) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } - setGLFunctionAvailability(true); + setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION if(DEBUG) { - System.err.println("X11GLXContext.createContext done (old2 ctx) "+toHexString(context)); + System.err.println("X11GLXContext.createContext(0) done "+toHexString(context)); + } + return; + } + + // To use GLX_ARB_create_context, we have to make a temp context current, + // so we are able to use GetProcAddress + long temp_context = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); + if (temp_context == 0) { + throw new GLException("Unable to create temp OpenGL context(1)"); + } + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + temp_context)) { + throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + } + setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION + + if( !isFunctionAvailable("glXCreateContextAttribsARB") || + !isExtensionAvailable("GLX_ARB_create_context") ) { + if(glp.isGL3()) { + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)"); } + // continue with temp context for GL < 3.0 + context = temp_context; + if(DEBUG) { + System.err.println("X11GLXContext.createContext(1) done (!GLX_ARB_create_context) "+toHexString(context)); + } + return; + } + + int minor[] = new int[1]; + int major[] = new int[1]; + int ctp[] = new int[1]; + context = createContextARB(share, direct, major, minor, ctp); + + if(0!=context) { + // need to update the GL func table .. + setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); + + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { + throw new GLException("Cannot make previous verified context current"); + } + if(DEBUG) { + System.err.println("X11GLXContext.createContext(2) done "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "+toHexString(context)); + } } else { + if(DEBUG) { + System.err.println("X11GLXContext.createContext(2) failed "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")); + } + if(!glp.isGL2()) { + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + throw new GLException("Unable to create context(2) (have GLX_ARB_create_context)"); + } - // To use GLX_ARB_create_context, we have to make a temp context current, - // so we are able to use GetProcAddress - long temp_context = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); - if (temp_context == 0) { - throw new GLException("Unable to create temp OpenGL context"); - } else { - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - temp_context)) { - throw new GLException("Error making temp context (old) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); - } - setGLFunctionAvailability(true); - - if( !isFunctionAvailable("glXCreateContextAttribsARB") || - !isExtensionAvailable("GLX_ARB_create_context") ) { - if(glCaps.getGLProfile().isGL3()) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)"); - } - - // continue with temp context for GL < 3.0 - context = temp_context; - if(DEBUG) { - System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no GLX_ARB_create_context) "+toHexString(context)); - } - } else { - GLXExt glXExt = getGLXExt(); - - // preset with default values - int attribs[] = { - /* 0 */ GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - /* 2 */ GLX.GLX_CONTEXT_MINOR_VERSION_ARB, 0, - /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, - /* 6 */ GLX.GLX_CONTEXT_FLAGS_ARB, 0 /* GLX.GLX_CONTEXT_DEBUG_BIT_ARB */, - /* 8 */ 0, 0, - /* 10 */ 0 - }; - - if(glCaps.getGLProfile().isGL3()) { - // Try >= 3.2 core first - // and verify with a None drawable binding (default framebuffer) - attribs[0+1] = 3; - attribs[2+1] = 2; - if(glCaps.getGLProfile().isGL3bc()) { - attribs[8+0] = GLX.GLX_CONTEXT_PROFILE_MASK_ARB; - attribs[8+1] = GLX.GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - } - /** - * don't stricten requirements any further, even compatible would be fine - * - else { - attribs[8+0] = GLX.GLX_CONTEXT_PROFILE_MASK_ARB; - attribs[8+1] = GLX.GLX_CONTEXT_CORE_PROFILE_BIT_ARB; - } - */ - - context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); - if(0!=context) { - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - if(DEBUG) { - System.err.println("X11GLXContext.createContext couldn't make >= 3.2 core context current - fallback"); - } - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, context); - context = 0; - } else if(DEBUG) { - System.err.println("X11GLXContext.createContext >= 3.2 available "+toHexString(context)); - } - } else { - if(DEBUG) { - System.err.println("X11GLXContext.createContext couldn't create >= 3.2 core context - fallback"); - } - } - if(0==context) { - // Try >= 3.1 forward compatible - last resort for GL3 ! - attribs[0+1] = 3; - attribs[2+1] = 1; - if(!glCaps.getGLProfile().isGL3bc()) { - attribs[6+1] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - } - attribs[8+0] = 0; - attribs[8+1] = 0; - } - } - if(0==context) { - // 3.1 or 3.0 .. - context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); - if(0!=context) { - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - if(DEBUG) { - System.err.println("X11GLXContext.createContext couldn't make >= 3.0 core context current - fallback"); - } - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, context); - context = 0; - } else if(DEBUG) { - System.err.println("X11GLXContext.createContext >= 3.0 available "+toHexString(context)); - } - } else { - if(DEBUG) { - System.err.println("X11GLXContext.createContext couldn't create >= 3.0 core context - fallback"); - } - } - } - - if(0==context) { - if(glCaps.getGLProfile().isGL3()) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create OpenGL >= 3.1 context (have GLX_ARB_create_context)"); - } - - // continue with temp context for GL < 3.0 - context = temp_context; - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); - throw new GLException("Error making context (old) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); - } - if(DEBUG) { - System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no 3.0) "+toHexString(context)); - } - } else { - GLX.glXDestroyContext(display, temp_context); - - // need to update the GL func table .. - updateGLProcAddressTable(); - if(DEBUG) { - System.err.println("X11GLXContext.createContext done (new ctx >= 3.0) "+toHexString(context)); - } - } - } - } - } - GLContextShareSet.contextCreated(this); + // continue with temp context for GL <= 3.0 + context = temp_context; + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + } + if(DEBUG) { + System.err.println("X11GLXContext.createContext(1) done "+toHexString(context)); + } + } } // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] @@ -350,6 +343,7 @@ public abstract class X11GLXContext extends GLContextImpl { boolean created = false; if (context == 0) { create(); + GLContextShareSet.contextCreated(this); if (DEBUG) { System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); } @@ -374,7 +368,7 @@ public abstract class X11GLXContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false); + setGLFunctionAvailability(false, -1, -1, -1); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; @@ -441,7 +435,7 @@ public abstract class X11GLXContext extends GLContextImpl { } } - protected void updateGLProcAddressTable() { + protected void updateGLProcAddressTable(int major, int minor, int ctp) { if (DEBUG) { System.err.println(getThreadName() + ": !!! Initializing GLX extension address table"); } @@ -454,7 +448,7 @@ public abstract class X11GLXContext extends GLContextImpl { glXExtProcAddressTable = new GLXExtProcAddressTable(); } resetProcAddressTable(getGLXExtProcAddressTable()); - super.updateGLProcAddressTable(); + super.updateGLProcAddressTable(major, minor, ctp); } public synchronized String getPlatformExtensionsString() { diff --git a/src/jogl/classes/javax/media/opengl/GL4.java b/src/jogl/classes/javax/media/opengl/GL4.java new file mode 100644 index 000000000..29a316333 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GL4.java @@ -0,0 +1,5 @@ +package javax.media.opengl; + +public interface GL4 extends GLBase { +} + diff --git a/src/jogl/classes/javax/media/opengl/GL4bc.java b/src/jogl/classes/javax/media/opengl/GL4bc.java new file mode 100644 index 000000000..be1131e91 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GL4bc.java @@ -0,0 +1,5 @@ +package javax.media.opengl; + +public interface GL4bc extends GL4 { +} + diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java index 369907c22..5ba410a61 100644 --- a/src/jogl/classes/javax/media/opengl/GLBase.java +++ b/src/jogl/classes/javax/media/opengl/GLBase.java @@ -63,6 +63,20 @@ public interface GLBase { */ public boolean isGL(); + /** + * Indicates whether this GL object conforms to the GL4 compatibility profile. + * The GL4 compatibility profile merges the GL2 profile and GL4 core profile. + * @return whether this GL object conforms to the GL4 compatibility profile + */ + public boolean isGL4bc(); + + /** + * Indicates whether this GL object conforms to the GL4 core profile. + * The GL4 core profile reflects OpenGL versions greater or equal 3.1 + * @return whether this GL object conforms to the GL4 core profile + */ + public boolean isGL4(); + /** * Indicates whether this GL object conforms to the GL3 compatibility profile. * The GL3 compatibility profile merges the GL2 profile and GL3 core profile. @@ -130,6 +144,20 @@ public interface GLBase { */ public GL getGL() throws GLException; + /** + * Casts this object to the GL4bc interface. + * @return this object cast to the GL4bc interface + * @throws GLException if this GLObject is not a GL4bc implementation + */ + public GL4bc getGL4bc() throws GLException; + + /** + * Casts this object to the GL4 interface. + * @return this object cast to the GL4 interface + * @throws GLException if this GLObject is not a GL4 implementation + */ + public GL4 getGL4() throws GLException; + /** * Casts this object to the GL3bc interface. * @return this object cast to the GL3bc interface diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 1e52c2a65..a8dbf9213 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -260,7 +260,9 @@ public abstract class GLContext { public final String toString() { StringBuffer sb = new StringBuffer(); sb.append(getClass().getName()); - sb.append(" ["); + sb.append(" [OpenGL "); + sb.append(getGLVersion()); + sb.append(", "); sb.append(getGL()); if(getGLDrawable()!=getGLDrawableRead()) { sb.append(",\n\tDrawable Read : "); @@ -280,4 +282,68 @@ public abstract class GLContext { GLX) extensions. Can only be called while this context is current. */ public abstract String getPlatformExtensionsString(); + + public final int getGLVersionMajor() { return ctxMajorVersion; } + public final int getGLVersionMinor() { return ctxMajorVersion; } + public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } + public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } + + /** + * Returns a valid OpenGL version string, ie + * major.minor ([option]?[options,]*) - gl-version + * + *

    + *
  • options + *
      + *
    • old refers to the non ARB_create_context created context + *
    • new refers to the ARB_create_context created context + *
    • compatible profile + *
    • core profile + *
    • forward compatible + *
    • any refers to the non forward compatible context + *
    • ES refers to the GLES context variant + *
    + *
  • gl-version the GL_VERSION string + *
+ * + * e.g.: + * + * + * + * + * + * + *
row 2, cell 1row 2, cell 2
+ * + * + * + * + * + * + * + * + * + *
ES2 2.0 (ES, any, new) - 2.0 ES Profile
ATIGL2 3.0 (compatibility profile, any, new) - 3.2.9704 Compatibility Profile Context
ATIGL3 3.3 (core profile, any, new) - 1.4 (3.2.9704 Compatibility Profile Context)
ATIGL3bc3.3 (compatibility profile, any, new) - 1.4 (3.2.9704 Compatibility Profile Context)
NVGL2 3.0 (compatibility profile, any, new) - 3.0.0 NVIDIA 195.36.07.03
NVGL3 3.3 (core profile, any, new) - 3.3.0 NVIDIA 195.36.07.03
NVGL3bc 3.3 (compatibility profile, any, new) - 3.3.0 NVIDIA 195.36.07.03
+ */ + public final String getGLVersion() { + return ctxVersionString; + } + + protected int ctxMajorVersion=-1; + protected int ctxMinorVersion=-1; + protected int ctxOptions=0; + protected String ctxVersionString=null; + + /** ARB_create_context related: created via ARB_create_context */ + protected static final int CTX_IS_ARB_CREATED = 1 << 0; + /** ARB_create_context related: compatibility profile */ + protected static final int CTX_PROFILE_COMPAT = 1 << 1; + /** ARB_create_context related: core profile */ + protected static final int CTX_PROFILE_CORE = 1 << 2; + /** ARB_create_context related: flag forward compatible */ + protected static final int CTX_OPTION_FORWARD = 1 << 3; + /** ARB_create_context related: not flag forward compatible */ + protected static final int CTX_OPTION_ANY = 1 << 4; + /** ARB_create_context related: flag debug */ + protected static final int CTX_OPTION_DEBUG = 1 << 5; } diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 755fae73d..231faab8c 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -62,6 +62,13 @@ public class GLProfile implements Cloneable { // Public (user-visible) profiles // + /** The desktop OpenGL compatibility profile 4.x, with x >= 0, ie GL2 plus GL4.
+ bc stands for backward compatibility. */ + public static final String GL4bc = "GL4bc"; + + /** The desktop OpenGL core profile 4.x, with x >= 0 */ + public static final String GL4 = "GL4"; + /** The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.
bc stands for backward compatibility. */ public static final String GL3bc = "GL3bc"; @@ -90,12 +97,12 @@ public class GLProfile implements Cloneable { /** * All GL Profiles in the order of default detection: GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3 */ - public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3bc, GL3 }; + public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL4bc, GL3bc, GL4, GL3 }; /** * All GL2ES2 Profiles in the order of default detection: GL2ES2, GL2, GLES2, GL3 */ - public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GLES2, GL3bc, GL3 }; + public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GLES2, GL4bc, GL3bc, GL4, GL3 }; /** * All GL2ES1 Profiles in the order of default detection: GL2ES1, GL2, GLES1 @@ -193,7 +200,11 @@ public class GLProfile implements Cloneable { } private static final String getGLImplBaseClassName(String profileImpl) { - if(GL3bc.equals(profileImpl)) { + if(GL4bc.equals(profileImpl)) { + return "com.jogamp.opengl.impl.gl4.GL4bc"; + } else if(GL4.equals(profileImpl)) { + return "com.jogamp.opengl.impl.gl4.GL4"; + } else if(GL3bc.equals(profileImpl)) { return "com.jogamp.opengl.impl.gl3.GL3bc"; } else if(GL3.equals(profileImpl)) { return "com.jogamp.opengl.impl.gl3.GL3"; @@ -254,19 +265,29 @@ public class GLProfile implements Cloneable { return profileImpl; } + /** Indicates whether this profile is capable of GL4bc. */ + public final boolean isGL4bc() { + return GL4bc.equals(profile); + } + + /** Indicates whether this profile is capable of GL4. */ + public final boolean isGL4() { + return isGL4bc() || GL4.equals(profile); + } + /** Indicates whether this profile is capable of GL3bc. */ public final boolean isGL3bc() { - return GL3bc.equals(profile); + return isGL4bc() || GL3bc.equals(profile); } /** Indicates whether this profile is capable of GL3. */ public final boolean isGL3() { - return isGL3bc() || GL3.equals(profile); + return isGL4() || isGL3bc() || GL3.equals(profile); } /** Indicates whether this profile is capable of GL2. */ public final boolean isGL2() { - return GL2.equals(profile); + return isGL3bc() || GL2.equals(profile); } /** Indicates whether this profile is capable of GLES1. */ @@ -294,24 +315,14 @@ public class GLProfile implements Cloneable { return GL2GL3.equals(profile) || isGL2() || isGL3() ; } - /** Indicates whether this profile uses the native OpenGL ES1 implementations. */ - public final boolean usesNativeGLES1() { - return GLES1.equals(profileImpl); + /** Indicates whether this profile uses the native desktop OpenGL GL4bc implementations. */ + public final boolean usesNativeGL4bc() { + return GL4bc.equals(profileImpl); } - /** Indicates whether this profile uses the native OpenGL ES2 implementations. */ - public final boolean usesNativeGLES2() { - return GLES2.equals(profileImpl); - } - - /** Indicates whether this profile uses either of the native OpenGL ES implementations. */ - public final boolean usesNativeGLES() { - return usesNativeGLES2() || usesNativeGLES1(); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL2 implementations. */ - public final boolean usesNativeGL2() { - return GL2.equals(profileImpl) || GL2ES12.equals(profileImpl) ; + /** Indicates whether this profile uses the native desktop OpenGL GL4 implementations. */ + public final boolean usesNativeGL4() { + return usesNativeGL4bc() || GL4.equals(profileImpl); } /** Indicates whether this profile uses the native desktop OpenGL GL3bc implementations. */ @@ -324,9 +335,29 @@ public class GLProfile implements Cloneable { return usesNativeGL3bc() || GL3.equals(profileImpl); } + /** Indicates whether this profile uses the native desktop OpenGL GL2 implementations. */ + public final boolean usesNativeGL2() { + return GL2.equals(profileImpl) || GL2ES12.equals(profileImpl) ; + } + /** Indicates whether this profile uses the native desktop OpenGL GL2 or GL3 implementations. */ public final boolean usesNativeGL2GL3() { - return usesNativeGL2() || usesNativeGL3() ; + return usesNativeGL2() || usesNativeGL3() || usesNativeGL4(); + } + + /** Indicates whether this profile uses the native OpenGL ES1 implementations. */ + public final boolean usesNativeGLES1() { + return GLES1.equals(profileImpl); + } + + /** Indicates whether this profile uses the native OpenGL ES2 implementations. */ + public final boolean usesNativeGLES2() { + return GLES2.equals(profileImpl); + } + + /** Indicates whether this profile uses either of the native OpenGL ES implementations. */ + public final boolean usesNativeGLES() { + return usesNativeGLES2() || usesNativeGLES1(); } /** Indicates whether this profile supports GLSL. */ @@ -634,6 +665,49 @@ public class GLProfile implements Cloneable { return "GLProfile[" + profile + "/" + profileImpl + "]"; } + public static final int GL_VERSIONS[][] = { + /* 0.*/ { -1 }, + /* 1.*/ { 0, 1, 2, 3, 4, 5 }, + /* 2.*/ { 0, 1 }, + /* 3.*/ { 0, 1, 2, 3 }, + /* 4.*/ { 0 } }; + + public static final int getMaxMajor() { + return GL_VERSIONS.length-1; + } + + public static final int getMaxMinor(int major) { + if(1>major || major>=GL_VERSIONS.length) return -1; + return GL_VERSIONS[major].length-1; + } + + public static final boolean isValidGLVersion(int major, int minor) { + if(1>major || major>=GL_VERSIONS.length) return false; + if(0>minor || minor>=GL_VERSIONS[major].length) return false; + return true; + } + + public static final boolean decrementGLVersion(int major[], int minor[]) { + if(null==major || major.length<1 ||null==minor || minor.length<1) { + throw new GLException("invalid array arguments"); + } + int m = major[0]; + int n = minor[0]; + if(!isValidGLVersion(m, n)) return false; + + // decrement .. + n -= 1; + if(n < 0) { + m -= 1; + n = GL_VERSIONS[m].length-1; + } + if(!isValidGLVersion(m, n)) return false; + major[0]=m; + minor[0]=n; + + return true; + } + // The intersection between desktop OpenGL and the union of the OpenGL ES profiles // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes private static final String GL2ES12 = "GL2ES12"; -- cgit v1.2.3 From 8778a3d70f8d57bc4f9142a3f59ea59754f08c1d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 17 Apr 2010 01:32:26 +0200 Subject: JOGL GL4 preperation (cont): - Cont. on Context creation refactoring (bb028021be2714e66d9b1062298a3e308c649c56) - Added Windows/WGL implementation - Added efficienct sharedContext usage if ARB is available, ie no more temp context has to be created. - Added more GLProfile GL4* code .. --- make/java-run-newt.sh | 7 +- .../opengl/impl/windows/wgl/WindowsWGLContext.java | 239 +++++++++++---------- .../windows/wgl/WindowsWGLDrawableFactory.java | 33 ++- .../jogamp/opengl/impl/x11/glx/X11GLXContext.java | 129 +++++------ .../opengl/impl/x11/glx/X11GLXDrawableFactory.java | 32 ++- src/jogl/classes/javax/media/opengl/GLContext.java | 1 + src/jogl/classes/javax/media/opengl/GLProfile.java | 19 ++ 7 files changed, 277 insertions(+), 183 deletions(-) (limited to 'src/jogl/classes/javax/media/opengl/GLContext.java') diff --git a/make/java-run-newt.sh b/make/java-run-newt.sh index 39654d03b..cb256e273 100755 --- a/make/java-run-newt.sh +++ b/make/java-run-newt.sh @@ -20,4 +20,9 @@ if [ $MOSX -eq 1 ] ; then X_ARGS="-XstartOnFirstThread" fi -java $X_ARGS -Djava.awt.headless=true com.jogamp.newt.util.MainThread $* 2>&1 | tee java-run-newt.log +# D_ARGS="-Dgluegen.debug.ProcAddressHelper=true -Dgluegen.debug.NativeLibrary=true -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all" +# D_ARGS="-Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all -Djogl.debug.GLSLState" +# D_ARGS="-Dnativewindow.debug.X11Util=true -Djogl.debug.GLDrawableFactory=true" +# D_ARGS="-Dnativewindow.debug.X11Util=true" + +java $X_ARGS -Djava.awt.headless=true $D_ARGS com.jogamp.newt.util.MainThread $* 2>&1 | tee java-run-newt.log diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index 7f9459a48..95706a7a1 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -122,48 +122,123 @@ public class WindowsWGLContext extends GLContextImpl { protected Map/**/ getExtensionNameMap() { return extensionNameMap; } - protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { - return 0; // FIXME + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); + WGLExt wglExt; + if(null==factory.getSharedContext()) { + wglExt = getWGLExt(); + } else { + wglExt = factory.getSharedContext().getWGLExt(); + } + + boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; + boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; + boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ; + + long _context=0; + + int attribs[] = { + /* 0 */ WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, major, + /* 2 */ WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, minor, + /* 4 */ WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, // default + /* 6 */ WGLExt.WGL_CONTEXT_FLAGS_ARB, 0, + /* 8 */ 0, 0, + /* 10 */ 0 + }; + + if ( major > 3 || major == 3 && minor >= 2 ) { + // FIXME: Verify with a None drawable binding (default framebuffer) + attribs[8+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB; + if( ctBwdCompat ) { + attribs[8+1] = WGLExt.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + } else { + attribs[8+1] = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB; + } + } + + if ( major >= 3 ) { + if( !ctBwdCompat && ctFwdCompat ) { + attribs[6+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + } + if( ctDebug) { + attribs[6+1] |= WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB; + } + } + + _context = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), share, attribs, 0); + if(0==_context) { + if(DEBUG) { + System.err.println("WindowsWGLContext.createContextARB couldn't create "+getGLVersion(null, major, minor, ctp, "@creation")); + } + } else { + // In contrast to GLX no verification with a drawable binding, ie default framebuffer, is necessary, + // if no 3.2 is available creation fails already! + // Nevertheless .. we do it .. + if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), _context)) { + if(DEBUG) { + System.err.println("WindowsWGLContext.createContextARB couldn't make current "+getGLVersion(null, major, minor, ctp, "@creation")); + } + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(_context); + _context = 0; + } } + return _context; + } /** * Creates and initializes an appropriate OpenGL context. Should only be * called by {@link #makeCurrentImpl()}. */ protected void create() { - GLCapabilities glCaps = drawable.getChosenGLCapabilities(); - if(DEBUG) { - System.err.println("WindowsWGLContext.create got "+glCaps); + if(0!=context) { + throw new GLException("context is not null: "+context); } + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); + GLCapabilities glCaps = drawable.getChosenGLCapabilities(); if (drawable.getNativeWindow().getSurfaceHandle() == 0) { throw new GLException("Internal error: attempted to create OpenGL context without an associated drawable"); } // Windows can set up sharing of display lists after creation time WindowsWGLContext other = (WindowsWGLContext) GLContextShareSet.getShareContext(this); - long hglrc2 = 0; + long share = 0; if (other != null) { - hglrc2 = other.getHGLRC(); - if (hglrc2 == 0) { + share = other.getHGLRC(); + if (share == 0) { throw new GLException("GLContextShareSet returned an invalid OpenGL context"); } } - // To use WGL_ARB_create_context, we have to make a temp context current, - // so we are able to use GetProcAddress - long temp_hglrc = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle()); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created temp OpenGL context " + toHexString(temp_hglrc) + " for " + this + ", device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", not yet sharing"); + int minor[] = new int[1]; + int major[] = new int[1]; + int ctp[] = new int[1]; + boolean createContextARBTried = false; + + // utilize the shared context's GLXExt in case it was using the ARB method and it already exists + if(null!=factory.getSharedContext() && factory.getSharedContext().isCreatedWithARBMethod()) { + if(DEBUG) { + System.err.println("WindowsWGLContext.createContext using shared Context: "+factory.getSharedContext()); + } + hglrc = createContextARB(share, true, major, minor, ctp); + createContextARBTried = true; } - if (temp_hglrc == 0) { - throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle())); - } else { + + long temp_hglrc = 0; + if(0==hglrc) { + // To use WGL_ARB_create_context, we have to make a temp context current, + // so we are able to use GetProcAddress + temp_hglrc = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle()); + if (temp_hglrc == 0) { + throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle())); + } if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) { throw new GLException("Error making temp context current: 0x" + Integer.toHexString(WGL.GetLastError())); } setGLFunctionAvailability(true, 0, 0, 0); - if( !isFunctionAvailable("wglCreateContextAttribsARB") || + if( createContextARBTried || + !isFunctionAvailable("wglCreateContextAttribsARB") || !isExtensionAvailable("WGL_ARB_create_context") ) { if(glCaps.getGLProfile().isGL3()) { WGL.wglMakeCurrent(0, 0); @@ -173,111 +248,51 @@ public class WindowsWGLContext extends GLContextImpl { // continue with temp context for GL < 3.0 hglrc = temp_hglrc; - if(DEBUG) { - System.err.println("WindowsWGLContext.create done (old ctx < 3.0 - no WGL_ARB_create_context) 0x"+Long.toHexString(hglrc)); - } - } else { - WGLExt wglExt = getWGLExt(); + return; + } + hglrc = createContextARB(share, true, major, minor, ctp); + createContextARBTried=true; + } + + if(0!=hglrc) { + share = 0; // mark as shared .. - // preset with default values - int attribs[] = { - /* 0 */ WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - /* 2 */ WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, 0, - /* 4 */ WGLExt.WGL_CONTEXT_FLAGS_ARB, 0 /* WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB */, - /* 6 */ 0, 0, - /* 8 */ 0 - }; + // need to update the GL func table .. + setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - if(glCaps.getGLProfile().isGL3()) { - // Try >= 3.2 core first ! - // In contrast to GLX no verify with a None drawable binding (default framebuffer) is necessary, - // if no 3.2 is available creation fails already! - attribs[0+1] = 3; - attribs[2+1] = 2; - if(glCaps.getGLProfile().isGL3bc()) { - attribs[6+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB; - attribs[6+1] = WGLExt.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - } - /** - * don't stricten requirements any further, even compatible would be fine - * - } else { - attribs[6+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB; - attribs[6+1] = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB; - } - */ - hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0); - if(0==hglrc) { - if(DEBUG) { - System.err.println("WindowsWGLContext.createContext couldn't create >= 3.2 core context - fallback"); - } - // Try >= 3.1 forward compatible - last resort for GL3 ! - attribs[0+1] = 3; - attribs[2+1] = 1; - if(!glCaps.getGLProfile().isGL3bc()) { - attribs[4+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - } - attribs[6+0] = 0; - attribs[6+1] = 0; - } else if(DEBUG) { - System.err.println("WindowsWGLContext.createContext >= 3.2 available 0x"+Long.toHexString(hglrc)); - } - } - if(0==hglrc) { - // 3.1 or 3.0 .. - hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0); - if(DEBUG) { - if(0==hglrc) { - System.err.println("WindowsWGLContext.createContext couldn't create >= 3.0 context - fallback"); - } else { - System.err.println("WindowsWGLContext.createContext >= 3.0 available 0x"+Long.toHexString(hglrc)); - } - } - } + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(temp_hglrc); - if(0==hglrc) { - if(glCaps.getGLProfile().isGL3()) { - WGL.wglMakeCurrent(0, 0); - WGL.wglDeleteContext(temp_hglrc); - throw new GLException("Unable to create OpenGL >= 3.1 context (have WGL_ARB_create_context)"); - } - - // continue with temp context for GL < 3.0 - hglrc = temp_hglrc; - if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { - throw new GLException("Error making old context current: 0x" + Integer.toHexString(WGL.GetLastError())); - } - updateGLProcAddressTable(0, 0, 0); - if(DEBUG) { - System.err.println("WindowsWGLContext.create done (old ctx < 3.0 - no 3.0) 0x"+Long.toHexString(hglrc)); - } - } else { - hglrc2 = 0; // mark as shared .. - WGL.wglMakeCurrent(0, 0); - WGL.wglDeleteContext(temp_hglrc); - - if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { - throw new GLException("Error making new context current: 0x" + Integer.toHexString(WGL.GetLastError())); - } - updateGLProcAddressTable(0, 0, 0); - if(DEBUG) { - System.err.println("WindowsWGLContext.create done (new ctx >= 3.0) 0x"+Long.toHexString(hglrc)); - } - } + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { + throw new GLException("Cannot make previous verified context current: 0x" + Integer.toHexString(WGL.GetLastError())); + } + } else { + if(glCaps.getGLProfile().isGL3()) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(temp_hglrc); + throw new GLException("WindowsWGLContext.createContext failed, but context > GL2 requested "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "); + } + if(DEBUG) { + System.err.println("WindowsWGLContext.createContext failed, fall back to !ARB context "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")); + } + + // continue with temp context for GL < 3.0 + hglrc = temp_hglrc; + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(hglrc); + throw new GLException("Error making old context current: 0x" + Integer.toHexString(WGL.GetLastError())); } } - if(0!=hglrc2) { - if (!WGL.wglShareLists(hglrc2, hglrc)) { - throw new GLException("wglShareLists(" + toHexString(hglrc2) + + + if(0!=share) { + if (!WGL.wglShareLists(share, hglrc)) { + throw new GLException("wglShareLists(" + toHexString(share) + ", " + toHexString(hglrc) + ") failed: error code 0x" + Integer.toHexString(WGL.GetLastError())); } } GLContextShareSet.contextCreated(this); - WGL.wglMakeCurrent(0, 0); // release immediatly to gain from ARB/EXT wglMakeContextCurrent(draw, read, ctx)! - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created OpenGL context " + toHexString(hglrc) + " for " + this + ", device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", sharing with " + toHexString(hglrc2)); - } } protected int makeCurrentImpl() throws GLException { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index e3938f9fe..bc99338ab 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -77,13 +77,22 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements WindowsWGLContext sharedContext=null; boolean canCreateGLPbuffer = false; + // package private .. + final WindowsWGLContext getSharedContext() { + validate(); + return sharedContext; + } + void initShared() { if(null==sharedDrawable) { sharedDrawable = new WindowsDummyWGLDrawable(this, null); - sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null); - sharedContext.makeCurrent(); - canCreateGLPbuffer = sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer"); - sharedContext.release(); + WindowsWGLContext _sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null); + { + _sharedContext.makeCurrent(); + canCreateGLPbuffer = _sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer"); + _sharedContext.release(); + } + _sharedContext = _sharedContext; if (DEBUG) { System.err.println("!!! SharedContext: "+sharedContext+", pbuffer supported "+canCreateGLPbuffer); } @@ -115,20 +124,30 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } + initShared(); return new WindowsOnscreenWGLDrawable(this, target); } protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) { + validate(); + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + initShared(); return new WindowsOffscreenWGLDrawable(this, target); } public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { validate(); - initShared(); + initShared(); // setup canCreateGLPBuffer return canCreateGLPbuffer; } protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { + validate(); + if (target == null) { + throw new IllegalArgumentException("Null target"); + } initShared(); final List returnList = new ArrayList(); final GLDrawableFactory factory = this; @@ -160,6 +179,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements } protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + validate(); + initShared(); AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capabilities, chooser, screen) ); @@ -169,6 +190,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLContext createExternalGLContext() { validate(); + initShared(); return WindowsExternalWGLContext.create(this, null); } @@ -179,6 +201,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLDrawable createExternalGLDrawable() { validate(); + initShared(); return WindowsExternalWGLDrawable.create(this, null); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index ad4cb2da5..f5e291c5f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -111,9 +111,16 @@ public abstract class X11GLXContext extends GLContextImpl { protected abstract void create(); protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); long display = config.getScreen().getDevice().getHandle(); - GLXExt glXExt = getGLXExt(); + + GLXExt glXExt; + if(null==factory.getSharedContext()) { + glXExt = getGLXExt(); + } else { + glXExt = factory.getSharedContext().getGLXExt(); + } boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; @@ -121,12 +128,10 @@ public abstract class X11GLXContext extends GLContextImpl { long _context=0; - String verstr = getGLVersion(null, major, minor, ctp, "@creation"); - int attribs[] = { /* 0 */ GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, major, /* 2 */ GLX.GLX_CONTEXT_MINOR_VERSION_ARB, minor, - /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, + /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, // default /* 6 */ GLX.GLX_CONTEXT_FLAGS_ARB, 0, /* 8 */ 0, 0, /* 10 */ 0 @@ -154,7 +159,7 @@ public abstract class X11GLXContext extends GLContextImpl { _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); if(0==_context) { if(DEBUG) { - System.err.println("X11GLXContext.createContextARB couldn't create "+verstr+" _context"); + System.err.println("X11GLXContext.createContextARB couldn't create "+getGLVersion(null, major, minor, ctp, "@creation")); } } else { if (!GLX.glXMakeContextCurrent(display, @@ -162,13 +167,11 @@ public abstract class X11GLXContext extends GLContextImpl { drawableRead.getNativeWindow().getSurfaceHandle(), _context)) { if(DEBUG) { - System.err.println("X11GLXContext.createContextARB couldn't make "+verstr+" context current"); + System.err.println("X11GLXContext.createContextARB couldn't make current "+getGLVersion(null, major, minor, ctp, "@creation")); } GLX.glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, _context); _context = 0; - } else if(DEBUG) { - System.err.println("X11GLXContext.createContextARB "+verstr+" available "+toHexString(_context)); } } return _context; @@ -180,10 +183,11 @@ public abstract class X11GLXContext extends GLContextImpl { * Note: The direct parameter may be overwritten by the direct state of a shared context. */ protected void createContext(boolean direct) { - X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - if(DEBUG) { - System.err.println("X11GLXContext.createContext got "+config); + if(0!=context) { + throw new GLException("context is not null: "+context); } + X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); long display = config.getScreen().getDevice().getHandle(); X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this); @@ -198,7 +202,7 @@ public abstract class X11GLXContext extends GLContextImpl { GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); GLProfile glp = glCaps.getGLProfile(); - isVendorATI = ((X11GLXDrawableFactory)(drawable.getFactoryImpl())).isVendorATI(); + isVendorATI = factory.isVendorATI(); if(config.getFBConfigID()<0) { // not able to use FBConfig @@ -216,70 +220,78 @@ public abstract class X11GLXContext extends GLContextImpl { throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION - if(DEBUG) { - System.err.println("X11GLXContext.createContext(0) done "+toHexString(context)); - } return; } - // To use GLX_ARB_create_context, we have to make a temp context current, - // so we are able to use GetProcAddress - long temp_context = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); - if (temp_context == 0) { - throw new GLException("Unable to create temp OpenGL context(1)"); - } - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - temp_context)) { - throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + int minor[] = new int[1]; + int major[] = new int[1]; + int ctp[] = new int[1]; + boolean createContextARBTried = false; + + // utilize the shared context's GLXExt in case it was using the ARB method and it already exists + if(null!=factory.getSharedContext() && factory.getSharedContext().isCreatedWithARBMethod()) { + if(DEBUG) { + System.err.println("X11GLXContext.createContext using shared Context: "+factory.getSharedContext()); + } + context = createContextARB(share, direct, major, minor, ctp); + createContextARBTried = true; } - setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION - if( !isFunctionAvailable("glXCreateContextAttribsARB") || - !isExtensionAvailable("GLX_ARB_create_context") ) { - if(glp.isGL3()) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)"); + long temp_context = 0; + if(0==context) { + // To use GLX_ARB_create_context, we have to make a temp context current, + // so we are able to use GetProcAddress + temp_context = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); + if (temp_context == 0) { + throw new GLException("Unable to create temp OpenGL context(1)"); } + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + temp_context)) { + throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + } + setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION - // continue with temp context for GL < 3.0 - context = temp_context; - if(DEBUG) { - System.err.println("X11GLXContext.createContext(1) done (!GLX_ARB_create_context) "+toHexString(context)); + if( createContextARBTried || + !isFunctionAvailable("glXCreateContextAttribsARB") || + !isExtensionAvailable("GLX_ARB_create_context") ) { + if(glp.isGL3()) { + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)"); + } + + // continue with temp context for GL < 3.0 + context = temp_context; + return; } - return; + context = createContextARB(share, direct, major, minor, ctp); + createContextARBTried=true; } - int minor[] = new int[1]; - int major[] = new int[1]; - int ctp[] = new int[1]; - context = createContextARB(share, direct, major, minor, ctp); - if(0!=context) { // need to update the GL func table .. setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - throw new GLException("Cannot make previous verified context current"); - } - if(DEBUG) { - System.err.println("X11GLXContext.createContext(2) done "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "+toHexString(context)); + if(0!=temp_context) { + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { + throw new GLException("Cannot make previous verified context current"); + } } } else { - if(DEBUG) { - System.err.println("X11GLXContext.createContext(2) failed "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")); - } if(!glp.isGL2()) { GLX.glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create context(2) (have GLX_ARB_create_context)"); + throw new GLException("X11GLXContext.createContext failed, but context > GL2 requested "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "); + } + if(DEBUG) { + System.err.println("X11GLXContext.createContext failed, fall back to !ARB context "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")); } // continue with temp context for GL <= 3.0 @@ -292,9 +304,6 @@ public abstract class X11GLXContext extends GLContextImpl { GLX.glXDestroyContext(display, temp_context); throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } - if(DEBUG) { - System.err.println("X11GLXContext.createContext(1) done "+toHexString(context)); - } } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index cfcd5cbe3..0d74bb791 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -86,15 +86,24 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna public boolean isVendorNVIDIA() { return isVendorNVIDIA; } private X11DummyGLXDrawable sharedDrawable=null; - private GLContext sharedContext=null; + private X11GLXContext sharedContext=null; + + // package private .. + final X11GLXContext getSharedContext() { + validate(); + return sharedContext; + } private void initShared() { if(null==sharedDrawable) { X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); - sharedContext = sharedDrawable.createContext(null); - sharedContext.makeCurrent(); - sharedContext.release(); + X11GLXContext _sharedContext = (X11GLXContext) sharedDrawable.createContext(null); + { + _sharedContext.makeCurrent(); + _sharedContext.release(); + } + sharedContext = _sharedContext; X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); if (DEBUG) { System.err.println("!!! SharedContext: "+sharedContext); @@ -136,6 +145,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } + initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } @@ -143,9 +153,11 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna } protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) { + validate(); if (target == null) { throw new IllegalArgumentException("Null target"); } + initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } @@ -187,6 +199,12 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna } protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { + validate(); + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + initShared(); + GLDrawableImpl pbufferDrawable; /** @@ -197,7 +215,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna */ boolean usedSharedContext=false; if( isVendorATI() && null == GLContext.getCurrent() ) { - initShared(); sharedContext.makeCurrent(); usedSharedContext=true; } @@ -216,6 +233,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + validate(); + initShared(); X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); NullWindow nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); @@ -225,16 +244,19 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna public GLContext createExternalGLContext() { validate(); + initShared(); return X11ExternalGLXContext.create(this, null); } public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { validate(); + initShared(); return canCreateGLPbuffer(device); } public GLDrawable createExternalGLDrawable() { validate(); + initShared(); return X11ExternalGLXDrawable.create(this, null); } diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index a8dbf9213..833ebf192 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -287,6 +287,7 @@ public abstract class GLContext { public final int getGLVersionMinor() { return ctxMajorVersion; } public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } + public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } /** * Returns a valid OpenGL version string, ie diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 231faab8c..e1fc9f53f 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -715,6 +715,8 @@ public class GLProfile implements Cloneable { private static final boolean isAWTAvailable; private static final boolean isAWTJOGLAvailable; + private static final boolean hasGL4bcImpl; + private static final boolean hasGL4Impl; private static final boolean hasGL3bcImpl; private static final boolean hasGL3Impl; private static final boolean hasGL2Impl; @@ -791,6 +793,8 @@ public class GLProfile implements Cloneable { } // FIXME: check for real GL3 availability .. ? + hasGL4bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); + hasGL4Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4Impl"); hasGL3bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3bcImpl"); hasGL3Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3Impl"); hasGL2Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2.GL2Impl"); @@ -837,6 +841,8 @@ public class GLProfile implements Cloneable { System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); + System.err.println("GLProfile.static hasGL4bcImpl "+hasGL4bcImpl); + System.err.println("GLProfile.static hasGL4Impl "+hasGL4Impl); System.err.println("GLProfile.static hasGL3bcImpl "+hasGL3bcImpl); System.err.println("GLProfile.static hasGL3Impl "+hasGL3Impl); System.err.println("GLProfile.static hasGL2Impl "+hasGL2Impl); @@ -891,6 +897,7 @@ public class GLProfile implements Cloneable { * Returns the profile implementation */ private static String computeProfileImpl(String profile) { + // FIXME Order of return profiles, after we can test their availability if (GL2ES1.equals(profile)) { if(hasGL2ES12Impl) { return GL2ES12; @@ -908,9 +915,21 @@ public class GLProfile implements Cloneable { return GL3; } else if(hasGL3bcImpl) { return GL3bc; + } else if(hasGL4Impl) { + return GL4; + } else if(hasGL4bcImpl) { + return GL4bc; } else if(hasGLES2Impl) { return GLES2; } + } else if(GL4bc.equals(profile) && hasGL4bcImpl) { + return GL4bc; + } else if(GL4.equals(profile)) { + if(hasGL4Impl) { + return GL4; + } else if(hasGL4bcImpl) { + return GL4bc; + } } else if(GL3bc.equals(profile) && hasGL3bcImpl) { return GL3bc; } else if(GL3.equals(profile)) { -- cgit v1.2.3 From 32790c376583beccd030eecd7c56cbe66d380172 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 20 Apr 2010 11:46:26 +0200 Subject: JOGL GL4 preperation (cont): - All available OpenGL versions (native/platform) are verified at GLProfile initialization and can be queried .. A mapping of major,compat -> major,minor,options is created. - Removal of temp context creation, when creating a context. This was necessary to query general availability of ARB_create_context. Due to the shared context of X11GLXDrawableFactory and WindowsWGLDrawableFactory, this is no more necessary. Due to the version mapping, the ARB_create_context paramters are known. - NativeWindow X11Lib: Added X11ErrorHandler, throwing a RuntimeException. Necessary to catch BadMatch .. etc X11 errors, eg for glXCreateContextAttribsARB Hence all X11 calls are covered now. - X11DummyGLXDrawable needs to use an own Window, otherwise GLn n>2 fails - Flattening the desktop GL* implementation, all use GL4bcImpl, which reduces the footprint dramatically. - GL*Impl.isGL*() (desktop) utilizes the GLContext.isGL*(), hence the results reflect the actual native context version. - GLContextImpl makeCurrent/create: Added workflow documentation, clarified code, defined abstract methods to have a protocol. - Removed moved files (from here to gluegen), see gluegen a01cb3d59715a41153380f1977ec75263b762dc6 - NativeLibLoader -> JNILibLoader - Fixed Exception Handling (as in gluegen bce53b52c8638729750c4286dbc04cb14329fd34), ie removed empty catch Throwable .. - GLContext.setSwapInterval(): Nop in offscreen case, otherwise X11IOError (NVIDIA Bug) Test: Tests - Junit - demos.gears.Gears - demos.jrefract.JRefract Platforms - Linux 64/32 ATI/NVidia - MacOsX - Windows (virtualbox 3.1.6, offscreen failed) TODO/BUGS: - FIXME ATI GLn n>2 with AWT, can't make context current, works well on NVIDIA though - FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! - Add GL 3.3 to GL3/gl3ext.h - Add GL 4.0 to GL3/gl3ext.h and fix the GL3/GL4 seperation - Rename jogl.gl2.jar -> jogl.gldesktop.jar (as done with it's native lib already) --- make/build-jogl.xml | 133 +++-- make/build-junit.xml | 18 + make/build-nativewindow.xml | 14 +- make/config/jogl/cg-common-CustomJavaCode.java | 2 +- make/config/jogl/gl-gl2.cfg | 48 +- make/config/jogl/gl-gl2es12.cfg | 90 ---- make/config/jogl/gl-gl3.cfg | 43 +- make/config/jogl/gl-gl3bc.cfg | 64 +-- make/config/jogl/gl-gl4.cfg | 37 ++ make/config/jogl/gl-gl4bc.cfg | 110 +++++ make/config/jogl/gl-impl-CustomCCode-gl2.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl2es12.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl3.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl3bc.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl4bc.c | 24 + .../config/jogl/gl-impl-CustomJavaCode-common.java | 74 ++- .../jogl/gl-impl-CustomJavaCode-desktop.java | 250 +++++++--- make/config/jogl/gl-impl-CustomJavaCode-gl2.java | 514 -------------------- .../jogl/gl-impl-CustomJavaCode-gl2es12.java | 455 ------------------ make/config/jogl/gl-impl-CustomJavaCode-gl3.java | 468 ------------------ make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java | 514 -------------------- make/config/jogl/gl-impl-CustomJavaCode-gl4.java | 339 +++++++++++++ make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java | 385 +++++++++++++++ make/config/jogl/gl-impl-CustomJavaCode-gles1.java | 41 -- make/config/jogl/gl-impl-CustomJavaCode-gles2.java | 41 -- make/config/jogl/gl3-common.cfg | 3 + make/config/jogl/gl3-desktop-tracker.cfg | 38 -- make/config/jogl/gl4-common.cfg | 5 + make/config/jogl/gl4-desktop-tracker.cfg | 38 ++ make/config/jogl/glu-CustomJavaCode-base.java | 4 +- make/config/jogl/glu-CustomJavaCode-gl2es1.java | 2 +- make/config/jogl/glu-common.cfg | 2 +- make/config/jogl/obsolete/gl-gl2es12.cfg | 90 ++++ .../config/jogl/obsolete/gl-impl-CustomCCode-gl2.c | 24 + .../jogl/obsolete/gl-impl-CustomCCode-gl2es12.c | 24 + .../config/jogl/obsolete/gl-impl-CustomCCode-gl3.c | 24 + .../jogl/obsolete/gl-impl-CustomJavaCode-gl2.java | 385 +++++++++++++++ .../obsolete/gl-impl-CustomJavaCode-gl2es12.java | 353 ++++++++++++++ make/config/nativewindow/x11-CustomJavaCode.java | 3 +- make/stub_includes/opengl/gl4.c | 10 +- make/stub_includes/opengl/gl4bc.c | 18 + .../opengl/impl/ExtensionAvailabilityCache.java | 4 +- .../com/jogamp/opengl/impl/GLContextImpl.java | 489 ++++++++++++------- .../jogamp/opengl/impl/GLDrawableFactoryImpl.java | 5 +- .../com/jogamp/opengl/impl/GLDrawableImpl.java | 2 +- .../com/jogamp/opengl/impl/GLJNILibLoader.java | 100 ++++ .../com/jogamp/opengl/impl/NativeLibLoader.java | 109 ----- .../com/jogamp/opengl/impl/ThreadingImpl.java | 11 +- .../com/jogamp/opengl/impl/egl/EGLContext.java | 10 +- .../jogamp/opengl/impl/egl/EGLDrawableFactory.java | 12 +- .../opengl/impl/egl/EGLDynamicLookupHelper.java | 12 +- .../jogamp/opengl/impl/egl/EGLExternalContext.java | 2 +- .../opengl/impl/macosx/cgl/MacOSXCGLContext.java | 19 +- .../impl/macosx/cgl/MacOSXCGLDrawableFactory.java | 11 +- .../impl/macosx/cgl/MacOSXExternalCGLContext.java | 5 +- .../impl/macosx/cgl/MacOSXOnscreenCGLContext.java | 4 +- .../impl/macosx/cgl/MacOSXPbufferCGLContext.java | 13 +- .../macosx/cgl/awt/MacOSXJava2DCGLContext.java | 11 +- .../windows/wgl/WindowsExternalWGLContext.java | 2 +- .../opengl/impl/windows/wgl/WindowsWGLContext.java | 16 +- .../windows/wgl/WindowsWGLDrawableFactory.java | 52 +- .../WindowsWGLGraphicsConfigurationFactory.java | 1 - .../opengl/impl/x11/glx/X11DummyGLXDrawable.java | 13 +- .../opengl/impl/x11/glx/X11ExternalGLXContext.java | 2 +- .../jogamp/opengl/impl/x11/glx/X11GLXContext.java | 121 +++-- .../opengl/impl/x11/glx/X11GLXDrawableFactory.java | 52 +- .../opengl/impl/x11/glx/X11PbufferGLXContext.java | 29 +- .../com/jogamp/opengl/util/ImmModeSink.java | 6 +- .../opengl/util/glsl/fixedfunc/FixedFuncUtil.java | 2 +- src/jogl/classes/javax/media/opengl/GL4.java | 5 - src/jogl/classes/javax/media/opengl/GL4bc.java | 5 - src/jogl/classes/javax/media/opengl/GLContext.java | 187 +++++++- .../javax/media/opengl/GLDrawableFactory.java | 62 +-- src/jogl/classes/javax/media/opengl/GLProfile.java | 534 ++++++++++++--------- .../test/junit/jogl/acore/TestGLProfile01CORE.java | 95 ++++ .../jogamp/test/junit/jogl/awt/TestAWT01GLn.java | 106 ++++ .../junit/jogl/offscreen/TestOffscreen01NEWT.java | 39 +- .../test/junit/jogl/texture/TestTexture01AWT.java | 2 +- .../jogamp/nativewindow/impl/NWJNILibLoader.java | 50 ++ .../com/jogamp/nativewindow/impl/NWReflection.java | 188 -------- .../nativewindow/impl/NativeLibLoaderBase.java | 210 -------- .../nativewindow/impl/NativeWindowFactoryImpl.java | 5 +- .../nativewindow/impl/jawt/JAWTJNILibLoader.java | 78 +++ .../impl/jawt/JAWTNativeLibLoader.java | 78 --- .../jogamp/nativewindow/impl/jawt/JAWTUtil.java | 4 +- .../com/jogamp/nativewindow/impl/jvm/JVMUtil.java | 72 --- .../com/jogamp/nativewindow/impl/x11/X11Util.java | 2 +- .../nativewindow/GraphicsConfigurationFactory.java | 3 +- .../media/nativewindow/NativeWindowFactory.java | 13 +- src/nativewindow/native/JVM_Tool.c | 51 -- src/nativewindow/native/x11/Xmisc.c | 50 +- src/newt/classes/com/jogamp/newt/NewtFactory.java | 2 +- src/newt/classes/com/jogamp/newt/Window.java | 5 +- .../com/jogamp/newt/impl/NEWTJNILibLoader.java | 62 +++ .../com/jogamp/newt/impl/NativeLibLoader.java | 62 --- .../classes/com/jogamp/newt/intel/gdl/Display.java | 2 +- .../classes/com/jogamp/newt/macosx/MacDisplay.java | 2 +- .../jogamp/newt/opengl/broadcom/egl/Display.java | 2 +- .../com/jogamp/newt/opengl/kd/KDDisplay.java | 2 +- .../classes/com/jogamp/newt/util/MainThread.java | 6 +- .../com/jogamp/newt/windows/WindowsDisplay.java | 2 +- .../classes/com/jogamp/newt/x11/X11Display.java | 2 +- src/newt/native/X11Window.c | 34 +- 103 files changed, 3850 insertions(+), 4070 deletions(-) delete mode 100644 make/config/jogl/gl-gl2es12.cfg create mode 100644 make/config/jogl/gl-gl4.cfg create mode 100644 make/config/jogl/gl-gl4bc.cfg delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl2.c delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl2es12.c delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl3.c delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl3bc.c create mode 100644 make/config/jogl/gl-impl-CustomCCode-gl4bc.c delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl2.java delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl3.java delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java create mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl4.java create mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java delete mode 100644 make/config/jogl/gl3-desktop-tracker.cfg create mode 100644 make/config/jogl/gl4-common.cfg create mode 100644 make/config/jogl/gl4-desktop-tracker.cfg create mode 100644 make/config/jogl/obsolete/gl-gl2es12.cfg create mode 100644 make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c create mode 100644 make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c create mode 100644 make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c create mode 100644 make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java create mode 100644 make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java create mode 100644 make/stub_includes/opengl/gl4bc.c create mode 100644 src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java delete mode 100644 src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java delete mode 100644 src/jogl/classes/javax/media/opengl/GL4.java delete mode 100644 src/jogl/classes/javax/media/opengl/GL4bc.java create mode 100755 src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java create mode 100755 src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTJNILibLoader.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTNativeLibLoader.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jvm/JVMUtil.java delete mode 100644 src/nativewindow/native/JVM_Tool.c create mode 100644 src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java delete mode 100644 src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java (limited to 'src/jogl/classes/javax/media/opengl/GLContext.java') diff --git a/make/build-jogl.xml b/make/build-jogl.xml index d42b859bd..6d95ebea8 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -104,9 +104,6 @@ - - @@ -508,12 +505,24 @@ - - + + + + + + + + + + - @@ -544,7 +553,7 @@ - + - - - - - - - - - @@ -826,6 +820,21 @@ targetfile="${src.generated.java}/javax/media/opengl/DebugGL3.java" /> + + + + + + + + + + + @@ -899,7 +908,29 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -1259,9 +1290,7 @@ - - - + @@ -1269,24 +1298,6 @@ - - - - - - - - - - - - - - - - - - @@ -1393,13 +1404,6 @@ linker.cfg.id="${linker.cfg.id.gl2}"/> - - - - - - + @@ -1450,7 +1453,6 @@ - @@ -1528,14 +1530,7 @@ - - - - - - - + - - - - - - - + diff --git a/make/build-junit.xml b/make/build-junit.xml index 887060084..ebf3f683e 100644 --- a/make/build-junit.xml +++ b/make/build-junit.xml @@ -81,6 +81,24 @@ + + + + + + + + + + + + + + + + + + - - + diff --git a/make/config/jogl/cg-common-CustomJavaCode.java b/make/config/jogl/cg-common-CustomJavaCode.java index 974e24bf4..d1e4f8bf5 100755 --- a/make/config/jogl/cg-common-CustomJavaCode.java +++ b/make/config/jogl/cg-common-CustomJavaCode.java @@ -1,5 +1,5 @@ static { - com.jogamp.opengl.impl.NativeLibLoader.loadCgImpl(); + com.jogamp.opengl.impl.GLJNILibLoader.loadCgImpl(); } /** A convenience method which reads all available data from the InputStream and then calls cgCreateProgram. */ diff --git a/make/config/jogl/gl-gl2.cfg b/make/config/jogl/gl-gl2.cfg index 37452d159..48dd8eda6 100644 --- a/make/config/jogl/gl-gl2.cfg +++ b/make/config/jogl/gl-gl2.cfg @@ -12,72 +12,32 @@ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java Package javax.media.opengl -Style InterfaceAndImpl +Style InterfaceOnly JavaClass GL2 Extends GL2 GLBase Extends GL2 GL Extends GL2 GL2ES1 Extends GL2 GL2ES2 Extends GL2 GL2GL3 -ImplPackage com.jogamp.opengl.impl.gl2 -ImplJavaClass GL2Impl -Implements GL2Impl GLBase -Implements GL2Impl GL -Implements GL2Impl GL2ES1 -Implements GL2Impl GL2ES2 -Implements GL2Impl GL2GL3 Include gl-common.cfg Include gl-common-extensions.cfg Include gl-desktop.cfg -EmitProcAddressTable true -ProcAddressTableClassName GL2ProcAddressTable -GetProcAddressTableExpr ((GL2ProcAddressTable)_context.getGLProcAddressTable()) - # Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums TagNativeBinding true # Ignore extensions that are already picked up via the GL2ES1 interface IgnoreExtension GL_EXT_point_parameters -# Add PixelStorei StateTracker -# -CustomJavaCode GL2Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - CustomJavaCode GL2 public boolean glIsPBOPackEnabled(); CustomJavaCode GL2 public boolean glIsPBOUnpackEnabled(); IncludeAs CustomJavaCode GL2 gl-if-CustomJavaCode-gl2.java -CustomJavaCode GL2Impl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2Impl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2Impl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2Impl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2Impl public void glClearDepthf(float depth) { -CustomJavaCode GL2Impl glClearDepth((double)depth); } - -CustomJavaCode GL2Impl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL2Impl glDepthRange((double)zNear, (double)zFar); } - Include gl-headers.cfg Include ../intptr.cfg -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-gl2.java -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-desktop.java -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl2.c +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff -Import javax.media.opengl.GLES1 -Import javax.media.opengl.GLES2 -Import javax.media.opengl.GL2 -Import javax.media.opengl.GLArrayData -Import javax.media.opengl.GLUniformData -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl2es12.cfg b/make/config/jogl/gl-gl2es12.cfg deleted file mode 100644 index 3942b1419..000000000 --- a/make/config/jogl/gl-gl2es12.cfg +++ /dev/null @@ -1,90 +0,0 @@ -# This .cfg file is used to generate the GL interface and implementing class. -JavaOutputDir gensrc/classes -NativeOutputDir gensrc/native/jogl/gl2es12 - -ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL.java -ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES1.java -ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/GLBase.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java - -Style ImplOnly -ImplPackage com.jogamp.opengl.impl.gl2es12 -ImplJavaClass GL2ES12Impl -Implements GL2ES12Impl GLBase -Implements GL2ES12Impl GL -Implements GL2ES12Impl GL2ES1 -Implements GL2ES12Impl GL2ES2 - -Include gl-common.cfg -Include gl-common-extensions.cfg -Include gl-desktop.cfg - -# Because we're manually implementing glMapBuffer but only producing -# the implementing class, GlueGen doesn't notice that it has to emit a -# proc address table entry for it. Force it to here. -ForceProcAddressGen glMapBuffer - -# Force all of the methods to be emitted using dynamic linking so we -# don't need to link against any emulation library on the desktop or -# depend on the presence of an import library for a particular device -ForceProcAddressGen __ALL__ - -# Also force the calling conventions of the locally generated function -# pointer typedefs for these routines to APIENTRY -LocalProcAddressCallingConvention __ALL__ APIENTRY - -EmitProcAddressTable true -ProcAddressTableClassName GL2ES12ProcAddressTable -GetProcAddressTableExpr ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable()) - -# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums -TagNativeBinding true - -# There seem to be some errors in the glue code generation where we are not ignoring -# enough routines from desktop GL in GL2ES12Impl. For now manually ignore those which -# we know shouldn't be in there -Ignore glGetTexImage -Ignore glPixelStoref - -# Add PixelStorei StateTracker -# -# Add input validation to glPixelStorei to make sure that, even if we -# are running on top of desktop OpenGL, parameters not exposed in -# OpenGL ES can not be changed -CustomJavaCode GL2ES12Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei if (pname != GL_PACK_ALIGNMENT && pname != GL_UNPACK_ALIGNMENT) { -JavaPrologue glPixelStorei throw new GLException("Unsupported pixel store parameter name 0x" + Integer.toHexString(pname)); -JavaPrologue glPixelStorei } -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - -CustomJavaCode GL2ES12Impl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2ES12Impl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2ES12Impl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2ES12Impl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2ES12Impl public void glClearDepthf(float depth) { -CustomJavaCode GL2ES12Impl glClearDepth((double)depth); } - -CustomJavaCode GL2ES12Impl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL2ES12Impl glDepthRange((double)zNear, (double)zFar); } - -Include gl-headers.cfg -Include ../intptr.cfg - -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2es12.java -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-embedded.java -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl2es12.c - -Import javax.media.opengl.GLES1 -Import javax.media.opengl.GLES2 -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl3.cfg b/make/config/jogl/gl-gl3.cfg index 0bfe2cc38..d5e0003d4 100644 --- a/make/config/jogl/gl-gl3.cfg +++ b/make/config/jogl/gl-gl3.cfg @@ -8,7 +8,7 @@ ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/G ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/GLBase.java Package javax.media.opengl -Style InterfaceAndImpl +Style InterfaceOnly JavaClass GL3 Extends GL3 GLBase Extends GL3 GL @@ -27,48 +27,15 @@ Include gl3-desktop.cfg IncludeAs CustomJavaCode GL3 gl-if-CustomJavaCode-gl3.java -EmitProcAddressTable true -ProcAddressTableClassName GL3ProcAddressTable -GetProcAddressTableExpr ((GL3ProcAddressTable)_context.getGLProcAddressTable()) - -# Force all of the methods to be emitted using dynamic linking so we -# don't need to link against any emulation library on the desktop or -# depend on the presence of an import library for a particular device -ForceProcAddressGen __ALL__ - -# Also force the calling conventions of the locally generated function -# pointer typedefs for these routines to APIENTRY -LocalProcAddressCallingConvention __ALL__ APIENTRY +EmitProcAddressTable false # Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums TagNativeBinding true -# Add PixelStorei StateTracker -# -CustomJavaCode GL3Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - -CustomJavaCode GL3Impl public void glClearDepthf(float depth) { -CustomJavaCode GL3Impl glClearDepth((double)depth); } - -CustomJavaCode GL3Impl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL3Impl glDepthRange((double)zNear, (double)zFar); } - Include gl3-headers.cfg Include ../intptr.cfg -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-gl3.java -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-desktop.java -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl3.c +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff -Import javax.media.opengl.GLES2 -Import javax.media.opengl.GL3 -Import javax.media.opengl.GLArrayData -Import javax.media.opengl.GLUniformData -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl3bc.cfg b/make/config/jogl/gl-gl3bc.cfg index 7bba2f635..7c53ea8d6 100644 --- a/make/config/jogl/gl-gl3bc.cfg +++ b/make/config/jogl/gl-gl3bc.cfg @@ -14,7 +14,7 @@ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java Package javax.media.opengl -Style InterfaceAndImpl +Style InterfaceOnly JavaClass GL3bc Extends GL3bc GLBase Extends GL3bc GL @@ -23,15 +23,6 @@ Extends GL3bc GL2ES2 Extends GL3bc GL2GL3 Extends GL3bc GL2 Extends GL3bc GL3 -ImplPackage com.jogamp.opengl.impl.gl3 -ImplJavaClass GL3bcImpl -Implements GL3bcImpl GLBase -Implements GL3bcImpl GL -Implements GL3bcImpl GL2ES1 -Implements GL3bcImpl GL2ES2 -Implements GL3bcImpl GL2GL3 -Implements GL3bcImpl GL2 -Implements GL3bcImpl GL3 Include gl-common.cfg Include gl-common-extensions.cfg @@ -39,64 +30,17 @@ Include gl-desktop.cfg Include gl3-common.cfg Include gl3-desktop.cfg -# Because we're manually implementing glMapBuffer but only producing -# the implementing class, GlueGen doesn't notice that it has to emit a -# proc address table entry for it. Force it to here. -ForceProcAddressGen glMapBuffer - -# Force all of the methods to be emitted using dynamic linking so we -# don't need to link against any emulation library on the desktop or -# depend on the presence of an import library for a particular device -ForceProcAddressGen __ALL__ - -# Also force the calling conventions of the locally generated function -# pointer typedefs for these routines to APIENTRY -LocalProcAddressCallingConvention __ALL__ APIENTRY - -EmitProcAddressTable true -ProcAddressTableClassName GL3bcProcAddressTable -GetProcAddressTableExpr ((GL3bcProcAddressTable)_context.getGLProcAddressTable()) - # Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums TagNativeBinding true # Ignore extensions that are already picked up via the GL2ES1 interface IgnoreExtension GL_EXT_point_parameters -# Add PixelStorei StateTracker -CustomJavaCode GL3bcImpl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - -CustomJavaCode GL3bcImpl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL3bcImpl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL3bcImpl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL3bcImpl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL3bcImpl public void glClearDepthf(float depth) { -CustomJavaCode GL3bcImpl glClearDepth((double)depth); } - -CustomJavaCode GL3bcImpl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL3bcImpl glDepthRange((double)zNear, (double)zFar); } - Include gl-headers.cfg Include gl3ext-headers.cfg Include ../intptr.cfg -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-gl3bc.java -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-desktop.java -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl3bc.c +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff -Import javax.media.opengl.GLES1 -Import javax.media.opengl.GLES2 -Import javax.media.opengl.GL2GL3 -Import javax.media.opengl.GL2 -Import javax.media.opengl.GL3 -Import javax.media.opengl.GL3bc -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl4.cfg b/make/config/jogl/gl-gl4.cfg new file mode 100644 index 000000000..1d4392899 --- /dev/null +++ b/make/config/jogl/gl-gl4.cfg @@ -0,0 +1,37 @@ +# This .cfg file is used to generate the GL interface and implementing class. +JavaOutputDir gensrc/classes +NativeOutputDir gensrc/native/jogl/gl4 + +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2GL3.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL3.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/GLBase.java + +Package javax.media.opengl +Style InterfaceOnly +JavaClass GL4 +Extends GL4 GLBase +Extends GL4 GL +Extends GL4 GL2ES2 +Extends GL4 GL2GL3 +Extends GL4 GL3 +Include gl-common.cfg +Include gl-common-extensions.cfg +Include gl3-common.cfg +Include gl4-common.cfg +Include gl3-desktop.cfg + +IncludeAs CustomJavaCode GL4 gl-if-CustomJavaCode-gl3.java + +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff + + +# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums +TagNativeBinding true + +Include gl3-headers.cfg +Include ../intptr.cfg + diff --git a/make/config/jogl/gl-gl4bc.cfg b/make/config/jogl/gl-gl4bc.cfg new file mode 100644 index 000000000..3a3e02041 --- /dev/null +++ b/make/config/jogl/gl-gl4bc.cfg @@ -0,0 +1,110 @@ +# This .cfg file is used to generate the GL interface and implementing class. +JavaOutputDir gensrc/classes +NativeOutputDir gensrc/native/jogl/gl4 + +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2ES1.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2GL3.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL3.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL4.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL3bc.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/GLBase.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java + +Package javax.media.opengl +Style InterfaceAndImpl +JavaClass GL4bc +Extends GL4bc GLBase +Extends GL4bc GL +Extends GL4bc GL2ES1 +Extends GL4bc GL2ES2 +Extends GL4bc GL2GL3 +Extends GL4bc GL2 +Extends GL4bc GL3 +Extends GL4bc GL3bc +Extends GL4bc GL4 +ImplPackage com.jogamp.opengl.impl.gl4 +ImplJavaClass GL4bcImpl +Implements GL4bcImpl GLBase +Implements GL4bcImpl GL +Implements GL4bcImpl GL2ES1 +Implements GL4bcImpl GL2ES2 +Implements GL4bcImpl GL2GL3 +Implements GL4bcImpl GL2 +Implements GL4bcImpl GL3 +Implements GL4bcImpl GL3bc +Implements GL4bcImpl GL4 + +Include gl-common.cfg +Include gl-common-extensions.cfg +Include gl-desktop.cfg +Include gl3-common.cfg +Include gl4-common.cfg +Include gl3-desktop.cfg + +# Because we're manually implementing glMapBuffer but only producing +# the implementing class, GlueGen doesn't notice that it has to emit a +# proc address table entry for it. Force it to here. +ForceProcAddressGen glMapBuffer + +# Force all of the methods to be emitted using dynamic linking so we +# don't need to link against any emulation library on the desktop or +# depend on the presence of an import library for a particular device +ForceProcAddressGen __ALL__ + +# Also force the calling conventions of the locally generated function +# pointer typedefs for these routines to APIENTRY +LocalProcAddressCallingConvention __ALL__ APIENTRY + +EmitProcAddressTable true +ProcAddressTableClassName GL4bcProcAddressTable +GetProcAddressTableExpr ((GL4bcProcAddressTable)_context.getGLProcAddressTable()) + +# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums +TagNativeBinding true + +# Ignore extensions that are already picked up via the GL2ES1 interface +IgnoreExtension GL_EXT_point_parameters + +# Add PixelStorei StateTracker +CustomJavaCode GL4bcImpl private static final int params_offset = 0; // just a helper for JavaPrologue .. + +JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); + +JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } + +CustomJavaCode GL4bcImpl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL4bcImpl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL4bcImpl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL4bcImpl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL4bcImpl public void glClearDepthf(float depth) { +CustomJavaCode GL4bcImpl glClearDepth((double)depth); } + +CustomJavaCode GL4bcImpl public void glDepthRangef(float zNear, float zFar) { +CustomJavaCode GL4bcImpl glDepthRange((double)zNear, (double)zFar); } + +Include gl-headers.cfg +Include gl3ext-headers.cfg +Include ../intptr.cfg + +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-common.java +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-gl4bc.java +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-desktop.java +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-gl2_es2.java +IncludeAs CustomCCode gl-impl-CustomCCode-gl4bc.c + +Import javax.media.opengl.GLES1 +Import javax.media.opengl.GLES2 +Import javax.media.opengl.GL2GL3 +Import javax.media.opengl.GL2 +Import javax.media.opengl.GL3 +Import javax.media.opengl.GL3bc +Import javax.media.opengl.GL4 +Import com.jogamp.opengl.impl.InternalBufferUtil +Import java.io.PrintStream diff --git a/make/config/jogl/gl-impl-CustomCCode-gl2.c b/make/config/jogl/gl-impl-CustomCCode-gl2.c deleted file mode 100644 index 91fd0078b..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl2.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2.GL2Impl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl2_GL2Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2.GL2Impl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl2_GL2Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl2es12.c b/make/config/jogl/gl-impl-CustomCCode-gl2es12.c deleted file mode 100644 index 07b821802..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl2es12.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl3.c b/make/config/jogl/gl-impl-CustomCCode-gl3.c deleted file mode 100644 index f540a7d4a..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl3.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3Impl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3Impl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl3bc.c b/make/config/jogl/gl-impl-CustomCCode-gl3bc.c deleted file mode 100644 index 21de8c925..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl3bc.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3bcImpl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3bcImpl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3bcImpl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3bcImpl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl4bc.c b/make/config/jogl/gl-impl-CustomCCode-gl4bc.c new file mode 100644 index 000000000..bcda20fa4 --- /dev/null +++ b/make/config/jogl/gl-impl-CustomCCode-gl4bc.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl4.GL4bcImpl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl4_GL4bcImpl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl4.GL4bcImpl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl4_GL4bcImpl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/gl-impl-CustomJavaCode-common.java b/make/config/jogl/gl-impl-CustomJavaCode-common.java index 564606799..4872490b0 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-common.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-common.java @@ -1,16 +1,58 @@ - public GLProfile getGLProfile() { - return this.glProfile; - } - private GLProfile glProfile; - - public int glGetBoundBuffer(int target) { - return bufferStateTracker.getBoundBufferObject(target, this); - } - - public boolean glIsVBOArrayEnabled() { - return checkArrayVBOEnabled(false); - } - - public boolean glIsVBOElementEnabled() { - return checkElementVBOEnabled(false); - } + public GLProfile getGLProfile() { + return this.glProfile; + } + private GLProfile glProfile; + + public int glGetBoundBuffer(int target) { + return bufferStateTracker.getBoundBufferObject(target, this); + } + + public boolean glIsVBOArrayEnabled() { + return checkArrayVBOEnabled(false); + } + + public boolean glIsVBOElementEnabled() { + return checkElementVBOEnabled(false); + } + + public final boolean isGL() { + return true; + } + + public final GL getGL() throws GLException { + return this; + } + + public boolean isFunctionAvailable(String glFunctionName) { + return _context.isFunctionAvailable(glFunctionName); + } + + public boolean isExtensionAvailable(String glExtensionName) { + return _context.isExtensionAvailable(glExtensionName); + } + + public Object getExtension(String extensionName) { + // At this point we don't expose any extensions using this mechanism + return null; + } + + /** Returns the context this GL object is associated with for better + error checking by DebugGL. */ + public GLContext getContext() { + return _context; + } + + private GLContextImpl _context; + + public void setSwapInterval(int interval) { + _context.setSwapInterval(interval); + } + + public int getSwapInterval() { + return _context.getSwapInterval(); + } + + public Object getPlatformGLExtensions() { + return _context.getPlatformGLExtensions(); + } + diff --git a/make/config/jogl/gl-impl-CustomJavaCode-desktop.java b/make/config/jogl/gl-impl-CustomJavaCode-desktop.java index 04ba39c3d..93a275269 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-desktop.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-desktop.java @@ -1,79 +1,191 @@ -private int[] imageSizeTemp = new int[1]; - -/** Helper for more precise computation of number of bytes that will - be touched by a pixel pack or unpack operation. */ -private int imageSizeInBytes(int bytesPerElement, - int width, int height, int depth, boolean pack) { - int rowLength = 0; - int skipRows = 0; - int skipPixels = 0; - int alignment = 1; - int imageHeight = 0; - int skipImages = 0; - - if (pack) { - glGetIntegerv(GL_PACK_ROW_LENGTH, imageSizeTemp, 0); - rowLength = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_SKIP_ROWS, imageSizeTemp, 0); - skipRows = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_SKIP_PIXELS, imageSizeTemp, 0); - skipPixels = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_ALIGNMENT, imageSizeTemp, 0); - alignment = imageSizeTemp[0]; - if (depth > 1) { - glGetIntegerv(GL_PACK_IMAGE_HEIGHT, imageSizeTemp, 0); - imageHeight = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_SKIP_IMAGES, imageSizeTemp, 0); - skipImages = imageSizeTemp[0]; + private int[] imageSizeTemp = new int[1]; + + /** Helper for more precise computation of number of bytes that will + be touched by a pixel pack or unpack operation. */ + private int imageSizeInBytes(int bytesPerElement, + int width, int height, int depth, boolean pack) { + int rowLength = 0; + int skipRows = 0; + int skipPixels = 0; + int alignment = 1; + int imageHeight = 0; + int skipImages = 0; + + if (pack) { + glGetIntegerv(GL_PACK_ROW_LENGTH, imageSizeTemp, 0); + rowLength = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_SKIP_ROWS, imageSizeTemp, 0); + skipRows = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_SKIP_PIXELS, imageSizeTemp, 0); + skipPixels = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_ALIGNMENT, imageSizeTemp, 0); + alignment = imageSizeTemp[0]; + if (depth > 1) { + glGetIntegerv(GL_PACK_IMAGE_HEIGHT, imageSizeTemp, 0); + imageHeight = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_SKIP_IMAGES, imageSizeTemp, 0); + skipImages = imageSizeTemp[0]; + } + } else { + glGetIntegerv(GL_UNPACK_ROW_LENGTH, imageSizeTemp, 0); + rowLength = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_SKIP_ROWS, imageSizeTemp, 0); + skipRows = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, imageSizeTemp, 0); + skipPixels = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_ALIGNMENT, imageSizeTemp, 0); + alignment = imageSizeTemp[0]; + if (depth > 1) { + glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, imageSizeTemp, 0); + imageHeight = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_SKIP_IMAGES, imageSizeTemp, 0); + skipImages = imageSizeTemp[0]; + } } - } else { - glGetIntegerv(GL_UNPACK_ROW_LENGTH, imageSizeTemp, 0); - rowLength = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_SKIP_ROWS, imageSizeTemp, 0); - skipRows = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_SKIP_PIXELS, imageSizeTemp, 0); - skipPixels = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_ALIGNMENT, imageSizeTemp, 0); - alignment = imageSizeTemp[0]; - if (depth > 1) { - glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, imageSizeTemp, 0); - imageHeight = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_SKIP_IMAGES, imageSizeTemp, 0); - skipImages = imageSizeTemp[0]; + // Try to deal somewhat correctly with potentially invalid values + width = Math.max(0, width ); + height = Math.max(1, height); // min 1D + depth = Math.max(1, depth ); // min 1 * imageSize + skipRows = Math.max(0, skipRows); + skipPixels = Math.max(0, skipPixels); + alignment = Math.max(1, alignment); + skipImages = Math.max(0, skipImages); + + imageHeight = ( imageHeight > 0 ) ? imageHeight : height; + rowLength = ( rowLength > 0 ) ? rowLength : width; + + int rowLengthInBytes = rowLength * bytesPerElement; + + if (alignment > 1) { + int padding = rowLengthInBytes % alignment; + if (padding > 0) { + rowLengthInBytes += alignment - padding; + } } + + /** + * skipPixels and skipRows is a static one time offset. + * + * skipImages and depth are in multiples of image size. + * + * rowlenght is the actual repeating offset + * to go from line n to line n+1 at the same x-axis position. + */ + return + ( skipImages + depth - 1 ) * imageHeight * rowLengthInBytes + // whole images + ( skipRows + height - 1 ) * rowLengthInBytes + // lines with padding + ( skipPixels + width ) * bytesPerElement; // last line + } + + public final boolean isGL4bc() { + return _context.isGL4bc(); + } + + public final boolean isGL4() { + return _context.isGL4(); + } + + public final boolean isGL3bc() { + return _context.isGL3bc(); + } + + public final boolean isGL3() { + return _context.isGL3(); } - // Try to deal somewhat correctly with potentially invalid values - width = Math.max(0, width ); - height = Math.max(1, height); // min 1D - depth = Math.max(1, depth ); // min 1 * imageSize - skipRows = Math.max(0, skipRows); - skipPixels = Math.max(0, skipPixels); - alignment = Math.max(1, alignment); - skipImages = Math.max(0, skipImages); - imageHeight = ( imageHeight > 0 ) ? imageHeight : height; - rowLength = ( rowLength > 0 ) ? rowLength : width; + public final boolean isGL2() { + return _context.isGL2(); + } + + public final boolean isGL2ES1() { + return _context.isGL2ES1(); + } - int rowLengthInBytes = rowLength * bytesPerElement; + public final boolean isGL2ES2() { + return _context.isGL2ES2(); + } - if (alignment > 1) { - int padding = rowLengthInBytes % alignment; - if (padding > 0) { - rowLengthInBytes += alignment - padding; + public final boolean isGL2GL3() { + return _context.isGL2GL3(); + } + + public final boolean hasGLSL() { + return _context.hasGLSL(); + } + + public final GL4bc getGL4bc() throws GLException { + if(!isGL4bc()) { + throw new GLException("Not a GL4bc implementation"); + } + return this; + } + + public final GL4 getGL4() throws GLException { + if(!isGL4bc()) { + throw new GLException("Not a GL4 implementation"); } + return this; } - /** - * skipPixels and skipRows is a static one time offset. - * - * skipImages and depth are in multiples of image size. - * - * rowlenght is the actual repeating offset - * to go from line n to line n+1 at the same x-axis position. - */ - return - ( skipImages + depth - 1 ) * imageHeight * rowLengthInBytes + // whole images - ( skipRows + height - 1 ) * rowLengthInBytes + // lines with padding - ( skipPixels + width ) * bytesPerElement; // last line -} + public final GL3bc getGL3bc() throws GLException { + if(!isGL3bc()) { + throw new GLException("Not a GL3bc implementation"); + } + return this; + } + + public final GL3 getGL3() throws GLException { + if(!isGL3()) { + throw new GLException("Not a GL3 implementation"); + } + return this; + } + + public final GL2 getGL2() throws GLException { + if(!isGL2()) { + throw new GLException("Not a GL2 implementation"); + } + return this; + } + + public final GL2ES1 getGL2ES1() throws GLException { + if(!isGL2ES1()) { + throw new GLException("Not a GL2ES1 implementation"); + } + return this; + } + + public final GL2ES2 getGL2ES2() throws GLException { + if(!isGL2ES2()) { + throw new GLException("Not a GL2ES2 implementation"); + } + return this; + } + + public final GL2GL3 getGL2GL3() throws GLException { + if(!isGL2GL3()) { + throw new GLException("Not a GL2GL3 implementation"); + } + return this; + } + + public final boolean isGLES1() { + return false; + } + + public final boolean isGLES2() { + return false; + } + + public final boolean isGLES() { + return false; + } + + public final GLES1 getGLES1() throws GLException { + throw new GLException("Not a GLES1 implementation"); + } + + public final GLES2 getGLES2() throws GLException { + throw new GLException("Not a GLES2 implementation"); + } diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl2.java b/make/config/jogl/gl-impl-CustomJavaCode-gl2.java deleted file mode 100644 index 0658b8a01..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl2.java +++ /dev/null @@ -1,514 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - - -public GL2Impl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.glProfile = glp; -} - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return false; -} - -public final boolean isGL3() { - return false; -} - -public final boolean isGL2() { - return true; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return true; -} - -public final boolean isGL2ES2() { - return true; -} - -public final boolean isGL2GL3() { - return true; -} - -public final boolean hasGLSL() { - return true; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - throw new GLException("Not a GL3bc implementation"); -} - -public final GL3 getGL3() throws GLException { - throw new GLException("Not a GL3 implementation"); -} - -public final GL2 getGL2() throws GLException { - return this; -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - return this; -} - -public final GL2ES2 getGL2ES2() throws GLException { - return this; -} - -public final GL2GL3 getGL2GL3() throws GLException { - return this; -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -/** - * Provides platform-independent access to the wglAllocateMemoryNV / - * glXAllocateMemoryNV extension. - */ -public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { - return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); -} - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_COLOR_INDEX: - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - case GL_BGR: - elements = 3; - break; - case GL_RGBA: - case GL_BGRA: - case GL_ABGR_EXT: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BITMAP: - if (format == GL_COLOR_INDEX) { - return (d * (h * ((w+7)/8))); - } else { - return 0; - } - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - esize = 1; - elements = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - esize = 4; - elements = 1; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveARBPixelBufferObject; -private boolean haveEXTPixelBufferObject; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); - haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkPackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -private boolean checkPackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -public boolean glIsPBOPackEnabled() { - return checkPackPBOEnabled(false); -} - -public boolean glIsPBOUnpackEnabled() { - return checkUnpackPBOEnabled(false); -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL2ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - - public void glVertexPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glColorPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - - } - public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.getComponentNumber()!=3) { - throw new GLException("Only 3 components per normal allowed"); - } - if(array.isVBO()) { - glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glTexCoordPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java b/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java deleted file mode 100644 index 54c7bd92b..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java +++ /dev/null @@ -1,455 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - -public GL2ES12Impl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.isGL2ES2 = glp.isGL2ES2(); - this.glProfile = glp; -} - -private boolean isGL2ES2; - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return false; -} - -public final boolean isGL3() { - return false; -} - -public final boolean isGL2() { - return false; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return !isGL2ES2; -} - -public final boolean isGL2ES2() { - return isGL2ES2; -} - -public final boolean isGL2GL3() { - return false; -} - -public final boolean hasGLSL() { - return isGL2ES2; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - throw new GLException("Not a GL3bc implementation"); -} - -public final GL3 getGL3() throws GLException { - throw new GLException("Not a GL3 implementation"); -} - -public final GL2 getGL2() throws GLException { - throw new GLException("Not a GL2 implementation"); -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - if (isGL2ES1()) { - return this; - } - throw new GLException("Not a GL2ES1 implementation"); -} - -public final GL2ES2 getGL2ES2() throws GLException { - if (isGL2ES2()) { - return this; - } - throw new GLException("Not a GL2ES2 implementation"); -} - -public final GL2GL3 getGL2GL3() throws GLException { - throw new GLException("Not a GL2GL3 implementation"); -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - elements = 3; - break; - case GL_RGBA: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_5_5_5_1: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return true; -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return false; -} - -private boolean checkPackPBODisabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return true; -} - -private boolean checkPackPBOEnabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return false; -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - - public void glVertexPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glColorPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - - } - public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.getComponentNumber()!=3) { - throw new GLException("Only 3 components per normal allowed"); - } - if(array.isVBO()) { - glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glTexCoordPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl3.java b/make/config/jogl/gl-impl-CustomJavaCode-gl3.java deleted file mode 100644 index cff0b0f94..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl3.java +++ /dev/null @@ -1,468 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - -public GL3Impl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.glProfile = glp; -} - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return false; -} - -public final boolean isGL3() { - return true; -} - -public final boolean isGL2() { - return false; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return false; -} - -public final boolean isGL2ES2() { - return true; -} - -public final boolean isGL2GL3() { - return true; -} - -public final boolean hasGLSL() { - return true; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - throw new GLException("Not a GL3bc implementation"); -} - -public final GL3 getGL3() throws GLException { - return this; -} - -public final GL2 getGL2() throws GLException { - throw new GLException("Not a GL2 implementation"); -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - throw new GLException("Not a GLES2ES1 implementation"); -} - -public final GL2ES2 getGL2ES2() throws GLException { - return this; -} - -public final GL2GL3 getGL2GL3() throws GLException { - return this; -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -/** - * Provides platform-independent access to the wglAllocateMemoryNV / - * glXAllocateMemoryNV extension. - */ -public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { - return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); -} - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - case GL_BGR: - elements = 3; - break; - case GL_RGBA: - case GL_BGRA: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - esize = 1; - elements = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - esize = 4; - elements = 1; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveARBPixelBufferObject; -private boolean haveEXTPixelBufferObject; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); - haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkPackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -private boolean checkPackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -public boolean glIsPBOPackEnabled() { - return checkPackPBOEnabled(false); -} - -public boolean glIsPBOUnpackEnabled() { - return checkUnpackPBOEnabled(false); -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java deleted file mode 100644 index 2f804a218..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java +++ /dev/null @@ -1,514 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - - -public GL3bcImpl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.glProfile = glp; -} - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return true; -} - -public final boolean isGL3() { - return true; -} - -public final boolean isGL2() { - return true; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return true; -} - -public final boolean isGL2ES2() { - return true; -} - -public final boolean isGL2GL3() { - return true; -} - -public final boolean hasGLSL() { - return true; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - return this; -} - -public final GL3 getGL3() throws GLException { - return this; -} - -public final GL2 getGL2() throws GLException { - return this; -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - return this; -} - -public final GL2ES2 getGL2ES2() throws GLException { - return this; -} - -public final GL2GL3 getGL2GL3() throws GLException { - return this; -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -/** - * Provides platform-independent access to the wglAllocateMemoryNV / - * glXAllocateMemoryNV extension. - */ -public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { - return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); -} - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_COLOR_INDEX: - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - case GL_BGR: - elements = 3; - break; - case GL_RGBA: - case GL_BGRA: - case GL_ABGR_EXT: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BITMAP: - if (format == GL_COLOR_INDEX) { - return (d * (h * ((w+7)/8))); - } else { - return 0; - } - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - esize = 1; - elements = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - esize = 4; - elements = 1; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveARBPixelBufferObject; -private boolean haveEXTPixelBufferObject; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); - haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkPackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -private boolean checkPackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -public boolean glIsPBOPackEnabled() { - return checkPackPBOEnabled(false); -} - -public boolean glIsPBOUnpackEnabled() { - return checkUnpackPBOEnabled(false); -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL3bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - - public void glVertexPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glColorPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - - } - public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.getComponentNumber()!=3) { - throw new GLException("Only 3 components per normal allowed"); - } - if(array.isVBO()) { - glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glTexCoordPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl4.java b/make/config/jogl/gl-impl-CustomJavaCode-gl4.java new file mode 100644 index 000000000..a2c70eeee --- /dev/null +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl4.java @@ -0,0 +1,339 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + +public GL3Impl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.glProfile = glp; +} + +/** + * Provides platform-independent access to the wglAllocateMemoryNV / + * glXAllocateMemoryNV extension. + */ +public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + case GL_BGR: + elements = 3; + break; + case GL_RGBA: + case GL_BGRA: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveARBPixelBufferObject; +private boolean haveEXTPixelBufferObject; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); + haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkPackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +private boolean checkPackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +public boolean glIsPBOPackEnabled() { + return checkPackPBOEnabled(false); +} + +public boolean glIsPBOUnpackEnabled() { + return checkUnpackPBOEnabled(false); +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java new file mode 100644 index 000000000..bceb12fe5 --- /dev/null +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java @@ -0,0 +1,385 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + + +public GL4bcImpl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.glProfile = glp; +} + +/** + * Provides platform-independent access to the wglAllocateMemoryNV / + * glXAllocateMemoryNV extension. + */ +public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + case GL_BGR: + elements = 3; + break; + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (d * (h * ((w+7)/8))); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveARBPixelBufferObject; +private boolean haveEXTPixelBufferObject; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); + haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkPackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +private boolean checkPackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +public boolean glIsPBOPackEnabled() { + return checkPackPBOEnabled(false); +} + +public boolean glIsPBOUnpackEnabled() { + return checkUnpackPBOEnabled(false); +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + + public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + + } + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java index 6fb8a32ef..b4efac8a1 100755 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java @@ -6,10 +6,6 @@ public GLES1Impl(GLProfile glp, GLContextImpl context) { this.glProfile = glp; } -public final boolean isGL() { - return true; -} - public final boolean isGL4bc() { return false; } @@ -58,10 +54,6 @@ public final boolean hasGLSL() { return false; } -public final GL getGL() throws GLException { - return this; -} - public final GL4bc getGL4bc() throws GLException { throw new GLException("Not a GL4bc implementation"); } @@ -102,39 +94,6 @@ public final GL2GL3 getGL2GL3() throws GLException { throw new GLException("Not a GL2GL3 implementation"); } -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - // // Helpers for ensuring the correct amount of texture data // diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java index 8204bd1ae..bb8ddb7ef 100755 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java @@ -10,10 +10,6 @@ public GLES2Impl(GLProfile glp, GLContextImpl context) { this.glProfile = glp; } -public final boolean isGL() { - return true; -} - public final boolean isGL4bc() { return false; } @@ -62,10 +58,6 @@ public final boolean hasGLSL() { return true; } -public final GL getGL() throws GLException { - return this; -} - public final GL4bc getGL4bc() throws GLException { throw new GLException("Not a GL4bc implementation"); } @@ -106,39 +98,6 @@ public final GL2GL3 getGL2GL3() throws GLException { throw new GLException("Not a GL2GL3 implementation"); } -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - // // Helpers for ensuring the correct amount of texture data // diff --git a/make/config/jogl/gl3-common.cfg b/make/config/jogl/gl3-common.cfg index fac8323bb..c2cc2968e 100644 --- a/make/config/jogl/gl3-common.cfg +++ b/make/config/jogl/gl3-common.cfg @@ -16,6 +16,9 @@ RenameExtensionIntoCore GL_ARB_geometry_shader4 RenameExtensionIntoCore GL_ARB_sync # <<< OpenGL 3.2 +# >>> OpenGL 3.3 +# <<< OpenGL 3.3 + # Ignore GL functions that deal with explicit pointer values in such a # way that we cannot implement the functionality in Java Ignore glMultiDrawElementsBaseVertex diff --git a/make/config/jogl/gl3-desktop-tracker.cfg b/make/config/jogl/gl3-desktop-tracker.cfg deleted file mode 100644 index 4b9a7edb7..000000000 --- a/make/config/jogl/gl3-desktop-tracker.cfg +++ /dev/null @@ -1,38 +0,0 @@ - -# Track server-side object creation and deletion when necessary -# Note that this is only necessary when the Java 2D / JOGL bridge is active, -# so will never be needed for the embedded OpenGL variants -JavaEpilogue glGenBuffers if (tracker != null) tracker.addBuffers({0}, {1}); -JavaEpilogue glGenFencesAPPLE if (tracker != null) tracker.addFencesAPPLE({0}, {1}); -JavaEpilogue glGenFencesNV if (tracker != null) tracker.addFencesNV({0}, {1}); -JavaEpilogue glGenFragmentShadersATI if (tracker != null) tracker.addFragmentShadersATI(_res, {0}); -JavaEpilogue glGenFramebuffersEXT if (tracker != null) tracker.addFramebuffersEXT({0}, {1}); -JavaEpilogue glGenLists if (tracker != null) tracker.addLists(_res, {0}); -JavaEpilogue glGenOcclusionQueriesNV if (tracker != null) tracker.addOcclusionQueriesNV({0}, {1}); -JavaEpilogue glCreateProgram if (tracker != null) tracker.addProgramObject(_res); -JavaEpilogue glGenPrograms if (tracker != null) tracker.addPrograms({0}, {1}); -JavaEpilogue glGenQueries if (tracker != null) tracker.addQueries({0}, {1}); -JavaEpilogue glGenRenderbuffersEXT if (tracker != null) tracker.addRenderbuffersEXT({0}, {1}); -JavaEpilogue glCreateShader if (tracker != null) tracker.addShaderObject(_res); -JavaEpilogue glGenTextures if (tracker != null) tracker.addTextures({0}, {1}); -JavaEpilogue glGenVertexArraysAPPLE if (tracker != null) tracker.addVertexArraysAPPLE({0}, {1}); -JavaEpilogue glGenVertexShadersEXT if (tracker != null) tracker.addVertexShadersEXT(_res, {0}); - -JavaEpilogue glDeleteBuffers if (tracker != null) tracker.removeBuffers({0}, {1}); -JavaEpilogue glDeleteFencesAPPLE if (tracker != null) tracker.removeFencesAPPLE({0}, {1}); -JavaEpilogue glDeleteFencesNV if (tracker != null) tracker.removeFencesNV({0}, {1}); -JavaEpilogue glDeleteFragmentShaderATI if (tracker != null) tracker.removeFragmentShaderATI({0}); -JavaEpilogue glDeleteFramebuffersEXT if (tracker != null) tracker.removeFramebuffersEXT({0}, {1}); -JavaEpilogue glDeleteLists if (tracker != null) tracker.removeLists({0}, {1}); -JavaEpilogue glDeleteOcclusionQueriesNV if (tracker != null) tracker.removeOcclusionQueriesNV({0}, {1}); -JavaEpilogue glDeleteProgram if (tracker != null) tracker.removeProgramObject({0}); -JavaEpilogue glDeleteObject if (tracker != null) tracker.removeProgramOrShaderObject({0}); -JavaEpilogue glDeletePrograms if (tracker != null) tracker.removePrograms({0}, {1}); -JavaEpilogue glDeleteProgramsNV if (tracker != null) tracker.removeProgramsNV({0}, {1}); -JavaEpilogue glDeleteQueries if (tracker != null) tracker.removeQueries({0}, {1}); -JavaEpilogue glDeleteRenderbuffersEXT if (tracker != null) tracker.removeRenderbuffersEXT({0}, {1}); -JavaEpilogue glDeleteShader if (tracker != null) tracker.removeShaderObject({0}); -JavaEpilogue glDeleteTextures if (tracker != null) tracker.removeTextures({0}, {1}); -JavaEpilogue glDeleteVertexArraysAPPLE if (tracker != null) tracker.removeVertexArraysAPPLE({0}, {1}); -JavaEpilogue glDeleteVertexShaderEXT if (tracker != null) tracker.removeVertexShaderEXT({0}); - diff --git a/make/config/jogl/gl4-common.cfg b/make/config/jogl/gl4-common.cfg new file mode 100644 index 000000000..2c119da30 --- /dev/null +++ b/make/config/jogl/gl4-common.cfg @@ -0,0 +1,5 @@ + +# >>> OpenGL 4.0 +# <<< OpenGL 4.0 + + diff --git a/make/config/jogl/gl4-desktop-tracker.cfg b/make/config/jogl/gl4-desktop-tracker.cfg new file mode 100644 index 000000000..4b9a7edb7 --- /dev/null +++ b/make/config/jogl/gl4-desktop-tracker.cfg @@ -0,0 +1,38 @@ + +# Track server-side object creation and deletion when necessary +# Note that this is only necessary when the Java 2D / JOGL bridge is active, +# so will never be needed for the embedded OpenGL variants +JavaEpilogue glGenBuffers if (tracker != null) tracker.addBuffers({0}, {1}); +JavaEpilogue glGenFencesAPPLE if (tracker != null) tracker.addFencesAPPLE({0}, {1}); +JavaEpilogue glGenFencesNV if (tracker != null) tracker.addFencesNV({0}, {1}); +JavaEpilogue glGenFragmentShadersATI if (tracker != null) tracker.addFragmentShadersATI(_res, {0}); +JavaEpilogue glGenFramebuffersEXT if (tracker != null) tracker.addFramebuffersEXT({0}, {1}); +JavaEpilogue glGenLists if (tracker != null) tracker.addLists(_res, {0}); +JavaEpilogue glGenOcclusionQueriesNV if (tracker != null) tracker.addOcclusionQueriesNV({0}, {1}); +JavaEpilogue glCreateProgram if (tracker != null) tracker.addProgramObject(_res); +JavaEpilogue glGenPrograms if (tracker != null) tracker.addPrograms({0}, {1}); +JavaEpilogue glGenQueries if (tracker != null) tracker.addQueries({0}, {1}); +JavaEpilogue glGenRenderbuffersEXT if (tracker != null) tracker.addRenderbuffersEXT({0}, {1}); +JavaEpilogue glCreateShader if (tracker != null) tracker.addShaderObject(_res); +JavaEpilogue glGenTextures if (tracker != null) tracker.addTextures({0}, {1}); +JavaEpilogue glGenVertexArraysAPPLE if (tracker != null) tracker.addVertexArraysAPPLE({0}, {1}); +JavaEpilogue glGenVertexShadersEXT if (tracker != null) tracker.addVertexShadersEXT(_res, {0}); + +JavaEpilogue glDeleteBuffers if (tracker != null) tracker.removeBuffers({0}, {1}); +JavaEpilogue glDeleteFencesAPPLE if (tracker != null) tracker.removeFencesAPPLE({0}, {1}); +JavaEpilogue glDeleteFencesNV if (tracker != null) tracker.removeFencesNV({0}, {1}); +JavaEpilogue glDeleteFragmentShaderATI if (tracker != null) tracker.removeFragmentShaderATI({0}); +JavaEpilogue glDeleteFramebuffersEXT if (tracker != null) tracker.removeFramebuffersEXT({0}, {1}); +JavaEpilogue glDeleteLists if (tracker != null) tracker.removeLists({0}, {1}); +JavaEpilogue glDeleteOcclusionQueriesNV if (tracker != null) tracker.removeOcclusionQueriesNV({0}, {1}); +JavaEpilogue glDeleteProgram if (tracker != null) tracker.removeProgramObject({0}); +JavaEpilogue glDeleteObject if (tracker != null) tracker.removeProgramOrShaderObject({0}); +JavaEpilogue glDeletePrograms if (tracker != null) tracker.removePrograms({0}, {1}); +JavaEpilogue glDeleteProgramsNV if (tracker != null) tracker.removeProgramsNV({0}, {1}); +JavaEpilogue glDeleteQueries if (tracker != null) tracker.removeQueries({0}, {1}); +JavaEpilogue glDeleteRenderbuffersEXT if (tracker != null) tracker.removeRenderbuffersEXT({0}, {1}); +JavaEpilogue glDeleteShader if (tracker != null) tracker.removeShaderObject({0}); +JavaEpilogue glDeleteTextures if (tracker != null) tracker.removeTextures({0}, {1}); +JavaEpilogue glDeleteVertexArraysAPPLE if (tracker != null) tracker.removeVertexArraysAPPLE({0}, {1}); +JavaEpilogue glDeleteVertexShaderEXT if (tracker != null) tracker.removeVertexShaderEXT({0}); + diff --git a/make/config/jogl/glu-CustomJavaCode-base.java b/make/config/jogl/glu-CustomJavaCode-base.java index aeb4f2ef9..480f5d117 100755 --- a/make/config/jogl/glu-CustomJavaCode-base.java +++ b/make/config/jogl/glu-CustomJavaCode-base.java @@ -169,7 +169,7 @@ protected static boolean checkedGLUtessellatorImpl = false; protected static final void validateGLUtessellatorImpl() { if(!checkedGLUtessellatorImpl) { - availableGLUtessellatorImpl = NWReflection.isClassAvailable("com.jogamp.opengl.impl.glu.tessellator.GLUtessellatorImpl"); + availableGLUtessellatorImpl = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.glu.tessellator.GLUtessellatorImpl"); checkedGLUtessellatorImpl = true; } if(!availableGLUtessellatorImpl) { @@ -1220,7 +1220,7 @@ protected static final void validateGLUquadricImpl() { if(!checkedGLUquadricImpl) { synchronized (syncObject) { if(!checkedGLUquadricImpl) { - availableGLUquadricImpl = NWReflection.isClassAvailable("com.jogamp.opengl.impl.glu.GLUquadricImpl"); + availableGLUquadricImpl = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.glu.GLUquadricImpl"); checkedGLUquadricImpl = true; } } diff --git a/make/config/jogl/glu-CustomJavaCode-gl2es1.java b/make/config/jogl/glu-CustomJavaCode-gl2es1.java index b5cb3b2f8..f3b4322d9 100755 --- a/make/config/jogl/glu-CustomJavaCode-gl2es1.java +++ b/make/config/jogl/glu-CustomJavaCode-gl2es1.java @@ -86,7 +86,7 @@ protected static boolean checkedMipmap = false; protected static final void validateMipmap() { if(!checkedMipmap) { - availableMipmap = NWReflection.isClassAvailable("com.jogamp.opengl.impl.glu.mipmap.Mipmap"); + availableMipmap = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.glu.mipmap.Mipmap"); checkedMipmap = true; } if(!availableMipmap) { diff --git a/make/config/jogl/glu-common.cfg b/make/config/jogl/glu-common.cfg index 937ca0348..f5fc7c1b3 100644 --- a/make/config/jogl/glu-common.cfg +++ b/make/config/jogl/glu-common.cfg @@ -14,7 +14,7 @@ Import javax.media.opengl.glu.* Import com.jogamp.opengl.impl.* Import com.jogamp.opengl.impl.glu.* Import com.jogamp.opengl.impl.glu.tessellator.GLUtessellatorImpl -Import com.jogamp.nativewindow.impl.NWReflection +Import com.jogamp.common.util.ReflectionUtil # Raise GLException instead of RuntimeException in glue code RuntimeExceptionType GLException diff --git a/make/config/jogl/obsolete/gl-gl2es12.cfg b/make/config/jogl/obsolete/gl-gl2es12.cfg new file mode 100644 index 000000000..3942b1419 --- /dev/null +++ b/make/config/jogl/obsolete/gl-gl2es12.cfg @@ -0,0 +1,90 @@ +# This .cfg file is used to generate the GL interface and implementing class. +JavaOutputDir gensrc/classes +NativeOutputDir gensrc/native/jogl/gl2es12 + +ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL.java +ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES1.java +ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/GLBase.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java + +Style ImplOnly +ImplPackage com.jogamp.opengl.impl.gl2es12 +ImplJavaClass GL2ES12Impl +Implements GL2ES12Impl GLBase +Implements GL2ES12Impl GL +Implements GL2ES12Impl GL2ES1 +Implements GL2ES12Impl GL2ES2 + +Include gl-common.cfg +Include gl-common-extensions.cfg +Include gl-desktop.cfg + +# Because we're manually implementing glMapBuffer but only producing +# the implementing class, GlueGen doesn't notice that it has to emit a +# proc address table entry for it. Force it to here. +ForceProcAddressGen glMapBuffer + +# Force all of the methods to be emitted using dynamic linking so we +# don't need to link against any emulation library on the desktop or +# depend on the presence of an import library for a particular device +ForceProcAddressGen __ALL__ + +# Also force the calling conventions of the locally generated function +# pointer typedefs for these routines to APIENTRY +LocalProcAddressCallingConvention __ALL__ APIENTRY + +EmitProcAddressTable true +ProcAddressTableClassName GL2ES12ProcAddressTable +GetProcAddressTableExpr ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable()) + +# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums +TagNativeBinding true + +# There seem to be some errors in the glue code generation where we are not ignoring +# enough routines from desktop GL in GL2ES12Impl. For now manually ignore those which +# we know shouldn't be in there +Ignore glGetTexImage +Ignore glPixelStoref + +# Add PixelStorei StateTracker +# +# Add input validation to glPixelStorei to make sure that, even if we +# are running on top of desktop OpenGL, parameters not exposed in +# OpenGL ES can not be changed +CustomJavaCode GL2ES12Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. + +JavaPrologue glPixelStorei if (pname != GL_PACK_ALIGNMENT && pname != GL_UNPACK_ALIGNMENT) { +JavaPrologue glPixelStorei throw new GLException("Unsupported pixel store parameter name 0x" + Integer.toHexString(pname)); +JavaPrologue glPixelStorei } +JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); + +JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } + +CustomJavaCode GL2ES12Impl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL2ES12Impl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL2ES12Impl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL2ES12Impl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL2ES12Impl public void glClearDepthf(float depth) { +CustomJavaCode GL2ES12Impl glClearDepth((double)depth); } + +CustomJavaCode GL2ES12Impl public void glDepthRangef(float zNear, float zFar) { +CustomJavaCode GL2ES12Impl glDepthRange((double)zNear, (double)zFar); } + +Include gl-headers.cfg +Include ../intptr.cfg + +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-common.java +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2es12.java +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-embedded.java +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2_es2.java +IncludeAs CustomCCode gl-impl-CustomCCode-gl2es12.c + +Import javax.media.opengl.GLES1 +Import javax.media.opengl.GLES2 +Import com.jogamp.opengl.impl.InternalBufferUtil +Import java.io.PrintStream diff --git a/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c new file mode 100644 index 000000000..91fd0078b --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2.GL2Impl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl2_GL2Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2.GL2Impl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl2_GL2Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c new file mode 100644 index 000000000..07b821802 --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c new file mode 100644 index 000000000..f540a7d4a --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl3.GL3Impl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl3_GL3Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl3.GL3Impl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl3_GL3Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java new file mode 100644 index 000000000..a1a6917df --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java @@ -0,0 +1,385 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + + +public GL2Impl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.glProfile = glp; +} + +/** + * Provides platform-independent access to the wglAllocateMemoryNV / + * glXAllocateMemoryNV extension. + */ +public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + case GL_BGR: + elements = 3; + break; + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (d * (h * ((w+7)/8))); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveARBPixelBufferObject; +private boolean haveEXTPixelBufferObject; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); + haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkPackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +private boolean checkPackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +public boolean glIsPBOPackEnabled() { + return checkPackPBOEnabled(false); +} + +public boolean glIsPBOUnpackEnabled() { + return checkUnpackPBOEnabled(false); +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL2ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + + public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + + } + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + diff --git a/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java new file mode 100644 index 000000000..aed442da3 --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java @@ -0,0 +1,353 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + +public GL2ES12Impl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.isGL2ES2 = glp.isGL2ES2(); + this.glProfile = glp; +} + +private boolean isGL2ES2; + +public boolean isFunctionAvailable(String glFunctionName) { + return _context.isFunctionAvailable(glFunctionName); +} + +public boolean isExtensionAvailable(String glExtensionName) { + return _context.isExtensionAvailable(glExtensionName); +} + +public Object getExtension(String extensionName) { + // At this point we don't expose any extensions using this mechanism + return null; +} + +/** Returns the context this GL object is associated with for better + error checking by DebugGL. */ +public GLContext getContext() { + return _context; +} + +private GLContextImpl _context; + +public void setSwapInterval(int interval) { + _context.setSwapInterval(interval); +} + +public int getSwapInterval() { + return _context.getSwapInterval(); +} + +public Object getPlatformGLExtensions() { + return _context.getPlatformGLExtensions(); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + elements = 3; + break; + case GL_RGBA: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_5_5_5_1: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return true; +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return false; +} + +private boolean checkPackPBODisabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return true; +} + +private boolean checkPackPBOEnabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return false; +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + + public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + + } + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + + diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index 57f37bee7..44bb1e8d0 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -26,9 +26,8 @@ public static native long DefaultVisualID(long display, int screen); - /** public static native long CreateDummyWindow(long display, int screen_index, long visualID); - public static native void DestroyDummyWindow(long display, long window); */ + public static native void DestroyDummyWindow(long display, long window); public static native long dlopen(String name); public static native long dlsym(String name); diff --git a/make/stub_includes/opengl/gl4.c b/make/stub_includes/opengl/gl4.c index cf8a709f7..5e9d87ccd 100644 --- a/make/stub_includes/opengl/gl4.c +++ b/make/stub_includes/opengl/gl4.c @@ -1,11 +1,11 @@ #define GLAPI -// Define GL4_PROTOTYPES so that the OpenGL prototypes in +// Define GL3_PROTOTYPES so that the OpenGL prototypes in // "gl3.h" are parsed. -#define GL4_PROTOTYPES +#define GL3_PROTOTYPES -// Define GL_GL4EXT_PROTOTYPES so that the OpenGL extension prototypes in +// Define GL_GL3EXT_PROTOTYPES so that the OpenGL extension prototypes in // "gl3ext.h" are parsed. -#define GL_GL4EXT_PROTOTYPES +#define GL_GL3EXT_PROTOTYPES -#include +#include diff --git a/make/stub_includes/opengl/gl4bc.c b/make/stub_includes/opengl/gl4bc.c new file mode 100644 index 000000000..262e005f7 --- /dev/null +++ b/make/stub_includes/opengl/gl4bc.c @@ -0,0 +1,18 @@ +#define GLAPI + +// Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +// "glext.h" are parsed. +#define GL_GLEXT_PROTOTYPES + +#include + +// Define GL3_PROTOTYPES so that the OpenGL prototypes in +// "gl3.h" are parsed. +#define GL3_PROTOTYPES + +// Define GL_GL3EXT_PROTOTYPES so that the OpenGL extension prototypes in +// "gl3ext.h" are parsed. +#define GL_GL3EXT_PROTOTYPES + +#include + diff --git a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java index 082f006e8..1ed0396a9 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java @@ -174,12 +174,12 @@ public final class ExtensionAvailabilityCache { major[0] = 3; minor[0] = 0; } - while (GLProfile.isValidGLVersion(major[0], minor[0])) { + while (GLContext.isValidGLVersion(major[0], minor[0])) { availableExtensionCache.add("GL_VERSION_" + major[0] + "_" + minor[0]); if (DEBUG) { System.err.println("ExtensionAvailabilityCache: Added GL_VERSION_" + major[0] + "_" + minor[0] + " to known extensions"); } - if(!GLProfile.decrementGLVersion(major, minor)) break; + if(!GLContext.decrementGLVersion(major, minor)) break; } // put a dummy var in here so that the cache is no longer empty even if diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java index 8c5890d1e..3abb69a7f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java @@ -45,9 +45,10 @@ import java.util.*; import javax.media.opengl.*; import javax.media.nativewindow.*; -import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.gluegen.runtime.*; import com.jogamp.gluegen.runtime.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.ReflectionUtil; public abstract class GLContextImpl extends GLContext { protected GLContextLock lock = new GLContextLock(); @@ -123,108 +124,137 @@ public abstract class GLContextImpl extends GLContext { return (GLDrawableImpl) getGLDrawable(); } - /** - * Platform dependent but harmonized implementation of the ARB_create_context - * mechanism to create a context.
- * The implementation shall verify this context, ie issue a - * MakeCurrent call if necessary.
- * - * @param share the shared context or null - * @param direct flag if direct is requested - * @param ctxOptionFlags ARB_create_context related, see references below - * @param major major number - * @param minor minor number - * @return the valid context if successfull, or null - * - * @see #CTX_PROFILE_COMPAT - * @see #CTX_OPTION_FORWARD - * @see #CTX_OPTION_DEBUG - */ - protected abstract long createContextARBImpl(long share, boolean direct, int ctxOptionFlags, - int major, int minor); + public final GL getGL() { + return gl; + } - private long createContextARB(long share, boolean direct, int ctxOptionFlags, - int majorMax, int minorMax, - int majorMin, int minorMin, - int major[], int minor[]) { - major[0]=majorMax; - minor[0]=minorMax; - long _context=0; + public GL setGL(GL gl) { + if(DEBUG) { + String sgl1 = (null!=this.gl)?this.gl.getClass().toString()+", "+this.gl.toString():new String(""); + String sgl2 = (null!=gl)?gl.getClass().toString()+", "+gl.toString():new String(""); + Exception e = new Exception("setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); + e.printStackTrace(); + } + this.gl = gl; + return gl; + } - while ( 0==_context && - GLProfile.isValidGLVersion(major[0], minor[0]) && - ( major[0]>majorMin || major[0]==majorMin && minor[0] >=minorMin ) ) { + // This is only needed for Mac OS X on-screen contexts + protected void update() throws GLException { } - _context = createContextARBImpl(share, direct, ctxOptionFlags, major[0], minor[0]); + public boolean isSynchronized() { + return !lock.getFailFastMode(); + } - if(0==_context) { - if(!GLProfile.decrementGLVersion(major, minor)) break; - } + public void setSynchronized(boolean isSynchronized) { + lock.setFailFastMode(!isSynchronized); + } + + public abstract Object getPlatformGLExtensions(); + + public void release() throws GLException { + if (!lock.isHeld()) { + throw new GLException("Context not current on current thread"); + } + setCurrent(null); + try { + releaseImpl(); + } finally { + lock.unlock(); } - return _context; } - /** - * Platform independent part of using the ARB_create_context - * mechanism to create a context.
- */ - protected long createContextARB(long share, boolean direct, - int major[], int minor[], int ctp[]) - { - AbstractGraphicsConfiguration config = drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); - GLProfile glp = glCaps.getGLProfile(); - long _context = 0; + protected abstract void releaseImpl() throws GLException; - ctp[0] = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE | CTX_OPTION_ANY; // default - boolean isBackwardCompatibility = glp.isGL2() || glp.isGL3bc() || glp.isGL4bc() ; - int majorMin, minorMin; - int majorMax, minorMax; - if( glp.isGL4() ) { - // ?? majorMax=GLProfile.getMaxMajor(); minorMax=GLProfile.getMaxMinor(majorMax); - majorMax=4; minorMax=GLProfile.getMaxMinor(majorMax); - majorMin=4; minorMin=0; - } else if( glp.isGL3() ) { - majorMax=3; minorMax=GLProfile.getMaxMinor(majorMax); - majorMin=3; minorMin=1; - } else /* if( glp.isGL2() ) */ { - majorMax=3; minorMax=0; - majorMin=1; minorMin=1; // our minimum desktop OpenGL runtime requirements + public void destroy() { + if (lock.isHeld()) { + // release current context + release(); } - // Try the requested .. - if(isBackwardCompatibility) { - ctp[0] &= ~CTX_PROFILE_CORE ; - ctp[0] |= CTX_PROFILE_COMPAT ; - } - _context = createContextARB(share, direct, ctp[0], - /* max */ majorMax, minorMax, - /* min */ majorMin, minorMin, - /* res */ major, minor); - - if(0==_context && !isBackwardCompatibility) { - ctp[0] &= ~CTX_PROFILE_COMPAT ; - ctp[0] |= CTX_PROFILE_CORE ; - ctp[0] &= ~CTX_OPTION_ANY ; - ctp[0] |= CTX_OPTION_FORWARD ; - _context = createContextARB(share, direct, ctp[0], - /* max */ majorMax, minorMax, - /* min */ majorMin, minorMin, - /* res */ major, minor); - if(0==_context) { - // Try a compatible one .. even though not requested .. last resort - ctp[0] &= ~CTX_PROFILE_CORE ; - ctp[0] |= CTX_PROFILE_COMPAT ; - ctp[0] &= ~CTX_OPTION_FORWARD ; - ctp[0] |= CTX_OPTION_ANY ; - _context = createContextARB(share, direct, ctp[0], - /* max */ majorMax, minorMax, - /* min */ majorMin, minorMin, - /* res */ major, minor); - } + + // Must hold the lock around the destroy operation to make sure we + // don't destroy the context out from under another thread rendering to it + lock.lock(); + try { + /* FIXME: refactor dependence on Java 2D / JOGL bridge + if (tracker != null) { + // Don't need to do anything for contexts that haven't been + // created yet + if (isCreated()) { + // If we are tracking creation and destruction of server-side + // OpenGL objects, we must decrement the reference count of the + // GLObjectTracker upon context destruction. + // + // Note that we can only eagerly delete these server-side + // objects if there is another context currrent right now + // which shares textures and display lists with this one. + tracker.unref(deletedObjectTracker); + } + } + */ + + // Because we don't know how many other contexts we might be + // sharing with (and it seems too complicated to implement the + // GLObjectTracker's ref/unref scheme for the buffer-related + // optimizations), simply clear the cache of known buffers' sizes + // when we destroy contexts + if (bufferSizeTracker != null) { + bufferSizeTracker.clearCachedBufferSizes(); + } + + if (bufferStateTracker != null) { + bufferStateTracker.clearBufferObjectState(); + } + + if (glStateTracker != null) { + glStateTracker.clearStates(false); + } + + destroyImpl(); + } finally { + lock.unlock(); } - return _context; } + protected abstract void destroyImpl() throws GLException; + + //---------------------------------------------------------------------- + // + + /** + * MakeCurrent functionality, which also issues the creation of the actual OpenGL context.
+ * The complete callgraph for general OpenGL context creation is:
+ *
    + *
  • {@link #makeCurrent} GLContextImpl + *
  • {@link #makeCurrentImpl} Platform Implementation + *
  • {@link #create} Platform Implementation + *
  • If ARB_create_context is supported: + *
      + *
    • {@link #createContextARB} GLContextImpl + *
    • {@link #createContextARBImpl} Platform Implementation + *
    + *

+ * + * Once at startup, ie triggered by the singleton {@link GLDrawableImpl} constructor, + * calling {@link #createContextARB} will query all available OpenGL versions:
+ *
    + *
  • FOR ALL GL* DO: + *
      + *
    • {@link #createContextARBMapVersionsAvailable} + *
        + *
      • {@link #createContextARBVersions} + *
      + *
    • {@link #mapVersionAvailable} + *
    + *

+ * + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #mapVersionAvailable + * @see #destroyContextARBImpl + */ public int makeCurrent() throws GLException { // Support calls to makeCurrent() over and over again with // different contexts without releasing them @@ -287,103 +317,206 @@ public abstract class GLContextImpl extends GLContext { return res; } + /** + * @see #makeCurrent + */ protected abstract int makeCurrentImpl() throws GLException; - public void release() throws GLException { - if (!lock.isHeld()) { - throw new GLException("Context not current on current thread"); - } - setCurrent(null); - try { - releaseImpl(); - } finally { - lock.unlock(); - } - } + /** + * @see #makeCurrent + */ + protected abstract void create() throws GLException ; - protected abstract void releaseImpl() throws GLException; + /** + * Platform dependent but harmonized implementation of the ARB_create_context + * mechanism to create a context.
+ * + * This method is called from {@link #createContextARB}.
+ * + * The implementation shall verify this context with a + * MakeContextCurrent call.
+ * + * @param share the shared context or null + * @param direct flag if direct is requested + * @param ctxOptionFlags ARB_create_context related, see references below + * @param major major number + * @param minor minor number + * @return the valid context if successfull, or null + * + * @see #makeCurrent + * @see #CTX_PROFILE_COMPAT + * @see #CTX_OPTION_FORWARD + * @see #CTX_OPTION_DEBUG + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected abstract long createContextARBImpl(long share, boolean direct, int ctxOptionFlags, + int major, int minor); - public void destroy() { - if (lock.isHeld()) { - // release current context - release(); - } + /** + * Destroy the context created by {@link #createContextARBImpl}. + * + * @see #makeCurrent + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected abstract void destroyContextARBImpl(long context); - // Must hold the lock around the destroy operation to make sure we - // don't destroy the context out from under another thread rendering to it - lock.lock(); - try { - /* FIXME: refactor dependence on Java 2D / JOGL bridge - if (tracker != null) { - // Don't need to do anything for contexts that haven't been - // created yet - if (isCreated()) { - // If we are tracking creation and destruction of server-side - // OpenGL objects, we must decrement the reference count of the - // GLObjectTracker upon context destruction. - // - // Note that we can only eagerly delete these server-side - // objects if there is another context currrent right now - // which shares textures and display lists with this one. - tracker.unref(deletedObjectTracker); + /** + * Platform independent part of using the ARB_create_context + * mechanism to create a context.
+ * + * The implementation of {@link #create} shall use this protocol in case the platform supports ARB_create_context.
+ * + * This method may call {@link #createContextARBImpl} and {@link #destroyContextARBImpl}.
+ * + * This method will also query all available native OpenGL context when first called,
+ * usually the first call should happen with the shared GLContext of the DrawableFactory.
+ * + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected long createContextARB(long share, boolean direct, + int major[], int minor[], int ctp[]) + { + AbstractGraphicsConfiguration config = drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); + GLProfile glp = glCaps.getGLProfile(); + long _context = 0; + + if( !mappedVersionsAvailableSet ) { + synchronized(mappedVersionsAvailableLock) { + if( !mappedVersionsAvailableSet ) { + createContextARBMapVersionsAvailable(4, false /* compat */); // GL4 + createContextARBMapVersionsAvailable(4, true /* compat */); // GL4bc + createContextARBMapVersionsAvailable(3, false /* compat */); // GL3 + createContextARBMapVersionsAvailable(3, true /* compat */); // GL3bc + createContextARBMapVersionsAvailable(2, true /* compat */); // GL2 + mappedVersionsAvailableSet=true; + } } - } - */ - - // Because we don't know how many other contexts we might be - // sharing with (and it seems too complicated to implement the - // GLObjectTracker's ref/unref scheme for the buffer-related - // optimizations), simply clear the cache of known buffers' sizes - // when we destroy contexts - if (bufferSizeTracker != null) { - bufferSizeTracker.clearCachedBufferSizes(); - } + } - if (bufferStateTracker != null) { - bufferStateTracker.clearBufferObjectState(); - } - - if (glStateTracker != null) { - glStateTracker.clearStates(false); - } - - destroyImpl(); - } finally { - lock.unlock(); + int reqMajor; + if(glp.isGL4()) { + reqMajor=4; + } else if (glp.isGL3()) { + reqMajor=3; + } else /* if (glp.isGL2()) */ { + reqMajor=2; } + boolean compat = glp.isGL2(); // incl GL3bc and GL4bc + + int key = compose8bit(reqMajor, compat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0); + int val = mappedVersionsAvailable.get( key ); + long _ctx = 0; + if(val>0) { + int _major = getComposed8bit(val, 1); + int _minor = getComposed8bit(val, 2); + int _ctp = getComposed8bit(val, 3); + + _ctx = createContextARBImpl(share, direct, _ctp, _major, _minor); + if(0!=_ctx) { + setGLFunctionAvailability(true, _major, _minor, _ctp); + } + } + return _ctx; } - protected abstract void destroyImpl() throws GLException; + private void createContextARBMapVersionsAvailable(int reqMajor, boolean compat) + { + long _context; + int ctp = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE | CTX_OPTION_ANY; // default + if(compat) { + ctp &= ~CTX_PROFILE_CORE ; + ctp |= CTX_PROFILE_COMPAT ; + } - // This is only needed for Mac OS X on-screen contexts - protected void update() throws GLException { + // FIXME GL3GL4: + // To avoid OpenGL implementation bugs and raise compatibility + // within JOGL, we map to the proper GL version. + // This may change later when GL3 and GL4 drivers become more mature! + // Bug: To ensure GL profile compatibility within the JOGL application + // Bug: we always try to map against the highest GL version, + // Bug: so the use can always cast to a higher one + // Bug: int majorMax=GLContext.getMaxMajor(); + // Bug: int minorMax=GLContext.getMaxMinor(majorMax); + int majorMax, minorMax; + int majorMin, minorMin; + int major[] = new int[1]; + int minor[] = new int[1]; + if( 4 == reqMajor ) { + majorMax=4; minorMax=GLContext.getMaxMinor(majorMax); + majorMin=4; minorMin=0; + } else if( 3 == reqMajor ) { + majorMax=3; minorMax=GLContext.getMaxMinor(majorMax); + majorMin=3; minorMin=1; + } else /* if( glp.isGL2() ) */ { + majorMax=3; minorMax=0; + majorMin=1; minorMin=1; // our minimum desktop OpenGL runtime requirements + } + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + + if(0==_context && !compat) { + ctp &= ~CTX_PROFILE_COMPAT ; + ctp |= CTX_PROFILE_CORE ; + ctp &= ~CTX_OPTION_ANY ; + ctp |= CTX_OPTION_FORWARD ; + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + if(0==_context) { + // Try a compatible one .. even though not requested .. last resort + ctp &= ~CTX_PROFILE_CORE ; + ctp |= CTX_PROFILE_COMPAT ; + ctp &= ~CTX_OPTION_FORWARD ; + ctp |= CTX_OPTION_ANY ; + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + } + } + if(0!=_context) { + destroyContextARBImpl(_context); + mapVersionAvailable(reqMajor, compat, major[0], minor[0], ctp); + } } - public boolean isSynchronized() { - return !lock.getFailFastMode(); - } + private long createContextARBVersions(long share, boolean direct, int ctxOptionFlags, + int majorMax, int minorMax, + int majorMin, int minorMin, + int major[], int minor[]) { + major[0]=majorMax; + minor[0]=minorMax; + long _context=0; - public void setSynchronized(boolean isSynchronized) { - lock.setFailFastMode(!isSynchronized); - } + while ( 0==_context && + GLContext.isValidGLVersion(major[0], minor[0]) && + ( major[0]>majorMin || major[0]==majorMin && minor[0] >=minorMin ) ) { - public final GL getGL() { - return gl; - } + _context = createContextARBImpl(share, direct, ctxOptionFlags, major[0], minor[0]); - public GL setGL(GL gl) { - if(DEBUG) { - String sgl1 = (null!=this.gl)?this.gl.getClass().toString()+", "+this.gl.toString():new String(""); - String sgl2 = (null!=gl)?gl.getClass().toString()+", "+gl.toString():new String(""); - Exception e = new Exception("setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); - e.printStackTrace(); + if(0==_context) { + if(!GLContext.decrementGLVersion(major, minor)) break; + } } - this.gl = gl; - return gl; + return _context; } - public abstract Object getPlatformGLExtensions(); - //---------------------------------------------------------------------- // Managing the actual OpenGL version, usually figured at creation time. // As a last resort, the GL_VERSION string may be used .. @@ -395,7 +528,15 @@ public abstract class GLContextImpl extends GLContext { * Otherwise .. don't touch .. */ protected void setContextVersion(int major, int minor, int ctp) { + if (0==ctp) { + GLException e = new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); + throw e; + } if(major>0 || minor>0) { + if (!GLContext.isValidGLVersion(major, minor)) { + GLException e = new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); + throw e; + } ctxMajorVersion = major; ctxMinorVersion = minor; ctxOptions = ctp; @@ -408,6 +549,7 @@ public abstract class GLContextImpl extends GLContext { if(null==versionStr) { throw new GLException("GL_VERSION is NULL: "+this); } + ctxOptions = ctp; // Set version Version version = new Version(versionStr); @@ -460,7 +602,10 @@ public abstract class GLContextImpl extends GLContext { // private Object createInstance(GLProfile glp, String suffix, Class[] cstrArgTypes, Object[] cstrArgs) { - return NWReflection.createInstance(glp.getGLImplBaseClassName()+suffix, cstrArgTypes, cstrArgs); + try { + return ReflectionUtil.createInstance(glp.getGLImplBaseClassName()+suffix, cstrArgTypes, cstrArgs); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + return null; } /** Create the GL for this context. */ @@ -697,10 +842,6 @@ public abstract class GLContextImpl extends GLContext { return Thread.currentThread().getName(); } - public static String toHexString(long hex) { - return "0x" + Long.toHexString(hex); - } - //---------------------------------------------------------------------- // Helpers for buffer object optimizations diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java index 0cc10b35e..cdf5beb24 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java @@ -42,8 +42,8 @@ package com.jogamp.opengl.impl; import java.nio.*; import javax.media.nativewindow.*; import javax.media.opengl.*; +import com.jogamp.common.util.*; import com.jogamp.gluegen.runtime.*; -import com.jogamp.nativewindow.impl.NWReflection; import java.lang.reflect.*; /** Extends GLDrawableFactory with a few methods for handling @@ -183,6 +183,9 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected abstract NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height); + protected abstract GLDrawableImpl getSharedDrawable(); + protected abstract GLContextImpl getSharedContext(); + protected GLDrawableFactoryImpl() { super(); isValid = true; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java index 04114a445..2fef8fd80 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java @@ -88,7 +88,7 @@ public abstract class GLDrawableImpl implements GLDrawable { protected abstract void swapBuffersImpl(); public static String toHexString(long hex) { - return GLContextImpl.toHexString(hex); + return "0x" + Long.toHexString(hex); } public GLProfile getGLProfile() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java b/src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java new file mode 100644 index 000000000..7747b014b --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.common.jvm.JNILibLoaderBase; + +public class GLJNILibLoader extends JNILibLoaderBase { + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("newt", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadGLDesktop() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("jogl_desktop", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadES2() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("jogl_es2", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadES1() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("jogl_es1", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadCgImpl() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String[] preload = { "nativewindow", "cg", "cgGL" }; + loadLibrary("jogl_cg", preload, true); + return null; + } + }); + } + + private static final String[] nativeOSPreload = { "nativewindow_x11" }; +} + diff --git a/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java b/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java deleted file mode 100644 index b6024f240..000000000 --- a/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.opengl.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; -import com.jogamp.nativewindow.impl.NativeLibLoaderBase; - -public class NativeLibLoader extends NativeLibLoaderBase { - public static void loadNEWT() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("newt", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadGLDesktop() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_desktop", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadGLDesktopES12() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_gl2es12", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadES2() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_es2", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadES1() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_es1", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadCgImpl() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String[] preload = { "nativewindow", "cg", "cgGL" }; - loadLibrary("jogl_cg", preload, true); - return null; - } - }); - } - - private static final String[] nativeOSPreload = { "nativewindow_x11" }; -} - diff --git a/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java index b32ed51b6..1a68f38d4 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java @@ -37,8 +37,9 @@ import java.lang.reflect.InvocationTargetException; import java.security.AccessController; import java.security.PrivilegedAction; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import javax.media.nativewindow.NativeWindowFactory; -import com.jogamp.nativewindow.impl.NWReflection; import javax.media.opengl.GLException; /** Implementation of the {@link javax.media.opengl.Threading} class. */ @@ -71,8 +72,8 @@ public class ThreadingImpl { // while holding the AWT lock. The optimization of // makeCurrent / release calls isn't worth these stability // problems. - hasAWT = NWReflection.isClassAvailable("java.awt.Canvas") && - NWReflection.isClassAvailable("javax.media.opengl.awt.GLCanvas"); + hasAWT = ReflectionUtil.isClassAvailable("java.awt.Canvas") && + ReflectionUtil.isClassAvailable("javax.media.opengl.awt.GLCanvas"); String osType = NativeWindowFactory.getNativeWindowType(false); _isX11 = NativeWindowFactory.TYPE_X11.equals(osType); @@ -102,8 +103,8 @@ public class ThreadingImpl { Object threadingPluginObj=null; // try to fetch the AWTThreadingPlugin try { - threadingPluginObj = NWReflection.createInstance("com.jogamp.opengl.impl.awt.AWTThreadingPlugin"); - } catch (Throwable t) { } + threadingPluginObj = ReflectionUtil.createInstance("com.jogamp.opengl.impl.awt.AWTThreadingPlugin"); + } catch (JogampRuntimeException jre) { /* n/a .. */ } return threadingPluginObj; } }); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java index 8c3e9a1c4..48f80977c 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java @@ -95,11 +95,11 @@ public abstract class EGLContext extends GLContextImpl { boolean created = false; if (eglContext == 0) { create(); + created = true; if (DEBUG) { System.err.println(getThreadName() + ": !!! Created GL context 0x" + Long.toHexString(eglContext) + " for " + getClass().getName()); } - created = true; } if (EGL.eglGetCurrentContext() != eglContext) { if (!EGL.eglMakeCurrent(((EGLDrawable)drawable).getDisplay(), @@ -112,7 +112,7 @@ public abstract class EGLContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_ES|CTX_PROFILE_CORE|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; @@ -153,6 +153,10 @@ public abstract class EGLContext extends GLContextImpl { return 0; // FIXME } + protected void destroyContextARBImpl(long _context) { + // FIXME + } + protected void create() throws GLException { long eglDisplay = ((EGLDrawable)drawable).getDisplay(); EGLGraphicsConfiguration config = ((EGLDrawable)drawable).getGraphicsConfiguration(); @@ -218,7 +222,7 @@ public abstract class EGLContext extends GLContextImpl { throw new GLException("Error making context 0x" + Long.toHexString(eglContext) + " current: error code " + EGL.eglGetError()); } - setGLFunctionAvailability(true, contextAttrs[1], 0, CTX_IS_ARB_CREATED|CTX_PROFILE_CORE|CTX_OPTION_ANY); + setGLFunctionAvailability(true, glProfile.usesNativeGLES2()?2:1, 0, CTX_PROFILE_ES|CTX_PROFILE_CORE|CTX_OPTION_ANY); } public boolean isCreated() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java index 5a193b2ff..4fccf22f8 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java @@ -37,8 +37,10 @@ package com.jogamp.opengl.impl.egl; import javax.media.nativewindow.*; import javax.media.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.NullWindow; public class EGLDrawableFactory extends GLDrawableFactoryImpl { @@ -50,8 +52,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { // Check for other underlying stuff .. if(NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { try { - NWReflection.createInstance("com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfigurationFactory"); - } catch (Throwable t) {} + ReflectionUtil.createInstance("com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfigurationFactory"); + } catch (JogampRuntimeException jre) { /* n/a .. */ } } } @@ -59,6 +61,10 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { super(); } + + protected final GLDrawableImpl getSharedDrawable() { return null; } + protected final GLContextImpl getSharedContext() { return null; } + public GLDrawableImpl createOnscreenDrawable(NativeWindow target) { if (target == null) { throw new IllegalArgumentException("Null target"); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java index 70f0540bf..9e34dc9e9 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java @@ -64,9 +64,9 @@ public abstract class EGLDynamicLookupHelper implements DynamicLookupHelper { EGLDynamicLookupHelper tmp=null; try { tmp = new EGLES1DynamicLookupHelper(); - } catch (Throwable t) { + } catch (GLException gle) { if(DEBUG) { - t.printStackTrace(); + gle.printStackTrace(); } } eglES1DynamicLookupHelper = tmp; @@ -74,9 +74,9 @@ public abstract class EGLDynamicLookupHelper implements DynamicLookupHelper { tmp=null; try { tmp = new EGLES2DynamicLookupHelper(); - } catch (Throwable t) { + } catch (GLException gle) { if(DEBUG) { - t.printStackTrace(); + gle.printStackTrace(); } } eglES2DynamicLookupHelper = tmp; @@ -191,9 +191,9 @@ public abstract class EGLDynamicLookupHelper implements DynamicLookupHelper { } if (esProfile==2) { - NativeLibLoader.loadES2(); + GLJNILibLoader.loadES2(); } else if (esProfile==1) { - NativeLibLoader.loadES1(); + GLJNILibLoader.loadES1(); } else { throw new GLException("Unsupported: ES"+esProfile); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java index 0adede4ea..5a8454ea7 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java @@ -47,7 +47,7 @@ public class EGLExternalContext extends EGLContext { public EGLExternalContext(AbstractGraphicsScreen screen) { super(null, null); GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_IS_ARB_CREATED|CTX_PROFILE_ES|CTX_PROFILE_CORE|CTX_OPTION_ANY); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java index 9182a71de..ebefaf466 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java @@ -88,11 +88,13 @@ public abstract class MacOSXCGLContext extends GLContextImpl protected Map/**/ getExtensionNameMap() { return null; } - protected abstract boolean create(); + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + return 0; // FIXME + } - protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { - return 0; // FIXME - } + protected void destroyContextARBImpl(long _context) { + // FIXME + } /** * Creates and initializes an appropriate OpenGl nsContext. Should only be @@ -154,7 +156,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl if (!CGL.makeCurrentContext(nsContext)) { throw new GLException("Error making nsContext current"); } - setGLFunctionAvailability(true, 0, 0, 0); + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); GLContextShareSet.contextCreated(this); return true; } @@ -165,13 +167,14 @@ public abstract class MacOSXCGLContext extends GLContextImpl } boolean created = false; if ( 0 == cglContext && 0 == nsContext) { - if (!create()) { + create(); + created = 0 != cglContext || 0 != nsContext ; + if(!created) { return CONTEXT_NOT_CURRENT; } if (DEBUG) { System.err.println("!!! Created OpenGL context " + toHexString(nsContext) + " for " + getClass().getName()); } - created = true; } if ( 0 != cglContext ) { @@ -185,7 +188,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index 906088642..d10434252 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -43,8 +43,10 @@ import com.jogamp.common.os.DynamicLookupHelper; import java.nio.*; import javax.media.nativewindow.*; import javax.media.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.NullWindow; public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { public MacOSXCGLDrawableFactory() { @@ -55,11 +57,14 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements D new MacOSXCGLGraphicsConfigurationFactory(); try { - NWReflection.createInstance("com.jogamp.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", + ReflectionUtil.createInstance("com.jogamp.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", new Object[] {}); - } catch (Throwable t) { } + } catch (JogampRuntimeException jre) { /* n/a .. */ } } + protected final GLDrawableImpl getSharedDrawable() { return null; } + protected final GLContextImpl getSharedContext() { return null; } + public GLDrawableImpl createOnscreenDrawable(NativeWindow target) { if (target == null) { throw new IllegalArgumentException("Null target"); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java index 248bbb4d6..eba3cf50e 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java @@ -56,7 +56,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { this.cglContext = cglContext; this.nsContext = nsContext; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } @@ -110,8 +110,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { } } - protected boolean create() { - return true; + protected void create() { } public int makeCurrent() throws GLException { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java index 4c64864fa..c4eaee489 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java @@ -115,8 +115,8 @@ public class MacOSXOnscreenCGLContext extends MacOSXCGLContext { CGL.updateContext(nsContext); } - protected boolean create() { - return create(false, false); + protected void create() { + create(false, false); } public void setOpenGLMode(int mode) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java index 5844b8edd..e90672a1d 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java @@ -59,13 +59,14 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { boolean created = false; if (nsContext == 0) { - if (!create()) { + create(); + created = 0 != nsContext ; + if(!created) { return CONTEXT_NOT_CURRENT; } if (DEBUG) { System.err.println("!!! Created OpenGL context " + toHexString(nsContext) + " for " + getClass().getName()); } - created = true; } if (!impl.makeCurrent(nsContext)) { @@ -73,7 +74,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // Initialize render-to-texture support if requested DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); @@ -134,7 +135,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { return GLPbuffer.APPLE_FLOAT; } - protected boolean create() { + protected void create() { DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); GLCapabilities capabilities = (GLCapabilities)config.getChosenCapabilities(); if (capabilities.getPbufferFloatingPointBuffers() && @@ -152,9 +153,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { if (!impl.makeCurrent(nsContext)) { throw new GLException("Error making nsContext current"); } - setGLFunctionAvailability(true, 0, 0, 0); - - return true; + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); } //--------------------------------------------------------------------------- diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java index 9189b41f3..97a1435bc 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java @@ -73,7 +73,9 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL protected int makeCurrentImpl() throws GLException { boolean created = false; if (nsContext == 0) { - if (!create()) { + create(); + created = 0 != nsContext ; + if(!created) { return CONTEXT_NOT_CURRENT; } if (DEBUG) { @@ -87,13 +89,13 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; } - protected boolean create() { + protected void create() { // Find and configure share context MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this); long share = 0; @@ -119,11 +121,10 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL long ctx = Java2D.createOGLContextOnSurface(graphics, share); if (ctx == 0) { - return false; + return; } // FIXME: think about GLContext sharing nsContext = ctx; - return true; } protected void releaseImpl() throws GLException { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java index aae376a6c..e712d8568 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java @@ -56,7 +56,7 @@ public class WindowsExternalWGLContext extends WindowsWGLContext { System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(hglrc) + " for " + this); } GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); cfg.updateCapabilitiesByWGL(this); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index 95706a7a1..0f1f9813f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -122,13 +122,18 @@ public class WindowsWGLContext extends GLContextImpl { protected Map/**/ getExtensionNameMap() { return extensionNameMap; } + protected void destroyContextARBImpl(long context) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(context); + } + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); WGLExt wglExt; if(null==factory.getSharedContext()) { wglExt = getWGLExt(); } else { - wglExt = factory.getSharedContext().getWGLExt(); + wglExt = ((WindowsWGLContext)factory.getSharedContext()).getWGLExt(); } boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; @@ -235,7 +240,7 @@ public class WindowsWGLContext extends GLContextImpl { if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) { throw new GLException("Error making temp context current: 0x" + Integer.toHexString(WGL.GetLastError())); } - setGLFunctionAvailability(true, 0, 0, 0); + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); if( createContextARBTried || !isFunctionAvailable("wglCreateContextAttribsARB") || @@ -257,9 +262,6 @@ public class WindowsWGLContext extends GLContextImpl { if(0!=hglrc) { share = 0; // mark as shared .. - // need to update the GL func table .. - setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - WGL.wglMakeCurrent(0, 0); WGL.wglDeleteContext(temp_hglrc); @@ -302,10 +304,10 @@ public class WindowsWGLContext extends GLContextImpl { boolean created = false; if (hglrc == 0) { create(); + created = true; if (DEBUG) { System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); } - created = true; } if (WGL.wglGetCurrentContext() != hglrc) { @@ -320,7 +322,7 @@ public class WindowsWGLContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index bc99338ab..a4bf89b81 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -45,8 +45,9 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.nativewindow.windows.*; import javax.media.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.nativewindow.impl.NullWindow; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { @@ -66,40 +67,38 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements // The act of constructing them causes them to be registered new WindowsWGLGraphicsConfigurationFactory(); try { - NWReflection.createInstance("com.jogamp.opengl.impl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", + ReflectionUtil.createInstance("com.jogamp.opengl.impl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", new Object[] {}); - } catch (Throwable t) { } + } catch (JogampRuntimeException jre) { /* n/a .. */ } loadOpenGL32Library(); + + sharedDrawable = new WindowsDummyWGLDrawable(this, null); + WindowsWGLContext ctx = (WindowsWGLContext) sharedDrawable.createContext(null); + ctx.makeCurrent(); + canCreateGLPbuffer = ctx.getGL().isExtensionAvailable("GL_ARB_pbuffer"); + ctx.release(); + sharedContext = ctx; + if(null==sharedContext) { + throw new GLException("Couldn't init shared resources"); + } + if (DEBUG) { + System.err.println("!!! SharedContext: "+sharedContext+", pbuffer supported "+canCreateGLPbuffer); + } } WindowsDummyWGLDrawable sharedDrawable=null; WindowsWGLContext sharedContext=null; boolean canCreateGLPbuffer = false; - // package private .. - final WindowsWGLContext getSharedContext() { + protected final GLDrawableImpl getSharedDrawable() { validate(); - return sharedContext; + return sharedDrawable; } - void initShared() { - if(null==sharedDrawable) { - sharedDrawable = new WindowsDummyWGLDrawable(this, null); - WindowsWGLContext _sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null); - { - _sharedContext.makeCurrent(); - canCreateGLPbuffer = _sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer"); - _sharedContext.release(); - } - _sharedContext = _sharedContext; - if (DEBUG) { - System.err.println("!!! SharedContext: "+sharedContext+", pbuffer supported "+canCreateGLPbuffer); - } - if(null==sharedContext) { - throw new GLException("Couldn't init shared resources"); - } - } + protected final GLContextImpl getSharedContext() { + validate(); + return sharedContext; } public void shutdown() { @@ -124,7 +123,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); return new WindowsOnscreenWGLDrawable(this, target); } @@ -133,13 +131,11 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); return new WindowsOffscreenWGLDrawable(this, target); } public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { validate(); - initShared(); // setup canCreateGLPBuffer return canCreateGLPbuffer; } @@ -148,7 +144,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); final List returnList = new ArrayList(); final GLDrawableFactory factory = this; final WindowsWGLContext _sharedContext = sharedContext; @@ -180,7 +175,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { validate(); - initShared(); AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capabilities, chooser, screen) ); @@ -190,7 +184,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLContext createExternalGLContext() { validate(); - initShared(); return WindowsExternalWGLContext.create(this, null); } @@ -201,7 +194,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLDrawable createExternalGLDrawable() { validate(); - initShared(); return WindowsExternalWGLDrawable.create(this, null); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index c9805fef1..ab3227257 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -135,7 +135,6 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio pfd = WindowsWGLGraphicsConfiguration.createPixelFormatDescriptor(); // Produce a recommended pixel format selection for the GLCapabilitiesChooser. // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available - factory.initShared(); factory.sharedContext.makeCurrent(); WGLExt wglExt = factory.sharedContext.getWGLExt(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java index a865e91e8..1f148bead 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java @@ -42,7 +42,7 @@ import com.jogamp.nativewindow.impl.x11.*; public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { - // private long dummyWindow = 0; + private long dummyWindow = 0; /** * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, @@ -62,17 +62,15 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { X11GraphicsDevice device = (X11GraphicsDevice) screen.getDevice(); long dpy = device.getHandle(); int scrn = screen.getIndex(); - // long visualID = config.getVisualID(); - // System.out.println("X11DummyGLXDrawable: dpy "+toHexString(dpy)+", scrn "+scrn+", visualID "+toHexString(visualID)); + long visualID = config.getVisualID(); X11Lib.XLockDisplay(dpy); try{ - nw.setSurfaceHandle( X11Lib.RootWindow(dpy, scrn) ); - // dummyWindow = X11Lib.CreateDummyWindow(dpy, scrn, visualID); - // nw.setSurfaceHandle( dummyWindow ); + dummyWindow = X11Lib.CreateDummyWindow(dpy, scrn, visualID); } finally { X11Lib.XUnlockDisplay(dpy); } + nw.setSurfaceHandle( dummyWindow ); } public void setSize(int width, int height) { @@ -87,11 +85,10 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { } public void destroy() { - /** if(0!=dummyWindow) { X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); long dpy = config.getScreen().getDevice().getHandle(); X11Lib.DestroyDummyWindow(dpy, dummyWindow); - } */ + } } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java index b8f25aad7..139c0deed 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java @@ -55,7 +55,7 @@ public class X11ExternalGLXContext extends X11GLXContext { super(drawable, null); this.context = context; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index f5e291c5f..7d907bf28 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -103,12 +103,31 @@ public abstract class X11GLXContext extends GLContextImpl { protected Map/**/ getExtensionNameMap() { return extensionNameMap; } - /** Helper routine which usually just turns around and calls - * createContext (except for pbuffers, which use a different context - * creation mechanism). Should only be called by {@link - * makeCurrentImpl()}. - */ - protected abstract void create(); + protected boolean glXMakeContextCurrent(long dpy, long writeDrawable, long readDrawable, long ctx) { + boolean res = false; + + try { + res = GLX.glXMakeContextCurrent(dpy, writeDrawable, readDrawable, ctx); + } catch (RuntimeException re) { + if(DEBUG) { + System.err.println("X11GLXContext.glXMakeContextCurrent failed: "+re+", with "+ + "dpy "+toHexString(dpy)+ + ", write "+toHexString(writeDrawable)+ + ", read "+toHexString(readDrawable)+ + ", ctx "+toHexString(ctx)); + re.printStackTrace(); + } + } + return res; + } + + protected void destroyContextARBImpl(long _context) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + long display = config.getScreen().getDevice().getHandle(); + + glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, _context); + } protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); @@ -119,7 +138,7 @@ public abstract class X11GLXContext extends GLContextImpl { if(null==factory.getSharedContext()) { glXExt = getGLXExt(); } else { - glXExt = factory.getSharedContext().getGLXExt(); + glXExt = ((X11GLXContext)factory.getSharedContext()).getGLXExt(); } boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; @@ -156,20 +175,27 @@ public abstract class X11GLXContext extends GLContextImpl { } } - _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + try { + _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + } catch (RuntimeException re) { + if(DEBUG) { + System.err.println("X11GLXContext.createContextARB glXCreateContextAttribsARB failed: "+re+", with "+getGLVersion(null, major, minor, ctp, "@creation")); + re.printStackTrace(); + } + } if(0==_context) { if(DEBUG) { System.err.println("X11GLXContext.createContextARB couldn't create "+getGLVersion(null, major, minor, ctp, "@creation")); } } else { - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - _context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + _context)) { if(DEBUG) { System.err.println("X11GLXContext.createContextARB couldn't make current "+getGLVersion(null, major, minor, ctp, "@creation")); } - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, _context); _context = 0; } @@ -179,7 +205,7 @@ public abstract class X11GLXContext extends GLContextImpl { /** * Creates and initializes an appropriate OpenGL context. Should only be - * called by {@link create()}. + * called by {@link #create()}. * Note: The direct parameter may be overwritten by the direct state of a shared context. */ protected void createContext(boolean direct) { @@ -213,13 +239,13 @@ public abstract class X11GLXContext extends GLContextImpl { if (context == 0) { throw new GLException("Unable to create context(0)"); } - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } - setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION return; } @@ -245,21 +271,21 @@ public abstract class X11GLXContext extends GLContextImpl { if (temp_context == 0) { throw new GLException("Unable to create temp OpenGL context(1)"); } - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - temp_context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + temp_context)) { throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } - setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION if( createContextARBTried || !isFunctionAvailable("glXCreateContextAttribsARB") || !isExtensionAvailable("GLX_ARB_create_context") ) { if(glp.isGL3()) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)"); + throw new GLException("Unable to create OpenGL >= 3.1 context (failed GLX_ARB_create_context), GLProfile "+glp+", Drawable "+drawable); } // continue with temp context for GL < 3.0 @@ -271,22 +297,19 @@ public abstract class X11GLXContext extends GLContextImpl { } if(0!=context) { - // need to update the GL func table .. - setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - if(0!=temp_context) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { throw new GLException("Cannot make previous verified context current"); } } } else { if(!glp.isGL2()) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); throw new GLException("X11GLXContext.createContext failed, but context > GL2 requested "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "); } @@ -296,11 +319,11 @@ public abstract class X11GLXContext extends GLContextImpl { // continue with temp context for GL <= 3.0 context = temp_context; - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } @@ -349,19 +372,19 @@ public abstract class X11GLXContext extends GLContextImpl { boolean created = false; if (context == 0) { create(); + created = true; GLContextShareSet.contextCreated(this); if (DEBUG) { System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); } - created = true; } if (GLX.glXGetCurrentContext() != context) { - if (!GLX.glXMakeContextCurrent(dpy, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + if (!glXMakeContextCurrent(dpy, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { throw new GLException("Error making context current: "+this); } if (DEBUG && (VERBOSE || created)) { @@ -374,7 +397,7 @@ public abstract class X11GLXContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; @@ -386,7 +409,7 @@ public abstract class X11GLXContext extends GLContextImpl { protected void releaseImplAfterLock() throws GLException { getDrawableImpl().getFactoryImpl().lockToolkit(); try { - if (!GLX.glXMakeContextCurrent(drawable.getNativeWindow().getDisplayHandle(), 0, 0, 0)) { + if (!glXMakeContextCurrent(drawable.getNativeWindow().getDisplayHandle(), 0, 0, 0)) { throw new GLException("Error freeing OpenGL context"); } } finally { @@ -494,6 +517,10 @@ public abstract class X11GLXContext extends GLContextImpl { private int hasSwapIntervalSGI = 0; protected void setSwapIntervalImpl(int interval) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); + if(!glCaps.isOnscreen()) return; + getDrawableImpl().getFactoryImpl().lockToolkit(); try { GLXExt glXExt = getGLXExt(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 0d74bb791..f331ad2a2 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -43,8 +43,9 @@ import javax.media.nativewindow.x11.*; import javax.media.opengl.*; import com.jogamp.gluegen.runtime.opengl.*; import com.jogamp.opengl.impl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.nativewindow.impl.NullWindow; -import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.nativewindow.impl.x11.*; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { @@ -58,9 +59,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna // The act of constructing them causes them to be registered new X11GLXGraphicsConfigurationFactory(); try { - NWReflection.createInstance("com.jogamp.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", + ReflectionUtil.createInstance("com.jogamp.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", new Object[] {}); - } catch (Throwable t) { } + } catch (JogampRuntimeException jre) { /* n/a .. */ } X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.createThreadLocalDisplay(null)); vendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); @@ -70,9 +71,20 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna X11Util.markGlobalDisplayUndeletable(sharedDevice.getHandle()); // ATI hack .. } sharedScreen = new X11GraphicsScreen(sharedDevice, 0); + X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); + sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); + X11GLXContext ctx = (X11GLXContext) sharedDrawable.createContext(null); + ctx.makeCurrent(); + ctx.release(); + sharedContext = ctx; + X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); + if(null==sharedContext) { + throw new GLException("Couldn't init shared resources"); + } if (DEBUG) { System.err.println("!!! Vendor: "+vendorName+", ATI: "+isVendorATI+", NV: "+isVendorNVIDIA); System.err.println("!!! SharedScreen: "+sharedScreen); + System.err.println("!!! SharedContext: "+sharedContext); } } @@ -88,30 +100,14 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna private X11DummyGLXDrawable sharedDrawable=null; private X11GLXContext sharedContext=null; - // package private .. - final X11GLXContext getSharedContext() { + protected final GLDrawableImpl getSharedDrawable() { validate(); - return sharedContext; + return sharedDrawable; } - private void initShared() { - if(null==sharedDrawable) { - X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); - sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); - X11GLXContext _sharedContext = (X11GLXContext) sharedDrawable.createContext(null); - { - _sharedContext.makeCurrent(); - _sharedContext.release(); - } - sharedContext = _sharedContext; - X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); - if (DEBUG) { - System.err.println("!!! SharedContext: "+sharedContext); - } - if(null==sharedContext) { - throw new GLException("Couldn't init shared resources"); - } - } + protected final GLContextImpl getSharedContext() { + validate(); + return sharedContext; } public void shutdown() { @@ -145,7 +141,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } @@ -157,11 +152,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } - initShared(); return new X11OffscreenGLXDrawable(this, target); } @@ -203,7 +196,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); GLDrawableImpl pbufferDrawable; @@ -234,7 +226,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { validate(); - initShared(); X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); NullWindow nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); @@ -244,19 +235,16 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna public GLContext createExternalGLContext() { validate(); - initShared(); return X11ExternalGLXContext.create(this, null); } public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { validate(); - initShared(); return canCreateGLPbuffer(device); } public GLDrawable createExternalGLDrawable() { validate(); - initShared(); return X11ExternalGLXDrawable.create(this, null); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java index e0993abc3..1b70adf6b 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java @@ -68,33 +68,6 @@ public class X11PbufferGLXContext extends X11GLXContext { } protected void create() { - if (DEBUG) { - System.err.println("Creating context for pbuffer " + drawable.getWidth() + - " x " + drawable.getHeight()); - } - - // Create a gl context for the p-buffer. - X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this); - long share = 0; - if (other != null) { - share = other.getContext(); - if (share == 0) { - throw new GLException("GLContextShareSet returned an invalid OpenGL context"); - } - } - X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration) - getGLDrawable().getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - - context = GLX.glXCreateNewContext(drawable.getNativeWindow().getDisplayHandle(), - config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, true); - if (context == 0) { - throw new GLException("pbuffer creation error: glXCreateNewContext() failed"); - } - GLContextShareSet.contextCreated(this); - - if (DEBUG) { - System.err.println("Created context for pbuffer " + drawable.getWidth() + - " x " + drawable.getHeight()); - } + createContext(true); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index ad230a415..04b994198 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -1,9 +1,9 @@ package com.jogamp.opengl.util; +import com.jogamp.common.util.*; import javax.media.opengl.*; import javax.media.opengl.fixedfunc.*; -import com.jogamp.nativewindow.impl.NWReflection; import java.nio.*; import java.util.Iterator; import java.util.ArrayList; @@ -341,9 +341,9 @@ public class ImmModeSink { } else { Class clazz = indices.getClass(); int type=-1; - if(NWReflection.instanceOf(clazz, ByteBuffer.class.getName())) { + if(ReflectionUtil.instanceOf(clazz, ByteBuffer.class.getName())) { type = GL.GL_UNSIGNED_BYTE; - } else if(NWReflection.instanceOf(clazz, ShortBuffer.class.getName())) { + } else if(ReflectionUtil.instanceOf(clazz, ShortBuffer.class.getName())) { type = GL.GL_UNSIGNED_SHORT; } if(0>type) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java index f00357bfb..7ec4ac50e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java @@ -28,7 +28,7 @@ public class FixedFuncUtil { gl.getContext().setGL(impl); return impl; } - throw new GLException("GL Object is neither GL2ES1 nor GL2ES2"); + throw new GLException("GL Object is neither GL2ES1 nor GL2ES2: "+gl.getContext()); } /** diff --git a/src/jogl/classes/javax/media/opengl/GL4.java b/src/jogl/classes/javax/media/opengl/GL4.java deleted file mode 100644 index 29a316333..000000000 --- a/src/jogl/classes/javax/media/opengl/GL4.java +++ /dev/null @@ -1,5 +0,0 @@ -package javax.media.opengl; - -public interface GL4 extends GLBase { -} - diff --git a/src/jogl/classes/javax/media/opengl/GL4bc.java b/src/jogl/classes/javax/media/opengl/GL4bc.java deleted file mode 100644 index be1131e91..000000000 --- a/src/jogl/classes/javax/media/opengl/GL4bc.java +++ /dev/null @@ -1,5 +0,0 @@ -package javax.media.opengl; - -public interface GL4bc extends GL4 { -} - diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 833ebf192..e5b499af9 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -40,6 +40,7 @@ package javax.media.opengl; import java.util.HashMap; +import com.jogamp.common.util.IntIntHashMap; /** Abstraction for an OpenGL rendering context. In order to perform OpenGL rendering, a context must be "made current" on the current @@ -261,6 +262,12 @@ public abstract class GLContext { StringBuffer sb = new StringBuffer(); sb.append(getClass().getName()); sb.append(" [OpenGL "); + sb.append(getGLVersionMajor()); + sb.append("."); + sb.append(getGLVersionMinor()); + sb.append(", options 0x"); + sb.append(Integer.toHexString(ctxOptions)); + sb.append(", "); sb.append(getGLVersion()); sb.append(", "); sb.append(getGL()); @@ -284,7 +291,7 @@ public abstract class GLContext { public abstract String getPlatformExtensionsString(); public final int getGLVersionMajor() { return ctxMajorVersion; } - public final int getGLVersionMinor() { return ctxMajorVersion; } + public final int getGLVersionMinor() { return ctxMinorVersion; } public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } @@ -342,9 +349,181 @@ public abstract class GLContext { /** ARB_create_context related: core profile */ protected static final int CTX_PROFILE_CORE = 1 << 2; /** ARB_create_context related: flag forward compatible */ - protected static final int CTX_OPTION_FORWARD = 1 << 3; + protected static final int CTX_PROFILE_ES = 1 << 3; + /** ARB_create_context related: flag forward compatible */ + protected static final int CTX_OPTION_FORWARD = 1 << 4; /** ARB_create_context related: not flag forward compatible */ - protected static final int CTX_OPTION_ANY = 1 << 4; + protected static final int CTX_OPTION_ANY = 1 << 5; /** ARB_create_context related: flag debug */ - protected static final int CTX_OPTION_DEBUG = 1 << 5; + protected static final int CTX_OPTION_DEBUG = 1 << 6; + + + public final boolean isGL4bc() { + return ctxMajorVersion>=4 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES)); + } + + public final boolean isGL4() { + return ctxMajorVersion>=4 && 0==(ctxOptions & (CTX_PROFILE_ES)); + } + + public final boolean isGL3bc() { + return ctxMajorVersion>=3 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES)); + } + + public final boolean isGL3() { + return ctxMajorVersion>=3 && 0==(ctxOptions & (CTX_PROFILE_ES)); + } + + public final boolean isGL2() { + return ctxMajorVersion>=1 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES)); + } + + public final boolean isGLES1() { + return ctxMajorVersion==1 && CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGLES2() { + return ctxMajorVersion==2 && CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGLES() { + return CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGL2ES1() { + return isGL2() || isGLES1() ; + } + + public final boolean isGL2ES2() { + return isGL2() || isGL3() || isGLES2() ; + } + + public final boolean isGL2GL3() { + return isGL2() || isGL3(); + } + + public final boolean hasGLSL() { + return isGL2ES2() ; + } + + public static final int GL_VERSIONS[][] = { + /* 0.*/ { -1 }, + /* 1.*/ { 0, 1, 2, 3, 4, 5 }, + /* 2.*/ { 0, 1 }, + /* 3.*/ { 0, 1, 2, 3 }, + /* 4.*/ { 0 } }; + + public static final int getMaxMajor() { + return GL_VERSIONS.length-1; + } + + public static final int getMaxMinor(int major) { + if(1>major || major>=GL_VERSIONS.length) return -1; + return GL_VERSIONS[major].length-1; + } + + public static final boolean isValidGLVersion(int major, int minor) { + if(1>major || major>=GL_VERSIONS.length) return false; + if(0>minor || minor>=GL_VERSIONS[major].length) return false; + return true; + } + + public static final boolean decrementGLVersion(int major[], int minor[]) { + if(null==major || major.length<1 ||null==minor || minor.length<1) { + throw new GLException("invalid array arguments"); + } + int m = major[0]; + int n = minor[0]; + if(!isValidGLVersion(m, n)) return false; + + // decrement .. + n -= 1; + if(n < 0) { + m -= 1; + n = GL_VERSIONS[m].length-1; + } + if(!isValidGLVersion(m, n)) return false; + major[0]=m; + minor[0]=n; + + return true; + } + + public static final boolean isGLVersionAvailable(int major, boolean compatibility) { + int key = compose8bit(major, compatibility?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0); + int val = mappedVersionsAvailable.get( key ); + return val>0; + } + public static final boolean isGL4bcAvailable() { return isGLVersionAvailable(4, true); } + public static final boolean isGL4Available() { return isGLVersionAvailable(4, false); } + public static final boolean isGL3bcAvailable() { return isGLVersionAvailable(3, true); } + public static final boolean isGL3Available() { return isGLVersionAvailable(3, false); } + public static final boolean isGL2Available() { return isGLVersionAvailable(2, true); } + + protected static final IntIntHashMap mappedVersionsAvailable; + protected static volatile boolean mappedVersionsAvailableSet; + protected static Object mappedVersionsAvailableLock; + + static { + mappedVersionsAvailableLock = new Object(); + mappedVersionsAvailableSet = false; + mappedVersionsAvailable = new IntIntHashMap(); + mappedVersionsAvailable.setKeyNotFoundValue(-1); + } + + /** + * Called by {@link GLContextImpl#createContextARBMapVersionsAvailable} not intendet to be used by + * implementations. However, if {@link #createContextARB} is not being used within the + * {@link GLDrawableImpl} constructor, GLProfile has to map the available versions. + * + * @see #createContextARBMapVersionsAvailable + */ + protected static void mapVersionAvailable(int reqMajor, boolean reqCompat, int resMajor, int resMinor, int resCtp) + { + int key = compose8bit(reqMajor, reqCompat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0); + int val = compose8bit(resMajor, resMinor, resCtp, 0); + mappedVersionsAvailable.put( key, val ); + } + + protected static int compose8bit(int one, int two, int three, int four) { + return ( ( one & 0x000000FF ) << 24 ) | + ( ( two & 0x000000FF ) << 16 ) | + ( ( three & 0x000000FF ) << 8 ) | + ( ( four & 0x000000FF ) ) ; + } + + protected static int getComposed8bit(int bits32, int which ) { + switch (which) { + case 1: return ( bits32 & 0xFF000000 ) >> 24 ; + case 2: return ( bits32 & 0x00FF0000 ) >> 16 ; + case 3: return ( bits32 & 0x0000FF00 ) >> 8 ; + case 4: return ( bits32 & 0xFF0000FF ) ; + } + throw new GLException("argument which out of range: "+which); + } + + protected static String composed8BitToString(int bits32, boolean hex1, boolean hex2, boolean hex3, boolean hex4) { + int a = getComposed8bit(bits32, 1); + int b = getComposed8bit(bits32, 2); + int c = getComposed8bit(bits32, 3); + int d = getComposed8bit(bits32, 4); + return "["+toString(a, hex1)+", "+toString(b, hex2)+", "+toString(c, hex3)+", "+toString(d, hex4)+"]"; + } + + protected static String toString(int val, boolean hex) { + if(hex) { + return "0x" + Integer.toHexString(val); + } + return String.valueOf(val); + } + + protected static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + protected static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + } + diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index 80c2c10e2..b02bffb61 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -42,8 +42,9 @@ package javax.media.opengl; import javax.media.nativewindow.*; import java.security.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.NWReflection; /**

Provides a virtual machine- and operating system-independent mechanism for creating {@link GLDrawable}s.

@@ -96,51 +97,50 @@ public abstract class GLDrawableFactory { static { GLDrawableFactory tmp = null; try { - tmp = (GLDrawableFactory) NWReflection.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory"); - } catch (Throwable t) { + tmp = (GLDrawableFactory) ReflectionUtil.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory"); + } catch (JogampRuntimeException jre) { if (GLProfile.DEBUG) { System.err.println("GLDrawableFactory.static - EGLDrawableFactory - not available"); - t.printStackTrace(); + jre.printStackTrace(); } } eglFactory = tmp; nativeOSType = NativeWindowFactory.getNativeWindowType(true); - String factoryClassName = null; tmp = null; - try { - factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext()); - if (null == factoryClassName) { - if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) { - factoryClassName = "com.jogamp.opengl.impl.x11.glx.X11GLXDrawableFactory"; - } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) { - factoryClassName = "com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory"; - } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) { - if(NWReflection.isClassAvailable(macosxFactoryClassNameAWTCGL)) { - factoryClassName = macosxFactoryClassNameAWTCGL; - } else { - factoryClassName = macosxFactoryClassNameCGL; - } + String factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext()); + if (null == factoryClassName) { + if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) { + factoryClassName = "com.jogamp.opengl.impl.x11.glx.X11GLXDrawableFactory"; + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) { + factoryClassName = "com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory"; + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) { + if(ReflectionUtil.isClassAvailable(macosxFactoryClassNameAWTCGL)) { + factoryClassName = macosxFactoryClassNameAWTCGL; } else { - // may use egl*Factory .. - if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - No native OS Factory for: "+nativeOSType+"; May use EGLDrawableFactory, if available." ); - } + factoryClassName = macosxFactoryClassNameCGL; } - } - if (null != factoryClassName) { + } else { + // may use egl*Factory .. if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - Native OS Factory for: "+nativeOSType+": "+factoryClassName); + System.err.println("GLDrawableFactory.static - No native OS Factory for: "+nativeOSType+"; May use EGLDrawableFactory, if available." ); } - tmp = (GLDrawableFactory) NWReflection.createInstance(factoryClassName); - } - } catch (Throwable t) { - if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); - t.printStackTrace(); } } + if (null != factoryClassName) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - Native OS Factory for: "+nativeOSType+": "+factoryClassName); + } + try { + tmp = (GLDrawableFactory) ReflectionUtil.createInstance(factoryClassName); + } catch (JogampRuntimeException jre) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); + jre.printStackTrace(); + } + } + } nativeOSFactory = tmp; } diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index e1fc9f53f..9e3a532e6 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -36,12 +36,13 @@ package javax.media.opengl; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.DRIHack; import com.jogamp.opengl.impl.Debug; -import com.jogamp.opengl.impl.NativeLibLoader; -import com.jogamp.nativewindow.impl.NWReflection; -import com.jogamp.nativewindow.impl.jvm.JVMUtil; +import com.jogamp.opengl.impl.GLJNILibLoader; +import com.jogamp.common.jvm.JVMUtil; import java.util.HashMap; +import java.util.Iterator; import java.security.AccessControlContext; import java.security.AccessController; import javax.media.opengl.fixedfunc.GLPointerFunc; @@ -58,6 +59,45 @@ import javax.media.opengl.fixedfunc.GLPointerFunc; public class GLProfile implements Cloneable { public static final boolean DEBUG = Debug.debug("GLProfile"); + // + // Query platform available OpenGL implementation + // + + public static final boolean isGL4bcAvailable() { return hasGL4bcImpl; } + public static final boolean isGL4Available() { return hasGL4Impl; } + public static final boolean isGL3bcAvailable() { return hasGL3bcImpl; } + public static final boolean isGL3Available() { return hasGL3Impl; } + public static final boolean isGL2Available() { return hasGL2Impl; } + public static final boolean isGLES2Available() { return hasGLES2Impl; } + public static final boolean isGLES1Available() { return hasGLES1Impl; } + public static final String glAvailabilityToString() { + StringBuffer sb = new StringBuffer(); + sb.append("GLAvailability[Native[GL4bc "); + sb.append(hasGL4bcImpl); + sb.append(", GL4 "); + sb.append(hasGL4Impl); + sb.append(", GL3bc "); + sb.append(hasGL3bcImpl); + sb.append(", GL3 "); + sb.append(hasGL3Impl); + sb.append(", GL2 "); + sb.append(hasGL2Impl); + sb.append(", GLES1 "); + sb.append(hasGLES1Impl); + sb.append(", GLES2 "); + sb.append(hasGLES2Impl); + sb.append("], Profiles["); + for(Iterator i=mappedProfiles.values().iterator(); i.hasNext(); ) { + sb.append(((GLProfile)i.next()).toString()); + sb.append(", "); + } + sb.append(", default "); + sb.append(defaultGLProfile); + sb.append("]]"); + + return sb.toString(); + } + // // Public (user-visible) profiles // @@ -95,22 +135,92 @@ public class GLProfile implements Cloneable { public static final String GL2GL3 = "GL2GL3"; /** - * All GL Profiles in the order of default detection: GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3 + * All GL Profiles in the order of default detection. + * Desktop compatibility profiles (the one with fixed function pipeline) comes first. + * + * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! + * + *
    + *
  • GL2 + *
  • GL3bc + *
  • GL4bc + *
  • GL2GL3 + *
  • GL3 + *
  • GL4 + *
  • GL2ES2 + *
  • GLES2 + *
  • GL2ES1 + *
  • GLES1 + *
+ * */ - public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL4bc, GL3bc, GL4, GL3 }; + public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL3bc, GL4bc, GL2GL3, GL3, GL4, GL2ES2, GLES2, GL2ES1, GLES1 }; /** - * All GL2ES2 Profiles in the order of default detection: GL2ES2, GL2, GLES2, GL3 + * Order of maximum fixed function profiles + * + *
    + *
  • GL4bc + *
  • GL3bc + *
  • GL2 + *
  • GL2ES1 + *
  • GLES1 + *
+ * + */ + public static final String[] GL_PROFILE_LIST_MAX_FIXEDFUNC = new String[] { GL4bc, GL3bc, GL2, GL2ES1, GLES1 }; + + /** + * Order of maximum programmable shader profiles + * + *
    + *
  • GL4 + *
  • GL4bc + *
  • GL3 + *
  • GL3bc + *
  • GL2 + *
  • GL2ES2 + *
  • GLES2 + *
+ * + */ + public static final String[] GL_PROFILE_LIST_MAX_PROGSHADER = new String[] { GL4, GL4bc, GL3, GL3bc, GL2, GL2ES2, GLES2 }; + + /** + * All GL2ES2 Profiles in the order of default detection. + * + * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! + * + *
    + *
  • GL2ES2 + *
  • GL2 + *
  • GL3 + *
  • GL4 + *
  • GLES2 + *
+ * */ - public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GLES2, GL4bc, GL3bc, GL4, GL3 }; + public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GL3, GL4, GLES2 }; /** - * All GL2ES1 Profiles in the order of default detection: GL2ES1, GL2, GLES1 + * All GL2ES1 Profiles in the order of default detection. + * + * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! + * + *
    + *
  • GL2ES1 + *
  • GL2 + *
  • GL3bc + *
  • GL4bc + *
  • GLES1 + *
+ * */ - public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL2, GLES1 }; + public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL2, GL3bc, GL4bc, GLES1 }; /** Returns a default GLProfile object, reflecting the best for the running platform. * It selects the first of the set {@link GLProfile#GL_PROFILE_LIST_ALL} + * @see #GL_PROFILE_LIST_ALL */ public static final GLProfile getDefault() { if(null==defaultGLProfile) { @@ -119,22 +229,30 @@ public class GLProfile implements Cloneable { return defaultGLProfile; } - /** Returns a GLProfile object. - * Verfifies the given profile and chooses an apropriate implementation. - * A generic value of null or GL will result in - * the default profile. + /** + * Returns the highest profile, implementing the fixed function pipeline + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_FIXEDFUNC} * * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MAX_FIXEDFUNC */ - public static final GLProfile get(String profile) + public static final GLProfile getMaxFixedFunc() throws GLException { - if(null==profile || profile.equals("GL")) return getDefault(); - GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); - if(null==glProfile) { - throw new GLException("No implementation for profile "+profile+" available"); - } - return glProfile; + return get(GL_PROFILE_LIST_MAX_FIXEDFUNC); + } + + /** + * Returns the highest profile, implementing the programmable shader pipeline. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_PROGSHADER} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MAX_PROGSHADER + */ + public static final GLProfile getMaxProgrammable() + throws GLException + { + return get(GL_PROFILE_LIST_MAX_PROGSHADER); } /** @@ -142,6 +260,7 @@ public class GLProfile implements Cloneable { * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES1} * * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_GL2ES1 */ public static final GLProfile getGL2ES1() throws GLException @@ -154,6 +273,7 @@ public class GLProfile implements Cloneable { * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES2} * * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_GL2ES2 */ public static final GLProfile getGL2ES2() throws GLException @@ -161,6 +281,24 @@ public class GLProfile implements Cloneable { return get(GL_PROFILE_LIST_GL2ES2); } + /** Returns a GLProfile object. + * Verfifies the given profile and chooses an apropriate implementation. + * A generic value of null or GL will result in + * the default profile. + * + * @throws GLException if no implementation for the given profile is found. + */ + public static final GLProfile get(String profile) + throws GLException + { + if(null==profile || profile.equals("GL")) return getDefault(); + GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); + if(null==glProfile) { + throw new GLException("No implementation for profile "+profile+" available"); + } + return glProfile; + } + /** * Returns the first profile from the given list, * where an implementation is available. @@ -200,18 +338,12 @@ public class GLProfile implements Cloneable { } private static final String getGLImplBaseClassName(String profileImpl) { - if(GL4bc.equals(profileImpl)) { + if ( GL4bc.equals(profileImpl) || + GL4.equals(profileImpl) || + GL3bc.equals(profileImpl) || + GL3.equals(profileImpl) || + GL2.equals(profileImpl) ) { return "com.jogamp.opengl.impl.gl4.GL4bc"; - } else if(GL4.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl4.GL4"; - } else if(GL3bc.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl3.GL3bc"; - } else if(GL3.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl3.GL3"; - } else if(GL2.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl2.GL2"; - } else if(GL2ES12.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl2es12.GL2ES12"; } else if(GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl)) { return "com.jogamp.opengl.impl.es1.GLES1"; } else if(GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl)) { @@ -285,7 +417,7 @@ public class GLProfile implements Cloneable { return isGL4() || isGL3bc() || GL3.equals(profile); } - /** Indicates whether this profile is capable of GL2. */ + /** Indicates whether this context is a GL2 context */ public final boolean isGL2() { return isGL3bc() || GL2.equals(profile); } @@ -315,34 +447,9 @@ public class GLProfile implements Cloneable { return GL2GL3.equals(profile) || isGL2() || isGL3() ; } - /** Indicates whether this profile uses the native desktop OpenGL GL4bc implementations. */ - public final boolean usesNativeGL4bc() { - return GL4bc.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL4 implementations. */ - public final boolean usesNativeGL4() { - return usesNativeGL4bc() || GL4.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL3bc implementations. */ - public final boolean usesNativeGL3bc() { - return GL3bc.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL3 implementations. */ - public final boolean usesNativeGL3() { - return usesNativeGL3bc() || GL3.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL2 implementations. */ - public final boolean usesNativeGL2() { - return GL2.equals(profileImpl) || GL2ES12.equals(profileImpl) ; - } - - /** Indicates whether this profile uses the native desktop OpenGL GL2 or GL3 implementations. */ - public final boolean usesNativeGL2GL3() { - return usesNativeGL2() || usesNativeGL3() || usesNativeGL4(); + /** Indicates whether this profile supports GLSL. */ + public final boolean hasGLSL() { + return isGL2ES2() ; } /** Indicates whether this profile uses the native OpenGL ES1 implementations. */ @@ -360,11 +467,6 @@ public class GLProfile implements Cloneable { return usesNativeGLES2() || usesNativeGLES1(); } - /** Indicates whether this profile supports GLSL. */ - public final boolean hasGLSL() { - return isGL2ES2() ; - } - /** * General validation if type is a valid GL data type * for the current profile @@ -665,70 +767,23 @@ public class GLProfile implements Cloneable { return "GLProfile[" + profile + "/" + profileImpl + "]"; } - public static final int GL_VERSIONS[][] = { - /* 0.*/ { -1 }, - /* 1.*/ { 0, 1, 2, 3, 4, 5 }, - /* 2.*/ { 0, 1 }, - /* 3.*/ { 0, 1, 2, 3 }, - /* 4.*/ { 0 } }; - - public static final int getMaxMajor() { - return GL_VERSIONS.length-1; - } - - public static final int getMaxMinor(int major) { - if(1>major || major>=GL_VERSIONS.length) return -1; - return GL_VERSIONS[major].length-1; - } - - public static final boolean isValidGLVersion(int major, int minor) { - if(1>major || major>=GL_VERSIONS.length) return false; - if(0>minor || minor>=GL_VERSIONS[major].length) return false; - return true; - } - - public static final boolean decrementGLVersion(int major[], int minor[]) { - if(null==major || major.length<1 ||null==minor || minor.length<1) { - throw new GLException("invalid array arguments"); - } - int m = major[0]; - int n = minor[0]; - if(!isValidGLVersion(m, n)) return false; - - // decrement .. - n -= 1; - if(n < 0) { - m -= 1; - n = GL_VERSIONS[m].length-1; - } - if(!isValidGLVersion(m, n)) return false; - major[0]=m; - minor[0]=n; - - return true; - } - - // The intersection between desktop OpenGL and the union of the OpenGL ES profiles - // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes - private static final String GL2ES12 = "GL2ES12"; - private static final boolean isAWTAvailable; private static final boolean isAWTJOGLAvailable; - private static final boolean hasGL4bcImpl; - private static final boolean hasGL4Impl; - private static final boolean hasGL3bcImpl; - private static final boolean hasGL3Impl; - private static final boolean hasGL2Impl; - private static final boolean hasGL2ES12Impl; - private static final boolean hasGLES2Impl; - private static final boolean hasGLES1Impl; + private static /*final*/ boolean hasGL234Impl; + private static /*final*/ boolean hasGL4bcImpl; + private static /*final*/ boolean hasGL4Impl; + private static /*final*/ boolean hasGL3bcImpl; + private static /*final*/ boolean hasGL3Impl; + private static /*final*/ boolean hasGL2Impl; + private static /*final*/ boolean hasGLES2Impl; + private static /*final*/ boolean hasGLES1Impl; /** The JVM/process wide default GL profile **/ - private static GLProfile defaultGLProfile; + private static /*final*/ GLProfile defaultGLProfile; /** All GLProfiles */ - private static final HashMap/**/ mappedProfiles; + private static /*final*/ HashMap/**/ mappedProfiles; /** * Tries the profiles implementation and native libraries. @@ -740,119 +795,174 @@ public class GLProfile implements Cloneable { AccessControlContext acc = AccessController.getContext(); isAWTAvailable = !Debug.getBooleanProperty("java.awt.headless", true, acc) && - NWReflection.isClassAvailable("java.awt.Component") ; + ReflectionUtil.isClassAvailable("java.awt.Component") ; isAWTJOGLAvailable = isAWTAvailable && - NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow - NWReflection.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL + ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow + ReflectionUtil.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL boolean hasDesktopGL = false; - boolean hasDesktopGLES12 = false; boolean hasNativeOSFactory = false; - + Throwable t; + + // + // First iteration of desktop GL availability detection + // - native libs exist + // - class exists + // + t=null; try { // See DRIHack.java for an explanation of why this is necessary DRIHack.begin(); - NativeLibLoader.loadGLDesktop(); + GLJNILibLoader.loadGLDesktop(); DRIHack.end(); hasDesktopGL = true; - } catch (Throwable t) { + } catch (UnsatisfiedLinkError ule) { + t=ule; + } catch (SecurityException se) { + t=se; + } catch (NullPointerException npe) { + t=npe; + } catch (RuntimeException re) { + t=re; + } + if(null!=t) { if (DEBUG) { System.err.println("GLProfile.static Desktop GL Library not available"); t.printStackTrace(); } } - try { - // See DRIHack.java for an explanation of why this is necessary - DRIHack.begin(); - NativeLibLoader.loadGLDesktopES12(); - DRIHack.end(); - hasDesktopGLES12 = true; - } catch (Throwable t) { - if (DEBUG) { - System.err.println("GLProfile.static Desktop GL ES12 Library not available"); - t.printStackTrace(); + hasGL234Impl = hasDesktopGL && ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); + hasGL4bcImpl = hasGL234Impl; + hasGL4Impl = hasGL234Impl; + hasGL3bcImpl = hasGL234Impl; + hasGL3Impl = hasGL234Impl; + hasGL2Impl = hasGL234Impl; + mappedProfiles = computeProfileMap(); + + // + // Second iteration of desktop GL availability detection + // utilizing the detected GL version in the shared context. + // + // - Instantiate GLDrawableFactory incl its shared dummy drawable/context, + // which will register at GLContext .. + // + + if(hasDesktopGL) { + // if successfull it has a shared dummy drawable and context created + try { + hasNativeOSFactory = null != GLDrawableFactory.getFactoryImpl(GL2); + } catch (RuntimeException re) { + System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); + re.printStackTrace(); } } - if(hasDesktopGL||hasDesktopGLES12) { - try { - hasNativeOSFactory = null!=GLDrawableFactory.getFactoryImpl(GL2); - } catch (Throwable t) { - if (DEBUG) { - System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); - t.printStackTrace(); - } - } + if(hasNativeOSFactory && !GLContext.mappedVersionsAvailableSet) { + // nobody yet set the available desktop versions, see {@link GLContextImpl#makeCurrent}, + // so we have to add the usual suspect + GLContext.mapVersionAvailable(2, true, 1, 5, GLContext.CTX_PROFILE_COMPAT|GLContext.CTX_OPTION_ANY); } if(!hasNativeOSFactory) { - hasDesktopGLES12=false; - hasDesktopGL=false; + hasDesktopGL = false; + hasGL234Impl = false; + hasGL4bcImpl = false; + hasGL4Impl = false; + hasGL3bcImpl = false; + hasGL3Impl = false; + hasGL2Impl = false; + } else { + hasGL4bcImpl = GLContext.isGL4bcAvailable(); + hasGL4Impl = GLContext.isGL4Available(); + hasGL3bcImpl = GLContext.isGL3bcAvailable(); + hasGL3Impl = GLContext.isGL3Available(); + hasGL2Impl = GLContext.isGL2Available(); } - // FIXME: check for real GL3 availability .. ? - hasGL4bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); - hasGL4Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4Impl"); - hasGL3bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3bcImpl"); - hasGL3Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3Impl"); - hasGL2Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2.GL2Impl"); - - hasGL2ES12Impl = hasDesktopGLES12 && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2es12.GL2ES12Impl"); - boolean btest = false; - boolean hasEGLDynLookup = NWReflection.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper"); + boolean hasEGLDynLookup = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper"); boolean hasEGLDrawableFactory = false; + t=null; try { if(hasEGLDynLookup) { hasEGLDrawableFactory = null!=GLDrawableFactory.getFactoryImpl(GLES2); - btest = hasEGLDrawableFactory && - NWReflection.isClassAvailable("com.jogamp.opengl.impl.es2.GLES2Impl") && - null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(2); + try { + btest = hasEGLDrawableFactory && + ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es2.GLES2Impl") && + null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(2); + } catch (GLException gle) { + // n/a .. + } } - } catch (Throwable t) { + } catch (UnsatisfiedLinkError ule) { + t=ule; + } catch (SecurityException se) { + t=se; + } catch (NullPointerException npe) { + t=npe; + } catch (RuntimeException re) { + t=re; + } + if(null!=t) { if (DEBUG) { System.err.println("GLProfile.static - GL ES2 Factory/Library not available"); t.printStackTrace(); } } hasGLES2Impl = btest; + if(hasGLES2Impl) { + GLContext.mapVersionAvailable(2, false, 2, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_PROFILE_CORE|GLContext.CTX_OPTION_ANY); + } btest = false; - try { - if(hasEGLDynLookup) { + if(hasEGLDynLookup) { + try { btest = hasEGLDrawableFactory && - NWReflection.isClassAvailable("com.jogamp.opengl.impl.es1.GLES1Impl") && + ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es1.GLES1Impl") && null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(1); - } - } catch (Throwable t) { - if (DEBUG) { - System.err.println("GLProfile.static - GL ES1 Factory/Library not available"); - t.printStackTrace(); + } catch (GLException jre) { + /* just not available .. */ } } hasGLES1Impl = btest; + if(hasGLES1Impl) { + GLContext.mapVersionAvailable(1, false, 1, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_PROFILE_CORE|GLContext.CTX_OPTION_ANY); + } + + mappedProfiles = computeProfileMap(); + if(null==defaultGLProfile) { + throw new GLException("No profile available: "+list2String(GL_PROFILE_LIST_ALL)); + } if (DEBUG) { System.err.println("GLProfile.static isAWTAvailable "+isAWTAvailable); System.err.println("GLProfile.static isAWTJOGLAvailable "+isAWTJOGLAvailable); System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); - System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); - System.err.println("GLProfile.static hasGL4bcImpl "+hasGL4bcImpl); - System.err.println("GLProfile.static hasGL4Impl "+hasGL4Impl); - System.err.println("GLProfile.static hasGL3bcImpl "+hasGL3bcImpl); - System.err.println("GLProfile.static hasGL3Impl "+hasGL3Impl); - System.err.println("GLProfile.static hasGL2Impl "+hasGL2Impl); - System.err.println("GLProfile.static hasGL2ES12Impl "+hasGL2ES12Impl); System.err.println("GLProfile.static hasEGLDynLookup "+hasEGLDynLookup); System.err.println("GLProfile.static hasEGLDrawableFactory "+hasEGLDrawableFactory); - System.err.println("GLProfile.static hasGLES2Impl "+hasGLES2Impl); - System.err.println("GLProfile.static hasGLES1Impl "+hasGLES1Impl); + System.err.println("GLProfile.static hasGL234Impl "+hasGL234Impl); + System.err.println("GLProfile.static "+glAvailabilityToString()); + } + } + + private static final String list2String(String[] list) { + StringBuffer msg = new StringBuffer(); + msg.append("["); + for (int i = 0; i < list.length; i++) { + if (i > 0) + msg.append(", "); + msg.append(list[i]); } + msg.append("]"); + return msg.toString(); + } + private static HashMap computeProfileMap() { + defaultGLProfile=null; HashMap/**/ _mappedProfiles = new HashMap(GL_PROFILE_LIST_ALL.length); for(int i=0; i 0) - msg.append(", "); - msg.append(list[i]); - } - msg.append("]"); - return msg.toString(); + return _mappedProfiles; } /** * Returns the profile implementation */ private static String computeProfileImpl(String profile) { - // FIXME Order of return profiles, after we can test their availability if (GL2ES1.equals(profile)) { - if(hasGL2ES12Impl) { - return GL2ES12; - } else if(hasGL2Impl) { + if(hasGL2Impl) { return GL2; + } else if(hasGL3bcImpl) { + return GL3bc; + } else if(hasGL4bcImpl) { + return GL4bc; } else if(hasGLES1Impl) { return GLES1; } } else if (GL2ES2.equals(profile)) { - if(hasGL2ES12Impl) { - return GL2ES12; - } else if(hasGL2Impl) { + if(hasGL2Impl) { return GL2; } else if(hasGL3Impl) { return GL3; - } else if(hasGL3bcImpl) { - return GL3bc; } else if(hasGL4Impl) { return GL4; - } else if(hasGL4bcImpl) { - return GL4bc; } else if(hasGLES2Impl) { return GLES2; } - } else if(GL4bc.equals(profile) && hasGL4bcImpl) { - return GL4bc; - } else if(GL4.equals(profile)) { - if(hasGL4Impl) { - return GL4; + } else if(GL2GL3.equals(profile)) { + if(hasGL2Impl) { + return GL2; + } else if(hasGL3bcImpl) { + return GL3bc; } else if(hasGL4bcImpl) { return GL4bc; + } else if(hasGL3Impl) { + return GL3; + } else if(hasGL4Impl) { + return GL4; } + } else if(GL4bc.equals(profile) && hasGL4bcImpl) { + return GL4bc; + } else if(GL4.equals(profile) && hasGL4Impl) { + return GL4; } else if(GL3bc.equals(profile) && hasGL3bcImpl) { return GL3bc; - } else if(GL3.equals(profile)) { - if(hasGL3Impl) { - return GL3; - } else if(hasGL3bcImpl) { - return GL3bc; - } + } else if(GL3.equals(profile) && hasGL3Impl) { + return GL3; } else if(GL2.equals(profile) && hasGL2Impl) { return GL2; - } else if(GL2GL3.equals(profile) && hasGL2Impl) { - return GL2; } else if(GLES2.equals(profile) && hasGLES2Impl) { return GLES2; } else if(GLES1.equals(profile) && hasGLES1Impl) { diff --git a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java new file mode 100755 index 000000000..a1ff0d860 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.test.junit.jogl.acore; + + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +public class TestGLProfile01CORE { + static GLProfile glp; + static GLDrawableFactory factory; + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + factory = GLDrawableFactory.getFactory(glp); + Assert.assertNotNull(factory); + } + + @AfterClass + public static void releaseClass() { + factory.shutdown(); + factory=null; + } + + @Test + public void test01GLProfileDefault() { + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + } + + @Test + public void test02GLProfileMaxFixedFunc() { + System.out.println("GLProfile getMaxFixedFunc(): "+GLProfile.getMaxFixedFunc()); + } + + @Test + public void test02GLProfileMaxProgrammable() { + System.out.println("GLProfile getMaxProgrammable(): "+GLProfile.getMaxProgrammable()); + } + + public static void main(String args[]) throws IOException { + String tstname = TestGLProfile01CORE.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java new file mode 100755 index 000000000..ac34b46b5 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.test.junit.jogl.awt; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.After; +import org.junit.Test; + +public class TestAWT01GLn { + Frame frame=null; + GLCanvas glCanvas=null; + + @Before + public void init() { + frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + } + + @After + public void release() { + Assert.assertNotNull(frame); + Assert.assertNotNull(glCanvas); + frame.setVisible(false); + frame.remove(glCanvas); + frame.dispose(); + frame=null; + glCanvas=null; + } + + protected void runTestGL(GLCapabilities caps) throws InterruptedException { + glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(512, 512); + + glCanvas.addGLEventListener(new Gears()); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + } + + @Test + public void test01GLDefault() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + /** Both fail on ATI .. if GLn n>2 + public void test02GL3bc() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3bc)); + runTestGL(caps); + } + + public void test03GLMaxFixed() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc()); + runTestGL(caps); + } */ + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestAWT01GLn.class.getName()); + } +} diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java index ec03bec95..459b41f16 100755 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java @@ -55,16 +55,16 @@ import com.jogamp.test.junit.jogl.demos.es1.RedSquare; import java.io.IOException; public class TestOffscreen01NEWT { - static GLProfile glp; + static GLProfile glpDefault; static GLDrawableFactory factory; static int width, height; - GLCapabilities caps; + GLCapabilities capsDefault; @BeforeClass public static void initClass() { - glp = GLProfile.getDefault(); - Assert.assertNotNull(glp); - factory = GLDrawableFactory.getFactory(glp); + glpDefault = GLProfile.getDefault(); + Assert.assertNotNull(glpDefault); + factory = GLDrawableFactory.getFactory(glpDefault); Assert.assertNotNull(factory); width = 640; height = 480; @@ -78,7 +78,8 @@ public class TestOffscreen01NEWT { @Before public void init() { - caps = new GLCapabilities(glp); + capsDefault = new GLCapabilities(glpDefault); + Assert.assertNotNull(capsDefault); } private void do01OffscreenWindowPBuffer(GLCapabilities caps) { @@ -115,20 +116,20 @@ public class TestOffscreen01NEWT { @Test public void test01aOffscreenWindowPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); do01OffscreenWindowPBuffer(caps2); } @Test public void test01bOffscreenWindowPBufferStencil() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); caps2.setStencilBits(8); do01OffscreenWindowPBuffer(caps2); } @Test public void test01cOffscreenWindowPBufferStencilAlpha() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); caps2.setStencilBits(8); caps2.setAlphaBits(8); do01OffscreenWindowPBuffer(caps2); @@ -136,7 +137,7 @@ public class TestOffscreen01NEWT { @Test public void test01cOffscreenWindowPBuffer555() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); caps2.setRedBits(5); caps2.setGreenBits(5); caps2.setBlueBits(5); @@ -145,7 +146,7 @@ public class TestOffscreen01NEWT { @Test public void test02Offscreen3Windows1DisplayPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); int winnum = 3, i; Window windows[] = new Window[winnum]; GLWindow glWindows[] = new GLWindow[winnum]; @@ -192,7 +193,7 @@ public class TestOffscreen01NEWT { @Test public void test03Offscreen3Windows3DisplaysPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); int winnum = 3, i; Display displays[] = new Display[winnum]; Screen screens[] = new Screen[winnum]; @@ -240,7 +241,7 @@ public class TestOffscreen01NEWT { @Test public void test04OffscreenSnapshotWithDemoPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); System.out.println("Create Window 1"); Display display = NewtFactory.createDisplay(null); // local display @@ -283,6 +284,12 @@ public class TestOffscreen01NEWT { @Test public void test11OffscreenWindowPixmap() { + // Offscreen doesn't work on >= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); Display display = NewtFactory.createDisplay(null); // local display @@ -318,6 +325,12 @@ public class TestOffscreen01NEWT { @Test public void test14OffscreenSnapshotWithDemoPixmap() { + // Offscreen doesn't work on >= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); System.out.println("Create Window 1"); diff --git a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java index 563c7f88e..4bbbaa271 100755 --- a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java @@ -93,7 +93,7 @@ public class TestTexture01AWT { frame.setVisible(true); animator.start(); - Thread.sleep(1000); // 1000 ms + Thread.sleep(500); // 500 ms animator.stop(); frame.setVisible(false); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java new file mode 100644 index 000000000..c3c04287a --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, Sven Gothel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Sven Gothel nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Sven Gothel BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jogamp.nativewindow.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.common.jvm.JNILibLoaderBase; + +public class NWJNILibLoader extends JNILibLoaderBase { + + public static void loadNativeWindow(final String ossuffix) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("nativewindow_"+ossuffix, null, false); + return null; + } + }); + } + +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java deleted file mode 100644 index 9bac9477a..000000000 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ - -package com.jogamp.nativewindow.impl; - -import java.lang.reflect.*; -import javax.media.nativewindow.*; - -public final class NWReflection { - - public static final boolean DEBUG = Debug.debug("NWReflection"); - - /** - * Returns true only if the class could be loaded. - */ - public static final boolean isClassAvailable(String clazzName) { - try { - return null != Class.forName(clazzName, false, NWReflection.class.getClassLoader()); - } catch (ClassNotFoundException e) { - return false; - } - } - - /** - * Loads and returns the class or null. - * @see Class#forName(java.lang.String, boolean, java.lang.ClassLoader) - */ - public static final Class getClass(String clazzName, boolean initialize) { - try { - return getClassImpl(clazzName, initialize); - } catch (ClassNotFoundException e) { - return null; - } - } - - private static Class getClassImpl(String clazzName, boolean initialize) throws ClassNotFoundException { - return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader()); - } - - /** - * @throws NativeWindowException if the constructor can not be delivered. - */ - public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { - try { - return getConstructor(getClassImpl(clazzName, true), cstrArgTypes); - } catch (ClassNotFoundException ex) { - throw new NativeWindowException(clazzName + " not available", ex); - } - } - - /** - * @throws NativeWindowException if the constructor can not be delivered. - */ - public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { - try { - return clazz.getDeclaredConstructor(cstrArgTypes); - } catch (NoSuchMethodException ex) { - String args = ""; - for (int i = 0; i < cstrArgTypes.length; i++) { - args += cstrArgTypes[i].getName(); - if(i != cstrArgTypes.length-1) { - args+= ", "; - } - } - throw new NativeWindowException("Constructor: '" + clazz + "(" + args + ")' not found", ex); - } - } - - public static final Constructor getConstructor(String clazzName) { - return getConstructor(clazzName, new Class[0]); - } - - /** - * @throws NativeWindowException if the instance can not be created. - */ - public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { - try { - return getConstructor(clazz, cstrArgTypes).newInstance(cstrArgs); - } catch (InstantiationException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); - } catch (InvocationTargetException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); - } catch (IllegalAccessException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); - } - } - - public static final Object createInstance(Class clazz, Object[] cstrArgs) { - Class[] cstrArgTypes = new Class[cstrArgs.length]; - for(int i=0; i=0; i--) { - Class face = clazzes[i]; - if(face.getName().equals(faceName)) { - return true; - } - } - clazz = clazz.getSuperclass(); - } while (clazz!=null); - return false; - } - - public static boolean isAWTComponent(Object target) { - return instanceOf(target, "java.awt.Component"); - } - - public static boolean isAWTComponent(Class clazz) { - return instanceOf(clazz, "java.awt.Component"); - } - -} - diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java deleted file mode 100644 index c4f1d7e08..000000000 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.nativewindow.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; - -public class NativeLibLoaderBase { - public static final boolean DEBUG = Debug.debug("NativeLibLoader"); - - public interface LoaderAction { - /** - * Loads the library specified by libname. Optionally preloads the libraries specified by - * preload. The implementation should ignore, if the preload-libraries have already been - * loaded. - * @param libname the library to load - * @param preload the libraries to load before loading the main library if not null - * @param preloadIgnoreError true, if errors during loading the preload-libraries should be ignored - */ - void loadLibrary(String libname, String[] preload, - boolean preloadIgnoreError); - } - - private static class DefaultAction implements LoaderAction { - public void loadLibrary(String libname, String[] preload, boolean preloadIgnoreError) { - if (null!=preload) { - for (int i=0; i - 4395095 JNI access to java.nio DirectBuffer constructor/accessor - 6852404 Race condition in JNI Direct Buffer access and creation routines - - * - * Make sure to initialize this class as soon as possible, - * before doing any multithreading work. - * - */ -public class JVMUtil { - private static final boolean DEBUG = Debug.debug("JVMUtil"); - - static { - NativeLibLoaderBase.loadNativeWindow("jvm"); - - ByteBuffer buffer = InternalBufferUtil.newByteBuffer(64); - if( ! initialize(buffer) ) { - throw new RuntimeException("Failed to initialize the JVMUtil "+Thread.currentThread().getName()); - } - if(DEBUG) { - Exception e = new Exception("JVMUtil.initSingleton() .. initialized "+Thread.currentThread().getName()); - e.printStackTrace(); - } - } - - public static void initSingleton() { - } - - private JVMUtil() {} - - private static native boolean initialize(java.nio.ByteBuffer buffer); -} - diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java index 41ffccc42..5f5c10885 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java @@ -53,7 +53,7 @@ public class X11Util { private static final boolean DEBUG = Debug.debug("X11Util"); static { - NativeLibLoaderBase.loadNativeWindow("x11"); + NWJNILibLoader.loadNativeWindow("x11"); installIOErrorHandler(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java index a8b67fddc..c692e51c4 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -35,6 +35,7 @@ package javax.media.nativewindow; import java.lang.reflect.*; import java.util.*; +import com.jogamp.common.util.*; import com.jogamp.nativewindow.impl.*; /** @@ -77,7 +78,7 @@ public abstract class GraphicsConfigurationFactory { if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { try { GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory) - NWReflection.createInstance("com.jogamp.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {}); + ReflectionUtil.createInstance("com.jogamp.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {}); registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, factory); } catch (Exception e) { throw new RuntimeException(e); diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 5b1bf54bb..944fdee74 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -36,8 +36,9 @@ import java.lang.reflect.*; import java.security.*; import java.util.*; +import com.jogamp.common.util.*; +import com.jogamp.common.jvm.JVMUtil; import com.jogamp.nativewindow.impl.*; -import com.jogamp.nativewindow.impl.jvm.JVMUtil; /** Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the {@link NativeWindow} interface, @@ -123,10 +124,10 @@ public abstract class NativeWindowFactory { // make it easier to run this code on mobile devices Class componentClass = null; - if ( NWReflection.isClassAvailable("java.awt.Component") && - NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) { + if ( ReflectionUtil.isClassAvailable("java.awt.Component") && + ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) { try { - componentClass = NWReflection.getClass("java.awt.Component", false); + componentClass = ReflectionUtil.getClass("java.awt.Component", false); } catch (Exception e) { } } @@ -177,7 +178,7 @@ public abstract class NativeWindowFactory { try { Constructor factoryConstructor = - NWReflection.getConstructor("com.jogamp.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {}); + ReflectionUtil.getConstructor("com.jogamp.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {}); _factory = (NativeWindowFactory) factoryConstructor.newInstance(null); } catch (Exception e) { } } @@ -185,7 +186,7 @@ public abstract class NativeWindowFactory { if (toolkitLockForced && null==_factory) { try { Constructor factoryConstructor = - NWReflection.getConstructor("com.jogamp.nativewindow.impl.LockingNativeWindowFactory", new Class[] {}); + ReflectionUtil.getConstructor("com.jogamp.nativewindow.impl.LockingNativeWindowFactory", new Class[] {}); _factory = (NativeWindowFactory) factoryConstructor.newInstance(null); } catch (Exception e) { } } diff --git a/src/nativewindow/native/JVM_Tool.c b/src/nativewindow/native/JVM_Tool.c deleted file mode 100644 index ce827129c..000000000 --- a/src/nativewindow/native/JVM_Tool.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -#include - -JNIEXPORT jboolean JNICALL -Java_com_jogamp_nativewindow_impl_jvm_JVMUtil_initialize(JNIEnv *env, jclass _unused, jobject nioBuffer) { - int res; - void * ptr = NULL; - if (nioBuffer != NULL) { - ptr = (void *) (*env)->GetDirectBufferAddress(env, nioBuffer); - } - return ( NULL==ptr ) ? JNI_FALSE : JNI_TRUE ; -} - diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c index 4320a8f12..52449ae84 100644 --- a/src/nativewindow/native/x11/Xmisc.c +++ b/src/nativewindow/native/x11/Xmisc.c @@ -128,6 +128,7 @@ static void _FatalError(JNIEnv *env, const char* msg, ...) va_end(ap); fprintf(stderr, buffer); + fprintf(stderr, "\n"); (*env)->FatalError(env, buffer); } @@ -201,32 +202,54 @@ static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, cons (*env)->ThrowNew(env, clazzRuntimeException, buffer); } +static JNIEnv * x11ErrorHandlerJNIEnv = NULL; +static XErrorHandler origErrorHandler = NULL ; + +static int x11ErrorHandler(Display *dpy, XErrorEvent *e) +{ + _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "Nativewindow X11 Error: Display %p, Code 0x%X", dpy, e->error_code); + + return 0; +} + +static void x11ErrorHandlerEnable(int onoff, JNIEnv * env) { + if(onoff) { + if(NULL==origErrorHandler) { + x11ErrorHandlerJNIEnv = env; + origErrorHandler = XSetErrorHandler(x11ErrorHandler); + } + } else { + XSetErrorHandler(origErrorHandler); + origErrorHandler = NULL; + } +} + + static XIOErrorHandler origIOErrorHandler = NULL; -static JNIEnv * displayIOErrorHandlerJNIEnv = NULL; -static int displayIOErrorHandler(Display *dpy) +static int x11IOErrorHandler(Display *dpy) { - _FatalError(displayIOErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p not available", dpy); + _FatalError(x11ErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p not available", dpy); origIOErrorHandler(dpy); return 0; } -static void displayIOErrorHandlerEnable(int onoff, JNIEnv * env) { +static void x11IOErrorHandlerEnable(int onoff, JNIEnv * env) { if(onoff) { if(NULL==origIOErrorHandler) { - displayIOErrorHandlerJNIEnv = env; - origIOErrorHandler = XSetIOErrorHandler(displayIOErrorHandler); + x11ErrorHandlerJNIEnv = env; + origIOErrorHandler = XSetIOErrorHandler(x11IOErrorHandler); } } else { XSetIOErrorHandler(origIOErrorHandler); origIOErrorHandler = NULL; - displayIOErrorHandlerJNIEnv = NULL; } } JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Util_installIOErrorHandler(JNIEnv *env, jclass _unused) { - displayIOErrorHandlerEnable(1, env); + x11ErrorHandlerEnable(1, env); + x11IOErrorHandlerEnable(1, env); } JNIEXPORT jlong JNICALL @@ -345,6 +368,7 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclas * Class: com_jogamp_nativewindow_impl_x11_X11Lib * Method: CreateDummyWindow * Signature: (JIJ)J + */ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummyWindow (JNIEnv *env, jobject obj, jlong display, jint screen_index, jlong visualID) { @@ -370,7 +394,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy } if(visualID<0) { - _throwNewRuntimeException(NULL, env, "invalid VisualID ..\n"); + _throwNewRuntimeException(NULL, env, "invalid VisualID .."); return 0; } @@ -396,7 +420,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy if (visual==NULL) { - _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!"); return 0; } @@ -440,13 +464,13 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy return (jlong) window; } - */ /* * Class: com_jogamp_nativewindow_impl_x11_X11Lib * Method: DestroyDummyWindow * Signature: (JJ)V + */ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummyWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { @@ -454,7 +478,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummy Window w = (Window) window; if(NULL==dpy) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); + _throwNewRuntimeException(NULL, env, "invalid display connection.."); return; } XLockDisplay(dpy) ; @@ -467,5 +491,3 @@ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummy XUnlockDisplay(dpy) ; } - */ - diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java index 2a696aa07..2d5c10c52 100755 --- a/src/newt/classes/com/jogamp/newt/NewtFactory.java +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -36,7 +36,7 @@ package com.jogamp.newt; import javax.media.nativewindow.*; import java.util.ArrayList; import java.util.Iterator; -import com.jogamp.nativewindow.impl.jvm.JVMUtil; +import com.jogamp.common.jvm.JVMUtil; public abstract class NewtFactory { // Work-around for initialization order problems on Mac OS X diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 8f09ae364..5123ab19f 100755 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -36,8 +36,8 @@ package com.jogamp.newt; import com.jogamp.newt.impl.Debug; import com.jogamp.newt.util.EDTUtil; +import com.jogamp.common.util.*; import javax.media.nativewindow.*; -import com.jogamp.nativewindow.impl.NWReflection; import java.util.ArrayList; import java.util.Iterator; @@ -127,7 +127,7 @@ public abstract class Window implements NativeWindow if ( argsChecked < cstrArguments.length ) { throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); } - Window window = (Window) NWReflection.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; + Window window = (Window) ReflectionUtil.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; window.invalidate(); window.screen = screen; window.setUndecorated(undecorated); @@ -144,7 +144,6 @@ public abstract class Window implements NativeWindow } return window; } catch (Throwable t) { - t.printStackTrace(); throw new NativeWindowException(t); } } diff --git a/src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java b/src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java new file mode 100644 index 000000000..a4d234fd5 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.newt.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.common.jvm.JNILibLoaderBase; + +public class NEWTJNILibLoader extends JNILibLoaderBase { + + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("newt", null, true); + return null; + } + }); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java b/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java deleted file mode 100644 index 52e4c0dc3..000000000 --- a/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.newt.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; -import com.jogamp.nativewindow.impl.NativeLibLoaderBase; - -public class NativeLibLoader extends NativeLibLoaderBase { - - public static void loadNEWT() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("newt", null, true); - return null; - } - }); - } - -} diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java index eb93943ee..a3e5501c4 100644 --- a/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java +++ b/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java @@ -40,7 +40,7 @@ public class Display extends com.jogamp.newt.Display { static int initCounter = 0; static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!Screen.initIDs()) { throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java index 2f86125f8..0b5297685 100755 --- a/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java +++ b/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java @@ -41,7 +41,7 @@ import com.jogamp.newt.util.MainThread; public class MacDisplay extends Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if(!initNSApplication()) { throw new NativeWindowException("Failed to initialize native Application hook"); diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java index a375181ac..999a407ec 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java +++ b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java @@ -41,7 +41,7 @@ import javax.media.nativewindow.egl.*; public class Display extends com.jogamp.newt.Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!Window.initIDs()) { throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java index b09568237..6a28f992b 100755 --- a/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java +++ b/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java @@ -42,7 +42,7 @@ import javax.media.nativewindow.egl.*; public class KDDisplay extends Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!KDWindow.initIDs()) { throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index 6cd4f8c69..daa09edce 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -43,10 +43,10 @@ import java.security.*; import javax.media.nativewindow.*; +import com.jogamp.common.util.*; import com.jogamp.newt.*; import com.jogamp.newt.impl.*; import com.jogamp.newt.macosx.MacDisplay; -import com.jogamp.nativewindow.impl.NWReflection; /** * NEWT Utility class MainThread

@@ -116,7 +116,7 @@ public class MainThread { // start user app .. try { - Class mainClass = NWReflection.getClass(mainClassName, true); + Class mainClass = ReflectionUtil.getClass(mainClassName, true); if(null==mainClass) { throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); } @@ -159,7 +159,7 @@ public class MainThread { System.arraycopy(args, 1, mainClassArgs, 0, args.length-1); } - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); shouldStop = false; tasks = new ArrayList(); diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java index 05cab1a0a..281022901 100755 --- a/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java +++ b/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java @@ -45,7 +45,7 @@ public class WindowsDisplay extends Display { private static long hInstance; static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!WindowsWindow.initIDs()) { throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/x11/X11Display.java index 5fd6d9640..c8faefbf1 100755 --- a/src/newt/classes/com/jogamp/newt/x11/X11Display.java +++ b/src/newt/classes/com/jogamp/newt/x11/X11Display.java @@ -41,7 +41,7 @@ import com.jogamp.nativewindow.impl.x11.X11Util; public class X11Display extends Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!initIDs()) { throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 33c5324e2..296172f6e 100755 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -159,11 +159,11 @@ static void _FatalError(JNIEnv *env, const char* msg, ...) va_end(ap); fprintf(stderr, buffer); + fprintf(stderr, "\n"); (*env)->FatalError(env, buffer); } -static const char * const ClazzNameRuntimeException = - "java/lang/RuntimeException"; +static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; static jclass runtimeExceptionClz=NULL; static const char * const ClazzNameNewtWindow = @@ -200,6 +200,7 @@ static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, cons */ +static JNIEnv * x11ErrorHandlerJNIEnv = NULL; static XErrorHandler origErrorHandler = NULL ; static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) @@ -213,15 +214,16 @@ static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) { fprintf(stderr, " BadWindow (%p): Window probably already removed\n", e->resourceid); } else { - return origErrorHandler(dpy, e); + _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "NEWT X11 Error: Display %p, Code 0x%X", dpy, e->error_code); } return 0; } -static void displayDispatchErrorHandlerEnable(int onoff) { +static void displayDispatchErrorHandlerEnable(int onoff, JNIEnv * env) { if(onoff) { if(NULL==origErrorHandler) { + x11ErrorHandlerJNIEnv = env; origErrorHandler = XSetErrorHandler(displayDispatchErrorHandler); } } else { @@ -329,13 +331,13 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_CompleteDisplay javaObjectAtom = (jlong) XInternAtom(dpy, "JOGL_JAVA_OBJECT", False); if(None==javaObjectAtom) { - _throwNewRuntimeException(dpy, env, "could not create Atom JOGL_JAVA_OBJECT, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not create Atom JOGL_JAVA_OBJECT, bail out!"); return; } windowDeleteAtom = (jlong) XInternAtom(dpy, "WM_DELETE_WINDOW", False); if(None==windowDeleteAtom) { - _throwNewRuntimeException(dpy, env, "could not create Atom WM_DELETE_WINDOW, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not create Atom WM_DELETE_WINDOW, bail out!"); return; } @@ -371,7 +373,7 @@ static void setJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, jlon { jobject test = (jobject) getPtrOut32Long(jogl_java_object_data); if( ! (jwindow==test) ) { - _throwNewRuntimeException(dpy, env, "Internal Error .. Encoded Window ref not the same %p != %p !\n", jwindow, test); + _throwNewRuntimeException(dpy, env, "Internal Error .. Encoded Window ref not the same %p != %p !", jwindow, test); return; } } @@ -415,7 +417,7 @@ static jobject getJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, j #ifdef VERBOSE_ON if(JNI_FALSE == (*env)->IsInstanceOf(env, jwindow, newtWindowClz)) { - _throwNewRuntimeException(dpy, env, "fetched Atom JOGL_JAVA_OBJECT window is not a NEWT Window: javaWindow 0x%X !\n", jwindow); + _throwNewRuntimeException(dpy, env, "fetched Atom JOGL_JAVA_OBJECT window is not a NEWT Window: javaWindow 0x%X !", jwindow); } #endif return jwindow; @@ -457,20 +459,20 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_DispatchMessages num_events--; if( 0==evt.xany.window ) { - _throwNewRuntimeException(dpy, env, "event window NULL, bail out!\n"); + _throwNewRuntimeException(dpy, env, "event window NULL, bail out!"); return ; } if(dpy!=evt.xany.display) { - _throwNewRuntimeException(dpy, env, "wrong display, bail out!\n"); + _throwNewRuntimeException(dpy, env, "wrong display, bail out!"); return ; } - displayDispatchErrorHandlerEnable(1); + displayDispatchErrorHandlerEnable(1, env); jwindow = getJavaWindowProperty(env, dpy, evt.xany.window, javaObjectAtom); - displayDispatchErrorHandlerEnable(0); + displayDispatchErrorHandlerEnable(0, env); if(NULL==jwindow) { fprintf(stderr, "Warning: NEWT X11 DisplayDispatch %p, Couldn't handle event %d for invalid X11 window %p\n", @@ -685,7 +687,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Window_CreateWindow } if(visualID<0) { - _throwNewRuntimeException(NULL, env, "invalid VisualID ..\n"); + _throwNewRuntimeException(NULL, env, "invalid VisualID .."); return 0; } @@ -712,7 +714,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Window_CreateWindow if (visual==NULL) { - _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!"); return 0; } @@ -797,11 +799,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_CloseWindow jwindow = getJavaWindowProperty(env, dpy, w, javaObjectAtom); if(NULL==jwindow) { - _throwNewRuntimeException(dpy, env, "could not fetch Java Window object, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not fetch Java Window object, bail out!"); return; } if ( JNI_FALSE == (*env)->IsSameObject(env, jwindow, obj) ) { - _throwNewRuntimeException(dpy, env, "Internal Error .. Window global ref not the same!\n"); + _throwNewRuntimeException(dpy, env, "Internal Error .. Window global ref not the same!"); return; } (*env)->DeleteGlobalRef(env, jwindow); -- cgit v1.2.3 From 012fca06f2539db232f0183f72187ec2f8ca54f5 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 22 Apr 2010 21:15:48 +0200 Subject: Review of using isGL2() and GL2.GL* --- .../com/jogamp/opengl/impl/glu/mipmap/Mipmap.java | 287 +++++++++++---------- .../impl/macosx/cgl/MacOSXOffscreenCGLContext.java | 2 +- .../impl/macosx/cgl/MacOSXPbufferCGLContext.java | 2 +- .../impl/macosx/cgl/MacOSXPbufferCGLDrawable.java | 4 +- .../impl/windows/wgl/WindowsPbufferWGLContext.java | 2 +- .../impl/x11/glx/X11OffscreenGLXContext.java | 2 +- .../com/jogamp/opengl/util/glsl/ShaderUtil.java | 2 +- .../com/jogamp/opengl/util/texture/Texture.java | 28 +- .../util/texture/spi/TGAImage.java.javame_cdc_fp | 8 +- .../opengl/util/texture/spi/TGAImage.java.javase | 8 +- src/jogl/classes/javax/media/opengl/GLContext.java | 10 +- 11 files changed, 178 insertions(+), 177 deletions(-) (limited to 'src/jogl/classes/javax/media/opengl/GLContext.java') diff --git a/src/jogl/classes/com/jogamp/opengl/impl/glu/mipmap/Mipmap.java b/src/jogl/classes/com/jogamp/opengl/impl/glu/mipmap/Mipmap.java index 2c3f60d32..1c0707c57 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/glu/mipmap/Mipmap.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/glu/mipmap/Mipmap.java @@ -46,6 +46,7 @@ package com.jogamp.opengl.impl.glu.mipmap; import javax.media.opengl.GL; import javax.media.opengl.GL2; +import javax.media.opengl.GL2GL3; import javax.media.opengl.glu.GLU; import javax.media.opengl.GLException; import java.nio.*; @@ -125,7 +126,7 @@ public class Mipmap { if( !legalFormat( format ) || !legalType( type ) ) { return( GLU.GLU_INVALID_ENUM ); } - if( format == GL2.GL_STENCIL_INDEX ) { + if( format == GL2GL3.GL_STENCIL_INDEX ) { return( GLU.GLU_INVALID_ENUM ); } if( !isLegalFormatForPackedPixelType( format, type ) ) { @@ -137,18 +138,18 @@ public class Mipmap { public static boolean legalFormat( int format ) { switch( format ) { case( GL2.GL_COLOR_INDEX ): - case( GL2.GL_STENCIL_INDEX ): - case( GL2.GL_DEPTH_COMPONENT ): - case( GL2.GL_RED ): - case( GL2.GL_GREEN ): - case( GL2.GL_BLUE ): - case( GL2.GL_ALPHA ): - case( GL2.GL_RGB ): - case( GL2.GL_RGBA ): - case( GL2.GL_LUMINANCE ): - case( GL2.GL_LUMINANCE_ALPHA ): - case( GL2.GL_BGR ): - case( GL2.GL_BGRA ): + case( GL2GL3.GL_STENCIL_INDEX ): + case( GL2GL3.GL_DEPTH_COMPONENT ): + case( GL2GL3.GL_RED ): + case( GL2GL3.GL_GREEN ): + case( GL2GL3.GL_BLUE ): + case( GL2GL3.GL_ALPHA ): + case( GL2GL3.GL_RGB ): + case( GL2GL3.GL_RGBA ): + case( GL2GL3.GL_LUMINANCE ): + case( GL2GL3.GL_LUMINANCE_ALPHA ): + case( GL2GL3.GL_BGR ): + case( GL2GL3.GL_BGRA ): return( true ); default: return( false ); @@ -158,25 +159,25 @@ public class Mipmap { public static boolean legalType( int type ) { switch( type ) { case( GL2.GL_BITMAP ): - case( GL2.GL_BYTE ): - case( GL2.GL_UNSIGNED_BYTE ): - case( GL2.GL_SHORT ): - case( GL2.GL_UNSIGNED_SHORT ): - case( GL2.GL_INT ): - case( GL2.GL_UNSIGNED_INT ): - case( GL2.GL_FLOAT ): - case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): - case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): - case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): - case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): - case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): - case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): - case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): - case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): - case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): - case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): - case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): - case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + case( GL2GL3.GL_BYTE ): + case( GL2GL3.GL_UNSIGNED_BYTE ): + case( GL2GL3.GL_SHORT ): + case( GL2GL3.GL_UNSIGNED_SHORT ): + case( GL2GL3.GL_INT ): + case( GL2GL3.GL_UNSIGNED_INT ): + case( GL2GL3.GL_FLOAT ): + case( GL2GL3.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2GL3.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ): return( true ); default: return( false ); @@ -186,18 +187,18 @@ public class Mipmap { public static boolean isTypePackedPixel( int type ) { assert( legalType( type ) ); - if( type == GL2.GL_UNSIGNED_BYTE_3_3_2 || - type == GL2.GL_UNSIGNED_BYTE_2_3_3_REV || - type == GL2.GL_UNSIGNED_SHORT_5_6_5 || - type == GL2.GL_UNSIGNED_SHORT_5_6_5_REV || - type == GL2.GL_UNSIGNED_SHORT_4_4_4_4 || - type == GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV || - type == GL2.GL_UNSIGNED_SHORT_5_5_5_1 || - type == GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV || - type == GL2.GL_UNSIGNED_INT_8_8_8_8 || - type == GL2.GL_UNSIGNED_INT_8_8_8_8_REV || - type == GL2.GL_UNSIGNED_INT_10_10_10_2 || - type == GL2.GL_UNSIGNED_INT_2_10_10_10_REV ) { + if( type == GL2GL3.GL_UNSIGNED_BYTE_3_3_2 || + type == GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5 || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8 || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL2GL3.GL_UNSIGNED_INT_10_10_10_2 || + type == GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ) { return( true ); } return( false ); @@ -210,23 +211,23 @@ public class Mipmap { } // 3_3_2/2_3_3_REV & 5_6_5/5_6_5_REV are only compatible with RGB - if( (type == GL2.GL_UNSIGNED_BYTE_3_3_2 || type == GL2.GL_UNSIGNED_BYTE_2_3_3_REV || - type == GL2.GL_UNSIGNED_SHORT_5_6_5 || type == GL2.GL_UNSIGNED_SHORT_5_6_5_REV ) - & format != GL2.GL_RGB ) { + if( (type == GL2GL3.GL_UNSIGNED_BYTE_3_3_2 || type == GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5 || type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV ) + & format != GL2GL3.GL_RGB ) { return( false ); } // 4_4_4_4/4_4_4_4_REV & 5_5_5_1/1_5_5_5_REV & 8_8_8_8/8_8_8_8_REV & // 10_10_10_2/2_10_10_10_REV are only campatible with RGBA, BGRA & ARGB_EXT - if( ( type == GL2.GL_UNSIGNED_SHORT_4_4_4_4 || - type == GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV || - type == GL2.GL_UNSIGNED_SHORT_5_5_5_1 || - type == GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV || - type == GL2.GL_UNSIGNED_INT_8_8_8_8 || - type == GL2.GL_UNSIGNED_INT_8_8_8_8_REV || - type == GL2.GL_UNSIGNED_INT_10_10_10_2 || - type == GL2.GL_UNSIGNED_INT_2_10_10_10_REV ) && - (format != GL2.GL_RGBA && format != GL2.GL_BGRA) ) { + if( ( type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8 || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL2GL3.GL_UNSIGNED_INT_10_10_10_2 || + type == GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ) && + (format != GL2GL3.GL_RGBA && format != GL2GL3.GL_BGRA) ) { return( false ); } return( true ); @@ -272,27 +273,27 @@ public class Mipmap { assert( heightAtLevelOne > 0 ); // does width x height at level 1 & all their mipmaps fit? - if( target == GL2.GL_TEXTURE_2D || target == GL2.GL_PROXY_TEXTURE_2D ) { - proxyTarget = GL2.GL_PROXY_TEXTURE_2D; + if( target == GL2GL3.GL_TEXTURE_2D || target == GL2GL3.GL_PROXY_TEXTURE_2D ) { + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_2D; gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, heightAtLevelOne, 0, format, type, null ); - } else if( (target == GL2.GL_TEXTURE_CUBE_MAP_POSITIVE_X) || - (target == GL2.GL_TEXTURE_CUBE_MAP_NEGATIVE_X) || - (target == GL2.GL_TEXTURE_CUBE_MAP_POSITIVE_Y) || - (target == GL2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) || - (target == GL2.GL_TEXTURE_CUBE_MAP_POSITIVE_Z) || - (target == GL2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) ) { - proxyTarget = GL2.GL_PROXY_TEXTURE_CUBE_MAP; + } else if( (target == GL2GL3.GL_TEXTURE_CUBE_MAP_POSITIVE_X) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_NEGATIVE_X) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_POSITIVE_Y) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_POSITIVE_Z) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) ) { + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_CUBE_MAP; gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, heightAtLevelOne, 0, format, type, null ); } else { - assert( target == GL2.GL_TEXTURE_1D || target == GL2.GL_PROXY_TEXTURE_1D ); - proxyTarget = GL2.GL_PROXY_TEXTURE_1D; - gl.getGL2().glTexImage1D( proxyTarget, 1, internalFormat, widthAtLevelOne, + assert( target == GL2GL3.GL_TEXTURE_1D || target == GL2GL3.GL_PROXY_TEXTURE_1D ); + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_1D; + gl.getGL2GL3().glTexImage1D( proxyTarget, 1, internalFormat, widthAtLevelOne, 0, format, type, null ); } - if(gl.isGL2()) { - gl.getGL2().glGetTexLevelParameteriv( proxyTarget, 1, GL2.GL_TEXTURE_WIDTH, proxyWidth, 0 ); + if(gl.isGL2GL3()) { + gl.getGL2GL3().glGetTexLevelParameteriv( proxyTarget, 1, GL2GL3.GL_TEXTURE_WIDTH, proxyWidth, 0 ); } else { proxyWidth[0] = 0; } @@ -324,7 +325,7 @@ public class Mipmap { } } int[] maxsize = new int[1]; - gl.glGetIntegerv( GL2.GL_MAX_TEXTURE_SIZE, maxsize , 0); + gl.glGetIntegerv( GL2GL3.GL_MAX_TEXTURE_SIZE, maxsize , 0); // clamp user's texture sizes to maximum sizes, if necessary newWidth[0] = nearestPower( width ); if( newWidth[0] > maxsize[0] ) { @@ -355,13 +356,13 @@ public class Mipmap { assert( depthAtLevelOne > 0 ); // does width x height x depth at level 1 & all their mipmaps fit? - if( target == GL2.GL_TEXTURE_3D || target == GL2.GL_PROXY_TEXTURE_3D ) { - proxyTarget = GL2.GL_PROXY_TEXTURE_3D; - gl.getGL2().glTexImage3D( proxyTarget, 1, internalFormat, widthAtLevelOne, + if( target == GL2GL3.GL_TEXTURE_3D || target == GL2GL3.GL_PROXY_TEXTURE_3D ) { + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_3D; + gl.getGL2GL3().glTexImage3D( proxyTarget, 1, internalFormat, widthAtLevelOne, heightAtLevelOne, depthAtLevelOne, 0, format, type, null ); } - if(gl.isGL2()) { - gl.getGL2().glGetTexLevelParameteriv( proxyTarget, 1, GL2.GL_TEXTURE_WIDTH, proxyWidth, 0 ); + if(gl.isGL2GL3()) { + gl.getGL2GL3().glGetTexLevelParameteriv( proxyTarget, 1, GL2GL3.GL_TEXTURE_WIDTH, proxyWidth, 0 ); } else { proxyWidth[0] = 0; } @@ -388,30 +389,30 @@ public class Mipmap { // Return the number of elements per grtoup of a specified gromat // If the type is packedpixels then answer is 1 - if( type == GL2.GL_UNSIGNED_BYTE_3_3_2 || - type == GL2.GL_UNSIGNED_BYTE_2_3_3_REV || - type == GL2.GL_UNSIGNED_SHORT_5_6_5 || - type == GL2.GL_UNSIGNED_SHORT_5_6_5_REV || - type == GL2.GL_UNSIGNED_SHORT_4_4_4_4 || - type == GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV || - type == GL2.GL_UNSIGNED_SHORT_5_5_5_1 || - type == GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV || - type == GL2.GL_UNSIGNED_INT_8_8_8_8 || - type == GL2.GL_UNSIGNED_INT_8_8_8_8_REV || - type == GL2.GL_UNSIGNED_INT_10_10_10_2 || - type == GL2.GL_UNSIGNED_INT_2_10_10_10_REV ) { + if( type == GL2GL3.GL_UNSIGNED_BYTE_3_3_2 || + type == GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5 || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8 || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL2GL3.GL_UNSIGNED_INT_10_10_10_2 || + type == GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ) { return( 1 ); } // Types are not packed pixels so get elements per group switch( format ) { - case( GL2.GL_RGB ): - case( GL2.GL_BGR ): + case( GL2GL3.GL_RGB ): + case( GL2GL3.GL_BGR ): return( 3 ); - case( GL2.GL_LUMINANCE_ALPHA ): + case( GL2GL3.GL_LUMINANCE_ALPHA ): return( 2 ); - case( GL2.GL_RGBA ): - case( GL2.GL_BGRA ): + case( GL2GL3.GL_RGBA ): + case( GL2GL3.GL_BGRA ): return( 4 ); default: return( 1 ); @@ -423,27 +424,27 @@ public class Mipmap { switch( type ) { case( GL2.GL_BITMAP ): - case( GL2.GL_BYTE ): - case( GL2.GL_UNSIGNED_BYTE ): - case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): - case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2GL3.GL_BYTE ): + case( GL2GL3.GL_UNSIGNED_BYTE ): + case( GL2GL3.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV ): return( 1 ); - case( GL2.GL_SHORT ): - case( GL2.GL_UNSIGNED_SHORT ): - case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): - case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): - case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): - case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): - case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): - case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2GL3.GL_SHORT ): + case( GL2GL3.GL_UNSIGNED_SHORT ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV ): return( 2 ); - case( GL2.GL_INT ): - case( GL2.GL_UNSIGNED_INT ): - case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): - case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): - case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): - case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - case( GL2.GL_FLOAT ): + case( GL2GL3.GL_INT ): + case( GL2GL3.GL_UNSIGNED_INT ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2GL3.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ): + case( GL2GL3.GL_FLOAT ): return( 4 ); default: return( 4 ); @@ -451,7 +452,7 @@ public class Mipmap { } public static boolean is_index( int format ) { - return( format == GL2.GL_COLOR_INDEX || format == GL2.GL_STENCIL_INDEX ); + return( format == GL2.GL_COLOR_INDEX || format == GL2GL3.GL_STENCIL_INDEX ); } /* Compute memory required for internal packed array of data of given type and format. */ @@ -483,67 +484,67 @@ public class Mipmap { public static void retrieveStoreModes( GL gl, PixelStorageModes psm ) { int[] a = new int[1]; - gl.glGetIntegerv( GL2.GL_UNPACK_ALIGNMENT, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ALIGNMENT, a, 0); psm.setUnpackAlignment( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_ROW_LENGTH, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ROW_LENGTH, a, 0); psm.setUnpackRowLength( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_SKIP_ROWS, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_ROWS, a, 0); psm.setUnpackSkipRows( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_SKIP_PIXELS, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_PIXELS, a, 0); psm.setUnpackSkipPixels( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_LSB_FIRST, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_LSB_FIRST, a, 0); psm.setUnpackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL2.GL_UNPACK_SWAP_BYTES, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SWAP_BYTES, a, 0); psm.setUnpackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL2.GL_PACK_ALIGNMENT, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_ALIGNMENT, a, 0); psm.setPackAlignment( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_ROW_LENGTH, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_ROW_LENGTH, a, 0); psm.setPackRowLength( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_SKIP_ROWS, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_ROWS, a, 0); psm.setPackSkipRows( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_SKIP_PIXELS, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_PIXELS, a, 0); psm.setPackSkipPixels( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_LSB_FIRST, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_LSB_FIRST, a, 0); psm.setPackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL2.GL_PACK_SWAP_BYTES, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_SWAP_BYTES, a, 0); psm.setPackSwapBytes( ( a[0] == 1 ) ); } public static void retrieveStoreModes3D( GL gl, PixelStorageModes psm ) { int[] a = new int[1]; - gl.glGetIntegerv( GL2.GL_UNPACK_ALIGNMENT, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ALIGNMENT, a, 0); psm.setUnpackAlignment( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_ROW_LENGTH, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ROW_LENGTH, a, 0); psm.setUnpackRowLength( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_SKIP_ROWS, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_ROWS, a, 0); psm.setUnpackSkipRows( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_SKIP_PIXELS, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_PIXELS, a, 0); psm.setUnpackSkipPixels( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_LSB_FIRST, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_LSB_FIRST, a, 0); psm.setUnpackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL2.GL_UNPACK_SWAP_BYTES, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SWAP_BYTES, a, 0); psm.setUnpackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL2.GL_UNPACK_SKIP_IMAGES, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_IMAGES, a, 0); psm.setUnpackSkipImages( a[0] ); - gl.glGetIntegerv( GL2.GL_UNPACK_IMAGE_HEIGHT, a, 0); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_IMAGE_HEIGHT, a, 0); psm.setUnpackImageHeight( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_ALIGNMENT, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_ALIGNMENT, a, 0); psm.setPackAlignment( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_ROW_LENGTH, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_ROW_LENGTH, a, 0); psm.setPackRowLength( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_SKIP_ROWS, a, 0); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_ROWS, a, 0); psm.setPackSkipRows( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_SKIP_PIXELS, a, 0 ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_PIXELS, a, 0 ); psm.setPackSkipPixels( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_LSB_FIRST, a, 0 ); + gl.glGetIntegerv( GL2GL3.GL_PACK_LSB_FIRST, a, 0 ); psm.setPackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL2.GL_PACK_SWAP_BYTES, a, 0 ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SWAP_BYTES, a, 0 ); psm.setPackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL2.GL_PACK_SKIP_IMAGES, a, 0 ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_IMAGES, a, 0 ); psm.setPackSkipImages( a[0] ); - gl.glGetIntegerv( GL2.GL_PACK_IMAGE_HEIGHT, a, 0 ); + gl.glGetIntegerv( GL2GL3.GL_PACK_IMAGE_HEIGHT, a, 0 ); psm.setPackImageHeight( a[0] ); } @@ -574,8 +575,8 @@ public class Mipmap { if( !isLegalFormatForPackedPixelType( format, typeout ) ) { return( GLU.GLU_INVALID_OPERATION ); } - beforeimage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthin, heightin, format, GL2.GL_UNSIGNED_SHORT ) )); - afterimage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthout, heightout, format, GL2.GL_UNSIGNED_SHORT ) )); + beforeimage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthin, heightin, format, GL2GL3.GL_UNSIGNED_SHORT ) )); + afterimage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthout, heightout, format, GL2GL3.GL_UNSIGNED_SHORT ) )); if( beforeimage == null || afterimage == null ) { return( GLU.GLU_OUT_OF_MEMORY ); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOffscreenCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOffscreenCGLContext.java index 8b8bb46fa..89e293665 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOffscreenCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOffscreenCGLContext.java @@ -51,7 +51,7 @@ public class MacOSXOffscreenCGLContext extends MacOSXPbufferCGLContext public int getOffscreenContextPixelDataType() { GL gl = getGL(); - return gl.isGL2()?GL2.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; + return gl.isGL2GL3()?GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; } public int getOffscreenContextReadBuffer() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java index e90672a1d..52a892b70 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java @@ -80,7 +80,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); GLCapabilities capabilities = (GLCapabilities)config.getChosenCapabilities(); GL gl = getGL(); - boolean rect = gl.isGL2() && capabilities.getPbufferRenderToTextureRectangle(); + boolean rect = gl.isGL2GL3() && capabilities.getPbufferRenderToTextureRectangle(); if (rect) { if (!gl.isExtensionAvailable("GL_EXT_texture_rectangle")) { System.err.println("MacOSXPbufferCGLContext: WARNING: GL_EXT_texture_rectangle extension not " + diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java index b02cea03e..afdc40dbb 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -112,7 +112,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { GLCapabilities capabilities = (GLCapabilities)config.getChosenCapabilities(); GLProfile glProfile = capabilities.getGLProfile(); int renderTarget; - if (glProfile.isGL2() && capabilities.getPbufferRenderToTextureRectangle()) { + if (glProfile.isGL2GL3() && capabilities.getPbufferRenderToTextureRectangle()) { renderTarget = GL2.GL_TEXTURE_RECTANGLE; } else { int w = getNextPowerOf2(getWidth()); @@ -132,7 +132,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { throw new GLException("Floating-point support (GL_APPLE_float_pixels) not available"); } */ - if(glProfile.isGL2()) { + if(glProfile.isGL2GL3()) { switch (capabilities.getRedBits()) { case 16: internalFormat = GL2.GL_RGBA_FLOAT16_APPLE; break; case 32: internalFormat = GL2.GL_RGBA_FLOAT32_APPLE; break; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java index b0524bcd9..a9e02e11f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java @@ -101,7 +101,7 @@ public class WindowsPbufferWGLContext extends WindowsWGLContext { // Initialize render-to-texture support if requested GL gl = getGL(); rtt = capabilities.getPbufferRenderToTexture(); - rect = gl.isGL2() && capabilities.getPbufferRenderToTextureRectangle(); + rect = gl.isGL2GL3() && capabilities.getPbufferRenderToTextureRectangle(); if (rtt) { if (DEBUG) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXContext.java index 306a711bd..bea953ee9 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXContext.java @@ -54,7 +54,7 @@ public class X11OffscreenGLXContext extends X11GLXContext { public int getOffscreenContextPixelDataType() { GL gl = getGL(); - return gl.isGL2()?GL2.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; + return gl.isGL2GL3()?GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; } public int getOffscreenContextReadBuffer() { diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java index 21f359f52..c7e845953 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java @@ -221,7 +221,7 @@ public class ShaderUtil { v = true; } shaderCompilerAvailable = new Boolean(v); - } else if( gl.isGL2() || gl.isGL2ES2() ) { + } else if( gl.isGL2ES2() ) { shaderCompilerAvailable = new Boolean(true); } else { throw new GLException("Invalid OpenGL profile"); diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java index 5ef96eeaf..57ac0d45a 100755 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java @@ -487,7 +487,7 @@ public class Texture { } if (!done && preferTexRect(gl) && !isPOT && - haveTexRect(gl) && !data.isDataCompressed() && gl.isGL2()) { + haveTexRect(gl) && !data.isDataCompressed() && !gl.isGL3() && !gl.isGLES()) { // GL_ARB_texture_rectangle does not work for compressed textures if (DEBUG) { System.err.println("Using GL_ARB_texture_rectangle preferentially on this hardware"); @@ -514,7 +514,7 @@ public class Texture { done = true; } - if (!done && haveTexRect(gl) && !data.isDataCompressed() && gl.isGL2()) { + if (!done && haveTexRect(gl) && !data.isDataCompressed() && !gl.isGL3() && !gl.isGLES()) { // GL_ARB_texture_rectangle does not work for compressed textures if (DEBUG) { System.err.println("Using GL_ARB_texture_rectangle"); @@ -1013,10 +1013,10 @@ public class Texture { int[] skipRows = { 0 }; int[] skipPixels = { 0 }; gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, align, 0); // save alignment - if(gl.isGL2()) { - gl.glGetIntegerv(GL2.GL_UNPACK_ROW_LENGTH, rowLength, 0); // save row length - gl.glGetIntegerv(GL2.GL_UNPACK_SKIP_ROWS, skipRows, 0); // save skipped rows - gl.glGetIntegerv(GL2.GL_UNPACK_SKIP_PIXELS, skipPixels, 0); // save skipped pixels + if(gl.isGL2GL3()) { + gl.glGetIntegerv(GL2GL3.GL_UNPACK_ROW_LENGTH, rowLength, 0); // save row length + gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_ROWS, skipRows, 0); // save skipped rows + gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_PIXELS, skipPixels, 0); // save skipped pixels } gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, data.getAlignment()); if (DEBUG && VERBOSE) { @@ -1028,10 +1028,10 @@ public class Texture { System.out.println("width = " + width); System.out.println("height = " + height); } - if(gl.isGL2()) { - gl.glPixelStorei(GL2.GL_UNPACK_ROW_LENGTH, rowlen); - gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, srcy); - gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, srcx); + if(gl.isGL2GL3()) { + gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, rowlen); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, srcy); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, srcx); } else { if ( rowlen!=0 && rowlen!=width && srcy!=0 && srcx!=0 ) { @@ -1044,10 +1044,10 @@ public class Texture { data.getPixelFormat(), data.getPixelType(), buffer); gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, align[0]); // restore alignment - if(gl.isGL2()) { - gl.glPixelStorei(GL2.GL_UNPACK_ROW_LENGTH, rowLength[0]); // restore row length - gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, skipRows[0]); // restore skipped rows - gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, skipPixels[0]); // restore skipped pixels + if(gl.isGL2GL3()) { + gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, rowLength[0]); // restore row length + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, skipRows[0]); // restore skipped rows + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, skipPixels[0]); // restore skipped pixels } } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp index d1eca7c69..6e6e4ab04 100755 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javame_cdc_fp @@ -308,8 +308,8 @@ public class TGAImage { GL gl = GLContext.getCurrentGL(); if (header.pixelDepth() == 24) { bpp=3; - if(gl.isGL2()) { - format = GL2.GL_BGR; + if(gl.isGL2GL3()) { + format = GL2GL3.GL_BGR; } else { format = GL.GL_RGB; swapBGR(tmpData, rawWidth, header.height(), bpp); @@ -318,8 +318,8 @@ public class TGAImage { assert header.pixelDepth() == 32; bpp=4; - if(gl.isGL2()) { - format = GL2.GL_BGRA; + if(gl.isGL2GL3()) { + format = GL2GL3.GL_BGRA; } else { format = GL.GL_RGBA; swapBGR(tmpData, rawWidth, header.height(), bpp); diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javase b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javase index 8575f553d..16ba538b5 100755 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javase +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java.javase @@ -310,8 +310,8 @@ public class TGAImage { GL gl = GLContext.getCurrentGL(); if (header.pixelDepth() == 24) { bpp=3; - if(gl.isGL2()) { - format = GL2.GL_BGR; + if(gl.isGL2GL3()) { + format = GL2GL3.GL_BGR; } else { format = GL.GL_RGB; swapBGR(tmpData, rawWidth, header.height(), bpp); @@ -320,8 +320,8 @@ public class TGAImage { assert header.pixelDepth() == 32; bpp=4; - if(gl.isGL2()) { - format = GL2.GL_BGRA; + if(gl.isGL2GL3()) { + format = GL2GL3.GL_BGRA; } else { format = GL.GL_RGBA; swapBGR(tmpData, rawWidth, header.height(), bpp); diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index e5b499af9..2709dd506 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -378,6 +378,10 @@ public abstract class GLContext { return ctxMajorVersion>=1 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES)); } + public final boolean isGL2GL3() { + return isGL2() || isGL3(); + } + public final boolean isGLES1() { return ctxMajorVersion==1 && CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES); } @@ -395,11 +399,7 @@ public abstract class GLContext { } public final boolean isGL2ES2() { - return isGL2() || isGL3() || isGLES2() ; - } - - public final boolean isGL2GL3() { - return isGL2() || isGL3(); + return isGL2GL3() || isGLES2() ; } public final boolean hasGLSL() { -- cgit v1.2.3