pgraph: fix precision issues with Color(Scale)Attrib quantization

This commit is contained in:
rdb 2018-09-28 13:19:36 +02:00
parent c43d9b5002
commit fac82e6dca
2 changed files with 10 additions and 10 deletions

View File

@ -133,17 +133,17 @@ get_hash_impl() const {
}
/**
* Quantizes the color color to the nearest multiple of 1000, just to prevent
* Quantizes the flat color to the nearest multiple of 1024, just to prevent
* runaway accumulation of only slightly-different ColorAttribs.
*/
void ColorAttrib::
quantize_color() {
switch (_type) {
case T_flat:
_color[0] = cfloor(_color[0] * 1000.0f + 0.5f) * 0.001f;
_color[1] = cfloor(_color[1] * 1000.0f + 0.5f) * 0.001f;
_color[2] = cfloor(_color[2] * 1000.0f + 0.5f) * 0.001f;
_color[3] = cfloor(_color[3] * 1000.0f + 0.5f) * 0.001f;
_color[0] = cfloor(_color[0] * 1024.0f + 0.5f) / 1024.0f;
_color[1] = cfloor(_color[1] * 1024.0f + 0.5f) / 1024.0f;
_color[2] = cfloor(_color[2] * 1024.0f + 0.5f) / 1024.0f;
_color[3] = cfloor(_color[3] * 1024.0f + 0.5f) / 1024.0f;
break;
case T_off:

View File

@ -230,15 +230,15 @@ invert_compose_impl(const RenderAttrib *other) const {
}
/**
* Quantizes the color scale to the nearest multiple of 1000, just to prevent
* Quantizes the color scale to the nearest multiple of 1024, just to prevent
* runaway accumulation of only slightly-different ColorScaleAttribs.
*/
void ColorScaleAttrib::
quantize_scale() {
_scale[0] = cfloor(_scale[0] * 1000.0f + 0.5f) * 0.001f;
_scale[1] = cfloor(_scale[1] * 1000.0f + 0.5f) * 0.001f;
_scale[2] = cfloor(_scale[2] * 1000.0f + 0.5f) * 0.001f;
_scale[3] = cfloor(_scale[3] * 1000.0f + 0.5f) * 0.001f;
_scale[0] = cfloor(_scale[0] * 1024.0f + 0.5f) / 1024.0f;
_scale[1] = cfloor(_scale[1] * 1024.0f + 0.5f) / 1024.0f;
_scale[2] = cfloor(_scale[2] * 1024.0f + 0.5f) / 1024.0f;
_scale[3] = cfloor(_scale[3] * 1024.0f + 0.5f) / 1024.0f;
}
/**