From 575a3feeaa7420f65a4468b997167d7555794c08 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 19 May 2019 10:34:24 +0200 Subject: [PATCH] Always require GL_EXT_texture_sRGB_decode. Keeping the pure OpenGL path does not seem to actually buy us any compatibility, so we simplify things a bit for an upcoming fix. Strangely enough, this does not seem to be in any OpenGL standard. Sampler objects, which we also require, is, though. --- nageru/flags.h | 1 - nageru/mixer.cpp | 16 +++++++--------- nageru/pbo_frame_allocator.cpp | 6 +----- nageru/theme.cpp | 6 +----- nageru/tweaked_inputs.h | 20 ++++---------------- 5 files changed, 13 insertions(+), 36 deletions(-) diff --git a/nageru/flags.h b/nageru/flags.h index a401dbf..caad05a 100644 --- a/nageru/flags.h +++ b/nageru/flags.h @@ -66,7 +66,6 @@ struct Flags { bool enable_audio = true; // Kaeru only. If false, then transcode_audio is also false. int x264_bit_depth = 8; // Not user-settable. bool use_zerocopy = false; // Not user-settable. - bool can_disable_srgb_decoder = false; // Not user-settable. bool fullscreen = false; std::map card_to_mjpeg_stream_export; // If a card is not in the map, it is not exported. }; diff --git a/nageru/mixer.cpp b/nageru/mixer.cpp index 83d6ead..91c82d4 100644 --- a/nageru/mixer.cpp +++ b/nageru/mixer.cpp @@ -153,11 +153,8 @@ void ensure_texture_resolution(PBOFrameAllocator::Userdata *userdata, unsigned f case PixelFormat_8BitBGRA: glBindTexture(GL_TEXTURE_2D, userdata->tex_rgba[field]); check_error(); - if (global_flags.can_disable_srgb_decoder) { // See the comments in tweaked_inputs.h. - glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); - } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); - } + // NOTE: sRGB may be disabled by sRGBSwitchingFlatInput. + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); check_error(); break; default: @@ -314,10 +311,11 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards) CHECK(init_movit(MOVIT_SHADER_DIR, MOVIT_DEBUG_OFF)); check_error(); - // This nearly always should be true. - global_flags.can_disable_srgb_decoder = - epoxy_has_gl_extension("GL_EXT_texture_sRGB_decode") && - epoxy_has_gl_extension("GL_ARB_sampler_objects"); + if (!epoxy_has_gl_extension("GL_EXT_texture_sRGB_decode") || + !epoxy_has_gl_extension("GL_ARB_sampler_objects")) { + fprintf(stderr, "Nageru requires GL_EXT_texture_sRGB_decode and GL_ARB_sampler_objects to run.\n"); + exit(1); + } // Since we allow non-bouncing 4:2:2 YCbCrInputs, effective subpixel precision // will be halved when sampling them, and we need to compensate here. diff --git a/nageru/pbo_frame_allocator.cpp b/nageru/pbo_frame_allocator.cpp index 7fb06f8..4640d35 100644 --- a/nageru/pbo_frame_allocator.cpp +++ b/nageru/pbo_frame_allocator.cpp @@ -166,11 +166,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w check_error(); set_clamp_to_edge(); if (field == 0) { - if (global_flags.can_disable_srgb_decoder) { // See the comments in tweaked_inputs.h. - glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); - } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); - } + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); check_error(); } break; diff --git a/nageru/theme.cpp b/nageru/theme.cpp index 7226e82..33fa114 100644 --- a/nageru/theme.cpp +++ b/nageru/theme.cpp @@ -905,11 +905,7 @@ LiveInputWrapper::LiveInputWrapper( for (unsigned i = 0; i < num_inputs; ++i) { // We upload our textures ourselves, and Movit swaps // R and B in the shader if we specify BGRA, so lie and say RGBA. - if (global_flags.can_disable_srgb_decoder) { - rgba_inputs.push_back(new sRGBSwitchingFlatInput(inout_format, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, GL_UNSIGNED_BYTE, global_flags.width, global_flags.height)); - } else { - rgba_inputs.push_back(new NonsRGBCapableFlatInput(inout_format, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, GL_UNSIGNED_BYTE, global_flags.width, global_flags.height)); - } + rgba_inputs.push_back(new sRGBSwitchingFlatInput(inout_format, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, GL_UNSIGNED_BYTE, global_flags.width, global_flags.height)); chain->add_input(rgba_inputs.back()); } diff --git a/nageru/tweaked_inputs.h b/nageru/tweaked_inputs.h index 0ca13ce..3b70a13 100644 --- a/nageru/tweaked_inputs.h +++ b/nageru/tweaked_inputs.h @@ -3,6 +3,7 @@ // Some tweaked variations of Movit inputs. +#include #include namespace movit { @@ -26,21 +27,9 @@ public: // or not. (FlatInput deals with this if you give it pixels, but we give it // already uploaded textures.) // -// If we have GL_EXT_texture_sRGB_decode (very common, as far as I can tell), -// we can just always upload with the sRGB flag turned on, and then turn it off -// if not requested; that's sRGBSwitchingFlatInput. If not, we just need to -// turn off the functionality altogether, which is NonsRGBCapableFlatInput. -// -// If you're using NonsRGBCapableFlatInput, upload with GL_RGBA8. -// If using sRGBSwitchingFlatInput, upload with GL_SRGB8_ALPHA8. - -class NonsRGBCapableFlatInput : public movit::FlatInput { -public: - NonsRGBCapableFlatInput(movit::ImageFormat format, movit::MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height) - : movit::FlatInput(format, pixel_format, type, width, height) {} - - bool can_output_linear_gamma() const override { return false; } -}; +// Since we require GL_EXT_texture_sRGB_decode (very common, as far as I can tell), +// we can just always upload with the sRGB flag turned on (upload your texture with +// GL_SRGB8_ALPHA8), and then sRGBSwitchingFlatInput will turn it off if not requested. class sRGBSwitchingFlatInput : public movit::FlatInput { public: @@ -69,5 +58,4 @@ private: GLuint texture_unit; }; - #endif // !defined(_TWEAKED_INPUTS_H) -- 2.39.2