log2(1.0f / movit_texel_subpixel_precision));
printf("Wrongly rounded x+0.48 or x+0.52 values: %d/510\n",
movit_num_wrongly_rounded);
+ if (movit_num_wrongly_rounded > 0) {
+ if (movit_shader_rounding_supported) {
+ printf("Rounding off in the shader to compensate.\n");
+ } else {
+ printf("No shader roundoff available; cannot compensate.\n");
+ }
+ }
unsigned img_w, img_h;
unsigned char *src_img = load_image(argc > 1 ? argv[1] : "blg_wheels_woman_1.jpg", &img_w, &img_h);
string DitherEffect::output_fragment_shader()
{
char buf[256];
- sprintf(buf, "#define NEED_EXPLICIT_ROUND %d\n", (movit_num_wrongly_rounded > 0));
+ sprintf(buf, "#define NEED_EXPLICIT_ROUND %d\n", (movit_num_wrongly_rounded > 0 && movit_shader_rounding_supported));
return buf + read_file("dither_effect.frag");
}
+#ifdef GL_EXT_gpu_shader4
+// We sometimes want round().
+#extension GL_EXT_gpu_shader4 : enable
+#endif
+
varying vec2 tc;
float movit_texel_subpixel_precision;
bool movit_srgb_textures_supported;
int movit_num_wrongly_rounded;
+bool movit_shader_rounding_supported;
// The rules for objects with nontrivial constructors in static scope
// are somewhat convoluted, and easy to mess up. We simply have a
// sRGB texture decode would be nice, but are not mandatory
// (GammaExpansionEffect can do the same thing if needed).
movit_srgb_textures_supported = glewIsSupported("GL_EXT_texture_sRGB");
+
+ // We may want to use round() at the end of the final shader,
+ // if supported. We need either GLSL 1.30 or this extension to do that,
+ // and 1.30 brings with it other things that we don't want to demand
+ // for now.
+ movit_shader_rounding_supported = glewIsSupported("GL_EXT_gpu_shader4");
}
} // namespace
// round the right way (giving some leeway, but not a lot); the number
// of errors are stored here.
//
-// If this value is above 0, and you have enabled dithering, we will
-// round off explicitly at the very end of the shader.
+// If this value is above 0, the extension GL_EXT_gpu_shader4 is available
+// (giving round()) and you have enabled dithering, we will round off
+// explicitly at the very end of the shader.
+//
+// Note: I don't know of any cards that round off wrong (well, outside
+// our tolerance) and do not have this extension.
extern int movit_num_wrongly_rounded;
+extern bool movit_shader_rounding_supported;
// Whether the GPU in use supports GL_EXT_texture_sRGB.
extern bool movit_srgb_textures_supported;