From: Steinar H. Gunderson Date: Wed, 12 Feb 2014 00:44:42 +0000 (+0100) Subject: Make init_movit() return a true/false error value. X-Git-Tag: 1.0~46 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=0fa51e08f83e0283337216f5b951b3d5a8c0555b Make init_movit() return a true/false error value. This allows clients to programmatically enable/disable Movit usage as needed on very old platforms. --- diff --git a/demo.cpp b/demo.cpp index 81d3e50..81bda2d 100644 --- 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", diff --git a/init.cpp b/init.cpp index d8d249f..fd22778 100644 --- 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 398ddbe..25869d1 100644 --- a/init.h +++ b/init.h @@ -1,6 +1,7 @@ #ifndef _MOVIT_INIT_H #define _MOVIT_INIT_H +#include "defs.h" #include 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. diff --git a/test_util.cpp b/test_util.cpp index 59c0ef4..61c3918 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -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);