68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package assetmanager
|
|
|
|
import (
|
|
"errors"
|
|
"reflect"
|
|
|
|
"git.tek.govt.hu/dowerx/opengl-deferred/types/geometry"
|
|
"git.tek.govt.hu/dowerx/opengl-deferred/types/shader"
|
|
"git.tek.govt.hu/dowerx/opengl-deferred/types/texture"
|
|
)
|
|
|
|
type AssetManager struct {
|
|
Geometries map[string]geometry.Geometry
|
|
Textures map[string]texture.Texture
|
|
Shadres map[string]shader.Shader
|
|
}
|
|
|
|
var instance *AssetManager
|
|
|
|
var (
|
|
geometryType = reflect.TypeOf(geometry.Geometry{})
|
|
textureType = reflect.TypeOf(texture.Texture{})
|
|
shaderType = reflect.TypeOf(shader.Shader{})
|
|
)
|
|
|
|
func Get() *AssetManager {
|
|
if instance != nil {
|
|
return &AssetManager{}
|
|
}
|
|
|
|
instance = &AssetManager{
|
|
Geometries: make(map[string]geometry.Geometry),
|
|
Textures: make(map[string]texture.Texture),
|
|
Shadres: make(map[string]shader.Shader),
|
|
}
|
|
|
|
return instance
|
|
}
|
|
|
|
func (m *AssetManager) Add(key string, item interface{}) error {
|
|
switch reflect.TypeOf(item) {
|
|
case geometryType:
|
|
m.Geometries[key] = item.(geometry.Geometry)
|
|
case textureType:
|
|
m.Textures[key] = item.(texture.Texture)
|
|
case shaderType:
|
|
m.Shadres[key] = item.(shader.Shader)
|
|
default:
|
|
return errors.New("unknown asset type")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *AssetManager) Delete() {
|
|
for _, g := range m.Geometries {
|
|
g.Delete()
|
|
}
|
|
|
|
for _, t := range m.Textures {
|
|
t.Delete()
|
|
}
|
|
|
|
for _, s := range m.Shadres {
|
|
s.Delete()
|
|
}
|
|
}
|