From e99f5060d62aad25fcc37ebf50c8f2a270c9d5df Mon Sep 17 00:00:00 2001
From: Sven Gothel
-Bug818 OSX GLJPanel NV GT330 Crash
+Bug818 OSX GLJPanel and GLCanvas NV GT330 Crash
- * In case the desired type or bit-number is not supported, the next available one is chosen.
+ * In case the bit-count is not supported,
+ * the next available one is chosen, i.e. next higher (preferred) or lower bit-count.
*
* Use {@link #getDepthAttachment()} and/or {@link #getStencilAttachment()} to retrieve details
@@ -1623,68 +1687,58 @@ public class FBObject {
*
* @param gl
* @param atype either {@link Type#DEPTH}, {@link Type#STENCIL} or {@link Type#DEPTH_STENCIL}
- * @param reqBits desired bits for depth or -1 for default (24 bits)
+ * @param reqBits desired bits for depth or stencil,
+ * may use generic values {@link #DEFAULT_BITS}, {@link #REQUESTED_BITS}, {@link #CHOSEN_BITS} or {@link #MAXIMUM_BITS}.
* @throws GLException in case the renderbuffer couldn't be allocated or one is already attached.
* @throws IllegalArgumentException
* @see #getDepthAttachment()
* @see #getStencilAttachment()
*/
- public final void attachRenderbuffer(final GL gl, final Attachment.Type atype, int reqBits) throws GLException, IllegalArgumentException {
- if( 0 > reqBits ) {
- reqBits = 24;
+ public final void attachRenderbuffer(final GL gl, final Attachment.Type atype, final int reqBits) throws GLException, IllegalArgumentException {
+ final int reqDepth, reqStencil;
+ if( MAXIMUM_BITS > reqBits ) {
+ throw new IllegalArgumentException("reqBits out of range, shall be >= "+MAXIMUM_BITS);
+ } else if( MAXIMUM_BITS == reqBits ) {
+ reqDepth = 32;
+ reqStencil = 16;
+ } else if( CHOSEN_BITS == reqBits ) {
+ final GLCapabilitiesImmutable caps = gl.getContext().getGLDrawable().getChosenGLCapabilities();
+ reqDepth = caps.getDepthBits();
+ reqStencil = caps.getStencilBits();
+ } else if( REQUESTED_BITS == reqBits ) {
+ final GLCapabilitiesImmutable caps = gl.getContext().getGLDrawable().getRequestedGLCapabilities();
+ reqDepth = caps.getDepthBits();
+ reqStencil = caps.getStencilBits();
+ } else if( DEFAULT_BITS == reqBits ) {
+ reqDepth = 24;
+ reqStencil = 8;
+ } else {
+ reqDepth = reqBits;
+ reqStencil = reqBits;
}
final int internalFormat;
int internalStencilFormat = -1;
switch ( atype ) {
case DEPTH:
- if( 32 <= reqBits && depth32Avail ) {
- internalFormat = GL.GL_DEPTH_COMPONENT32;
- } else if( 24 <= reqBits && depth24Avail ) {
- internalFormat = GL.GL_DEPTH_COMPONENT24;
- } else {
- internalFormat = GL.GL_DEPTH_COMPONENT16;
- }
+ internalFormat = getDepthIFormat(reqDepth);
break;
case STENCIL:
- if( 16 <= reqBits && stencil16Avail ) {
- internalFormat = GL2GL3.GL_STENCIL_INDEX16;
- } else if( 8 <= reqBits && stencil08Avail ) {
- internalFormat = GL.GL_STENCIL_INDEX8;
- } else if( 4 <= reqBits && stencil04Avail ) {
- internalFormat = GL.GL_STENCIL_INDEX4;
- } else if( 1 <= reqBits && stencil01Avail ) {
- internalFormat = GL.GL_STENCIL_INDEX1;
- } else {
- throw new GLException("stencil buffer n/a");
- }
+ internalFormat = getStencilIFormat(reqStencil);
break;
case DEPTH_STENCIL:
if( packedDepthStencilAvail ) {
internalFormat = GL.GL_DEPTH24_STENCIL8;
} else {
- if( 24 <= reqBits && depth24Avail ) {
- internalFormat = GL.GL_DEPTH_COMPONENT24;
- } else {
- internalFormat = GL.GL_DEPTH_COMPONENT16;
- }
- if( stencil08Avail ) {
- internalStencilFormat = GL.GL_STENCIL_INDEX8;
- } else if( stencil04Avail ) {
- internalStencilFormat = GL.GL_STENCIL_INDEX4;
- } else if( stencil01Avail ) {
- internalStencilFormat = GL.GL_STENCIL_INDEX1;
- } else {
- throw new GLException("stencil buffer n/a");
- }
+ internalFormat = getDepthIFormat(reqDepth);
+ internalStencilFormat = getStencilIFormat(reqStencil);
}
break;
default:
throw new IllegalArgumentException("only depth/stencil types allowed, was "+atype+", "+this);
}
-
attachRenderbufferImpl(gl, atype, internalFormat);
if(0<=internalStencilFormat) {
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java
index 8b00aefb7..f70ebf928 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java
@@ -95,19 +95,19 @@ public class StereoClientRenderer implements GLEventListener {
if(numSamples>0) {
fbos[i].attachColorbuffer(gl, 0, true); // MSAA requires alpha
- fbos[i].attachRenderbuffer(gl, Type.DEPTH, 24);
+ fbos[i].attachRenderbuffer(gl, Type.DEPTH, FBObject.DEFAULT_BITS);
final FBObject ssink = new FBObject();
{
ssink.init(gl, size.getWidth(), size.getHeight(), 0);
ssink.attachTexture2D(gl, 0, false, magFilter, minFilter, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
- ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
}
fbos[i].setSamplingSink(ssink);
fbos[i].resetSamplingSink(gl); // validate
fboTexs[i] = fbos[i].getSamplingSink().getTextureAttachment();
} else {
fboTexs[i] = fbos[i].attachTexture2D(gl, 0, false, magFilter, minFilter, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
- fbos[i].attachRenderbuffer(gl, Type.DEPTH, 24);
+ fbos[i].attachRenderbuffer(gl, Type.DEPTH, FBObject.DEFAULT_BITS);
}
fbos[i].unbind(gl);
System.err.println("FBO["+i+"]: "+fbos[i]);
diff --git a/src/jogl/classes/javax/media/opengl/GLFBODrawable.java b/src/jogl/classes/javax/media/opengl/GLFBODrawable.java
index e98e5cbd5..01db60b2e 100644
--- a/src/jogl/classes/javax/media/opengl/GLFBODrawable.java
+++ b/src/jogl/classes/javax/media/opengl/GLFBODrawable.java
@@ -80,11 +80,14 @@ public interface GLFBODrawable extends GLDrawable {
/** FBO Mode Bit: Use a {@link TextureAttachment} for the {@link #getColorbuffer(int) render colorbuffer} ({@link #FBOMODE_DEFAULT default}), see {@link #setFBOMode(int)}. */
public static final int FBOMODE_USE_TEXTURE = 1 << 0;
- /** FBO Mode Bit: Use a depth renderbuffer ({@link #FBOMODE_DEFAULT default}), see {@link #setFBOMode(int)}. */
+ /**
+ * FBO Mode Bit: Use a depth renderbuffer ({@link #FBOMODE_DEFAULT default}), see {@link #setFBOMode(int)}.
+ * @deprecated Use {@link GLCapabilities#setDepthBits(int)}!
+ */
public static final int FBOMODE_USE_DEPTH = 1 << 1;
- /** FBO Default Mode Bit: {@link #FBOMODE_USE_TEXTURE} | {@link #FBOMODE_USE_DEPTH}. */
- public static final int FBOMODE_DEFAULT = FBOMODE_USE_TEXTURE | FBOMODE_USE_DEPTH;
+ /** FBO Default Mode Bit: {@link #FBOMODE_USE_TEXTURE}. */
+ public static final int FBOMODE_DEFAULT = FBOMODE_USE_TEXTURE;
/**
* @return true
if initialized, i.e. a {@link GLContext} is bound and made current once, otherwise false
.
@@ -101,8 +104,8 @@ public interface GLFBODrawable extends GLDrawable {
* {@link #FBOMODE_USE_TEXTURE} is always added at initialization.
*
bufferCount
(see above)
- * @throws GLException if already initialized, see {@link #isInitialized()}.
+ * @throws IllegalStateException if already initialized, see {@link #isInitialized()}.
*/
- int setNumBuffers(final int bufferCount) throws GLException;
+ int setNumBuffers(final int bufferCount) throws /* IllegalStateException, */ GLException;
/**
* @return the number of buffers (FBO) being used. 1 if not using {@link GLCapabilities#getDoubleBuffered() double buffering},
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index 132367102..5bc4c9a60 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -1663,7 +1663,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
final boolean useGLSLFlip_pre = flipVertical && offscreenIsFBO && reqOffscreenCaps.getGLProfile().isGL2ES2() && USE_GLSL_TEXTURE_RASTERIZER;
if( offscreenIsFBO && !useGLSLFlip_pre ) {
// Texture attachment only required for GLSL vertical flip, hence simply use a color-renderbuffer attachment.
- ((GLFBODrawable)offscreenDrawable).setFBOMode(GLFBODrawable.FBOMODE_USE_DEPTH);
+ ((GLFBODrawable)offscreenDrawable).setFBOMode(0);
}
offscreenContext = (GLContextImpl) offscreenDrawable.createContext(shareWith[0]);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
index 422714ac5..fbd40ebdd 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -459,7 +459,7 @@ public class VBORegion2PMSAAES2 extends GLRegion {
fbo.attachColorbuffer(gl, 0, true);
if( !blendingEnabled ) {
// no depth-buffer w/ blending
- fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
}
final FBObject ssink = new FBObject();
{
@@ -469,7 +469,7 @@ public class VBORegion2PMSAAES2 extends GLRegion {
ssink.attachTexture2D(gl, 0, true, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
if( !blendingEnabled ) {
// no depth-buffer w/ blending
- ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
}
}
fbo.setSamplingSink(ssink);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
index 5251ade39..8f1de9157 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -580,7 +580,7 @@ public class VBORegion2PVBAAES2 extends GLRegion {
texA = fbo.attachTexture2D(gl, 0, true, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
if( !blendingEnabled ) {
// no depth-buffer w/ blending
- fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS);
}
if( DEBUG_FBO_1 ) {
System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString());
diff --git a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java
index 1bdc99a9b..fdd5aa5e9 100644
--- a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java
@@ -91,7 +91,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
final GLCapabilitiesImmutable fboCaps, final int textureUnit) {
super(factory, surface, fboCaps, false);
this.initialized = false;
- this.fboModeBits = FBOMODE_USE_TEXTURE | FBOMODE_USE_DEPTH;
+ this.fboModeBits = FBOMODE_USE_TEXTURE;
this.parent = parent;
this.origParentChosenCaps = getChosenGLCapabilities(); // just to avoid null, will be reset at initialize(..)
@@ -102,11 +102,14 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
}
private final void setupFBO(final GL gl, final int idx, final int width, final int height, final int samples,
- final boolean useAlpha, final boolean useStencil, final boolean useDepth, final boolean useTexture,
- final boolean realUnbind) {
+ final boolean useAlpha, final int depthBits, final int stencilBits,
+ final boolean useTexture, final boolean realUnbind) {
final FBObject fbo = new FBObject();
fbos[idx] = fbo;
+ final boolean useDepth = depthBits > 0 || 0 != ( FBOMODE_USE_DEPTH & fboModeBits );
+ final boolean useStencil = stencilBits > 0;
+
fbo.init(gl, width, height, samples);
if(fbo.getNumSamples() != samples) {
throw new InternalError("Sample number mismatch: "+samples+", fbos["+idx+"] "+fbo);
@@ -118,12 +121,12 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
}
if( useStencil ) {
if( useDepth ) {
- fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, 24);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, depthBits);
} else {
- fbo.attachRenderbuffer(gl, Attachment.Type.STENCIL, 24);
+ fbo.attachRenderbuffer(gl, Attachment.Type.STENCIL, stencilBits);
}
} else if( useDepth ) {
- fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, depthBits);
}
if(samples > 0) {
final FBObject ssink = new FBObject();
@@ -136,12 +139,12 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
}
if( useStencil ) {
if( useDepth ) {
- ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, 24);
+ ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH_STENCIL, depthBits);
} else {
- ssink.attachRenderbuffer(gl, Attachment.Type.STENCIL, 24);
+ ssink.attachRenderbuffer(gl, Attachment.Type.STENCIL, stencilBits);
}
} else if( useDepth ) {
- ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, depthBits);
}
}
fbo.setSamplingSink(ssink);
@@ -206,14 +209,13 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
}
final boolean useTexture = 0 != ( FBOMODE_USE_TEXTURE & fboModeBits );
- final boolean useDepth = 0 != ( FBOMODE_USE_DEPTH & fboModeBits );
- final boolean useStencil = chosenFBOCaps.getStencilBits() > 0;
final boolean useAlpha = chosenFBOCaps.getAlphaBits() > 0;
final int width = getSurfaceWidth();
final int height = getSurfaceHeight();
for(int i=0; i+ * - NVIDIA GeForce GT 330M + * - GL_VENDOR: "NVIDIA Corporation" + * - GL_RENDERER: "NVIDIA GeForce GT 330M OpenGL Engine" + * - GL_VERSION: "2.1 NVIDIA-8.12.47 310.40.00.05f01" + * - Mac OSX 10.6.8 + *+ */ +public class Bug818GLJPanelAndGLCanvasApplet extends JApplet { + + private static final long serialVersionUID = 1L; + + private Animator animatorCanvas; + + private Animator animatorPanel; + + public static JFrame frame; + public static JPanel appletHolder; + public static boolean isApplet = true; + + static public void main(final String args[]) { + isApplet = false; + + final JApplet myApplet = new Bug818GLJPanelAndGLCanvasApplet(); + + appletHolder = new JPanel(); + + frame = new JFrame("Bug818GLJPanelApplet"); + frame.getContentPane().add(myApplet); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(final WindowEvent e) { + System.exit(0); + } + }); + + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + myApplet.init(); + frame.validate(); + frame.pack(); + frame.setVisible(true); + } } ); + } catch( final Throwable throwable ) { + throwable.printStackTrace(); + } + + myApplet.start(); + } + + + @Override + public void init() { + + final JPanel panel = new JPanel(); + panel.setLayout(new GridLayout(2, 2)); + System.err.println("Pre Orientation L2R: "+panel.getComponentOrientation().isLeftToRight()); + panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); + System.err.println("Post Orientation L2R: "+panel.getComponentOrientation().isLeftToRight()); + setContentPane(panel); + panel.add(new JLabel("GLJPanel")); + panel.add(new JLabel("GLCanvas")); + + final GLJPanel gljPanel = new GLJPanel(); + gljPanel.addGLEventListener(new JOGLQuad(false)); + animatorPanel = new Animator(gljPanel); + gljPanel.setPreferredSize(new Dimension(300, 300)); + panel.add(gljPanel); + + final GLCanvas glCanvas = new GLCanvas(); + glCanvas.addGLEventListener(new JOGLQuad(true)); + animatorCanvas = new Animator(glCanvas); + glCanvas.setPreferredSize(new Dimension(300, 300)); + panel.add(glCanvas); + } + + @Override + public void start() { + + animatorCanvas.start(); + animatorCanvas.setUpdateFPSFrames(60, System.err); + animatorPanel.start(); + animatorPanel.setUpdateFPSFrames(60, System.err); + } + + @Override + public void stop() { + + animatorCanvas.stop(); + animatorPanel.stop(); + } + + @Override + public void destroy() {} + + /** + * Self-contained example (within a single class only to keep it simple) displaying a rotating quad + */ + static class JOGLQuad implements GLEventListener { + + private static final float[] VERTEX_DATA = { + -1.0f, 1.0f, 0.0f, // Top Left + 1.0f, 1.0f, 0.0f, // Top Right + 1.0f, -1.0f, 0.0f, // Bottom Right + -1.0f, -1.0f, 0.0f // Bottom Left + }; + + private static final float[] TEXCOORD_DATA = { + 0.0f, 1.0f, // Top Left + 1.0f, 1.0f, // Top Right + 1.0f, 0.0f, // Bottom Right + 0.0f, 0.0f // Bottom Left + }; + + private final FloatBuffer vertexBuf; + + private final FloatBuffer texCoordBuf; + + private int vertexVBO; + + private int texCoordVBO; + + private float rotateT = 0.0f; + + private final boolean canvas; + + private Texture texture; + + JOGLQuad(final boolean canvas) { + + this.canvas = canvas; + + ByteBuffer bb = ByteBuffer.allocateDirect(VERTEX_DATA.length * 4); + bb.order(ByteOrder.nativeOrder()); + vertexBuf = bb.asFloatBuffer(); + vertexBuf.put(VERTEX_DATA); + vertexBuf.rewind(); + + bb = ByteBuffer.allocateDirect(TEXCOORD_DATA.length * 4); + bb.order(ByteOrder.nativeOrder()); + texCoordBuf = bb.asFloatBuffer(); + texCoordBuf.put(TEXCOORD_DATA); + texCoordBuf.rewind(); + } + + @Override + public void init(final GLAutoDrawable glDrawable) { + + final GL2 gl = glDrawable.getGL().getGL2(); + + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(JoglVersion.getGLInfo(gl, null, false /* withCapabilitiesAndExtensionInfo */).toString()); + + gl.glShadeModel(GLLightingFunc.GL_SMOOTH); + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + gl.glClearDepth(1.0f); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glDepthFunc(GL.GL_LEQUAL); + gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); + + final int[] tmp = new int[2]; + gl.glGenBuffers(tmp.length, tmp, 0); + vertexVBO = tmp[0]; + texCoordVBO = tmp[1]; + + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexVBO); + gl.glBufferData(GL.GL_ARRAY_BUFFER, VERTEX_DATA.length * 4, vertexBuf, GL.GL_STATIC_DRAW); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, texCoordVBO); + gl.glBufferData(GL.GL_ARRAY_BUFFER, TEXCOORD_DATA.length * 4, texCoordBuf, GL.GL_STATIC_DRAW); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + try { + final InputStream stream = getClass().getClassLoader().getResourceAsStream("com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-base.jpg"); + texture = TextureIO.newTexture(stream, true, TextureIO.JPG); + } catch (final Exception exc) { + exc.printStackTrace(System.err); + } + } + + @Override + public void dispose(final GLAutoDrawable drawable) { + + final GL2 gl = drawable.getGL().getGL2(); + final int[] tmp = new int[] {vertexVBO, texCoordVBO}; + gl.glGenBuffers(tmp.length, tmp, 0); + } + + @Override + public void reshape(final GLAutoDrawable gLDrawable, final int x, final int y, final int width, final int height) { + + final GL2 gl = gLDrawable.getGL().getGL2(); + final float aspect = (float) width / (float) height; + gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + gl.glLoadIdentity(); + final float fh = 0.5f; + final float fw = fh * aspect; + gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + @Override + public void display(final GLAutoDrawable gLDrawable) { + + final GL2 gl = gLDrawable.getGL().getGL2(); + + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + gl.glLoadIdentity(); + gl.glTranslatef(0.0f, 0.0f, -5.0f); + + // rotate about the three axes + gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f); + gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f); + gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f); + + // set the color of the quad + if (canvas) { + gl.glColor3f(0.2f, 0.2f, 1.0f); + } else { + gl.glColor3f(1.0f, 0.2f, 0.2f); + } + + if (texture != null) { + texture.bind(gl); + texture.enable(gl); + } else { + System.err.println("no texture"); + } + + // Draw A Quad + gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); + gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexVBO); + gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, texCoordVBO); + gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + gl.glDrawArrays(GL2GL3.GL_QUADS, 0, 4); + gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY); + + if (texture != null) { + texture.disable(gl); + } + + // increasing rotation for the next iteration + rotateT += 0.2f; + } + + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelApplet.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelApplet.java deleted file mode 100644 index 8280919e6..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelApplet.java +++ /dev/null @@ -1,308 +0,0 @@ -/** - * 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.gl2.awt; - -import java.awt.Dimension; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; - -import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.GL2ES1; -import javax.media.opengl.GL2GL3; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.awt.GLCanvas; -import javax.media.opengl.awt.GLJPanel; -import javax.media.opengl.fixedfunc.GLLightingFunc; -import javax.media.opengl.fixedfunc.GLMatrixFunc; -import javax.media.opengl.fixedfunc.GLPointerFunc; -import javax.swing.JApplet; -import javax.swing.JPanel; -import javax.swing.JFrame; - -import com.jogamp.common.util.VersionUtil; -import com.jogamp.opengl.JoglVersion; -import com.jogamp.opengl.util.Animator; -import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureIO; - -/** - * Bug 818: OSX GLJPanel Crash - *
- * - NVIDIA GeForce GT 330M - * - GL_VENDOR: "NVIDIA Corporation" - * - GL_RENDERER: "NVIDIA GeForce GT 330M OpenGL Engine" - * - GL_VERSION: "2.1 NVIDIA-8.12.47 310.40.00.05f01" - * - Mac OSX 10.6.8 - *- */ -public class Bug818GLJPanelApplet extends JApplet { - - private static final long serialVersionUID = 1L; - - private Animator animatorCanvas; - - private Animator animatorPanel; - - public static JFrame frame; - public static JPanel appletHolder; - public static boolean isApplet = true; - - static public void main(final String args[]) { - isApplet = false; - - final JApplet myApplet = new Bug818GLJPanelApplet(); - - appletHolder = new JPanel(); - - frame = new JFrame("Bug818GLJPanelApplet"); - frame.getContentPane().add(myApplet); - - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(final WindowEvent e) { - System.exit(0); - } - }); - - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - myApplet.init(); - frame.validate(); - frame.pack(); - frame.setVisible(true); - } } ); - } catch( final Throwable throwable ) { - throwable.printStackTrace(); - } - - myApplet.start(); - } - - - @Override - public void init() { - - final JPanel panel = new JPanel(); - setContentPane(panel); - - final GLCanvas glCanvas = new GLCanvas(); - glCanvas.addGLEventListener(new JOGLQuad(true)); - animatorCanvas = new Animator(glCanvas); - glCanvas.setPreferredSize(new Dimension(300, 300)); - panel.add(glCanvas); - - final GLJPanel gljPanel = new GLJPanel(); - gljPanel.addGLEventListener(new JOGLQuad(false)); - animatorPanel = new Animator(gljPanel); - gljPanel.setPreferredSize(new Dimension(300, 300)); - panel.add(gljPanel); - } - - @Override - public void start() { - - animatorCanvas.start(); - animatorCanvas.setUpdateFPSFrames(60, System.err); - animatorPanel.start(); - animatorPanel.setUpdateFPSFrames(60, System.err); - } - - @Override - public void stop() { - - animatorCanvas.stop(); - animatorPanel.stop(); - } - - @Override - public void destroy() {} - - /** - * Self-contained example (within a single class only to keep it simple) displaying a rotating quad - */ - static class JOGLQuad implements GLEventListener { - - private static final float[] VERTEX_DATA = { - -1.0f, 1.0f, 0.0f, // Top Left - 1.0f, 1.0f, 0.0f, // Top Right - 1.0f, -1.0f, 0.0f, // Bottom Right - -1.0f, -1.0f, 0.0f // Bottom Left - }; - - private static final float[] TEXCOORD_DATA = { - 0.0f, 1.0f, // Top Left - 1.0f, 1.0f, // Top Right - 1.0f, 0.0f, // Bottom Right - 0.0f, 0.0f // Bottom Left - }; - - private final FloatBuffer vertexBuf; - - private final FloatBuffer texCoordBuf; - - private int vertexVBO; - - private int texCoordVBO; - - private float rotateT = 0.0f; - - private final boolean canvas; - - private Texture texture; - - JOGLQuad(final boolean canvas) { - - this.canvas = canvas; - - ByteBuffer bb = ByteBuffer.allocateDirect(VERTEX_DATA.length * 4); - bb.order(ByteOrder.nativeOrder()); - vertexBuf = bb.asFloatBuffer(); - vertexBuf.put(VERTEX_DATA); - vertexBuf.rewind(); - - bb = ByteBuffer.allocateDirect(TEXCOORD_DATA.length * 4); - bb.order(ByteOrder.nativeOrder()); - texCoordBuf = bb.asFloatBuffer(); - texCoordBuf.put(TEXCOORD_DATA); - texCoordBuf.rewind(); - } - - @Override - public void init(final GLAutoDrawable glDrawable) { - - final GL2 gl = glDrawable.getGL().getGL2(); - - System.err.println(VersionUtil.getPlatformInfo()); - System.err.println(JoglVersion.getGLInfo(gl, null, false /* withCapabilitiesAndExtensionInfo */).toString()); - - gl.glShadeModel(GLLightingFunc.GL_SMOOTH); - gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - gl.glClearDepth(1.0f); - gl.glEnable(GL.GL_DEPTH_TEST); - gl.glDepthFunc(GL.GL_LEQUAL); - gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); - - final int[] tmp = new int[2]; - gl.glGenBuffers(tmp.length, tmp, 0); - vertexVBO = tmp[0]; - texCoordVBO = tmp[1]; - - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexVBO); - gl.glBufferData(GL.GL_ARRAY_BUFFER, VERTEX_DATA.length * 4, vertexBuf, GL.GL_STATIC_DRAW); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, texCoordVBO); - gl.glBufferData(GL.GL_ARRAY_BUFFER, TEXCOORD_DATA.length * 4, texCoordBuf, GL.GL_STATIC_DRAW); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - - try { - final InputStream stream = getClass().getClassLoader().getResourceAsStream("com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-base.jpg"); - texture = TextureIO.newTexture(stream, true, TextureIO.JPG); - } catch (final Exception exc) { - exc.printStackTrace(System.err); - } - } - - @Override - public void dispose(final GLAutoDrawable drawable) { - - final GL2 gl = drawable.getGL().getGL2(); - final int[] tmp = new int[] {vertexVBO, texCoordVBO}; - gl.glGenBuffers(tmp.length, tmp, 0); - } - - @Override - public void reshape(final GLAutoDrawable gLDrawable, final int x, final int y, final int width, final int height) { - - final GL2 gl = gLDrawable.getGL().getGL2(); - final float aspect = (float) width / (float) height; - gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - gl.glLoadIdentity(); - final float fh = 0.5f; - final float fw = fh * aspect; - gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f); - gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - gl.glLoadIdentity(); - } - - @Override - public void display(final GLAutoDrawable gLDrawable) { - - final GL2 gl = gLDrawable.getGL().getGL2(); - - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - gl.glLoadIdentity(); - gl.glTranslatef(0.0f, 0.0f, -5.0f); - - // rotate about the three axes - gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f); - gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f); - gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f); - - // set the color of the quad - if (canvas) { - gl.glColor3f(0.2f, 1.0f, 1.0f); - } else { - gl.glColor3f(1.0f, 0.2f, 0.2f); - } - - if (texture != null) { - texture.bind(gl); - texture.enable(gl); - } else { - System.err.println("no texture"); - } - - // Draw A Quad - gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); - gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexVBO); - gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, texCoordVBO); - gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - gl.glDrawArrays(GL2GL3.GL_QUADS, 0, 4); - gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); - gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY); - - if (texture != null) { - texture.disable(gl); - } - - // increasing rotation for the next iteration - rotateT += 0.2f; - } - - } -} - -- cgit v1.2.3