|
@@ -22,7 +22,7 @@
|
|
* #define RLGL_STANDALONE
|
|
* #define RLGL_STANDALONE
|
|
* Use rlgl as standalone library (no raylib dependency)
|
|
* Use rlgl as standalone library (no raylib dependency)
|
|
*
|
|
*
|
|
-* #define SUPPORT_VR_SIMULATION / SUPPORT_STEREO_RENDERING
|
|
|
|
|
|
+* #define SUPPORT_VR_SIMULATOR
|
|
* Support VR simulation functionality (stereo rendering)
|
|
* Support VR simulation functionality (stereo rendering)
|
|
*
|
|
*
|
|
* #define SUPPORT_DISTORTION_SHADER
|
|
* #define SUPPORT_DISTORTION_SHADER
|
|
@@ -56,7 +56,7 @@
|
|
|
|
|
|
// Default configuration flags (supported features)
|
|
// Default configuration flags (supported features)
|
|
//-------------------------------------------------
|
|
//-------------------------------------------------
|
|
-#define SUPPORT_VR_SIMULATION
|
|
|
|
|
|
+#define SUPPORT_VR_SIMULATOR
|
|
#define SUPPORT_DISTORTION_SHADER
|
|
#define SUPPORT_DISTORTION_SHADER
|
|
//-------------------------------------------------
|
|
//-------------------------------------------------
|
|
|
|
|
|
@@ -222,6 +222,7 @@ typedef struct DrawCall {
|
|
//Guint fboId;
|
|
//Guint fboId;
|
|
} DrawCall;
|
|
} DrawCall;
|
|
|
|
|
|
|
|
+#if defined(SUPPORT_VR_SIMULATOR)
|
|
// Head-Mounted-Display device parameters
|
|
// Head-Mounted-Display device parameters
|
|
typedef struct VrDeviceInfo {
|
|
typedef struct VrDeviceInfo {
|
|
int hResolution; // HMD horizontal resolution in pixels
|
|
int hResolution; // HMD horizontal resolution in pixels
|
|
@@ -244,6 +245,7 @@ typedef struct VrStereoConfig {
|
|
Matrix eyesProjection[2]; // VR stereo rendering eyes projection matrices
|
|
Matrix eyesProjection[2]; // VR stereo rendering eyes projection matrices
|
|
Matrix eyesViewOffset[2]; // VR stereo rendering eyes view offset matrices
|
|
Matrix eyesViewOffset[2]; // VR stereo rendering eyes view offset matrices
|
|
} VrStereoConfig;
|
|
} VrStereoConfig;
|
|
|
|
+#endif
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------------
|
|
// Global Variables Definition
|
|
// Global Variables Definition
|
|
@@ -287,13 +289,16 @@ static bool texCompETC2Supported = false; // ETC2/EAC texture compression supp
|
|
static bool texCompPVRTSupported = false; // PVR texture compression support
|
|
static bool texCompPVRTSupported = false; // PVR texture compression support
|
|
static bool texCompASTCSupported = false; // ASTC texture compression support
|
|
static bool texCompASTCSupported = false; // ASTC texture compression support
|
|
|
|
|
|
|
|
+#if defined(SUPPORT_VR_SIMULATOR)
|
|
// VR global variables
|
|
// VR global variables
|
|
static VrDeviceInfo hmd; // Current VR device info
|
|
static VrDeviceInfo hmd; // Current VR device info
|
|
static VrStereoConfig vrConfig; // VR stereo configuration for simulator
|
|
static VrStereoConfig vrConfig; // VR stereo configuration for simulator
|
|
static bool vrSimulatorReady = false; // VR simulator ready flag
|
|
static bool vrSimulatorReady = false; // VR simulator ready flag
|
|
static bool vrStereoRender = false; // VR stereo rendering enabled/disabled flag
|
|
static bool vrStereoRender = false; // VR stereo rendering enabled/disabled flag
|
|
// NOTE: This flag is useful to render data over stereo image (i.e. FPS)
|
|
// NOTE: This flag is useful to render data over stereo image (i.e. FPS)
|
|
-#endif
|
|
|
|
|
|
+#endif // defined(SUPPORT_VR_SIMULATOR)
|
|
|
|
+
|
|
|
|
+#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
|
|
|
|
// Extension supported flag: Anisotropic filtering
|
|
// Extension supported flag: Anisotropic filtering
|
|
static bool texAnisotropicFilterSupported = false; // Anisotropic texture filtering support
|
|
static bool texAnisotropicFilterSupported = false; // Anisotropic texture filtering support
|
|
@@ -339,13 +344,13 @@ static void UpdateDefaultBuffers(void); // Update default internal buffers (
|
|
static void DrawDefaultBuffers(void); // Draw default internal buffers vertex data
|
|
static void DrawDefaultBuffers(void); // Draw default internal buffers vertex data
|
|
static void UnloadDefaultBuffers(void); // Unload default internal buffers vertex data from CPU and GPU
|
|
static void UnloadDefaultBuffers(void); // Unload default internal buffers vertex data from CPU and GPU
|
|
|
|
|
|
-// Configure stereo rendering (including distortion shader) with HMD device parameters
|
|
|
|
-static void SetStereoConfig(VrDeviceInfo info);
|
|
|
|
-
|
|
|
|
-// Set internal projection and modelview matrix depending on eyes tracking data
|
|
|
|
-static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView);
|
|
|
|
|
|
+#if defined(SUPPORT_VR_SIMULATOR)
|
|
|
|
+static void SetStereoConfig(VrDeviceInfo info); // Configure stereo rendering (including distortion shader) with HMD device parameters
|
|
|
|
+static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView); // Set internal projection and modelview matrix depending on eye
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
|
|
+
|
|
#if defined(GRAPHICS_API_OPENGL_11)
|
|
#if defined(GRAPHICS_API_OPENGL_11)
|
|
static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight);
|
|
static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight);
|
|
static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
|
|
static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
|
|
@@ -2068,12 +2073,16 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
|
|
}
|
|
}
|
|
|
|
|
|
int eyesCount = 1;
|
|
int eyesCount = 1;
|
|
|
|
+#if defined(SUPPORT_VR_SIMULATOR)
|
|
if (vrStereoRender) eyesCount = 2;
|
|
if (vrStereoRender) eyesCount = 2;
|
|
|
|
+#endif
|
|
|
|
|
|
for (int eye = 0; eye < eyesCount; eye++)
|
|
for (int eye = 0; eye < eyesCount; eye++)
|
|
{
|
|
{
|
|
- if (eyesCount == 2) SetStereoView(eye, matProjection, matModelView);
|
|
|
|
- else modelview = matModelView;
|
|
|
|
|
|
+ if (eyesCount == 1) modelview = matModelView;
|
|
|
|
+ #if defined(SUPPORT_VR_SIMULATOR)
|
|
|
|
+ else SetStereoView(eye, matProjection, matModelView);
|
|
|
|
+ #endif
|
|
|
|
|
|
// Calculate model-view-projection matrix (MVP)
|
|
// Calculate model-view-projection matrix (MVP)
|
|
Matrix matMVP = MatrixMultiply(modelview, projection); // Transform to screen-space coordinates
|
|
Matrix matMVP = MatrixMultiply(modelview, projection); // Transform to screen-space coordinates
|
|
@@ -2534,6 +2543,7 @@ void EndBlendMode(void)
|
|
BeginBlendMode(BLEND_ALPHA);
|
|
BeginBlendMode(BLEND_ALPHA);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#if defined(SUPPORT_VR_SIMULATOR)
|
|
// Init VR simulator for selected device
|
|
// Init VR simulator for selected device
|
|
// NOTE: It modifies the global variable: VrDeviceInfo hmd
|
|
// NOTE: It modifies the global variable: VrDeviceInfo hmd
|
|
void InitVrSimulator(int vrDevice)
|
|
void InitVrSimulator(int vrDevice)
|
|
@@ -2761,6 +2771,7 @@ void EndVrDrawing(void)
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
+#endif // SUPPORT_VR_SIMULATOR
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------------
|
|
// Module specific Functions Definition
|
|
// Module specific Functions Definition
|
|
@@ -3306,11 +3317,15 @@ static void DrawDefaultBuffers()
|
|
Matrix matModelView = modelview;
|
|
Matrix matModelView = modelview;
|
|
|
|
|
|
int eyesCount = 1;
|
|
int eyesCount = 1;
|
|
|
|
+#if defined(SUPPORT_VR_SIMULATOR)
|
|
if (vrStereoRender) eyesCount = 2;
|
|
if (vrStereoRender) eyesCount = 2;
|
|
|
|
+#endif
|
|
|
|
|
|
for (int eye = 0; eye < eyesCount; eye++)
|
|
for (int eye = 0; eye < eyesCount; eye++)
|
|
{
|
|
{
|
|
|
|
+ #if defined(SUPPORT_VR_SIMULATOR)
|
|
if (eyesCount == 2) SetStereoView(eye, matProjection, matModelView);
|
|
if (eyesCount == 2) SetStereoView(eye, matProjection, matModelView);
|
|
|
|
+ #endif
|
|
|
|
|
|
// Set current shader and upload current MVP matrix
|
|
// Set current shader and upload current MVP matrix
|
|
if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
|
|
if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
|
|
@@ -3516,6 +3531,7 @@ static void UnloadDefaultBuffers(void)
|
|
free(quads.indices);
|
|
free(quads.indices);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#if defined(SUPPORT_VR_SIMULATOR)
|
|
// Configure stereo rendering (including distortion shader) with HMD device parameters
|
|
// Configure stereo rendering (including distortion shader) with HMD device parameters
|
|
static void SetStereoConfig(VrDeviceInfo hmd)
|
|
static void SetStereoConfig(VrDeviceInfo hmd)
|
|
{
|
|
{
|
|
@@ -3607,6 +3623,8 @@ static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView)
|
|
SetMatrixModelview(eyeModelView);
|
|
SetMatrixModelview(eyeModelView);
|
|
SetMatrixProjection(eyeProjection);
|
|
SetMatrixProjection(eyeProjection);
|
|
}
|
|
}
|
|
|
|
+#endif // defined(SUPPORT_VR_SIMULATOR)
|
|
|
|
+
|
|
#endif //defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
#endif //defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
|
|
|
|
#if defined(GRAPHICS_API_OPENGL_11)
|
|
#if defined(GRAPHICS_API_OPENGL_11)
|