From b216c09ade7b56efb97fe82754b72b1620f67098 Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Mon, 16 Jan 2023 20:48:19 +0100
Subject: [PATCH] opengl: move `ra_gl_ctx_params.flipped` to `struct GL`

This is motivated by a need to access it from vo_gpu_next's opengl
wrapping code, and justified by it being an inherent property of the GL
context itself,
---
 video/out/opengl/common.h            | 5 +++++
 video/out/opengl/context.c           | 2 +-
 video/out/opengl/context.h           | 5 -----
 video/out/opengl/context_angle.c     | 2 +-
 video/out/opengl/context_dxinterop.c | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/video/out/opengl/common.h b/video/out/opengl/common.h
index 35535322ad..a6b02c9366 100644
--- a/video/out/opengl/common.h
+++ b/video/out/opengl/common.h
@@ -88,6 +88,11 @@ struct GL {
     int mpgl_caps;              // Bitfield of MPGL_CAP_* constants
     bool debug_context;         // use of e.g. GLX_CONTEXT_DEBUG_BIT_ARB
 
+    // Set to false if the implementation follows normal GL semantics, which is
+    // upside down. Set to true if it does *not*, i.e. if rendering is right
+    // side up
+    bool flipped;
+
     // Copy of function pointer used to load GL.
     // Caution: Not necessarily valid to use after VO init has completed!
     void *(*get_fn)(void *ctx, const char *n);
diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c
index 2162c459d6..c2b7312c6b 100644
--- a/video/out/opengl/context.c
+++ b/video/out/opengl/context.c
@@ -238,7 +238,7 @@ bool ra_gl_ctx_start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo)
         return true;
     *out_fbo = (struct ra_fbo) {
          .tex = p->wrapped_fb,
-         .flip = !p->params.flipped, // OpenGL FBs are normally flipped
+         .flip = !p->gl->flipped, // OpenGL FBs are normally flipped
     };
     return true;
 }
diff --git a/video/out/opengl/context.h b/video/out/opengl/context.h
index 19521ff54b..c96450ebd5 100644
--- a/video/out/opengl/context.h
+++ b/video/out/opengl/context.h
@@ -34,11 +34,6 @@ struct ra_gl_ctx_params {
     // See ra_swapchain_fns.get_vsync.
     void (*get_vsync)(struct ra_ctx *ctx, struct vo_vsync_info *info);
 
-    // Set to false if the implementation follows normal GL semantics, which is
-    // upside down. Set to true if it does *not*, i.e. if rendering is right
-    // side up
-    bool flipped;
-
     // If this is set to non-NULL, then the ra_gl_ctx will consider the GL
     // implementation to be using an external swapchain, which disables the
     // software simulation of --swapchain-depth. Any functions defined by this
diff --git a/video/out/opengl/context_angle.c b/video/out/opengl/context_angle.c
index 77a33f6bb1..f5cc2c5ed6 100644
--- a/video/out/opengl/context_angle.c
+++ b/video/out/opengl/context_angle.c
@@ -605,10 +605,10 @@ static bool angle_init(struct ra_ctx *ctx)
     };
     struct ra_gl_ctx_params params = {
         .swap_buffers = angle_swap_buffers,
-        .flipped = p->flipped,
         .external_swapchain = p->dxgi_swapchain ? &dxgi_swapchain_fns : NULL,
     };
 
+    gl->flipped = p->flipped;
     if (!ra_gl_ctx_init(ctx, gl, params))
         goto fail;
 
diff --git a/video/out/opengl/context_dxinterop.c b/video/out/opengl/context_dxinterop.c
index 5764254cc1..cda696f71b 100644
--- a/video/out/opengl/context_dxinterop.c
+++ b/video/out/opengl/context_dxinterop.c
@@ -555,10 +555,10 @@ static bool dxgl_init(struct ra_ctx *ctx)
     static const struct ra_swapchain_fns empty_swapchain_fns = {0};
     struct ra_gl_ctx_params params = {
         .swap_buffers = dxgl_swap_buffers,
-        .flipped = true,
         .external_swapchain = &empty_swapchain_fns,
     };
 
+    gl->flipped = true;
     if (!ra_gl_ctx_init(ctx, gl, params))
         goto fail;