]> git.sesse.net Git - nageru/commitdiff
Change from RGBA to BGRA; slightly more Intel GPU-friendly, and Caspar uses that...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 21 Apr 2017 18:19:00 +0000 (20:19 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 21 Apr 2017 18:19:00 +0000 (20:19 +0200)
bmusb
ffmpeg_capture.cpp
ffmpeg_capture.h
mixer.cpp
pbo_frame_allocator.cpp
theme.cpp
theme.h

diff --git a/bmusb b/bmusb
index 824260a0732a49b5a18f2e16e04b0373c37a3bea..c245ceb9081e412bb815480481670e295ddfc71a 160000 (submodule)
--- a/bmusb
+++ b/bmusb
@@ -1 +1 @@
-Subproject commit 824260a0732a49b5a18f2e16e04b0373c37a3bea
+Subproject commit c245ceb9081e412bb815480481670e295ddfc71a
index 2f9c6fdc1be3bb096c0a22dd760ac11084b02cd6..ab35c5c5ef1c5f18e66f338fa1cad20fef860a9d 100644 (file)
@@ -297,7 +297,7 @@ bool FFmpegCapture::play_video(const string &pathname)
                if (sws_ctx == nullptr || sws_last_width != frame->width || sws_last_height != frame->height) {
                        sws_ctx.reset(
                                sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format,
-                                       width, height, AV_PIX_FMT_RGBA,
+                                       width, height, AV_PIX_FMT_BGRA,
                                        SWS_BICUBIC, nullptr, nullptr, nullptr));
                        sws_last_width = frame->width;
                        sws_last_height = frame->height;
index 3b2f0e431bd6b08aa0cb7981182dd154bcf5ef5f..9753c0032f37ae184a91786335bb04534be9413c 100644 (file)
@@ -117,13 +117,13 @@ public:
        uint32_t get_current_video_mode() const override { return 0; }
 
        std::set<bmusb::PixelFormat> get_available_pixel_formats() const override {
-               return std::set<bmusb::PixelFormat>{ bmusb::PixelFormat_8BitRGBA };
+               return std::set<bmusb::PixelFormat>{ bmusb::PixelFormat_8BitBGRA };
        }
        void set_pixel_format(bmusb::PixelFormat pixel_format) override {
-               assert(pixel_format == bmusb::PixelFormat_8BitRGBA);
+               assert(pixel_format == bmusb::PixelFormat_8BitBGRA);
        }       
        bmusb::PixelFormat get_current_pixel_format() const override {
-               return bmusb::PixelFormat_8BitRGBA;
+               return bmusb::PixelFormat_8BitBGRA;
        }
 
        std::map<uint32_t, std::string> get_available_video_inputs() const override {
index 84419f41518fc4c092df7c6afc527e23c83c5121..3a14a757431a88b2924a3430dcbf922fe1b3e73c 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -89,7 +89,7 @@ void ensure_texture_resolution(PBOFrameAllocator::Userdata *userdata, unsigned f
        case bmusb::PixelFormat_8BitYCbCr:
                first = userdata->tex_y[field] == 0 || userdata->tex_cbcr[field] == 0;
                break;
-       case bmusb::PixelFormat_8BitRGBA:
+       case bmusb::PixelFormat_8BitBGRA:
                first = userdata->tex_rgba[field] == 0;
                break;
        default:
@@ -122,13 +122,13 @@ void ensure_texture_resolution(PBOFrameAllocator::Userdata *userdata, unsigned f
                        check_error();
                        break;
                }
-               case bmusb::PixelFormat_8BitRGBA:
+               case bmusb::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_RGBA, GL_UNSIGNED_BYTE, nullptr);
+                               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_RGBA, GL_UNSIGNED_BYTE, nullptr);
+                               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr);
                        }
                        check_error();
                        break;
@@ -403,7 +403,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
 
        bmusb::PixelFormat pixel_format;
        if (card_type == CardType::FFMPEG_INPUT) {
-               pixel_format = bmusb::PixelFormat_8BitRGBA;
+               pixel_format = bmusb::PixelFormat_8BitBGRA;
        } else if (global_flags.ten_bit_input) {
                pixel_format = PixelFormat_10BitYCbCr;
        } else {
@@ -660,9 +660,9 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
                                upload_texture(userdata->tex_cbcr[field], cbcr_width, video_format.height, cbcr_width * sizeof(uint16_t), interlaced_stride, GL_RG, GL_UNSIGNED_BYTE, field_cbcr_start);
                                break;
                        }
-                       case bmusb::PixelFormat_8BitRGBA: {
+                       case bmusb::PixelFormat_8BitBGRA: {
                                size_t field_start = video_offset + video_format.stride * field_start_line;
-                               upload_texture(userdata->tex_rgba[field], video_format.width, video_format.height, video_format.stride, interlaced_stride, GL_RGBA, GL_UNSIGNED_BYTE, field_start);
+                               upload_texture(userdata->tex_rgba[field], video_format.width, video_format.height, video_format.stride, interlaced_stride, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, field_start);
                                break;
                        }
                        default:
index ed1ddb5f9a1c0eb94588daa508c4ebf2fdaad858..35e4ed550e07367b20a219b65d4f43d966b24da1 100644 (file)
@@ -38,7 +38,7 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra
                // For 8-bit Y'CbCr, we ask the driver to split Y' and Cb/Cr
                // into separate textures. For 10-bit, the input format (v210)
                // is complicated enough that we need to interpolate up to 4:4:4,
-               // which we do in a compute shader ourselves. For RGBA, the data
+               // which we do in a compute shader ourselves. For BGRA, the data
                // is already 4:4:4:4.
                frame.interleaved = (pixel_format == bmusb::PixelFormat_8BitYCbCr);
 
@@ -58,7 +58,7 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra
                        glGenTextures(2, userdata[i].tex_444);
                        check_error();
                        break;
-               case bmusb::PixelFormat_8BitRGBA:
+               case bmusb::PixelFormat_8BitBGRA:
                        glGenTextures(2, userdata[i].tex_rgba);
                        check_error();
                        break;
@@ -134,7 +134,7 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra
                                        check_error();
                                }
                                break;
-                       case bmusb::PixelFormat_8BitRGBA:
+                       case bmusb::PixelFormat_8BitBGRA:
                                glBindTexture(GL_TEXTURE_2D, userdata[i].tex_rgba[field]);
                                check_error();
                                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -145,9 +145,9 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra
                                check_error();
                                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_RGBA, GL_UNSIGNED_BYTE, NULL);
+                                               glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
                                        } else {
-                                               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+                                               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
                                        }
                                        check_error();
                                }
@@ -192,7 +192,7 @@ PBOFrameAllocator::~PBOFrameAllocator()
                        glDeleteTextures(2, ((Userdata *)frame.userdata)->tex_cbcr);
                        check_error();
                        break;
-               case bmusb::PixelFormat_8BitRGBA:
+               case bmusb::PixelFormat_8BitBGRA:
                        glDeleteTextures(2, ((Userdata *)frame.userdata)->tex_rgba);
                        check_error();
                        break;
index 1434baaaadff5114bb3b5a0f341269bc40060ade..56e7ce2de3285733707c425b7d61f076eda6266b 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -222,7 +222,7 @@ int EffectChain_add_video_input(lua_State* L)
        // doesn't care about the object anymore. (If we change this, we'd need
        // to also unregister the signal connection on __gc.)
        int ret = wrap_lua_object_nonowned<LiveInputWrapper>(
-               L, "LiveInputWrapper", theme, chain, bmusb::PixelFormat_8BitRGBA,
+               L, "LiveInputWrapper", theme, chain, bmusb::PixelFormat_8BitBGRA,
                /*override_bounce=*/false, deinterlace);
        if (ret == 1) {
                Theme *theme = get_theme_updata(L);
@@ -692,8 +692,10 @@ LiveInputWrapper::LiveInputWrapper(Theme *theme, EffectChain *chain, bmusb::Pixe
                num_inputs = 1;
        }
 
-       if (pixel_format == bmusb::PixelFormat_8BitRGBA) {
+       if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
                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 {
@@ -798,7 +800,7 @@ void LiveInputWrapper::connect_signal_raw(int signal_num)
                        ycbcr_inputs[i]->set_width(this_width);
                        ycbcr_inputs[i]->set_height(this_height);
                        break;
-               case bmusb::PixelFormat_8BitRGBA:
+               case bmusb::PixelFormat_8BitBGRA:
                        rgba_inputs[i]->set_texture_num(userdata->tex_rgba[frame.field_number]);
                        rgba_inputs[i]->set_width(this_width);
                        rgba_inputs[i]->set_height(this_height);
diff --git a/theme.h b/theme.h
index b04050e51d05a6331b21d65409adda3311a61fa0..51107d6a5e088e3f6806c3785b6d1d8e1fdad85a 100644 (file)
--- a/theme.h
+++ b/theme.h
@@ -103,7 +103,7 @@ private:
 // the mixer, and communicates that state over to the actual YCbCrInput.
 class LiveInputWrapper {
 public:
-       // Note: <override_bounce> is irrelevant for PixelFormat_8BitRGBA.
+       // Note: <override_bounce> is irrelevant for PixelFormat_8BitBGRA.
        LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace);
 
        void connect_signal(int signal_num);
@@ -112,7 +112,7 @@ public:
        {
                if (deinterlace) {
                        return deinterlace_effect;
-               } else if (pixel_format == bmusb::PixelFormat_8BitRGBA) {
+               } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
                        return rgba_inputs[0];
                } else {
                        return ycbcr_inputs[0];