Class RenderState
RenderState
specifies material rendering properties that cannot
be controlled by a shader on a Material
. The properties
allow manipulation of rendering features such as depth testing, alpha blending,
face culling, stencil operations, and much more.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
BlendEquation
specifies the blending equation to combine pixels.static enum
BlendEquationAlpha
specifies the blending equation to combine pixels for the alpha component.static enum
BlendFunc
defines the blending functions for use withBlendMode.Custom
.static enum
BlendMode
specifies the blending operation to use.static enum
FaceCullMode
specifies the criteria for faces to be culled.static enum
StencilOperation
specifies the stencil operation to use in a certain scenario as specified insetStencil(boolean, com.jme3.material.RenderState.StencilOperation, com.jme3.material.RenderState.StencilOperation, com.jme3.material.RenderState.StencilOperation, com.jme3.material.RenderState.StencilOperation, com.jme3.material.RenderState.StencilOperation, com.jme3.material.RenderState.StencilOperation, com.jme3.material.RenderState.TestFunction, com.jme3.material.RenderState.TestFunction)
static enum
TestFunction
specifies the testing function for stencil test function. -
Field Summary
Modifier and TypeFieldDescriptionstatic final RenderState
TheADDITIONAL
render state is identical to theDEFAULT
render state except that all apply values are set to false.static final RenderState
TheDEFAULT
render state is the one used by default on all materials unless changed otherwise by the user.static final RenderState
TheNULL
render state is identical to theDEFAULT
render state except that depth testing and face culling are disabled. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Create a clone of thisRenderState
int
void
copyFrom
(RenderState state) Copy all values from the given state to this state.copyMergedTo
(RenderState additionalState, RenderState state) Mergesthis
state andadditionalState
into the parameterstate
based on a specific criteria.boolean
Tests for equivalence with the argument.void
Flips the given face cull mode so thatBack
becomesFront
andFront
becomesBack
.float
Deprecated.Deprecated.Retrieve the back depth test fail operation.Retrieve the back depth test pass operation.Retrieve the back stencil function.int
Returns the back stencil mask.int
Returns the back stencil reference.Retrieve the back stencil fail operation.Returns the blend equation.Returns the blend equation used for the alpha component.Returns the blend mode.Returns the destination factor for the alpha component inBlendMode.Custom
.Returns the destination factor for the RGB components inBlendMode.Custom
.Returns the source factor for the alpha component inBlendMode.Custom
.Returns the source factor for the RGB components inBlendMode.Custom
.Retrieve the depth comparison functionRetrieve the face cull mode.Retrieve the front depth test fail operation.Retrieve the front depth test pass operation.Retrieve the front stencil function.int
Returns the front stencil mask.int
Returns the front stencil reference.Retrieve the front stencil fail operation.float
returns the wireframe line widthfloat
Retrieve the poly offset factor value.float
Retrieve the poly offset units value.boolean
Deprecated.boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
Check if color writing is enabled.boolean
Check if depth test is enabled.boolean
Check if depth write is enabled.boolean
Checks if the face cull mode is "flippable".boolean
Deprecated.Always returns true since point sprite is always enabled.boolean
Check if polygon offset is enabled.boolean
Check if stencil test is enabled.boolean
Check if wireframe mode is enabled.void
read
(JmeImporter im) void
set
(RenderState state) void
setBackStencilMask
(int backStencilMask) Sets the back stencil mask.void
setBackStencilReference
(int backStencilReference) Sets the back stencil reference.void
setBlendEquation
(RenderState.BlendEquation blendEquation) Set the blending equation for the color component (RGB).void
setBlendEquationAlpha
(RenderState.BlendEquationAlpha blendEquationAlpha) Set the blending equation for the alpha component.void
setBlendMode
(RenderState.BlendMode blendMode) Set the blending mode.void
setColorWrite
(boolean colorWrite) Enable writing color.void
setCustomBlendFactors
(RenderState.BlendFunc sfactorRGB, RenderState.BlendFunc dfactorRGB, RenderState.BlendFunc sfactorAlpha, RenderState.BlendFunc dfactorAlpha) Sets the blend factors used for the source and destination color.void
setDepthFunc
(RenderState.TestFunction depthFunc) Set the depth comparison function to the given TestFunction default is LessOrEqual (GL_LEQUAL)void
setDepthTest
(boolean depthTest) Enable depth testing.void
setDepthWrite
(boolean depthWrite) Enable depth writing.void
setFaceCullMode
(RenderState.FaceCullMode cullMode) Set the face culling mode.void
setFrontStencilMask
(int frontStencilMask) Sets the front stencil mask.void
setFrontStencilReference
(int frontStencilReference) Sets the front stencil reference.void
setLineWidth
(float lineWidth) Sets the mesh line width.void
setPolyOffset
(float factor, float units) Offsets the on-screen z-order of the material's polygons, to combat visual artefacts like stitching, bleeding and z-fighting for overlapping polygons.void
setStencil
(boolean enabled, RenderState.StencilOperation _frontStencilStencilFailOperation, RenderState.StencilOperation _frontStencilDepthFailOperation, RenderState.StencilOperation _frontStencilDepthPassOperation, RenderState.StencilOperation _backStencilStencilFailOperation, RenderState.StencilOperation _backStencilDepthFailOperation, RenderState.StencilOperation _backStencilDepthPassOperation, RenderState.TestFunction _frontStencilFunction, RenderState.TestFunction _backStencilFunction) Enable stencil testing.void
setWireframe
(boolean wireframe) Enables wireframe rendering mode.toString()
void
write
(JmeExporter ex)
-
Field Details
-
DEFAULT
TheDEFAULT
render state is the one used by default on all materials unless changed otherwise by the user.It has the following properties:
- Back Face Culling
- Depth Testing Enabled
- Depth Writing Enabled
-
NULL
TheNULL
render state is identical to theDEFAULT
render state except that depth testing and face culling are disabled. -
ADDITIONAL
TheADDITIONAL
render state is identical to theDEFAULT
render state except that all apply values are set to false. This allows theADDITIONAL
render state to be combined with other state but only influencing values that were changed from the original.
-
-
Constructor Details
-
RenderState
public RenderState()
-
-
Method Details
-
write
- Specified by:
write
in interfaceSavable
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Throws:
IOException
-
clone
Create a clone of thisRenderState
-
equals
Tests for equivalence with the argument. Ifo
is null, false is returned. Either way, the current instance is unaffected. -
setColorWrite
public void setColorWrite(boolean colorWrite) Enable writing color.When color write is enabled, the result of a fragment shader, the
gl_FragColor
, will be rendered into the color buffer (including alpha).- Parameters:
colorWrite
- Set to true to enable color writing.
-
setFaceCullMode
Set the face culling mode.See the
RenderState.FaceCullMode
enum on what each value does. Face culling will project the triangle's points onto the screen and determine if the triangle is in counter-clockwise order or clockwise order. If a triangle is in counter-clockwise order, then it is considered a front-facing triangle, otherwise, it is considered a back-facing triangle.- Parameters:
cullMode
- the face culling mode.
-
setBlendMode
Set the blending mode.When blending is enabled, (
blendMode
is notRenderState.BlendMode.Off
) the input pixel will be blended with the pixel already in the color buffer. The blending operation is determined by theRenderState.BlendMode
. For example, theRenderState.BlendMode.Additive
will add the input pixel's color to the color already in the color buffer:
Result = Source Color + Destination Color
- Parameters:
blendMode
- The blend mode to use. Set toRenderState.BlendMode.Off
to disable blending.
-
setBlendEquation
Set the blending equation for the color component (RGB).The blending equation determines, how the RGB values of the input pixel will be blended with the RGB values of the pixel already in the color buffer.
For example,RenderState.BlendEquation.Add
will add the input pixel's color to the color already in the color buffer:
Result = Source Color + Destination Color
Note: This gets only used in
RenderState.BlendMode.Custom
mode. All other blend modes will ignore this setting.- Parameters:
blendEquation
- TheRenderState.BlendEquation
to use.
-
setBlendEquationAlpha
Set the blending equation for the alpha component.The alpha blending equation determines, how the alpha values of the input pixel will be blended with the alpha values of the pixel already in the color buffer.
For example,RenderState.BlendEquationAlpha.Add
will add the input pixel's color to the color already in the color buffer:
Result = Source Color + Destination Color
Note: This gets only used in
RenderState.BlendMode.Custom
mode. All other blend modes will ignore this setting.- Parameters:
blendEquationAlpha
- TheRenderState.BlendEquationAlpha
to use.
-
setCustomBlendFactors
public void setCustomBlendFactors(RenderState.BlendFunc sfactorRGB, RenderState.BlendFunc dfactorRGB, RenderState.BlendFunc sfactorAlpha, RenderState.BlendFunc dfactorAlpha) Sets the blend factors used for the source and destination color.These factors will be multiplied with the color values of the input pixel and the pixel already in the color buffer, before both colors gets combined by the
RenderState.BlendEquation
.Note: This gets only used in
RenderState.BlendMode.Custom
mode. All other blend modes will ignore this setting.- Parameters:
sfactorRGB
- The source blend factor for RGB components.dfactorRGB
- The destination blend factor for RGB components.sfactorAlpha
- The source blend factor for the alpha component.dfactorAlpha
- The destination blend factor for the alpha component.
-
setDepthTest
public void setDepthTest(boolean depthTest) Enable depth testing.When depth testing is enabled, a pixel must pass the depth test before it is written to the color buffer. The input pixel's depth value must be less than or equal than the value already in the depth buffer to pass the depth test.
- Parameters:
depthTest
- Enable or disable depth testing.
-
setDepthWrite
public void setDepthWrite(boolean depthWrite) Enable depth writing.After passing the
depth test
, a pixel's depth value will be written into the depth buffer if depth writing is enabled.- Parameters:
depthWrite
- True to enable writing to the depth buffer.
-
setWireframe
public void setWireframe(boolean wireframe) Enables wireframe rendering mode.When in wireframe mode,
meshes
rendered in triangle mode will not be solid, but instead, only the edges of the triangles will be rendered.- Parameters:
wireframe
- True to enable wireframe mode.
-
setPolyOffset
public void setPolyOffset(float factor, float units) Offsets the on-screen z-order of the material's polygons, to combat visual artefacts like stitching, bleeding and z-fighting for overlapping polygons. Factor and units are summed to produce the depth offset. This offset is applied in screen space, typically with positive Z pointing into the screen. Typical values are (1.0f, 1.0f) or (-1.0f, -1.0f)- Parameters:
factor
- scales the maximum Z slope, with respect to X or Y of the polygonunits
- scales the minimum resolvable depth buffer value- See Also:
-
setStencil
public void setStencil(boolean enabled, RenderState.StencilOperation _frontStencilStencilFailOperation, RenderState.StencilOperation _frontStencilDepthFailOperation, RenderState.StencilOperation _frontStencilDepthPassOperation, RenderState.StencilOperation _backStencilStencilFailOperation, RenderState.StencilOperation _backStencilDepthFailOperation, RenderState.StencilOperation _backStencilDepthPassOperation, RenderState.TestFunction _frontStencilFunction, RenderState.TestFunction _backStencilFunction) Enable stencil testing.Stencil testing can be used to filter pixels according to the stencil buffer. Objects can be rendered with some stencil operation to manipulate the values in the stencil buffer, then, other objects can be rendered to test against the values written previously.
- Parameters:
enabled
- Set to true to enable stencil functionality. If false all other parameters are ignored._frontStencilStencilFailOperation
- Sets the operation to occur when a front-facing triangle fails the front stencil function._frontStencilDepthFailOperation
- Sets the operation to occur when a front-facing triangle fails the depth test._frontStencilDepthPassOperation
- Set the operation to occur when a front-facing triangle passes the depth test._backStencilStencilFailOperation
- Set the operation to occur when a back-facing triangle fails the back stencil function._backStencilDepthFailOperation
- Set the operation to occur when a back-facing triangle fails the depth test._backStencilDepthPassOperation
- Set the operation to occur when a back-facing triangle passes the depth test._frontStencilFunction
- Set the test function for front-facing triangles._backStencilFunction
- Set the test function for back-facing triangles.
-
setDepthFunc
Set the depth comparison function to the given TestFunction default is LessOrEqual (GL_LEQUAL)- Parameters:
depthFunc
- the depth comparison function- See Also:
-
setLineWidth
public void setLineWidth(float lineWidth) Sets the mesh line width. Use this in conjunction withsetWireframe(boolean)
or with a mesh inMesh.Mode.Lines
mode. Note: this does not work in OpenGL core profile. It only works in compatibility profile.- Parameters:
lineWidth
- the line width.
-
isStencilTest
public boolean isStencilTest()Check if stencil test is enabled.- Returns:
- True if stencil test is enabled.
-
getFrontStencilStencilFailOperation
Retrieve the front stencil fail operation.- Returns:
- the front stencil fail operation.
- See Also:
-
getFrontStencilDepthFailOperation
Retrieve the front depth test fail operation.- Returns:
- the front depth test fail operation.
- See Also:
-
getFrontStencilDepthPassOperation
Retrieve the front depth test pass operation.- Returns:
- the front depth test pass operation.
- See Also:
-
getBackStencilStencilFailOperation
Retrieve the back stencil fail operation.- Returns:
- the back stencil fail operation.
- See Also:
-
getBackStencilDepthFailOperation
Retrieve the back depth test fail operation.- Returns:
- the back depth test fail operation.
- See Also:
-
getBackStencilDepthPassOperation
Retrieve the back depth test pass operation.- Returns:
- the back depth test pass operation.
- See Also:
-
getFrontStencilFunction
Retrieve the front stencil function.- Returns:
- the front stencil function.
- See Also:
-
getBackStencilFunction
Retrieve the back stencil function.- Returns:
- the back stencil function.
- See Also:
-
setFrontStencilMask
public void setFrontStencilMask(int frontStencilMask) Sets the front stencil mask.- Parameters:
frontStencilMask
- the desired bitmask (default=0x7fffffff)
-
setBackStencilMask
public void setBackStencilMask(int backStencilMask) Sets the back stencil mask.- Parameters:
backStencilMask
- the desired bitmask (default=0x7fffffff)
-
setFrontStencilReference
public void setFrontStencilReference(int frontStencilReference) Sets the front stencil reference.- Parameters:
frontStencilReference
- the desired reference (default=0x0)
-
setBackStencilReference
public void setBackStencilReference(int backStencilReference) Sets the back stencil reference.- Parameters:
backStencilReference
- the desired bitmask (default=0x0)
-
getFrontStencilMask
public int getFrontStencilMask()Returns the front stencil mask.- Returns:
- the bitmask applied before comparing the front stencil to its reference value
-
getFrontStencilReference
public int getFrontStencilReference()Returns the front stencil reference.- Returns:
- the reference value for the front stencil
-
getBackStencilMask
public int getBackStencilMask()Returns the back stencil mask.- Returns:
- the bitmask applied before comparing the back stencil to its reference value
-
getBackStencilReference
public int getBackStencilReference()Returns the back stencil reference.- Returns:
- the reference value for the back stencil
-
getBlendEquation
Returns the blend equation.- Returns:
- the blend equation.
-
getBlendEquationAlpha
Returns the blend equation used for the alpha component.- Returns:
- the blend equation for the alpha component.
-
getBlendMode
Returns the blend mode.- Returns:
- the blend mode.
-
getCustomSfactorRGB
Returns the source factor for the RGB components inBlendMode.Custom
.- Returns:
- the custom source factor for RGB components.
-
getCustomDfactorRGB
Returns the destination factor for the RGB components inBlendMode.Custom
.- Returns:
- the custom destination factor for RGB components.
-
getCustomSfactorAlpha
Returns the source factor for the alpha component inBlendMode.Custom
.- Returns:
- the custom destination factor for alpha component.
-
getCustomDfactorAlpha
Returns the destination factor for the alpha component inBlendMode.Custom
.- Returns:
- the custom destination factor for alpha component.
-
isPointSprite
Deprecated.Always returns true since point sprite is always enabled.- Returns:
- true
-
isAlphaTest
Deprecated.To use alpha test, set theAlphaDiscardThreshold
material parameter.- Returns:
- false
-
getFaceCullMode
Retrieve the face cull mode.- Returns:
- the face cull mode.
- See Also:
-
isDepthTest
public boolean isDepthTest()Check if depth test is enabled.- Returns:
- True if depth test is enabled.
- See Also:
-
isDepthWrite
public boolean isDepthWrite()Check if depth write is enabled.- Returns:
- True if depth write is enabled.
- See Also:
-
isWireframe
public boolean isWireframe()Check if wireframe mode is enabled.- Returns:
- True if wireframe mode is enabled.
- See Also:
-
isColorWrite
public boolean isColorWrite()Check if color writing is enabled.- Returns:
- True if color writing is enabled.
- See Also:
-
getPolyOffsetFactor
public float getPolyOffsetFactor()Retrieve the poly offset factor value.- Returns:
- the poly offset factor value.
- See Also:
-
getPolyOffsetUnits
public float getPolyOffsetUnits()Retrieve the poly offset units value.- Returns:
- the poly offset units value.
- See Also:
-
isPolyOffset
public boolean isPolyOffset()Check if polygon offset is enabled.- Returns:
- True if polygon offset is enabled.
- See Also:
-
getAlphaFallOff
Deprecated.- Returns:
- 0
-
getDepthFunc
Retrieve the depth comparison function- Returns:
- the depth comparison function
- See Also:
-
getAlphaFunc
Deprecated.- Returns:
RenderState.TestFunction.Greater
.
-
getLineWidth
public float getLineWidth()returns the wireframe line width- Returns:
- the line width
-
isApplyBlendMode
public boolean isApplyBlendMode() -
isApplyColorWrite
public boolean isApplyColorWrite() -
isApplyCullMode
public boolean isApplyCullMode() -
isApplyDepthTest
public boolean isApplyDepthTest() -
isApplyDepthWrite
public boolean isApplyDepthWrite() -
isApplyPolyOffset
public boolean isApplyPolyOffset() -
isApplyWireFrame
public boolean isApplyWireFrame() -
isApplyDepthFunc
public boolean isApplyDepthFunc() -
isApplyLineWidth
public boolean isApplyLineWidth() -
contentHashCode
public int contentHashCode()- Returns:
- value for use in hashing
-
copyMergedTo
Mergesthis
state andadditionalState
into the parameterstate
based on a specific criteria.The criteria for this merge is the following:
For every given property, such as alpha test or depth write, check if it was modified from the original in theadditionalState
if it was modified, then copy the property from theadditionalState
into the parameterstate
, otherwise, copy the property fromthis
into the parameterstate
. IfadditionalState
isnull
, then no modifications are made andthis
is returned, otherwise, the parameterstate
is returned with the result of the merge.- Parameters:
additionalState
- TheadditionalState
, from which data is taken only if it was modified by the user.state
- Contains output of the method ifadditionalState
is not null.- Returns:
state
ifadditionalState
is non-null, otherwise returnsthis
-
set
-
copyFrom
Copy all values from the given state to this state.This method is more precise than
set(com.jme3.material.RenderState)
.- Parameters:
state
- state to copy from
-
toString
-
flipFaceCull
public void flipFaceCull()Flips the given face cull mode so thatBack
becomesFront
andFront
becomesBack
.FrontAndBack
andOff
are unaffected. This is important for flipping the cull mode when normal vectors are found to be backward. -
isFaceCullFlippable
public boolean isFaceCullFlippable()Checks if the face cull mode is "flippable".The cull mode is flippable when it is either
Front
orBack
.- Returns:
-
AlphaDiscardThreshold
material parameter.