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
Nested ClassesModifier and TypeClassDescriptionstatic enumBlendEquationspecifies the blending equation to combine pixels.static enumBlendEquationAlphaspecifies the blending equation to combine pixels for the alpha component.static enumBlendFuncdefines the blending functions for use withBlendMode.Custom.static enumBlendModespecifies the blending operation to use.static enumFaceCullModespecifies the criteria for faces to be culled.static enumStencilOperationspecifies 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 enumTestFunctionspecifies the testing function for stencil test function. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RenderStateTheADDITIONALrender state is identical to theDEFAULTrender state except that all apply values are set to false.static final RenderStateTheDEFAULTrender state is the one used by default on all materials unless changed otherwise by the user.static final RenderStateTheNULLrender state is identical to theDEFAULTrender state except that depth testing and face culling are disabled. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Create a clone of thisRenderStateintcopyFrom(RenderState state) Copy all values from the given state to this state.copyMergedTo(RenderState additionalState, RenderState state) Mergesthisstate andadditionalStateinto the parameterstatebased on a specific criteria.booleanTests for equivalence with the argument.voidFlips the given face cull mode so thatBackbecomesFrontandFrontbecomesBack.floatDeprecated.Deprecated.Retrieve the back depth test fail operation.Retrieve the back depth test pass operation.Retrieve the back stencil function.intReturns the back stencil mask.intReturns 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.intReturns the front stencil mask.intReturns the front stencil reference.Retrieve the front stencil fail operation.floatreturns the wireframe line widthfloatRetrieve the poly offset factor value.floatRetrieve the poly offset units value.booleanDeprecated.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanCheck if color writing is enabled.booleanCheck if depth test is enabled.booleanCheck if depth write is enabled.booleanChecks if the face cull mode is "flippable".booleanDeprecated.Always returns true since point sprite is always enabled.booleanCheck if polygon offset is enabled.booleanCheck if stencil test is enabled.booleanCheck if wireframe mode is enabled.voidread(JmeImporter im) voidset(RenderState state) voidsetBackStencilMask(int backStencilMask) Sets the back stencil mask.voidsetBackStencilReference(int backStencilReference) Sets the back stencil reference.voidsetBlendEquation(RenderState.BlendEquation blendEquation) Set the blending equation for the color component (RGB).voidsetBlendEquationAlpha(RenderState.BlendEquationAlpha blendEquationAlpha) Set the blending equation for the alpha component.voidsetBlendMode(RenderState.BlendMode blendMode) Set the blending mode.voidsetColorWrite(boolean colorWrite) Enable writing color.voidsetCustomBlendFactors(RenderState.BlendFunc sfactorRGB, RenderState.BlendFunc dfactorRGB, RenderState.BlendFunc sfactorAlpha, RenderState.BlendFunc dfactorAlpha) Sets the blend factors used for the source and destination color.voidsetDepthFunc(RenderState.TestFunction depthFunc) Set the depth comparison function to the given TestFunction default is LessOrEqual (GL_LEQUAL)voidsetDepthTest(boolean depthTest) Enable depth testing.voidsetDepthWrite(boolean depthWrite) Enable depth writing.voidsetFaceCullMode(RenderState.FaceCullMode cullMode) Set the face culling mode.voidsetFrontStencilMask(int frontStencilMask) Sets the front stencil mask.voidsetFrontStencilReference(int frontStencilReference) Sets the front stencil reference.voidsetLineWidth(float lineWidth) Sets the mesh line width.voidsetPolyOffset(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.voidsetStencil(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.voidsetWireframe(boolean wireframe) Enables wireframe rendering mode.toString()voidwrite(JmeExporter ex)
-
Field Details
-
DEFAULT
TheDEFAULTrender 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
TheNULLrender state is identical to theDEFAULTrender state except that depth testing and face culling are disabled. -
ADDITIONAL
TheADDITIONALrender state is identical to theDEFAULTrender state except that all apply values are set to false. This allows theADDITIONALrender 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:
writein interfaceSavable- Throws:
IOException
-
read
- Specified by:
readin interfaceSavable- Throws:
IOException
-
clone
Create a clone of thisRenderState -
equals
Tests for equivalence with the argument. Ifois 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.FaceCullModeenum 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, (
blendModeis 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.Additivewill 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.Offto 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.Addwill add the input pixel's color to the color already in the color buffer:
Result = Source Color + Destination ColorNote: This gets only used in
RenderState.BlendMode.Custommode. All other blend modes will ignore this setting.- Parameters:
blendEquation- TheRenderState.BlendEquationto 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.Addwill add the input pixel's color to the color already in the color buffer:
Result = Source Color + Destination ColorNote: This gets only used in
RenderState.BlendMode.Custommode. All other blend modes will ignore this setting.- Parameters:
blendEquationAlpha- TheRenderState.BlendEquationAlphato 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.Custommode. 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,
meshesrendered 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.Linesmode. 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 theAlphaDiscardThresholdmaterial 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
Mergesthisstate andadditionalStateinto the parameterstatebased 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 theadditionalStateif it was modified, then copy the property from theadditionalStateinto the parameterstate, otherwise, copy the property fromthisinto the parameterstate. IfadditionalStateisnull, then no modifications are made andthisis returned, otherwise, the parameterstateis 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 ifadditionalStateis not null.- Returns:
stateifadditionalStateis 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 thatBackbecomesFrontandFrontbecomesBack.FrontAndBackandOffare 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
FrontorBack.- Returns:
-
AlphaDiscardThresholdmaterial parameter.