aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-06-30 12:40:10 +0200
committerGitHub <noreply@github.com>2024-06-30 12:40:10 +0200
commit4a55a7d4d8c3551cc4cfa3bd82867579494e3c70 (patch)
tree420f2cca39de625307d5356f5a01635071c8b42a /src/main/java/at
parent2e93920ab64bacfc428cf8bf040a2b10b6d9f2f8 (diff)
downloadskyhanni-4a55a7d4d8c3551cc4cfa3bd82867579494e3c70.tar.gz
skyhanni-4a55a7d4d8c3551cc4cfa3bd82867579494e3c70.tar.bz2
skyhanni-4a55a7d4d8c3551cc4cfa3bd82867579494e3c70.zip
Backend: Enabling Shader with Enum (#2035)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt37
4 files changed, 15 insertions, 36 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt
index db6e06d25..ffded8099 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt
@@ -33,7 +33,7 @@ object ChromaShaderManager {
private fun enable(chromaType: ChromaType) {
if (!chromaEnabled) {
chromaEnabled = true
- ShaderManager.enableShader(chromaType.shaderName)
+ ShaderManager.enableShader(chromaType.shader)
}
}
@@ -45,14 +45,14 @@ object ChromaShaderManager {
}
}
-enum class ChromaType(val shaderName: String) {
+enum class ChromaType(val shader: ShaderManager.Shaders) {
/**
* See [StandardChromaShader]
*/
- STANDARD("standard_chroma"),
+ STANDARD(ShaderManager.Shaders.STANDARD_CHROMA),
/**
* See [TexturedChromaShader]
*/
- TEXTURED("textured_chroma")
+ TEXTURED(ShaderManager.Shaders.TEXTURED_CHROMA)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 89489518c..fe9e9df6a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -1731,7 +1731,7 @@ object RenderUtils {
RoundedRectangleShader.centerPos = floatArrayOf(xIn + (widthIn / 2f), yIn + (heightIn / 2f))
GlStateManager.pushMatrix()
- ShaderManager.enableShader("rounded_rect")
+ ShaderManager.enableShader(ShaderManager.Shaders.ROUNDED_RECTANGLE)
Gui.drawRect(x - 5, y - 5, x + width + 5, y + height + 5, color)
@@ -1784,7 +1784,7 @@ object RenderUtils {
RoundedRectangleOutlineShader.borderBlur = max(1 - blur, 0f)
GlStateManager.pushMatrix()
- ShaderManager.enableShader("rounded_rect_outline")
+ ShaderManager.enableShader(ShaderManager.Shaders.ROUNDED_RECT_OUTLINE)
drawGradientRect(
x - borderAdjustment,
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
index 0ed562152..b51c83295 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
@@ -392,7 +392,7 @@ interface Renderable {
override fun render(posX: Int, posY: Int) {
DarkenShader.darknessLevel = amount
- ShaderManager.enableShader("darken")
+ ShaderManager.enableShader(ShaderManager.Shaders.DARKEN)
this@darken.render(posX, posY)
ShaderManager.disableShader()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt
index b32e3fa26..057e0a031 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt
@@ -31,40 +31,19 @@ object ShaderManager {
DARKEN(DarkenShader.INSTANCE)
;
- fun enableShader() = ShaderManager.enableShader(name.lowercase())
-
- companion object {
-
- fun getShaderInstance(shaderName: String): Shader? = when (shaderName) {
- "standard_chroma" -> STANDARD_CHROMA.shader
- "textured_chroma" -> TEXTURED_CHROMA.shader
- "rounded_rect" -> ROUNDED_RECTANGLE.shader
- "rounded_rect_outline" -> ROUNDED_RECT_OUTLINE.shader
- "darken" -> DARKEN.shader
- else -> {
- null
- }
- }
- }
+ fun enableShader() = enableShader(this)
}
- private val shaders: MutableMap<String, Shader> = mutableMapOf()
private var activeShader: Shader? = null
- fun enableShader(shaderName: String) {
- var shader = shaders[shaderName]
-
- if (shader == null) {
- shader = Shaders.getShaderInstance(shaderName)
- if (shader == null) return
- shaders[shaderName] = shader
- }
+ fun enableShader(shader: Shaders) {
+ val shaderInstance = shader.shader
- if (!shader.created) return
+ if (!shaderInstance.created) return
- activeShader = shader
- shader.enable()
- shader.updateUniforms()
+ activeShader = shaderInstance
+ shaderInstance.enable()
+ shaderInstance.updateUniforms()
}
fun attachShader(shaderProgram: Int, shaderID: Int) {
@@ -101,7 +80,7 @@ object ShaderManager {
ErrorManager.logErrorWithData(
OpenGLException("Shader compilation error."),
errorMessage,
- "GLSL Compilation Error:\n" to errorLog
+ "GLSL Compilation Error:\n" to errorLog,
)
} else {
LorenzUtils.consoleLog("$errorMessage $errorLog")