]> git.sesse.net Git - movit/commitdiff
Make init_movit() return a true/false error value.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 12 Feb 2014 00:44:42 +0000 (01:44 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 12 Feb 2014 00:44:42 +0000 (01:44 +0100)
This allows clients to programmatically enable/disable Movit usage
as needed on very old platforms.

demo.cpp
init.cpp
init.h
test_util.cpp

index 81d3e5091909e5cae8afe2b36fbd6b6addb3edb3..81bda2d60cf7de5659bcd4391e9bb1bc81e782f5 100644 (file)
--- a/demo.cpp
+++ b/demo.cpp
@@ -176,7 +176,7 @@ int main(int argc, char **argv)
        SDL_SetVideoMode(WIDTH, HEIGHT, 0, SDL_OPENGL);
        SDL_WM_SetCaption("OpenGL window", NULL);
 
-       init_movit(".", MOVIT_DEBUG_ON);
+       CHECK(init_movit(".", MOVIT_DEBUG_ON));
        printf("GPU texture subpixel precision: about %.1f bits\n",
                log2(1.0f / movit_texel_subpixel_precision));
        printf("Wrongly rounded x+0.48 or x+0.52 values: %d/510\n",
index d8d249f256203decf638fb92febea1f44e758bdc..fd22778f4ccec152cc973f2ebe1f6ffa51d1d935 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -251,25 +251,25 @@ void measure_roundoff_problems()
        check_error();
 }
 
-void check_extensions()
+bool check_extensions()
 {
        // We fundamentally need FBOs and floating-point textures.
-       assert(glewIsSupported("GL_ARB_framebuffer_object") != 0);
-       assert(glewIsSupported("GL_ARB_texture_float") != 0);
+       if (!glewIsSupported("GL_ARB_framebuffer_object")) return false;
+       if (!glewIsSupported("GL_ARB_texture_float")) return false;
 
        // We assume that we can use non-power-of-two textures without restrictions.
-       assert(glewIsSupported("GL_ARB_texture_non_power_of_two") != 0);
+       if (!glewIsSupported("GL_ARB_texture_non_power_of_two")) return false;
 
        // We also need GLSL fragment shaders.
-       assert(glewIsSupported("GL_ARB_fragment_shader") != 0);
-       assert(glewIsSupported("GL_ARB_shading_language_100") != 0);
+       if (!glewIsSupported("GL_ARB_fragment_shader")) return false;
+       if (!glewIsSupported("GL_ARB_shading_language_100")) return false;
 
        // FlatInput and YCbCrInput uses PBOs. (They could in theory do without,
        // but no modern card would really not provide it.)
-       assert(glewIsSupported("GL_ARB_pixel_buffer_object") != 0);
+       if (!glewIsSupported("GL_ARB_pixel_buffer_object")) return false;
 
        // ResampleEffect uses RG textures to encode a two-component LUT.
-       assert(glewIsSupported("GL_ARB_texture_rg") != 0);
+       if (!glewIsSupported("GL_ARB_texture_rg")) return false;
 
        // sRGB texture decode would be nice, but are not mandatory
        // (GammaExpansionEffect can do the same thing if needed).
@@ -280,29 +280,37 @@ void check_extensions()
        // 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");
+
+       return true;
 }
 
 }  // namespace
 
-void init_movit(const string& data_directory, MovitDebugLevel debug_level)
+bool init_movit(const string& data_directory, MovitDebugLevel debug_level)
 {
        if (movit_initialized) {
-               return;
+               return true;
        }
 
        movit_data_directory = new string(data_directory);
        movit_debug_level = debug_level;
 
-       glewInit();
+       GLenum err = glewInit();
+       if (err != GLEW_OK) {
+               return false;
+       }
 
        // geez 
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glDisable(GL_DITHER);
 
+       if (!check_extensions()) {
+               return false;
+       }
        measure_texel_subpixel_precision();
        measure_roundoff_problems();
-       check_extensions();
 
        movit_initialized = true;
+       return true;
 }
diff --git a/init.h b/init.h
index 398ddbe647e82b0fb832f26882dfb521ec91aaef..25869d17b1d266e5440bfedaeda8a79e0633ec4d 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1,6 +1,7 @@
 #ifndef _MOVIT_INIT_H
 #define _MOVIT_INIT_H
 
+#include "defs.h"
 #include <string>
 
 enum MovitDebugLevel {
@@ -10,7 +11,8 @@ enum MovitDebugLevel {
 
 // Initialize the library; in particular, will query the GPU for information
 // that is needed by various components. For instance, it verifies that
-// we have all the OpenGL extensions we need.
+// we have all the OpenGL extensions we need. Returns true if initialization
+// succeeded.
 //
 // The first parameter gives which directory to read .frag files from.
 // This is a temporary hack until we add something more solid.
@@ -20,8 +22,8 @@ enum MovitDebugLevel {
 // generated shaders to the current directory.
 //
 // If you call init_movit() twice with different parameters,
-// only the first will count.
-void init_movit(const std::string& data_directory, MovitDebugLevel debug_level);
+// only the first will count, and the second will always return true.
+bool init_movit(const std::string& data_directory, MovitDebugLevel debug_level) MUST_CHECK_RESULT;
 
 // GPU features. These are not intended for end-user use.
 
index 59c0ef420a43e04b846fa55a946b927ddddba180..61c3918810d1bb9fea9f0ef1da4fcb32690caaf0 100644 (file)
@@ -47,7 +47,7 @@ EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned
                                      GLenum framebuffer_format)
        : chain(width, height, get_static_pool()), width(width), height(height), finalized(false)
 {
-       init_movit(".", MOVIT_DEBUG_OFF);
+       CHECK(init_movit(".", MOVIT_DEBUG_OFF));
 
        if (data != NULL) {
                add_input(data, pixel_format, color_space, gamma_curve);