01-24-2019 05:05 AM
textureSwapChain = 0; swap_chain_desc = {};
swap_chain_desc.Type = ovrTexture_2D;
swap_chain_desc.ArraySize = 1;
swap_chain_desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
swap_chain_desc.Width = renderTargetSize.w;
swap_chain_desc.Height = renderTargetSize.h;
swap_chain_desc.MipLevels = 1;
swap_chain_desc.SampleCount = 1;
swap_chain_desc.StaticImage = ovrFalse;
If(ovr_CreateTextureSwapChainGL(session,&swap_chain_desc,&textureSwapChain) == ovrSuccess)
int Hmd::init_framebuffers(){
// Framebuffers
//-----------------------------------------------
// In order to display, it has to be "complete" (at least 1 color/depth/stencil buffer attached, 1color attachement, same number of multisamples, attachement completes)
frameBuffer = 0;
glGenFramebuffers(1, &frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); // ---- Texture "Color Buffer"
textureSwapChain = 0; swap_chain_desc = {};
swap_chain_desc.Type = ovrTexture_2D;
swap_chain_desc.ArraySize = 1;
swap_chain_desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
swap_chain_desc.Width = renderTargetSize.w;
swap_chain_desc.Height = renderTargetSize.h;
swap_chain_desc.MipLevels = 1;
swap_chain_desc.SampleCount = 1;
swap_chain_desc.StaticImage = ovrFalse;
ovr_CreateTextureSwapChainGL(session, &swap_chain_desc, &textureSwapChain);
hmdDesc = ovr_GetHmdDesc(session);
eyeRenderDesc[0] = ovr_GetRenderDesc(session, ovrEye_Left, hmdDesc.DefaultEyeFov[0]);
//eyeRenderDesc[1] = ovr_GetRenderDesc(session, ovrEye_Right, hmdDesc.DefaultEyeFov[1]);
hmdToEyeViewPose[0] = eyeRenderDesc[0].HmdToEyePose;
hmdToEyeViewPose[1] = eyeRenderDesc[1].HmdToEyePose; // Initialize our single full screen Fov layer.
layer.Header.Type = ovrLayerType_EyeFov;
layer.Header.Flags = 0;
layer.ColorTexture[0] = textureSwapChain;
layer.ColorTexture[1] = textureSwapChain;
layer.Fov[0] = eyeRenderDesc[0].Fov;
layer.Fov[1] = eyeRenderDesc[1].Fov;
layer.Viewport[0] = OVR::Recti(0, 0, renderTargetSize.w / 2, renderTargetSize.h);
layer.Viewport[1] = OVR::Recti(renderTargetSize.w / 2, 0, renderTargetSize.w / 2, renderTargetSize.h);
glGenTextures(1, &renderedTex); ovr_GetTextureSwapChainBufferGL(session, textureSwapChain, 0, &renderedTex); glBindTexture(GL_TEXTURE_2D, renderedTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, renderTargetSize.w, renderTargetSize.h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, 0); glGenRenderbuffers(1, &renderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, renderTargetSize.w, renderTargetSize.h); // Attaching the render buffer to the framebuffer
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);
// Attaching the color buffer to the frame Buffer
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderedTex, 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTex, 0); //}
// ---- RenderBuffer
// Render Buffer (to be able to render Depth calculation)
GLenum l_GLDrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, l_GLDrawBuffers); // "1" is the size of DrawBuffers
GLenum l_Check = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
if (l_Check!=GL_FRAMEBUFFER_COMPLETE)
{
printf("There is a problem with the FBO.\n");
exit(199);
} return 0;
}
Solved! Go to Solution.
01-24-2019 02:58 PM
01-24-2019 02:58 PM
01-25-2019 06:25 AM