Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • STJr/SRB2
  • Sryder/SRB2
  • wolfy852/SRB2
  • Alpha2244/SRB2
  • Inuyasha/SRB2
  • yoshibot/SRB2
  • TehRealSalt/SRB2
  • PrisimaTF/SRB2
  • Hatninja/SRB2
  • SteelT/SRB2
  • james/SRB2
  • ShaderWraith/SRB2
  • SinnamonLat/SRB2
  • mazmazz_/SRB2
  • filpAM/SRB2
  • chaoloveicemdboy/SRB2
  • Whooa21/SRB2
  • Machturne/SRB2
  • Golden/SRB2
  • Tatsuru/SRB2
  • Snu/SRB2
  • Zwip-Zwap_Zapony/SRB2
  • fickleheart/SRB2
  • alphaRexJames/SRB2
  • JJK/SRB2
  • diskpoppy/SRB2
  • Hannu_Hanhi/SRB2
  • ZipperQR/SRB2
  • kays/SRB2
  • spherallic/SRB2
  • Zippy_Zolton/SRB2
  • namiishere/SRB2
  • Ors/SRB2
  • SMS_Alfredo/SRB2
  • sonic_edge/SRB2
  • lavla/SRB2
  • ashi/SRB2
  • X.organic/SRB2
  • Fafabis/SRB2
  • Meziu/SRB2
  • v-rob/SRB2
  • tertu/SRB2
  • bitten2up/SRB2
  • flarn2006/SRB2
  • Krabs/SRB2
  • clairebun/SRB2
  • Lactozilla/SRB2
  • thehackstack/SRB2
  • Spice/SRB2
  • win8linux/SRB2
  • JohnFrostFox/SRB2
  • talktoneon726/SRB2
  • Wane/SRB2
  • Lamibe/SRB2
  • spectrumuk2/srb-2
  • nerdyminer18/srb-2
  • 256nil/SRB2
  • ARJr/SRB2
  • Alam/SRB2
  • Zenya/srb-2-marathon-demos
  • Acelite/srb-2-archivedmodifications
  • MIDIMan/SRB2
  • Lach/SRB2
  • Frostiikin/bounce-tweaks
  • Jaden/SRB2
  • Tyron/SRB2
  • Astronight/SRB2
  • Mari0shi06/SRB2
  • aiire/SRB2
  • Galactice/SRB2
  • srb2-ports/srb2-dreamcast
  • sdasdas/SRB2
  • chreas/srb-2-vr
  • StarManiaKG/the-story-of-sinically-rocketing-and-botching-the-2nd
  • LoganAir/SRB2
  • NepDisk/srb-2
  • alufolie91/SRB2
  • Felicia.iso/SRB2
  • twi/SRB2
  • BarrelsOFun/SRB2
  • Speed2411/SRB2
  • Leather_Realms/SRB2
  • Ayemar/SRB2
  • Acelite/SRB2
  • VladDoc/SRB2
  • kaldrum/model-features
  • strawberryfox417/SRB2
  • Lugent/SRB2
  • Rem/SRB2
  • Refrag/SRB2
  • Henry_3230/srb-3230
  • TehPuertoRicanSpartan2/tprs-srb2
  • Leminn/srb-2-marathon-stuff
  • chromaticpipe2/SRB2
  • MiguelGustavo15/SRB2
  • Maru/srb-2-tests
  • SilicDev/SRB2
  • UnmatchedBracket/SRB2
  • HybridDog/SRB2
  • xordspar0/SRB2
  • jsjhbewfhh/SRB2
  • Fancy2209/SRB2
  • Lorsoen/SRB2
  • shindoukin/SRB2
  • GamerOfDays/SRB2
  • Craftyawesome/SRB2
  • tenshi-tensai-tennoji/SRB2
  • Scarfdudebalder/SRB2
  • luigi-budd/srb-2-fix-interplag-lockon
  • mskluesner/SRB2
  • johnpetersa19/SRB2
  • Pheazant/SRB2
  • chromaticpipe2/srb2classic
  • romoney5/SRB2
  • PAS/SRB2Classic
  • BlueStaggo/SRB2
  • Jisk/srb-2-beef-jerky
  • voltybystorm/SRB2
118 results
Select Git revision
Show changes
Commits on Source (3)
Showing
with 574 additions and 45 deletions
File added
File added
File added
File added
File added
File added
File added
File added
File added
......@@ -9,9 +9,11 @@ opts+=-DUNIXCOMMON -DLUA_USE_POSIX
# instead of addresses
libs+=-lm -rdynamic
ifndef NOHW
opts+=-I/usr/X11R6/include
libs+=-L/usr/X11R6/lib
#libs+=-L../../libs/openvr/libopenvr_api.so
endif
SDL?=1
......
......@@ -25,6 +25,30 @@ opts+=-DDIRECTFULLSCREEN -DHAVE_SDL
ifndef NOHW
sources+=sdl/ogl_sdl.c
sources+=openvr/openvr_common.c openvr/openvr_common.h openvr/openvr_capi.h
endif
#LINK OPENVR LIBRARIES TO SDL/OPENGL
libs+=-lopenvr_api
ifdef LINUX
ifdef LINUX64
ifdef ARM64
LDFLAGS+=-L../libs/openvr/linuxarm64
else
LDFLAGS+=-L../libs/openvr/linux64
endif
else
LDFLAGS+=-L../libs/openvr/linux32
endif
endif
ifdef MINGW
ifdef MINGW64
LDFLAGS+=-L../libs/openvr/win64
else
LDFLAGS+=-L../libs/openvr/win32
endif
endif
ifdef NOMIXER
......
......@@ -60,7 +60,7 @@ endif
ifdef GCC45
WFLAGS+=-Wlogical-op
endif
WFLAGS+=-Waggregate-return
#WFLAGS+=-Waggregate-return
ifdef HAIKU
ifdef GCC41
#WFLAGS+=-Wno-attributes
......
......@@ -81,6 +81,7 @@
#ifdef HWRENDER
#include "hardware/hw_main.h" // 3D View Rendering
#include "openvr/openvr_common.h"
#endif
#ifdef _WINDOWS
......@@ -695,6 +696,13 @@ static void D_Display(void)
I_FinishUpdate(); // page flip or blit buffer
PS_STOP_TIMING(ps_swaptime);
}
#ifdef HWRENDER
if(vrPendingErrorMessage[0])
{
CONS_Alert(CONS_ERROR, "%s", vrPendingErrorMessage);
vrPendingErrorMessage[0] = 0;
}
#endif
}
// =========================================================================
......
......@@ -76,6 +76,7 @@
#include "../r_state.h"
#include "../tables.h"
#include "r_opengl/r_opengl.h"
#include "../openvr/openvr_common.h"
#ifdef HAVE_SPHEREFRUSTRUM
static GLdouble viewMatrix[16];
......@@ -329,7 +330,7 @@ angle_t gld_FrustumAngle(angle_t tiltangle)
// NEWCLIP TODO: SRB2CBTODO: make a global render_fov for this function
float render_fov = FIXED_TO_FLOAT(cv_fov.value);
float render_fov = FIXED_TO_FLOAT(openvr_started ? 120 * FRACUNIT : cv_fov.value);
float render_fovratio = (float)BASEVIDWIDTH / (float)BASEVIDHEIGHT; // SRB2CBTODO: NEWCLIPTODO: Is this right?
float render_multiplier = 64.0f / render_fovratio / RMUL;
......
......@@ -64,6 +64,11 @@ EXPORT void HWRAPI(DrawIntermissionBG) (void);
EXPORT void HWRAPI(MakeScreenTexture) (void);
EXPORT void HWRAPI(MakeScreenFinalTexture) (void);
EXPORT void HWRAPI(DrawScreenFinalTexture) (int width, int height);
EXPORT void HWRAPI(MakeViewTexture) (void);
EXPORT void HWRAPI(SetEye) (int);
EXPORT void HWRAPI(SubmitTextureToHMD) (void);
EXPORT void HWRAPI(ProjectUI)(int width, int height);
#define SCREENVERTS 10
EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]);
......@@ -119,6 +124,7 @@ struct hwdriver_s
MakeScreenTexture pfnMakeScreenTexture;
MakeScreenFinalTexture pfnMakeScreenFinalTexture;
DrawScreenFinalTexture pfnDrawScreenFinalTexture;
MakeViewTexture pfnMakeViewTexture;
CompileShaders pfnCompileShaders;
CleanShaders pfnCleanShaders;
......@@ -127,6 +133,10 @@ struct hwdriver_s
SetShaderInfo pfnSetShaderInfo;
LoadCustomShader pfnLoadCustomShader;
SetEye pfnSetEye;
SubmitTextureToHMD pfnSubmitTextureToHMD;
ProjectUI pfnProjectUI;
};
extern struct hwdriver_s hwdriver;
......
......@@ -42,6 +42,7 @@
#include "../d_main.h"
#include "../p_slopes.h"
#include "hw_md2.h"
#include "../openvr/openvr_common.h"
#ifdef NEWCLIP
#include "hw_clip.h"
......@@ -172,6 +173,8 @@ boolean gl_maploaded = false;
boolean gl_sessioncommandsadded = false;
boolean gl_shadersavailable = true;
boolean is_drawing_sky = false;
// ==========================================================================
// Lighting
// ==========================================================================
......@@ -5876,6 +5879,8 @@ void HWR_BuildSkyDome(void)
static void HWR_DrawSkyBackground(player_t *player)
{
if(cv_vrcomfortmode.value) return;
HWD.pfnSetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated);
if (cv_glskydome.value)
......@@ -6039,6 +6044,15 @@ static inline void HWR_ClearView(void)
// HWD.pfnGClipRect(0, 0, vid.width, vid.height);
}
// -----------------+
// HWR_SetEye : set vr eye frame buffer
// -----------------+
void HWR_SetEye(int eye)
{
HWD.pfnSetEye(eye);
}
// -----------------+
// HWR_SetViewSize : set projection and scaling values
......@@ -6216,7 +6230,15 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player)
{
angle_t a1 = gld_FrustumAngle(gl_aimingangle);
gld_clipper_Clear();
// Modify the viewangle based on the HMD's look direction.
// Use atan2 to get the angle (in radians) from HMD pose,
// then normalize and multiply by ANGLE_MAX so the game can use it.
if(openvr_started && cv_vrspriterotate.value)
{
viewangle -= ANGLE_MAX * atan2(vrHMDPoseMatrix[8], vrHMDPoseMatrix[0]) / M_PI * 0.5;
}
gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1);
#ifdef HAVE_SPHEREFRUSTRUM
gld_FrustrumSetup();
#endif
......@@ -6333,6 +6355,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
if (viewnumber == 0) // Only do it if it's the first screen being rendered
HWD.pfnClearBuffer(true, false, &ClearColor); // Clear the Color Buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs.
is_drawing_sky = true;
PS_START_TIMING(ps_hw_skyboxtime);
if (skybox && drawsky) // If there's a skybox and we should be drawing the sky, draw the skybox
HWR_RenderSkyboxView(viewnumber, player); // This is drawn before everything else so it is placed behind
......@@ -6348,6 +6371,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
HWR_SetLights(viewnumber);
#endif
}
is_drawing_sky = false;
// note: sets viewangle, viewx, viewy, viewz
R_SetupFrame(player);
......@@ -6417,8 +6441,10 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
//------------------------------------------------------------------------
HWR_ClearView(); // Clears the depth buffer and resets the view I believe
is_drawing_sky = true;
if (!skybox && drawsky) // Don't draw the regular sky if there's a skybox
HWR_DrawSkyBackground(player);
is_drawing_sky = false;
//Hurdler: it doesn't work in splitscreen mode
drawsky = splitscreen;
......@@ -6432,11 +6458,18 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
{
angle_t a1 = gld_FrustumAngle(gl_aimingangle);
gld_clipper_Clear();
// Modify the viewangle based on the HMD's look direction.
// Use atan2 to get the angle (in radians) from HMD pose,
// then normalize and multiply by ANGLE_MAX so the game can use it.
if(openvr_started && cv_vrspriterotate.value)
{
viewangle -= ANGLE_MAX * atan2(vrHMDPoseMatrix[8], vrHMDPoseMatrix[0]) / M_PI * 0.5;
gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1);
#ifdef HAVE_SPHEREFRUSTRUM
gld_FrustrumSetup();
#endif
}
}
#else
HWR_ClearClipSegs();
#endif
......@@ -6535,6 +6568,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
// added by Hurdler for correct splitscreen
// moved here by hurdler so it works with the new near clipping plane
HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE);
if(openvr_started) HWD.pfnMakeViewTexture();
}
void HWR_LoadLevel(void)
......@@ -6950,6 +6984,9 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum)
return;
HWR_GetFadeMask(wipelumpnum);
if(openvr_started)
openvr_compositor()->ClearLastSubmittedFrame();
HWD.pfnDoScreenWipe();
}
......@@ -6969,6 +7006,16 @@ void HWR_DrawScreenFinalTexture(int width, int height)
HWD.pfnDrawScreenFinalTexture(width, height);
}
void HWR_SubmitTextureToHMD(void)
{
HWD.pfnSubmitTextureToHMD();
}
void HWR_ProjectUI(int width, int height)
{
HWD.pfnProjectUI(width, height);
}
static inline UINT16 HWR_FindShaderDefs(UINT16 wadnum)
{
UINT16 i;
......
......@@ -38,6 +38,7 @@ void HWR_BuildSkyDome(void);
void HWR_DrawViewBorder(INT32 clearlines);
void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum);
void HWR_InitTextureMapping(void);
void HWR_SetEye(int eye);
void HWR_SetViewSize(void);
void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option);
void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap);
......@@ -75,6 +76,9 @@ FBITFIELD HWR_GetBlendModeFlag(INT32 style);
FBITFIELD HWR_SurfaceBlend(INT32 style, INT32 transtablenum, FSurfaceInfo *pSurf);
FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf);
void HWR_SubmitTextureToHMD(void);
void HWR_ProjectUI(int width, int height);
boolean HWR_CompileShaders(void);
void HWR_LoadAllCustomShaders(void);
......
......@@ -24,6 +24,8 @@
#include "../../r_local.h" // For rendertimefrac, used for the leveltime shader uniform
#include "r_opengl.h"
#include "r_vbo.h"
#include "../../openvr/openvr_common.h"
extern boolean is_drawing_sky;
#if defined (HWRENDER) && !defined (NOROPENGL)
......@@ -71,6 +73,7 @@ GLint screen_width = 0; // used by Draw2DLine()
GLint screen_height = 0;
GLbyte screen_depth = 0;
GLint textureformatGL = 0;
GLint texture_size_squared = 0;
GLint maximumAnisotropy = 0;
static GLboolean MipMap = GL_FALSE;
static GLint min_filter = GL_LINEAR;
......@@ -95,6 +98,8 @@ static GLuint screentexture = 0;
static GLuint startScreenWipe = 0;
static GLuint endScreenWipe = 0;
static GLuint finalScreenTexture = 0;
static GLuint uiTexture = 0;
static GLuint viewTexture = 0;
// shortcut for ((float)1/i)
static const GLfloat byte2float[256] = {
......@@ -248,7 +253,9 @@ static void GL_MSG_Error(const char *format, ...)
#define pglTexCoordPointer glTexCoordPointer
#define pglColorPointer glColorPointer
#define pglDrawArrays glDrawArrays
#define pglDrawArraysInstanced glDrawArraysInstanced
#define pglDrawElements glDrawElements
#define pglDrawElementsInstanced glDrawElementsInstanced
#define pglEnableClientState glEnableClientState
#define pglDisableClientState glDisableClientState
......@@ -346,8 +353,12 @@ typedef void (APIENTRY * PFNglColorPointer) (GLint size, GLenum type, GLsizei st
static PFNglColorPointer pglColorPointer;
typedef void (APIENTRY * PFNglDrawArrays) (GLenum mode, GLint first, GLsizei count);
static PFNglDrawArrays pglDrawArrays;
typedef void (APIENTRY * PFNglDrawArraysInstanced) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount);
static PFNglDrawArraysInstanced pglDrawArraysInstanced;
typedef void (APIENTRY * PFNglDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
static PFNglDrawElements pglDrawElements;
typedef void (APIENTRY * PFNglDrawElementsInstanced) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount);
static PFNglDrawElementsInstanced pglDrawElementsInstanced;
typedef void (APIENTRY * PFNglEnableClientState) (GLenum cap);
static PFNglEnableClientState pglEnableClientState;
typedef void (APIENTRY * PFNglDisableClientState) (GLenum cap);
......@@ -554,6 +565,8 @@ typedef void (APIENTRY *PFNglUniform4f) (GLint, GLfloat, GLfloat, GLfloat, GL
typedef void (APIENTRY *PFNglUniform1fv) (GLint, GLsizei, const GLfloat*);
typedef void (APIENTRY *PFNglUniform2fv) (GLint, GLsizei, const GLfloat*);
typedef void (APIENTRY *PFNglUniform3fv) (GLint, GLsizei, const GLfloat*);
typedef void (APIENTRY *PFNglUniform4fv) (GLint, GLsizei, const GLfloat*);
typedef void (APIENTRY *PFNglUniformMatrix4fv) (GLint,GLsizei,GLboolean,const GLfloat*);
typedef GLint (APIENTRY *PFNglGetUniformLocation) (GLuint, const GLchar*);
static PFNglCreateShader pglCreateShader;
......@@ -576,6 +589,8 @@ static PFNglUniform4f pglUniform4f;
static PFNglUniform1fv pglUniform1fv;
static PFNglUniform2fv pglUniform2fv;
static PFNglUniform3fv pglUniform3fv;
static PFNglUniform4fv pglUniform4fv;
static PFNglUniformMatrix4fv pglUniformMatrix4fv;
static PFNglGetUniformLocation pglGetUniformLocation;
// 13062019
......@@ -591,6 +606,16 @@ typedef enum
// misc. (custom shaders)
gluniform_leveltime,
//openVR eye-view matrix
gluniform_evm,
gluniform_evm0,
gluniform_evm1,
//openvr eye-projection matrix
gluniform_epm,
gluniform_epm0,
gluniform_epm1,
//openvr head-pose matrix
gluniform_hpm,
gluniform_max,
} gluniform_t;
......@@ -643,6 +668,44 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
"gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \
"}\0"
#define GLSL_VR_VERTEX_SHADER \
"uniform mat4 vrEyeMatrix[2];\n" \
"uniform mat4 vrEyeProjection[2];\n" \
"uniform mat4 vrHeadPoseMatrix;\n" \
"void main()\n" \
"{\n" \
"float offset[2] = float[2](0.5, -0.5);\n"\
"vec4 clipEdge[2] = vec4[2](vec4(1,0,0,1), vec4(-1,0,0,1));\n"\
"int eye = gl_InstanceID & 1;\n"\
"gl_Position = vrEyeProjection[eye] * vrEyeMatrix[eye] * vrHeadPoseMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \
"gl_Position.x *= 0.5;\n"\
"gl_Position.x += offset[eye] * gl_Position.w;\n"\
"gl_ClipDistance[0] = gl_Position * clipEdge[eye];\n"\
"gl_FrontColor = gl_Color;\n" \
"gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \
"//gl_ClipVertex = vrEyeMatrix * vrHeadPoseMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \
"}\0"
#define GLSL_VR_LIGHTING_VERTEX_SHADER \
"uniform mat4 vrEyeMatrix[2];\n" \
"uniform mat4 vrEyeProjection[2];\n" \
"uniform mat4 vrHeadPoseMatrix;\n" \
"void main()\n" \
"{\n" \
"float nDotVP = dot(gl_Normal, vec3(0, 1, 0));\n" \
"float light = 0.75 + max(nDotVP, 0.0);\n" \
"float offset[2] = float[2](0.5, -0.5);\n"\
"vec4 clipEdge[2] = vec4[2](vec4(1,0,0,1), vec4(-1,0,0,1));\n"\
"int eye = gl_InstanceID & 1;\n"\
"gl_Position = vrEyeProjection[eye] * vrEyeMatrix[eye] * vrHeadPoseMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \
"gl_Position.x *= 0.5;\n"\
"gl_Position.x += offset[eye] * gl_Position.w;\n"\
"gl_ClipDistance[0] = gl_Position * clipEdge[eye];\n"\
"gl_FrontColor = vec4(light, light, light, 1.0);\n" \
"gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \
"//gl_ClipVertex = vrEyeMatrix * vrHeadPoseMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \
"}\0"
// replicates the way fixed function lighting is used by the model lighting option,
// stores the lighting result to gl_Color
// (ambient lighting of 0.75 and diffuse lighting from above)
......@@ -828,11 +891,14 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f};
// ================
// Shader sources
// ================
static struct {
// Shader sources (vertex and fragment)
typedef struct
{
const char *vertex;
const char *fragment;
} const gl_shadersources[] = {
} shadersourcero_t;
static const shadersourcero_t gl_shadersources[] = {
// Default shader
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_DEFAULT_FRAGMENT_SHADER},
......@@ -863,6 +929,37 @@ static struct {
{NULL, NULL},
};
static shadersourcero_t gl_vrshadersources[] = {
// Default shader
{GLSL_VR_VERTEX_SHADER, GLSL_DEFAULT_FRAGMENT_SHADER},
// Floor shader
{GLSL_VR_VERTEX_SHADER, GLSL_SOFTWARE_FRAGMENT_SHADER},
// Wall shader
{GLSL_VR_VERTEX_SHADER, GLSL_SOFTWARE_FRAGMENT_SHADER},
// Sprite shader
{GLSL_VR_VERTEX_SHADER, GLSL_SOFTWARE_FRAGMENT_SHADER},
// Model shader
{GLSL_VR_VERTEX_SHADER, GLSL_SOFTWARE_FRAGMENT_SHADER},
// Model shader + diffuse lighting from above
{GLSL_VR_LIGHTING_VERTEX_SHADER, GLSL_SOFTWARE_MODEL_LIGHTING_FRAGMENT_SHADER},
// Water shader
{GLSL_VR_VERTEX_SHADER, GLSL_WATER_FRAGMENT_SHADER},
// Fog shader
{GLSL_VR_VERTEX_SHADER, GLSL_FOG_FRAGMENT_SHADER},
// Sky shader
{GLSL_VR_VERTEX_SHADER, GLSL_SKY_FRAGMENT_SHADER},
{NULL, NULL},
};
#endif // GL_SHADERS
void SetupGLFunc4(void)
......@@ -902,17 +999,23 @@ void SetupGLFunc4(void)
pglUniform1fv = GetGLFunc("glUniform1fv");
pglUniform2fv = GetGLFunc("glUniform2fv");
pglUniform3fv = GetGLFunc("glUniform3fv");
pglUniform4fv = GetGLFunc("glUniform4fv");
pglGetUniformLocation = GetGLFunc("glGetUniformLocation");
#endif
// GLU
pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps");
// Instanced rendering for VR
pglDrawArraysInstanced = GetGLFunc("glDrawArraysInstanced");
pglDrawElementsInstanced = GetGLFunc("glDrawElementsInstanced");
}
EXPORT boolean HWRAPI(CompileShaders) (void)
{
#ifdef GL_SHADERS
GLint i;
const shadersourcero_t *sources = openvr_started ? gl_vrshadersources : gl_shadersources;
if (!pglUseProgram)
return false;
......@@ -920,11 +1023,11 @@ EXPORT boolean HWRAPI(CompileShaders) (void)
gl_customshaders[SHADER_DEFAULT].vertex = NULL;
gl_customshaders[SHADER_DEFAULT].fragment = NULL;
for (i = 0; gl_shadersources[i].vertex && gl_shadersources[i].fragment; i++)
for (i = 0; sources[i].vertex && sources[i].fragment; i++)
{
gl_shader_t *shader, *usershader;
const GLchar *vert_shader = gl_shadersources[i].vertex;
const GLchar *frag_shader = gl_shadersources[i].fragment;
const GLchar *vert_shader = sources[i].vertex;
const GLchar *frag_shader = sources[i].fragment;
if (i >= HWR_MAXSHADERS)
break;
......@@ -1546,7 +1649,7 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1,
pglDisableClientState(GL_TEXTURE_COORD_ARRAY);
pglColor4ubv((GLubyte*)&Color.s);
pglVertexPointer(3, GL_FLOAT, 0, p);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, openvr_started + 1);
pglEnableClientState(GL_TEXTURE_COORD_ARRAY);
pglEnable(GL_TEXTURE_2D);
......@@ -2055,6 +2158,38 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
UNIFORM_1(shader->uniforms[gluniform_leveltime], shader_leveltime, pglUniform1f);
if(openvr_started)
{
float*eyeposematrix[2];
float*headposematrix;
if(is_drawing_sky)
{
eyeposematrix[0] = vrEyeSkyboxViewMatrix[0];
eyeposematrix[1] = vrEyeSkyboxViewMatrix[1];
headposematrix = vrHMDPoseSkyboxMatrix;
}
else
{
eyeposematrix[0] = vrScaledEyeViewMatrix[0];
eyeposematrix[1] = vrScaledEyeViewMatrix[1];
headposematrix = vrHMDScaledPoseMatrix;
}
if(shader->uniforms[gluniform_evm0] != -1)
{
pglUniformMatrix4fv(shader->uniforms[gluniform_evm0], 1, false, eyeposematrix[0]);
pglUniformMatrix4fv(shader->uniforms[gluniform_evm1], 1, false, eyeposematrix[1]);
}
if(shader->uniforms[gluniform_hpm] != -1)
pglUniformMatrix4fv(shader->uniforms[gluniform_hpm], 1, false, headposematrix);
if(shader->uniforms[gluniform_epm0] != -1)
{
pglUniformMatrix4fv(shader->uniforms[gluniform_epm0], 1, false, vrEyeProjMatrix[0]);
pglUniformMatrix4fv(shader->uniforms[gluniform_epm1], 1, false, vrEyeProjMatrix[1]);
}
}
#undef UNIFORM_1
#undef UNIFORM_2
#undef UNIFORM_3
......@@ -2151,6 +2286,15 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i, const GLchar
shader->uniforms[gluniform_fade_start] = GETUNI("fade_start");
shader->uniforms[gluniform_fade_end] = GETUNI("fade_end");
//VR
shader->uniforms[gluniform_hpm] = GETUNI("vrHeadPoseMatrix");
shader->uniforms[gluniform_evm] = GETUNI("vrEyeMatrix");
shader->uniforms[gluniform_epm] = GETUNI("vrEyeProjection");
shader->uniforms[gluniform_evm0] = GETUNI("vrEyeMatrix[0]");
shader->uniforms[gluniform_epm0] = GETUNI("vrEyeProjection[0]");
shader->uniforms[gluniform_evm1] = GETUNI("vrEyeMatrix[1]");
shader->uniforms[gluniform_epm1] = GETUNI("vrEyeProjection[1]");
// misc. (custom shaders)
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
......@@ -2296,7 +2440,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
pglDrawArrays(PolyFlags & PF_WireFrame ? GL_LINES : GL_TRIANGLE_FAN, 0, iNumPts);
pglDrawArraysInstanced(PolyFlags & PF_WireFrame ? GL_LINES : GL_TRIANGLE_FAN, 0, iNumPts, openvr_started + 1);
if (PolyFlags & PF_RemoveYWrap)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
......@@ -2314,7 +2458,7 @@ EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutV
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
pglDrawElements(GL_TRIANGLES, iNumPts, GL_UNSIGNED_INT, IndexArray);
pglDrawElementsInstanced(GL_TRIANGLES, iNumPts, GL_UNSIGNED_INT, IndexArray, openvr_started + 1);
// the DrawPolygon variant of this has some code about polyflags and wrapping here but havent noticed any problems from omitting it?
}
......@@ -2326,7 +2470,7 @@ static const boolean gl_ext_arb_vertex_buffer_object = true;
#define sky_vbo_u (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->u : &sky->data[0].u)
#define sky_vbo_r (gl_ext_arb_vertex_buffer_object ? &NULL_VBO_VERTEX->r : &sky->data[0].r)
EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky)
static void RenderSkyDome2(gl_sky_t *sky)
{
int i, j;
......@@ -2395,7 +2539,7 @@ EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky)
continue;
}
pglDrawArrays(mode, loop->vertexindex, loop->vertexcount);
pglDrawArraysInstanced(mode, loop->vertexindex, loop->vertexcount, openvr_started + 1);
}
}
......@@ -2410,6 +2554,15 @@ EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky)
pglDisableClientState(GL_COLOR_ARRAY);
}
EXPORT void HWRAPI(RenderSkyDome) (gl_sky_t *sky)
{
boolean skybox = is_drawing_sky;
is_drawing_sky = true;
RenderSkyDome2(sky);
is_drawing_sky = skybox;
}
// ==========================================================================
//
// ==========================================================================
......@@ -2854,7 +3007,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float
pglNormalPointer(GL_BYTE, sizeof(vbotiny_t), BUFFER_OFFSET(sizeof(short)*3));
pglTexCoordPointer(2, GL_FLOAT, sizeof(vbotiny_t), BUFFER_OFFSET(sizeof(short) * 3 + sizeof(char) * 6));
pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices);
pglDrawElementsInstanced(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices, openvr_started + 1);
pglBindBuffer(GL_ARRAY_BUFFER, 0);
}
else
......@@ -2862,7 +3015,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float
pglVertexPointer(3, GL_SHORT, 0, frame->vertices);
pglNormalPointer(GL_BYTE, 0, frame->normals);
pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs);
pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices);
pglDrawElementsInstanced(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices, openvr_started + 1);
}
}
else
......@@ -2886,7 +3039,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float
pglVertexPointer(3, GL_SHORT, 0, vertTinyBuffer);
pglNormalPointer(GL_BYTE, 0, normTinyBuffer);
pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs);
pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices);
pglDrawElementsInstanced(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices, openvr_started + 1);
}
}
else
......@@ -2906,7 +3059,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float
pglNormalPointer(GL_FLOAT, sizeof(vbo64_t), BUFFER_OFFSET(sizeof(float) * 3));
pglTexCoordPointer(2, GL_FLOAT, sizeof(vbo64_t), BUFFER_OFFSET(sizeof(float) * 6));
pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3);
pglDrawArraysInstanced(GL_TRIANGLES, 0, mesh->numTriangles * 3, openvr_started + 1);
// No tinyframes, no mesh indices
//pglDrawElements(GL_TRIANGLES, mesh->numTriangles * 3, GL_UNSIGNED_SHORT, mesh->indices);
pglBindBuffer(GL_ARRAY_BUFFER, 0);
......@@ -2916,7 +3069,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float
pglVertexPointer(3, GL_FLOAT, 0, frame->vertices);
pglNormalPointer(GL_FLOAT, 0, frame->normals);
pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs);
pglDrawArrays(GL_TRIANGLES, 0, mesh->numTriangles * 3);
pglDrawArraysInstanced(GL_TRIANGLES, 0, mesh->numTriangles * 3, openvr_started + 1);
}
}
else
......@@ -2941,7 +3094,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float
pglVertexPointer(3, GL_FLOAT, 0, vertBuffer);
pglNormalPointer(GL_FLOAT, 0, normBuffer);
pglTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs);
pglDrawArrays(GL_TRIANGLES, 0, mesh->numVertices);
pglDrawArraysInstanced(GL_TRIANGLES, 0, mesh->numVertices, openvr_started + 1);
}
}
}
......@@ -3094,7 +3247,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2])
pglColor4ubv(white);
pglVertexPointer(3, GL_FLOAT, 0, blackBack);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, openvr_started + 1);
pglEnableClientState(GL_TEXTURE_COORD_ARRAY);
for(x=0;x<SCREENVERTS-1;x++)
......@@ -3140,7 +3293,7 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2])
pglVertexPointer(3, GL_FLOAT, 0, vertCoords);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, openvr_started + 1);
}
}
......@@ -3156,10 +3309,15 @@ EXPORT void HWRAPI(FlushScreenTextures) (void)
pglDeleteTextures(1, &startScreenWipe);
pglDeleteTextures(1, &endScreenWipe);
pglDeleteTextures(1, &finalScreenTexture);
pglDeleteTextures(1, &viewTexture);
pglDeleteTextures(1, &uiTexture);
screentexture = 0;
startScreenWipe = 0;
endScreenWipe = 0;
finalScreenTexture = 0;
viewTexture = 0;
uiTexture = 0;
}
// Create Screen to fade from
......@@ -3268,7 +3426,7 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void)
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
pglVertexPointer(3, GL_FLOAT, 0, screenVerts);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, openvr_started + 1);
tex_downloaded = screentexture;
}
......@@ -3330,7 +3488,7 @@ EXPORT void HWRAPI(DoScreenWipe)(void)
pglColor4ubv(white);
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
pglVertexPointer(3, GL_FLOAT, 0, screenVerts);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, openvr_started + 1);
SetBlend(PF_Modulated|PF_Translucent|PF_NoDepthTest);
......@@ -3354,7 +3512,7 @@ EXPORT void HWRAPI(DoScreenWipe)(void)
pglClientActiveTexture(GL_TEXTURE1);
pglEnableClientState(GL_TEXTURE_COORD_ARRAY);
pglTexCoordPointer(2, GL_FLOAT, 0, defaultST);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, openvr_started + 1);
pglDisable(GL_TEXTURE_2D); // disable the texture in the 2nd texture unit
pglDisableClientState(GL_TEXTURE_COORD_ARRAY);
......@@ -3364,8 +3522,65 @@ EXPORT void HWRAPI(DoScreenWipe)(void)
tex_downloaded = endScreenWipe;
}
#define MAKETEXTURE(texture, format)\
INT32 texsize = 512;\
boolean firstTime = (texture == 0);\
/* look for power of two that is large enough for the screen*/\
while (texsize < screen_width || texsize < screen_height)\
texsize <<= 1;\
/*Create screen texture*/\
if (firstTime)\
pglGenTextures(1, &texture);\
pglBindTexture(GL_TEXTURE_2D, texture);\
if (firstTime)\
{\
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\
Clamp2D(GL_TEXTURE_WRAP_S);\
Clamp2D(GL_TEXTURE_WRAP_T);\
pglCopyTexImage2D(GL_TEXTURE_2D, 0, format, 0, 0, texsize, texsize, 0);\
}\
else\
pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize);\
tex_downloaded = texture;\
EXPORT void HWRAPI(MakeViewTexture) (void)
{
if(openvr_started)
{
FRGBAFloat clearColour;
MAKETEXTURE(viewTexture, GL_RGB);
clearColour.alpha = 0; clearColour.red = clearColour.green = clearColour.blue = 1;
ClearBuffer(true, true, &clearColour);
}
}
// Create a texture from the screen.
EXPORT void HWRAPI(MakeScreenTexture) (void)
{
MAKETEXTURE(screentexture, GL_RGB);
}
EXPORT void HWRAPI(MakeScreenFinalTexture) (void)
{
MAKETEXTURE(finalScreenTexture,
#ifdef _WIN32
GL_RGBA
#else
GL_RGB
#endif
);
}
static void MakeUITexture(void)
{
FRGBAFloat clearColour;
MAKETEXTURE(uiTexture, GL_RGBA);
clearColour.alpha = clearColour.red = clearColour.green = clearColour.blue = 0;
ClearBuffer(true, true, &clearColour);
}
/*// Create a texture from the screen.
EXPORT void HWRAPI(MakeScreenTexture) (void)
{
INT32 texsize = 2048;
boolean firstTime = (screentexture == 0);
......@@ -3395,6 +3610,7 @@ EXPORT void HWRAPI(MakeScreenTexture) (void)
tex_downloaded = screentexture;
}
EXPORT void HWRAPI(MakeScreenFinalTexture) (void)
{
INT32 texsize = 2048;
......@@ -3423,7 +3639,7 @@ EXPORT void HWRAPI(MakeScreenFinalTexture) (void)
pglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize);
tex_downloaded = finalScreenTexture;
}
}*/
EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
{
......@@ -3431,15 +3647,17 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
float origaspect, newaspect;
float xoff = 1, yoff = 1; // xoffset and yoffset for the polygon to have black bars around the screen
FRGBAFloat clearColour;
INT32 texsize = 2048;
INT32 texsize = 512;
float off[12];
float fix[8];
if(screen_width <= 1024)
texsize = 1024;
if(screen_width <= 512)
texsize = 512;
// look for power of two that is large enough for the screen
while (texsize < screen_width || texsize < screen_height)
texsize <<= 1;
// need this for VR. have to calculate the empty space to clip out
texture_size_squared = texsize;
xfix = 1/((float)(texsize)/((float)((screen_width))));
yfix = 1/((float)(texsize)/((float)((screen_height))));
......@@ -3493,8 +3711,180 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height)
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
pglVertexPointer(3, GL_FLOAT, 0, off);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, openvr_started + 1);
tex_downloaded = finalScreenTexture;
}
// This only gets called in VR mode to project the UI into world space
// and copy the results of renderplayerview back into the main framebuffer.
EXPORT void HWRAPI(ProjectUI)(int width, int height)
{
float xfix, yfix;
float origaspect, newaspect;
float xoff = 1, yoff = 1; // xoffset and yoffset for the polygon to have black bars around the screen
FRGBAFloat clearColour;
INT32 texsize = 512;
//HiddenAreaMesh_t*area = &openvr_visible_area[openvr_current_eye];
float off[12];
float fix[8];
//if (!gl_enable_screen_textures) return;
MakeUITexture();
// look for power of two that is large enough for the screen
while (texsize < screen_width || texsize < screen_height)
texsize <<= 1;
// need this for VR. have to calculate the empty space to clip out
texture_size_squared = texsize;
xfix = 1/((float)(texsize)/((float)((screen_width))));
yfix = 1/((float)(texsize)/((float)((screen_height))));
origaspect = (float)screen_width / screen_height;
newaspect = (float)width / height;
if (origaspect < newaspect)
{
xoff = origaspect / newaspect;
yoff = 1;
}
else if (origaspect > newaspect)
{
xoff = 1;
yoff = newaspect / origaspect;
}
//if(!area->unTriangleCount)
{
off[0] = -xoff;
off[1] = -yoff;
off[2] = 1.0f;
off[3] = -xoff;
off[4] = yoff;
off[5] = 1.0f;
off[6] = xoff;
off[7] = yoff;
off[8] = 1.0f;
off[9] = xoff;
off[10] = -yoff;
off[11] = 1.0f;
}
fix[0] = 0.0f;
fix[1] = 0.0f;
fix[2] = 0.0f;
fix[3] = yfix;
fix[4] = xfix;
fix[5] = yfix;
fix[6] = xfix;
fix[7] = 0.0f;
pglViewport(0, 0, width, height);
clearColour.red = clearColour.green = clearColour.blue = 0;
clearColour.alpha = 1;
ClearBuffer(true, false, &clearColour);
pglBindTexture(GL_TEXTURE_2D, viewTexture);
pglColor4ubv(white);
/*if(area->unTriangleCount)
{
pglTexCoordPointer(2, GL_FLOAT, 0, vrVisibleAreaUVs[openvr_current_eye]);
pglVertexPointer(3, GL_FLOAT, 0, vrVisibleAreaVertices[openvr_current_eye]);
if(gamestate == GS_LEVEL)
pglDrawArrays(GL_TRIANGLES, 0, area->unTriangleCount*3);
}
else*/
{
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
pglVertexPointer(3, GL_FLOAT, 0, off);
if(gamestate == GS_LEVEL)
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
{
gl_shader_t *shader = &gl_shaders[8];//gl_shaderstate.current;
//gl_shaderprogram_t *shader = &gl_shadersources[7];
pglUseProgram(shader->program);
if(shader->uniforms[gluniform_evm0] != -1)
{
pglUniformMatrix4fv(shader->uniforms[gluniform_evm0], 1, false, vrEyeViewMatrix[0]);
pglUniformMatrix4fv(shader->uniforms[gluniform_evm1], 1, false, vrEyeViewMatrix[1]);
}
if(shader->uniforms[gluniform_hpm] != -1)
pglUniformMatrix4fv(shader->uniforms[gluniform_hpm], 1, false, vrHMDPoseMatrix);
if(shader->uniforms[gluniform_epm0] != -1)
{
pglUniformMatrix4fv(shader->uniforms[gluniform_epm0], 1, false, vrEyeProjMatrix[0]);
pglUniformMatrix4fv(shader->uniforms[gluniform_epm1], 1, false, vrEyeProjMatrix[1]);
}
}
pglBindTexture(GL_TEXTURE_2D, uiTexture);
off[ 0] =-xoff * cv_vruiscale.value;
off[ 1] =-yoff * cv_vruiscale.value;
off[ 3] =-xoff * cv_vruiscale.value;
off[ 4] = yoff * cv_vruiscale.value;
off[ 6] = xoff * cv_vruiscale.value;
off[ 7] = yoff * cv_vruiscale.value;
off[ 9] = xoff * cv_vruiscale.value;
off[10] =-yoff * cv_vruiscale.value;
off[2] = off[5] = off[8] = off[11] = cv_vruidistance.value;
pglVertexPointer(3, GL_FLOAT, 0, off);
SetBlend(PF_Translucent);
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
pglUseProgram(0);
gl_shaderstate.program = 0;
gl_shaderstate.changed = true;
}
EXPORT void HWRAPI(SubmitTextureToHMD)(void)
{
VRTextureBounds_t vrBounds, vrBoundsRight;
Texture_t vrTexture;
EVRCompositorError error = EVRCompositorError_VRCompositorError_None;
float screenspaceWidth = screen_width / (float)texture_size_squared;
float screenspaceHeight = screen_height / (float)texture_size_squared;
vrTexture.handle = (void*)(uintptr_t)finalScreenTexture;
vrTexture.eType = ETextureType_TextureType_OpenGL;
vrTexture.eColorSpace = EColorSpace_ColorSpace_Gamma;
vrBounds.uMin = 0;
vrBounds.vMin = 1.0 - screenspaceHeight;
vrBounds.uMax = screenspaceWidth / 2.;
vrBounds.vMax = vrBounds.vMin + screenspaceHeight;
vrBoundsRight.uMin = screenspaceWidth / 2.;
vrBoundsRight.vMin = 1.0 - screenspaceHeight;
vrBoundsRight.uMax = screenspaceWidth;
vrBoundsRight.vMax = vrBoundsRight.vMin + screenspaceHeight;
if((error = openvr_compositor()->Submit(0, &vrTexture, &vrBoundsRight, EVRSubmitFlags_Submit_Default)) != EVRCompositorError_VRCompositorError_None)
sprintf(vrPendingErrorMessage, "VR Compositor Submit Frame [LEFT EYE] ERROR: %d\n", (int)error);
if((error = openvr_compositor()->Submit(1, &vrTexture, &vrBounds, EVRSubmitFlags_Submit_Default)) != EVRCompositorError_VRCompositorError_None)
sprintf(vrPendingErrorMessage, "VR Compositor Submit Frame [RIGHT EYE] ERROR: %d\n", (int)error);
}
EXPORT void HWRAPI(SetEye)(int eye)
{
// DEPRECATED
//openvr_current_eye = eye;
(void)eye;
openvr_current_eye = 0;
}
#endif //HWRENDER
......@@ -51,6 +51,12 @@ void I_StartupGraphics(void);
/** \brief shutdown video mode
*/
void I_ShutdownGraphics(void);
#ifdef HWRENDER
void I_StartupVR(void);
void I_ChangeVRRenderSize(int mode);
void I_ChangeVRRenderScale(int mode);
void I_ShutdownVR(void);
#endif
/** \brief The I_SetPalette function
......
......@@ -326,7 +326,8 @@ static void M_VideoOptions(INT32 choice);
menu_t OP_VideoOptionsDef, OP_VideoModeDef, OP_ColorOptionsDef;
#ifdef HWRENDER
static void M_OpenGLOptionsMenu(void);
menu_t OP_OpenGLOptionsDef;
static void M_OpenVROptionsMenu(void);
menu_t OP_OpenGLOptionsDef, OP_VROptionsDef;
#ifdef ALAM_LIGHTING
menu_t OP_OpenGLLightingDef;
#endif // ALAM_LIGHTING
......@@ -1286,6 +1287,7 @@ enum
#endif
op_video_vsync,
op_video_renderer,
op_video_vr
};
static menuitem_t OP_VideoOptionsMenu[] =
......@@ -1343,7 +1345,8 @@ static menuitem_t OP_VideoOptionsMenu[] =
#ifdef HWRENDER
{IT_HEADER, NULL, "Renderer", NULL, 208},
{IT_CALL | IT_STRING, NULL, "OpenGL Options...", M_OpenGLOptionsMenu, 214},
{IT_STRING | IT_CVAR, NULL, "FPS Cap", &cv_fpscap, 219},
{IT_CALL | IT_STRING, NULL, "VR Options...", M_OpenVROptionsMenu, 219},
{IT_STRING | IT_CVAR, NULL, "FPS Cap", &cv_fpscap, 224},
#endif
};
......@@ -1394,6 +1397,20 @@ static menuitem_t OP_ColorOptionsMenu[] =
};
#ifdef HWRENDER
static menuitem_t OP_VROptionsMenu[] =
{
{IT_STRING | IT_CVAR, NULL, "Virtual Reality", &cv_vrenabled, 10},
{IT_STRING | IT_CVAR, NULL, "World Scale", &cv_vrscale, 30},
{IT_STRING | IT_CVAR, NULL, "Scale World With Player", &cv_vrplayerscale, 40},
{IT_STRING | IT_CVAR, NULL, "UI Distance", &cv_vruidistance, 50},
{IT_STRING | IT_CVAR, NULL, "UI Scale", &cv_vruiscale, 60},
{IT_STRING | IT_CVAR, NULL, "Rotate Sprites With HMD", &cv_vrspriterotate, 70},
{IT_STRING | IT_CVAR, NULL, "Desktop Render Mode", &cv_vrviewmode, 80},
{IT_STRING | IT_CVAR, NULL, "Lock Camera Forward", &cv_glshearing, 90},
{IT_STRING | IT_CVAR, NULL, "Disable Skybox Stereoscopy", &cv_vrdisableskystereo, 100},
{IT_STRING | IT_CVAR, NULL, "Disable Skyboxes", &cv_vrcomfortmode, 110}
};
static menuitem_t OP_OpenGLOptionsMenu[] =
{
{IT_HEADER, NULL, "3D Models", NULL, 0},
......@@ -1418,6 +1435,18 @@ static menuitem_t OP_OpenGLOptionsMenu[] =
#endif
};
static void M_OpenVROptionsMenu(void)
{
if (rendermode == render_opengl)
M_SetupNextMenu(&OP_VROptionsDef);
else
M_StartMessage(M_GetText("You must be in OpenGL mode\nto access this menu.\n\n(Press a key)\n"), NULL, MM_NOTHING);
}
menu_t OP_VROptionsDef = DEFAULTMENUSTYLE(
MTREE3(MN_OP_MAIN, MN_OP_VIDEO, MN_OP_OPENVR),
"M_VIDEO", OP_VROptionsMenu, &OP_VideoOptionsDef, 30, 30);
#ifdef ALAM_LIGHTING
static menuitem_t OP_OpenGLLightingMenu[] =
{
......@@ -3911,6 +3940,14 @@ void M_Init(void)
quitmsg[QUIT3MSG5] = M_GetText("You'll be back to play soon, though...\n......right?\n\n(Press 'Y' to quit)");
quitmsg[QUIT3MSG6] = M_GetText("Aww, is Egg Rock Zone too\ndifficult for you?\n\n(Press 'Y' to quit)");
#ifdef HWRENDER
// Permanently hide some options based on render mode
if (rendermode == render_soft)
{
OP_VideoOptionsMenu[op_video_vr].status = IT_DISABLED;
}
#endif
/*
Well the menu sucks for forcing us to have an item set
at all if every item just calls the same function, and
......