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