Procházet zdrojové kódy

Added an internal hint to set OpenVR overlay flags

Sam Lantinga před 3 dny
rodič
revize
299ed51984
1 změnil soubory, kde provedl 28 přidání a 14 odebrání
  1. 28 14
      src/video/openvr/SDL_openvrvideo.c

+ 28 - 14
src/video/openvr/SDL_openvrvideo.c

@@ -568,7 +568,7 @@ static bool OPENVR_SetupJoystickBasedOnLoadedActionManifest(SDL_VideoData * vide
     return true;
 }
 
-static bool OPENVR_InitializeOverlay(SDL_VideoDevice *_this,SDL_Window *window)
+static bool OPENVR_InitializeOverlay(SDL_VideoDevice *_this, SDL_Window *window)
 {
     SDL_VideoData *videodata = (SDL_VideoData *)_this->internal;
 
@@ -610,6 +610,32 @@ static bool OPENVR_InitializeOverlay(SDL_VideoDevice *_this,SDL_Window *window)
         SDL_free(cursorname);
         videodata->bHasShownOverlay = false;
     }
+    {
+        Uint32 overlay_flags = 0;
+
+        const char *hint = SDL_GetHint("SDL_OPENVR_OVERLAY_FLAGS");
+        if (hint && *hint) {
+            overlay_flags = SDL_atoi(hint);
+        } else {
+            overlay_flags |= (1 << 23); //vr::VROverlayFlags_EnableControlBar
+            overlay_flags |= (1 << 24); //vr::VROverlayFlags_EnableControlBarKeyboard
+            overlay_flags |= (1 << 25); //vr::VROverlayFlags_EnableControlBarClose
+#if 0
+            /* OpenVR overlays assume unpremultiplied alpha by default, set this flag to tag the source buffer as premultiplied.
+             * Note that (as of 2025) OpenVR overlay composition is higher quality when premultiplied buffers are provided,
+             * as texture samplers that blend energy (such as bilinear) do not yield sensical results when operating on natively
+             * unpremultiplied textures. It is thus preferable to hand openvr natively premultiplied buffers when accurate
+             * sampling / composition is required. */
+            overlay_flags |= (1 << 21);    // vr::VROverlayFlags_IsPremultiplied
+#endif
+        }
+
+        for (int i = 0; i < sizeof(overlay_flags) * 8; ++i) {
+            if (overlay_flags & (1 << i)) {
+                videodata->oOverlay->SetOverlayFlag(videodata->overlayID, (VROverlayFlags)(1 << i), true);
+            }
+        }
+    }
     {
         const char * hint = SDL_GetHint("SDL_OPENVR_OVERLAY_PANEL_WIDTH");
         float fWidth = hint ? (float)SDL_atof(hint) : 1.0f;
@@ -629,7 +655,7 @@ static bool OPENVR_InitializeOverlay(SDL_VideoDevice *_this,SDL_Window *window)
             EVROverlayError err = videodata->oOverlay->SetOverlayFromFile(videodata->thumbID, tmpcopy);
             SDL_free(tmpcopy);
             if (err == EVROverlayError_VROverlayError_None) {
-                videodata->bIconOverridden = SDL_GetHintBoolean("SDL_OPENVR_WINDOW_ICON_OVERRIDE",false);
+                videodata->bIconOverridden = SDL_GetHintBoolean("SDL_OPENVR_WINDOW_ICON_OVERRIDE", false);
             }
         }
     }
@@ -646,22 +672,10 @@ static bool OPENVR_InitializeOverlay(SDL_VideoDevice *_this,SDL_Window *window)
         return false;
     }
 
-
     global_openvr_driver = videodata;
     InitializeMouseFunctions();
 
     // Actually show the overlay.
-    videodata->oOverlay->SetOverlayFlag(videodata->overlayID, 1<<23, true); //vr::VROverlayFlags_EnableControlBar
-    videodata->oOverlay->SetOverlayFlag(videodata->overlayID, 1<<24, true); //vr::VROverlayFlags_EnableControlBarKeyboard
-    videodata->oOverlay->SetOverlayFlag(videodata->overlayID, 1<<25, true); //vr::VROverlayFlags_EnableControlBarClose
-#if 0
-    /* OpenVR overlays assume unpremultiplied alpha by default, set this flag to tag the source buffer as premultiplied.
-     * Note that (as of 2025) OpenVR overlay composition is higher quality when premultiplied buffers are provided,
-     * as texture samplers that blend energy (such as bilinear) do not yield sensical results when operating on natively
-     * unpremultiplied textures. It is thus preferable to hand openvr natively premultiplied buffers when accurate
-     * sampling / composition is required. */
-    videodata->oOverlay->SetOverlayFlag(videodata->overlayID, VROverlayFlags_IsPremultiplied, true );
-#endif
     videodata->oOverlay->SetOverlayName(videodata->overlayID, window->title);
 
     videodata->bDidCreateOverlay = true;