ebiten
ebiten copied to clipboard
ebiten: introduce a new data structure for uniform variables instead of a map
- A map might not be efficient. We might keep a map, but can wrap this as an internal data structure.
-
interface{}
is not efficient. What about[][4]byte
to represent a float, an int, and a bool?
If going with [][4]byte, please provide your own helpers to convert types to that.
Or rather, make it []ebiten.ShaderUniform, where ShaderUniform is a struct containing [4]byte and has constructor functions that generate one for a float, int or bool.
That way, these binary internals are hidden, but the same efficiency is provided.
Or rather, make it []ebiten.ShaderUniform, where ShaderUniform is a struct containing [4]byte and has constructor functions that generate one for a float, int or bool.
This is what I intended :-)
Minor point, I mentioned this on discord, but to keep it here: using uint32
directly and math.Float32bits
and math.Float32frombits
seems more appropriate that using [4]byte
. As far as I can tell, Golang APIs tend to prefer uint*
types to represent binary words if the data can fit in them.
This should be like
type Uniforms struct { /* ... */ }
func (u *Uniforms) AddInt(name string, value int)
func (u *Uniforms) AddVec2(name string, value [2]float32)
so that we could provide a type-safe API and hide the implementation. Let's wait for v3 anyway (probably 2027 or 2028 :-)
Wouldn't Uniforms.Set*()
be more accurate? And besides a Reset()
or similar, a single field clear may also be relevant (e.g. Uniforms.Unset/Delete(name string)
).
Yeah, set would be better