* Tried to fix canvas + multisampling bug by creating 1 sample pbuffer

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8167 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 13 years ago
parent 471f449017
commit 71cb644853
  1. 60
      engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglCanvas.java

@ -66,8 +66,12 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
private boolean runningFirstTime = true;
private boolean mouseWasGrabbed = false;
private boolean mouseWasCreated = false;
private boolean keyboardWasCreated = false;
private Pbuffer pbuffer;
private PixelFormat pixelFormat;
private PixelFormat pbufferFormat;
private PixelFormat canvasFormat;
private class GLCanvas extends Canvas {
@Override
@ -201,10 +205,18 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
}
private void pauseCanvas(){
if (Mouse.isCreated() && Mouse.isGrabbed()){
if (Mouse.isCreated()){
if (Mouse.isGrabbed()){
Mouse.setGrabbed(false);
mouseWasGrabbed = true;
}
mouseWasCreated = true;
Mouse.destroy();
}
if (Keyboard.isCreated()){
keyboardWasCreated = true;
Keyboard.destroy();
}
logger.log(Level.INFO, "OGL: Canvas will become invisible! Destroying ..");
@ -233,10 +245,21 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
logger.log(Level.INFO, "OGL: Display is active!");
if (Mouse.isCreated() && mouseWasGrabbed){
try {
if (mouseWasCreated){
Mouse.create();
if (mouseWasGrabbed){
Mouse.setGrabbed(true);
mouseWasGrabbed = false;
}
}
if (keyboardWasCreated){
Keyboard.create();
keyboardWasCreated = false;
}
} catch (LWJGLException ex){
logger.log(Level.SEVERE, "Encountered exception when restoring input", ex);
}
SwingUtilities.invokeLater(new Runnable(){
public void run(){
@ -249,15 +272,26 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
* It seems it is best to use one pixel format for all shared contexts.
* See http://developer.apple.com/library/mac/#qa/qa1248/_index.html.
*/
protected PixelFormat acquirePixelFormat(){
if (pixelFormat == null){
pixelFormat = new PixelFormat(settings.getBitsPerPixel(),
protected PixelFormat acquirePixelFormat(boolean forPbuffer){
if (forPbuffer){
if (pbufferFormat == null){
pbufferFormat = new PixelFormat(settings.getBitsPerPixel(),
0,
settings.getDepthBits(),
settings.getStencilBits(),
0);
}
return pbufferFormat;
}else{
if (canvasFormat == null){
canvasFormat = new PixelFormat(settings.getBitsPerPixel(),
0,
settings.getDepthBits(),
settings.getStencilBits(),
settings.getSamples());
}
return pixelFormat;
return canvasFormat;
}
}
/**
@ -271,7 +305,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
}
if (pbuffer == null) {
pbuffer = new Pbuffer(1, 1, acquirePixelFormat(), null);
pbuffer = new Pbuffer(1, 1, acquirePixelFormat(true), null);
logger.log(Level.INFO, "OGL: Pbuffer has been created");
}
}
@ -298,13 +332,13 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
}else{
// The context thread is no longer running.
// Destroy pbuffer.
if (pbuffer != null){
if (pbuffer != null && !pbuffer.isBufferLost()){
pbuffer.destroy();
pbuffer = null;
}
}
if (Display.isCreated()){
/* FIXES:
* org.lwjgl.LWJGLException: X Error
* BadWindow (invalid Window parameter) request_code: 2 minor_code: 0
@ -313,7 +347,11 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
* by destroying keyboard in by Display.destroy() or Display.setParent(null).
* Therefore Keyboard.destroy() should precede any of these calls.
*/
if (Keyboard.isCreated()){
// Should only happen if called in
// LwjglAbstractDisplay.deinitInThread().
Keyboard.destroy();
}
try {
// NOTE: On Windows XP, not calling setParent(null)
@ -359,7 +397,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
Display.setVSyncEnabled(settings.isVSync());
Display.setParent(canvas);
Display.create(acquirePixelFormat(), pbuffer);
Display.create(acquirePixelFormat(false), pbuffer);
// because the display is a different opengl context
// must reset the context state.

Loading…
Cancel
Save