func CreateRGBTexture(w, h int) *Texture {
	return &Texture{
		w:    w,
		h:    h,
		data: make([]byte, w*h*3),
	}
}
CreateRGBTexture creates an RGB texture of appropriate size.
package texture
import (
	"bytes"
	"github.com/blezek/tga"
	"github.com/jamiec7919/vermeer/core"
	m "github.com/jamiec7919/vermeer/math"
	_ "golang.org/x/image/tiff"  
	"image"
	_ "image/jpeg"  
	_ "image/png"   
	"io"
	"log"
	"os"
	"path/filepath"
	"sync"
	"sync/atomic"
)
const embeddedTexture = "data/checker.png"
type Texture struct {
	url    string
	fmt    int
	w, h   int
	data   []byte
	mipmap mipmap
}
type TexStore map[string]*Texture
var texStore atomic.Value
var loadMutex sync.Mutex
var testTexture *Texture
func init() {
	data, err := Asset(embeddedTexture)
	if err != nil {
		log.Printf("Failed to load embedded fallback texture: %v", err)
		tmp := CreateRGBTexture(2, 2)
		tmp.url = "test"
		tmp.SetRGB(0, 0, 2, 2, 2)
		tmp.SetRGB(1, 0, 250, 150, 250)
		tmp.SetRGB(0, 1, 250, 150, 250)
		tmp.SetRGB(1, 1, 2, 2, 2)
		mipmap := stdfilter(tmp.w, tmp.h, tmp.data, 3)
		tmp.mipmap = mipmap
		testTexture = tmp
	} else {
		t, err := loadTexture(embeddedTexture, bytes.NewReader(data))
		testTexture = t
		if err != nil {
			log.Printf("Failed to load embedded fallback texture: %v", err)
		}
	}
	texStore.Store(make(TexStore))
}
func LoadTexture(url string) (*Texture, error) {
	file, err := os.Open(url)
	if err != nil {
		return testTexture, err
	}
	defer file.Close()
	return loadTexture(url, file)
}
func loadTexture(url string, file io.Reader) (*Texture, error) {
	var err error
	var m image.Image
	if filepath.Ext(url) == ".tga" || filepath.Ext(url) == ".TGA" {
		m, err = tga.Decode(file)
	} else {
		m, _, err = image.Decode(file)
	}
	if err != nil {
		return testTexture, err
	}
	t := CreateRGBTexture(m.Bounds().Max.X-m.Bounds().Min.X, m.Bounds().Max.Y-m.Bounds().Min.Y)
	t.url = url
	for j := m.Bounds().Min.Y; j < m.Bounds().Max.Y; j++ {
		for i := m.Bounds().Min.X; i < m.Bounds().Max.X; i++ {
			r, g, b, _ := m.At(i, j).RGBA()
			t.SetRGB(i, m.Bounds().Max.Y-1-j, uint8(r>>8), uint8(g>>8), uint8(b>>8))
		}
	}
	mipmap := stdfilter(t.w, t.h, t.data, 3)
	t.mipmap = mipmap
	return t, nil
}
func (tex *Texture) SetRGB(x, y int, r, g, b byte) {
	tex.data[(x+(y*tex.w))*3+0] = r
	tex.data[(x+(y*tex.w))*3+1] = g
	tex.data[(x+(y*tex.w))*3+2] = b
}