6 bool movit_initialized = false;
7 float movit_texel_subpixel_precision;
8 bool movit_srgb_textures_supported;
12 void measure_texel_subpixel_precision()
14 static const unsigned width = 1024;
16 // Generate a destination texture to render to, and an FBO.
17 GLuint dst_texnum, fbo;
19 glGenTextures(1, &dst_texnum);
21 glBindTexture(GL_TEXTURE_2D, dst_texnum);
23 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
26 glGenFramebuffers(1, &fbo);
28 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
30 glFramebufferTexture2D(
38 // Now generate a simple texture that's just [0,1].
40 float texdata[] = { 0, 1 };
41 glGenTextures(1, &dst_texnum);
43 glBindTexture(GL_TEXTURE_1D, dst_texnum);
45 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
47 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
49 glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE16F_ARB, 2, 0, GL_LUMINANCE, GL_FLOAT, texdata);
51 glEnable(GL_TEXTURE_1D);
57 glDisable(GL_DEPTH_TEST);
59 glDepthMask(GL_FALSE);
62 glViewport(0, 0, width, 1);
64 glMatrixMode(GL_PROJECTION);
66 glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
68 glMatrixMode(GL_MODELVIEW);
72 // Draw the texture stretched over a long quad, interpolating it out.
73 // Note that since the texel center is in (0.5), we need to adjust the
74 // texture coordinates in order not to get long stretches of (1,1,1,...)
75 // at the start and (...,0,0,0) at the end.
79 glVertex2f(0.0f, 0.0f);
82 glVertex2f(1.0f, 0.0f);
85 glVertex2f(1.0f, 1.0f);
88 glVertex2f(0.0f, 1.0f);
93 glDisable(GL_TEXTURE_1D);
96 // Now read the data back and see what the card did.
97 // (We only look at the red channel; the others will surely be the same.)
98 // We assume a linear ramp; anything else will give sort of odd results here.
99 float out_data[width];
100 glReadPixels(0, 0, width, 1, GL_RED, GL_FLOAT, out_data);
103 float biggest_jump = 0.0f;
104 for (unsigned i = 1; i < width; ++i) {
105 assert(out_data[i] >= out_data[i - 1]);
106 biggest_jump = std::max(biggest_jump, out_data[i] - out_data[i - 1]);
109 movit_texel_subpixel_precision = biggest_jump;
112 glBindTexture(GL_TEXTURE_1D, 0);
114 glBindFramebuffer(GL_FRAMEBUFFER, 0);
116 glDeleteFramebuffers(1, &fbo);
118 glDeleteTextures(1, &dst_texnum);
120 glDeleteTextures(1, &src_texnum);
124 void check_extensions()
126 // We fundamentally need FBOs and floating-point textures.
127 assert(glewIsSupported("GL_ARB_framebuffer_object") != 0);
128 assert(glewIsSupported("GL_ARB_texture_float") != 0);
130 // We assume that we can use non-power-of-two textures without restrictions.
131 assert(glewIsSupported("GL_ARB_texture_non_power_of_two") != 0);
133 // We also need GLSL fragment shaders.
134 assert(glewIsSupported("GL_ARB_fragment_shader") != 0);
135 assert(glewIsSupported("GL_ARB_shading_language_100") != 0);
137 // FlatInput and YCbCrInput uses PBOs. (They could in theory do without,
138 // but no modern card would really not provide it.)
139 assert(glewIsSupported("GL_ARB_pixel_buffer_object") != 0);
141 // ResampleEffect uses RG textures to encode a two-component LUT.
142 assert(glewIsSupported("GL_ARB_texture_rg") != 0);
144 // sRGB texture decode would be nice, but are not mandatory
145 // (GammaExpansionEffect can do the same thing if needed).
146 movit_srgb_textures_supported = glewIsSupported("GL_EXT_texture_sRGB");
153 if (movit_initialized) {
160 glPixelStorei(GL_PACK_ALIGNMENT, 1);
161 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
163 measure_texel_subpixel_precision();
166 movit_initialized = true;