diff options
author | Sven Gothel <[email protected]> | 2013-01-12 09:04:31 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-01-12 09:04:31 +0100 |
commit | 62c8fcc30dd5f9558df9ca907a6936c7bc252527 (patch) | |
tree | 304acfb4d3628c809d49f06a894c5ba1b3081831 | |
parent | a1bc317c24d55da1199450fe4c9c85d1105844b5 (diff) |
Adding GEOMETRY_SHADER support in ShaderCode, adding core GL3/GEOMETRY_SHADER unit tests. ; Simplified GLContext version number
- Adding GEOMETRY_SHADER support in ShaderCode, adding core GL3/GEOMETRY_SHADER unit tests
Chuck Ritola reported in December 2012 that we lack support of GEOMETRY_SHADER
and he provided a test case.
The latter is cleaned up to use GL3 core profile features only
tesing a pass-through and the flip-XYZ geometry shader.
ShaderUtil is fixed.
- Simplified GLContext version number
The OpenGL major/minor version is now hold in a VersionNumber instance
to simplify usage. Also expose it via getGLVersionNumber() while marking
getGLVersionMajor() and getGLVersionMinor() deprecated.
13 files changed, 613 insertions, 53 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 395546ab9..b9c5302a9 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -260,8 +260,10 @@ function testawtswt() { #testnoawt com.jogamp.newt.opengl.GLWindow $* #testnoawt com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen01GLPBufferNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen02BitmapNEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestRedSquareES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $* +testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl3.newt.TestGeomShader01TextureGL3NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFloatUtil01MatrixMatrixMultNOUI $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestPMVMatrix01NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestPMVMatrix02NEWT $* @@ -287,7 +289,7 @@ function testawtswt() { #testawt com.jogamp.opengl.test.junit.jogl.acore.TestExclusiveContext01VSyncAnimAWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestExclusiveContext02FPSAnimNEWT $* #testawt com.jogamp.opengl.test.junit.jogl.acore.TestExclusiveContext02FPSAnimAWT $* -testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestExclusiveContext11VSyncAnimNEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestExclusiveContext11VSyncAnimNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestExclusiveContext12FPSAnimNEWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* diff --git a/src/jogl/classes/com/jogamp/opengl/GLExtensions.java b/src/jogl/classes/com/jogamp/opengl/GLExtensions.java index cf81b85ee..c0666d153 100644 --- a/src/jogl/classes/com/jogamp/opengl/GLExtensions.java +++ b/src/jogl/classes/com/jogamp/opengl/GLExtensions.java @@ -73,8 +73,9 @@ public class GLExtensions { public static final String OES_EGL_image_external = "GL_OES_EGL_image_external"; public static final String ARB_gpu_shader_fp64 = "GL_ARB_gpu_shader_fp64"; - public static final String ARB_shader_objects = "GL_ARB_shader_objects"; - + public static final String ARB_shader_objects = "GL_ARB_shader_objects"; + public static final String ARB_geometry_shader4 = "GL_ARB_geometry_shader4"; + // // Aliased GLX/WGL/.. extensions // diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java index e6dde3237..1e552c17f 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -45,6 +45,7 @@ import java.util.Set; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL3; import javax.media.opengl.GLES2; import javax.media.opengl.GLContext; import javax.media.opengl.GLException; @@ -72,6 +73,12 @@ public class ShaderCode { /** Unique resource suffix for {@link GL2ES2#GL_VERTEX_SHADER} in binary: <code>bvp</code> */ public static final String SUFFIX_VERTEX_BINARY = "bvp" ; + /** Unique resource suffix for {@link GL3#GL_GEOMETRY_SHADER} in source code: <code>gp</code> */ + public static final String SUFFIX_GEOMETRY_SOURCE = "gp" ; + + /** Unique resource suffix for {@link GL3#GL_GEOMETRY_SHADER} in binary: <code>bgp</code> */ + public static final String SUFFIX_GEOMETRY_BINARY = "bgp" ; + /** Unique resource suffix for {@link GL2ES2#GL_FRAGMENT_SHADER} in source code: <code>fp</code> */ public static final String SUFFIX_FRAGMENT_SOURCE = "fp" ; @@ -82,7 +89,7 @@ public class ShaderCode { public static final String SUB_PATH_NVIDIA = "nvidia" ; /** - * @param type either {@link GL2ES2#GL_VERTEX_SHADER} or {@link GL2ES2#GL_FRAGMENT_SHADER} + * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER} * @param count number of shaders * @param source CharSequence array containing the shader sources, organized as <code>source[count][strings-per-shader]</code>. * May be either an immutable <code>String</code> - or mutable <code>StringBuilder</code> array. @@ -96,6 +103,7 @@ public class ShaderCode { switch (type) { case GL2ES2.GL_VERTEX_SHADER: case GL2ES2.GL_FRAGMENT_SHADER: + case GL3.GL_GEOMETRY_SHADER: break; default: throw new GLException("Unknown shader type: "+type); @@ -114,7 +122,7 @@ public class ShaderCode { } /** - * @param type either {@link GL2ES2#GL_VERTEX_SHADER} or {@link GL2ES2#GL_FRAGMENT_SHADER} + * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER} * @param count number of shaders * @param binary binary buffer containing the shader binaries, */ @@ -122,6 +130,7 @@ public class ShaderCode { switch (type) { case GL2ES2.GL_VERTEX_SHADER: case GL2ES2.GL_FRAGMENT_SHADER: + case GL3.GL_GEOMETRY_SHADER: break; default: throw new GLException("Unknown shader type: "+type); @@ -139,7 +148,7 @@ public class ShaderCode { * which location is resolved using the <code>context</code> class, see {@link #readShaderSource(Class, String)}. * * @param gl current GL object to determine whether a shader compiler is available. If null, no validation is performed. - * @param type either {@link GL2ES2#GL_VERTEX_SHADER} or {@link GL2ES2#GL_FRAGMENT_SHADER} + * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER} * @param count number of shaders * @param context class used to help resolving the source location * @param sourceFiles array of source locations, organized as <code>sourceFiles[count]</code> @@ -183,7 +192,7 @@ public class ShaderCode { * Creates a complete {@link ShaderCode} object while reading the shader binary of <code>binaryFile</code>, * which location is resolved using the <code>context</code> class, see {@link #readShaderBinary(Class, String)}. * - * @param type either {@link GL2ES2#GL_VERTEX_SHADER} or {@link GL2ES2#GL_FRAGMENT_SHADER} + * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER} * @param count number of shaders * @param context class used to help resolving the source location * @param binFormat a valid native binary format as they can be queried by {@link ShaderUtil#getShaderBinaryFormats(GL)}. @@ -215,13 +224,15 @@ public class ShaderCode { * <ul> * <li>Source<ul> * <li>{@link GL2ES2#GL_VERTEX_SHADER vertex}: {@link #SUFFIX_VERTEX_SOURCE}</li> - * <li>{@link GL2ES2#GL_FRAGMENT_SHADER fragment}: {@link #SUFFIX_FRAGMENT_SOURCE}</li></ul></li> + * <li>{@link GL2ES2#GL_FRAGMENT_SHADER fragment}: {@link #SUFFIX_FRAGMENT_SOURCE}</li> + * <li>{@link GL3#GL_GEOMETRY_SHADER geometry}: {@link #SUFFIX_GEOMETRY_SOURCE}</li></ul></li> * <li>Binary<ul> * <li>{@link GL2ES2#GL_VERTEX_SHADER vertex}: {@link #SUFFIX_VERTEX_BINARY}</li> - * <li>{@link GL2ES2#GL_FRAGMENT_SHADER fragment}: {@link #SUFFIX_FRAGMENT_BINARY}</li></ul></li> + * <li>{@link GL2ES2#GL_FRAGMENT_SHADER fragment}: {@link #SUFFIX_FRAGMENT_BINARY}</li> + * <li>{@link GL3#GL_GEOMETRY_SHADER geometry}: {@link #SUFFIX_GEOMETRY_BINARY}</li></ul></li> * </ul> * @param binary true for a binary resource, false for a source resource - * @param type either {@link GL2ES2#GL_VERTEX_SHADER} or {@link GL2ES2#GL_FRAGMENT_SHADER} + * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER} * * @throws GLException if <code>type</code> is not supported * @@ -233,6 +244,8 @@ public class ShaderCode { return binary?SUFFIX_VERTEX_BINARY:SUFFIX_VERTEX_SOURCE; case GL2ES2.GL_FRAGMENT_SHADER: return binary?SUFFIX_FRAGMENT_BINARY:SUFFIX_FRAGMENT_SOURCE; + case GL3.GL_GEOMETRY_SHADER: + return binary?SUFFIX_GEOMETRY_BINARY:SUFFIX_GEOMETRY_SOURCE; default: throw new GLException("illegal shader type: "+type); } @@ -311,7 +324,7 @@ public class ShaderCode { * * @param gl current GL object to determine whether a shader compiler is available (if <code>source</code> is used), * or to determine the shader binary format (if <code>binary</code> is used). - * @param type either {@link GL2ES2#GL_VERTEX_SHADER} or {@link GL2ES2#GL_FRAGMENT_SHADER} + * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER} * @param count number of shaders * @param context class used to help resolving the source and binary location * @param srcRoot relative <i>root</i> path for <code>srcBasenames</code> @@ -411,7 +424,7 @@ public class ShaderCode { * * @param gl current GL object to determine whether a shader compiler is available (if <code>source</code> is used), * or to determine the shader binary format (if <code>binary</code> is used). - * @param type either {@link GL2ES2#GL_VERTEX_SHADER} or {@link GL2ES2#GL_FRAGMENT_SHADER} + * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER} * @param context class used to help resolving the source and binary location * @param srcRoot relative <i>root</i> path for <code>basename</code> * @param binRoot relative <i>root</i> path for <code>basename</code> @@ -447,6 +460,8 @@ public class ShaderCode { return "VERTEX_SHADER"; case GL2ES2.GL_FRAGMENT_SHADER: return "FRAGMENT_SHADER"; + case GL3.GL_GEOMETRY_SHADER: + return "GEOMETRY_SHADER"; } return "UNKNOWN_SHADER"; } 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 5afc5e38c..eceeea6db 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java @@ -40,6 +40,7 @@ import java.util.*; import javax.media.opengl.*; import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.GLExtensions; public class ShaderUtil { public static String getShaderInfoLog(GL _gl, int shaderObj) { @@ -210,6 +211,13 @@ public class ShaderUtil { } return info.shaderCompilerAvailable.booleanValue(); } + + /** Returns true if GeometryShader is supported, i.e. whether GLContext is ≥ 3.2 or ARB_geometry_shader4 extension is available. */ + public static boolean isGeometryShaderSupported(GL _gl) { + final GLContext ctx = _gl.getContext(); + return ctx.getGLVersionNumber().compareTo(GLContext.Version32) >= 0 || + ctx.isExtensionAvailable(GLExtensions.ARB_geometry_shader4); + } public static void shaderSource(GL _gl, int shader, CharSequence[] source) { diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 461d481a8..8cc29f1f2 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -116,6 +116,15 @@ public abstract class GLContext { /** Indicates that a newly-created context was made current during the last call to {@link #makeCurrent makeCurrent}. */ public static final int CONTEXT_CURRENT_NEW = 2; + /** Version 3.2. As an OpenGL version, it qualifies for geometry shader */ + public static final VersionNumber Version32 = new VersionNumber(3, 2, 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); + + /** Version 3.0. As an OpenGL version, it qualifies for {@link #isGL2()} only */ + public static final VersionNumber Version30 = new VersionNumber(3, 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; /** <code>ARB_create_context</code> related: desktop compatibility profile. Cache key value. See {@link #isGLCompatibilityProfile()}, {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */ @@ -156,8 +165,7 @@ public abstract class GLContext { resetStates(); } - protected int ctxMajorVersion; - protected int ctxMinorVersion; + protected VersionNumber ctxVersion; protected int ctxOptions; protected String ctxVersionString; protected VersionNumber ctxGLSLVersion; @@ -172,8 +180,7 @@ public abstract class GLContext { System.err.println(getThreadName() + ": GLContext.resetStates()"); // Thread.dumpStack(); } - ctxMajorVersion=-1; - ctxMinorVersion=-1; + ctxVersion = new VersionNumber(-1, -1, -1); ctxOptions=0; ctxVersionString=null; ctxGLSLVersion=null; @@ -629,8 +636,15 @@ public abstract class GLContext { return ctxVersionString; } - public final int getGLVersionMajor() { return ctxMajorVersion; } - public final int getGLVersionMinor() { return ctxMinorVersion; } + /** @deprecated Use {@link #getGLVersionNumber()} */ + public final int getGLVersionMajor() { return ctxVersion.getMajor(); } + /** @deprecated Use {@link #getGLVersionNumber()} */ + public final int getGLVersionMinor() { return ctxVersion.getMinor(); } + /** + * Returns this context OpenGL version. + * @see #getGLSLVersionNumber() + **/ + public final VersionNumber getGLVersionNumber() { return ctxVersion; } public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } public final boolean isGLCoreProfile() { return ( 0 != ( CTX_PROFILE_CORE & ctxOptions ) ); } public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } @@ -659,8 +673,7 @@ public abstract class GLContext { * * @param GLSL version number if context has been made current at least once, otherwise <code>null</code>. * - * @see #getGLVersionMajor() - * @see #getGLVersionMinor() + * @see #getGLVersionNumber() */ public final VersionNumber getGLSLVersionNumber() { return ctxGLSLVersion; @@ -733,7 +746,7 @@ public abstract class GLContext { public final boolean hasGLSL() { return isGLES2() || isGL3() || - isGL2() && ctxMajorVersion>1 ; + isGL2() && ctxVersion.getMajor()>1 ; } /** @@ -810,46 +823,46 @@ public abstract class GLContext { /** @see GLProfile#isGL4bc() */ public final boolean isGL4bc() { - return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) - && 0 != (ctxOptions & CTX_PROFILE_COMPAT); + return ctxVersion.getMajor() >= 4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) + && 0 != (ctxOptions & CTX_PROFILE_COMPAT); } /** @see GLProfile#isGL4() */ public final boolean isGL4() { - return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) - && 0 != (ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_CORE)); + return ctxVersion.getMajor() >= 4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) + && 0 != (ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_CORE)); } /** Indicates whether this profile is capable of GL4 (core only). <p>Includes [ GL4 ].</p> */ public final boolean isGL4core() { - return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) - && 0 != (ctxOptions & CTX_PROFILE_CORE); + return ctxVersion.getMajor() >= 4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) + && 0 != (ctxOptions & CTX_PROFILE_CORE); } /** @see GLProfile#isGL3bc() */ public final boolean isGL3bc() { - return ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 ) + return ctxVersion.compareTo(Version31) >= 0 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) && 0 != (ctxOptions & CTX_PROFILE_COMPAT); } /** @see GLProfile#isGL3() */ public final boolean isGL3() { - return ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 ) + return ctxVersion.compareTo(Version31) >= 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). <p>Includes [ GL4, GL3 ].</p> */ + /** 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 ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 ) + return ctxVersion.compareTo(Version31) >= 0 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) && 0 != (ctxOptions & CTX_PROFILE_CORE); } /** @see GLProfile#isGL2() */ public final boolean isGL2() { - return ctxMajorVersion>=1 && 0!=(ctxOptions & CTX_PROFILE_COMPAT); + return ctxVersion.getMajor()>=1 && 0!=(ctxOptions & CTX_PROFILE_COMPAT); } /** @see GLProfile#isGL2GL3() */ @@ -859,12 +872,12 @@ public abstract class GLContext { /** @see GLProfile#isGLES1() */ public final boolean isGLES1() { - return ctxMajorVersion==1 && 0 != ( ctxOptions & CTX_PROFILE_ES ) ; + return ctxVersion.getMajor() == 1 && 0 != ( ctxOptions & CTX_PROFILE_ES ) ; } /** @see GLProfile#isGLES2() */ public final boolean isGLES2() { - return ctxMajorVersion==2 && 0 != ( ctxOptions & CTX_PROFILE_ES ) ; + return ctxVersion.getMajor() == 2 && 0 != ( ctxOptions & CTX_PROFILE_ES ) ; } /** @see GLProfile#isGLES() */ diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 36aaeb597..d960883d5 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -568,7 +568,7 @@ public abstract class GLContextImpl extends GLContext { final boolean created; try { created = createImpl(shareWith); // may throws exception if fails! - if( created && isGL3core() && ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 ) ) { + if( created && isGL3core() ) { // Due to GL 3.1 core spec: E.1. DEPRECATED AND REMOVED FEATURES (p 296), // GL 3.2 core spec: E.2. DEPRECATED AND REMOVED FEATURES (p 331) // there is no more default VAO buffer 0 bound, hence generating and binding one @@ -606,10 +606,10 @@ public abstract class GLContextImpl extends GLContext { if( 0 == ( ctxOptions & GLContext.CTX_PROFILE_ES) ) { // not ES profile final int reqMajor; final int reqProfile; - if(ctxMajorVersion<3 || ctxMajorVersion==3 && ctxMinorVersion==0) { + if( ctxVersion.compareTo(Version30) <= 0 ) { reqMajor = 2; } else { - reqMajor = ctxMajorVersion; + reqMajor = ctxVersion.getMajor(); } if( 0 != ( ctxOptions & GLContext.CTX_PROFILE_CORE) ) { reqProfile = GLContext.CTX_PROFILE_CORE; @@ -617,7 +617,7 @@ public abstract class GLContextImpl extends GLContext { reqProfile = GLContext.CTX_PROFILE_COMPAT; } GLContext.mapAvailableGLVersion(device, reqMajor, reqProfile, - ctxMajorVersion, ctxMinorVersion, ctxOptions); + ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); GLContext.setAvailableGLVersionsSet(device); if (DEBUG) { @@ -780,7 +780,7 @@ public abstract class GLContextImpl extends GLContext { success |= hasGL4; if(hasGL4) { // Map all lower compatible profiles: GL3 - GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); if(PROFILE_ALIASING) { hasGL3 = true; } @@ -799,13 +799,13 @@ public abstract class GLContextImpl extends GLContext { success |= hasGL4bc; if(hasGL4bc) { // Map all lower compatible profiles: GL3bc, GL2, GL4, GL3 - GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_COMPAT, ctxMajorVersion, ctxMinorVersion, ctxOptions); - GLContext.mapAvailableGLVersion(device, 2, CTX_PROFILE_COMPAT, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_COMPAT, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); + GLContext.mapAvailableGLVersion(device, 2, CTX_PROFILE_COMPAT, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); if(!hasGL4) { - GLContext.mapAvailableGLVersion(device, 4, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 4, CTX_PROFILE_CORE, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); } if(!hasGL3) { - GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); } if(PROFILE_ALIASING) { hasGL3bc = true; @@ -821,9 +821,9 @@ public abstract class GLContextImpl extends GLContext { success |= hasGL3bc; if(hasGL3bc) { // Map all lower compatible profiles: GL2 and GL3 - GLContext.mapAvailableGLVersion(device, 2, CTX_PROFILE_COMPAT, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 2, CTX_PROFILE_COMPAT, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); if(!hasGL3) { - GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); } if(PROFILE_ALIASING) { hasGL2 = true; @@ -915,7 +915,7 @@ public abstract class GLContextImpl extends GLContext { AbstractGraphicsDevice device = drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); // ctxMajorVersion, ctxMinorVersion, ctxOptions is being set by // createContextARBVersions(..) -> setGLFunctionAvailbility(..) -> setContextVersion(..) - GLContext.mapAvailableGLVersion(device, reqMajor, reqProfile, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, reqMajor, reqProfile, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); destroyContextARBImpl(_context); if (DEBUG) { System.err.println(getThreadName() + ": createContextARB-MapVersionsAvailable HAVE: " +reqMajor+"."+reqProfile+ " -> "+getGLVersion()); @@ -978,13 +978,12 @@ public abstract class GLContextImpl extends GLContext { if (!GLContext.isValidGLVersion(major, minor)) { throw new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); } - ctxMajorVersion = major; - ctxMinorVersion = minor; + ctxVersion = new VersionNumber(major, minor, 0); ctxOptions = ctp; if(setVersionString) { - ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, gl.glGetString(GL.GL_VERSION)); + ctxVersionString = getGLVersion(major, minor, ctxOptions, gl.glGetString(GL.GL_VERSION)); ctxGLSLVersion = null; - if(ctxMajorVersion >= 2) { // >= ES2 || GL2.0 + if(major >= 2) { // >= ES2 || GL2.0 final String glslVersion = gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION); if( null != glslVersion ) { ctxGLSLVersion = new VersionNumber(glslVersion, "."); @@ -995,7 +994,7 @@ public abstract class GLContextImpl extends GLContext { } if( null == ctxGLSLVersion ){ final int[] sver = new int[2]; - getStaticGLSLVersionNumber(ctxMajorVersion, ctxMinorVersion, ctxOptions, sver); + getStaticGLSLVersionNumber(major, minor, ctxOptions, sver); ctxGLSLVersion = new VersionNumber(sver[0], sver[1], 0); } } @@ -1424,7 +1423,7 @@ public abstract class GLContextImpl extends GLContext { final int glErrX = gl.glGetError(); // clear GL error, maybe caused by above operations if(DEBUG) { - System.err.println(getThreadName() + ": GLContext.setGLFuncAvail.X: OK "+contextFQN+" - "+GLContext.getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, null)+" - glErr "+toHexString(glErrX)); + System.err.println(getThreadName() + ": GLContext.setGLFuncAvail.X: OK "+contextFQN+" - "+GLContext.getGLVersion(ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions, null)+" - glErr "+toHexString(glErrX)); } return true; } diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java index bd8e7dee9..572888bae 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java @@ -281,7 +281,7 @@ public abstract class EGLContext extends GLContextImpl { // /* pp */ void mapCurrentAvailableGLVersion(AbstractGraphicsDevice device) { - mapStaticGLVersion(device, ctxMajorVersion, ctxMinorVersion, ctxOptions); + mapStaticGLVersion(device, ctxVersion.getMajor(), ctxVersion.getMinor(), ctxOptions); } /* pp */ int getContextOptions() { return ctxOptions; } /* pp */ static void mapStaticGLESVersion(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/GeomShader01TextureGL3.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/GeomShader01TextureGL3.java new file mode 100644 index 000000000..929491187 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/GeomShader01TextureGL3.java @@ -0,0 +1,293 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community OR + * CONTRIBUTORS 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. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.demos.gl3; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URLConnection; +import java.nio.FloatBuffer; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL3; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLUniformData; +import javax.media.opengl.fixedfunc.GLMatrixFunc; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.util.GLArrayDataServer; +import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.util.glsl.ShaderCode; +import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.glsl.ShaderState; +import com.jogamp.opengl.util.glsl.ShaderUtil; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; + +/** + * JOGL Geometry ShaderCode test case using OpenGL 3.2 core profile features only. + * <p> + * Demonstrates <code>pass through</code> and <code>XYZ flipping</code> + * geometry shader. + * </p> + * <p> + * If the <code>XYZ flipping</code> geometry shader functions properly, + * the texture will be flipped horizontally and vertically. + * </p> + * + * @author Chuck Ritola December 2012 + * @author Sven Gothel (GL3 core, pass-though, core geometry shader) + */ +public class GeomShader01TextureGL3 implements GLEventListener { + private final int geomShader; + private Texture texture; + private ShaderState st; + private PMVMatrix pmvMatrix; + private GLUniformData pmvMatrixUniform; + private GLArrayDataServer interleavedVBO; + + static final String shaderBasename = "texture01_xxx"; + static final String[] geomShaderBaseNames = new String[] { "passthrough01_xxx", "flipXYZ01_xxx" }; + + public GeomShader01TextureGL3(int geomShader) { + this.geomShader = geomShader; + } + + @Override + public void init(GLAutoDrawable drawable) { + { + final GL gl = drawable.getGL(); + System.err.println("Init - START - useGeomShader "+geomShader+" -> "+geomShaderBaseNames[geomShader]); + System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); + System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); + System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); + System.err.println("GL GLSL: "+gl.hasGLSL()+", has-compiler: "+gl.isFunctionAvailable("glCompileShader")+", version "+(gl.hasGLSL() ? gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION) : "none")); + System.err.println("GL Profile: "+gl.getGLProfile()); + System.err.println("GL Renderer Quirks:" + gl.getContext().getRendererQuirks().toString()); + System.err.println("GL:" + gl + ", " + gl.getContext().getGLVersion()); + if( !gl.isGL3() ) { + throw new RuntimeException("GL object not a GL3 core compatible profile: "+gl); + } + if( !ShaderUtil.isGeometryShaderSupported(gl) ) { + throw new RuntimeException("GL object not >= 3.2, i.e. no geometry shader support.: "+gl); + } + } + final GL3 gl = drawable.getGL().getGL3(); + + final ShaderProgram sp; + { + final ShaderCode vs, gs, fs; + vs = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), + "shader", "shader/bin", shaderBasename, true); + gs = ShaderCode.create(gl, GL3.GL_GEOMETRY_SHADER, this.getClass(), + "shader", "shader/bin", geomShaderBaseNames[geomShader], true); + fs = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), + "shader", "shader/bin", shaderBasename, true); + vs.defaultShaderCustomization(gl, true, null); + gs.defaultShaderCustomization(gl, true, null); + fs.defaultShaderCustomization(gl, true, null); + + sp = new ShaderProgram(); + sp.add(gl, vs, System.err); + sp.add(gl, gs, System.err); + sp.add(gl, fs, System.err); + if(!sp.link(gl, System.err)) { + throw new GLException("Couldn't link program: "+sp); + } + } + + st=new ShaderState(); + st.attachShaderProgram(gl, sp, true); + + // setup mgl_PMVMatrix + pmvMatrix = new PMVMatrix(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv + st.ownUniform(pmvMatrixUniform); + st.uniform(gl, pmvMatrixUniform); + + st.ownUniform(pmvMatrixUniform); + if(!st.uniform(gl, pmvMatrixUniform)) { + throw new GLException("Error setting PMVMatrix in shader: "+st); + } + if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", 0))) { + throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); + } + + try { + texture = createTestTexture(gl); + } catch (IOException e) { + throw new RuntimeException(e); + } + if(null == texture) { + throw new RuntimeException("Could not load test texture"); + } + + // Tri order: + // TL, BL, BR + // TL, TR, BR + { + int i=0; + TextureCoords tc = texture.getImageTexCoords(); + s_triTexCoords[i++] = tc.left(); s_triTexCoords[i++] = tc.top(); + s_triTexCoords[i++] = tc.left(); s_triTexCoords[i++] = tc.bottom(); + s_triTexCoords[i++] = tc.right(); s_triTexCoords[i++] = tc.bottom(); + s_triTexCoords[i++] = tc.left(); s_triTexCoords[i++] = tc.top(); + s_triTexCoords[i++] = tc.right(); s_triTexCoords[i++] = tc.top(); + s_triTexCoords[i++] = tc.right(); s_triTexCoords[i++] = tc.bottom(); + } + + interleavedVBO = GLArrayDataServer.createGLSLInterleaved(2+4+2, GL.GL_FLOAT, false, 3*6, GL.GL_STATIC_DRAW); + { + interleavedVBO.addGLSLSubArray("mgl_Vertex", 2, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); + + FloatBuffer ib = (FloatBuffer)interleavedVBO.getBuffer(); + + for(int i=0; i<6; i++) { + ib.put(s_triVertices, i*2, 2); + ib.put(s_triColors, i*4, 4); + ib.put(s_triTexCoords, i*2, 2); + } + } + interleavedVBO.seal(gl, true); + interleavedVBO.enableBuffer(gl, false); + st.ownAttribute(interleavedVBO, true); + + gl.glClearColor(0f, 0f, 0f, 0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + st.useProgram(gl, false); + } + + private Texture createTestTexture(GL3 gl) throws IOException { + final URLConnection urlConn = IOUtil.getResource(this.getClass(), "../../util/texture/test-ntscI01-160x90.png"); + if(null == urlConn) { return null; } + final InputStream istream = urlConn.getInputStream(); + if(null == istream) { return null; } + final TextureData texData = TextureIO.newTextureData(gl.getGLProfile(), istream, false /* mipmap */, TextureIO.PNG); + final Texture res = TextureIO.newTexture(gl, texData); + texData.destroy(); + return res; + } + + @Override + public void dispose(GLAutoDrawable drawable) { + final GL3 gl = drawable.getGL().getGL3(); + if(null!=texture) { + texture.disable(gl); + texture.destroy(gl); + } + + if(null != st) { + pmvMatrixUniform = null; + pmvMatrix.destroy(); + pmvMatrix=null; + st.destroy(gl); + st=null; + } + } + + @Override + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL3 gl = drawable.getGL().getGL3(); + + gl.setSwapInterval(1); + + // Clear background to white + gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f); + + if(null != st) { + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f); + + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + + st.useProgram(gl, true); + st.uniform(gl, pmvMatrixUniform); + st.useProgram(gl, false); + } + } + + @Override + public void display(GLAutoDrawable drawable) { + final GL3 gl = drawable.getGL().getGL3(); + + gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT); + + if(null != st) { + //Draw the image as a pseudo-quad using two triangles + st.useProgram(gl, true); + interleavedVBO.enableBuffer(gl, true); + gl.glActiveTexture(GL.GL_TEXTURE0); + texture.enable(gl); + texture.bind(gl); + + gl.glDrawArrays(GL.GL_TRIANGLES, 0, 6); + + texture.disable(gl); + interleavedVBO.enableBuffer(gl, false); + st.useProgram(gl, false); + } + }//end display() + + private static final float[] s_triVertices = { + -1f, 1f, // TL + -1f, -1f, // BL + 1f, -1f, // BR + -1f, 1f, // TL + 1f, 1f, // TR + 1f, -1f // BR + }; + private static final float[] s_triColors = { + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f, + 1f, 1f, 1f, 1f + }; + private static final float[] s_triTexCoords = { + 0f, 1f, // TL + 0f, 0f, // BL + 1f, 0f, // BR + 0f, 1f, // TL + 1f, 1f, // TR + 1f, 0f // BR + }; + +}//end Test diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/newt/TestGeomShader01TextureGL3NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/newt/TestGeomShader01TextureGL3NEWT.java new file mode 100644 index 000000000..71c0ae7ac --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/newt/TestGeomShader01TextureGL3NEWT.java @@ -0,0 +1,126 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community OR + * CONTRIBUTORS 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. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.demos.gl3.newt; + +import java.io.IOException; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.gl3.GeomShader01TextureGL3; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +/** + * Test Geometry shader demo GeomShader01TextureGL3 + */ +public class TestGeomShader01TextureGL3NEWT extends UITestCase { + static long duration = 500; // ms + + static GLCapabilities getCaps(String profile) { + if( !GLProfile.isAvailable(profile) ) { + System.err.println("Profile "+profile+" n/a"); + return null; + } + return new GLCapabilities(GLProfile.get(profile)); + } + + @Test + public void test01_GL3Core_Passthrough() throws InterruptedException { + GLCapabilities caps = getCaps(GLProfile.GL3); + if( null == caps ) { return; } + testImpl(caps, 0); + } + + @Test + public void test02_GL3Core_FlipXYZ() throws InterruptedException { + GLCapabilities caps = getCaps(GLProfile.GL3); + if( null == caps ) { return; } + testImpl(caps, 1); + } + + @Test + public void test11_GL3Compat_Passthrough() throws InterruptedException { + GLCapabilities caps = getCaps(GLProfile.GL3bc); + if( null == caps ) { return; } + testImpl(caps, 0); + } + + @Test + public void test12_GL3Compat_FlipXYZ() throws InterruptedException { + GLCapabilities caps = getCaps(GLProfile.GL3bc); + if( null == caps ) { return; } + testImpl(caps, 1); + } + + private void testImpl(GLCapabilities caps, int geomShader) throws InterruptedException { + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setSize(800, 600); + glWindow.setVisible(true); + glWindow.setTitle("JOGL Geometry Shader Banana Test"); + Assert.assertTrue(glWindow.isNativeValid()); + + QuitAdapter quitAdapter = new QuitAdapter(); + glWindow.addKeyListener(quitAdapter); + glWindow.addWindowListener(quitAdapter); + glWindow.addGLEventListener( new GeomShader01TextureGL3(geomShader) ); + + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); + glWindow.addGLEventListener(snapshotGLEventListener); + + final Animator animator = new Animator(glWindow); + animator.start(); + + animator.setUpdateFPSFrames(60, System.err); + snapshotGLEventListener.setMakeSnapshot(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + glWindow.destroy(); + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = MiscUtils.atol(args[i], duration); + } + } + org.junit.runner.JUnitCore.main(TestGeomShader01TextureGL3NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/flipXYZ01_xxx.gp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/flipXYZ01_xxx.gp new file mode 100644 index 000000000..f65ffacdb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/flipXYZ01_xxx.gp @@ -0,0 +1,32 @@ +// Copyright 2012 JogAmp Community. All rights reserved. +// Requires version >= 150 + +layout (triangles) in; +layout (triangle_strip, max_vertices=3) out; + +in VertexData { + vec4 frontColor; + vec2 texCoord; +} vp_data[3]; + +out VertexData { + vec4 frontColor; + vec2 texCoord; +} gp_data; + +void main() +{ + for(int i = 0; i < gl_in.length(); i++) + { + // copy attributes + gl_Position = vec4(gl_in[i].gl_Position.xyz*-1,1); // This line flips the coordinates. + gp_data.frontColor = vp_data[i].frontColor; + gp_data.texCoord = vp_data[i].texCoord; + + // done with the vertex + EmitVertex(); + } +} + + + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/passthrough01_xxx.gp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/passthrough01_xxx.gp new file mode 100644 index 000000000..588b72426 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/passthrough01_xxx.gp @@ -0,0 +1,31 @@ +// Copyright 2012 JogAmp Community. All rights reserved. +// Requires version >= 150 + +layout (triangles) in; +layout (triangle_strip, max_vertices=3) out; + +in VertexData { + vec4 frontColor; + vec2 texCoord; +} vp_data[3]; + +out VertexData { + vec4 frontColor; + vec2 texCoord; +} gp_data; + +void main() +{ + for(int i = 0; i < gl_in.length(); i++) + { + // copy attributes + gl_Position = gl_in[i].gl_Position; + gp_data.frontColor = vp_data[i].frontColor; + gp_data.texCoord = vp_data[i].texCoord; + + // done with the vertex + EmitVertex(); + } +} + + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/texture01_xxx.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/texture01_xxx.fp new file mode 100644 index 000000000..61f4529ac --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/texture01_xxx.fp @@ -0,0 +1,20 @@ +// Copyright 2012 JogAmp Community. All rights reserved. +// Requires version >= 130 + +in VertexData { + vec4 frontColor; + vec2 texCoord; +} gp_data; + +out vec4 mgl_FragColor; + +uniform sampler2D mgl_ActiveTexture; + +void main (void) +{ + vec4 texColor = texture(mgl_ActiveTexture, gp_data.texCoord); + + // mix frontColor with texture .. + mgl_FragColor = vec4(gp_data.frontColor*texColor); +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/texture01_xxx.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/texture01_xxx.vp new file mode 100644 index 000000000..b220c83f1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl3/shader/texture01_xxx.vp @@ -0,0 +1,20 @@ +// Copyright 2012 JogAmp Community. All rights reserved. +// Requires version >= 130 + +uniform mat4 mgl_PMVMatrix[2]; + +in vec4 mgl_Vertex; +in vec4 mgl_Color; +in vec4 mgl_MultiTexCoord; + +out VertexData { + vec4 frontColor; + vec2 texCoord; +} vp_data; + +void main(void) +{ + vp_data.frontColor = mgl_Color; + vp_data.texCoord = mgl_MultiTexCoord.st; + gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; +} |