Fix initial OpenXR world shader setup

This commit is contained in:
obesecatlord 2026-05-10 22:50:13 -05:00
parent f47d1c0331
commit 56b5e8c38e
4 changed files with 39 additions and 5 deletions

View file

@ -12,6 +12,7 @@
#ifdef HWRENDER #ifdef HWRENDER
#include "hw_glob.h" #include "hw_glob.h"
#include "hw_batching.h" #include "hw_batching.h"
#include "hw_main.h"
#include "../i_system.h" #include "../i_system.h"
#include "../qs22j.h" #include "../qs22j.h"
@ -387,14 +388,14 @@ static unsigned int HWR_MarkStateChanges(DrawCallInfo *current, DrawCallInfo *ne
// check if a state change is required and flag it to stateChanges // check if a state change is required and flag it to stateChanges
if (current->shader != next->shader && cv_glshaders.value && gl_shadersavailable) if (current->shader != next->shader && HWR_UseShader())
stateChanges |= SHADER_CHANGED; stateChanges |= SHADER_CHANGED;
if (HWR_GetDrawCallTexture(current) != HWR_GetDrawCallTexture(next) if (HWR_GetDrawCallTexture(current) != HWR_GetDrawCallTexture(next)
|| HWR_GetDrawCallBrightmap(current) != HWR_GetDrawCallBrightmap(next)) || HWR_GetDrawCallBrightmap(current) != HWR_GetDrawCallBrightmap(next))
stateChanges |= TEXTURE_CHANGED; stateChanges |= TEXTURE_CHANGED;
if (current->polyFlags != next->polyFlags) if (current->polyFlags != next->polyFlags)
stateChanges |= POLYFLAGS_CHANGED; stateChanges |= POLYFLAGS_CHANGED;
if (cv_glshaders.value && gl_shadersavailable) if (HWR_UseShader())
{ {
if (currentSI->PolyColor.rgba != nextSI->PolyColor.rgba || if (currentSI->PolyColor.rgba != nextSI->PolyColor.rgba ||
currentSI->TintColor.rgba != nextSI->TintColor.rgba || currentSI->TintColor.rgba != nextSI->TintColor.rgba ||
@ -418,7 +419,7 @@ static unsigned int HWR_MarkStateChanges(DrawCallInfo *current, DrawCallInfo *ne
static void HWR_ExecuteStateChanges(unsigned int stateChanges, DrawCallInfo *dc) static void HWR_ExecuteStateChanges(unsigned int stateChanges, DrawCallInfo *dc)
{ {
if ((stateChanges & SHADER_CHANGED) && cv_glshaders.value && gl_shadersavailable) if ((stateChanges & SHADER_CHANGED) && HWR_UseShader())
{ {
GL_SetShader(dc->shader); GL_SetShader(dc->shader);
ps_hw_numshaders++; ps_hw_numshaders++;
@ -477,7 +478,7 @@ void HWR_RenderBatches(void)
// sort the draw calls // sort the draw calls
ps_hw_batchsorttime = I_GetPreciseTime(); ps_hw_batchsorttime = I_GetPreciseTime();
if (cv_glshaders.value && gl_shadersavailable) if (HWR_UseShader())
qs22j(drawCallOrder, cst->drawCallsSize, sizeof(UINT32), compareDrawCalls); qs22j(drawCallOrder, cst->drawCallsSize, sizeof(UINT32), compareDrawCalls);
else else
qs22j(drawCallOrder, cst->drawCallsSize, sizeof(UINT32), compareDrawCallsNoShaders); qs22j(drawCallOrder, cst->drawCallsSize, sizeof(UINT32), compareDrawCallsNoShaders);

View file

@ -122,6 +122,10 @@ static angle_t gl_aimingangle;
// Returns true if shaders can be used. // Returns true if shaders can be used.
boolean HWR_UseShader(void) boolean HWR_UseShader(void)
{ {
#ifdef HAVE_VR
if (vr_started)
return gl_shadersavailable;
#endif
return (cv_glshaders.value && gl_shadersavailable); return (cv_glshaders.value && gl_shadersavailable);
} }
@ -775,7 +779,7 @@ void HWR_RenderPlayerView(void)
ClearColor.blue = 0.0f; ClearColor.blue = 0.0f;
ClearColor.alpha = 1.0f; ClearColor.alpha = 1.0f;
if (cv_glshaders.value) if (HWR_UseShader())
{ {
GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime. GL_SetShaderInfo(HWD_SHADERINFO_LEVELTIME, (INT32)leveltime); // The water surface shader needs the leveltime.

View file

@ -3129,6 +3129,21 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
camrotate = cv_cam_rotate[num].value; camrotate = cv_cam_rotate[num].value;
camdist = FixedMul(cv_cam_dist[num].value, mapobjectscale); camdist = FixedMul(cv_cam_dist[num].value, mapobjectscale);
camheight = FixedMul(cv_cam_height[num].value, mapobjectscale); camheight = FixedMul(cv_cam_height[num].value, mapobjectscale);
#ifdef HAVE_VR
if (vr_started)
{
const fixed_t vr_camdist = FixedMul(160*FRACUNIT, mapobjectscale);
const fixed_t vr_camheight = FixedMul(50*FRACUNIT, mapobjectscale);
// Match kart-public-vr's chase camera defaults in VR. Blankart's
// normal camera is higher and farther back, which makes the headset
// view start too high and pitched down.
if (camdist > vr_camdist)
camdist = vr_camdist;
if (camheight > vr_camheight)
camheight = vr_camheight;
}
#endif
if (leveltime > introtime) if (leveltime > introtime)
{ {

View file

@ -10,6 +10,10 @@
#include "../i_video.h" #include "../i_video.h"
#include "../r_fps.h" #include "../r_fps.h"
#include "../v_video.h" #include "../v_video.h"
#ifdef HWRENDER
#include "../hardware/hw_glob.h"
#include "../hardware/hw_main.h"
#endif
#include <stdbool.h> #include <stdbool.h>
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include "../sdl/sdlmain.h" #include "../sdl/sdlmain.h"
@ -519,6 +523,12 @@ boolean VR_Init(void)
vr_started = true; vr_started = true;
vr_enabled = true; vr_enabled = true;
#ifdef HWRENDER
if (gl_shadersavailable) {
CONS_Printf("VR: Recompiling hardware shaders with OpenXR view uniforms.\n");
HWR_CompileShaders();
}
#endif
CV_StealthSet(&cv_vidwait, "Off"); CV_StealthSet(&cv_vidwait, "Off");
CV_StealthSetValue(&cv_fpscap, -1); CV_StealthSetValue(&cv_fpscap, -1);
CV_StealthSet(&cv_ticrate, "Compact"); CV_StealthSet(&cv_ticrate, "Compact");
@ -550,6 +560,10 @@ void VR_Shutdown(void)
vr_started = false; vr_started = false;
vr_enabled = false; vr_enabled = false;
vr_drawing_ui = false; vr_drawing_ui = false;
#ifdef HWRENDER
if (gl_shadersavailable)
HWR_CompileShaders();
#endif
displayRefreshRateExtensionEnabled = false; displayRefreshRateExtensionEnabled = false;
pfnEnumerateDisplayRefreshRatesFB = NULL; pfnEnumerateDisplayRefreshRatesFB = NULL;
pfnGetDisplayRefreshRateFB = NULL; pfnGetDisplayRefreshRateFB = NULL;