SceneRefract: Draw to correct FBO in off-screen mode
The "refract" scene incorrectly used FBO 0 in off-screen mode. This commit
updates the scene to properly handle a non-zero canvas FBO.
diff --git a/src/scene-refract.cpp b/src/scene-refract.cpp
index 4bc2fd8..0c726fc 100644
--- a/src/scene-refract.cpp
+++ b/src/scene-refract.cpp
@@ -177,7 +177,7 @@
//
bool
-DistanceRenderTarget::setup(unsigned int width, unsigned int height)
+DistanceRenderTarget::setup(unsigned int canvas_fbo, unsigned int width, unsigned int height)
{
static const string vtx_shader_filename(Options::data_path + "/shaders/depth.vert");
static const string frg_shader_filename(Options::data_path + "/shaders/depth.frag");
@@ -193,6 +193,7 @@
canvas_height_ = height;
width_ = canvas_width_ * 2;
height_ = canvas_height_ * 2;
+ canvas_fbo_ = canvas_fbo;
// If the texture will be too large for the implemnetation, we need to
// clamp the dimensions but maintain the aspect ratio.
@@ -236,7 +237,7 @@
Log::error("DistanceRenderTarget::setup: glCheckFramebufferStatus failed (0x%x)\n", status);
return false;
}
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, canvas_fbo_);
return true;
}
@@ -273,7 +274,7 @@
void DistanceRenderTarget::disable()
{
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, canvas_fbo_);
glViewport(0, 0, canvas_width_, canvas_height_);
glCullFace(GL_BACK);
}
@@ -383,7 +384,7 @@
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
- if (!depthTarget_.setup(canvas_.width(), canvas_.height())) {
+ if (!depthTarget_.setup(canvas_.fbo(), canvas_.width(), canvas_.height())) {
Log::error("Failed to set up the render target for the depth pass\n");
return false;
}
diff --git a/src/scene-refract.h b/src/scene-refract.h
index d8e65f0..3733a21 100644
--- a/src/scene-refract.h
+++ b/src/scene-refract.h
@@ -46,6 +46,7 @@
unsigned int height_;
unsigned int tex_[2];
unsigned int fbo_;
+ unsigned int canvas_fbo_;
public:
DistanceRenderTarget() :
canvas_width_(0),
@@ -57,7 +58,7 @@
tex_[DEPTH] = tex_[COLOR] = 0;
}
~DistanceRenderTarget() {}
- bool setup(unsigned int width, unsigned int height);
+ bool setup(unsigned int canvas_fbo, unsigned int width, unsigned int height);
void teardown();
void enable(const LibMatrix::mat4& mvp);
void disable();