From 1663ad225027d43e939d7c0523138c679a00597d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 22 Dec 2014 22:49:14 +0900 Subject: [PATCH] Remove shader programColorFinal --- .../opengl/internal/shader/drawtexture.go | 7 +--- internal/opengl/internal/shader/program.go | 34 ------------------- internal/opengl/internal/shader/shader.go | 30 ++++++---------- 3 files changed, 11 insertions(+), 60 deletions(-) diff --git a/internal/opengl/internal/shader/drawtexture.go b/internal/opengl/internal/shader/drawtexture.go index 01740dc08..12dea7410 100644 --- a/internal/opengl/internal/shader/drawtexture.go +++ b/internal/opengl/internal/shader/drawtexture.go @@ -47,12 +47,7 @@ func DrawTexture(native gl.Texture, target gl.Texture, projectionMatrix [4][4]fl return } // TODO: Check performance - program := gl.Program(0) - if 0 < target { - program = useProgramColorMatrix(glMatrix(projectionMatrix), geo, color) - } else { - program = useProgramColorFinal(glMatrix(projectionMatrix), geo) - } + program := useProgramColorMatrix(glMatrix(projectionMatrix), geo, color) gl.ActiveTexture(gl.TEXTURE0) native.Bind(gl.TEXTURE_2D) diff --git a/internal/opengl/internal/shader/program.go b/internal/opengl/internal/shader/program.go index e09dea9e6..109010c00 100644 --- a/internal/opengl/internal/shader/program.go +++ b/internal/opengl/internal/shader/program.go @@ -29,10 +29,6 @@ var programColorMatrix = program{ shaderIds: []shaderId{shaderVertex, shaderColorMatrix}, } -var programColorFinal = program{ - shaderIds: []shaderId{shaderVertex, shaderColorFinal}, -} - func (p *program) create() { p.native = gl.CreateProgram() if p.native == 0 { @@ -59,7 +55,6 @@ func initialize() { }() programColorMatrix.create() - programColorFinal.create() } func getAttributeLocation(program gl.Program, name string) gl.AttribLocation { @@ -119,32 +114,3 @@ func useProgramColorMatrix(projectionMatrix [16]float32, geo Matrix, color Matri return program.native } - -func useProgramColorFinal(projectionMatrix [16]float32, geo Matrix) gl.Program { - if lastProgram != programColorFinal.native { - programColorFinal.native.Use() - lastProgram = programColorFinal.native - } - - program := programColorFinal - - getUniformLocation(program.native, "projection_matrix").UniformMatrix4fv(false, projectionMatrix) - - a := float32(geo.Element(0, 0)) - b := float32(geo.Element(0, 1)) - c := float32(geo.Element(1, 0)) - d := float32(geo.Element(1, 1)) - tx := float32(geo.Element(0, 2)) - ty := float32(geo.Element(1, 2)) - glModelviewMatrix := [...]float32{ - a, c, 0, 0, - b, d, 0, 0, - 0, 0, 1, 0, - tx, ty, 0, 1, - } - getUniformLocation(program.native, "modelview_matrix").UniformMatrix4fv(false, glModelviewMatrix) - - getUniformLocation(program.native, "texture").Uniform1i(0) - - return program.native -} diff --git a/internal/opengl/internal/shader/shader.go b/internal/opengl/internal/shader/shader.go index 844ea3fe2..ae45a04b2 100644 --- a/internal/opengl/internal/shader/shader.go +++ b/internal/opengl/internal/shader/shader.go @@ -31,9 +31,7 @@ type shaderId int const ( shaderVertex shaderId = iota - shaderVertexFinal shaderColorMatrix - shaderColorFinal ) var shaders = map[shaderId]*shader{ @@ -62,27 +60,19 @@ varying vec2 vertex_out_tex_coord; void main(void) { vec4 color = texture2D(texture, vertex_out_tex_coord); - // Un-premultiply alpha - color.rgb /= color.a; - // Apply the color matrix - color = (color_matrix * color) + color_matrix_translation; - // Premultiply alpha - color = clamp(color, 0.0, 1.0); - color.rgb *= color.a; + + if (color_matrix != mat4(1.0) || color_matrix_translation != vec4(0.0)) { + // Un-premultiply alpha + color.rgb /= color.a; + // Apply the color matrix + color = (color_matrix * color) + color_matrix_translation; + color = clamp(color, 0.0, 1.0); + // Premultiply alpha + color.rgb *= color.a; + } gl_FragColor = color; } -`, - }, - shaderColorFinal: { - shaderType: gl.FRAGMENT_SHADER, - source: ` -uniform sampler2D texture; -varying vec2 vertex_out_tex_coord; - -void main(void) { - gl_FragColor = texture2D(texture, vertex_out_tex_coord); -} `, }, }