]> git.sesse.net Git - movit/commitdiff
Check required extensions at start.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 28 Oct 2012 17:48:25 +0000 (18:48 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 28 Oct 2012 17:48:25 +0000 (18:48 +0100)
flat_input.h
init.cpp
init.h

index cf6b0b9264d878b0e90378c00d61cb5369fec741..8b5a3ce4c07d004368063634014b9c88087cd3fc 100644 (file)
@@ -2,6 +2,7 @@
 #define _FLAT_INPUT_H 1
 
 #include "input.h"
+#include "init.h"
 
 // A FlatInput is the normal, “classic” case of an input, where everything
 // comes from a single 2D array with chunky pixels.
@@ -17,9 +18,9 @@ public:
        // mipmap generation) at that point.
        void finalize();
 
-       // TODO: Check that we actually have the required extension.
        virtual bool can_output_linear_gamma() const {
-               return (type == GL_UNSIGNED_BYTE &&
+               return (movit_srgb_textures_supported &&
+                       type == GL_UNSIGNED_BYTE &&
                        (image_format.gamma_curve == GAMMA_LINEAR ||
                         image_format.gamma_curve == GAMMA_sRGB));
        }
index 129ee4c894d91ea3d5072b35a9812338981707fc..ac52aa2ce3d7eee956e6cc629912e699bb6553b1 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -2,8 +2,12 @@
 #include "opengl.h"
 #include "util.h"
 
+#include <set>
+#include <string>
+
 bool movit_initialized = false;
 float movit_texel_subpixel_precision;
+bool movit_srgb_textures_supported;
 
 namespace {
 
@@ -119,6 +123,43 @@ void measure_texel_subpixel_precision()
        check_error();
 }
 
+void get_extensions(std::set<std::string> *extensions)
+{
+       char *str = strdup(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
+       for (char *ptr = strtok(str, " "); ptr != NULL; ptr = strtok(NULL, " ")) {
+               extensions->insert(ptr);
+       }
+       free(str);
+}
+
+void check_extensions()
+{
+       std::set<std::string> extensions;
+       get_extensions(&extensions);
+
+       // We fundamentally need FBOs and floating-point textures.
+       assert(extensions.count("GL_ARB_framebuffer_object") != 0);
+       assert(extensions.count("GL_ARB_texture_float") != 0);
+
+       // We assume that we can use non-power-of-two textures without restrictions.
+       assert(extensions.count("GL_ARB_texture_non_power_of_two") != 0);
+
+       // We also need GLSL fragment shaders.
+       assert(extensions.count("GL_ARB_fragment_shader") != 0);
+       assert(extensions.count("GL_ARB_shading_language_100") != 0);
+
+       // FlatInput and YCbCrInput uses PBOs. (They could in theory do without,
+       // but no modern card would really not provide it.)
+       assert(extensions.count("GL_ARB_pixel_buffer_object") != 0);
+
+       // ResampleEffect uses RG textures to encode a two-component LUT.
+       assert(extensions.count("GL_ARB_texture_rg") != 0);
+
+       // sRGB texture decode would be nice, but are not mandatory
+       // (GammaExpansionEffect can do the same thing if needed).
+       movit_srgb_textures_supported = extensions.count("GL_EXT_texture_sRGB");
+}
+
 }  // namespace
 
 void init_movit()
@@ -132,6 +173,7 @@ void init_movit()
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
        measure_texel_subpixel_precision();
+       check_extensions();
 
        movit_initialized = true;
 }
diff --git a/init.h b/init.h
index e0dbe63688fff77225e45e4a162b2ad7cf1003df..a1e71dd54053b3f168f3c47267eba1512bd2096b 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2,8 +2,8 @@
 #define _INIT_H
 
 // Initialize the library; in particular, will query the GPU for information
-// that is needed by various components. (In time, for instance, we will query
-// about extensions here.)
+// that is needed by various components. For instance, it verifies that
+// we have all the OpenGL extensions we need.
 void init_movit();
 
 // GPU features. These are not intended for end-user use.
@@ -18,4 +18,7 @@ extern bool movit_initialized;
 // We currently don't bother to test above 2^10.
 extern float movit_texel_subpixel_precision;
 
+// Whether the GPU in use supports GL_EXT_texture_sRGB.
+extern bool movit_srgb_textures_supported;
+
 #endif  // !defined(_INIT_H)