mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphicscommand: Remove the source-region parts from the uniform variables
This commit is contained in:
parent
780465b702
commit
1fe2f47701
30
image.go
30
image.go
@ -367,7 +367,6 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
|
||||
mode := driver.CompositeMode(options.CompositeMode)
|
||||
|
||||
us := []interface{}{}
|
||||
var firstImage *Image
|
||||
for _, v := range options.Uniforms {
|
||||
switch v := v.(type) {
|
||||
case *Image:
|
||||
@ -375,17 +374,6 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
|
||||
panic("ebiten: the given image to DrawTriangles must not be disposed")
|
||||
}
|
||||
us = append(us, v.buffered)
|
||||
if firstImage == nil {
|
||||
firstImage = v
|
||||
} else {
|
||||
b := v.Bounds()
|
||||
us = append(us, []float32{
|
||||
float32(b.Min.X),
|
||||
float32(b.Min.Y),
|
||||
float32(b.Max.X),
|
||||
float32(b.Max.Y),
|
||||
})
|
||||
}
|
||||
default:
|
||||
us = append(us, v)
|
||||
}
|
||||
@ -395,25 +383,17 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
|
||||
// The actual value is set at graphicscommand package.
|
||||
us = append([]interface{}{[]float32{0, 0}}, us...)
|
||||
|
||||
var bx0, by0, bx1, by1 float32
|
||||
if firstImage != nil {
|
||||
b := firstImage.Bounds()
|
||||
bx0 = float32(b.Min.X)
|
||||
by0 = float32(b.Min.Y)
|
||||
bx1 = float32(b.Max.X)
|
||||
by1 = float32(b.Max.Y)
|
||||
}
|
||||
|
||||
vs := make([]float32, len(vertices)*graphics.VertexFloatNum)
|
||||
for i, v := range vertices {
|
||||
vs[i*graphics.VertexFloatNum] = v.DstX
|
||||
vs[i*graphics.VertexFloatNum+1] = v.DstY
|
||||
vs[i*graphics.VertexFloatNum+2] = v.SrcX
|
||||
vs[i*graphics.VertexFloatNum+3] = v.SrcY
|
||||
vs[i*graphics.VertexFloatNum+4] = bx0
|
||||
vs[i*graphics.VertexFloatNum+5] = by0
|
||||
vs[i*graphics.VertexFloatNum+6] = bx1
|
||||
vs[i*graphics.VertexFloatNum+7] = by1
|
||||
// TODO: Remove these values for the source region.
|
||||
vs[i*graphics.VertexFloatNum+4] = 0
|
||||
vs[i*graphics.VertexFloatNum+5] = 0
|
||||
vs[i*graphics.VertexFloatNum+6] = 0
|
||||
vs[i*graphics.VertexFloatNum+7] = 0
|
||||
vs[i*graphics.VertexFloatNum+8] = v.ColorR
|
||||
vs[i*graphics.VertexFloatNum+9] = v.ColorG
|
||||
vs[i*graphics.VertexFloatNum+10] = v.ColorB
|
||||
|
@ -410,28 +410,10 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error {
|
||||
if c.shader != nil {
|
||||
us := make([]interface{}, len(c.uniforms))
|
||||
|
||||
firstImage := true
|
||||
for i := 0; i < len(c.uniforms); i++ {
|
||||
switch v := c.uniforms[i].(type) {
|
||||
case *Image:
|
||||
us[i] = v.image.ID()
|
||||
if firstImage {
|
||||
firstImage = false
|
||||
continue
|
||||
}
|
||||
|
||||
// Convert pixels to texels.
|
||||
w, h := v.InternalSize()
|
||||
i++
|
||||
region := c.uniforms[i].([]float32)
|
||||
vs := []float32{
|
||||
region[0] / float32(w),
|
||||
region[1] / float32(h),
|
||||
region[2] / float32(w),
|
||||
region[3] / float32(h),
|
||||
}
|
||||
|
||||
us[i] = vs
|
||||
default:
|
||||
us[i] = v
|
||||
}
|
||||
|
@ -116,9 +116,7 @@ func TestShaderMultipleSources(t *testing.T) {
|
||||
[]float32{0, 0},
|
||||
srcs[0],
|
||||
srcs[1],
|
||||
[]float32{0, 0, 1, 1},
|
||||
srcs[2],
|
||||
[]float32{0, 0, 1, 1},
|
||||
}
|
||||
dst.DrawTriangles(nil, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, s, us)
|
||||
|
||||
|
@ -357,23 +357,11 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
|
||||
s = shader.shader
|
||||
}
|
||||
|
||||
firstImage := true
|
||||
us := make([]interface{}, len(uniforms))
|
||||
for i := 0; i < len(uniforms); i++ {
|
||||
switch v := uniforms[i].(type) {
|
||||
case *Image:
|
||||
us[i] = v.backend.restorable
|
||||
if !firstImage {
|
||||
i++
|
||||
region := uniforms[i].([]float32)
|
||||
us[i] = []float32{
|
||||
region[0] + oxf,
|
||||
region[1] + oyf,
|
||||
region[2] + oxf,
|
||||
region[3] + oyf,
|
||||
}
|
||||
}
|
||||
firstImage = false
|
||||
default:
|
||||
us[i] = v
|
||||
}
|
||||
|
@ -289,9 +289,7 @@ func ShaderProgramFill(r, g, b, a byte) shaderir.Program {
|
||||
// Uniform variables's indices and their values are:
|
||||
//
|
||||
// 0: the framebuffer size (Vec2)
|
||||
// 1: the first images (Texture2D)
|
||||
// 2n: the n-th image (Texture2D)
|
||||
// 2n+1: the n-th image's region (Vec4)
|
||||
// 1-: the images (Texture2D)
|
||||
//
|
||||
// The first image's size and region are represented in attribute variables.
|
||||
//
|
||||
@ -363,7 +361,7 @@ func ShaderProgramImages(imageNum int) shaderir.Program {
|
||||
},
|
||||
{
|
||||
Type: shaderir.UniformVariable,
|
||||
Index: 2 * i,
|
||||
Index: i + 1,
|
||||
},
|
||||
texPos,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user