When using numpy arrays or glm this is extremely useful
The problem is very apparent when using glm since a glm matrix. We can convert it into a list or tuple but this creates a tuple/list for each column in the matrix. Just cut all that complexity and use buffer protocol.
# Set identity matrix
program["some_matrix"] = glm.mat4()
The current uniform setters are function based. It might be cleaner to just expose a Uniform object instead that can also be inspected.
# Setting python value directly
program["member"].value = value
# Supporting explicit buffer protocol write
program["member"].write(data)
# Progam can have __setitem__ like before that will forward the value to the right member
program["something"] = value
There's just more you can do when returning an instance. We can still do some hidden function magic in the background to optimize how different uniforms types are written.
It also means the user can query other useful information
# Get the slot the uniform is assigned to
program["my_uniform"].location
# Get the array length
program["my_uniform"].length
# Get the value of the uniform
program["my_uniform"].value
It can also query for the internal uniform type and other lower level things useful for debugging.
When using numpy arrays or glm this is extremely useful
The problem is very apparent when using glm since a glm matrix. We can convert it into a list or tuple but this creates a tuple/list for each column in the matrix. Just cut all that complexity and use buffer protocol.
The current uniform setters are function based. It might be cleaner to just expose a
Uniform
object instead that can also be inspected.There's just more you can do when returning an instance. We can still do some hidden function magic in the background to optimize how different uniforms types are written.
It also means the user can query other useful information
It can also query for the internal uniform type and other lower level things useful for debugging.