2015-10-21 16:29:00 -07:00
|
|
|
#include "OVR_CAPI_GL.h"
|
2016-09-24 13:22:26 +02:00
|
|
|
#include "Assert.h"
|
2017-04-13 03:53:35 +02:00
|
|
|
#include "Session.h"
|
2016-09-05 22:04:26 +02:00
|
|
|
#include "CompositorGL.h"
|
2016-09-23 22:35:19 +02:00
|
|
|
#include "TextureGL.h"
|
2015-10-21 16:29:00 -07:00
|
|
|
|
2016-04-29 11:18:52 +00:00
|
|
|
OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateTextureSwapChainGL(ovrSession session,
|
|
|
|
|
const ovrTextureSwapChainDesc* desc,
|
|
|
|
|
ovrTextureSwapChain* out_TextureSwapChain)
|
|
|
|
|
{
|
2016-08-20 02:10:39 +02:00
|
|
|
REV_TRACE(ovr_CreateTextureSwapChainGL);
|
|
|
|
|
|
2016-04-29 11:18:52 +00:00
|
|
|
if (!desc || !out_TextureSwapChain || desc->Type != ovrTexture_2D)
|
|
|
|
|
return ovrError_InvalidParameter;
|
|
|
|
|
|
2016-09-05 22:04:26 +02:00
|
|
|
if (!session->Compositor)
|
2016-09-06 16:48:15 +02:00
|
|
|
{
|
2017-02-15 17:22:48 +01:00
|
|
|
session->Compositor.reset(CompositorGL::Create());
|
2016-09-06 16:48:15 +02:00
|
|
|
if (!session->Compositor)
|
|
|
|
|
return ovrError_RuntimeException;
|
|
|
|
|
}
|
2016-07-01 14:22:37 +00:00
|
|
|
|
2017-04-11 19:07:19 +02:00
|
|
|
if (session->Compositor->GetAPI() != vr::TextureType_OpenGL)
|
2016-09-05 22:04:26 +02:00
|
|
|
return ovrError_RuntimeException;
|
2015-10-21 16:29:00 -07:00
|
|
|
|
2016-09-05 22:04:26 +02:00
|
|
|
return session->Compositor->CreateTextureSwapChain(desc, out_TextureSwapChain);
|
2016-06-30 23:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 16:29:00 -07:00
|
|
|
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetTextureSwapChainBufferGL(ovrSession session,
|
|
|
|
|
ovrTextureSwapChain chain,
|
|
|
|
|
int index,
|
2016-04-29 11:18:52 +00:00
|
|
|
unsigned int* out_TexId)
|
|
|
|
|
{
|
2016-08-20 02:10:39 +02:00
|
|
|
REV_TRACE(ovr_GetTextureSwapChainBufferGL);
|
|
|
|
|
|
2016-07-01 21:34:40 +00:00
|
|
|
if (!session)
|
|
|
|
|
return ovrError_InvalidSession;
|
|
|
|
|
|
|
|
|
|
if (!chain || !out_TexId)
|
|
|
|
|
return ovrError_InvalidParameter;
|
|
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
|
index = chain->CurrentIndex;
|
|
|
|
|
|
2017-10-09 22:54:47 +02:00
|
|
|
TextureGL* texture = dynamic_cast<TextureGL*>(chain->Textures[index].get());
|
|
|
|
|
if (!texture)
|
|
|
|
|
return ovrError_InvalidParameter;
|
|
|
|
|
|
2016-09-23 22:35:19 +02:00
|
|
|
*out_TexId = texture->Texture;
|
2016-04-29 11:18:52 +00:00
|
|
|
return ovrSuccess;
|
|
|
|
|
}
|
2015-10-21 16:29:00 -07:00
|
|
|
|
|
|
|
|
OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateMirrorTextureGL(ovrSession session,
|
|
|
|
|
const ovrMirrorTextureDesc* desc,
|
2016-04-27 15:44:47 +00:00
|
|
|
ovrMirrorTexture* out_MirrorTexture)
|
|
|
|
|
{
|
2016-08-20 02:10:39 +02:00
|
|
|
REV_TRACE(ovr_CreateMirrorTextureGL);
|
|
|
|
|
|
2016-04-29 11:18:52 +00:00
|
|
|
if (!desc || !out_MirrorTexture)
|
|
|
|
|
return ovrError_InvalidParameter;
|
|
|
|
|
|
2016-09-05 22:04:26 +02:00
|
|
|
if (!session->Compositor)
|
2016-09-06 16:48:15 +02:00
|
|
|
{
|
2017-02-15 17:22:48 +01:00
|
|
|
session->Compositor.reset(CompositorGL::Create());
|
2016-09-06 16:48:15 +02:00
|
|
|
if (!session->Compositor)
|
|
|
|
|
return ovrError_RuntimeException;
|
|
|
|
|
}
|
2016-07-01 14:22:37 +00:00
|
|
|
|
2017-04-11 19:07:19 +02:00
|
|
|
if (session->Compositor->GetAPI() != vr::TextureType_OpenGL)
|
2016-09-05 22:04:26 +02:00
|
|
|
return ovrError_RuntimeException;
|
2015-10-21 16:29:00 -07:00
|
|
|
|
2016-09-05 22:04:26 +02:00
|
|
|
return session->Compositor->CreateMirrorTexture(desc, out_MirrorTexture);
|
2016-06-30 23:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-14 21:51:27 +02:00
|
|
|
|
|
|
|
|
OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateMirrorTextureWithOptionsGL(ovrSession session,
|
|
|
|
|
const ovrMirrorTextureDesc* desc,
|
|
|
|
|
ovrMirrorTexture* out_MirrorTexture)
|
|
|
|
|
{
|
|
|
|
|
return ovr_CreateMirrorTextureGL(session, desc, out_MirrorTexture);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 16:29:00 -07:00
|
|
|
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetMirrorTextureBufferGL(ovrSession session,
|
|
|
|
|
ovrMirrorTexture mirrorTexture,
|
2016-04-29 11:18:52 +00:00
|
|
|
unsigned int* out_TexId)
|
|
|
|
|
{
|
2016-08-20 02:10:39 +02:00
|
|
|
REV_TRACE(ovr_GetMirrorTextureBufferGL);
|
|
|
|
|
|
2016-07-01 21:34:40 +00:00
|
|
|
if (!session)
|
|
|
|
|
return ovrError_InvalidSession;
|
|
|
|
|
|
|
|
|
|
if (!mirrorTexture || !out_TexId)
|
|
|
|
|
return ovrError_InvalidParameter;
|
|
|
|
|
|
2017-10-09 22:54:47 +02:00
|
|
|
TextureGL* texture = dynamic_cast<TextureGL*>(mirrorTexture->Texture.get());
|
|
|
|
|
if (!texture)
|
|
|
|
|
return ovrError_InvalidParameter;
|
|
|
|
|
|
2016-09-23 22:35:19 +02:00
|
|
|
*out_TexId = texture->Texture;
|
2016-04-29 11:18:52 +00:00
|
|
|
return ovrSuccess;
|
|
|
|
|
}
|