Added textures to backend

This commit is contained in:
Sasha Koshka 2023-08-21 00:35:55 -04:00
parent 3cffcfd4e5
commit fae918a196

43
texture.go Normal file
View File

@ -0,0 +1,43 @@
package x
import "image"
import "git.tebibyte.media/tomo/tomo"
type texture struct {
pix []uint8
stride int
rect image.Rectangle
}
func (backend *Backend) NewTexture (source image.Image) tomo.Texture {
bounds := source.Bounds()
texture := &texture {
pix: make([]uint8, bounds.Dx() * bounds.Dy() * 4),
stride: bounds.Dx(),
rect: bounds.Sub(bounds.Min),
}
index := 0
var point image.Point
for point.Y = bounds.Min.Y; point.Y < bounds.Max.Y; point.Y ++ {
for point.X = bounds.Min.X; point.X < bounds.Max.X; point.X ++ {
r, g, b, a := source.At(point.X, point.Y).RGBA()
texture.pix[index + 0] = uint8(b >> 8)
texture.pix[index + 1] = uint8(g >> 8)
texture.pix[index + 2] = uint8(r >> 8)
texture.pix[index + 3] = uint8(a >> 8)
index += 4
}}
return texture
}
func (this *texture) Clip (bounds image.Rectangle) tomo.Texture {
clipped := *this
clipped.rect = bounds
return &clipped
}
func (this *texture) Close () error {
return nil
}