* Switch to new native library loader
* Deprecate old library loader * Add warning when the requested number of antialiasing samples cannot be satisfied * Cleaned up LwjglContext.determineMaxSamples()
This commit is contained in:
parent
17fd3d466e
commit
54ffe15dda
@ -307,13 +307,5 @@ public class JmeDesktopSystem extends JmeSystemDelegate {
|
|||||||
logger.log(Level.SEVERE, "Security error in creating log file", ex);
|
logger.log(Level.SEVERE, "Security error in creating log file", ex);
|
||||||
}
|
}
|
||||||
logger.log(Level.INFO, "Running on {0}", getFullName());
|
logger.log(Level.INFO, "Running on {0}", getFullName());
|
||||||
|
|
||||||
if (!lowPermissions) {
|
|
||||||
try {
|
|
||||||
Natives.extractNativeLibs(getPlatform(), settings);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
logger.log(Level.SEVERE, "Error while copying native libraries", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,24 @@ public final class NativeLibraryLoader {
|
|||||||
private NativeLibraryLoader() {
|
private NativeLibraryLoader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if native bullet is on the classpath.
|
||||||
|
*
|
||||||
|
* Currently the context extracts the native bullet libraries, so
|
||||||
|
* this method is needed to determine if it is needed.
|
||||||
|
* Ideally, native bullet should be responsible for its own natives.
|
||||||
|
*
|
||||||
|
* @return True native bullet is on the classpath, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isUsingNativeBullet() {
|
||||||
|
try {
|
||||||
|
Class clazz = Class.forName("com.jme3.bullet.util.NativeMeshUtil");
|
||||||
|
return clazz != null;
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify a custom location where native libraries should
|
* Specify a custom location where native libraries should
|
||||||
* be extracted to. Ensure this is a unique path not used
|
* be extracted to. Ensure this is a unique path not used
|
||||||
|
@ -41,7 +41,10 @@ import java.util.logging.Logger;
|
|||||||
/**
|
/**
|
||||||
* Helper class for extracting the natives (dll, so) from the jars.
|
* Helper class for extracting the natives (dll, so) from the jars.
|
||||||
* This class should only be used internally.
|
* This class should only be used internally.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link NativeLibraryLoader} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final class Natives {
|
public final class Natives {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(Natives.class.getName());
|
private static final Logger logger = Logger.getLogger(Natives.class.getName());
|
||||||
@ -238,6 +241,10 @@ public final class Natives {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void extractNativeLibs(Platform platform, AppSettings settings) throws IOException {
|
public static void extractNativeLibs(Platform platform, AppSettings settings) throws IOException {
|
||||||
|
if (true) {
|
||||||
|
throw new UnsupportedEncodingException("Now, why would you EVER want to do that?");
|
||||||
|
}
|
||||||
|
|
||||||
String renderer = settings.getRenderer();
|
String renderer = settings.getRenderer();
|
||||||
String audioRenderer = settings.getAudioRenderer();
|
String audioRenderer = settings.getAudioRenderer();
|
||||||
boolean needLWJGL = false;
|
boolean needLWJGL = false;
|
||||||
|
@ -83,6 +83,8 @@ public abstract class JoglAbstractDisplay extends JoglContext implements GLEvent
|
|||||||
protected boolean wasAnimating = false;
|
protected boolean wasAnimating = false;
|
||||||
|
|
||||||
protected void initGLCanvas() {
|
protected void initGLCanvas() {
|
||||||
|
loadNatives();
|
||||||
|
|
||||||
device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||||
|
|
||||||
//FIXME use the settings to know whether to use the max programmable profile
|
//FIXME use the settings to know whether to use the max programmable profile
|
||||||
|
@ -40,16 +40,21 @@ import com.jme3.renderer.jogl.JoglRenderer;
|
|||||||
import com.jme3.system.AppSettings;
|
import com.jme3.system.AppSettings;
|
||||||
import com.jme3.system.JmeContext;
|
import com.jme3.system.JmeContext;
|
||||||
import com.jme3.system.NanoTimer;
|
import com.jme3.system.NanoTimer;
|
||||||
|
import com.jme3.system.NativeLibraryLoader;
|
||||||
import com.jme3.system.SystemListener;
|
import com.jme3.system.SystemListener;
|
||||||
import com.jme3.system.Timer;
|
import com.jme3.system.Timer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import javax.media.opengl.GL;
|
import javax.media.opengl.GL;
|
||||||
import javax.media.opengl.GL2GL3;
|
import javax.media.opengl.GL2GL3;
|
||||||
import javax.media.opengl.GLContext;
|
import javax.media.opengl.GLContext;
|
||||||
|
|
||||||
public abstract class JoglContext implements JmeContext {
|
public abstract class JoglContext implements JmeContext {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(JoglContext.class.getName());
|
||||||
|
|
||||||
protected AtomicBoolean created = new AtomicBoolean(false);
|
protected AtomicBoolean created = new AtomicBoolean(false);
|
||||||
protected AtomicBoolean renderable = new AtomicBoolean(false);
|
protected AtomicBoolean renderable = new AtomicBoolean(false);
|
||||||
protected final Object createdLock = new Object();
|
protected final Object createdLock = new Object();
|
||||||
@ -63,6 +68,13 @@ public abstract class JoglContext implements JmeContext {
|
|||||||
protected MouseInput mouseInput;
|
protected MouseInput mouseInput;
|
||||||
protected JoyInput joyInput;
|
protected JoyInput joyInput;
|
||||||
|
|
||||||
|
public void loadNatives() {
|
||||||
|
// Not sure if need to load OpenAL here ...
|
||||||
|
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setSystemListener(SystemListener listener){
|
public void setSystemListener(SystemListener listener){
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
@ -162,6 +174,11 @@ public abstract class JoglContext implements JmeContext {
|
|||||||
samples = settings.getSamples();
|
samples = settings.getSamples();
|
||||||
int supportedSamples = determineMaxSamples(samples);
|
int supportedSamples = determineMaxSamples(samples);
|
||||||
if (supportedSamples < samples) {
|
if (supportedSamples < samples) {
|
||||||
|
logger.log(Level.WARNING,
|
||||||
|
"Couldn''t satisfy antialiasing samples requirement: x{0}. "
|
||||||
|
+ "Video hardware only supports: x{1}",
|
||||||
|
new Object[]{samples, supportedSamples});
|
||||||
|
|
||||||
samples = supportedSamples;
|
samples = supportedSamples;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ public abstract class JoglNewtAbstractDisplay extends JoglContext implements GLE
|
|||||||
protected boolean wasAnimating = false;
|
protected boolean wasAnimating = false;
|
||||||
|
|
||||||
protected void initGLCanvas() {
|
protected void initGLCanvas() {
|
||||||
|
loadNatives();
|
||||||
//FIXME use the settings to know whether to use the max programmable profile
|
//FIXME use the settings to know whether to use the max programmable profile
|
||||||
//then call GLProfile.getMaxProgrammable(true);
|
//then call GLProfile.getMaxProgrammable(true);
|
||||||
//FIXME use the default profile only on embedded devices
|
//FIXME use the default profile only on embedded devices
|
||||||
|
@ -121,6 +121,7 @@ public class JoglOffscreenBuffer extends JoglContext implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
|
loadNatives();
|
||||||
logger.log(Level.FINE, "Using JOGL {0}", NewtVersion.getInstance().getImplementationVersion());
|
logger.log(Level.FINE, "Using JOGL {0}", NewtVersion.getInstance().getImplementationVersion());
|
||||||
initInThread();
|
initInThread();
|
||||||
while (!needClose.get()){
|
while (!needClose.get()){
|
||||||
|
@ -199,10 +199,12 @@ public abstract class LwjglAbstractDisplay extends LwjglContext implements Runna
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
if (listener == null)
|
if (listener == null) {
|
||||||
throw new IllegalStateException("SystemListener is not set on context!"
|
throw new IllegalStateException("SystemListener is not set on context!"
|
||||||
+ "Must set with JmeContext.setSystemListner().");
|
+ "Must set with JmeContext.setSystemListner().");
|
||||||
|
}
|
||||||
|
|
||||||
|
loadNatives();
|
||||||
logger.log(Level.FINE, "Using LWJGL {0}", Sys.getVersion());
|
logger.log(Level.FINE, "Using LWJGL {0}", Sys.getVersion());
|
||||||
if (!initInThread()) {
|
if (!initInThread()) {
|
||||||
logger.log(Level.SEVERE, "Display initialization failed. Cannot continue.");
|
logger.log(Level.SEVERE, "Display initialization failed. Cannot continue.");
|
||||||
|
@ -42,6 +42,7 @@ import com.jme3.renderer.lwjgl.LwjglRenderer;
|
|||||||
import com.jme3.system.AppSettings;
|
import com.jme3.system.AppSettings;
|
||||||
import com.jme3.system.JmeContext;
|
import com.jme3.system.JmeContext;
|
||||||
import com.jme3.system.JmeSystem;
|
import com.jme3.system.JmeSystem;
|
||||||
|
import com.jme3.system.NativeLibraryLoader;
|
||||||
import com.jme3.system.SystemListener;
|
import com.jme3.system.SystemListener;
|
||||||
import com.jme3.system.Timer;
|
import com.jme3.system.Timer;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@ -115,7 +116,6 @@ public abstract class LwjglContext implements JmeContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected int determineMaxSamples(int requestedSamples) {
|
protected int determineMaxSamples(int requestedSamples) {
|
||||||
boolean displayWasCurrent = false;
|
|
||||||
try {
|
try {
|
||||||
// If we already have a valid context, determine samples using current
|
// If we already have a valid context, determine samples using current
|
||||||
// context.
|
// context.
|
||||||
@ -124,9 +124,10 @@ public abstract class LwjglContext implements JmeContext {
|
|||||||
return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES);
|
return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES);
|
||||||
} else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) {
|
} else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) {
|
||||||
return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT);
|
return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT);
|
||||||
|
} else {
|
||||||
|
// Unknown.
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
// Doesn't support any of the needed extensions .. continue down.
|
|
||||||
displayWasCurrent = true;
|
|
||||||
}
|
}
|
||||||
} catch (LWJGLException ex) {
|
} catch (LWJGLException ex) {
|
||||||
listener.handleError("Failed to check if display is current", ex);
|
listener.handleError("Failed to check if display is current", ex);
|
||||||
@ -138,74 +139,59 @@ public abstract class LwjglContext implements JmeContext {
|
|||||||
} else {
|
} else {
|
||||||
Pbuffer pb = null;
|
Pbuffer pb = null;
|
||||||
|
|
||||||
if (!displayWasCurrent) {
|
// OpenGL2 method: Create pbuffer and query samples
|
||||||
// OpenGL2 method: Create pbuffer and query samples
|
// from GL_ARB_framebuffer_object or GL_EXT_framebuffer_multisample.
|
||||||
// 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 (DOESNT WORK RIGHT NOW ..)
|
|
||||||
requestedSamples = FastMath.nearestPowerOfTwo(requestedSamples);
|
|
||||||
try {
|
try {
|
||||||
requestedSamples = Integer.MAX_VALUE;
|
pb = new Pbuffer(1, 1, new PixelFormat(0, 0, 0), null);
|
||||||
/*
|
pb.makeCurrent();
|
||||||
while (requestedSamples > 1) {
|
|
||||||
try {
|
if (GLContext.getCapabilities().GL_ARB_framebuffer_object) {
|
||||||
pb = new Pbuffer(1, 1, new PixelFormat(16, 0, 8, 0, requestedSamples), null);
|
return GL11.glGetInteger(ARBFramebufferObject.GL_MAX_SAMPLES);
|
||||||
} catch (LWJGLException ex) {
|
} else if (GLContext.getCapabilities().GL_EXT_framebuffer_multisample) {
|
||||||
if (ex.getMessage().startsWith("Failed to find ARB pixel format")) {
|
return GL11.glGetInteger(EXTFramebufferMultisample.GL_MAX_SAMPLES_EXT);
|
||||||
// Unsupported format, so continue.
|
}
|
||||||
requestedSamples = FastMath.nearestPowerOfTwo(requestedSamples / 2);
|
|
||||||
} else {
|
// OpenGL2 method failed.
|
||||||
// Something else went wrong ..
|
return Integer.MAX_VALUE;
|
||||||
return Integer.MAX_VALUE;
|
} catch (LWJGLException ex) {
|
||||||
}
|
// Something else failed.
|
||||||
} finally {
|
return Integer.MAX_VALUE;
|
||||||
if (pb != null){
|
|
||||||
pb.destroy();
|
|
||||||
pb = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
} finally {
|
} finally {
|
||||||
if (displayWasCurrent) {
|
if (pb != null) {
|
||||||
try {
|
pb.destroy();
|
||||||
Display.makeCurrent();
|
|
||||||
} catch (LWJGLException ex) {
|
|
||||||
listener.handleError("Failed to make display current after checking samples", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return requestedSamples;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void loadNatives() {
|
||||||
|
if (JmeSystem.isLowPermissions()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ("LWJGL".equals(settings.getAudioRenderer())) {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("openal", true);
|
||||||
|
}
|
||||||
|
if (settings.useJoysticks()) {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("jinput", true);
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("jinput-dx8", true);
|
||||||
|
}
|
||||||
|
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
||||||
|
}
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("lwjgl", true);
|
||||||
|
}
|
||||||
|
|
||||||
protected int getNumSamplesToUse() {
|
protected int getNumSamplesToUse() {
|
||||||
int samples = 0;
|
int samples = 0;
|
||||||
if (settings.getSamples() > 1){
|
if (settings.getSamples() > 1){
|
||||||
samples = settings.getSamples();
|
samples = settings.getSamples();
|
||||||
int supportedSamples = determineMaxSamples(samples);
|
int supportedSamples = determineMaxSamples(samples);
|
||||||
if (supportedSamples < samples) {
|
if (supportedSamples < samples) {
|
||||||
|
logger.log(Level.WARNING,
|
||||||
|
"Couldn''t satisfy antialiasing samples requirement: x{0}. "
|
||||||
|
+ "Video hardware only supports: x{1}",
|
||||||
|
new Object[]{samples, supportedSamples});
|
||||||
|
|
||||||
samples = supportedSamples;
|
samples = supportedSamples;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user