-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
271 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
fabric/src/main/java/com/noxcrew/noxesium/feature/ui/render/api/BlendState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.noxcrew.noxesium.feature.ui.render.api; | ||
|
||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import org.lwjgl.opengl.GL11; | ||
|
||
/** | ||
* Holds a snapshot of the current blending state. | ||
*/ | ||
public class BlendState { | ||
|
||
/** | ||
* Returns the initial blend state before UI rendering starts in vanilla. | ||
*/ | ||
public static BlendState initial() { | ||
var state = new BlendState(); | ||
state.blend = false; | ||
state.srcRgb = GL11.GL_SRC_ALPHA; | ||
state.dstRgb = GL11.GL_ONE_MINUS_SRC_ALPHA; | ||
state.srcAlpha = GL11.GL_ONE; | ||
state.dstAlpha = GL11.GL_ZERO; | ||
return state; | ||
} | ||
|
||
/** | ||
* Returns the standard blend state when rendering UI elements. | ||
*/ | ||
public static BlendState standard() { | ||
var state = new BlendState(); | ||
state.blend = true; | ||
state.srcRgb = GL11.GL_SRC_ALPHA; | ||
state.dstRgb = GL11.GL_ONE_MINUS_SRC_ALPHA; | ||
state.srcAlpha = GL11.GL_ONE; | ||
state.dstAlpha = GL11.GL_ONE_MINUS_SRC_ALPHA; | ||
return state; | ||
} | ||
|
||
/** | ||
* Takes a snapshot of the current blend state | ||
* intended by vanilla. | ||
*/ | ||
public static BlendState snapshot() { | ||
var state = new BlendState(); | ||
state.blend = GlStateManager.BLEND.mode.enabled; | ||
state.srcRgb = GlStateManager.BLEND.srcRgb; | ||
state.dstRgb = GlStateManager.BLEND.dstRgb; | ||
state.srcAlpha = GlStateManager.BLEND.srcAlpha; | ||
state.dstAlpha = GlStateManager.BLEND.dstAlpha; | ||
return state; | ||
} | ||
|
||
private boolean blend; | ||
private int srcRgb, dstRgb, srcAlpha, dstAlpha; | ||
|
||
/** | ||
* Applies this blend state. | ||
*/ | ||
public void apply() { | ||
if (blend) { | ||
GlStateManager._enableBlend(); | ||
} else { | ||
GlStateManager._disableBlend(); | ||
} | ||
|
||
GlStateManager._blendFuncSeparate(srcRgb, dstRgb, srcAlpha, dstAlpha); | ||
} | ||
|
||
/** | ||
* Returns whether blending is enabled. | ||
*/ | ||
public boolean enabled() { | ||
return blend; | ||
} | ||
|
||
/** | ||
* Returns the srcRgb value. | ||
*/ | ||
public int srcRgb() { | ||
return srcRgb; | ||
} | ||
|
||
/** | ||
* Returns the dstRgb value. | ||
*/ | ||
public int dstRgb() { | ||
return dstRgb; | ||
} | ||
|
||
/** | ||
* Returns the srcAlpha value. | ||
*/ | ||
public int srcAlpha() { | ||
return srcAlpha; | ||
} | ||
|
||
/** | ||
* Returns the dstAlpha value. | ||
*/ | ||
public int dstAlpha() { | ||
return dstAlpha; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
fabric/src/main/java/com/noxcrew/noxesium/feature/ui/render/api/BlendStateHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.noxcrew.noxesium.feature.ui.render.api; | ||
|
||
/** | ||
* A hook that receives any changes to the blending state. | ||
*/ | ||
public interface BlendStateHook { | ||
|
||
/** | ||
* Called when the blending state is attempted to | ||
* be changed to [newValue]. If `true` is returned | ||
* the call is prevented. | ||
*/ | ||
boolean changeState(boolean newValue); | ||
|
||
/** | ||
* Called when the blending function is attempted to | ||
* be changed to the new values. If `true` is returned | ||
* the call is prevented. | ||
*/ | ||
boolean changeFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.