renderstate.java
来自「java 3d game jme 工程开发源代码」· Java 代码 · 共 417 行 · 第 1/2 页
JAVA
417 行
/*
* 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.scene.state;
import java.io.IOException;
import java.util.Arrays;
import java.util.Stack;
import com.jme.scene.Spatial;
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;
/**
* <code>RenderState</code> is the base class for all states that affect the
* rendering of a piece of geometry. They aren't created directly, but are
* created for users from the renderer. The renderstate of a parent affects its
* children and it is OK to assign to more than one Spatial the same render
* state.
*
* @author Mark Powell
* @author Joshua Slack
* @author Jack Lindamood (javadoc only)
* @version $Id: RenderState.java,v 1.31 2006/11/19 00:41:36 renanse Exp $
*/
public abstract class RenderState implements Savable {
/**
* Enumerates every possible {@link RenderState} type.
*
* @note The order of this enumeration matters as long as the deprecated
* integer render state types still exist, because the ordinal should map
* to the old values. When the deprecated integer types are removed, then
* we can re-order this enum.
*
* @author Carter
*/
public static enum StateType {
/** The value returned by getType() for BlendState. */
Blend(true),
/** The value returned by getType() for FogState. */
Fog(false),
/** The value returned by getType() for LightState. */
Light(false),
/** The value returend by getType() for MaterialState. */
Material(false),
/** The value returned by getType() for ShadeState. */
Shade(true),
/** The value returned by getType() for TextureState. */
Texture(false),
/** The value returned by getType() for WireframeState. */
Wireframe(false),
/** The value returned by getType() for ZBufferState. */
ZBuffer(true),
/** The value returned by getType() for CullState. */
Cull(true),
/** The value returned by getType() for VertexProgramState. */
VertexProgram(true),
/** The value returned by getType() for FragmentProgramState. */
FragmentProgram(true),
/** The value returned by getType() for StencilState. */
Stencil(true),
/** The value returned by getType() for GLSLShaderObjectsState. */
GLSLShaderObjects(true),
/** The value returned by getType() for ColorMaskState. */
ColorMask(true),
/** The value returned by getType() for ClipState. */
Clip(true);
/**
* <p>
* If false, each renderstate of that type is always applied in the renderer
* and only field by field checks are done to minimize jni overhead. This is
* slower than setting to true, but relieves the programmer from situations
* where he has to remember to update the needsRefresh field of a state.
* </p>
* <p>
* If true, each renderstate of that type is checked for == with the last
* applied renderstate of the same type. If same and the state's
* needsRefresh method returns false, then application of the renderstate is
* skipped. This can be much faster than setting false, but in certain
* circumstances, the programmer must manually set needsRefresh (for
* example, in a FogState, if you call getFogColor().set(....) to change the
* color, the fogstate will not set the needsRefresh field. In non-quick
* compare mode, this is not a problem because it will go into the apply
* method and do an actual check of the current fog color in opengl vs. the
* color in the state being applied.)
* </p>
* <p>
* DEFAULTS:
* <ul>
* <li>Blend: true</li>
* <li>Clip: true</li>
* <li>ColorMask: true</li>
* <li>Cull: true</li>
* <li>Fog: false</li>
* <li>FragmentProgram: true</li>
* <li>GLSLShaderObjects: true</li>
* <li>Light: false</li>
* <li>Material: false</li>
* <li>Shade: true</li>
* <li>Stencil: true</li>
* <li>Texture: false</li>
* <li>VertexProgram: true</li>
* <li>Wireframe: false</li>
* <li>ZBuffer: true</li>\
* </ul>
*/
private boolean quickCompare = false;
private StateType(boolean quickCompare) {
this.quickCompare = quickCompare;
}
public boolean canQuickCompare() {
return quickCompare;
}
}
/** The value returned by getType() for BlendState.
* @deprecated As of 2.0, use {@link RenderState.StateType#Blend} */
public static final int RS_BLEND = 0;
/** The value returned by getType() for FogState.
* @deprecated As of 2.0, use {@link RenderState.StateType#fog} */
public static final int RS_FOG = 1;
/** The value returned by getType() for LightState.
* @deprecated As of 2.0, use {@link RenderState.StateType#Light} */
public static final int RS_LIGHT = 2;
/** The value returend by getType() for MaterialState.
* @deprecated As of 2.0, use {@link RenderState.StateType#Material} */
public static final int RS_MATERIAL = 3;
/** The value returned by getType() for ShadeState.
* @deprecated As of 2.0, use {@link RenderState.StateType#Shade} */
public static final int RS_SHADE = 4;
/** The value returned by getType() for TextureState.
* @deprecated As of 2.0, use {@link RenderState.StateType#Texture} */
public static final int RS_TEXTURE = 5;
/** The value returned by getType() for WireframeState.
* @deprecated As of 2.0, use {@link RenderState.StateType#Wireframe} */
public static final int RS_WIREFRAME = 6;
/** The value returned by getType() for ZBufferState.
* @deprecated As of 2.0, use {@link RenderState.StateType#ZBuffer} */
public static final int RS_ZBUFFER = 7;
/** The value returned by getType() for CullState.
* @deprecated As of 2.0, use {@link RenderState.StateType#Cull} */
public static final int RS_CULL = 8;
/** The value returned by getType() for VertexProgramState.
* @deprecated As of 2.0, use {@link RenderState.StateType#VertexProgram} */
public static final int RS_VERTEX_PROGRAM = 9;
/** The value returned by getType() for FragmentProgramState.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?