ebiten: Refactoring

This commit is contained in:
Hajime Hoshi 2020-07-26 14:33:37 +09:00
parent 637afe6d67
commit d08a04a635
2 changed files with 21 additions and 21 deletions

View File

@ -305,9 +305,10 @@ func (g *Graphics) DrawShader(dst driver.ImageID, srcs [graphics.ShaderImageNum]
us[0].value = []float32{float32(vw), float32(vh)} us[0].value = []float32{float32(vw), float32(vh)}
for i, o := range offsets { for i, o := range offsets {
const offset = 1
o := o o := o
us[i+1].name = fmt.Sprintf("U%d", i+1) us[i+offset].name = fmt.Sprintf("U%d", i+offset)
us[i+1].value = o[:] us[i+offset].value = o[:]
} }
for i, v := range uniforms { for i, v := range uniforms {

View File

@ -34,7 +34,25 @@ var __textureDstSize vec2
func textureDstSize() vec2 { func textureDstSize() vec2 {
return __textureDstSize return __textureDstSize
} }
`
for i := 0; i < graphics.ShaderImageNum; i++ {
var offset string
if i >= 1 {
shaderSuffix += fmt.Sprintf(`
var __textureOffset%[1]d vec2
`, i)
offset = fmt.Sprintf(" + __textureOffset%d", i)
}
// __t%d is a special variable for a texture variable.
shaderSuffix += fmt.Sprintf(`
func texture%[1]dAt(pos vec2) vec4 {
return texture2D(__t%[1]d, pos%[2]s)
}
`, i, offset)
}
shaderSuffix += `
func __vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2, vec4) { func __vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2, vec4) {
return mat4( return mat4(
2/textureDstSize().x, 0, 0, 0, 2/textureDstSize().x, 0, 0, 0,
@ -44,25 +62,6 @@ func __vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2, vec4) {
) * vec4(position, 0, 1), texCoord, color ) * vec4(position, 0, 1), texCoord, color
} }
` `
for i := 1; i < graphics.ShaderImageNum; i++ {
shaderSuffix += fmt.Sprintf(`
var __offset%d vec2
`, i)
}
for i := 0; i < graphics.ShaderImageNum; i++ {
var offset string
if i >= 1 {
offset = fmt.Sprintf(" + __offset%d", i)
}
// __t%d is a special variable for a texture variable.
shaderSuffix += fmt.Sprintf(`
func texture%[1]dAt(pos vec2) vec4 {
return texture2D(__t%[1]d, pos%[2]s)
}
`, i, offset)
}
} }
type Shader struct { type Shader struct {