ebiten icon indicating copy to clipboard operation
ebiten copied to clipboard

ebiten: introduce a new data structure for uniform variables instead of a map

Open hajimehoshi opened this issue 2 years ago • 6 comments

  • 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?

hajimehoshi avatar Apr 02 '22 19:04 hajimehoshi

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.

divVerent avatar Apr 04 '22 02:04 divVerent

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 :-)

hajimehoshi avatar Apr 04 '22 04:04 hajimehoshi

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.

tinne26 avatar Apr 25 '22 17:04 tinne26

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 :-)

hajimehoshi avatar Aug 29 '23 15:08 hajimehoshi

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)).

tinne26 avatar Aug 29 '23 20:08 tinne26

Yeah, set would be better

hajimehoshi avatar Aug 30 '23 02:08 hajimehoshi