Browse Source

Expose Oculus Rift functionality directly

raysan5 9 years ago
parent
commit
55b9a2479a
2 changed files with 28 additions and 11 deletions
  1. 20 11
      src/rlgl.c
  2. 8 0
      src/rlgl.h

+ 20 - 11
src/rlgl.c

@@ -54,12 +54,11 @@
         #include <OpenGL/gl3.h>     // OpenGL 3 library for OSX
     #else
     #define GLAD_IMPLEMENTATION
-#if defined(RLGL_STANDALONE)
-    #include "glad.h"               // GLAD extensions loading library, includes OpenGL headers
-#else
-    #include "external/glad.h"      // GLAD extensions loading library, includes OpenGL headers
-#endif
-
+    #if defined(RLGL_STANDALONE)
+        #include "glad.h"           // GLAD extensions loading library, includes OpenGL headers
+    #else
+        #include "external/glad.h"  // GLAD extensions loading library, includes OpenGL headers
+    #endif
     #endif
 #endif
 
@@ -86,6 +85,12 @@
     #include "external/OculusSDK/LibOVR/Include/OVR_CAPI_GL.h"    // Oculus SDK for OpenGL
 #endif
 
+#if defined(RLGL_STANDALONE)
+    #define OCULUSAPI
+#else
+    #define OCULUSAPI static
+#endif
+
 //----------------------------------------------------------------------------------
 // Defines and Macros
 //----------------------------------------------------------------------------------
@@ -362,11 +367,13 @@ static char *ReadTextFile(const char *fileName); // Read chars array from text f
 #endif
 
 #if defined(RLGL_OCULUS_SUPPORT)
+#if !defined(RLGL_STANDALONE)
 static bool InitOculusDevice(void);         // Initialize Oculus device (returns true if success)
 static void CloseOculusDevice(void);        // Close Oculus device
 static void UpdateOculusTracking(void);     // Update Oculus head position-orientation tracking
 static void BeginOculusDrawing(void);       // Setup Oculus buffers for drawing
 static void EndOculusDrawing(void);         // Finish Oculus drawing and blit framebuffer to mirror
+#endif
 
 static OculusBuffer LoadOculusBuffer(ovrSession session, int width, int height);    // Load Oculus required buffers
 static void UnloadOculusBuffer(ovrSession session, OculusBuffer buffer);            // Unload texture required buffers
@@ -377,6 +384,8 @@ static OculusLayer InitOculusLayer(ovrSession session);
 static Matrix FromOvrMatrix(ovrMatrix4f ovrM);  // Convert from Oculus ovrMatrix4f struct to raymath Matrix struct
 #endif
 
+
+
 #if defined(GRAPHICS_API_OPENGL_11)
 static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight);
 static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
@@ -3936,7 +3945,7 @@ static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight)
 
 #if defined(RLGL_OCULUS_SUPPORT)
 // Initialize Oculus device (returns true if success)
-static bool InitOculusDevice(void)
+OCULUSAPI bool InitOculusDevice(void)
 {
     bool oculusReady = false;
 
@@ -3983,7 +3992,7 @@ static bool InitOculusDevice(void)
 }
 
 // Close Oculus device (and unload buffers)
-static void CloseOculusDevice(void)
+OCULUSAPI void CloseOculusDevice(void)
 {
     UnloadOculusMirror(session, mirror);    // Unload Oculus mirror buffer
     UnloadOculusBuffer(session, buffer);    // Unload Oculus texture buffers
@@ -3993,7 +4002,7 @@ static void CloseOculusDevice(void)
 }
 
 // Update Oculus head position-orientation tracking
-static void UpdateOculusTracking(void)
+OCULUSAPI void UpdateOculusTracking(void)
 {
     frameIndex++;
 
@@ -4016,7 +4025,7 @@ static void UpdateOculusTracking(void)
 }
 
 // Setup Oculus buffers for drawing
-static void BeginOculusDrawing(void)
+OCULUSAPI void BeginOculusDrawing(void)
 {
     GLuint currentTexId;
     int currentIndex;
@@ -4030,7 +4039,7 @@ static void BeginOculusDrawing(void)
 }
 
 // Finish Oculus drawing and blit framebuffer to mirror
-static void EndOculusDrawing(void)
+OCULUSAPI void EndOculusDrawing(void)
 {
     // Unbind current framebuffer (Oculus buffer)
     glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);

+ 8 - 0
src/rlgl.h

@@ -363,6 +363,7 @@ Light CreateLight(int type, Vector3 position, Color diffuse);       // Create a
 void DestroyLight(Light light);                                     // Destroy a light and take it out of the list
 
 void TraceLog(int msgType, const char *text, ...);
+float *MatrixToFloat(Matrix mat);
 
 void InitVrDevice(int hmdDevice);           // Init VR device
 void CloseVrDevice(void);                   // Close VR device
@@ -371,6 +372,13 @@ void BeginVrDrawing(void);                  // Begin VR drawing configuration
 void EndVrDrawing(void);                    // End VR drawing process (and desktop mirror)
 bool IsVrDeviceReady(void);                 // Detect if VR device (or simulator) is ready
 void ToggleVrMode(void);                    // Enable/Disable VR experience (device or simulator)
+
+// Oculus Rift API for direct access the device (no simulator)
+bool InitOculusDevice(void);                // Initialize Oculus device (returns true if success)
+void CloseOculusDevice(void);               // Close Oculus device
+void UpdateOculusTracking(void);            // Update Oculus head position-orientation tracking
+void BeginOculusDrawing(void);              // Setup Oculus buffers for drawing
+void EndOculusDrawing(void);                // Finish Oculus drawing and blit framebuffer to mirror
 #endif
 
 #ifdef __cplusplus