16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 03:09:18 +02:00

multisampling

This commit is contained in:
milek7
2018-07-13 00:32:25 +02:00
parent c94820e8b7
commit 0acf2da5c1
10 changed files with 96 additions and 52 deletions

View File

@@ -19,7 +19,7 @@ void gl::framebuffer::bind(GLuint id)
void gl::framebuffer::attach(const opengl_texture &tex, GLenum location)
{
bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, location, GL_TEXTURE_2D, tex.id, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, location, tex.target, tex.id, 0);
}
void gl::framebuffer::attach(const renderbuffer &rb, GLenum location)
@@ -35,8 +35,21 @@ bool gl::framebuffer::is_complete()
return status == GL_FRAMEBUFFER_COMPLETE;
}
void gl::framebuffer::clear()
void gl::framebuffer::clear(GLbitfield mask)
{
bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(mask);
}
void gl::framebuffer::blit_to(framebuffer &other, int w, int h, GLbitfield mask)
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, *this);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, other);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, mask, GL_NEAREST);
unbind();
}
void gl::framebuffer::blit_from(framebuffer &other, int w, int h, GLbitfield mask)
{
other.blit_to(*this, w, h, mask);
}

View File

@@ -15,9 +15,11 @@ namespace gl
void attach(const opengl_texture &tex, GLenum location);
void attach(const renderbuffer &rb, GLenum location);
void clear();
void clear(GLbitfield mask);
bool is_complete();
void blit_to(framebuffer &other, int w, int h, GLbitfield mask);
void blit_from(framebuffer &other, int w, int h, GLbitfield mask);
using bindable::bind;
static void bind(GLuint id);

View File

@@ -25,7 +25,7 @@ void gl::postfx::apply(opengl_texture &src, framebuffer *dst)
{
if (dst)
{
dst->clear();
dst->clear(GL_COLOR_BUFFER_BIT);
dst->bind();
}
else
@@ -36,5 +36,6 @@ void gl::postfx::apply(opengl_texture &src, framebuffer *dst)
glActiveTexture(GL_TEXTURE0);
src.bind();
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

View File

@@ -17,8 +17,11 @@ void gl::renderbuffer::bind(GLuint id)
glBindRenderbuffer(GL_RENDERBUFFER, id);
}
void gl::renderbuffer::alloc(GLuint format, int width, int height)
void gl::renderbuffer::alloc(GLuint format, int width, int height, int samples)
{
bind();
glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
if (samples == 1)
glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
else
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, format, width, height);
}

View File

@@ -11,7 +11,7 @@ namespace gl
renderbuffer();
~renderbuffer();
void alloc(GLuint format, int width, int height);
void alloc(GLuint format, int width, int height, int samples = 1);
static void bind(GLuint id);
using bindable::bind;