local COLOR_INDEX = 3
local mesh = love.graphics.newMesh(3)
mesh:setVertexAttribute(1, COLOR_INDEX, 0.1, 0.2, 0.3, 0.4)
print(mesh:getVertexAttribute(1, COLOR_INDEX))
getVertexAttribute does not return the values that were originally passed to setVertexAttribute. This is because each color component of a vertex is represented by a single byte internally. So setVertexAttribute crams the floating point values into a 0..255 value range and getVertexAttribute converts them back into floating point numbers, leading to some loss in precision.
But this can't be fixed by cindy or any other library. I consider it a small flaw in how this specific part of the API was designed.
BurrickSlayer wrote: ↑Wed Nov 22, 2023 7:01 pm
getVertexAttribute does not return the values that were originally passed to setVertexAttribute. This is because each color component of a vertex is represented by a single byte internally.
The data type of color components (and any vertex attribute component) isn't fixed like that. You can make a mesh that uses any supported data type for its vertex attributes, for example 16 bit instead of 8 bit fixed-point values for colors.
Ahh, thanks, I knew I had missed something! Actually I forgot about this newMesh overload where you can specify a custom vertex format.
In my case it would be probably somewhat overkill to define the color components as float, only for the sake of having setters and getters that behave symmetrically. I have settled with "normalizing" the input colors (Math.floor(red * 255) / 255 etc.), so I can compare them with the output colors. But it's good to be reminded of this newMesh overload again.