|
@@ -29,7 +29,6 @@
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
*/
|
|
-
|
|
|
|
package com.jme3.system.lwjgl;
|
|
package com.jme3.system.lwjgl;
|
|
|
|
|
|
import com.jme3.input.lwjgl.JInputJoyInput;
|
|
import com.jme3.input.lwjgl.JInputJoyInput;
|
|
@@ -53,6 +52,7 @@ import com.jme3.renderer.opengl.GLTiming;
|
|
import com.jme3.renderer.opengl.GLTimingState;
|
|
import com.jme3.renderer.opengl.GLTimingState;
|
|
import com.jme3.renderer.opengl.GLTracer;
|
|
import com.jme3.renderer.opengl.GLTracer;
|
|
import com.jme3.system.*;
|
|
import com.jme3.system.*;
|
|
|
|
+import java.io.File;
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
@@ -69,7 +69,7 @@ public abstract class LwjglContext implements JmeContext {
|
|
private static final Logger logger = Logger.getLogger(LwjglContext.class.getName());
|
|
private static final Logger logger = Logger.getLogger(LwjglContext.class.getName());
|
|
|
|
|
|
protected static final String THREAD_NAME = "jME3 Main";
|
|
protected static final String THREAD_NAME = "jME3 Main";
|
|
-
|
|
|
|
|
|
+
|
|
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();
|
|
@@ -82,18 +82,18 @@ public abstract class LwjglContext implements JmeContext {
|
|
protected Timer timer;
|
|
protected Timer timer;
|
|
protected SystemListener listener;
|
|
protected SystemListener listener;
|
|
|
|
|
|
- public void setSystemListener(SystemListener listener){
|
|
|
|
|
|
+ public void setSystemListener(SystemListener listener) {
|
|
this.listener = listener;
|
|
this.listener = listener;
|
|
}
|
|
}
|
|
|
|
|
|
protected void printContextInitInfo() {
|
|
protected void printContextInitInfo() {
|
|
- logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n" +
|
|
|
|
- " * Graphics Adapter: {2}\n" +
|
|
|
|
- " * Driver Version: {3}\n" +
|
|
|
|
- " * Scaling Factor: {4}",
|
|
|
|
- new Object[]{ Sys.getVersion(), Thread.currentThread().getName(),
|
|
|
|
- Display.getAdapter(), Display.getVersion(),
|
|
|
|
- Display.getPixelScaleFactor() });
|
|
|
|
|
|
+ logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n"
|
|
|
|
+ + " * Graphics Adapter: {2}\n"
|
|
|
|
+ + " * Driver Version: {3}\n"
|
|
|
|
+ + " * Scaling Factor: {4}",
|
|
|
|
+ new Object[]{Sys.getVersion(), Thread.currentThread().getName(),
|
|
|
|
+ Display.getAdapter(), Display.getVersion(),
|
|
|
|
+ Display.getPixelScaleFactor()});
|
|
}
|
|
}
|
|
|
|
|
|
protected ContextAttribs createContextAttribs() {
|
|
protected ContextAttribs createContextAttribs() {
|
|
@@ -113,7 +113,7 @@ public abstract class LwjglContext implements JmeContext {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected int determineMaxSamples(int requestedSamples) {
|
|
protected int determineMaxSamples(int requestedSamples) {
|
|
try {
|
|
try {
|
|
// If we already have a valid context, determine samples using current
|
|
// If we already have a valid context, determine samples using current
|
|
@@ -131,13 +131,13 @@ public abstract class LwjglContext implements JmeContext {
|
|
} 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);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
|
|
if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
|
|
// No pbuffer, assume everything is supported.
|
|
// No pbuffer, assume everything is supported.
|
|
return Integer.MAX_VALUE;
|
|
return Integer.MAX_VALUE;
|
|
} else {
|
|
} else {
|
|
Pbuffer pb = null;
|
|
Pbuffer pb = null;
|
|
-
|
|
|
|
|
|
+
|
|
// 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 {
|
|
try {
|
|
@@ -155,33 +155,40 @@ public abstract class LwjglContext implements JmeContext {
|
|
} catch (LWJGLException ex) {
|
|
} catch (LWJGLException ex) {
|
|
// Something else failed.
|
|
// Something else failed.
|
|
return Integer.MAX_VALUE;
|
|
return Integer.MAX_VALUE;
|
|
- } finally {
|
|
|
|
|
|
+ } finally {
|
|
if (pb != null) {
|
|
if (pb != null) {
|
|
pb.destroy();
|
|
pb.destroy();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
protected void loadNatives() {
|
|
protected void loadNatives() {
|
|
if (JmeSystem.isLowPermissions()) {
|
|
if (JmeSystem.isLowPermissions()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ String extractPath = NativeLibraryLoader.getExtractionFolder().getAbsolutePath();
|
|
|
|
+
|
|
if ("LWJGL".equals(settings.getAudioRenderer())) {
|
|
if ("LWJGL".equals(settings.getAudioRenderer())) {
|
|
NativeLibraryLoader.loadNativeLibrary("openal", true);
|
|
NativeLibraryLoader.loadNativeLibrary("openal", true);
|
|
}
|
|
}
|
|
if (settings.useJoysticks()) {
|
|
if (settings.useJoysticks()) {
|
|
- NativeLibraryLoader.loadNativeLibrary("jinput", true);
|
|
|
|
- NativeLibraryLoader.loadNativeLibrary("jinput-dx8", true);
|
|
|
|
|
|
+ System.setProperty("net.java.games.input.librarypath", extractPath);
|
|
|
|
+ NativeLibraryLoader.loadNativeLibrary("jinput", true, false);
|
|
|
|
+ NativeLibraryLoader.loadNativeLibrary("jinput-dx8", true, false);
|
|
}
|
|
}
|
|
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
|
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
|
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
|
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
|
}
|
|
}
|
|
- NativeLibraryLoader.loadNativeLibrary("lwjgl", true);
|
|
|
|
|
|
+
|
|
|
|
+ System.setProperty("org.lwjgl.librarypath", extractPath);
|
|
|
|
+ NativeLibraryLoader.loadNativeLibrary("lwjgl", true, false);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
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) {
|
|
@@ -189,62 +196,62 @@ public abstract class LwjglContext implements JmeContext {
|
|
"Couldn''t satisfy antialiasing samples requirement: x{0}. "
|
|
"Couldn''t satisfy antialiasing samples requirement: x{0}. "
|
|
+ "Video hardware only supports: x{1}",
|
|
+ "Video hardware only supports: x{1}",
|
|
new Object[]{samples, supportedSamples});
|
|
new Object[]{samples, supportedSamples});
|
|
-
|
|
|
|
|
|
+
|
|
samples = supportedSamples;
|
|
samples = supportedSamples;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return samples;
|
|
return samples;
|
|
}
|
|
}
|
|
|
|
|
|
- protected void initContextFirstTime(){
|
|
|
|
|
|
+ protected void initContextFirstTime() {
|
|
if (!GLContext.getCapabilities().OpenGL20) {
|
|
if (!GLContext.getCapabilities().OpenGL20) {
|
|
- throw new RendererException("OpenGL 2.0 or higher is " +
|
|
|
|
- "required for jMonkeyEngine");
|
|
|
|
|
|
+ throw new RendererException("OpenGL 2.0 or higher is "
|
|
|
|
+ + "required for jMonkeyEngine");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
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)) {
|
|
GL gl = new LwjglGL();
|
|
GL gl = new LwjglGL();
|
|
GLExt glext = new LwjglGLExt();
|
|
GLExt glext = new LwjglGLExt();
|
|
GLFbo glfbo;
|
|
GLFbo glfbo;
|
|
-
|
|
|
|
|
|
+
|
|
if (GLContext.getCapabilities().OpenGL30) {
|
|
if (GLContext.getCapabilities().OpenGL30) {
|
|
glfbo = new LwjglGLFboGL3();
|
|
glfbo = new LwjglGLFboGL3();
|
|
} else {
|
|
} else {
|
|
glfbo = new LwjglGLFboEXT();
|
|
glfbo = new LwjglGLFboEXT();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (settings.getBoolean("GraphicsDebug")) {
|
|
if (settings.getBoolean("GraphicsDebug")) {
|
|
- gl = new GLDebugDesktop(gl, glext, glfbo);
|
|
|
|
|
|
+ gl = new GLDebugDesktop(gl, glext, glfbo);
|
|
glext = (GLExt) gl;
|
|
glext = (GLExt) gl;
|
|
glfbo = (GLFbo) gl;
|
|
glfbo = (GLFbo) gl;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (settings.getBoolean("GraphicsTiming")) {
|
|
if (settings.getBoolean("GraphicsTiming")) {
|
|
GLTimingState timingState = new GLTimingState();
|
|
GLTimingState timingState = new GLTimingState();
|
|
- gl = (GL) GLTiming.createGLTiming(gl, timingState, GL.class, GL2.class, GL3.class, GL4.class);
|
|
|
|
|
|
+ gl = (GL) GLTiming.createGLTiming(gl, timingState, GL.class, GL2.class, GL3.class, GL4.class);
|
|
glext = (GLExt) GLTiming.createGLTiming(glext, timingState, GLExt.class);
|
|
glext = (GLExt) GLTiming.createGLTiming(glext, timingState, GLExt.class);
|
|
glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class);
|
|
glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (settings.getBoolean("GraphicsTrace")) {
|
|
if (settings.getBoolean("GraphicsTrace")) {
|
|
- gl = (GL) GLTracer.createDesktopGlTracer(gl, GL.class, GL2.class, GL3.class, GL4.class);
|
|
|
|
|
|
+ gl = (GL) GLTracer.createDesktopGlTracer(gl, GL.class, GL2.class, GL3.class, GL4.class);
|
|
glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class);
|
|
glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class);
|
|
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
|
|
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
renderer = new GLRenderer(gl, glext, glfbo);
|
|
renderer = new GLRenderer(gl, glext, glfbo);
|
|
renderer.initialize();
|
|
renderer.initialize();
|
|
} else {
|
|
} else {
|
|
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
|
|
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (GLContext.getCapabilities().GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) {
|
|
if (GLContext.getCapabilities().GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) {
|
|
ARBDebugOutput.glDebugMessageCallbackARB(new ARBDebugOutputCallback(new LwjglGLDebugOutputHandler()));
|
|
ARBDebugOutput.glDebugMessageCallbackARB(new ARBDebugOutputCallback(new LwjglGLDebugOutputHandler()));
|
|
}
|
|
}
|
|
-
|
|
|
|
- renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
|
|
|
|
- renderer.setLinearizeSrgbImages(settings.getGammaCorrection());
|
|
|
|
|
|
+
|
|
|
|
+ renderer.setMainFrameBufferSrgb(settings.isGammaCorrection());
|
|
|
|
+ renderer.setLinearizeSrgbImages(settings.isGammaCorrection());
|
|
|
|
|
|
// Init input
|
|
// Init input
|
|
if (keyInput != null) {
|
|
if (keyInput != null) {
|
|
@@ -260,42 +267,42 @@ public abstract class LwjglContext implements JmeContext {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void internalDestroy(){
|
|
|
|
|
|
+ public void internalDestroy() {
|
|
renderer = null;
|
|
renderer = null;
|
|
timer = null;
|
|
timer = null;
|
|
renderable.set(false);
|
|
renderable.set(false);
|
|
- synchronized (createdLock){
|
|
|
|
|
|
+ synchronized (createdLock) {
|
|
created.set(false);
|
|
created.set(false);
|
|
createdLock.notifyAll();
|
|
createdLock.notifyAll();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void internalCreate(){
|
|
|
|
|
|
+
|
|
|
|
+ public void internalCreate() {
|
|
timer = new LwjglTimer();
|
|
timer = new LwjglTimer();
|
|
-
|
|
|
|
- synchronized (createdLock){
|
|
|
|
|
|
+
|
|
|
|
+ synchronized (createdLock) {
|
|
created.set(true);
|
|
created.set(true);
|
|
createdLock.notifyAll();
|
|
createdLock.notifyAll();
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (renderable.get()){
|
|
|
|
|
|
+
|
|
|
|
+ if (renderable.get()) {
|
|
initContextFirstTime();
|
|
initContextFirstTime();
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
assert getType() == Type.Canvas;
|
|
assert getType() == Type.Canvas;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void create(){
|
|
|
|
|
|
+ public void create() {
|
|
create(false);
|
|
create(false);
|
|
}
|
|
}
|
|
|
|
|
|
- public void destroy(){
|
|
|
|
|
|
+ public void destroy() {
|
|
destroy(false);
|
|
destroy(false);
|
|
}
|
|
}
|
|
|
|
|
|
- protected void waitFor(boolean createdVal){
|
|
|
|
- synchronized (createdLock){
|
|
|
|
- while (created.get() != createdVal){
|
|
|
|
|
|
+ protected void waitFor(boolean createdVal) {
|
|
|
|
+ synchronized (createdLock) {
|
|
|
|
+ while (created.get() != createdVal) {
|
|
try {
|
|
try {
|
|
createdLock.wait();
|
|
createdLock.wait();
|
|
} catch (InterruptedException ex) {
|
|
} catch (InterruptedException ex) {
|
|
@@ -304,11 +311,11 @@ public abstract class LwjglContext implements JmeContext {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean isCreated(){
|
|
|
|
|
|
+ public boolean isCreated() {
|
|
return created.get();
|
|
return created.get();
|
|
}
|
|
}
|
|
-
|
|
|
|
- public boolean isRenderable(){
|
|
|
|
|
|
+
|
|
|
|
+ public boolean isRenderable() {
|
|
return renderable.get();
|
|
return renderable.get();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -316,7 +323,7 @@ public abstract class LwjglContext implements JmeContext {
|
|
this.settings.copyFrom(settings);
|
|
this.settings.copyFrom(settings);
|
|
}
|
|
}
|
|
|
|
|
|
- public AppSettings getSettings(){
|
|
|
|
|
|
+ public AppSettings getSettings() {
|
|
return settings;
|
|
return settings;
|
|
}
|
|
}
|
|
|
|
|