Skip to content

Commit

Permalink
fix render states merging when additionalState is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Mar 1, 2024
1 parent 56fecab commit 1caefd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 9 additions & 8 deletions jme3-core/src/main/java/com/jme3/material/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -907,20 +907,21 @@ private BindUnits updateShaderMaterialParameters(Renderer renderer, Shader shade


private void updateRenderState(Geometry geometry, RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) {
RenderState finalRenderState;
if (renderManager.getForcedRenderState() != null) {
mergedRenderState.copyFrom(renderManager.getForcedRenderState());
finalRenderState=mergedRenderState.copyFrom(renderManager.getForcedRenderState());
} else if (techniqueDef.getRenderState() != null) {
mergedRenderState.copyFrom(RenderState.DEFAULT);
techniqueDef.getRenderState().copyMergedTo(additionalState, mergedRenderState);
finalRenderState=mergedRenderState.copyFrom(RenderState.DEFAULT);
finalRenderState=techniqueDef.getRenderState().copyMergedTo(additionalState, finalRenderState);
} else {
mergedRenderState.copyFrom(RenderState.DEFAULT);
RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState);
finalRenderState=mergedRenderState.copyFrom(RenderState.DEFAULT);
finalRenderState=RenderState.DEFAULT.copyMergedTo(additionalState, finalRenderState);
}
// test if the face cull mode should be flipped before render
if (mergedRenderState.isFaceCullFlippable() && isNormalsBackward(geometry.getWorldScale())) {
mergedRenderState.flipFaceCull();
if (finalRenderState.isFaceCullFlippable() && isNormalsBackward(geometry.getWorldScale())) {
finalRenderState.flipFaceCull();
}
renderer.applyRenderState(mergedRenderState);
renderer.applyRenderState(finalRenderState);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion jme3-core/src/main/java/com/jme3/material/RenderState.java
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ public void set(RenderState state) {
* This method is more precise than {@link #set(com.jme3.material.RenderState)}.
* @param state state to copy from
*/
public void copyFrom(RenderState state) {
public RenderState copyFrom(RenderState state) {
this.applyBlendMode = state.applyBlendMode;
this.applyColorWrite = state.applyColorWrite;
this.applyCullMode = state.applyCullMode;
Expand Down Expand Up @@ -1734,6 +1734,7 @@ public void copyFrom(RenderState state) {
this.sfactorRGB = state.sfactorRGB;
this.stencilTest = state.stencilTest;
this.wireframe = state.wireframe;
return this;
}

@Override
Expand Down

0 comments on commit 1caefd1

Please sign in to comment.