Перемещаем все программы в GLPrograms
This commit is contained in:
parent
1f50315ed5
commit
244f6e3461
@ -136,6 +136,19 @@ class GLStateTracker(val locator: ISBFileLocator) {
|
|||||||
// bindings available for use.
|
// bindings available for use.
|
||||||
val capabilities: GLCapabilities = GL.createCapabilities()
|
val capabilities: GLCapabilities = GL.createCapabilities()
|
||||||
|
|
||||||
|
val programs = GLPrograms(this)
|
||||||
|
|
||||||
|
val flat2DLines by lazy { StreamVertexBuilder(this, GLAttributeList.VEC2F, GeometryType.LINES) }
|
||||||
|
val flat2DTriangles by lazy { StreamVertexBuilder(this, GLAttributeList.VEC2F, GeometryType.TRIANGLES) }
|
||||||
|
val flat2DTexturedQuads by lazy { StreamVertexBuilder(this, GLAttributeList.VERTEX_TEXTURE, GeometryType.QUADS) }
|
||||||
|
val quadWireframe by lazy { StreamVertexBuilder(this, GLAttributeList.VEC2F, GeometryType.QUADS_AS_LINES_WIREFRAME) }
|
||||||
|
|
||||||
|
val matrixStack = Matrix4fStack()
|
||||||
|
val freeType = FreeType()
|
||||||
|
val font = Font(this)
|
||||||
|
val thread: Thread = Thread.currentThread()
|
||||||
|
val box2dRenderer = Box2DRenderer(this)
|
||||||
|
|
||||||
private val cleanerBacklog = ArrayList<() -> Unit>()
|
private val cleanerBacklog = ArrayList<() -> Unit>()
|
||||||
|
|
||||||
var objectsCleaned = 0
|
var objectsCleaned = 0
|
||||||
@ -326,8 +339,6 @@ class GLStateTracker(val locator: ISBFileLocator) {
|
|||||||
checkForGLError()
|
checkForGLError()
|
||||||
}
|
}
|
||||||
|
|
||||||
val thread: Thread = Thread.currentThread()
|
|
||||||
|
|
||||||
fun ensureSameThread() {
|
fun ensureSameThread() {
|
||||||
if (thread !== Thread.currentThread()) {
|
if (thread !== Thread.currentThread()) {
|
||||||
throw IllegalAccessException("Trying to access $this outside of $thread!")
|
throw IllegalAccessException("Trying to access $this outside of $thread!")
|
||||||
@ -435,50 +446,6 @@ class GLStateTracker(val locator: ISBFileLocator) {
|
|||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
val shaderVertexTexture: TexturedProgram
|
|
||||||
val shaderVertexTextureColor: TexturedColoredProgram
|
|
||||||
|
|
||||||
inner class TexturedProgram(shaders: Iterable<Shader>) : GLShaderProgram(this@GLStateTracker, shaders) {
|
|
||||||
var transform by F4x4Uniform("transform")
|
|
||||||
var texture by IUniform("texture0")
|
|
||||||
|
|
||||||
init {
|
|
||||||
transform = Matrix4f.IDENTITY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class TexturedColoredProgram(shaders: Iterable<Shader>) : GLShaderProgram(this@GLStateTracker, shaders) {
|
|
||||||
var transform by F4x4Uniform("transform")
|
|
||||||
var texture by IUniform("texture0")
|
|
||||||
var color by F4Uniform("color")
|
|
||||||
|
|
||||||
init {
|
|
||||||
transform = Matrix4f.IDENTITY
|
|
||||||
color = Color.WHITE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val textureF = internalFragment("shaders/fragment/texture.glsl")
|
|
||||||
val textureColorF = internalFragment("shaders/fragment/texture_color.glsl")
|
|
||||||
val textureV = internalVertex("shaders/vertex/texture.glsl")
|
|
||||||
|
|
||||||
shaderVertexTexture = TexturedProgram(listOf(textureF, textureV))
|
|
||||||
shaderVertexTextureColor = TexturedColoredProgram(listOf(textureColorF, textureV))
|
|
||||||
}
|
|
||||||
|
|
||||||
val programs = GLPrograms(this)
|
|
||||||
|
|
||||||
val flat2DLines by lazy { StreamVertexBuilder(this, GLAttributeList.VEC2F, GeometryType.LINES) }
|
|
||||||
val flat2DTriangles by lazy { StreamVertexBuilder(this, GLAttributeList.VEC2F, GeometryType.TRIANGLES) }
|
|
||||||
val flat2DTexturedQuads by lazy { StreamVertexBuilder(this, GLAttributeList.VERTEX_TEXTURE, GeometryType.QUADS) }
|
|
||||||
val quadWireframe by lazy { StreamVertexBuilder(this, GLAttributeList.VEC2F, GeometryType.QUADS_AS_LINES_WIREFRAME) }
|
|
||||||
|
|
||||||
val matrixStack = Matrix4fStack()
|
|
||||||
val freeType = FreeType()
|
|
||||||
|
|
||||||
val font = Font(this)
|
|
||||||
|
|
||||||
inline fun quadWireframe(color: Color = Color.WHITE, lambda: (VertexBuilder) -> Unit) {
|
inline fun quadWireframe(color: Color = Color.WHITE, lambda: (VertexBuilder) -> Unit) {
|
||||||
val builder = quadWireframe
|
val builder = quadWireframe
|
||||||
|
|
||||||
@ -513,8 +480,6 @@ class GLStateTracker(val locator: ISBFileLocator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val box2dRenderer = Box2DRenderer(this)
|
|
||||||
|
|
||||||
inner class Shader(body: String, type: Int) {
|
inner class Shader(body: String, type: Int) {
|
||||||
constructor(body: File, type: Int) : this(body.also { require(it.exists()) { "Shader file does not exists: $body" } }.readText(), type)
|
constructor(body: File, type: Int) : this(body.also { require(it.exists()) { "Shader file does not exists: $body" } }.readText(), type)
|
||||||
|
|
||||||
|
@ -212,6 +212,26 @@ class GLFlatProgram(state: GLStateTracker) : GLShaderProgram(state, state.shader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GLTexturedProgram(state: GLStateTracker) : GLShaderProgram(state, listOf(state.internalVertex("shaders/vertex/texture.glsl"), state.internalFragment("shaders/fragment/texture.glsl"))) {
|
||||||
|
var transform by F4x4Uniform("transform")
|
||||||
|
var texture by IUniform("texture0")
|
||||||
|
|
||||||
|
init {
|
||||||
|
transform = Matrix4f.IDENTITY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GLTexturedColoredProgram(state: GLStateTracker) : GLShaderProgram(state, listOf(state.internalVertex("shaders/vertex/texture.glsl"), state.internalFragment("shaders/fragment/texture_color.glsl"))) {
|
||||||
|
var transform by F4x4Uniform("transform")
|
||||||
|
var texture by IUniform("texture0")
|
||||||
|
var color by F4Uniform("color")
|
||||||
|
|
||||||
|
init {
|
||||||
|
transform = Matrix4f.IDENTITY
|
||||||
|
color = Color.WHITE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class GLPrograms(val state: GLStateTracker) {
|
class GLPrograms(val state: GLStateTracker) {
|
||||||
val tile by lazy { GLTileProgram(state) }
|
val tile by lazy { GLTileProgram(state) }
|
||||||
val font by lazy { GLFontProgram(state) }
|
val font by lazy { GLFontProgram(state) }
|
||||||
@ -221,6 +241,8 @@ class GLPrograms(val state: GLStateTracker) {
|
|||||||
val light by lazy { GLLightProgram(state) }
|
val light by lazy { GLLightProgram(state) }
|
||||||
val hardLightGeometry by lazy { GLHardLightGeometryProgram(state) }
|
val hardLightGeometry by lazy { GLHardLightGeometryProgram(state) }
|
||||||
val softLightGeometry by lazy { GLSoftLightGeometryProgram(state) }
|
val softLightGeometry by lazy { GLSoftLightGeometryProgram(state) }
|
||||||
|
val textured by lazy { GLTexturedProgram(state) }
|
||||||
|
val texturedColored by lazy { GLTexturedColoredProgram(state) }
|
||||||
|
|
||||||
val viewColorQuad by lazy { GLColorQuadProgram(state) }
|
val viewColorQuad by lazy { GLColorQuadProgram(state) }
|
||||||
val viewTextureQuad by lazy { GLTextureQuadProgram(state) }
|
val viewTextureQuad by lazy { GLTextureQuadProgram(state) }
|
||||||
|
@ -15,10 +15,10 @@ class ItemRenderer(state: GLStateTracker, entity: ItemEntity, chunk: ClientChunk
|
|||||||
if (textures.isEmpty())
|
if (textures.isEmpty())
|
||||||
return
|
return
|
||||||
|
|
||||||
state.shaderVertexTexture.use()
|
state.programs.textured.use()
|
||||||
state.shaderVertexTexture.transform = stack.last
|
state.programs.textured.transform = stack.last
|
||||||
state.activeTexture = 0
|
state.activeTexture = 0
|
||||||
state.shaderVertexTexture.texture = 0
|
state.programs.textured.texture = 0
|
||||||
|
|
||||||
for (texture in textures) {
|
for (texture in textures) {
|
||||||
texture.bind()
|
texture.bind()
|
||||||
|
Loading…
Reference in New Issue
Block a user