|
|
|
@ -29,7 +29,6 @@ |
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
package com.jme3.system.lwjgl; |
|
|
|
|
|
|
|
|
|
import com.jme3.input.lwjgl.JInputJoyInput; |
|
|
|
@ -69,7 +68,7 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
private static final Logger logger = Logger.getLogger(LwjglContext.class.getName()); |
|
|
|
|
|
|
|
|
|
protected static final String THREAD_NAME = "jME3 Main"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected AtomicBoolean created = new AtomicBoolean(false); |
|
|
|
|
protected AtomicBoolean renderable = new AtomicBoolean(false); |
|
|
|
|
protected final Object createdLock = new Object(); |
|
|
|
@ -82,18 +81,18 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
protected Timer timer; |
|
|
|
|
protected SystemListener listener; |
|
|
|
|
|
|
|
|
|
public void setSystemListener(SystemListener listener){ |
|
|
|
|
public void setSystemListener(SystemListener listener) { |
|
|
|
|
this.listener = listener; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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() { |
|
|
|
@ -113,7 +112,7 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int determineMaxSamples(int requestedSamples) { |
|
|
|
|
try { |
|
|
|
|
// If we already have a valid context, determine samples using current
|
|
|
|
@ -131,13 +130,13 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
} catch (LWJGLException ex) { |
|
|
|
|
listener.handleError("Failed to check if display is current", ex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
@ -155,13 +154,14 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
} catch (LWJGLException ex) { |
|
|
|
|
// Something else failed.
|
|
|
|
|
return Integer.MAX_VALUE; |
|
|
|
|
} finally { |
|
|
|
|
} finally { |
|
|
|
|
if (pb != null) { |
|
|
|
|
pb.destroy(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void loadNatives() { |
|
|
|
|
if (JmeSystem.isLowPermissions()) { |
|
|
|
|
return; |
|
|
|
@ -178,10 +178,10 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
} |
|
|
|
|
NativeLibraryLoader.loadNativeLibrary("lwjgl", true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int getNumSamplesToUse() { |
|
|
|
|
int samples = 0; |
|
|
|
|
if (settings.getSamples() > 1){ |
|
|
|
|
if (settings.getSamples() > 1) { |
|
|
|
|
samples = settings.getSamples(); |
|
|
|
|
int supportedSamples = determineMaxSamples(samples); |
|
|
|
|
if (supportedSamples < samples) { |
|
|
|
@ -189,60 +189,60 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
"Couldn''t satisfy antialiasing samples requirement: x{0}. " |
|
|
|
|
+ "Video hardware only supports: x{1}", |
|
|
|
|
new Object[]{samples, supportedSamples}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
samples = supportedSamples; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return samples; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initContextFirstTime(){ |
|
|
|
|
protected void initContextFirstTime() { |
|
|
|
|
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) |
|
|
|
|
|| settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) { |
|
|
|
|
|| settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) { |
|
|
|
|
GL gl = new LwjglGL(); |
|
|
|
|
GLExt glext = new LwjglGLExt(); |
|
|
|
|
GLFbo glfbo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GLContext.getCapabilities().OpenGL30) { |
|
|
|
|
glfbo = new LwjglGLFboGL3(); |
|
|
|
|
} else { |
|
|
|
|
glfbo = new LwjglGLFboEXT(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.getBoolean("GraphicsDebug")) { |
|
|
|
|
gl = new GLDebugDesktop(gl, glext, glfbo); |
|
|
|
|
gl = new GLDebugDesktop(gl, glext, glfbo); |
|
|
|
|
glext = (GLExt) gl; |
|
|
|
|
glfbo = (GLFbo) gl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.getBoolean("GraphicsTiming")) { |
|
|
|
|
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); |
|
|
|
|
glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderer = new GLRenderer(gl, glext, glfbo); |
|
|
|
|
renderer.initialize(); |
|
|
|
|
} else { |
|
|
|
|
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GLContext.getCapabilities().GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) { |
|
|
|
|
ARBDebugOutput.glDebugMessageCallbackARB(new ARBDebugOutputCallback(new LwjglGLDebugOutputHandler())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderer.setMainFrameBufferSrgb(settings.getGammaCorrection()); |
|
|
|
|
renderer.setLinearizeSrgbImages(settings.getGammaCorrection()); |
|
|
|
|
|
|
|
|
@ -260,42 +260,42 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void internalDestroy(){ |
|
|
|
|
public void internalDestroy() { |
|
|
|
|
renderer = null; |
|
|
|
|
timer = null; |
|
|
|
|
renderable.set(false); |
|
|
|
|
synchronized (createdLock){ |
|
|
|
|
synchronized (createdLock) { |
|
|
|
|
created.set(false); |
|
|
|
|
createdLock.notifyAll(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void internalCreate(){ |
|
|
|
|
|
|
|
|
|
public void internalCreate() { |
|
|
|
|
timer = new LwjglTimer(); |
|
|
|
|
|
|
|
|
|
synchronized (createdLock){ |
|
|
|
|
|
|
|
|
|
synchronized (createdLock) { |
|
|
|
|
created.set(true); |
|
|
|
|
createdLock.notifyAll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (renderable.get()){ |
|
|
|
|
|
|
|
|
|
if (renderable.get()) { |
|
|
|
|
initContextFirstTime(); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
assert getType() == Type.Canvas; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void create(){ |
|
|
|
|
public void create() { |
|
|
|
|
create(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void destroy(){ |
|
|
|
|
public void destroy() { |
|
|
|
|
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 { |
|
|
|
|
createdLock.wait(); |
|
|
|
|
} catch (InterruptedException ex) { |
|
|
|
@ -304,11 +304,11 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isCreated(){ |
|
|
|
|
public boolean isCreated() { |
|
|
|
|
return created.get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isRenderable(){ |
|
|
|
|
|
|
|
|
|
public boolean isRenderable() { |
|
|
|
|
return renderable.get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -316,7 +316,7 @@ public abstract class LwjglContext implements JmeContext { |
|
|
|
|
this.settings.copyFrom(settings); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public AppSettings getSettings(){ |
|
|
|
|
public AppSettings getSettings() { |
|
|
|
|
return settings; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|