mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
TextureLoadOptions+fix DT bug+remove SetAttribute
This commit is contained in:
@ -24,10 +24,22 @@ type Texture struct {
|
||||
Pixels []byte
|
||||
}
|
||||
|
||||
func LoadPNGTexture(file string) (Texture, error) {
|
||||
type TextureLoadOptions struct {
|
||||
TryLoadFromCache bool
|
||||
WriteToCache bool
|
||||
GenMipMaps bool
|
||||
}
|
||||
|
||||
if tex, ok := GetTexturePath(file); ok {
|
||||
return tex, nil
|
||||
func LoadPNGTexture(file string, loadOptions *TextureLoadOptions) (Texture, error) {
|
||||
|
||||
if loadOptions == nil {
|
||||
loadOptions = &TextureLoadOptions{}
|
||||
}
|
||||
|
||||
if loadOptions.TryLoadFromCache {
|
||||
if tex, ok := GetTextureFromCachePath(file); ok {
|
||||
return tex, nil
|
||||
}
|
||||
}
|
||||
|
||||
//Load from disk
|
||||
@ -72,14 +84,19 @@ func LoadPNGTexture(file string) (Texture, error) {
|
||||
// set the texture wrapping/filtering options (on the currently bound texture object)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
||||
|
||||
// load and generate the texture
|
||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, tex.Width, tex.Height, 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tex.Pixels[0]))
|
||||
gl.GenerateMipmap(gl.TEXTURE_2D)
|
||||
|
||||
SetTexture(tex)
|
||||
if loadOptions.GenMipMaps {
|
||||
gl.GenerateMipmap(tex.TexID)
|
||||
}
|
||||
|
||||
if loadOptions.WriteToCache {
|
||||
AddTextureToCache(tex)
|
||||
}
|
||||
|
||||
return tex, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user