Remove shader programColorFinal

This commit is contained in:
Hajime Hoshi 2014-12-22 22:49:14 +09:00
parent 2620414409
commit 1663ad2250
3 changed files with 11 additions and 60 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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);
}
`,
},
}