51 lines
830 B
Go
51 lines
830 B
Go
|
|
package shader
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
|
||
|
|
"zworld/assets"
|
||
|
|
"zworld/engine/renderapi/texture"
|
||
|
|
"zworld/engine/renderapi/types"
|
||
|
|
)
|
||
|
|
|
||
|
|
type InputDetails struct {
|
||
|
|
Index int
|
||
|
|
Type string
|
||
|
|
}
|
||
|
|
|
||
|
|
type Details struct {
|
||
|
|
Inputs map[string]InputDetails
|
||
|
|
Bindings map[string]int
|
||
|
|
Textures []texture.Slot
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d *Details) ParseInputs() (Inputs, error) {
|
||
|
|
inputs := Inputs{}
|
||
|
|
for name, input := range d.Inputs {
|
||
|
|
kind, err := types.TypeFromString(input.Type)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
inputs[name] = Input{
|
||
|
|
Index: input.Index,
|
||
|
|
Type: kind,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return inputs, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func ReadDetails(path string) (*Details, error) {
|
||
|
|
data, err := assets.ReadAll(path)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
details := &Details{}
|
||
|
|
err = json.Unmarshal(data, details)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return details, nil
|
||
|
|
}
|