Skip to content

Commit

Permalink
Copy texture to framebuffer, instead of framebuffer to texture, befor…
Browse files Browse the repository at this point in the history
…e submitting, so gamma correction could work in VR
  • Loading branch information
cmbruns committed Jun 26, 2017
1 parent d24a600 commit 45980ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/gl/stereo3d/gl_openvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,12 @@ bool OpenVREyePose::submitFrame(VR_IVRCompositor_FnTable * vrCompositor) const
return false;
if (vrCompositor == nullptr)
return false;
// Copy HDR framebuffer into 24-bit RGB texture
GLRenderer->mBuffers->BindEyeFB(eye, true);
// Copy HDR game texture to local vr LDR framebuffer, so gamma correction could work
if (eyeTexture->handle == nullptr) {
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

GLuint handle;
glGenTextures(1, &handle);
eyeTexture->handle = (void *)(std::ptrdiff_t)handle;
Expand All @@ -408,11 +411,19 @@ bool OpenVREyePose::submitFrame(VR_IVRCompositor_FnTable * vrCompositor) const
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, GLRenderer->mSceneViewport.width,
GLRenderer->mSceneViewport.height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);

glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, handle, 0);
GLenum drawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, drawBuffers);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
// TODO: react to error if it ever happens
}
}
glBindTexture(GL_TEXTURE_2D, (GLuint)(std::ptrdiff_t)eyeTexture->handle);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 0, 0,
GLRenderer->mSceneViewport.width,
GLRenderer->mSceneViewport.height, 0);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
GLRenderer->mBuffers->BindEyeTexture(eye, 0);
GL_IRECT box = {0, 0, GLRenderer->mSceneViewport.width, GLRenderer->mSceneViewport.height};
GLRenderer->DrawPresentTexture(box, true);

vrCompositor->Submit(EVREye(eye), eyeTexture, nullptr, EVRSubmitFlags_Submit_Default);
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/gl/stereo3d/gl_openvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class OpenVREyePose : public ShiftedEyePose
VSMatrix eyeToHeadTransform;
VSMatrix otherEyeToHeadTransform;
Texture_t* eyeTexture;
mutable uint32_t framebuffer;
int eye;

mutable const TrackedDevicePose_t * currentPose;
Expand Down

0 comments on commit 45980ec

Please sign in to comment.