|
@@ -3,16 +3,14 @@
|
|
#include "Framebuffer.h"
|
|
#include "Framebuffer.h"
|
|
#include "client/Utils.h"
|
|
#include "client/Utils.h"
|
|
|
|
|
|
-Framebuffer::Framebuffer(u32 width, u32 height, u32 mode, int textureCompareFunc) : mode(mode), buffer(0), valid(false)
|
|
+Framebuffer::Framebuffer(u32 width, u32 height, u32 mode, int textureCompareFunc) : mode(mode), buffer(0), valid(false) {
|
|
-{
|
|
|
|
glGenFramebuffers(1, &buffer);
|
|
glGenFramebuffers(1, &buffer);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
|
|
-
|
|
+
|
|
GLuint attachments[4];
|
|
GLuint attachments[4];
|
|
u32 counter = 0;
|
|
u32 counter = 0;
|
|
-
|
|
+
|
|
- if(mode & POSITION)
|
|
+ if(mode & POSITION) {
|
|
- {
|
|
|
|
glGenTextures(1, &(textures[0]));
|
|
glGenTextures(1, &(textures[0]));
|
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
@@ -20,13 +18,12 @@ Framebuffer::Framebuffer(u32 width, u32 height, u32 mode, int textureCompareFunc
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[0], 0);
|
|
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[0], 0);
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
counter++;
|
|
counter++;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- if(mode & NORMAL)
|
|
+ if(mode & NORMAL) {
|
|
- {
|
|
|
|
glGenTextures(1, &(textures[1]));
|
|
glGenTextures(1, &(textures[1]));
|
|
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
@@ -34,13 +31,12 @@ Framebuffer::Framebuffer(u32 width, u32 height, u32 mode, int textureCompareFunc
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[1], 0);
|
|
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[1], 0);
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
counter++;
|
|
counter++;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- if(mode & COLOR)
|
|
+ if(mode & COLOR) {
|
|
- {
|
|
|
|
glGenTextures(1, &(textures[2]));
|
|
glGenTextures(1, &(textures[2]));
|
|
glBindTexture(GL_TEXTURE_2D, textures[2]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[2]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
|
@@ -48,13 +44,12 @@ Framebuffer::Framebuffer(u32 width, u32 height, u32 mode, int textureCompareFunc
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[2], 0);
|
|
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[2], 0);
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
counter++;
|
|
counter++;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- if(mode & RED)
|
|
+ if(mode & RED) {
|
|
- {
|
|
|
|
glGenTextures(1, &textures[3]);
|
|
glGenTextures(1, &textures[3]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[3]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[3]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
@@ -62,13 +57,12 @@ Framebuffer::Framebuffer(u32 width, u32 height, u32 mode, int textureCompareFunc
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[3], 0);
|
|
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + counter, GL_TEXTURE_2D, textures[3], 0);
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
attachments[counter] = GL_COLOR_ATTACHMENT0 + counter;
|
|
counter++;
|
|
counter++;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- if(mode & DEPTH24_STENCIL8)
|
|
+ if(mode & DEPTH24_STENCIL8) {
|
|
- {
|
|
|
|
glGenTextures(1, &textures[4]);
|
|
glGenTextures(1, &textures[4]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[4]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[4]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
|
|
@@ -76,99 +70,82 @@ Framebuffer::Framebuffer(u32 width, u32 height, u32 mode, int textureCompareFunc
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
- if(textureCompareFunc != 0)
|
|
+ if(textureCompareFunc != 0) {
|
|
- {
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, textureCompareFunc);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, textureCompareFunc);
|
|
}
|
|
}
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textures[4], 0);
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textures[4], 0);
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- glDrawBuffers(counter, attachments);
|
|
+ glDrawBuffers(counter, attachments);
|
|
-
|
|
+
|
|
- if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
|
+ if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
|
- {
|
|
+ std::cout << "frame buffer is not complete\n";
|
|
- std::cout << "frame buffer is not complete\n";
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
valid = true;
|
|
valid = true;
|
|
}
|
|
}
|
|
|
|
|
|
-Framebuffer::~Framebuffer()
|
|
+Framebuffer::~Framebuffer() {
|
|
-{
|
|
|
|
glDeleteFramebuffers(1, &buffer);
|
|
glDeleteFramebuffers(1, &buffer);
|
|
- for(GLuint& texture : textures)
|
|
+ for(GLuint& texture : textures) {
|
|
- {
|
|
|
|
glDeleteTextures(1, &texture);
|
|
glDeleteTextures(1, &texture);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-bool Framebuffer::isValid() const
|
|
+bool Framebuffer::isValid() const {
|
|
-{
|
|
|
|
return valid;
|
|
return valid;
|
|
}
|
|
}
|
|
|
|
|
|
-void Framebuffer::bind() const
|
|
+void Framebuffer::bind() const {
|
|
-{
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
}
|
|
}
|
|
|
|
|
|
-void Framebuffer::resize(u32 width, u32 height) const
|
|
+void Framebuffer::resize(u32 width, u32 height) const {
|
|
-{
|
|
+ if(mode & POSITION) {
|
|
- if(mode & POSITION)
|
|
|
|
- {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
}
|
|
}
|
|
- if(mode & NORMAL)
|
|
+ if(mode & NORMAL) {
|
|
- {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
}
|
|
}
|
|
- if(mode & COLOR)
|
|
+ if(mode & COLOR) {
|
|
- {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textures[2]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[2]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
|
}
|
|
}
|
|
- if(mode & RED)
|
|
+ if(mode & RED) {
|
|
- {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textures[3]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[3]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
|
|
}
|
|
}
|
|
- if(mode & DEPTH24_STENCIL8)
|
|
+ if(mode & DEPTH24_STENCIL8) {
|
|
- {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textures[4]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[4]);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void Framebuffer::bindPositionTexture(u32 textureUnit) const
|
|
+void Framebuffer::bindPositionTexture(u32 textureUnit) const {
|
|
-{
|
|
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
|
}
|
|
}
|
|
|
|
|
|
-void Framebuffer::bindNormalTexture(u32 textureUnit) const
|
|
+void Framebuffer::bindNormalTexture(u32 textureUnit) const {
|
|
-{
|
|
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
|
}
|
|
}
|
|
|
|
|
|
-void Framebuffer::bindColorTexture(u32 textureUnit) const
|
|
+void Framebuffer::bindColorTexture(u32 textureUnit) const {
|
|
-{
|
|
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glBindTexture(GL_TEXTURE_2D, textures[2]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[2]);
|
|
}
|
|
}
|
|
|
|
|
|
-void Framebuffer::bindRedTexture(u32 textureUnit) const
|
|
+void Framebuffer::bindRedTexture(u32 textureUnit) const {
|
|
-{
|
|
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glBindTexture(GL_TEXTURE_2D, textures[3]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[3]);
|
|
}
|
|
}
|
|
|
|
|
|
-void Framebuffer::bindDepthTexture(u32 textureUnit) const
|
|
+void Framebuffer::bindDepthTexture(u32 textureUnit) const {
|
|
-{
|
|
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
glBindTexture(GL_TEXTURE_2D, textures[4]);
|
|
glBindTexture(GL_TEXTURE_2D, textures[4]);
|
|
}
|
|
}
|