Oculus SDK 1.3 + GLFW3 sample -NOT WORKING-
This commit is contained in:
parent
9639b14e1b
commit
173529e048
5
.gitignore
vendored
5
.gitignore
vendored
@ -61,4 +61,7 @@ xcschememanagement.plist
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
*.dll
|
||||
src/libraylib.a
|
||||
src/libraylib.a
|
||||
|
||||
# oculus example
|
||||
!examples/oculus_glfw_sample/LibOVRRT32_1.dll
|
BIN
examples/oculus_glfw_sample/LibOVRRT32_1.dll
Normal file
BIN
examples/oculus_glfw_sample/LibOVRRT32_1.dll
Normal file
Binary file not shown.
@ -0,0 +1,196 @@
|
||||
/********************************************************************************//**
|
||||
\file OVR_CAPI_Util.h
|
||||
\brief This header provides LibOVR utility function declarations
|
||||
\copyright Copyright 2015-2016 Oculus VR, LLC All Rights reserved.
|
||||
*************************************************************************************/
|
||||
|
||||
#ifndef OVR_CAPI_Util_h
|
||||
#define OVR_CAPI_Util_h
|
||||
|
||||
|
||||
#include "../OVR_CAPI.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/// Enumerates modifications to the projection matrix based on the application's needs.
|
||||
///
|
||||
/// \see ovrMatrix4f_Projection
|
||||
///
|
||||
typedef enum ovrProjectionModifier_
|
||||
{
|
||||
/// Use for generating a default projection matrix that is:
|
||||
/// * Right-handed.
|
||||
/// * Near depth values stored in the depth buffer are smaller than far depth values.
|
||||
/// * Both near and far are explicitly defined.
|
||||
/// * With a clipping range that is (0 to w).
|
||||
ovrProjection_None = 0x00,
|
||||
|
||||
/// Enable if using left-handed transformations in your application.
|
||||
ovrProjection_LeftHanded = 0x01,
|
||||
|
||||
/// After the projection transform is applied, far values stored in the depth buffer will be less than closer depth values.
|
||||
/// NOTE: Enable only if the application is using a floating-point depth buffer for proper precision.
|
||||
ovrProjection_FarLessThanNear = 0x02,
|
||||
|
||||
/// When this flag is used, the zfar value pushed into ovrMatrix4f_Projection() will be ignored
|
||||
/// NOTE: Enable only if ovrProjection_FarLessThanNear is also enabled where the far clipping plane will be pushed to infinity.
|
||||
ovrProjection_FarClipAtInfinity = 0x04,
|
||||
|
||||
/// Enable if the application is rendering with OpenGL and expects a projection matrix with a clipping range of (-w to w).
|
||||
/// Ignore this flag if your application already handles the conversion from D3D range (0 to w) to OpenGL.
|
||||
ovrProjection_ClipRangeOpenGL = 0x08,
|
||||
} ovrProjectionModifier;
|
||||
|
||||
|
||||
/// Return values for ovr_Detect.
|
||||
///
|
||||
/// \see ovr_Detect
|
||||
///
|
||||
typedef struct OVR_ALIGNAS(8) ovrDetectResult_
|
||||
{
|
||||
/// Is ovrFalse when the Oculus Service is not running.
|
||||
/// This means that the Oculus Service is either uninstalled or stopped.
|
||||
/// IsOculusHMDConnected will be ovrFalse in this case.
|
||||
/// Is ovrTrue when the Oculus Service is running.
|
||||
/// This means that the Oculus Service is installed and running.
|
||||
/// IsOculusHMDConnected will reflect the state of the HMD.
|
||||
ovrBool IsOculusServiceRunning;
|
||||
|
||||
/// Is ovrFalse when an Oculus HMD is not detected.
|
||||
/// If the Oculus Service is not running, this will be ovrFalse.
|
||||
/// Is ovrTrue when an Oculus HMD is detected.
|
||||
/// This implies that the Oculus Service is also installed and running.
|
||||
ovrBool IsOculusHMDConnected;
|
||||
|
||||
OVR_UNUSED_STRUCT_PAD(pad0, 6) ///< \internal struct padding
|
||||
|
||||
} ovrDetectResult;
|
||||
|
||||
OVR_STATIC_ASSERT(sizeof(ovrDetectResult) == 8, "ovrDetectResult size mismatch");
|
||||
|
||||
|
||||
/// Detects Oculus Runtime and Device Status
|
||||
///
|
||||
/// Checks for Oculus Runtime and Oculus HMD device status without loading the LibOVRRT
|
||||
/// shared library. This may be called before ovr_Initialize() to help decide whether or
|
||||
/// not to initialize LibOVR.
|
||||
///
|
||||
/// \param[in] timeoutMilliseconds Specifies a timeout to wait for HMD to be attached or 0 to poll.
|
||||
///
|
||||
/// \return Returns an ovrDetectResult object indicating the result of detection.
|
||||
///
|
||||
/// \see ovrDetectResult
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrDetectResult) ovr_Detect(int timeoutMilliseconds);
|
||||
|
||||
// On the Windows platform,
|
||||
#ifdef _WIN32
|
||||
/// This is the Windows Named Event name that is used to check for HMD connected state.
|
||||
#define OVR_HMD_CONNECTED_EVENT_NAME L"OculusHMDConnected"
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
/// Used to generate projection from ovrEyeDesc::Fov.
|
||||
///
|
||||
/// \param[in] fov Specifies the ovrFovPort to use.
|
||||
/// \param[in] znear Distance to near Z limit.
|
||||
/// \param[in] zfar Distance to far Z limit.
|
||||
/// \param[in] projectionModFlags A combination of the ovrProjectionModifier flags.
|
||||
///
|
||||
/// \return Returns the calculated projection matrix.
|
||||
///
|
||||
/// \see ovrProjectionModifier
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrMatrix4f) ovrMatrix4f_Projection(ovrFovPort fov, float znear, float zfar, unsigned int projectionModFlags);
|
||||
|
||||
|
||||
/// Extracts the required data from the result of ovrMatrix4f_Projection.
|
||||
///
|
||||
/// \param[in] projection Specifies the project matrix from which to extract ovrTimewarpProjectionDesc.
|
||||
/// \param[in] projectionModFlags A combination of the ovrProjectionModifier flags.
|
||||
/// \return Returns the extracted ovrTimewarpProjectionDesc.
|
||||
/// \see ovrTimewarpProjectionDesc
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrTimewarpProjectionDesc) ovrTimewarpProjectionDesc_FromProjection(ovrMatrix4f projection, unsigned int projectionModFlags);
|
||||
|
||||
|
||||
/// Generates an orthographic sub-projection.
|
||||
///
|
||||
/// Used for 2D rendering, Y is down.
|
||||
///
|
||||
/// \param[in] projection The perspective matrix that the orthographic matrix is derived from.
|
||||
/// \param[in] orthoScale Equal to 1.0f / pixelsPerTanAngleAtCenter.
|
||||
/// \param[in] orthoDistance Equal to the distance from the camera in meters, such as 0.8m.
|
||||
/// \param[in] HmdToEyeOffsetX Specifies the offset of the eye from the center.
|
||||
///
|
||||
/// \return Returns the calculated projection matrix.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrMatrix4f) ovrMatrix4f_OrthoSubProjection(ovrMatrix4f projection, ovrVector2f orthoScale,
|
||||
float orthoDistance, float HmdToEyeOffsetX);
|
||||
|
||||
|
||||
|
||||
/// Computes offset eye poses based on headPose returned by ovrTrackingState.
|
||||
///
|
||||
/// \param[in] headPose Indicates the HMD position and orientation to use for the calculation.
|
||||
/// \param[in] HmdToEyeOffset Can be ovrEyeRenderDesc.HmdToEyeOffset returned from
|
||||
/// ovr_GetRenderDesc. For monoscopic rendering, use a vector that is the average
|
||||
/// of the two vectors for both eyes.
|
||||
/// \param[out] outEyePoses If outEyePoses are used for rendering, they should be passed to
|
||||
/// ovr_SubmitFrame in ovrLayerEyeFov::RenderPose or ovrLayerEyeFovDepth::RenderPose.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(void) ovr_CalcEyePoses(ovrPosef headPose,
|
||||
const ovrVector3f HmdToEyeOffset[2],
|
||||
ovrPosef outEyePoses[2]);
|
||||
|
||||
|
||||
/// Returns the predicted head pose in outHmdTrackingState and offset eye poses in outEyePoses.
|
||||
///
|
||||
/// This is a thread-safe function where caller should increment frameIndex with every frame
|
||||
/// and pass that index where applicable to functions called on the rendering thread.
|
||||
/// Assuming outEyePoses are used for rendering, it should be passed as a part of ovrLayerEyeFov.
|
||||
/// The caller does not need to worry about applying HmdToEyeOffset to the returned outEyePoses variables.
|
||||
///
|
||||
/// \param[in] hmd Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] frameIndex Specifies the targeted frame index, or 0 to refer to one frame after
|
||||
/// the last time ovr_SubmitFrame was called.
|
||||
/// \param[in] HmdToEyeOffset Can be ovrEyeRenderDesc.HmdToEyeOffset returned from
|
||||
/// ovr_GetRenderDesc. For monoscopic rendering, use a vector that is the average
|
||||
/// of the two vectors for both eyes.
|
||||
/// \param[in] latencyMarker Specifies that this call is the point in time where
|
||||
/// the "App-to-Mid-Photon" latency timer starts from. If a given ovrLayer
|
||||
/// provides "SensorSampleTimestamp", that will override the value stored here.
|
||||
/// \param[out] outEyePoses The predicted eye poses.
|
||||
/// \param[out] outSensorSampleTime The time when this function was called. May be NULL, in which case it is ignored.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(void) ovr_GetEyePoses(ovrSession session, long long frameIndex, ovrBool latencyMarker,
|
||||
const ovrVector3f HmdToEyeOffset[2],
|
||||
ovrPosef outEyePoses[2],
|
||||
double* outSensorSampleTime);
|
||||
|
||||
|
||||
|
||||
/// Tracking poses provided by the SDK come in a right-handed coordinate system. If an application
|
||||
/// is passing in ovrProjection_LeftHanded into ovrMatrix4f_Projection, then it should also use
|
||||
/// this function to flip the HMD tracking poses to be left-handed.
|
||||
///
|
||||
/// While this utility function is intended to convert a left-handed ovrPosef into a right-handed
|
||||
/// coordinate system, it will also work for converting right-handed to left-handed since the
|
||||
/// flip operation is the same for both cases.
|
||||
///
|
||||
/// \param[in] inPose that is right-handed
|
||||
/// \param[out] outPose that is requested to be left-handed (can be the same pointer to inPose)
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(void) ovrPosef_FlipHandedness(const ovrPosef* inPose, ovrPosef* outPose);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif // Header include guard
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,70 @@
|
||||
/************************************************************************************
|
||||
|
||||
Filename : OVR_StereoProjection.h
|
||||
Content : Stereo projection functions
|
||||
Created : November 30, 2013
|
||||
Authors : Tom Fosyth
|
||||
|
||||
Copyright : Copyright 2014-2016 Oculus VR, LLC All Rights reserved.
|
||||
|
||||
Licensed under the Oculus VR Rift SDK License Version 3.3 (the "License");
|
||||
you may not use the Oculus VR Rift SDK except in compliance with the License,
|
||||
which is provided at the time of installation or download, or which
|
||||
otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.oculusvr.com/licenses/LICENSE-3.3
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*************************************************************************************/
|
||||
|
||||
#ifndef OVR_StereoProjection_h
|
||||
#define OVR_StereoProjection_h
|
||||
|
||||
|
||||
#include "Extras/OVR_Math.h"
|
||||
|
||||
|
||||
namespace OVR {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
// ***** Stereo Enumerations
|
||||
|
||||
// StereoEye specifies which eye we are rendering for; it is used to
|
||||
// retrieve StereoEyeParams.
|
||||
enum StereoEye
|
||||
{
|
||||
StereoEye_Left,
|
||||
StereoEye_Right,
|
||||
StereoEye_Center
|
||||
};
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
// ***** Propjection functions
|
||||
|
||||
Matrix4f CreateProjection ( bool rightHanded, bool isOpenGL, FovPort fov, StereoEye eye,
|
||||
float zNear = 0.01f, float zFar = 10000.0f,
|
||||
bool flipZ = false, bool farAtInfinity = false);
|
||||
|
||||
Matrix4f CreateOrthoSubProjection ( bool rightHanded, StereoEye eyeType,
|
||||
float tanHalfFovX, float tanHalfFovY,
|
||||
float unitsX, float unitsY, float distanceFromCamera,
|
||||
float interpupillaryDistance, Matrix4f const &projection,
|
||||
float zNear = 0.0f, float zFar = 0.0f,
|
||||
bool flipZ = false, bool farAtInfinity = false);
|
||||
|
||||
ScaleAndOffset2D CreateNDCScaleAndOffsetFromFov ( FovPort fov );
|
||||
|
||||
|
||||
} //namespace OVR
|
||||
|
||||
#endif // OVR_StereoProjection_h
|
2103
examples/oculus_glfw_sample/OculusSDK/LibOVR/Include/OVR_CAPI.h
Normal file
2103
examples/oculus_glfw_sample/OculusSDK/LibOVR/Include/OVR_CAPI.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,76 @@
|
||||
/********************************************************************************//**
|
||||
\file OVR_CAPI_Audio.h
|
||||
\brief CAPI audio functions.
|
||||
\copyright Copyright 2015 Oculus VR, LLC. All Rights reserved.
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
#ifndef OVR_CAPI_Audio_h
|
||||
#define OVR_CAPI_Audio_h
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include "OVR_CAPI.h"
|
||||
#define OVR_AUDIO_MAX_DEVICE_STR_SIZE 128
|
||||
|
||||
/// Gets the ID of the preferred VR audio output device.
|
||||
///
|
||||
/// \param[out] deviceOutId The ID of the user's preferred VR audio device to use, which will be valid upon a successful return value, else it will be WAVE_MAPPER.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutWaveId(UINT* deviceOutId);
|
||||
|
||||
/// Gets the ID of the preferred VR audio input device.
|
||||
///
|
||||
/// \param[out] deviceInId The ID of the user's preferred VR audio device to use, which will be valid upon a successful return value, else it will be WAVE_MAPPER.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInWaveId(UINT* deviceInId);
|
||||
|
||||
|
||||
/// Gets the GUID of the preferred VR audio device as a string.
|
||||
///
|
||||
/// \param[out] deviceOutStrBuffer A buffer where the GUID string for the device will copied to.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutGuidStr(WCHAR deviceOutStrBuffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE]);
|
||||
|
||||
|
||||
/// Gets the GUID of the preferred VR audio device.
|
||||
///
|
||||
/// \param[out] deviceOutGuid The GUID of the user's preferred VR audio device to use, which will be valid upon a successful return value, else it will be NULL.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutGuid(GUID* deviceOutGuid);
|
||||
|
||||
|
||||
/// Gets the GUID of the preferred VR microphone device as a string.
|
||||
///
|
||||
/// \param[out] deviceInStrBuffer A buffer where the GUID string for the device will copied to.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInGuidStr(WCHAR deviceInStrBuffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE]);
|
||||
|
||||
|
||||
/// Gets the GUID of the preferred VR microphone device.
|
||||
///
|
||||
/// \param[out] deviceInGuid The GUID of the user's preferred VR audio device to use, which will be valid upon a successful return value, else it will be NULL.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInGuid(GUID* deviceInGuid);
|
||||
|
||||
#endif //OVR_OS_MS
|
||||
|
||||
#endif // OVR_CAPI_Audio_h
|
@ -0,0 +1,131 @@
|
||||
/********************************************************************************//**
|
||||
\file OVR_CAPI_D3D.h
|
||||
\brief D3D specific structures used by the CAPI interface.
|
||||
\copyright Copyright 2014-2016 Oculus VR, LLC All Rights reserved.
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef OVR_CAPI_D3D_h
|
||||
#define OVR_CAPI_D3D_h
|
||||
|
||||
#include "OVR_CAPI.h"
|
||||
#include "OVR_Version.h"
|
||||
|
||||
|
||||
#if defined (_WIN32)
|
||||
#include <Unknwn.h>
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
// ***** Direct3D Specific
|
||||
|
||||
/// Create Texture Swap Chain suitable for use with Direct3D 11 and 12.
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] d3dPtr Specifies the application's D3D11Device to create resources with or the D3D12CommandQueue
|
||||
/// which must be the same one the application renders to the eye textures with.
|
||||
/// \param[in] desc Specifies requested texture properties. See notes for more info about texture format.
|
||||
/// \param[in] bindFlags Specifies what ovrTextureBindFlags the application requires for this texture chain.
|
||||
/// \param[out] out_TextureSwapChain Returns the created ovrTextureSwapChain, which will be valid upon a successful return value, else it will be NULL.
|
||||
/// This texture chain must be eventually destroyed via ovr_DestroyTextureSwapChain before destroying the HMD with ovr_Destroy.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
/// \note The texture format provided in \a desc should be thought of as the format the distortion-compositor will use for the
|
||||
/// ShaderResourceView when reading the contents of the texture. To that end, it is highly recommended that the application
|
||||
/// requests texture swapchain formats that are in sRGB-space (e.g. OVR_FORMAT_R8G8B8A8_UNORM_SRGB) as the compositor
|
||||
/// does sRGB-correct rendering. As such, the compositor relies on the GPU's hardware sampler to do the sRGB-to-linear
|
||||
/// conversion. If the application still prefers to render to a linear format (e.g. OVR_FORMAT_R8G8B8A8_UNORM) while handling the
|
||||
/// linear-to-gamma conversion via HLSL code, then the application must still request the corresponding sRGB format and also use
|
||||
/// the \a ovrTextureMisc_DX_Typeless flag in the ovrTextureSwapChainDesc's Flag field. This will allow the application to create
|
||||
/// a RenderTargetView that is the desired linear format while the compositor continues to treat it as sRGB. Failure to do so
|
||||
/// will cause the compositor to apply unexpected gamma conversions leading to gamma-curve artifacts. The \a ovrTextureMisc_DX_Typeless
|
||||
/// flag for depth buffer formats (e.g. OVR_FORMAT_D32_FLOAT) is ignored as they are always converted to be typeless.
|
||||
///
|
||||
/// \see ovr_GetTextureSwapChainLength
|
||||
/// \see ovr_GetTextureSwapChainCurrentIndex
|
||||
/// \see ovr_GetTextureSwapChainDesc
|
||||
/// \see ovr_GetTextureSwapChainBufferDX
|
||||
/// \see ovr_DestroyTextureSwapChain
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateTextureSwapChainDX(ovrSession session,
|
||||
IUnknown* d3dPtr,
|
||||
const ovrTextureSwapChainDesc* desc,
|
||||
ovrTextureSwapChain* out_TextureSwapChain);
|
||||
|
||||
|
||||
/// Get a specific buffer within the chain as any compatible COM interface (similar to QueryInterface)
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] chain Specifies an ovrTextureSwapChain previously returned by ovr_CreateTextureSwapChainDX
|
||||
/// \param[in] index Specifies the index within the chain to retrieve. Must be between 0 and length (see ovr_GetTextureSwapChainLength),
|
||||
/// or may pass -1 to get the buffer at the CurrentIndex location. (Saving a call to GetTextureSwapChainCurrentIndex)
|
||||
/// \param[in] iid Specifies the interface ID of the interface pointer to query the buffer for.
|
||||
/// \param[out] out_Buffer Returns the COM interface pointer retrieved.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
/// <b>Example code</b>
|
||||
/// \code{.cpp}
|
||||
/// ovr_GetTextureSwapChainBuffer(session, chain, 0, IID_ID3D11Texture2D, &d3d11Texture);
|
||||
/// ovr_GetTextureSwapChainBuffer(session, chain, 1, IID_PPV_ARGS(&dxgiResource));
|
||||
/// \endcode
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetTextureSwapChainBufferDX(ovrSession session,
|
||||
ovrTextureSwapChain chain,
|
||||
int index,
|
||||
IID iid,
|
||||
void** out_Buffer);
|
||||
|
||||
|
||||
/// Create Mirror Texture which is auto-refreshed to mirror Rift contents produced by this application.
|
||||
///
|
||||
/// A second call to ovr_CreateMirrorTextureDX for a given ovrSession before destroying the first one
|
||||
/// is not supported and will result in an error return.
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] d3dPtr Specifies the application's D3D11Device to create resources with or the D3D12CommandQueue
|
||||
/// which must be the same one the application renders to the textures with.
|
||||
/// \param[in] desc Specifies requested texture properties. See notes for more info about texture format.
|
||||
/// \param[out] out_MirrorTexture Returns the created ovrMirrorTexture, which will be valid upon a successful return value, else it will be NULL.
|
||||
/// This texture must be eventually destroyed via ovr_DestroyMirrorTexture before destroying the HMD with ovr_Destroy.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
/// \note The texture format provided in \a desc should be thought of as the format the compositor will use for the RenderTargetView when
|
||||
/// writing into mirror texture. To that end, it is highly recommended that the application requests a mirror texture format that is
|
||||
/// in sRGB-space (e.g. OVR_FORMAT_R8G8B8A8_UNORM_SRGB) as the compositor does sRGB-correct rendering. If however the application wants
|
||||
/// to still read the mirror texture as a linear format (e.g. OVR_FORMAT_R8G8B8A8_UNORM) and handle the sRGB-to-linear conversion in
|
||||
/// HLSL code, then it is recommended the application still requests an sRGB format and also use the \a ovrTextureMisc_DX_Typeless flag in the
|
||||
/// ovrMirrorTextureDesc's Flags field. This will allow the application to bind a ShaderResourceView that is a linear format while the
|
||||
/// compositor continues to treat is as sRGB. Failure to do so will cause the compositor to apply unexpected gamma conversions leading to
|
||||
/// gamma-curve artifacts.
|
||||
///
|
||||
/// \see ovr_GetMirrorTextureBufferDX
|
||||
/// \see ovr_DestroyMirrorTexture
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateMirrorTextureDX(ovrSession session,
|
||||
IUnknown* d3dPtr,
|
||||
const ovrMirrorTextureDesc* desc,
|
||||
ovrMirrorTexture* out_MirrorTexture);
|
||||
|
||||
/// Get a the underlying buffer as any compatible COM interface (similar to QueryInterface)
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] mirrorTexture Specifies an ovrMirrorTexture previously returned by ovr_CreateMirrorTextureDX
|
||||
/// \param[in] iid Specifies the interface ID of the interface pointer to query the buffer for.
|
||||
/// \param[out] out_Buffer Returns the COM interface pointer retrieved.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetMirrorTextureBufferDX(ovrSession session,
|
||||
ovrMirrorTexture mirrorTexture,
|
||||
IID iid,
|
||||
void** out_Buffer);
|
||||
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
#endif // OVR_CAPI_D3D_h
|
@ -0,0 +1,99 @@
|
||||
/********************************************************************************//**
|
||||
\file OVR_CAPI_GL.h
|
||||
\brief OpenGL-specific structures used by the CAPI interface.
|
||||
\copyright Copyright 2015 Oculus VR, LLC. All Rights reserved.
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef OVR_CAPI_GL_h
|
||||
#define OVR_CAPI_GL_h
|
||||
|
||||
#include "OVR_CAPI.h"
|
||||
|
||||
/// Creates a TextureSwapChain suitable for use with OpenGL.
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] desc Specifies the requested texture properties. See notes for more info about texture format.
|
||||
/// \param[out] out_TextureSwapChain Returns the created ovrTextureSwapChain, which will be valid upon
|
||||
/// a successful return value, else it will be NULL. This texture swap chain must be eventually
|
||||
/// destroyed via ovr_DestroyTextureSwapChain before destroying the HMD with ovr_Destroy.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
/// \note The \a format provided should be thought of as the format the distortion compositor will use when reading
|
||||
/// the contents of the texture. To that end, it is highly recommended that the application requests texture swap chain
|
||||
/// formats that are in sRGB-space (e.g. OVR_FORMAT_R8G8B8A8_UNORM_SRGB) as the distortion compositor does sRGB-correct
|
||||
/// rendering. Furthermore, the app should then make sure "glEnable(GL_FRAMEBUFFER_SRGB);" is called before rendering
|
||||
/// into these textures. Even though it is not recommended, if the application would like to treat the texture as a linear
|
||||
/// format and do linear-to-gamma conversion in GLSL, then the application can avoid calling "glEnable(GL_FRAMEBUFFER_SRGB);",
|
||||
/// but should still pass in an sRGB variant for the \a format. Failure to do so will cause the distortion compositor
|
||||
/// to apply incorrect gamma conversions leading to gamma-curve artifacts.
|
||||
///
|
||||
/// \see ovr_GetTextureSwapChainLength
|
||||
/// \see ovr_GetTextureSwapChainCurrentIndex
|
||||
/// \see ovr_GetTextureSwapChainDesc
|
||||
/// \see ovr_GetTextureSwapChainBufferGL
|
||||
/// \see ovr_DestroyTextureSwapChain
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateTextureSwapChainGL(ovrSession session,
|
||||
const ovrTextureSwapChainDesc* desc,
|
||||
ovrTextureSwapChain* out_TextureSwapChain);
|
||||
|
||||
/// Get a specific buffer within the chain as a GL texture name
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] chain Specifies an ovrTextureSwapChain previously returned by ovr_CreateTextureSwapChainGL
|
||||
/// \param[in] index Specifies the index within the chain to retrieve. Must be between 0 and length (see ovr_GetTextureSwapChainLength)
|
||||
/// or may pass -1 to get the buffer at the CurrentIndex location. (Saving a call to GetTextureSwapChainCurrentIndex)
|
||||
/// \param[out] out_TexId Returns the GL texture object name associated with the specific index requested
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetTextureSwapChainBufferGL(ovrSession session,
|
||||
ovrTextureSwapChain chain,
|
||||
int index,
|
||||
unsigned int* out_TexId);
|
||||
|
||||
|
||||
/// Creates a Mirror Texture which is auto-refreshed to mirror Rift contents produced by this application.
|
||||
///
|
||||
/// A second call to ovr_CreateMirrorTextureGL for a given ovrSession before destroying the first one
|
||||
/// is not supported and will result in an error return.
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] desc Specifies the requested mirror texture description.
|
||||
/// \param[out] out_MirrorTexture Specifies the created ovrMirrorTexture, which will be valid upon a successful return value, else it will be NULL.
|
||||
/// This texture must be eventually destroyed via ovr_DestroyMirrorTexture before destroying the HMD with ovr_Destroy.
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
/// \note The \a format provided should be thought of as the format the distortion compositor will use when writing into the mirror
|
||||
/// texture. It is highly recommended that mirror textures are requested as sRGB formats because the distortion compositor
|
||||
/// does sRGB-correct rendering. If the application requests a non-sRGB format (e.g. R8G8B8A8_UNORM) as the mirror texture,
|
||||
/// then the application might have to apply a manual linear-to-gamma conversion when reading from the mirror texture.
|
||||
/// Failure to do so can result in incorrect gamma conversions leading to gamma-curve artifacts and color banding.
|
||||
///
|
||||
/// \see ovr_GetMirrorTextureBufferGL
|
||||
/// \see ovr_DestroyMirrorTexture
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateMirrorTextureGL(ovrSession session,
|
||||
const ovrMirrorTextureDesc* desc,
|
||||
ovrMirrorTexture* out_MirrorTexture);
|
||||
|
||||
/// Get a the underlying buffer as a GL texture name
|
||||
///
|
||||
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
|
||||
/// \param[in] mirrorTexture Specifies an ovrMirrorTexture previously returned by ovr_CreateMirrorTextureGL
|
||||
/// \param[out] out_TexId Specifies the GL texture object name associated with the mirror texture
|
||||
///
|
||||
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
|
||||
/// ovr_GetLastErrorInfo to get more information.
|
||||
///
|
||||
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetMirrorTextureBufferGL(ovrSession session,
|
||||
ovrMirrorTexture mirrorTexture,
|
||||
unsigned int* out_TexId);
|
||||
|
||||
|
||||
#endif // OVR_CAPI_GL_h
|
@ -0,0 +1,53 @@
|
||||
/********************************************************************************//**
|
||||
\file OVR_CAPI.h
|
||||
\brief Keys for CAPI proprty function calls
|
||||
\copyright Copyright 2015 Oculus VR, LLC All Rights reserved.
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef OVR_CAPI_Keys_h
|
||||
#define OVR_CAPI_Keys_h
|
||||
|
||||
#include "OVR_Version.h"
|
||||
|
||||
|
||||
|
||||
#define OVR_KEY_USER "User" // string
|
||||
|
||||
#define OVR_KEY_NAME "Name" // string
|
||||
|
||||
#define OVR_KEY_GENDER "Gender" // string "Male", "Female", or "Unknown"
|
||||
#define OVR_DEFAULT_GENDER "Unknown"
|
||||
|
||||
#define OVR_KEY_PLAYER_HEIGHT "PlayerHeight" // float meters
|
||||
#define OVR_DEFAULT_PLAYER_HEIGHT 1.778f
|
||||
|
||||
#define OVR_KEY_EYE_HEIGHT "EyeHeight" // float meters
|
||||
#define OVR_DEFAULT_EYE_HEIGHT 1.675f
|
||||
|
||||
#define OVR_KEY_NECK_TO_EYE_DISTANCE "NeckEyeDistance" // float[2] meters
|
||||
#define OVR_DEFAULT_NECK_TO_EYE_HORIZONTAL 0.0805f
|
||||
#define OVR_DEFAULT_NECK_TO_EYE_VERTICAL 0.075f
|
||||
|
||||
|
||||
#define OVR_KEY_EYE_TO_NOSE_DISTANCE "EyeToNoseDist" // float[2] meters
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define OVR_PERF_HUD_MODE "PerfHudMode" // int, allowed values are defined in enum ovrPerfHudMode
|
||||
|
||||
#define OVR_LAYER_HUD_MODE "LayerHudMode" // int, allowed values are defined in enum ovrLayerHudMode
|
||||
#define OVR_LAYER_HUD_CURRENT_LAYER "LayerHudCurrentLayer" // int, The layer to show
|
||||
#define OVR_LAYER_HUD_SHOW_ALL_LAYERS "LayerHudShowAll" // bool, Hide other layers when the hud is enabled
|
||||
|
||||
#define OVR_DEBUG_HUD_STEREO_MODE "DebugHudStereoMode" // int, allowed values are defined in enum ovrDebugHudStereoMode
|
||||
#define OVR_DEBUG_HUD_STEREO_GUIDE_INFO_ENABLE "DebugHudStereoGuideInfoEnable" // bool
|
||||
#define OVR_DEBUG_HUD_STEREO_GUIDE_SIZE "DebugHudStereoGuideSize2f" // float[2]
|
||||
#define OVR_DEBUG_HUD_STEREO_GUIDE_POSITION "DebugHudStereoGuidePosition3f" // float[3]
|
||||
#define OVR_DEBUG_HUD_STEREO_GUIDE_YAWPITCHROLL "DebugHudStereoGuideYawPitchRoll3f" // float[3]
|
||||
#define OVR_DEBUG_HUD_STEREO_GUIDE_COLOR "DebugHudStereoGuideColor4f" // float[4]
|
||||
|
||||
|
||||
|
||||
#endif // OVR_CAPI_Keys_h
|
@ -0,0 +1,191 @@
|
||||
/********************************************************************************//**
|
||||
\file OVR_ErrorCode.h
|
||||
\brief This header provides LibOVR error code declarations.
|
||||
\copyright Copyright 2015-2016 Oculus VR, LLC All Rights reserved.
|
||||
*************************************************************************************/
|
||||
|
||||
#ifndef OVR_ErrorCode_h
|
||||
#define OVR_ErrorCode_h
|
||||
|
||||
|
||||
#include "OVR_Version.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef OVR_RESULT_DEFINED
|
||||
#define OVR_RESULT_DEFINED ///< Allows ovrResult to be independently defined.
|
||||
/// API call results are represented at the highest level by a single ovrResult.
|
||||
typedef int32_t ovrResult;
|
||||
#endif
|
||||
|
||||
|
||||
/// \brief Indicates if an ovrResult indicates success.
|
||||
///
|
||||
/// Some functions return additional successful values other than ovrSucces and
|
||||
/// require usage of this macro to indicate successs.
|
||||
///
|
||||
#if !defined(OVR_SUCCESS)
|
||||
#define OVR_SUCCESS(result) (result >= 0)
|
||||
#endif
|
||||
|
||||
|
||||
/// \brief Indicates if an ovrResult indicates an unqualified success.
|
||||
///
|
||||
/// This is useful for indicating that the code intentionally wants to
|
||||
/// check for result == ovrSuccess as opposed to OVR_SUCCESS(), which
|
||||
/// checks for result >= ovrSuccess.
|
||||
///
|
||||
#if !defined(OVR_UNQUALIFIED_SUCCESS)
|
||||
#define OVR_UNQUALIFIED_SUCCESS(result) (result == ovrSuccess)
|
||||
#endif
|
||||
|
||||
|
||||
/// \brief Indicates if an ovrResult indicates failure.
|
||||
///
|
||||
#if !defined(OVR_FAILURE)
|
||||
#define OVR_FAILURE(result) (!OVR_SUCCESS(result))
|
||||
#endif
|
||||
|
||||
|
||||
// Success is a value greater or equal to 0, while all error types are negative values.
|
||||
#ifndef OVR_SUCCESS_DEFINED
|
||||
#define OVR_SUCCESS_DEFINED ///< Allows ovrResult to be independently defined.
|
||||
typedef enum ovrSuccessType_
|
||||
{
|
||||
/// This is a general success result. Use OVR_SUCCESS to test for success.
|
||||
ovrSuccess = 0,
|
||||
|
||||
/// Returned from a call to SubmitFrame. The call succeeded, but what the app
|
||||
/// rendered will not be visible on the HMD. Ideally the app should continue
|
||||
/// calling SubmitFrame, but not do any rendering. When the result becomes
|
||||
/// ovrSuccess, rendering should continue as usual.
|
||||
ovrSuccess_NotVisible = 1000,
|
||||
|
||||
ovrSuccess_HMDFirmwareMismatch = 4100, ///< The HMD Firmware is out of date but is acceptable.
|
||||
ovrSuccess_TrackerFirmwareMismatch = 4101, ///< The Tracker Firmware is out of date but is acceptable.
|
||||
ovrSuccess_ControllerFirmwareMismatch = 4104, ///< The controller firmware is out of date but is acceptable.
|
||||
ovrSuccess_TrackerDriverNotFound = 4105, ///< The tracker driver interface was not found. Can be a temporary error
|
||||
|
||||
} ovrSuccessType;
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum ovrErrorType_
|
||||
{
|
||||
/* General errors */
|
||||
ovrError_MemoryAllocationFailure = -1000, ///< Failure to allocate memory.
|
||||
ovrError_SocketCreationFailure = -1001, ///< Failure to create a socket.
|
||||
ovrError_InvalidSession = -1002, ///< Invalid ovrSession parameter provided.
|
||||
ovrError_Timeout = -1003, ///< The operation timed out.
|
||||
ovrError_NotInitialized = -1004, ///< The system or component has not been initialized.
|
||||
ovrError_InvalidParameter = -1005, ///< Invalid parameter provided. See error info or log for details.
|
||||
ovrError_ServiceError = -1006, ///< Generic service error. See error info or log for details.
|
||||
ovrError_NoHmd = -1007, ///< The given HMD doesn't exist.
|
||||
ovrError_Unsupported = -1009, ///< Function call is not supported on this hardware/software
|
||||
ovrError_DeviceUnavailable = -1010, ///< Specified device type isn't available.
|
||||
ovrError_InvalidHeadsetOrientation = -1011, ///< The headset was in an invalid orientation for the requested operation (e.g. vertically oriented during ovr_RecenterPose).
|
||||
ovrError_ClientSkippedDestroy = -1012, ///< The client failed to call ovr_Destroy on an active session before calling ovr_Shutdown. Or the client crashed.
|
||||
ovrError_ClientSkippedShutdown = -1013, ///< The client failed to call ovr_Shutdown or the client crashed.
|
||||
|
||||
/* Audio error range, reserved for Audio errors. */
|
||||
ovrError_AudioReservedBegin = -2000, ///< First Audio error.
|
||||
ovrError_AudioDeviceNotFound = -2001, ///< Failure to find the specified audio device.
|
||||
ovrError_AudioComError = -2002, ///< Generic COM error.
|
||||
ovrError_AudioReservedEnd = -2999, ///< Last Audio error.
|
||||
|
||||
/* Initialization errors. */
|
||||
ovrError_Initialize = -3000, ///< Generic initialization error.
|
||||
ovrError_LibLoad = -3001, ///< Couldn't load LibOVRRT.
|
||||
ovrError_LibVersion = -3002, ///< LibOVRRT version incompatibility.
|
||||
ovrError_ServiceConnection = -3003, ///< Couldn't connect to the OVR Service.
|
||||
ovrError_ServiceVersion = -3004, ///< OVR Service version incompatibility.
|
||||
ovrError_IncompatibleOS = -3005, ///< The operating system version is incompatible.
|
||||
ovrError_DisplayInit = -3006, ///< Unable to initialize the HMD display.
|
||||
ovrError_ServerStart = -3007, ///< Unable to start the server. Is it already running?
|
||||
ovrError_Reinitialization = -3008, ///< Attempting to re-initialize with a different version.
|
||||
ovrError_MismatchedAdapters = -3009, ///< Chosen rendering adapters between client and service do not match
|
||||
ovrError_LeakingResources = -3010, ///< Calling application has leaked resources
|
||||
ovrError_ClientVersion = -3011, ///< Client version too old to connect to service
|
||||
ovrError_OutOfDateOS = -3012, ///< The operating system is out of date.
|
||||
ovrError_OutOfDateGfxDriver = -3013, ///< The graphics driver is out of date.
|
||||
ovrError_IncompatibleGPU = -3014, ///< The graphics hardware is not supported
|
||||
ovrError_NoValidVRDisplaySystem = -3015, ///< No valid VR display system found.
|
||||
ovrError_Obsolete = -3016, ///< Feature or API is obsolete and no longer supported.
|
||||
ovrError_DisabledOrDefaultAdapter = -3017, ///< No supported VR display system found, but disabled or driverless adapter found.
|
||||
ovrError_HybridGraphicsNotSupported = -3018, ///< The system is using hybrid graphics (Optimus, etc...), which is not support.
|
||||
ovrError_DisplayManagerInit = -3019, ///< Initialization of the DisplayManager failed.
|
||||
ovrError_TrackerDriverInit = -3020, ///< Failed to get the interface for an attached tracker
|
||||
|
||||
/* Hardware errors */
|
||||
ovrError_InvalidBundleAdjustment = -4000, ///< Headset has no bundle adjustment data.
|
||||
ovrError_USBBandwidth = -4001, ///< The USB hub cannot handle the camera frame bandwidth.
|
||||
ovrError_USBEnumeratedSpeed = -4002, ///< The USB camera is not enumerating at the correct device speed.
|
||||
ovrError_ImageSensorCommError = -4003, ///< Unable to communicate with the image sensor.
|
||||
ovrError_GeneralTrackerFailure = -4004, ///< We use this to report various sensor issues that don't fit in an easily classifiable bucket.
|
||||
ovrError_ExcessiveFrameTruncation = -4005, ///< A more than acceptable number of frames are coming back truncated.
|
||||
ovrError_ExcessiveFrameSkipping = -4006, ///< A more than acceptable number of frames have been skipped.
|
||||
ovrError_SyncDisconnected = -4007, ///< The sensor is not receiving the sync signal (cable disconnected?).
|
||||
ovrError_TrackerMemoryReadFailure = -4008, ///< Failed to read memory from the sensor.
|
||||
ovrError_TrackerMemoryWriteFailure = -4009, ///< Failed to write memory from the sensor.
|
||||
ovrError_TrackerFrameTimeout = -4010, ///< Timed out waiting for a camera frame.
|
||||
ovrError_TrackerTruncatedFrame = -4011, ///< Truncated frame returned from sensor.
|
||||
ovrError_TrackerDriverFailure = -4012, ///< The sensor driver has encountered a problem.
|
||||
ovrError_TrackerNRFFailure = -4013, ///< The sensor wireless subsystem has encountered a problem.
|
||||
ovrError_HardwareGone = -4014, ///< The hardware has been unplugged
|
||||
ovrError_NordicEnabledNoSync = -4015, ///< The nordic indicates that sync is enabled but it is not sending sync pulses
|
||||
ovrError_NordicSyncNoFrames = -4016, ///< It looks like we're getting a sync signal, but no camera frames have been received
|
||||
ovrError_CatastrophicFailure = -4017, ///< A catastrophic failure has occurred. We will attempt to recover by resetting the device
|
||||
|
||||
ovrError_HMDFirmwareMismatch = -4100, ///< The HMD Firmware is out of date and is unacceptable.
|
||||
ovrError_TrackerFirmwareMismatch = -4101, ///< The sensor Firmware is out of date and is unacceptable.
|
||||
ovrError_BootloaderDeviceDetected = -4102, ///< A bootloader HMD is detected by the service.
|
||||
ovrError_TrackerCalibrationError = -4103, ///< The sensor calibration is missing or incorrect.
|
||||
ovrError_ControllerFirmwareMismatch = -4104, ///< The controller firmware is out of date and is unacceptable.
|
||||
|
||||
ovrError_IMUTooManyLostSamples = -4200, ///< Too many lost IMU samples.
|
||||
ovrError_IMURateError = -4201, ///< IMU rate is outside of the expected range.
|
||||
ovrError_FeatureReportFailure = -4202, ///< A feature report has failed.
|
||||
|
||||
/* Synchronization errors */
|
||||
ovrError_Incomplete = -5000, ///<Requested async work not yet complete.
|
||||
ovrError_Abandoned = -5001, ///<Requested async work was abandoned and result is incomplete.
|
||||
|
||||
/* Rendering errors */
|
||||
ovrError_DisplayLost = -6000, ///<In the event of a system-wide graphics reset or cable unplug this is returned to the app.
|
||||
ovrError_TextureSwapChainFull = -6001, ///<ovr_CommitTextureSwapChain was called too many times on a texture swapchain without calling submit to use the chain.
|
||||
ovrError_TextureSwapChainInvalid = -6002, ///<The ovrTextureSwapChain is in an incomplete or inconsistent state. Ensure ovr_CommitTextureSwapChain was called at least once first.
|
||||
|
||||
/* Fatal errors */
|
||||
ovrError_RuntimeException = -7000, ///< A runtime exception occurred. The application is required to shutdown LibOVR and re-initialize it before this error state will be cleared.
|
||||
|
||||
|
||||
ovrError_MetricsUnknownApp = -90000,
|
||||
ovrError_MetricsDuplicateApp = -90001,
|
||||
ovrError_MetricsNoEvents = -90002,
|
||||
ovrError_MetricsRuntime = -90003,
|
||||
ovrError_MetricsFile = -90004,
|
||||
ovrError_MetricsNoClientInfo = -90005,
|
||||
ovrError_MetricsNoAppMetaData = -90006,
|
||||
ovrError_MetricsNoApp = -90007,
|
||||
ovrError_MetricsOafFailure = -90008,
|
||||
ovrError_MetricsSessionAlreadyActive = -90009,
|
||||
ovrError_MetricsSessionNotActive = -90010,
|
||||
|
||||
} ovrErrorType;
|
||||
|
||||
|
||||
|
||||
/// Provides information about the last error.
|
||||
/// \see ovr_GetLastErrorInfo
|
||||
typedef struct ovrErrorInfo_
|
||||
{
|
||||
ovrResult Result; ///< The result from the last API call that generated an error ovrResult.
|
||||
char ErrorString[512]; ///< A UTF8-encoded null-terminated English string describing the problem. The format of this string is subject to change in future versions.
|
||||
} ovrErrorInfo;
|
||||
|
||||
#endif /* OVR_ErrorCode_h */
|
@ -0,0 +1,60 @@
|
||||
/********************************************************************************//**
|
||||
\file OVR_Version.h
|
||||
\brief This header provides LibOVR version identification.
|
||||
\copyright Copyright 2014-2016 Oculus VR, LLC All Rights reserved.
|
||||
*************************************************************************************/
|
||||
|
||||
#ifndef OVR_Version_h
|
||||
#define OVR_Version_h
|
||||
|
||||
|
||||
|
||||
/// Conventional string-ification macro.
|
||||
#if !defined(OVR_STRINGIZE)
|
||||
#define OVR_STRINGIZEIMPL(x) #x
|
||||
#define OVR_STRINGIZE(x) OVR_STRINGIZEIMPL(x)
|
||||
#endif
|
||||
|
||||
|
||||
// Master version numbers
|
||||
#define OVR_PRODUCT_VERSION 1 // Product version doesn't participate in semantic versioning.
|
||||
#define OVR_MAJOR_VERSION 1 // If you change these values then you need to also make sure to change LibOVR/Projects/Windows/LibOVR.props in parallel.
|
||||
#define OVR_MINOR_VERSION 3 //
|
||||
#define OVR_PATCH_VERSION 0
|
||||
#define OVR_BUILD_NUMBER 0
|
||||
|
||||
// This is the ((product * 100) + major) version of the service that the DLL is compatible with.
|
||||
// When we backport changes to old versions of the DLL we update the old DLLs
|
||||
// to move this version number up to the latest version.
|
||||
// The DLL is responsible for checking that the service is the version it supports
|
||||
// and returning an appropriate error message if it has not been made compatible.
|
||||
#define OVR_DLL_COMPATIBLE_VERSION 101
|
||||
|
||||
#define OVR_FEATURE_VERSION 0
|
||||
|
||||
|
||||
/// "Major.Minor.Patch"
|
||||
#if !defined(OVR_VERSION_STRING)
|
||||
#define OVR_VERSION_STRING OVR_STRINGIZE(OVR_MAJOR_VERSION.OVR_MINOR_VERSION.OVR_PATCH_VERSION)
|
||||
#endif
|
||||
|
||||
|
||||
/// "Major.Minor.Patch.Build"
|
||||
#if !defined(OVR_DETAILED_VERSION_STRING)
|
||||
#define OVR_DETAILED_VERSION_STRING OVR_STRINGIZE(OVR_MAJOR_VERSION.OVR_MINOR_VERSION.OVR_PATCH_VERSION.OVR_BUILD_NUMBER)
|
||||
#endif
|
||||
|
||||
|
||||
/// \brief file description for version info
|
||||
/// This appears in the user-visible file properties. It is intended to convey publicly
|
||||
/// available additional information such as feature builds.
|
||||
#if !defined(OVR_FILE_DESCRIPTION_STRING)
|
||||
#if defined(_DEBUG)
|
||||
#define OVR_FILE_DESCRIPTION_STRING "dev build debug"
|
||||
#else
|
||||
#define OVR_FILE_DESCRIPTION_STRING "dev build"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // OVR_Version_h
|
7684
examples/oculus_glfw_sample/glad.c
Normal file
7684
examples/oculus_glfw_sample/glad.c
Normal file
File diff suppressed because one or more lines are too long
14241
examples/oculus_glfw_sample/glad.h
Normal file
14241
examples/oculus_glfw_sample/glad.h
Normal file
File diff suppressed because one or more lines are too long
492
examples/oculus_glfw_sample/oculus_glfw_sample.c
Normal file
492
examples/oculus_glfw_sample/oculus_glfw_sample.c
Normal file
@ -0,0 +1,492 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib Oculus minimum sample (OpenGL 3.3 Core)
|
||||
*
|
||||
* NOTE: This example requires raylib module [rlgl]
|
||||
*
|
||||
* Compile rlgl using:
|
||||
* gcc -c rlgl.c -Wall -std=c99 -DRLGL_STANDALONE -DRAYMATH_IMPLEMENTATION -DGRAPHICS_API_OPENGL_33
|
||||
*
|
||||
* Compile example using:
|
||||
* gcc -o oculus_glfw_sample.exe oculus_glfw_sample.c rlgl.o glad.o -L. -lLibOVRRT32_1 -lglfw3 -lopengl32 -lgdi32 -std=c99
|
||||
*
|
||||
* This example has been created using raylib 1.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#define GLFW_EXPOSE_NATIVE_WGL
|
||||
#define OVR_OS_WIN32
|
||||
#elif defined(__APPLE__)
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#define GLFW_EXPOSE_NATIVE_NSGL
|
||||
#define OVR_OS_MAC
|
||||
#elif defined(__linux__)
|
||||
#define GLFW_EXPOSE_NATIVE_X11
|
||||
#define GLFW_EXPOSE_NATIVE_GLX
|
||||
#define OVR_OS_LINUX
|
||||
#endif
|
||||
|
||||
#include "glad.h" // Extensions loading library
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
|
||||
#include "OculusSDK/LibOVR/Include/OVR_CAPI_GL.h" // Oculus SDK for OpenGL
|
||||
|
||||
//#include "GL/CAPI_GLE.h" // stripped-down GLEW/GLAD library to manage extensions (really required?)
|
||||
//#include "Extras/OVR_Math.h" // math utilities C++ (really required?)
|
||||
|
||||
#define RLGL_STANDALONE
|
||||
#include "rlgl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef struct OculusBuffer {
|
||||
ovrTextureSwapChain textureChain;
|
||||
GLuint depthId;
|
||||
GLuint fboId;
|
||||
int width;
|
||||
int height;
|
||||
} OculusBuffer;
|
||||
|
||||
typedef enum { LOG_INFO = 0, LOG_ERROR, LOG_WARNING, LOG_DEBUG, LOG_OTHER } TraceLogType;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
static OculusBuffer LoadOculusBuffer(ovrSession session, int width, int height);
|
||||
static void UnloadOculusBuffer(ovrSession session, OculusBuffer buffer);
|
||||
static void SetOculusBuffer(ovrSession session, OculusBuffer buffer);
|
||||
static void UnsetOculusBuffer(OculusBuffer buffer);
|
||||
|
||||
static void ErrorCallback(int error, const char* description)
|
||||
{
|
||||
fputs(description, stderr);
|
||||
}
|
||||
|
||||
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
{
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static void DrawRectangleV(Vector2 position, Vector2 size, Color color);
|
||||
static void TraceLog(int msgType, const char *text, ...);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main Entry point
|
||||
//----------------------------------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
ovrResult result = ovr_Initialize(NULL);
|
||||
if (OVR_FAILURE(result)) TraceLog(LOG_ERROR, "OVR: Could not initialize Oculus device");
|
||||
|
||||
ovrSession session;
|
||||
ovrGraphicsLuid luid; // Useless for OpenGL since SDK 0.7
|
||||
|
||||
result = ovr_Create(&session, &luid);
|
||||
if (OVR_FAILURE(result))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "OVR: Could not create Oculus session");
|
||||
ovr_Shutdown();
|
||||
}
|
||||
|
||||
ovrHmdDesc hmdDesc = ovr_GetHmdDesc(session);
|
||||
|
||||
TraceLog(LOG_INFO, "OVR: Product Name: %s", hmdDesc.ProductName);
|
||||
TraceLog(LOG_INFO, "OVR: Manufacturer: %s", hmdDesc.Manufacturer);
|
||||
TraceLog(LOG_INFO, "OVR: Product ID: %i", hmdDesc.ProductId);
|
||||
TraceLog(LOG_INFO, "OVR: Product Type: %i", hmdDesc.Type);
|
||||
TraceLog(LOG_INFO, "OVR: Serian Number: %s", hmdDesc.SerialNumber);
|
||||
TraceLog(LOG_INFO, "OVR: Resolution: %ix%i", hmdDesc.Resolution.w, hmdDesc.Resolution.h);
|
||||
|
||||
int screenWidth = hmdDesc.Resolution.w/2 + 100; // Added 100 pixels for testing
|
||||
int screenHeight = hmdDesc.Resolution.h/2 + 100; // Added 100 pixels for testing
|
||||
|
||||
// GLFW3 Initialization + OpenGL 3.3 Context + Extensions
|
||||
//--------------------------------------------------------
|
||||
GLFWwindow *window;
|
||||
|
||||
glfwSetErrorCallback(ErrorCallback);
|
||||
|
||||
if (!glfwInit())
|
||||
{
|
||||
TraceLog(LOG_WARNING, "GLFW3: Can not initialize GLFW");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else TraceLog(LOG_INFO, "GLFW3: GLFW initialized successfully");
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_DECORATED, GL_FALSE); // Mandatory on Oculus Rift to avoid program crash!
|
||||
|
||||
window = glfwCreateWindow(screenWidth, screenHeight, "rlgl standalone", NULL, NULL);
|
||||
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else TraceLog(LOG_INFO, "GLFW3: Window created successfully");
|
||||
|
||||
glfwSetKeyCallback(window, KeyCallback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(0);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "GLAD: Cannot load OpenGL extensions");
|
||||
exit(1);
|
||||
}
|
||||
else TraceLog(LOG_INFO, "GLAD: OpenGL extensions loaded successfully");
|
||||
|
||||
rlglInit();
|
||||
rlglInitGraphics(0, 0, screenWidth, screenHeight);
|
||||
rlClearColor(245, 245, 245, 255); // Define clear color
|
||||
|
||||
Vector2 position = { screenWidth/2 - 100, screenHeight/2 - 100 };
|
||||
Vector2 size = { 200, 200 };
|
||||
Color color = { 180, 20, 20, 255 };
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
OculusBuffer eyeRenderBuffer[2];
|
||||
|
||||
GLuint mirrorFBO = 0;
|
||||
ovrMirrorTexture mirrorTexture = NULL;
|
||||
|
||||
bool isVisible = true;
|
||||
long long frameIndex = 0;
|
||||
|
||||
// Make eyes render buffers
|
||||
ovrSizei recommendedTexSizeLeft = ovr_GetFovTextureSize(session, ovrEye_Left, hmdDesc.DefaultEyeFov[0], 1.0f);
|
||||
eyeRenderBuffer[0] = LoadOculusBuffer(session, recommendedTexSizeLeft.w, recommendedTexSizeLeft.h);
|
||||
ovrSizei recommendedTexSizeRight = ovr_GetFovTextureSize(session, ovrEye_Right, hmdDesc.DefaultEyeFov[1], 1.0f);
|
||||
eyeRenderBuffer[1] = LoadOculusBuffer(session, recommendedTexSizeRight.w, recommendedTexSizeRight.h);
|
||||
|
||||
// Note: the mirror window can be any size, for this sample we use 1/2 the HMD resolution
|
||||
ovrSizei windowSize = { hmdDesc.Resolution.w/2, hmdDesc.Resolution.h/2 };
|
||||
|
||||
// Define mirror texture descriptor
|
||||
ovrMirrorTextureDesc mirrorDesc;
|
||||
memset(&mirrorDesc, 0, sizeof(mirrorDesc));
|
||||
mirrorDesc.Width = windowSize.w;
|
||||
mirrorDesc.Height = windowSize.h;
|
||||
mirrorDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
|
||||
// Create mirror texture and an FBO used to copy mirror texture to back buffer
|
||||
result = ovr_CreateMirrorTextureGL(session, &mirrorDesc, &mirrorTexture);
|
||||
if (!OVR_SUCCESS(result)) TraceLog(LOG_WARNING, "OVR: Failed to create mirror texture");
|
||||
|
||||
// Configure the mirror read buffer
|
||||
GLuint texId;
|
||||
ovr_GetMirrorTextureBufferGL(session, mirrorTexture, &texId);
|
||||
|
||||
glGenFramebuffers(1, &mirrorFBO);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, mirrorFBO);
|
||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texId, 0);
|
||||
glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
glDeleteFramebuffers(1, &mirrorFBO);
|
||||
TraceLog(LOG_WARNING, "OVR: Could not initialize mirror framebuffers");
|
||||
}
|
||||
|
||||
// FloorLevel will give tracking poses where the floor height is 0
|
||||
ovr_SetTrackingOriginType(session, ovrTrackingOrigin_FloorLevel);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// TODO: Update game here!
|
||||
|
||||
// Call ovr_GetRenderDesc each frame to get the ovrEyeRenderDesc, as the returned values (e.g. HmdToEyeOffset) may change at runtime.
|
||||
ovrEyeRenderDesc eyeRenderDesc[2];
|
||||
eyeRenderDesc[0] = ovr_GetRenderDesc(session, ovrEye_Left, hmdDesc.DefaultEyeFov[0]);
|
||||
eyeRenderDesc[1] = ovr_GetRenderDesc(session, ovrEye_Right, hmdDesc.DefaultEyeFov[1]);
|
||||
|
||||
// Get eye poses, feeding in correct IPD offset
|
||||
ovrPosef eyeRenderPose[2];
|
||||
ovrVector3f hmdToEyeOffset[2] = { eyeRenderDesc[0].HmdToEyeOffset, eyeRenderDesc[1].HmdToEyeOffset };
|
||||
|
||||
double sensorSampleTime; // sensorSampleTime is fed into the layer later
|
||||
ovr_GetEyePoses(session, frameIndex, ovrTrue, hmdToEyeOffset, eyeRenderPose, &sensorSampleTime);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Clear screen to red color
|
||||
glClearColor(1.0f, 0.1f, 0.1f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if (isVisible)
|
||||
{
|
||||
for (int eye = 0; eye < 2; ++eye)
|
||||
{
|
||||
SetOculusBuffer(session, eyeRenderBuffer[eye]);
|
||||
|
||||
// TODO: Get view and projection matrices for the eye
|
||||
// Sample using Oculus OVR_Math.h (C++)
|
||||
/*
|
||||
Matrix4f projection[eye] = Matrix4f(ovrMatrix4f_Projection(eyeRenderDesc[eye].Fov, 0.01f, 10000.0f, ovrProjection_None));
|
||||
Matrix4f eyeOrientation[eye] = Matrix4f(Quatf(eyeRenderPose[eye].Orientation).Inverted());
|
||||
Matrix4f eyePose[eye] = Matrix4f::Translation(-Vector3f(eyeRenderPose[eye].Position));
|
||||
Matrix4f mvp = projection[eye]*eyeOrientation[eye]*eyePose[eye];
|
||||
*/
|
||||
|
||||
// Sample using custom raymath.h (C) -INCOMPLETE-
|
||||
/*
|
||||
Matrix projection = MatrixPerspective(eyeRenderDesc[eye].Fov, ((double)screenWidth/(double)screenHeight), 0.01, 1000.0);
|
||||
Matrix eyeOrientation = QuaternionToMatrix((Quaternion){ -eyeRenderPose[eye].Orientation.x, -eyeRenderPose[eye].Orientation.y,
|
||||
-eyeRenderPose[eye].Orientation.z, -eyeRenderPose[eye].Orientation.w });
|
||||
Matrix eyePose = MatrixTranslate(-eyeRenderPose[eye].Position.x, -eyeRenderPose[eye].Position.y, -eyeRenderPose[eye].Position.z);
|
||||
Matrix mvp = MatrixMultiply(projection, MatrixMultiply(eyeOrientation, eyePose));
|
||||
*/
|
||||
|
||||
// Render everything
|
||||
// TODO: Pass calculated mvp matrix to default shader to consider projection and orientation!
|
||||
//DrawRectangleV(position, size, color);
|
||||
//rlglDraw();
|
||||
|
||||
UnsetOculusBuffer(eyeRenderBuffer[eye]);
|
||||
|
||||
// Commit changes to the textures so they get picked up frame
|
||||
ovr_CommitTextureSwapChain(session, eyeRenderBuffer[eye].textureChain);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up positional data
|
||||
ovrViewScaleDesc viewScaleDesc;
|
||||
viewScaleDesc.HmdSpaceToWorldScaleInMeters = 1.0f;
|
||||
viewScaleDesc.HmdToEyeOffset[0] = hmdToEyeOffset[0];
|
||||
viewScaleDesc.HmdToEyeOffset[1] = hmdToEyeOffset[1];
|
||||
|
||||
// Create the main eye layer
|
||||
ovrLayerEyeFov eyeLayer;
|
||||
eyeLayer.Header.Type = ovrLayerType_EyeFov;
|
||||
eyeLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft; // Because OpenGL
|
||||
|
||||
for (int eye = 0; eye < 2; eye++)
|
||||
{
|
||||
eyeLayer.ColorTexture[eye] = eyeRenderBuffer[eye].textureChain;
|
||||
eyeLayer.Viewport[eye] = (ovrRecti){ eyeRenderBuffer[eye].width, eyeRenderBuffer[eye].height };
|
||||
eyeLayer.Fov[eye] = hmdDesc.DefaultEyeFov[eye];
|
||||
eyeLayer.RenderPose[eye] = eyeRenderPose[eye];
|
||||
eyeLayer.SensorSampleTime = sensorSampleTime;
|
||||
}
|
||||
|
||||
// Append all the layers to global list
|
||||
ovrLayerHeader *layerList = &eyeLayer.Header;
|
||||
ovrResult result = ovr_SubmitFrame(session, frameIndex, NULL, &layerList, 1);
|
||||
|
||||
// exit the rendering loop if submit returns an error, will retry on ovrError_DisplayLost
|
||||
if (!OVR_SUCCESS(result)) return 1;
|
||||
|
||||
isVisible = (result == ovrSuccess);
|
||||
|
||||
// Get session status information
|
||||
ovrSessionStatus sessionStatus;
|
||||
ovr_GetSessionStatus(session, &sessionStatus);
|
||||
if (sessionStatus.ShouldQuit) TraceLog(LOG_WARNING, "OVR: Session should quit.");
|
||||
if (sessionStatus.ShouldRecenter) ovr_RecenterTrackingOrigin(session);
|
||||
|
||||
// Blit mirror texture to back buffer
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, mirrorFBO);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
GLint w = mirrorDesc.Width;
|
||||
GLint h = mirrorDesc.Height;
|
||||
glBlitFramebuffer(0, h, w, 0, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
//frameIndex++; //?
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
if (mirrorFBO) glDeleteFramebuffers(1, &mirrorFBO);
|
||||
if (mirrorTexture) ovr_DestroyMirrorTexture(session, mirrorTexture);
|
||||
for (int eye = 0; eye < 2; eye++) UnloadOculusBuffer(session, eyeRenderBuffer[eye]);
|
||||
|
||||
rlglClose();
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
ovr_Destroy(session); // Must be called after glfwTerminate()
|
||||
ovr_Shutdown();
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definitions
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Load Oculus required buffers: texture-swap-chain, fbo, texture-depth
|
||||
static OculusBuffer LoadOculusBuffer(ovrSession session, int width, int height)
|
||||
{
|
||||
OculusBuffer buffer;
|
||||
buffer.width = width;
|
||||
buffer.height = height;
|
||||
|
||||
// Create OVR texture chain
|
||||
ovrTextureSwapChainDesc desc = {};
|
||||
desc.Type = ovrTexture_2D;
|
||||
desc.ArraySize = 1;
|
||||
desc.Width = width;
|
||||
desc.Height = height;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
desc.SampleCount = 1;
|
||||
desc.StaticImage = ovrFalse;
|
||||
|
||||
ovrResult result = ovr_CreateTextureSwapChainGL(session, &desc, &buffer.textureChain);
|
||||
|
||||
int textureCount = 0;
|
||||
ovr_GetTextureSwapChainLength(session, buffer.textureChain, &textureCount);
|
||||
|
||||
if (OVR_SUCCESS(result))
|
||||
{
|
||||
for (int i = 0; i < textureCount; ++i)
|
||||
{
|
||||
GLuint chainTexId;
|
||||
ovr_GetTextureSwapChainBufferGL(session, buffer.textureChain, i, &chainTexId);
|
||||
glBindTexture(GL_TEXTURE_2D, chainTexId);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate framebuffer
|
||||
glGenFramebuffers(1, &buffer.fboId);
|
||||
|
||||
// Create Depth texture
|
||||
glGenTextures(1, &buffer.depthId);
|
||||
glBindTexture(GL_TEXTURE_2D, buffer.depthId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, buffer.width, buffer.height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Unload texture required buffers
|
||||
static void UnloadOculusBuffer(ovrSession session, OculusBuffer buffer)
|
||||
{
|
||||
if (buffer.textureChain)
|
||||
{
|
||||
ovr_DestroyTextureSwapChain(session, buffer.textureChain);
|
||||
buffer.textureChain = NULL;
|
||||
}
|
||||
|
||||
if (buffer.depthId)
|
||||
{
|
||||
glDeleteTextures(1, &buffer.depthId);
|
||||
buffer.depthId = 0;
|
||||
}
|
||||
|
||||
if (buffer.fboId)
|
||||
{
|
||||
glDeleteFramebuffers(1, &buffer.fboId);
|
||||
buffer.fboId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Set current Oculus buffer
|
||||
static void SetOculusBuffer(ovrSession session, OculusBuffer buffer)
|
||||
{
|
||||
GLuint currentTexId;
|
||||
int currentIndex;
|
||||
|
||||
ovr_GetTextureSwapChainCurrentIndex(session, buffer.textureChain, ¤tIndex);
|
||||
ovr_GetTextureSwapChainBufferGL(session, buffer.textureChain, currentIndex, ¤tTexId);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, buffer.fboId);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, currentTexId, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, buffer.depthId, 0);
|
||||
|
||||
glViewport(0, 0, buffer.width, buffer.height);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
|
||||
// Unset Oculus buffer
|
||||
static void UnsetOculusBuffer(OculusBuffer buffer)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, buffer.fboId);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
||||
}
|
||||
|
||||
// Draw rectangle using rlgl OpenGL 1.1 style coding (translated to OpenGL 3.3 internally)
|
||||
static void DrawRectangleV(Vector2 position, Vector2 size, Color color)
|
||||
{
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
rlVertex2i(position.x, position.y);
|
||||
rlVertex2i(position.x, position.y + size.y);
|
||||
rlVertex2i(position.x + size.x, position.y + size.y);
|
||||
|
||||
rlVertex2i(position.x, position.y);
|
||||
rlVertex2i(position.x + size.x, position.y + size.y);
|
||||
rlVertex2i(position.x + size.x, position.y);
|
||||
rlEnd();
|
||||
}
|
||||
|
||||
// Output a trace log message
|
||||
// NOTE: Expected msgType: (0)Info, (1)Error, (2)Warning
|
||||
static void TraceLog(int msgType, const char *text, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
|
||||
switch(msgType)
|
||||
{
|
||||
case LOG_INFO: fprintf(stdout, "INFO: "); break;
|
||||
case LOG_ERROR: fprintf(stdout, "ERROR: "); break;
|
||||
case LOG_WARNING: fprintf(stdout, "WARNING: "); break;
|
||||
case LOG_DEBUG: fprintf(stdout, "DEBUG: "); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
vfprintf(stdout, text, args);
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
va_end(args);
|
||||
|
||||
//if (msgType == LOG_ERROR) exit(1);
|
||||
}
|
131
examples/oculus_glfw_sample/raylib_rlgl_standalone.c
Normal file
131
examples/oculus_glfw_sample/raylib_rlgl_standalone.c
Normal file
@ -0,0 +1,131 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [rlgl] example - Using rlgl module as standalone module
|
||||
*
|
||||
* NOTE: This example requires OpenGL 3.3 or ES2 versions for shaders support,
|
||||
* OpenGL 1.1 does not support shaders but it can also be used.
|
||||
*
|
||||
* Compile rlgl module using:
|
||||
* gcc -c rlgl.c -Wall -std=c99 -DRLGL_STANDALONE -DRAYMATH_IMPLEMENTATION -DGRAPHICS_API_OPENGL_33
|
||||
*
|
||||
* Compile example using:
|
||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) rlgl.o glad.o -lglfw3 -lopengl32 -lgdi32 -std=c99
|
||||
*
|
||||
* This example has been created using raylib 1.5 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "glad.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define RLGL_STANDALONE
|
||||
#include "rlgl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
static void ErrorCallback(int error, const char* description)
|
||||
{
|
||||
fputs(description, stderr);
|
||||
}
|
||||
|
||||
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
{
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawRectangleV(Vector2 position, Vector2 size, Color color);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main Entry point
|
||||
//----------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
GLFWwindow *window;
|
||||
|
||||
glfwSetErrorCallback(ErrorCallback);
|
||||
|
||||
if (!glfwInit()) exit(EXIT_FAILURE);
|
||||
|
||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
window = glfwCreateWindow(screenWidth, screenHeight, "rlgl standalone", NULL, NULL);
|
||||
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(window, KeyCallback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
printf("Cannot load GL extensions.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rlglInit();
|
||||
rlglInitGraphics(0, 0, screenWidth, screenHeight);
|
||||
rlClearColor(245, 245, 245, 255); // Define clear color
|
||||
|
||||
Vector2 position = { screenWidth/2 - 100, screenHeight/2 - 100 };
|
||||
Vector2 size = { 200, 200 };
|
||||
Color color = { 180, 20, 20, 255 };
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
rlClearScreenBuffers();
|
||||
|
||||
DrawRectangleV(position, size, color);
|
||||
|
||||
rlglDraw();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
rlglClose();
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definitions
|
||||
//----------------------------------------------------------------------------------
|
||||
void DrawRectangleV(Vector2 position, Vector2 size, Color color)
|
||||
{
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
rlVertex2i(position.x, position.y);
|
||||
rlVertex2i(position.x, position.y + size.y);
|
||||
rlVertex2i(position.x + size.x, position.y + size.y);
|
||||
|
||||
rlVertex2i(position.x, position.y);
|
||||
rlVertex2i(position.x + size.x, position.y + size.y);
|
||||
rlVertex2i(position.x + size.x, position.y);
|
||||
rlEnd();
|
||||
}
|
1128
examples/oculus_glfw_sample/raymath.h
Normal file
1128
examples/oculus_glfw_sample/raymath.h
Normal file
File diff suppressed because it is too large
Load Diff
2960
examples/oculus_glfw_sample/rlgl.c
Normal file
2960
examples/oculus_glfw_sample/rlgl.c
Normal file
File diff suppressed because it is too large
Load Diff
327
examples/oculus_glfw_sample/rlgl.h
Normal file
327
examples/oculus_glfw_sample/rlgl.h
Normal file
@ -0,0 +1,327 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* rlgl - raylib OpenGL abstraction layer
|
||||
*
|
||||
* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version:
|
||||
* OpenGL 1.1 - Direct map rl* -> gl*
|
||||
* OpenGL 3.3 - Vertex data is stored in VAOs, call rlglDraw() to render
|
||||
* OpenGL ES 2 - Vertex data is stored in VBOs or VAOs (when available), call rlglDraw() to render
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef RLGL_H
|
||||
#define RLGL_H
|
||||
|
||||
//#define RLGL_STANDALONE // NOTE: To use rlgl as standalone lib, just uncomment this line
|
||||
|
||||
#ifndef RLGL_STANDALONE
|
||||
#include "raylib.h" // Required for typedef(s): Model, Shader, Texture2D
|
||||
#include "utils.h" // Required for function TraceLog()
|
||||
#endif
|
||||
|
||||
#ifdef RLGL_STANDALONE
|
||||
#define RAYMATH_STANDALONE
|
||||
#endif
|
||||
|
||||
#include "raymath.h" // Required for types: Vector3, Matrix
|
||||
|
||||
// Select desired OpenGL version
|
||||
// NOTE: Those preprocessor defines are only used on rlgl module,
|
||||
// if OpenGL version is required by any other module, it uses rlGetVersion()
|
||||
|
||||
// Choose opengl version here or just define it at compile time: -DGRAPHICS_API_OPENGL_33
|
||||
//#define GRAPHICS_API_OPENGL_11 // Only available on PLATFORM_DESKTOP
|
||||
//#define GRAPHICS_API_OPENGL_33 // Only available on PLATFORM_DESKTOP
|
||||
//#define GRAPHICS_API_OPENGL_ES2 // Only available on PLATFORM_ANDROID or PLATFORM_RPI or PLATFORM_WEB
|
||||
|
||||
// Security check in case no GRAPHICS_API_OPENGL_* defined
|
||||
#if !defined(GRAPHICS_API_OPENGL_11) && !defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_ES2)
|
||||
#define GRAPHICS_API_OPENGL_11
|
||||
#endif
|
||||
|
||||
// Security check in case multiple GRAPHICS_API_OPENGL_* defined
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
#undef GRAPHICS_API_OPENGL_33
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
#undef GRAPHICS_API_OPENGL_ES2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
// NOTE: This is the maximum amount of lines, triangles and quads per frame, be careful!
|
||||
#define MAX_LINES_BATCH 8192
|
||||
#define MAX_TRIANGLES_BATCH 4096
|
||||
#define MAX_QUADS_BATCH 4096
|
||||
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// NOTE: Reduce memory sizes for embedded systems (RPI and HTML5)
|
||||
// NOTE: On HTML5 (emscripten) this is allocated on heap, by default it's only 16MB!...just take care...
|
||||
#define MAX_LINES_BATCH 1024 // Critical for wire shapes (sphere)
|
||||
#define MAX_TRIANGLES_BATCH 2048 // Critical for some shapes (sphere)
|
||||
#define MAX_QUADS_BATCH 1024 // Be careful with text, every letter maps a quad
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef enum { RL_PROJECTION, RL_MODELVIEW, RL_TEXTURE } MatrixMode;
|
||||
|
||||
typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode;
|
||||
|
||||
typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
||||
|
||||
#if defined(RLGL_STANDALONE)
|
||||
#ifndef __cplusplus
|
||||
// Boolean type
|
||||
typedef enum { false, true } bool;
|
||||
#endif
|
||||
|
||||
// byte type
|
||||
typedef unsigned char byte;
|
||||
|
||||
// Color type, RGBA (32bit)
|
||||
typedef struct Color {
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
} Color;
|
||||
|
||||
// Texture formats (support depends on OpenGL version)
|
||||
typedef enum {
|
||||
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
||||
UNCOMPRESSED_GRAY_ALPHA,
|
||||
UNCOMPRESSED_R5G6B5, // 16 bpp
|
||||
UNCOMPRESSED_R8G8B8, // 24 bpp
|
||||
UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
|
||||
UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
|
||||
UNCOMPRESSED_R8G8B8A8, // 32 bpp
|
||||
COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
|
||||
COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
|
||||
COMPRESSED_DXT3_RGBA, // 8 bpp
|
||||
COMPRESSED_DXT5_RGBA, // 8 bpp
|
||||
COMPRESSED_ETC1_RGB, // 4 bpp
|
||||
COMPRESSED_ETC2_RGB, // 4 bpp
|
||||
COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
|
||||
COMPRESSED_PVRT_RGB, // 4 bpp
|
||||
COMPRESSED_PVRT_RGBA, // 4 bpp
|
||||
COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
|
||||
COMPRESSED_ASTC_8x8_RGBA // 2 bpp
|
||||
} TextureFormat;
|
||||
|
||||
// Bounding box type
|
||||
typedef struct BoundingBox {
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
} BoundingBox;
|
||||
|
||||
// Mesh with vertex data type
|
||||
// NOTE: If using OpenGL 1.1, data loaded in CPU; if OpenGL 3.3+ data loaded in GPU (vaoId)
|
||||
typedef struct Mesh {
|
||||
int vertexCount; // num vertices
|
||||
float *vertices; // vertex position (XYZ - 3 components per vertex)
|
||||
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex)
|
||||
float *texcoords2; // vertex second texture coordinates (useful for lightmaps)
|
||||
float *normals; // vertex normals (XYZ - 3 components per vertex)
|
||||
float *tangents; // vertex tangents (XYZ - 3 components per vertex)
|
||||
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex)
|
||||
|
||||
BoundingBox bounds; // mesh limits defined by min and max points
|
||||
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
unsigned int vboId[6]; // OpenGL Vertex Buffer Objects id (6 types of vertex data)
|
||||
} Mesh;
|
||||
|
||||
// Shader type
|
||||
typedef struct Shader {
|
||||
unsigned int id; // Shader program id
|
||||
|
||||
// Variable attributes
|
||||
int vertexLoc; // Vertex attribute location point (vertex shader)
|
||||
int texcoordLoc; // Texcoord attribute location point (vertex shader)
|
||||
int normalLoc; // Normal attribute location point (vertex shader)
|
||||
int colorLoc; // Color attibute location point (vertex shader)
|
||||
|
||||
// Uniforms
|
||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||
int tintColorLoc; // Color uniform location point (fragment shader)
|
||||
|
||||
int mapDiffuseLoc; // Diffuse map texture uniform location point (fragment shader)
|
||||
int mapNormalLoc; // Normal map texture uniform location point (fragment shader)
|
||||
int mapSpecularLoc; // Specular map texture uniform location point (fragment shader)
|
||||
} Shader;
|
||||
|
||||
// Texture2D type
|
||||
// NOTE: Data stored in GPU memory
|
||||
typedef struct Texture2D {
|
||||
unsigned int id; // OpenGL texture id
|
||||
int width; // Texture base width
|
||||
int height; // Texture base height
|
||||
int mipmaps; // Mipmap levels, 1 by default
|
||||
int format; // Data format (TextureFormat)
|
||||
} Texture2D;
|
||||
|
||||
// RenderTexture2D type, for texture rendering
|
||||
typedef struct RenderTexture2D {
|
||||
unsigned int id; // Render texture (fbo) id
|
||||
Texture2D texture; // Color buffer attachment texture
|
||||
Texture2D depth; // Depth buffer attachment texture
|
||||
} RenderTexture2D;
|
||||
|
||||
// Material type
|
||||
typedef struct Material {
|
||||
Shader shader;
|
||||
|
||||
Texture2D texDiffuse; // Diffuse texture
|
||||
Texture2D texNormal; // Normal texture
|
||||
Texture2D texSpecular; // Specular texture
|
||||
|
||||
Color colDiffuse;
|
||||
Color colAmbient;
|
||||
Color colSpecular;
|
||||
|
||||
float glossiness;
|
||||
float normalDepth;
|
||||
} Material;
|
||||
|
||||
// 3d Model type
|
||||
typedef struct Model {
|
||||
Mesh mesh;
|
||||
Matrix transform;
|
||||
Material material;
|
||||
} Model;
|
||||
|
||||
// Color blending modes (pre-defined)
|
||||
typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Matrix operations
|
||||
//------------------------------------------------------------------------------------
|
||||
void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
||||
void rlPushMatrix(void); // Push the current matrix to stack
|
||||
void rlPopMatrix(void); // Pop lattest inserted matrix from stack
|
||||
void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
||||
void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
|
||||
void rlRotatef(float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix
|
||||
void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
|
||||
void rlMultMatrixf(float *mat); // Multiply the current matrix by another matrix
|
||||
void rlFrustum(double left, double right, double bottom, double top, double near, double far);
|
||||
void rlOrtho(double left, double right, double bottom, double top, double near, double far);
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Vertex level operations
|
||||
//------------------------------------------------------------------------------------
|
||||
void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
||||
void rlEnd(void); // Finish vertex providing
|
||||
void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
||||
void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
||||
void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
||||
void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
||||
void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
||||
void rlColor4ub(byte r, byte g, byte b, byte a); // Define one vertex (color) - 4 byte
|
||||
void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
||||
void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - OpenGL equivalent functions (common to 1.1, 3.3+, ES2)
|
||||
// NOTE: This functions are used to completely abstract raylib code from OpenGL layer
|
||||
//------------------------------------------------------------------------------------
|
||||
void rlEnableTexture(unsigned int id); // Enable texture usage
|
||||
void rlDisableTexture(void); // Disable texture usage
|
||||
void rlEnableRenderTexture(unsigned int id); // Enable render texture (fbo)
|
||||
void rlDisableRenderTexture(void); // Disable render texture (fbo), return to default framebuffer
|
||||
void rlEnableDepthTest(void); // Enable depth test
|
||||
void rlDisableDepthTest(void); // Disable depth test
|
||||
void rlDeleteTextures(unsigned int id); // Delete OpenGL texture from GPU
|
||||
void rlDeleteRenderTextures(RenderTexture2D target); // Delete render textures (fbo) from GPU
|
||||
void rlDeleteShader(unsigned int id); // Delete OpenGL shader program from GPU
|
||||
void rlDeleteVertexArrays(unsigned int id); // Unload vertex data (VAO) from GPU memory
|
||||
void rlDeleteBuffers(unsigned int id); // Unload vertex data (VBO) from GPU memory
|
||||
void rlClearColor(byte r, byte g, byte b, byte a); // Clear color buffer with color
|
||||
void rlClearScreenBuffers(void); // Clear used screen buffers (color and depth)
|
||||
int rlGetVersion(void); // Returns current OpenGL version
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - rlgl functionality
|
||||
//------------------------------------------------------------------------------------
|
||||
void rlglInit(void); // Initialize rlgl (shaders, VAO, VBO...)
|
||||
void rlglClose(void); // De-init rlgl
|
||||
void rlglDraw(void); // Draw VAO/VBO
|
||||
void rlglInitGraphics(int offsetX, int offsetY, int width, int height); // Initialize Graphics (OpenGL stuff)
|
||||
|
||||
unsigned int rlglLoadTexture(void *data, int width, int height, int textureFormat, int mipmapCount); // Load texture in GPU
|
||||
RenderTexture2D rlglLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments)
|
||||
void rlglUpdateTexture(unsigned int id, int width, int height, int format, void *data); // Update GPU texture with new data
|
||||
void rlglGenerateMipmaps(Texture2D texture); // Generate mipmap data for selected texture
|
||||
|
||||
// NOTE: There is a set of shader related functions that are available to end user,
|
||||
// to avoid creating function wrappers through core module, they have been directly declared in raylib.h
|
||||
|
||||
Model rlglLoadModel(Mesh mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
||||
void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color, bool wires);
|
||||
|
||||
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
|
||||
|
||||
unsigned char *rlglReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
||||
void *rlglReadTexturePixels(Texture2D texture); // Read texture pixel data
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
void PrintProjectionMatrix(void); // DEBUG: Print projection matrix
|
||||
void PrintModelviewMatrix(void); // DEBUG: Print modelview matrix
|
||||
#endif
|
||||
|
||||
#if defined(RLGL_STANDALONE)
|
||||
//------------------------------------------------------------------------------------
|
||||
// Shaders System Functions (Module: rlgl)
|
||||
// NOTE: This functions are useless when using OpenGL 1.1
|
||||
//------------------------------------------------------------------------------------
|
||||
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
|
||||
unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr); // Load custom shader strings and return program id
|
||||
void UnloadShader(Shader shader); // Unload a custom shader from memory
|
||||
void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
|
||||
void SetDefaultShader(void); // Set default shader to be used in batch draw
|
||||
void SetModelShader(Model *model, Shader shader); // Link a shader to a model
|
||||
|
||||
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
||||
void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
|
||||
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
|
||||
void SetShaderMapDiffuse(Shader *shader, Texture2D texture); // Default diffuse shader map texture assignment
|
||||
void SetShaderMapNormal(Shader *shader, const char *uniformName, Texture2D texture); // Normal map texture shader assignment
|
||||
void SetShaderMapSpecular(Shader *shader, const char *uniformName, Texture2D texture); // Specular map texture shader assignment
|
||||
void SetShaderMap(Shader *shader, int mapLocation, Texture2D texture, int textureUnit); // TODO: Generic shader map assignment
|
||||
|
||||
void SetBlendMode(int mode); // Set blending mode (alpha, additive, multiplied)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // RLGL_H
|
Loading…
Reference in New Issue
Block a user