Resize frame buffer method added
This commit is contained in:
parent
bc29860385
commit
8bfe44b3cd
6 changed files with 66 additions and 13 deletions
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
void glerr(GLenum type) { printf("GL ERROR\n"); }
|
||||
void glerr(GLenum type) {
|
||||
printf("GL ERROR - %i\n", type);
|
||||
}
|
||||
|
||||
#define AssertGL(x) \
|
||||
{ \
|
||||
x; \
|
||||
|
|
@ -15,7 +18,8 @@ void glerr(GLenum type) { printf("GL ERROR\n"); }
|
|||
using namespace tp;
|
||||
|
||||
RenderBuffer::RenderBuffer(const Vec2F& size) :
|
||||
mSize(size) {
|
||||
mSize(size), mSamples(0)
|
||||
{
|
||||
|
||||
mDrawBuffers[0] = { GL_COLOR_ATTACHMENT0 };
|
||||
|
||||
|
|
@ -47,7 +51,8 @@ RenderBuffer::RenderBuffer(const Vec2F& size) :
|
|||
}
|
||||
|
||||
RenderBuffer::RenderBuffer(const Vec2F& size, tp::uint1 samples) :
|
||||
mSize(size) {
|
||||
mSize(size), mSamples(samples)
|
||||
{
|
||||
|
||||
mDrawBuffers[0] = { GL_COLOR_ATTACHMENT0 };
|
||||
|
||||
|
|
@ -115,3 +120,40 @@ RenderBuffer::~RenderBuffer() {
|
|||
uint4 RenderBuffer::texId() const { return mTextureId; }
|
||||
|
||||
const Vec2F& RenderBuffer::getSize() const { return mSize; }
|
||||
|
||||
void RenderBuffer::resize(const Vec2F& size) {
|
||||
if (size == mSize) return;
|
||||
|
||||
// Update size
|
||||
mSize = size;
|
||||
|
||||
// Bind framebuffer
|
||||
AssertGL(glBindFramebuffer(GL_FRAMEBUFFER, mFrameBufferID));
|
||||
|
||||
// Resize color texture
|
||||
if (mSamples) {
|
||||
AssertGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextureId));
|
||||
AssertGL(glTexImage2DMultisample(
|
||||
GL_TEXTURE_2D_MULTISAMPLE, mSamples, GL_RGBA, (GLsizei)size.x, (GLsizei)size.y, GL_TRUE
|
||||
));
|
||||
AssertGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0));
|
||||
} else {
|
||||
AssertGL(glBindTexture(GL_TEXTURE_2D, mTextureId));
|
||||
AssertGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)size.x, (GLsizei)size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0));
|
||||
AssertGL(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
}
|
||||
|
||||
// Resize depth renderbuffer
|
||||
if (mSamples) {
|
||||
AssertGL(glBindRenderbuffer(GL_RENDERBUFFER, mDepthBufferID));
|
||||
AssertGL(glRenderbufferStorageMultisample(
|
||||
GL_RENDERBUFFER, mSamples, GLW_CONTEXT_DEPTH_COMPONENT, (GLsizei)size.x, (GLsizei)size.y
|
||||
));
|
||||
} else {
|
||||
AssertGL(glBindRenderbuffer(GL_RENDERBUFFER, mDepthBufferID));
|
||||
AssertGL(glRenderbufferStorage(GL_RENDERBUFFER, GLW_CONTEXT_DEPTH_COMPONENT, (GLsizei)size.x, (GLsizei)size.y));
|
||||
}
|
||||
|
||||
// Unbind framebuffer
|
||||
AssertGL(glBindFramebuffer(GL_FRAMEBUFFER, 0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
namespace tp {
|
||||
class RenderBuffer {
|
||||
public:
|
||||
RenderBuffer(const Vec2F& size);
|
||||
explicit RenderBuffer(const Vec2F& size);
|
||||
RenderBuffer(const Vec2F& size, tp::uint1 samples);
|
||||
~RenderBuffer();
|
||||
|
||||
|
|
@ -16,10 +16,12 @@ namespace tp {
|
|||
void clear();
|
||||
void endDraw();
|
||||
|
||||
uint4 texId() const;
|
||||
uint4 buffId() const;
|
||||
[[nodiscard]] uint4 texId() const;
|
||||
[[nodiscard]] uint4 buffId() const;
|
||||
|
||||
const Vec2F& getSize() const;
|
||||
void resize(const Vec2F& size);
|
||||
|
||||
[[nodiscard]] const Vec2F& getSize() const;
|
||||
|
||||
public:
|
||||
RGBA mClearCol = 0.f;
|
||||
|
|
@ -28,7 +30,8 @@ namespace tp {
|
|||
uint4 mFrameBufferID = 0; // regroups 0, 1, or more textures, and 0 or 1 depth buffer.
|
||||
uint4 mTextureId = 0; // texture we're going to render to ( colour attachement #0 )
|
||||
uint4 mDepthBufferID = 0;
|
||||
uint4 mDrawBuffers[1];
|
||||
uint4 mDrawBuffers[1] = { 0 };
|
||||
Vec2F mSize;
|
||||
ualni mSamples = 0;
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue