diff options
author | Mark Raynsford <[email protected]> | 2013-07-03 20:46:23 +0000 |
---|---|---|
committer | Mark Raynsford <[email protected]> | 2013-07-03 20:46:23 +0000 |
commit | 9afc340e1e81cec6fa6deda3fe548fd2fa1d8e5f (patch) | |
tree | 1edd169f74002ad0444ee8b3269358564fd8e961 /src/jogl/classes/javax | |
parent | 1455848398ccdfa89ec9f19379c5dcaed8198e28 (diff) | |
parent | de2905a6fce37e7caf69b148ef4cf7f347559530 (diff) |
Merge branch 'master' of ssh://jogamp.org/srv/scm/jogl into mark
Diffstat (limited to 'src/jogl/classes/javax')
-rw-r--r-- | src/jogl/classes/javax/media/opengl/GLContext.java | 20 | ||||
-rw-r--r-- | src/jogl/classes/javax/media/opengl/awt/GLJPanel.java | 65 |
2 files changed, 71 insertions, 14 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index cc37da0ff..84d371ac6 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -131,16 +131,16 @@ public abstract class GLContext { /* Version 1.50, i.e. GLSL 1.50 for GL 3.2. */ public static final VersionNumber Version150 = new VersionNumber(1, 50, 0); - /** Version 3.2. As an OpenGL version, it qualifies for geometry shader */ - public static final VersionNumber Version32 = new VersionNumber(3, 2, 0); + /** Version 3.0. As an OpenGL version, it qualifies for desktop {@link #isGL2()} only, or ES 3.0. */ + public static final VersionNumber Version300 = new VersionNumber(3, 0, 0); /** Version 3.1. As an OpenGL version, it qualifies for {@link #isGL3core()}, {@link #isGL3bc()} and {@link #isGL3()} */ - public static final VersionNumber Version31 = new VersionNumber(3, 1, 0); + public static final VersionNumber Version310 = new VersionNumber(3, 1, 0); - /** Version 3.0. As an OpenGL version, it qualifies for {@link #isGL2()} only */ - public static final VersionNumber Version30 = new VersionNumber(3, 0, 0); + /** Version 3.2. As an OpenGL version, it qualifies for geometry shader */ + public static final VersionNumber Version320 = new VersionNumber(3, 2, 0); - protected static final VersionNumber Version80 = new VersionNumber(8, 0, 0); + protected static final VersionNumber Version800 = new VersionNumber(8, 0, 0); /** <code>ARB_create_context</code> related: created via ARB_create_context. Cache key value. See {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */ protected static final int CTX_IS_ARB_CREATED = 1 << 0; @@ -753,7 +753,7 @@ public abstract class GLContext { return ""; } final int minor = ctxGLSLVersion.getMinor(); - final String esSuffix = isGLES() && ctxGLSLVersion.compareTo(Version30) >= 0 ? " es" : ""; + final String esSuffix = isGLES() && ctxGLSLVersion.compareTo(Version300) >= 0 ? " es" : ""; return "#version " + ctxGLSLVersion.getMajor() + ( minor < 10 ? "0"+minor : minor ) + esSuffix + "\n" ; } @@ -899,21 +899,21 @@ public abstract class GLContext { /** @see GLProfile#isGL3bc() */ public final boolean isGL3bc() { - return ctxVersion.compareTo(Version31) >= 0 + return ctxVersion.compareTo(Version310) >= 0 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) && 0 != (ctxOptions & CTX_PROFILE_COMPAT); } /** @see GLProfile#isGL3() */ public final boolean isGL3() { - return ctxVersion.compareTo(Version31) >= 0 + return ctxVersion.compareTo(Version310) >= 0 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) && 0 != (ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_CORE)); } /** Indicates whether this profile is capable of GL3 (core only). GL3 starts w/ OpenGL 3.1 <p>Includes [ GL4, GL3 ].</p> */ public final boolean isGL3core() { - return ctxVersion.compareTo(Version31) >= 0 + return ctxVersion.compareTo(Version310) >= 0 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) && 0 != (ctxOptions & CTX_PROFILE_CORE); } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index b11f359be..d3f20b2e5 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -110,6 +110,7 @@ import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.SingleAWTGLPixelBufferProvide <P> In case FBO is used and GLSL is available, a fragment shader is utilized to flip the FBO texture vertically. This hardware-accelerated step can be disabled via system property <code>jogl.gljpanel.noglsl</code>. + See <a href="#fboGLSLVerticalFlip">details here</a>. </P> <P> The OpenGL path is concluded by copying the rendered pixels an {@link BufferedImage} via {@link GL#glReadPixels(int, int, int, int, int, int, java.nio.Buffer) glReadPixels(..)} @@ -125,8 +126,14 @@ import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.SingleAWTGLPixelBufferProvide on the prepared {@link BufferedImage} as described above. </p> <P> - * Please read <A HREF="GLCanvas.html#java2dgl">Java2D OpenGL Remarks</A>. + * Please read <a href="GLCanvas.html#java2dgl">Java2D OpenGL Remarks</a>. * </P> + * + <a name="fboGLSLVerticalFlip"><h5>FBO / GLSL Vertical Flip</h5></a> + The FBO / GLSL code path uses one texture-unit and binds the FBO texture to it's active texture-target, + see {@link #setTextureUnit(int)} and {@link #getTextureUnit()}. + If the application uses the same texture-unit, ensure it setup their texture properly, i.e. texture-unit bind, enable and then it's parameters, + see {@link Texture#textureCallOrder Order of Texture Commands}. */ @SuppressWarnings("serial") @@ -212,6 +219,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private int viewportX; private int viewportY; + private int requestedTextureUnit = 0; // default + // The backend in use private volatile Backend backend; @@ -731,6 +740,40 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing return factory; } + /** + * Returns the used texture unit, i.e. a value of [0..n], or -1 if non used. + * <p> + * If implementation uses a texture-unit, it will be known only after the first initialization, i.e. display call. + * </p> + * <p> + * See <a href="#fboGLSLVerticalFlip">FBO / GLSL Vertical Flip</a>. + * </p> + */ + public final int getTextureUnit() { + final Backend b = backend; + if ( null == b ) { + return -1; + } + return b.getTextureUnit(); + } + + /** + * Allows user to request a texture unit to be used, + * must be called before the first initialization, i.e. {@link #display()} call. + * <p> + * Defaults to <code>0</code>. + * </p> + * <p> + * See <a href="#fboGLSLVerticalFlip">FBO / GLSL Vertical Flip</a>. + * </p> + * + * @param v requested texture unit + * @see #getTextureUnit() + */ + public final void setTextureUnit(int v) { + requestedTextureUnit = v; + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -947,6 +990,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing // Called to get the current backend's GLDrawable public GLDrawable getDrawable(); + /** Returns the used texture unit, i.e. a value of [0..n], or -1 if non used. */ + public int getTextureUnit(); + // Called to fetch the "real" GLCapabilities for the backend public GLCapabilitiesImmutable getChosenGLCapabilities(); @@ -987,7 +1033,6 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private GLDrawableImpl offscreenDrawable; private FBObject fboFlipped; private GLSLTextureRaster glslTextureRaster; - private final int fboTextureUnit = 0; private GLContextImpl offscreenContext; private boolean flipVertical; @@ -1035,12 +1080,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing final boolean _autoSwapBufferMode = helper.getAutoSwapBufferMode(); helper.setAutoSwapBufferMode(false); final GLFBODrawable fboDrawable = (GLFBODrawable) offscreenDrawable; + fboDrawable.setTextureUnit( GLJPanel.this.requestedTextureUnit ); try { fboFlipped = new FBObject(); fboFlipped.reset(gl, fboDrawable.getWidth(), fboDrawable.getHeight(), 0, false); fboFlipped.attachTexture2D(gl, 0, chosenCaps.getAlphaBits()>0); // fboFlipped.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); - glslTextureRaster = new GLSLTextureRaster(fboTextureUnit, true); + glslTextureRaster = new GLSLTextureRaster(fboDrawable.getTextureUnit(), true); glslTextureRaster.init(gl.getGL2ES2()); glslTextureRaster.reshape(gl.getGL2ES2(), 0, 0, fboDrawable.getWidth(), fboDrawable.getHeight()); } catch (Exception ex) { @@ -1210,7 +1256,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing fboDrawable.swapBuffers(); fboFlipped.bind(gl); - // gl.glActiveTexture(fboDrawable.getTextureUnit()); // implicit! + // gl.glActiveTexture(GL.GL_TEXTURE0 + fboDrawable.getTextureUnit()); // implicit by GLFBODrawableImpl: swapBuffers/contextMadeCurent -> swapFBOImpl gl.glBindTexture(GL.GL_TEXTURE_2D, fboTex.getName()); // gl.glClear(GL.GL_DEPTH_BUFFER_BIT); // fboFlipped runs w/o DEPTH! glslTextureRaster.display(gl.getGL2ES2()); @@ -1244,6 +1290,14 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing // correctness on all platforms } } + + @Override + public int getTextureUnit() { + if(null != glslTextureRaster && null != offscreenDrawable) { // implies flippedVertical + return ((GLFBODrawable)offscreenDrawable).getTextureUnit(); + } + return -1; + } @Override public void doPaintComponent(Graphics g) { @@ -1446,6 +1500,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing } @Override + public int getTextureUnit() { return -1; } + + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { // FIXME: should do better than this; is it possible to using only platform-independent code? return new GLCapabilities(null); |