conworlds
changeset 5:8b7da5ab814e
vr wrapper in progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 20 Aug 2014 16:34:43 +0300 |
parents | e6948e131526 |
children | 3c36bc28c6c2 |
files | src/vr/vr.h src/vr/vr_impl.h src/vr/vr_libovr.c src/vr/vr_null.c vrchess.vcxproj vrchess.vcxproj.filters |
diffstat | 6 files changed, 137 insertions(+), 70 deletions(-) [+] |
line diff
1.1 --- a/src/vr/vr.h Wed Aug 20 06:33:43 2014 +0300 1.2 +++ b/src/vr/vr.h Wed Aug 20 16:34:43 2014 +0300 1.3 @@ -1,6 +1,11 @@ 1.4 #ifndef VR_H_ 1.5 #define VR_H_ 1.6 1.7 +enum { 1.8 + VR_EYE_LEFT, 1.9 + VR_EYE_RIGHT 1.10 +}; 1.11 + 1.12 #ifdef __cplusplus 1.13 extern "C" { 1.14 #endif 1.15 @@ -14,17 +19,21 @@ 1.16 int vr_use_module(int idx); 1.17 int vr_use_module_named(const char *name); 1.18 1.19 +/* if we're using a vr module which requires a specific output resolution, vr_display_size 1.20 + * returns non-zero, and writes the size through the xsz/ysz pointers. Otherwise returns 0 1.21 + */ 1.22 +int vr_display_size(int *xsz, int *ysz); 1.23 +int vr_eye_texture_size(int eye, int *xsz, int *ysz); 1.24 + 1.25 /* returns non-zero if the active vr module provides this kind of matrix 1.26 * information, otherwise it returns zero, and sets mat to identity 1.27 */ 1.28 int vr_view_matrix(int eye, float *mat); 1.29 int vr_proj_matrix(int eye, float *mat); 1.30 1.31 -/* fbtex should be a texture containing both eye views side by side (LR) */ 1.32 -void vr_present(unsigned int fbtex); 1.33 - 1.34 -/* set the area of the framebuffer texture to be used */ 1.35 -void vr_fbrect(float u, float umax, float v, float vmax); 1.36 +void vr_begin(int eye); 1.37 +void vr_end(void); 1.38 +void vr_present(void); 1.39 1.40 #ifdef __cplusplus 1.41 }
2.1 --- a/src/vr/vr_impl.h Wed Aug 20 06:33:43 2014 +0300 2.2 +++ b/src/vr/vr_impl.h Wed Aug 20 16:34:43 2014 +0300 2.3 @@ -10,7 +10,9 @@ 2.4 void (*view_matrix)(int eye, float *mat); 2.5 void (*proj_matrix)(int eye, float *mat); 2.6 2.7 - void (*draw)(unsigned int fbtex, float u, float maxu, float v, float maxv); 2.8 + void (*begin)(int eye); 2.9 + void (*end)(void); 2.10 + void (*present)(void); 2.11 }; 2.12 2.13 void vr_init_modules(void);
3.1 --- a/src/vr/vr_libovr.c Wed Aug 20 06:33:43 2014 +0300 3.2 +++ b/src/vr/vr_libovr.c Wed Aug 20 16:34:43 2014 +0300 3.3 @@ -1,12 +1,71 @@ 3.4 +#ifdef WIN32 3.5 +#define OVR_OS_WIN32 3.6 +#endif 3.7 + 3.8 +#include <stdio.h> 3.9 +#include <stdlib.h> 3.10 +#include <OVR_CAPI.h> 3.11 +#include <OVR_CAPI_GL.h> 3.12 #include "vr_impl.h" 3.13 3.14 +static ovrHmd hmd; 3.15 + 3.16 static int init(void) 3.17 { 3.18 - return -1; 3.19 + int i, num_hmds; 3.20 + union ovrGLConfig glcfg; 3.21 + 3.22 + if(!ovr_Initialize()) { 3.23 + return -1; 3.24 + } 3.25 + printf("initialized LibOVR %s\n", ovr_GetVersionString()); 3.26 + 3.27 + if(!(num_hmds = ovrHmd_Detect())) { 3.28 + ovr_Shutdown(); 3.29 + return -1; 3.30 + } 3.31 + printf("%d Oculus HMD(s) found\n", num_hmds); 3.32 + 3.33 + hmd = 0; 3.34 + for(i=0; i<num_hmds; i++) { 3.35 + ovrHmd h; 3.36 + if(!(h = ovrHmd_Create(i))) { 3.37 + break; 3.38 + } 3.39 + printf(" [%d]: %s - %s\n", h->Manufacturer, h->ProductName); 3.40 + 3.41 + if(!hmd) { 3.42 + hmd = h; 3.43 + } else { 3.44 + ovrHmd_Destroy(h); 3.45 + } 3.46 + } 3.47 + 3.48 + if(!hmd) { 3.49 + fprintf(stderr, "failed to initialize any Oculus HMDs\n"); 3.50 + return -1; 3.51 + } 3.52 + 3.53 + ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0); 3.54 + 3.55 + glcfg.OGL.Header.API = ovrRenderAPI_OpenGL; 3.56 + glcfg.OGL.Header.RTSize = hmd->Resolution; 3.57 + glcfg.OGL.Header.Multisample = 0; 3.58 + glcfg.OGL.Window = 0; 3.59 + glcfg.OGL.DC = 0; 3.60 + 3.61 + if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, eyes_fov, eye_rend_desc))) { 3.62 + fprintf(stderr, "failed to configure LibOVR distortion renderer\n"); 3.63 + return -1; 3.64 + } 3.65 } 3.66 3.67 static void cleanup(void) 3.68 { 3.69 + if(hmd) { 3.70 + ovrHmd_Destroy(hmd); 3.71 + ovr_Destroy(); 3.72 + } 3.73 } 3.74 3.75 static void view_matrix(int eye, float *mat) 3.76 @@ -17,10 +76,19 @@ 3.77 { 3.78 } 3.79 3.80 -static void draw(unsigned int fbtex, float u, float maxu, float v, float maxv) 3.81 +static void begin(int eye) 3.82 { 3.83 } 3.84 3.85 +static void end(void) 3.86 +{ 3.87 +} 3.88 + 3.89 +static void present(void) 3.90 +{ 3.91 +} 3.92 + 3.93 + 3.94 struct vr_module *vr_module_libovr(void) 3.95 { 3.96 static struct vr_module m; 3.97 @@ -31,7 +99,9 @@ 3.98 m.cleanup = cleanup; 3.99 m.view_matrix = view_matrix; 3.100 m.proj_matrix = proj_matrix; 3.101 - m.draw = draw; 3.102 + m.begin = begin; 3.103 + m.end = end; 3.104 + m.present = present; 3.105 } 3.106 return &m; 3.107 }
4.1 --- a/src/vr/vr_null.c Wed Aug 20 06:33:43 2014 +0300 4.2 +++ b/src/vr/vr_null.c Wed Aug 20 16:34:43 2014 +0300 4.3 @@ -16,38 +16,6 @@ 4.4 return 0; 4.5 } 4.6 4.7 -static void draw(unsigned int fbtex, float u, float maxu, float v, float maxv) 4.8 -{ 4.9 - glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT); 4.10 - 4.11 - glDisable(GL_LIGHTING); 4.12 - glDisable(GL_DEPTH_TEST); 4.13 - glDisable(GL_FOG); 4.14 - glDisable(GL_CULL_FACE); 4.15 - 4.16 - glMatrixMode(GL_MODELVIEW); 4.17 - glLoadIdentity(); 4.18 - glMatrixMode(GL_PROJECTION); 4.19 - glLoadIdentity(); 4.20 - 4.21 - glBegin(GL_QUADS); 4.22 - glTexCoord2f(u, v); 4.23 - glVertex2f(-1, -1); 4.24 - glTexCoord2f((u + maxu) / 2, v); 4.25 - glVertex2f(1, -1); 4.26 - glTexCoord2f((u + maxu) / 2, maxv); 4.27 - glVertex2f(1, 1); 4.28 - glTexCoord2f(u, maxv); 4.29 - glVertex2f(-1, 1); 4.30 - glEnd(); 4.31 - 4.32 - glPopMatrix(); 4.33 - glMatrixMode(GL_MODELVIEW); 4.34 - glPopMatrix(); 4.35 - 4.36 - glPopAttrib(); 4.37 -} 4.38 - 4.39 struct vr_module *vr_module_null(void) 4.40 { 4.41 static struct vr_module m; 4.42 @@ -55,7 +23,6 @@ 4.43 if(!m.init) { 4.44 m.name = "null"; 4.45 m.init = init; 4.46 - m.draw = draw; 4.47 } 4.48 return &m; 4.49 }
5.1 --- a/vrchess.vcxproj Wed Aug 20 06:33:43 2014 +0300 5.2 +++ b/vrchess.vcxproj Wed Aug 20 16:34:43 2014 +0300 5.3 @@ -87,6 +87,10 @@ 5.4 <ClCompile Include="src\opengl.cc" /> 5.5 <ClCompile Include="src\sdr.c" /> 5.6 <ClCompile Include="src\texture.cc" /> 5.7 + <ClCompile Include="src\vr\vr.c" /> 5.8 + <ClCompile Include="src\vr\vr_libovr.c" /> 5.9 + <ClCompile Include="src\vr\vr_modules.c" /> 5.10 + <ClCompile Include="src\vr\vr_null.c" /> 5.11 </ItemGroup> 5.12 <ItemGroup> 5.13 <ClInclude Include="src\camera.h" /> 5.14 @@ -95,6 +99,8 @@ 5.15 <ClInclude Include="src\opengl.h" /> 5.16 <ClInclude Include="src\sdr.h" /> 5.17 <ClInclude Include="src\texture.h" /> 5.18 + <ClInclude Include="src\vr\vr.h" /> 5.19 + <ClInclude Include="src\vr\vr_impl.h" /> 5.20 </ItemGroup> 5.21 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 5.22 <ImportGroup Label="ExtensionTargets">
6.1 --- a/vrchess.vcxproj.filters Wed Aug 20 06:33:43 2014 +0300 6.2 +++ b/vrchess.vcxproj.filters Wed Aug 20 16:34:43 2014 +0300 6.3 @@ -1,60 +1,73 @@ 6.4 <?xml version="1.0" encoding="utf-8"?> 6.5 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 6.6 <ItemGroup> 6.7 - <Filter Include="Source Files"> 6.8 + <Filter Include="src"> 6.9 <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> 6.10 - <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> 6.11 + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;inl</Extensions> 6.12 </Filter> 6.13 - <Filter Include="Header Files"> 6.14 - <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> 6.15 - <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> 6.16 - </Filter> 6.17 - <Filter Include="Resource Files"> 6.18 - <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> 6.19 - <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> 6.20 + <Filter Include="src\vr"> 6.21 + <UniqueIdentifier>{e881ab02-1a45-43f6-a15d-ee7f77256a1e}</UniqueIdentifier> 6.22 </Filter> 6.23 </ItemGroup> 6.24 <ItemGroup> 6.25 <ClCompile Include="src\main.cc"> 6.26 - <Filter>Source Files</Filter> 6.27 + <Filter>src</Filter> 6.28 </ClCompile> 6.29 <ClCompile Include="src\camera.cc"> 6.30 - <Filter>Source Files</Filter> 6.31 + <Filter>src</Filter> 6.32 </ClCompile> 6.33 <ClCompile Include="src\opengl.cc"> 6.34 - <Filter>Source Files</Filter> 6.35 + <Filter>src</Filter> 6.36 </ClCompile> 6.37 <ClCompile Include="src\sdr.c"> 6.38 - <Filter>Source Files</Filter> 6.39 + <Filter>src</Filter> 6.40 </ClCompile> 6.41 <ClCompile Include="src\game.cc"> 6.42 - <Filter>Source Files</Filter> 6.43 + <Filter>src</Filter> 6.44 </ClCompile> 6.45 <ClCompile Include="src\image.cc"> 6.46 - <Filter>Source Files</Filter> 6.47 + <Filter>src</Filter> 6.48 </ClCompile> 6.49 <ClCompile Include="src\texture.cc"> 6.50 - <Filter>Source Files</Filter> 6.51 + <Filter>src</Filter> 6.52 + </ClCompile> 6.53 + <ClCompile Include="src\vr\vr.c"> 6.54 + <Filter>src\vr</Filter> 6.55 + </ClCompile> 6.56 + <ClCompile Include="src\vr\vr_libovr.c"> 6.57 + <Filter>src\vr</Filter> 6.58 + </ClCompile> 6.59 + <ClCompile Include="src\vr\vr_modules.c"> 6.60 + <Filter>src\vr</Filter> 6.61 + </ClCompile> 6.62 + <ClCompile Include="src\vr\vr_null.c"> 6.63 + <Filter>src\vr</Filter> 6.64 </ClCompile> 6.65 </ItemGroup> 6.66 <ItemGroup> 6.67 <ClInclude Include="src\camera.h"> 6.68 - <Filter>Header Files</Filter> 6.69 + <Filter>src</Filter> 6.70 + </ClInclude> 6.71 + <ClInclude Include="src\game.h"> 6.72 + <Filter>src</Filter> 6.73 + </ClInclude> 6.74 + <ClInclude Include="src\image.h"> 6.75 + <Filter>src</Filter> 6.76 + </ClInclude> 6.77 + <ClInclude Include="src\opengl.h"> 6.78 + <Filter>src</Filter> 6.79 </ClInclude> 6.80 <ClInclude Include="src\sdr.h"> 6.81 - <Filter>Header Files</Filter> 6.82 - </ClInclude> 6.83 - <ClInclude Include="src\opengl.h"> 6.84 - <Filter>Header Files</Filter> 6.85 - </ClInclude> 6.86 - <ClInclude Include="src\game.h"> 6.87 - <Filter>Header Files</Filter> 6.88 - </ClInclude> 6.89 - <ClInclude Include="src\image.h"> 6.90 - <Filter>Header Files</Filter> 6.91 + <Filter>src</Filter> 6.92 </ClInclude> 6.93 <ClInclude Include="src\texture.h"> 6.94 - <Filter>Header Files</Filter> 6.95 + <Filter>src</Filter> 6.96 + </ClInclude> 6.97 + <ClInclude Include="src\vr\vr.h"> 6.98 + <Filter>src\vr</Filter> 6.99 + </ClInclude> 6.100 + <ClInclude Include="src\vr\vr_impl.h"> 6.101 + <Filter>src\vr</Filter> 6.102 </ClInclude> 6.103 </ItemGroup> 6.104 </Project> 6.105 \ No newline at end of file