159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met: 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer. 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer in the 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * documentation and/or other materials provided with the distribution. 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * may be used to endorse or promote products derived from this software 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * without specific prior written permission. 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage com.jme3.system; 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.JoyInput; 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.KeyInput; 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.MouseInput; 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.TouchInput; 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.renderer.Renderer; 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Represents a rendering context within the engine. 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic interface JmeContext { 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * The type of context. 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public enum Type { 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * A display can represent a windowed or a fullscreen-exclusive display. 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * If windowed, the graphics are rendered to a new on-screen surface 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * enclosed in a window defined by the operating system. Implementations 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * are encouraged to not use AWT or Swing to create the OpenGL display 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * but rather use native operating system functions to set up a native 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * display with the windowing system. 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Display, 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * A canvas type context makes a rendering surface available as an 6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * AWT {@link java.awt.Canvas} object that can be embedded in a Swing/AWT 6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * frame. To retrieve the Canvas object, you should cast the context 6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * to {@link JmeCanvasContext}. 6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Canvas, 6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * An <code>OffscreenSurface</code> is a context that is not visible 7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * by the user. The application can use the offscreen surface to do 7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * General Purpose GPU computations or render a scene into a buffer 7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * in order to save it as a screenshot, video or send through a network. 7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta OffscreenSurface, 7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * A <code>Headless</code> context is not visible and does not have 7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * any drawable surface. The implementation does not provide any 7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * display, input, or sound support. 8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Headless; 8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return The type of the context. 8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Type getType(); 8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param settings the display settings to use for the created context. If 9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * the context has already been created, then <code>restart()</code> must be called 9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * for the changes to be applied. 9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setSettings(AppSettings settings); 9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Sets the listener that will receive events relating to context 9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * creation, update, and destroy. 9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setSystemListener(SystemListener listener); 10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return The current display settings. Note that they might be 10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * different from the ones set with setDisplaySettings() if the context 10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * was restarted or the settings changed internally. 10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public AppSettings getSettings(); 10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return The renderer for this context, or null if not created yet. 11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Renderer getRenderer(); 11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return Mouse input implementation. May be null if not available. 11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public MouseInput getMouseInput(); 11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return Keyboard input implementation. May be null if not available. 12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public KeyInput getKeyInput(); 12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return Joystick input implementation. May be null if not available. 12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public JoyInput getJoyInput(); 12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return Touch device input implementation. May be null if not available. 13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public TouchInput getTouchInput(); 13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return The timer for this context, or null if not created yet. 13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Timer getTimer(); 13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Sets the title of the display (if available). This does nothing 14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * for fullscreen, headless, or canvas contexts. 14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param title The new title of the display. 14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setTitle(String title); 14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return True if the context has been created but not yet destroyed. 14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public boolean isCreated(); 15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return True if the context contains a valid render surface, 15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * if any of the rendering methods in {@link Renderer} are called 15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * while this is <code>false</code>, then the result is undefined. 15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public boolean isRenderable(); 15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param enabled If enabled, the context will automatically flush 16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * frames to the video card (swap buffers) after an update cycle. 16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setAutoFlushFrames(boolean enabled); 16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Creates the context and makes it active. 16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param waitFor If true, will wait until context has initialized. 16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void create(boolean waitFor); 17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Destroys and then re-creates the context. This should be called after 17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * the display settings have been changed. 17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void restart(); 17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Destroys the context completely, making it inactive. 17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param waitFor If true, will wait until the context is destroyed fully. 18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void destroy(boolean waitFor); 18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 185