trying some shader stuff, but segfaults
This commit is contained in:
58
lib/FrameBuffer.cpp
Normal file
58
lib/FrameBuffer.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
// FrameBuffer.cpp
|
||||
|
||||
#include "FrameBuffer.h"
|
||||
|
||||
FrameBuffer::FrameBuffer(float width, float height) {
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
texture, 0);
|
||||
|
||||
glGenRenderbuffers(1, &rbo);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER, rbo);
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
std::cout << "ERROR::FRAMEBUFFER:: Framebuffer is not complete!"
|
||||
<< std::endl;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
FrameBuffer::~FrameBuffer() {
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
glDeleteTextures(1, &texture);
|
||||
glDeleteRenderbuffers(1, &rbo);
|
||||
}
|
||||
|
||||
unsigned int FrameBuffer::getFrameTexture() { return texture; }
|
||||
|
||||
void FrameBuffer::RescaleFrameBuffer(float width, float height) {
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
texture, 0);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER, rbo);
|
||||
}
|
||||
|
||||
void FrameBuffer::Bind() const { glBindFramebuffer(GL_FRAMEBUFFER, fbo); }
|
||||
|
||||
void FrameBuffer::Unbind() const { glBindFramebuffer(GL_FRAMEBUFFER, 0); }
|
38
lib/FrameBuffer.h
Normal file
38
lib/FrameBuffer.h
Normal file
@ -0,0 +1,38 @@
|
||||
// FrameBuffer.h
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#else
|
||||
#include "GL/glew.h"
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#if defined(__APPLE__)
|
||||
#include <SDL2/SDL.h>
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#include <SDL2/SDL_opengles.h>
|
||||
#else
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#endif
|
||||
#else
|
||||
#include <SDL.h>
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#include <SDL_opengles2.h>
|
||||
#else
|
||||
#include <SDL_opengl.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class FrameBuffer {
|
||||
public:
|
||||
FrameBuffer(float width, float height);
|
||||
~FrameBuffer();
|
||||
unsigned int getFrameTexture();
|
||||
void RescaleFrameBuffer(float width, float height);
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
|
||||
private:
|
||||
unsigned int fbo;
|
||||
unsigned int texture;
|
||||
unsigned int rbo;
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
|
||||
#include "../ImNodeFlow.h"
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
|
||||
@ -20,12 +20,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "../ImNodeFlow.h"
|
||||
#include "../image_model.h"
|
||||
#include "../imfilebrowser.h"
|
||||
#include "../stb_image.h"
|
||||
#include "../uuid.h"
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include "../emscripten_browser_file.h"
|
||||
@ -54,7 +53,11 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
~Exposure() { stbi_image_free(returnBundle.image); }
|
||||
~Exposure() {
|
||||
if (returnBundle.loaded) {
|
||||
stbi_image_free(returnBundle.image);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
ImGui::SetNextItemWidth(100);
|
||||
@ -158,7 +161,11 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
~Contrast() { stbi_image_free(returnBundle.image); }
|
||||
~Contrast() {
|
||||
if (returnBundle.loaded) {
|
||||
stbi_image_free(returnBundle.image);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
ImGui::SetNextItemWidth(100);
|
||||
@ -263,7 +270,11 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
~SimpleBrightness() { stbi_image_free(returnBundle.image); }
|
||||
~SimpleBrightness() {
|
||||
if (returnBundle.loaded) {
|
||||
stbi_image_free(returnBundle.image);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
ImGui::SetNextItemWidth(100);
|
||||
|
Reference in New Issue
Block a user