fix some shader bugs

This commit is contained in:
Bixilon 2021-07-01 16:23:23 +02:00
parent 237b63ae91
commit 2c2ec5bd9f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 11 additions and 1 deletions

View File

@ -60,6 +60,10 @@ interface Shader {
is Vec4 -> setVec4(uniformName, data)
is Vec3 -> setVec3(uniformName, data)
is Vec2 -> setVec2(uniformName, data)
is RGBColor -> setRGBColor(uniformName, data)
is UniformBuffer -> setUniformBuffer(uniformName, data)
// ToDo: Texture
else -> error("Don't know what todo with uniform type ${data::class.simpleName}!")
}
}

View File

@ -32,6 +32,9 @@ class GLSLShaderCode(
continue
}
val reader = GLSLStringReader(line.removePrefix("uniform "))
reader.skipWhitespaces()
reader.readUnquotedString() // data type
reader.skipWhitespaces()
uniforms += reader.readUnquotedString()
}

View File

@ -42,18 +42,21 @@ class OpenGLShader(
private set
val defines: MutableMap<String, Any> = mutableMapOf()
private var shader = -1
override var uniforms: List<String> = listOf()
override var uniforms: MutableList<String> = mutableListOf()
private set
private fun load(resourceLocation: ResourceLocation, shaderType: Int): Int {
val code = GLSLShaderCode(renderWindow, renderWindow.connection.assetsManager.readStringAsset(resourceLocation))
code.defines += defines
val program = glCreateShaderObjectARB(shaderType)
if (program.toLong() == MemoryUtil.NULL) {
throw ShaderLoadingException()
}
this.uniforms += code.uniforms
glShaderSourceARB(program, code.code)
glCompileShaderARB(program)