# HG changeset patch # User John Tsiombikas # Date 1408541683 -10800 # Node ID 8b7da5ab814eb942ceecd1f4b44a4dad983b3945 # Parent e6948e131526a658d77c8ab425f0e5edc024da08 vr wrapper in progress diff -r e6948e131526 -r 8b7da5ab814e src/vr/vr.h --- a/src/vr/vr.h Wed Aug 20 06:33:43 2014 +0300 +++ b/src/vr/vr.h Wed Aug 20 16:34:43 2014 +0300 @@ -1,6 +1,11 @@ #ifndef VR_H_ #define VR_H_ +enum { + VR_EYE_LEFT, + VR_EYE_RIGHT +}; + #ifdef __cplusplus extern "C" { #endif @@ -14,17 +19,21 @@ int vr_use_module(int idx); int vr_use_module_named(const char *name); +/* if we're using a vr module which requires a specific output resolution, vr_display_size + * returns non-zero, and writes the size through the xsz/ysz pointers. Otherwise returns 0 + */ +int vr_display_size(int *xsz, int *ysz); +int vr_eye_texture_size(int eye, int *xsz, int *ysz); + /* returns non-zero if the active vr module provides this kind of matrix * information, otherwise it returns zero, and sets mat to identity */ int vr_view_matrix(int eye, float *mat); int vr_proj_matrix(int eye, float *mat); -/* fbtex should be a texture containing both eye views side by side (LR) */ -void vr_present(unsigned int fbtex); - -/* set the area of the framebuffer texture to be used */ -void vr_fbrect(float u, float umax, float v, float vmax); +void vr_begin(int eye); +void vr_end(void); +void vr_present(void); #ifdef __cplusplus } diff -r e6948e131526 -r 8b7da5ab814e src/vr/vr_impl.h --- a/src/vr/vr_impl.h Wed Aug 20 06:33:43 2014 +0300 +++ b/src/vr/vr_impl.h Wed Aug 20 16:34:43 2014 +0300 @@ -10,7 +10,9 @@ void (*view_matrix)(int eye, float *mat); void (*proj_matrix)(int eye, float *mat); - void (*draw)(unsigned int fbtex, float u, float maxu, float v, float maxv); + void (*begin)(int eye); + void (*end)(void); + void (*present)(void); }; void vr_init_modules(void); diff -r e6948e131526 -r 8b7da5ab814e src/vr/vr_libovr.c --- a/src/vr/vr_libovr.c Wed Aug 20 06:33:43 2014 +0300 +++ b/src/vr/vr_libovr.c Wed Aug 20 16:34:43 2014 +0300 @@ -1,12 +1,71 @@ +#ifdef WIN32 +#define OVR_OS_WIN32 +#endif + +#include +#include +#include +#include #include "vr_impl.h" +static ovrHmd hmd; + static int init(void) { - return -1; + int i, num_hmds; + union ovrGLConfig glcfg; + + if(!ovr_Initialize()) { + return -1; + } + printf("initialized LibOVR %s\n", ovr_GetVersionString()); + + if(!(num_hmds = ovrHmd_Detect())) { + ovr_Shutdown(); + return -1; + } + printf("%d Oculus HMD(s) found\n", num_hmds); + + hmd = 0; + for(i=0; iManufacturer, h->ProductName); + + if(!hmd) { + hmd = h; + } else { + ovrHmd_Destroy(h); + } + } + + if(!hmd) { + fprintf(stderr, "failed to initialize any Oculus HMDs\n"); + return -1; + } + + ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0); + + glcfg.OGL.Header.API = ovrRenderAPI_OpenGL; + glcfg.OGL.Header.RTSize = hmd->Resolution; + glcfg.OGL.Header.Multisample = 0; + glcfg.OGL.Window = 0; + glcfg.OGL.DC = 0; + + if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, eyes_fov, eye_rend_desc))) { + fprintf(stderr, "failed to configure LibOVR distortion renderer\n"); + return -1; + } } static void cleanup(void) { + if(hmd) { + ovrHmd_Destroy(hmd); + ovr_Destroy(); + } } static void view_matrix(int eye, float *mat) @@ -17,10 +76,19 @@ { } -static void draw(unsigned int fbtex, float u, float maxu, float v, float maxv) +static void begin(int eye) { } +static void end(void) +{ +} + +static void present(void) +{ +} + + struct vr_module *vr_module_libovr(void) { static struct vr_module m; @@ -31,7 +99,9 @@ m.cleanup = cleanup; m.view_matrix = view_matrix; m.proj_matrix = proj_matrix; - m.draw = draw; + m.begin = begin; + m.end = end; + m.present = present; } return &m; } diff -r e6948e131526 -r 8b7da5ab814e src/vr/vr_null.c --- a/src/vr/vr_null.c Wed Aug 20 06:33:43 2014 +0300 +++ b/src/vr/vr_null.c Wed Aug 20 16:34:43 2014 +0300 @@ -16,38 +16,6 @@ return 0; } -static void draw(unsigned int fbtex, float u, float maxu, float v, float maxv) -{ - glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT); - - glDisable(GL_LIGHTING); - glDisable(GL_DEPTH_TEST); - glDisable(GL_FOG); - glDisable(GL_CULL_FACE); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glBegin(GL_QUADS); - glTexCoord2f(u, v); - glVertex2f(-1, -1); - glTexCoord2f((u + maxu) / 2, v); - glVertex2f(1, -1); - glTexCoord2f((u + maxu) / 2, maxv); - glVertex2f(1, 1); - glTexCoord2f(u, maxv); - glVertex2f(-1, 1); - glEnd(); - - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - glPopAttrib(); -} - struct vr_module *vr_module_null(void) { static struct vr_module m; @@ -55,7 +23,6 @@ if(!m.init) { m.name = "null"; m.init = init; - m.draw = draw; } return &m; } diff -r e6948e131526 -r 8b7da5ab814e vrchess.vcxproj --- a/vrchess.vcxproj Wed Aug 20 06:33:43 2014 +0300 +++ b/vrchess.vcxproj Wed Aug 20 16:34:43 2014 +0300 @@ -87,6 +87,10 @@ + + + + @@ -95,6 +99,8 @@ + + diff -r e6948e131526 -r 8b7da5ab814e vrchess.vcxproj.filters --- a/vrchess.vcxproj.filters Wed Aug 20 06:33:43 2014 +0300 +++ b/vrchess.vcxproj.filters Wed Aug 20 16:34:43 2014 +0300 @@ -1,60 +1,73 @@  - + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;inl - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {e881ab02-1a45-43f6-a15d-ee7f77256a1e} - Source Files + src - Source Files + src - Source Files + src - Source Files + src - Source Files + src - Source Files + src - Source Files + src + + + src\vr + + + src\vr + + + src\vr + + + src\vr - Header Files + src + + + src + + + src + + + src - Header Files - - - Header Files - - - Header Files - - - Header Files + src - Header Files + src + + + src\vr + + + src\vr \ No newline at end of file