* LwjglCanvas now correctly resets the renderer state by calling renderer.invalidateState(). Doing renderer.resetGLObjects() is NOT sufficient in many cases ...

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7443 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent a58814b838
commit f004d23070
  1. 61
      engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglCanvas.java
  2. 12
      engine/src/test/jme3test/awt/TestCanvas.java

@ -43,7 +43,6 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.Pbuffer; import org.lwjgl.opengl.Pbuffer;
@ -63,7 +62,6 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
private Thread renderThread; private Thread renderThread;
private boolean runningFirstTime = true; private boolean runningFirstTime = true;
private boolean mouseWasGrabbed = false; private boolean mouseWasGrabbed = false;
private boolean mouseActive, keyboardActive;
private Pbuffer pbuffer; private Pbuffer pbuffer;
@ -116,12 +114,12 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
logger.log(Level.SEVERE, "EDT: Broken barrier! ", ex); logger.log(Level.SEVERE, "EDT: Broken barrier! ", ex);
} }
logger.log(Level.INFO, "EDT: Acknowledged receipt of canvas death");
// GL context is dead at this point
// Reset barrier for future use // Reset barrier for future use
actionRequiredBarrier.reset(); actionRequiredBarrier.reset();
logger.log(Level.INFO, "EDT: Acknowledged receipt of canvas death");
// GL context is dead at this point
super.removeNotify(); super.removeNotify();
} }
} }
@ -199,19 +197,11 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
} }
private void pauseCanvas(){ private void pauseCanvas(){
mouseActive = Mouse.isCreated(); if (Mouse.isCreated() && Mouse.isGrabbed()){
keyboardActive = Keyboard.isCreated();
if (mouseActive && Mouse.isGrabbed()){
Mouse.setGrabbed(false); Mouse.setGrabbed(false);
mouseWasGrabbed = true; mouseWasGrabbed = true;
} }
if (mouseActive)
Mouse.destroy();
if (keyboardActive)
Keyboard.destroy();
logger.log(Level.INFO, "OGL: Canvas will become invisible! Destroying .."); logger.log(Level.INFO, "OGL: Canvas will become invisible! Destroying ..");
renderable.set(false); renderable.set(false);
@ -237,35 +227,12 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
renderable.set(true); renderable.set(true);
createContext(settings); createContext(settings);
// must call after createContext, as renderer might be null
// renderer.resetGLObjects();
logger.log(Level.INFO, "OGL: Waiting for display to become active..");
// NOTE: A deadlock will happen here if createContext had an exception
while (!Display.isCreated()){
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, "OGL: Interrupted! ", ex);
}
}
logger.log(Level.INFO, "OGL: Display is active!"); logger.log(Level.INFO, "OGL: Display is active!");
try { if (Mouse.isCreated() && mouseWasGrabbed){
if (mouseActive){
Mouse.create();
if (mouseWasGrabbed){
Mouse.setGrabbed(true); Mouse.setGrabbed(true);
mouseWasGrabbed = false; mouseWasGrabbed = false;
} }
}
if (keyboardActive){
Keyboard.create();
}
logger.log(Level.INFO, "OGL: Input has been reinitialized");
} catch (LWJGLException ex) {
listener.handleError("Failed to re-init input", ex);
}
SwingUtilities.invokeLater(new Runnable(){ SwingUtilities.invokeLater(new Runnable(){
public void run(){ public void run(){
@ -280,7 +247,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
protected void makePbufferAvailable() throws LWJGLException{ protected void makePbufferAvailable() throws LWJGLException{
if (pbuffer == null || pbuffer.isBufferLost()){ if (pbuffer == null || pbuffer.isBufferLost()){
if (pbuffer != null && pbuffer.isBufferLost()){ if (pbuffer != null && pbuffer.isBufferLost()){
pbuffer.releaseContext(); logger.log(Level.WARNING, "PBuffer was lost!");
pbuffer.destroy(); pbuffer.destroy();
} }
pbuffer = new Pbuffer(1, 1, new PixelFormat(0, 0, 0), null); pbuffer = new Pbuffer(1, 1, new PixelFormat(0, 0, 0), null);
@ -294,15 +261,9 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
* 2) Any time the canvas becomes non-displayable * 2) Any time the canvas becomes non-displayable
*/ */
protected void destroyContext(){ protected void destroyContext(){
try {
renderer.resetGLObjects();
if (Display.isCreated()){ if (Display.isCreated()){
Display.releaseContext();
Display.destroy(); Display.destroy();
} }
} catch (LWJGLException ex) {
listener.handleError("Failed to destroy context", ex);
}
try { try {
// The canvas is no longer visible, // The canvas is no longer visible,
@ -314,6 +275,9 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
// pbuffer is now available, make it current // pbuffer is now available, make it current
pbuffer.makeCurrent(); pbuffer.makeCurrent();
// invalidate the state so renderer can resume operation
renderer.invalidateState();
}else{ }else{
// The context thread is no longer running. // The context thread is no longer running.
// Destroy pbuffer. // Destroy pbuffer.
@ -342,6 +306,8 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
makePbufferAvailable(); makePbufferAvailable();
if (renderable.get()){ if (renderable.get()){
// if the pbuffer is currently active,
// make sure to deactivate it
if (pbuffer.isCurrent()){ if (pbuffer.isCurrent()){
pbuffer.releaseContext(); pbuffer.releaseContext();
} }
@ -354,7 +320,10 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
settings.getStencilBits(), settings.getStencilBits(),
settings.getSamples()); settings.getSamples());
Display.create(pf, pbuffer); Display.create(pf, pbuffer);
Display.makeCurrent();
// because the display is a different opengl context
// must reset the context state.
renderer.invalidateState();
}else{ }else{
pbuffer.makeCurrent(); pbuffer.makeCurrent();
} }

@ -37,12 +37,16 @@ import com.jme3.app.SimpleApplication;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext; import com.jme3.system.JmeCanvasContext;
import com.jme3.system.JmeSystem; import com.jme3.system.JmeSystem;
import com.jme3.util.JmeFormatter;
import java.awt.Canvas; import java.awt.Canvas;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
@ -173,6 +177,14 @@ public class TestCanvas {
} }
public static void main(String[] args){ public static void main(String[] args){
JmeFormatter formatter = new JmeFormatter();
Handler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(formatter);
Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
Logger.getLogger("").addHandler(consoleHandler);
SwingUtilities.invokeLater(new Runnable(){ SwingUtilities.invokeLater(new Runnable(){
public void run(){ public void run(){
JPopupMenu.setDefaultLightWeightPopupEnabled(false); JPopupMenu.setDefaultLightWeightPopupEnabled(false);

Loading…
Cancel
Save