graphicscommand: Adjust regions for secondory and following images correctly

This commit is contained in:
Hajime Hoshi 2020-05-30 15:44:59 +09:00
parent 915aecb960
commit b2eee7ee8a
2 changed files with 27 additions and 11 deletions

View File

@ -418,13 +418,27 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error {
if c.shader != nil {
us := make([]interface{}, len(c.uniforms))
// TODO: Adjust the source sizes in uniform variables.
for k, v := range c.uniforms {
switch v := v.(type) {
firstImage := true
for i := 0; i < len(c.uniforms); i++ {
switch v := c.uniforms[i].(type) {
case *Image:
us[k] = v.image.ID()
us[i] = v.image.ID()
if !firstImage {
// Convert pixels to texels.
w, h := v.InternalSize()
i++
region := c.uniforms[i].([]float32)
us[i] = []float32{
region[0] / float32(w),
region[1] / float32(h),
region[2] / float32(w),
region[3] / float32(h),
}
}
firstImage = false
default:
us[k] = v
us[i] = v
}
}
return theGraphicsDriver.DrawShader(c.dst.image.ID(), c.shader.shader.ID(), c.nindices, indexOffset, c.mode, us)

View File

@ -324,16 +324,18 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
firstImage := true
us := make([]interface{}, len(uniforms))
for i := 0; i < len(uniforms); i++ {
switch v := us[i].(type) {
switch v := uniforms[i].(type) {
case *Image:
us[i] = v.backend.restorable
if !firstImage {
i++
region := us[i].([]float32)
region[0] += oxf
region[1] += oyf
region[2] += oxf
region[3] += oyf
region := uniforms[i].([]float32)
us[i] = []float32{
region[0] + oxf,
region[1] + oyf,
region[2] + oxf,
region[3] + oyf,
}
}
firstImage = false
default: