+#include <assert.h>
#include "rtarg.h"
struct RTStackItem {
vp[2] = prev->get_width();
vp[3] = prev->get_height();
} else {
- memcpy(vp, rstack[rtop].saved_vp, 4 * sizeof(int));
+ glGetIntegerv(GL_VIEWPORT, vp);
}
rstack[++rtop].rt = rt;
+
+ rt->bind();
return true;
}
{
fbo = 0;
rbdepth = 0;
+ rbdepth_fmt = 0;
width = height = tex_width = tex_height = 0;
auto_vport = true;
rtcount = 0;
tex[i] = 0;
own_texture[i] = true;
}
+ depth = 0;
}
RenderTarget::~RenderTarget()
tex[i]->create(tex_width, tex_height, TEX_2D, fmt);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D,
tex[i]->get_id(), 0);
+ glBindTexture(GL_TEXTURE_2D, 0);
own_texture[i] = true;
}
} else {
}
if(flags & (RT_DEPTH | RT_STENCIL)) {
- unsigned int fmt, attachment;
+ unsigned int attachment;
glGenRenderbuffers(1, &rbdepth);
glBindRenderbuffer(GL_RENDERBUFFER, rbdepth);
switch(flags & (RT_DEPTH | RT_STENCIL)) {
case RT_DEPTH:
- fmt = GL_DEPTH_COMPONENT24;
+ rbdepth_fmt = GL_DEPTH_COMPONENT24;
attachment = GL_DEPTH_ATTACHMENT;
break;
case RT_STENCIL:
- fmt = GL_STENCIL_INDEX8;
+ rbdepth_fmt = GL_STENCIL_INDEX8;
attachment = GL_STENCIL_ATTACHMENT;
break;
case RT_DEPTH | RT_STENCIL:
- fmt = GL_DEPTH24_STENCIL8;
+ rbdepth_fmt = GL_DEPTH24_STENCIL8;
attachment = GL_DEPTH_STENCIL_ATTACHMENT;
break;
}
- glRenderbufferStorage(GL_RENDERBUFFER, fmt, width, height);
+ glRenderbufferStorage(GL_RENDERBUFFER, rbdepth_fmt, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, rbdepth);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
} else if(depth) {
attach_depth_texture(depth);
}
}
+bool RenderTarget::resize(int xsz, int ysz)
+{
+ int new_tx = next_pow2(xsz);
+ int new_ty = next_pow2(ysz);
+
+ if(new_tx != tex_width || new_ty != tex_height) {
+ tex_width = new_tx;
+ tex_height = new_ty;
+
+ for(int i=0; i<4; i++) {
+ if(tex[i]) {
+ tex[i]->create(new_tx, new_ty, TEX_2D, tex[i]->get_format());
+ }
+ }
+
+ if(depth) {
+ depth->create(new_tx, new_ty, TEX_2D, depth->get_format());
+ }
+ }
+
+ if(rbdepth) {
+ glBindRenderbuffer(GL_RENDERBUFFER, rbdepth);
+ glRenderbufferStorage(GL_RENDERBUFFER, rbdepth_fmt, xsz, ysz);
+ }
+
+ width = xsz;
+ height = ysz;
+ return true;
+}
+
int RenderTarget::get_width() const
{
return width;
default:
error_log("failed to attach depth/stencil texture: unexpected texture format: %x\n", fmt);
- break;
+ return;
}
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, tex->get_id(), 0);