Skip to content

Commit

Permalink
fix render states merging when additionalState is not set (#2208)
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl authored Mar 2, 2024
1 parent d0683ed commit c51ddf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 10 additions & 9 deletions jme3-core/src/main/java/com/jme3/material/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -907,22 +907,23 @@ 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);
}

/**
* Returns true if the geometry world scale indicates that normals will be backward.
* @param scalar geometry world scale
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 c51ddf4

Please sign in to comment.