Fixes a bug occurring when exiting the full screen mode and adds an abstract display based on NEWT (work in progress)
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9938 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
0170c7b5eb
commit
44b89a367c
@ -0,0 +1,178 @@ |
||||
/* |
||||
* Copyright (c) 2009-2012 jMonkeyEngine |
||||
* 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 'jMonkeyEngine' 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 THE COPYRIGHT OWNER 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. |
||||
*/ |
||||
|
||||
package com.jme3.system.jogl; |
||||
|
||||
import com.jme3.input.KeyInput; |
||||
import com.jme3.input.MouseInput; |
||||
import com.jme3.input.TouchInput; |
||||
import com.jme3.renderer.jogl.JoglRenderer; |
||||
import com.jogamp.newt.opengl.GLWindow; |
||||
import com.jogamp.opengl.util.Animator; |
||||
import com.jogamp.opengl.util.AnimatorBase; |
||||
import com.jogamp.opengl.util.FPSAnimator; |
||||
import java.util.concurrent.atomic.AtomicBoolean; |
||||
import java.util.logging.Logger; |
||||
import javax.media.opengl.DebugGL4bc; |
||||
import javax.media.opengl.GL; |
||||
import javax.media.opengl.GLAutoDrawable; |
||||
import javax.media.opengl.GLCapabilities; |
||||
import javax.media.opengl.GLEventListener; |
||||
import javax.media.opengl.GLProfile; |
||||
import javax.media.opengl.GLRunnable; |
||||
|
||||
public abstract class JoglNewtAbstractDisplay extends JoglContext implements GLEventListener { |
||||
|
||||
private static final Logger logger = Logger.getLogger(JoglNewtAbstractDisplay.class.getName()); |
||||
|
||||
protected GLWindow canvas; |
||||
|
||||
protected AnimatorBase animator; |
||||
|
||||
protected AtomicBoolean active = new AtomicBoolean(false); |
||||
|
||||
protected boolean wasActive = false; |
||||
|
||||
protected int frameRate; |
||||
|
||||
protected boolean useAwt = true; |
||||
|
||||
protected AtomicBoolean autoFlush = new AtomicBoolean(true); |
||||
|
||||
protected boolean wasAnimating = false; |
||||
|
||||
protected void initGLCanvas() { |
||||
//FIXME use the settings to know whether to use the max programmable profile
|
||||
//then call GLProfile.getMaxProgrammable(true);
|
||||
GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true)); |
||||
caps.setHardwareAccelerated(true); |
||||
caps.setDoubleBuffered(true); |
||||
caps.setStencilBits(settings.getStencilBits()); |
||||
caps.setDepthBits(settings.getDepthBits()); |
||||
|
||||
if (settings.getSamples() > 1) { |
||||
caps.setSampleBuffers(true); |
||||
caps.setNumSamples(settings.getSamples()); |
||||
} |
||||
canvas = GLWindow.create(caps); |
||||
if (settings.isVSync()) { |
||||
canvas.invoke(false, new GLRunnable() { |
||||
|
||||
public boolean run(GLAutoDrawable glad) { |
||||
canvas.getGL().setSwapInterval(1); |
||||
return true; |
||||
} |
||||
}); |
||||
} |
||||
canvas.requestFocus(); |
||||
canvas.setSize(settings.getWidth(), settings.getHeight()); |
||||
canvas.addGLEventListener(this); |
||||
|
||||
if (settings.getBoolean("GraphicsDebug")) { |
||||
canvas.invoke(false, new GLRunnable() { |
||||
|
||||
public boolean run(GLAutoDrawable glad) { |
||||
GL gl = glad.getGL(); |
||||
if (gl.isGL4bc()) { |
||||
canvas.setGL(new DebugGL4bc(gl.getGL4bc())); |
||||
} |
||||
return true; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
renderer = new JoglRenderer(); |
||||
} |
||||
|
||||
protected void startGLCanvas() { |
||||
if (frameRate > 0) { |
||||
animator = new FPSAnimator(canvas, frameRate); |
||||
} |
||||
else { |
||||
animator = new Animator(); |
||||
animator.add(canvas); |
||||
((Animator) animator).setRunAsFastAsPossible(true); |
||||
} |
||||
|
||||
animator.start(); |
||||
wasAnimating = true; |
||||
|
||||
//FIXME not sure it is the best place to do that
|
||||
renderable.set(true); |
||||
} |
||||
|
||||
protected void onCanvasAdded() { |
||||
} |
||||
|
||||
protected void onCanvasRemoved() { |
||||
} |
||||
|
||||
@Override |
||||
public KeyInput getKeyInput() { |
||||
//TODO
|
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public MouseInput getMouseInput() { |
||||
//TODO
|
||||
return null; |
||||
} |
||||
|
||||
public TouchInput getTouchInput() { |
||||
return null; |
||||
} |
||||
|
||||
public void setAutoFlushFrames(boolean enabled) { |
||||
autoFlush.set(enabled); |
||||
} |
||||
|
||||
/** |
||||
* Callback. |
||||
*/ |
||||
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { |
||||
listener.reshape(width, height); |
||||
} |
||||
|
||||
/** |
||||
* Callback. |
||||
*/ |
||||
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { |
||||
} |
||||
|
||||
/** |
||||
* Callback |
||||
*/ |
||||
public void dispose(GLAutoDrawable drawable) { |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue