blendstate.java
来自「java 3d game jme 工程开发源代码」· Java 代码 · 共 702 行 · 第 1/2 页
JAVA
702 行
/*
* 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 com.jme.renderer.ColorRGBA;
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
/**
* <code>BlendState</code> maintains the state of the blending values of a
* particular node and its children. The blend state provides a method for
* blending a source pixel with a destination pixel. The blend value provides a
* transparent or translucent surfaces. For example, this would allow for the
* rendering of green glass. Where you could see all objects behind this green
* glass but they would be tinted green.
*
* @author Mark Powell
* @author Joshua Slack
* @version $Id: BlendState.java,v 1.9 2007/08/02 22:05:39 nca Exp $
*/
public abstract class BlendState extends RenderState {
public enum SourceFunction {
/**
* The source value of the blend function is all zeros.
*/
Zero(false),
/**
* The source value of the blend function is all ones.
*/
One(false),
/**
* The source value of the blend function is the destination color.
*/
DestinationColor(false),
/**
* The source value of the blend function is 1 - the destination color.
*/
OneMinusDestinationColor(false),
/**
* The source value of the blend function is the source alpha value.
*/
SourceAlpha(false),
/**
* The source value of the blend function is 1 - the source alpha value.
*/
OneMinusSourceAlpha(false),
/**
* The source value of the blend function is the destination alpha.
*/
DestinationAlpha(false),
/**
* The source value of the blend function is 1 - the destination alpha.
*/
OneMinusDestinationAlpha(false),
/**
* The source value of the blend function is the minimum of alpha or 1 -
* alpha.
*/
SourceAlphaSaturate(false),
/**
* The source value of the blend function is the value of the constant
* color. (Rc, Gc, Bc, Ac) If not set, black with alpha = 0 is used. If
* not supported, falls back to One.
*/
ConstantColor(true),
/**
* The source value of the blend function is 1 minus the value of the
* constant color. (1-Rc, 1-Gc, 1-Bc, 1-Ac) If color is not set, black
* with alpha = 0 is used. If not supported, falls back to One.
*/
OneMinusConstantColor(true),
/**
* The source value of the blend function is the value of the constant
* color's alpha. (Ac, Ac, Ac, Ac) If not set, black with alpha = 0 is
* used. If not supported, falls back to One.
*/
ConstantAlpha(true),
/**
* The source value of the blend function is 1 minus the value of the
* constant color's alpha. (1-Ac, 1-Ac, 1-Ac, 1-Ac) If color is not set,
* black with alpha = 0 is used. If not supported, falls back to One.
*/
OneMinusConstantAlpha(true);
private boolean usesConstantColor;
private SourceFunction(boolean usesConstantColor) {
this.usesConstantColor = usesConstantColor;
}
public boolean usesConstantColor() {
return usesConstantColor;
}
}
public enum DestinationFunction {
/**
* The destination value of the blend function is all zeros.
*/
Zero(false),
/**
* The destination value of the blend function is all ones.
*/
One(false),
/**
* The destination value of the blend function is the source color.
*/
SourceColor(false),
/**
* The destination value of the blend function is 1 - the source color.
*/
OneMinusSourceColor(false),
/**
* The destination value of the blend function is the source alpha
* value.
*/
SourceAlpha(false),
/**
* The destination value of the blend function is 1 - the source alpha
* value.
*/
OneMinusSourceAlpha(false),
/**
* The destination value of the blend function is the destination alpha
* value.
*/
DestinationAlpha(false),
/**
* The destination value of the blend function is 1 - the destination
* alpha value.
*/
OneMinusDestinationAlpha(false),
/**
* The destination value of the blend function is the value of the
* constant color. (Rc, Gc, Bc, Ac) If not set, black with alpha = 0 is
* used. If not supported, falls back to One.
*/
ConstantColor(true),
/**
* The destination value of the blend function is 1 minus the value of
* the constant color. (1-Rc, 1-Gc, 1-Bc, 1-Ac) If color is not set,
* black with alpha = 0 is used. If not supported, falls back to One.
*/
OneMinusConstantColor(true),
/**
* The destination value of the blend function is the value of the
* constant color's alpha. (Ac, Ac, Ac, Ac) If not set, black with alpha =
* 0 is used. If not supported, falls back to One.
*/
ConstantAlpha(true),
/**
* The destination value of the blend function is 1 minus the value of
* the constant color's alpha. (1-Ac, 1-Ac, 1-Ac, 1-Ac) If color is not set,
* black with alpha = 0 is used. If not supported, falls back to One.
*/
OneMinusConstantAlpha(true);
private boolean usesConstantColor;
private DestinationFunction(boolean usesConstantColor) {
this.usesConstantColor = usesConstantColor;
}
public boolean usesConstantColor() {
return usesConstantColor;
}
}
public enum TestFunction {
/**
* Never passes the depth test.
*/
Never,
/**
* Always passes the depth test.
*/
Always,
/**
* Pass the test if this alpha is equal to the reference alpha.
*/
EqualTo,
/**
* Pass the test if this alpha is not equal to the reference alpha.
*/
NotEqualTo,
/**
* Pass the test if this alpha is less than the reference alpha.
*/
LessThan,
/**
* Pass the test if this alpha is less than or equal to the reference
* alpha.
*/
LessThanOrEqualTo,
/**
* Pass the test if this alpha is less than the reference alpha.
*/
GreaterThan,
/**
* Pass the test if this alpha is less than or equal to the reference
* alpha.
*/
GreaterThanOrEqualTo;
}
public enum BlendEquation {
/**
* Sets the blend equation so that the source and destination data are
* added. (Default) Clamps to [0,1] Useful for things like antialiasing
* and transparency.
*/
Add,
/**
* Sets the blend equation so that the source and destination data are
* subtracted (Src - Dest). Clamps to [0,1] Falls back to Add if
* supportsSubtract is false.
*/
Subtract,
/**
* Same as Subtract, but the order is reversed (Dst - Src). Clamps to
* [0,1] Falls back to Add if supportsSubtract is false.
*/
ReverseSubtract,
/**
* sets the blend equation so that each component of the result color is
* the minimum of the corresponding components of the source and
* destination colors. This and Max are useful for applications that
* analyze image data (image thresholding against a constant color, for
* example). Falls back to Add if supportsMinMax is false.
*/
Min,
/**
* sets the blend equation so that each component of the result color is
* the maximum of the corresponding components of the source and
* destination colors. This and Min are useful for applications that
* analyze image data (image thresholding against a constant color, for
* example). Falls back to Add if supportsMinMax is false.
*/
Max;
}
// support vars
protected static boolean supportsConstantColor = false;
protected static boolean supportsEq = false;
protected static boolean supportsSeparateEq = false;
protected static boolean supportsSeparateFunc = false;
protected static boolean supportsMinMax = false;
protected static boolean supportsSubtract = false;
// attributes
/** The current value of if blend is enabled. */
private boolean blendEnabled = false;
/** The blend color used in constant blend operations. */
private ColorRGBA constantColor = null;
/** The current source blend function. */
private SourceFunction sourceFunctionRGB = SourceFunction.SourceAlpha;
/** The current destiantion blend function. */
private DestinationFunction destinationFunctionRGB = DestinationFunction.OneMinusSourceAlpha;
/** The current blend equation. */
private BlendEquation blendEquationRGB = BlendEquation.Add;
/** The current source blend function. */
private SourceFunction sourceFunctionAlpha = SourceFunction.SourceAlpha;
/** The current destiantion blend function. */
private DestinationFunction destinationFunctionAlpha = DestinationFunction.OneMinusSourceAlpha;
/** The current blend equation. */
private BlendEquation blendEquationAlpha = BlendEquation.Add;
/** If enabled, alpha testing done. */
private boolean testEnabled = false;
/** Alpha test value. */
private TestFunction testFunction = TestFunction.Always;
/** The reference value to which incoming alpha values are compared. */
private float reference = 0;
/**
* Constructor instantiates a new <code>BlendState</code> object with
* default values.
*/
public BlendState() {
}
/**
* <code>getType</code> returns the type of render state this is.
* (RS_ALPHA).
*
* @see com.jme.scene.state.RenderState#getType()
* @deprecated As of 2.0, use {@link RenderState#getStateType()} instead.
*/
public int getType() {
return RS_BLEND;
}
/**
* <code>getStateType</code> returns the type {@link RenderState.StateType#Blend}
*
* @return {@link RenderState.StateType#Blend}
* @see com.jme.scene.state.RenderState#getStateType()
*/
public StateType getStateType() {
return StateType.Blend;
}
/**
* <code>isBlendEnabled</code> returns true if blending is turned on,
* otherwise false is returned.
*
* @return true if blending is enabled, false otherwise.
*/
public boolean isBlendEnabled() {
return blendEnabled;
}
/**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?