-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactors the context restart code. #1526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91cf45a
Refactors the context restart code.
Markil3 d3ca417
Fixed a misleading comment in lwjgl3's LwjglWindow
Markil3 45f8f95
Adds documentation to the LwjglContext methods.
Markil3 a7d3625
Merge commit '45f8f95fe13ecf8ebc2818e2e72a767193ed3925' into contextR…
Markil3 041ec54
Cleans up the code and comments.
Markil3 c8062e3
Moves the renderer initialization for jme3-lwjgl to just the first run.
Markil3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
jme3-examples/src/main/java/jme3test/renderer/TestContextRestart.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /* | ||
| * 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 whether gamma correction works after a context restart. This test | ||
| * generates a series of boxes, each one with a slightly different shade from | ||
| * the other. If the boxes look the same before and after the restart, that | ||
| * means that gamma correction is working properly. | ||
| * <p> | ||
| * Note that for testing, it may be helpful to bypass the test chooser and run | ||
| * this class directly, since it can be easier to define your own settings | ||
| * beforehand. Of course, it should still workif all you need to test is the | ||
| * gamma correction, as long as you enable it in the settings dialog. | ||
| * </p> | ||
| * | ||
| * @author Markil 3 | ||
| */ | ||
| public class TestContextRestart extends SimpleApplication | ||
| { | ||
| public static final String INPUT_RESTART_CONTEXT = "SIMPLEAPP_Restart"; | ||
|
|
||
| public static void main(String[] args) | ||
| { | ||
| TestContextRestart app = new TestContextRestart(); | ||
| AppSettings settings = new AppSettings(true); | ||
| settings.setGammaCorrection(true); | ||
| // 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); | ||
|
|
||
| inputManager.addMapping(INPUT_RESTART_CONTEXT, new KeyTrigger( | ||
| KeyInput.KEY_TAB)); | ||
| this.inputManager.addListener(new ActionListener() | ||
| { | ||
| @Override | ||
| public void onAction(String name, boolean isPressed, float tpf) | ||
| { | ||
| if (name.equals(INPUT_RESTART_CONTEXT)) | ||
| { | ||
| restart(); | ||
| } | ||
| } | ||
| }, INPUT_RESTART_CONTEXT); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,42 +251,65 @@ protected int getNumSamplesToUse() { | |
| return samples; | ||
| } | ||
|
|
||
| /** | ||
| * Reinitializes the relevent details of the context. For internal use only. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.initialize(); | ||
| } | ||
| renderer = new GLRenderer(gl, glext, glfbo); | ||
| renderer.initialize(); | ||
| } else { | ||
| throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer()); | ||
| } | ||
|
|
@@ -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") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.