* Fix issue 506

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9616 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent be58274ab8
commit e78474a5b1
  1. 11
      engine/src/lwjgl/com/jme3/system/lwjgl/LwjglCanvas.java
  2. 78
      engine/src/lwjgl/com/jme3/system/lwjgl/LwjglContext.java
  3. 9
      engine/src/lwjgl/com/jme3/system/lwjgl/LwjglDisplay.java
  4. 7
      engine/src/lwjgl/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java

@ -84,8 +84,9 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
public void addNotify(){ public void addNotify(){
super.addNotify(); super.addNotify();
if (renderThread != null && renderThread.getState() == Thread.State.TERMINATED) if (renderThread != null && renderThread.getState() == Thread.State.TERMINATED) {
return; // already destroyed. return; // already destroyed.
}
if (renderThread == null){ if (renderThread == null){
logger.log(Level.INFO, "EDT: Creating OGL thread."); logger.log(Level.INFO, "EDT: Creating OGL thread.");
@ -166,9 +167,10 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
} }
// do not do anything. // do not do anything.
// superclass's create() will be called at initInThread() // superclass's create() will be called at initInThread()
if (waitFor) if (waitFor) {
waitFor(true); waitFor(true);
} }
}
@Override @Override
public void setTitle(String title) { public void setTitle(String title) {
@ -307,10 +309,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
return pbufferFormat; return pbufferFormat;
}else{ }else{
if (canvasFormat == null){ if (canvasFormat == null){
int samples = 0; int samples = getNumSamplesToUse();
if (settings.getSamples() > 1){
samples = settings.getSamples();
}
canvasFormat = new PixelFormat(settings.getBitsPerPixel(), canvasFormat = new PixelFormat(settings.getBitsPerPixel(),
0, 0,
settings.getDepthBits(), settings.getDepthBits(),

@ -35,6 +35,7 @@ package com.jme3.system.lwjgl;
import com.jme3.input.lwjgl.JInputJoyInput; import com.jme3.input.lwjgl.JInputJoyInput;
import com.jme3.input.lwjgl.LwjglKeyInput; import com.jme3.input.lwjgl.LwjglKeyInput;
import com.jme3.input.lwjgl.LwjglMouseInput; import com.jme3.input.lwjgl.LwjglMouseInput;
import com.jme3.math.FastMath;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.renderer.lwjgl.LwjglGL1Renderer; import com.jme3.renderer.lwjgl.LwjglGL1Renderer;
import com.jme3.renderer.lwjgl.LwjglRenderer; import com.jme3.renderer.lwjgl.LwjglRenderer;
@ -45,6 +46,7 @@ import com.jme3.system.Timer;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
/** /**
@ -109,6 +111,73 @@ public abstract class LwjglContext implements JmeContext {
} }
} }
protected int determineMaxSamples(int requestedSamples) {
if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
// No pbuffer, assume everything is supported.
return Integer.MAX_VALUE;
} else {
Pbuffer pb = null;
// OpenGL2 method: Create pbuffer and query samples
// from GL_ARB_framebuffer_object or GL_EXT_framebuffer_multisample.
try {
pb = new Pbuffer(1, 1, new PixelFormat(0, 0, 0), null);
pb.makeCurrent();
if (GLContext.getCapabilities().GL_ARB_framebuffer_object) {
return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES);
} else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) {
return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT);
}
// OpenGL2 method failed.
} catch (LWJGLException ex) {
// Something else failed.
return Integer.MAX_VALUE;
} finally {
if (pb != null) {
pb.destroy();
pb = null;
}
}
// OpenGL1 method
requestedSamples = FastMath.nearestPowerOfTwo(requestedSamples);
while (requestedSamples > 1) {
try {
pb = new Pbuffer(1, 1, new PixelFormat(0, 0, 0, requestedSamples), null);
} catch (LWJGLException ex) {
if (ex.getMessage().startsWith("Failed to find ARB pixel format")) {
// Unsupported format, so continue.
requestedSamples /= 2;
} else {
// Something else went wrong ..
return Integer.MAX_VALUE;
}
} finally {
if (pb != null){
pb.destroy();
pb = null;
}
}
}
return requestedSamples;
}
}
protected int getNumSamplesToUse() {
int samples = 0;
if (settings.getSamples() > 1){
samples = settings.getSamples();
int supportedSamples = determineMaxSamples(samples);
if (supportedSamples < samples) {
samples = supportedSamples;
}
}
return samples;
}
protected void initContextFirstTime(){ protected void initContextFirstTime(){
if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2) if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2)
|| settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)){ || settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)){
@ -136,15 +205,18 @@ public abstract class LwjglContext implements JmeContext {
} }
// Init input // Init input
if (keyInput != null) if (keyInput != null) {
keyInput.initialize(); keyInput.initialize();
}
if (mouseInput != null) if (mouseInput != null) {
mouseInput.initialize(); mouseInput.initialize();
}
if (joyInput != null) if (joyInput != null) {
joyInput.initialize(); joyInput.initialize();
} }
}
public void internalDestroy(){ public void internalDestroy(){
renderer = null; renderer = null;

@ -82,10 +82,7 @@ public class LwjglDisplay extends LwjglAbstractDisplay {
displayMode = new DisplayMode(settings.getWidth(), settings.getHeight()); displayMode = new DisplayMode(settings.getWidth(), settings.getHeight());
} }
int samples = 0; int samples = getNumSamplesToUse();
if (settings.getSamples() > 1){
samples = settings.getSamples();
}
PixelFormat pf = new PixelFormat(settings.getBitsPerPixel(), PixelFormat pf = new PixelFormat(settings.getBitsPerPixel(),
0, 0,
settings.getDepthBits(), settings.getDepthBits(),
@ -133,9 +130,9 @@ public class LwjglDisplay extends LwjglAbstractDisplay {
if (!created.get() || pixelFormatChanged){ if (!created.get() || pixelFormatChanged){
ContextAttribs attr = createContextAttribs(); ContextAttribs attr = createContextAttribs();
if (attr != null){ if (attr != null) {
Display.create(pixelFormat, attr); Display.create(pixelFormat, attr);
}else{ } else {
Display.create(pixelFormat); Display.create(pixelFormat);
} }
renderable.set(true); renderable.set(true);

@ -61,15 +61,12 @@ public class LwjglOffscreenBuffer extends LwjglContext implements Runnable {
return; return;
} }
int samples = 0; int samples = getNumSamplesToUse();
if (settings.getSamples() > 1) {
samples = settings.getSamples();
}
pixelFormat = new PixelFormat(settings.getBitsPerPixel(), pixelFormat = new PixelFormat(settings.getBitsPerPixel(),
0, 0,
settings.getDepthBits(), settings.getDepthBits(),
settings.getStencilBits(), settings.getStencilBits(),
settings.getSamples()); samples);
width = settings.getWidth(); width = settings.getWidth();
height = settings.getHeight(); height = settings.getHeight();

Loading…
Cancel
Save