📄 renderer.java
字号:
/*
* Copyright (c) 2003-2009 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 com.jme.renderer;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import com.jme.curve.Curve;
import com.jme.image.Image;
import com.jme.image.Texture;
import com.jme.scene.Geometry;
import com.jme.scene.Line;
import com.jme.scene.Point;
import com.jme.scene.QuadMesh;
import com.jme.scene.Spatial;
import com.jme.scene.Text;
import com.jme.scene.TriMesh;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.ClipState;
import com.jme.scene.state.ColorMaskState;
import com.jme.scene.state.CullState;
import com.jme.scene.state.FogState;
import com.jme.scene.state.FragmentProgramState;
import com.jme.scene.state.GLSLShaderObjectsState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.ShadeState;
import com.jme.scene.state.StateRecord;
import com.jme.scene.state.StencilState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.VertexProgramState;
import com.jme.scene.state.WireframeState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.JmeException;
/**
* <code>Renderer</code> defines an abstract class that handles displaying of
* graphics data to the context. Creation of this object is typically handled
* via a call to a <code>DisplaySystem</code> subclass.
*
* All rendering state and tasks can be handled through this class.
*
* Example Usage: <br>
* NOTE: This example uses the <code>DisplaySystem</code> class to obtain the
* <code>Renderer</code>.
*
* <code>
* DisplaySystem ds = new LWJGLDisplaySystem();<br>
* ds.createWindow(640,480,16,60,false);<br>
* Renderer r = ds.getRenderer();<br>
* r.draw(point);<br>
* </code>
*
* @see com.jme.system.DisplaySystem
* @author Mark Powell
* @author Tijl Houtbeckers (added VBO delete methods)
* @version $Id: Renderer.java,v 1.72 2007/09/14 20:53:52 nca Exp $
*/
public abstract class Renderer {
/** The Spatial will inherit its render queue state from its parent. */
public static final int QUEUE_INHERIT = 0;
/** The Spatial will skip render queueing. */
public static final int QUEUE_SKIP = 1;
/** The Spatial will render in the opaque bucket. */
public static final int QUEUE_OPAQUE = 2;
/** The Spatial will render in the transparent bucket. */
public static final int QUEUE_TRANSPARENT = 3;
/** The Spatial will render in the ortho bucket. */
public static final int QUEUE_ORTHO = 4;
protected AbstractCamera camera;
// clear color
protected ColorRGBA backgroundColor;
protected boolean processingQueue;
protected RenderQueue queue;
private boolean headless = false;
// width and height of renderer
protected int width;
protected int height;
/** List of default states all spatials take if none is set. */
public static final RenderState[] defaultStateList = new RenderState[RenderState.StateType.values().length];
/**
* <code>setCamera</code> sets the reference to the applications camera
* object.
*
* @param camera
* the camera object to use with this <code>Renderer</code>.
*/
public abstract void setCamera(Camera camera);
/**
* <code>getCamera</code> returns the camera used by this renderer.
*
* @see com.jme.renderer.Renderer#getCamera()
*/
public Camera getCamera() {
return camera;
}
/**
*
* <code>createCamera</code> retrieves a default camera for this renderer.
*
* @param width
* the width of the frame.
* @param height
* the height of the frame.
* @return a default camera for this renderer.
*/
public abstract Camera createCamera(int width, int height);
/**
*
* <code>createBlendState</code> retrieves the blend state object for the
* proper renderer.
*
* @return the <code>BlendState</code> object that can make use of the
* proper renderer.
*/
public abstract BlendState createBlendState();
/**
*
* <code>createCullState</code> retrieves the cull state object for the
* proper renderer.
*
* @return the <code>CullState</code> object that can make use of the
* proper renderer.
*/
public abstract CullState createCullState();
/**
*
* <code>createFogState</code> retrieves the fog state object for the
* proper renderer.
*
* @return the <code>FogState</code> object that can make use of the
* proper renderer.
*/
public abstract FogState createFogState();
/**
*
* <code>createLightState</code> retrieves the light state object for the
* proper renderer.
*
* @return the <code>LightState</code> object that can make use of the
* proper renderer.
*/
public abstract LightState createLightState();
/**
*
* <code>createMaterialState</code> retrieves the material state object
* for the proper renderer.
*
* @return the <code>MaterialState</code> object that can make use of the
* proper renderer.
*/
public abstract MaterialState createMaterialState();
/**
*
* <code>createShadeState</code> retrieves the shade state object for the
* proper renderer.
*
* @return the <code>ShadeState</code> object that can make use of the
* proper renderer.
*/
public abstract ShadeState createShadeState();
/**
*
* <code>createTextureState</code> retrieves the texture state object for
* the proper renderer.
*
* @return the <code>TextureState</code> object that can make use of the
* proper renderer.
*/
public abstract TextureState createTextureState();
/**
*
* <code>createWireframeState</code> retrieves the wireframe state object
* for the proper renderer.
*
* @return the <code>WireframeState</code> object that can make use of the
* proper renderer.
*/
public abstract WireframeState createWireframeState();
/**
* Retrieves the Z buffer state object for the proper renderer.
*
* @return The <code>ZBufferState</code> object that can make use of the
* proper renderer.
*/
public abstract ZBufferState createZBufferState();
/**
* Retrieves the vertex program state object for the proper renderer.
*
* @return The <code>VertexProgramState</code> object that can make use of
* the proper renderer.
*/
public abstract VertexProgramState createVertexProgramState();
/**
* Retrieves the fragment program state object for the proper renderer.
*
* @return The <code>VertexProgramState</code> object that can make use of
* the proper renderer.
*/
public abstract FragmentProgramState createFragmentProgramState();
/**
* <code>createShaderObjectsState</code> retrieves the shader object state
* object for the proper renderer.
*
* @return the <code>ShaderObjectsState</code> object that can make use of
* the proper renderer.
*/
public abstract GLSLShaderObjectsState createGLSLShaderObjectsState();
/**
* Retrieves the stencil state object for the proper renderer.
*
* @return The <code>StencilState</code> object that can make use of the
* proper renderer.
*/
public abstract StencilState createStencilState();
/**
* Retrieves the clip state object for the proper renderer.
*
* @return The <code>ClipState</code> object that can make use of the
* proper renderer.
*/
public abstract ClipState createClipState();
/**
* Retrieves the color mask state object for the proper renderer.
*
* @return The <code>ColorMaskState</code> object that can make use of the
* proper renderer.
*/
public abstract ColorMaskState createColorMaskState();
/**
* <code>setBackgroundColor</code> sets the color of window. This color
* will be shown for any pixel that is not set via typical rendering
* operations.
*
* @param c
* the color to set the background to.
*/
public abstract void setBackgroundColor(ColorRGBA c);
/**
* <code>getBackgroundColor</code> retrieves the clear color of the
* current OpenGL context.
*
* @see com.jme.renderer.Renderer#getBackgroundColor()
* @return the current clear color.
*/
public ColorRGBA getBackgroundColor() {
return backgroundColor;
}
/**
* <code>clearZBuffer</code> clears the depth buffer of the renderer. The
* Z buffer allows sorting of pixels by depth or distance from the view
* port. Clearing this buffer prepares it for the next frame.
*
*/
public abstract void clearZBuffer();
/**
* <code>clearBackBuffer</code> clears the back buffer of the renderer.
* The backbuffer is the buffer being rendered to before it is displayed to
* the screen. Clearing this buffer frees it for rendering the next frame.
*
*/
public abstract void clearColorBuffer();
/**
* <code>clearStencilBuffer</code> clears the stencil buffer of the renderer.
*/
public abstract void clearStencilBuffer();
/**
* <code>clearBuffers</code> clears both the depth buffer and the back
* buffer.
*
*/
public abstract void clearBuffers();
/**
* <code>clearBuffers</code> clears both the depth buffer and the back
* buffer restricting the clear to the rectangle defined by the width and
* height of the renderer.
*
*/
public abstract void clearStrictBuffers();
/**
* <code>displayBackBuffer</code> swaps the back buffer with the currently
* displayed buffer. Swapping (page flipping) allows the renderer to display
* a prerenderer display without any flickering.
*
*/
public abstract void displayBackBuffer();
/**
*
* <code>setOrtho</code> sets the display system to be in orthographic
* mode. If the system has already been set to orthographic mode a
* <code>JmeException</code> is thrown. The origin (0,0) is the bottom
* left of the screen.
*
*/
public abstract void setOrtho();
/**
* @return true if the renderer is currently in ortho mode.
*/
public abstract boolean isInOrthoMode();
/**
* render queue if needed
*/
public void renderQueue() {
processingQueue = true;
queue.renderBuckets();
processingQueue = false;
}
/**
* clear the render queue
*/
public void clearQueue() {
queue.clearBuckets();
}
/**
*
* <code>setOrthoCenter</code> sets the display system to be in
* orthographic mode. If the system has already been set to orthographic
* mode a <code>JmeException</code> is thrown. The origin (0,0) is the
* center of the screen.
*
*
*/
public abstract void setOrthoCenter();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -