mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/shaderir: rename the built-in func to get a texel to __texelAt
This commit is contained in:
parent
49582519c1
commit
9d2178cf71
@ -91,14 +91,14 @@ func imageSrcRegionOnTexture() (vec2, vec2) {
|
||||
shaderSuffix += fmt.Sprintf(`
|
||||
func imageSrc%[1]dUnsafeAt(pos vec2) vec4 {
|
||||
// pos is the position in positions of the source texture (= 0th image's texture).
|
||||
return texture2D(__t%[1]d, %[2]s)
|
||||
return __texelAt(__t%[1]d, %[2]s)
|
||||
}
|
||||
|
||||
func imageSrc%[1]dAt(pos vec2) vec4 {
|
||||
// pos is the position of the source texture (= 0th image's texture).
|
||||
// If pos is in the region, the result is (1, 1). Otherwise, either element is 0.
|
||||
in := step(__textureSourceRegionOrigin, pos) - step(__textureSourceRegionOrigin + __textureSourceRegionSize, pos)
|
||||
return texture2D(__t%[1]d, %[2]s) * in.x * in.y
|
||||
return __texelAt(__t%[1]d, %[2]s) * in.x * in.y
|
||||
}
|
||||
`, i, pos)
|
||||
}
|
||||
|
@ -602,7 +602,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
t = shaderir.Type{Main: shaderir.Mat4}
|
||||
case shaderir.Texture2DF:
|
||||
case shaderir.TexelAt:
|
||||
if len(args) != 2 {
|
||||
cs.addError(e.Pos(), fmt.Sprintf("number of %s's arguments must be 2 but %d", callee.BuiltinFunc, len(args)))
|
||||
return nil, nil, nil, false
|
||||
|
@ -121,7 +121,7 @@ func (c *compileContext) builtinFuncString(f shaderir.BuiltinFunc) string {
|
||||
return "dFdx"
|
||||
case shaderir.Dfdy:
|
||||
return "dFdy"
|
||||
case shaderir.Texture2DF:
|
||||
case shaderir.TexelAt:
|
||||
if c.unit == shaderir.Pixel {
|
||||
return "texelFetch"
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
||||
if len(args) == 1 {
|
||||
return fmt.Sprintf("float4x4FromScalar(%s)", args[0])
|
||||
}
|
||||
case shaderir.Texture2DF:
|
||||
case shaderir.TexelAt:
|
||||
switch c.unit {
|
||||
case shaderir.Pixel:
|
||||
return fmt.Sprintf("%s.Load(int3(%s, 0))", args[0], strings.Join(args[1:], ", "))
|
||||
|
@ -143,8 +143,8 @@ func (c *compileContext) builtinFuncString(f shaderir.BuiltinFunc) string {
|
||||
return "ddx"
|
||||
case shaderir.Dfdy:
|
||||
return "ddy"
|
||||
case shaderir.Texture2DF:
|
||||
return "?(texture2D)"
|
||||
case shaderir.TexelAt:
|
||||
return "?(__texelAt)"
|
||||
default:
|
||||
return string(f)
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
|
||||
for _, exp := range e.Exprs[1:] {
|
||||
args = append(args, expr(&exp))
|
||||
}
|
||||
if callee.Type == shaderir.BuiltinFuncExpr && callee.BuiltinFunc == shaderir.Texture2DF {
|
||||
if callee.Type == shaderir.BuiltinFuncExpr && callee.BuiltinFunc == shaderir.TexelAt {
|
||||
switch p.Unit {
|
||||
case shaderir.Texel:
|
||||
return fmt.Sprintf("%s.sample(texture_sampler, %s)", args[0], strings.Join(args[1:], ", "))
|
||||
|
@ -149,8 +149,8 @@ func builtinFuncString(f shaderir.BuiltinFunc) string {
|
||||
return "float4x4"
|
||||
case shaderir.Inversesqrt:
|
||||
return "rsqrt"
|
||||
case shaderir.Texture2DF:
|
||||
return "?(texture2D)"
|
||||
case shaderir.TexelAt:
|
||||
return "?(__texelAt)"
|
||||
}
|
||||
return string(f)
|
||||
}
|
||||
|
@ -276,11 +276,11 @@ const (
|
||||
Reflect BuiltinFunc = "reflect"
|
||||
Refract BuiltinFunc = "refract"
|
||||
Transpose BuiltinFunc = "transpose"
|
||||
Texture2DF BuiltinFunc = "texture2D"
|
||||
Dfdx BuiltinFunc = "dfdx"
|
||||
Dfdy BuiltinFunc = "dfdy"
|
||||
Fwidth BuiltinFunc = "fwidth"
|
||||
DiscardF BuiltinFunc = "discard"
|
||||
TexelAt BuiltinFunc = "__texelAt"
|
||||
)
|
||||
|
||||
func ParseBuiltinFunc(str string) (BuiltinFunc, bool) {
|
||||
@ -334,11 +334,11 @@ func ParseBuiltinFunc(str string) (BuiltinFunc, bool) {
|
||||
Reflect,
|
||||
Refract,
|
||||
Transpose,
|
||||
Texture2DF,
|
||||
Dfdx,
|
||||
Dfdy,
|
||||
Fwidth,
|
||||
DiscardF:
|
||||
DiscardF,
|
||||
TexelAt:
|
||||
return BuiltinFunc(str), true
|
||||
}
|
||||
return "", false
|
||||
|
Loading…
Reference in New Issue
Block a user