]> git.sesse.net Git - nageru/commitdiff
Fix some overly repetitive code in PBOFrameAllocator.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 16 Mar 2019 23:42:31 +0000 (00:42 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 16 Mar 2019 23:42:31 +0000 (00:42 +0100)
nageru/pbo_frame_allocator.cpp

index 6211937b701f21dc2bdfbe916781f71f4629fb6b..1904cf17e26ea8ca3b7ea76ea56442a5acbb85bb 100644 (file)
@@ -55,9 +55,10 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
        frame.data_copy = new uint8_t[frame_size];
        check_error();
        frame.size = frame_size;
-       frame.userdata = &userdata[frame_idx];
-       userdata[frame_idx].pbo = pbo;
-       userdata[frame_idx].pixel_format = pixel_format;
+       Userdata *ud = &userdata[frame_idx];
+       frame.userdata = ud;
+       ud->pbo = pbo;
+       ud->pixel_format = pixel_format;
        frame.owner = this;
 
        // For 8-bit non-planar Y'CbCr, we ask the driver to split Y' and Cb/Cr
@@ -72,48 +73,48 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
        // resolution is progressive.
        switch (pixel_format) {
        case bmusb::PixelFormat_8BitYCbCr:
-               glGenTextures(2, userdata[frame_idx].tex_y);
+               glGenTextures(2, ud->tex_y);
                check_error();
-               glGenTextures(2, userdata[frame_idx].tex_cbcr);
+               glGenTextures(2, ud->tex_cbcr);
                check_error();
                break;
        case bmusb::PixelFormat_10BitYCbCr:
-               glGenTextures(2, userdata[frame_idx].tex_v210);
+               glGenTextures(2, ud->tex_v210);
                check_error();
-               glGenTextures(2, userdata[frame_idx].tex_444);
+               glGenTextures(2, ud->tex_444);
                check_error();
                break;
        case bmusb::PixelFormat_8BitBGRA:
-               glGenTextures(2, userdata[frame_idx].tex_rgba);
+               glGenTextures(2, ud->tex_rgba);
                check_error();
                break;
        case bmusb::PixelFormat_8BitYCbCrPlanar:
-               glGenTextures(2, userdata[frame_idx].tex_y);
+               glGenTextures(2, ud->tex_y);
                check_error();
-               glGenTextures(2, userdata[frame_idx].tex_cb);
+               glGenTextures(2, ud->tex_cb);
                check_error();
-               glGenTextures(2, userdata[frame_idx].tex_cr);
+               glGenTextures(2, ud->tex_cr);
                check_error();
                break;
        default:
                assert(false);
        }
 
-       userdata[frame_idx].last_width[0] = width;
-       userdata[frame_idx].last_height[0] = height;
-       userdata[frame_idx].last_cbcr_width[0] = width / 2;
-       userdata[frame_idx].last_cbcr_height[0] = height;
-       userdata[frame_idx].last_v210_width[0] = 0;
+       ud->last_width[0] = width;
+       ud->last_height[0] = height;
+       ud->last_cbcr_width[0] = width / 2;
+       ud->last_cbcr_height[0] = height;
+       ud->last_v210_width[0] = 0;
 
-       userdata[frame_idx].last_width[1] = 0;
-       userdata[frame_idx].last_height[1] = 0;
-       userdata[frame_idx].last_cbcr_width[1] = 0;
-       userdata[frame_idx].last_cbcr_height[1] = 0;
-       userdata[frame_idx].last_v210_width[1] = 0;
+       ud->last_width[1] = 0;
+       ud->last_height[1] = 0;
+       ud->last_cbcr_width[1] = 0;
+       ud->last_cbcr_height[1] = 0;
+       ud->last_v210_width[1] = 0;
 
-       userdata[frame_idx].last_interlaced = false;
-       userdata[frame_idx].last_has_signal = false;
-       userdata[frame_idx].last_is_connected = false;
+       ud->last_interlaced = false;
+       ud->last_has_signal = false;
+       ud->last_is_connected = false;
        for (unsigned field = 0; field < 2; ++field) {
                switch (pixel_format) {
                case bmusb::PixelFormat_10BitYCbCr: {
@@ -122,17 +123,17 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                        // Seemingly we need to set the minification filter even though
                        // shader image loads don't use them, or NVIDIA will just give us
                        // zero back.
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_v210[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_v210[field]);
                        check_error();
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                        check_error();
                        if (field == 0) {
-                               userdata[frame_idx].last_v210_width[0] = v210_width;
+                               ud->last_v210_width[0] = v210_width;
                                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, v210_width, height, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, nullptr);
                                check_error();
                        }
 
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_444[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_444[field]);
                        check_error();
                        set_clamp_to_edge();
                        if (field == 0) {
@@ -142,7 +143,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                        break;
                }
                case bmusb::PixelFormat_8BitYCbCr:
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_y[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_y[field]);
                        check_error();
                        set_clamp_to_edge();
                        if (field == 0) {
@@ -150,7 +151,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                                check_error();
                        }
 
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_cbcr[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_cbcr[field]);
                        check_error();
                        set_clamp_to_edge();
                        if (field == 0) {
@@ -159,7 +160,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                        }
                        break;
                case bmusb::PixelFormat_8BitBGRA:
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_rgba[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_rgba[field]);
                        check_error();
                        set_clamp_to_edge();
                        if (field == 0) {
@@ -172,7 +173,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                        }
                        break;
                case bmusb::PixelFormat_8BitYCbCrPlanar:
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_y[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_y[field]);
                        check_error();
                        set_clamp_to_edge();
                        if (field == 0) {
@@ -180,7 +181,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                                check_error();
                        }
 
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_cb[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_cb[field]);
                        check_error();
                        set_clamp_to_edge();
                        if (field == 0) {
@@ -188,7 +189,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                                check_error();
                        }
 
-                       glBindTexture(GL_TEXTURE_2D, userdata[frame_idx].tex_cr[field]);
+                       glBindTexture(GL_TEXTURE_2D, ud->tex_cr[field]);
                        check_error();
                        set_clamp_to_edge();
                        if (field == 0) {