|
| 1 | +/* |
| 2 | + * Copyright (c) 2009-2023 jMonkeyEngine |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are |
| 7 | + * met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * |
| 12 | + * * Redistributions in binary form must reproduce the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer in the |
| 14 | + * documentation and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
| 17 | + * may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 22 | + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | + */ |
| 32 | +package jme3test.renderer; |
| 33 | + |
| 34 | +import com.jme3.app.SimpleApplication; |
| 35 | +import com.jme3.input.KeyInput; |
| 36 | +import com.jme3.input.controls.ActionListener; |
| 37 | +import com.jme3.input.controls.KeyTrigger; |
| 38 | +import com.jme3.system.AppSettings; |
| 39 | + |
| 40 | +/** |
| 41 | + * Test for JMonkeyEngine issue #2011: context profiles are not defined for |
| 42 | + * OpenGL v3.0/v3.1 |
| 43 | + * <p> |
| 44 | + * If the issue is resolved, then pressing the "0" or "1" key shouldn't crash |
| 45 | + * the app; it should close the app display and create a new display, mostly |
| 46 | + * black with statistics displayed in the lower left. |
| 47 | + * <p> |
| 48 | + * If the issue is not resolved, then pressing the "0" or "1" key should crash |
| 49 | + * the app with multiple exceptions. |
| 50 | + * <p> |
| 51 | + * Since the issue was specific to LWJGL v3, this test should be built with the |
| 52 | + * jme3-lwjgl3 library, not jme3-lwjgl. |
| 53 | + * |
| 54 | + * @author Stephen Gold |
| 55 | + */ |
| 56 | +public class TestIssue2011 extends SimpleApplication { |
| 57 | + /** |
| 58 | + * Main entry point for the TestIssue2011 application. |
| 59 | + * |
| 60 | + * @param args array of command-line arguments (not null) |
| 61 | + */ |
| 62 | + public static void main(String[] args) { |
| 63 | + TestIssue2011 app = new TestIssue2011(); |
| 64 | + app.start(); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Initialize this application. |
| 69 | + */ |
| 70 | + @Override |
| 71 | + public void simpleInitApp() { |
| 72 | + inputManager.addMapping("3.0", new KeyTrigger(KeyInput.KEY_0), |
| 73 | + new KeyTrigger(KeyInput.KEY_NUMPAD0)); |
| 74 | + inputManager.addMapping("3.1", new KeyTrigger(KeyInput.KEY_1), |
| 75 | + new KeyTrigger(KeyInput.KEY_NUMPAD1)); |
| 76 | + inputManager.addMapping("3.2", new KeyTrigger(KeyInput.KEY_2), |
| 77 | + new KeyTrigger(KeyInput.KEY_NUMPAD2)); |
| 78 | + |
| 79 | + ActionListener listener = new ActionListener() { |
| 80 | + @Override |
| 81 | + public void onAction(String name, boolean keyPressed, float tpf) { |
| 82 | + if (name.equals("3.0") && keyPressed) { |
| 83 | + setApi(AppSettings.LWJGL_OPENGL30); |
| 84 | + } else if (name.equals("3.1") && keyPressed) { |
| 85 | + setApi(AppSettings.LWJGL_OPENGL31); |
| 86 | + } else if (name.equals("3.2") && keyPressed) { |
| 87 | + setApi(AppSettings.LWJGL_OPENGL32); |
| 88 | + } |
| 89 | + } |
| 90 | + }; |
| 91 | + |
| 92 | + inputManager.addListener(listener, "3.0", "3.1", "3.2"); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Restart the app, specifying which OpenGL version to use. |
| 97 | + * |
| 98 | + * @param desiredApi the string to be passed to setRenderer() |
| 99 | + */ |
| 100 | + private void setApi(String desiredApi) { |
| 101 | + System.out.println("desiredApi = " + desiredApi); |
| 102 | + settings.setRenderer(desiredApi); |
| 103 | + setSettings(settings); |
| 104 | + |
| 105 | + restart(); |
| 106 | + } |
| 107 | +} |
0 commit comments