Load OpenGL through SDL instead of glad
gl.h lists the 62 functions the editor calls, loaded with SDL_GL_GetProcAddress into gl, as in smack-a-brother. The 25k lines of glad and KHR headers are gone.
This commit is contained in:
1 parent
7e81ea4259
commit
6f2fc8c196
18 files changed
+254
-25290
No files matched your search
+28
-28
@@ -6,9 +6,9 @@ using namespace glm;
|
||||
|
||||
Framebuffer::Framebuffer()
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glGenRenderbuffers(1, &rbo);
|
||||
glGenTextures(1, &texture);
|
||||
gl.GenFramebuffers(1, &fbo);
|
||||
gl.GenRenderbuffers(1, &rbo);
|
||||
gl.GenTextures(1, &texture);
|
||||
set();
|
||||
}
|
||||
|
||||
@@ -17,27 +17,27 @@ Framebuffer::~Framebuffer()
|
||||
if (!is_valid())
|
||||
return;
|
||||
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
glDeleteRenderbuffers(1, &rbo);
|
||||
glDeleteTextures(1, &texture);
|
||||
gl.DeleteFramebuffers(1, &fbo);
|
||||
gl.DeleteRenderbuffers(1, &rbo);
|
||||
gl.DeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
void Framebuffer::set()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
gl.BindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
gl.BindTexture(GL_TEXTURE_2D, texture);
|
||||
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, size.x, size.y);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
||||
gl.BindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||
gl.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, size.x, size.y);
|
||||
gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void Framebuffer::resize_check()
|
||||
@@ -61,23 +61,23 @@ std::vector<uint8_t> Framebuffer::pixels_get() const
|
||||
auto count = size.x * size.y * IMAGE_CHANNELS;
|
||||
std::vector<uint8_t> pixels(count);
|
||||
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
gl.ReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
gl.PixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
gl.PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
gl.ReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
|
||||
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
void Framebuffer::clear(vec4 color) const
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
gl.Enable(GL_BLEND);
|
||||
gl.ClearColor(color.r, color.g, color.b, color.a);
|
||||
gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if (color.a <= 0.0f)
|
||||
glDisable(GL_BLEND);
|
||||
gl.Disable(GL_BLEND);
|
||||
}
|
||||
|
||||
bool Framebuffer::is_valid() const
|
||||
@@ -87,15 +87,15 @@ bool Framebuffer::is_valid() const
|
||||
|
||||
void Framebuffer::viewport_set() const
|
||||
{
|
||||
glViewport(0, 0, size.x, size.y);
|
||||
gl.Viewport(0, 0, size.x, size.y);
|
||||
}
|
||||
|
||||
void Framebuffer::bind() const
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
gl.BindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
}
|
||||
|
||||
void Framebuffer::unbind() const
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
Reference in new issue
Block a user