-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from JerboaBurrow/addMSAA
adds msaa setting into instanced
- Loading branch information
Showing
9 changed files
with
263 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifndef GLDRAWFRAMEBUFFER | ||
#define GLDRAWFRAMEBUFFER | ||
|
||
#include <cstdint> | ||
|
||
#include <glm/glm.hpp> | ||
|
||
#include <jGL/OpenGL/gl.h> | ||
|
||
namespace jGL::GL | ||
{ | ||
class glDrawFramebuffer | ||
{ | ||
|
||
public: | ||
|
||
glDrawFramebuffer() | ||
{ | ||
if(!glIsFramebuffer(buffer)) | ||
{ | ||
glGenFramebuffers(1, &buffer); | ||
} | ||
|
||
if(!glIsTexture(texture)) | ||
{ | ||
glGenTextures(1, &texture); | ||
} | ||
} | ||
|
||
void destroy() | ||
{ | ||
if (glIsFramebuffer(buffer)) | ||
{ | ||
glDeleteFramebuffers(1, &buffer); | ||
} | ||
|
||
if (glIsTexture(texture)) | ||
{ | ||
glDeleteTextures(1, &texture); | ||
} | ||
} | ||
|
||
void bind() | ||
{ | ||
glBindFramebuffer(GL_FRAMEBUFFER, buffer); | ||
glBufferStatus("bind framebuffer"); | ||
} | ||
|
||
void blit() | ||
{ | ||
glBindFramebuffer(GL_READ_FRAMEBUFFER, buffer); | ||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); | ||
glBlitFramebuffer(0, 0, resX, resY, 0, 0, resX, resY, GL_COLOR_BUFFER_BIT, GL_NEAREST); | ||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
glError("blit framebuffer"); | ||
} | ||
|
||
void setClear(glm::vec4 c) | ||
{ | ||
clearColour = c; | ||
glClearColor(clearColour.r, clearColour.g, clearColour.b, clearColour.a); | ||
} | ||
|
||
void clear() { glClear(GL_COLOR_BUFFER_BIT); } | ||
|
||
void setResolution(glm::vec2 res) | ||
{ | ||
resX = res.x; | ||
resY = res.y; | ||
} | ||
|
||
void setMSAA(uint8_t samples) | ||
{ | ||
msaaSamples = samples; | ||
|
||
glBindFramebuffer(GL_FRAMEBUFFER, buffer); | ||
glActiveTexture(GL_TEXTURE0); | ||
|
||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture); | ||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, msaaSamples, GL_RGB, resX, resY, GL_TRUE); | ||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); | ||
|
||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, texture, 0); | ||
setClear(clearColour); | ||
} | ||
|
||
static const bool isMSAA() {return msaaSamples > 0;} | ||
|
||
private: | ||
|
||
static bool initialised; | ||
|
||
static uint8_t msaaSamples; | ||
|
||
static GLuint buffer, texture; | ||
|
||
static uint16_t resX, resY; | ||
|
||
static glm::vec4 clearColour; | ||
|
||
}; | ||
} | ||
|
||
#endif /* GLDrawFRAMEBUFFER */ |
Oops, something went wrong.