c - What does the constant 0.0039215689 represent? -
i keep seeing constant pop in various graphics header files
0.0039215689 it seems have color maybe?
here first hit on google:
void rdp_g_setfogcolor(void) { gfx.fogcolor.r = _shiftr(w1, 24, 8) * 0.0039215689f; gfx.fogcolor.g = _shiftr(w1, 16, 8) * 0.0039215689f; gfx.fogcolor.b = _shiftr(w1, 8, 8) * 0.0039215689f; gfx.fogcolor.a = _shiftr(w1, 0, 8) * 0.0039215689f; } void rdp_g_setblendcolor(void) { gfx.blendcolor.r = _shiftr(w1, 24, 8) * 0.0039215689f; gfx.blendcolor.g = _shiftr(w1, 16, 8) * 0.0039215689f; gfx.blendcolor.b = _shiftr(w1, 8, 8) * 0.0039215689f; gfx.blendcolor.a = _shiftr(w1, 0, 8) * 0.0039215689f; if(opengl.ext_fragmentprogram && (system.options & brdp_combiner)) { glprogramenvparameter4farb(gl_fragment_program_arb, 2, gfx.blendcolor.r, gfx.blendcolor.g, gfx.blendcolor.b, gfx.blendcolor.a); } } //...more what number represent? why no 1 seem declare const?
i couldn't find on google explained it.
0.0039215689 approximately equal 1/255.
seeing opengl, performance important. it's safe guess done performance reasons.
multiplying reciprocal faster repeatedly dividing 255.
side note:
if you're wondering why such micro-optimization isn't left compiler, it's because unsafe floating-point optimization. in other words:
x / 255 != x * (1. / 255) due floating-point round-off errors.
so while modern compilers may smart enough optimization, not allowed unless explicitly tell them via compiler flag.
related: why doesn't gcc optimize a*a*a*a*a*a (a*a*a)*(a*a*a)?
Comments
Post a Comment