Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions jme3-core/src/main/java/com/jme3/app/SimpleApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public abstract class SimpleApplication extends LegacyApplication {
public static final String INPUT_MAPPING_CAMERA_POS = DebugKeysAppState.INPUT_MAPPING_CAMERA_POS;
public static final String INPUT_MAPPING_MEMORY = DebugKeysAppState.INPUT_MAPPING_MEMORY;
public static final String INPUT_MAPPING_HIDE_STATS = "SIMPLEAPP_HideStats";
public static final String INPUT_RESTART_CONTEXT = "SIMPLEAPP_Restart";

protected Node rootNode = new Node("Root Node");
protected Node guiNode = new Node("Gui Node");
Expand All @@ -92,6 +93,8 @@ public void onAction(String name, boolean value, float tpf) {
if (stateManager.getState(StatsAppState.class) != null) {
stateManager.getState(StatsAppState.class).toggleStats();
}
}else if (name.equals(INPUT_RESTART_CONTEXT)){
restart();
}
}
}
Expand Down Expand Up @@ -219,6 +222,7 @@ public void initialize() {

if (context.getType() == Type.Display) {
inputManager.addMapping(INPUT_MAPPING_EXIT, new KeyTrigger(KeyInput.KEY_ESCAPE));
inputManager.addMapping(INPUT_RESTART_CONTEXT, new KeyTrigger(KeyInput.KEY_TAB));
}

if (stateManager.getState(StatsAppState.class) != null) {
Expand All @@ -227,6 +231,7 @@ public void initialize() {
}

inputManager.addListener(actionListener, INPUT_MAPPING_EXIT);
inputManager.addListener(actionListener, INPUT_RESTART_CONTEXT);
}

if (stateManager.getState(StatsAppState.class) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2009-2021 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package jme3test.renderer;

import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;

/**
* Tests how gamma correction works after a context restart.
*
* @author Markil 3
*/
public class TestContextRestart extends SimpleApplication {
public static void main(String[] args) {
TestContextRestart app = new TestContextRestart();
AppSettings settings = new AppSettings(true);
settings.setGammaCorrection(true);
// Still need to see why setting this to anything higher than OPENGL2 causes the screen to blank in redisplay.
settings.setRenderer(AppSettings.LWJGL_OPENGL32);
app.setSettings(settings);
app.start();
}

@Override
public void simpleInitApp() {
for (int i = 0, l = 256; i < l; i += 8) {
Geometry box = new Geometry("Box" + i, new Box(10, 200, 10));
Material mat = new Material(this.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", new ColorRGBA((float) i / 255F, 0, 0, 1));
box.setMaterial(mat);
box.setLocalTranslation(-2.5F * (l / 2 - i), 0, -700);
box.addControl(new AbstractControl() {
@Override
protected void controlUpdate(float tpf) {
float[] angles = this.getSpatial().getLocalRotation().toAngles(new float[3]);
angles[0] = angles[0] + (FastMath.PI / 500F);
this.getSpatial().setLocalRotation(new Quaternion().fromAngles(angles));
}

@Override
protected void controlRender(RenderManager rm, ViewPort vp) {

}
});
this.rootNode.attachChild(box);
}

this.viewPort.setBackgroundColor(ColorRGBA.Yellow);

this.flyCam.setEnabled(false);
this.inputManager.setCursorVisible(true);
}
}
98 changes: 61 additions & 37 deletions jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,41 +251,64 @@ protected int getNumSamplesToUse() {
return samples;
}

/**
* Reinitializes the relevent details of the context. For internal use only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct the spelling of "relevant". "Relevent" is not a word in English.

*/
protected void reinitContext() {
initContext(false);
}

/**
* Initializes the LWJGL renderer and input for the first time. For internal
* use only.
*/
protected void initContextFirstTime() {
initContext(true);
}

/**
* Initializes the LWJGL renderer and input.
* @param first - Whether this is the first time we are initializing and we
* need to create the renderer or not. Otherwise, we'll just reset the
* renderer as needed.
*/
private void initContext(boolean first) {
if (!GLContext.getCapabilities().OpenGL20) {
throw new RendererException("OpenGL 2.0 or higher is "
+ "required for jMonkeyEngine");
}

int vers[] = getGLVersion(settings.getRenderer());
if (vers != null) {
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 = (GL) GLDebug.createProxy(gl, gl, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLDebug.createProxy(gl, glext, GLExt.class);
glfbo = (GLFbo) GLDebug.createProxy(gl, glfbo, GLFbo.class);
}
if (settings.getBoolean("GraphicsTiming")) {
GLTimingState timingState = new GLTimingState();
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);
glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class);
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
if (first) {
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 = (GL) GLDebug.createProxy(gl, gl, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLDebug.createProxy(gl, glext, GLExt.class);
glfbo = (GLFbo) GLDebug.createProxy(gl, glfbo, GLFbo.class);
}
if (settings.getBoolean("GraphicsTiming")) {
GLTimingState timingState = new GLTimingState();
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);
glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class);
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
}
renderer = new GLRenderer(gl, glext, glfbo);
}
renderer = new GLRenderer(gl, glext, glfbo);
renderer.initialize();
} else {
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
Expand All @@ -296,19 +319,20 @@ protected void initContextFirstTime() {
renderer.setMainFrameBufferSrgb(settings.isGammaCorrection());
renderer.setLinearizeSrgbImages(settings.isGammaCorrection());

// Init input
if (keyInput != null) {
keyInput.initialize();
}
if (first) {
// Init input
if (keyInput != null) {
keyInput.initialize();
}

if (mouseInput != null) {
mouseInput.initialize();
}
if (mouseInput != null) {
mouseInput.initialize();
}

if (joyInput != null) {
joyInput.initialize();
if (joyInput != null) {
joyInput.initialize();
}
}

}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public void runLoop(){
logger.log(Level.SEVERE, "Failed to set display settings!", ex);
}
listener.reshape(settings.getWidth(), settings.getHeight());
if (renderable.get()) {
reinitContext();
} else {
assert getType() == Type.Canvas;
}
logger.fine("Display restarted.");
} else if (Display.wasResized()) {
int newWidth = Display.getWidth();
Expand Down
Loading