Uhhhhh big big changes

This commit is contained in:
NaifBanana
2026-08-20 08:14:29 -05:00
parent bb2f046c90
commit be68245771
20 changed files with 561 additions and 285 deletions
+86 -27
View File
@@ -11,7 +11,9 @@ const ErrorCodeMap FrameBufferError::ErrorMessages = {
GLuint FrameBufferBase::declare() {
if (!_id) {
glGenFramebuffers(1, &_id);
OPENGL_CALL(
glGenFramebuffers(1, &_id)
);
}
bind();
return _id;
@@ -20,7 +22,9 @@ GLuint FrameBufferBase::declare() {
void FrameBufferBase::remove() {
if (_id) {
unbind();
glDeleteFramebuffers(1, &_id);
OPENGL_CALL(
glDeleteFramebuffers(1, &_id)
);
_id=0;
}
}
@@ -31,7 +35,9 @@ std::shared_ptr<RenderTarget> FrameBufferBase::detach(GLenum attch_) {
bind();
auto ret = _attachments.at(attch_);
_attachments.erase(attch_);
glFramebufferTexture(Target, attch_, 0, 0);
OPENGL_CALL(
glFramebufferTexture(Target, attch_, 0, 0)
);
return ret;
}
@@ -47,13 +53,13 @@ void FrameBufferBase::attach(
"Cannot attach object to `GL_NONE`"
));
}
glFramebufferTextureLayer(
OPENGL_CALL(glFramebufferTextureLayer(
Target,
attachment_,
texture_->id(),
level_,
layer_
);
));
_attachments[attachment_] = texture_;
}
@@ -69,43 +75,72 @@ void FrameBufferBase::attach(
));
}
if (texTypeIs2D(texture_->Target)) {
glFramebufferTexture2D(
OPENGL_CALL(glFramebufferTexture2D(
Target,
attachment_,
texture_->Target,
texture_->id(),
level_
);
));
} else {
glFramebufferTexture1D(
OPENGL_CALL(glFramebufferTexture1D(
Target,
attachment_,
texture_->Target,
texture_->id(),
level_
);
));
}
_attachments[attachment_] = texture_;
}
void FrameBufferBase::attach(
GLenum attachment,
std::shared_ptr<RenderBuffer> renderbuffer
) {
declare();
if (attachment == GL_NONE) {
THROW(FrameBufferError(FrameBufferError::INVALID_VALUE,
"Cannot attach RenderBuffer to `GL_NONE`"
));
}
OPENGL_CALL(glFramebufferRenderbuffer(
Target,
attachment,
GL_RENDERBUFFER,
renderbuffer->id()
));
_attachments[attachment] = renderbuffer;
}
void FrameBufferBase::bind() const {
if (_id) {
glBindFramebuffer(Target, _id);
OPENGL_CALL(
glBindFramebuffer(Target, _id)
);
} else {
THROW(OGLError(
OGLError::Codes::INVALID_OBJECT,
THROW(OpenGLObjectError(
OpenGLObjectError::Codes::INVALID_OBJECT,
"w/ FrameBuffer"
));
}
}
void FrameBufferBase::unbind() const {
glBindFramebuffer(Target, 0);
OPENGL_CALL(
glBindFramebuffer(Target, 0)
);
}
GLenum FrameBufferBase::status() const {
bind();
return glCheckFramebufferStatus(Target);
return OPENGL_CALL(
glCheckFramebufferStatus(Target)
);
}
bool FrameBufferBase::complete() const {
return status() == GL_FRAMEBUFFER_COMPLETE;
}
FrameBufferBase::AttachmentMap FrameBufferBase::getAllBuffers() const {
@@ -166,7 +201,7 @@ std::shared_ptr<RenderTarget> ReadFrameBuffer::setReadBuffer(GLenum attch_) {
}
}
_location = attch_;
glReadBuffer(_location);
OPENGL_CALL(glReadBuffer(_location));
return getReadBuffer();
}
@@ -222,7 +257,9 @@ WriteFrameBuffer::DrawTexVec WriteFrameBuffer::setWriteBuffers(const std::vector
}
}
_locations = attchs_;
glDrawBuffers(_locations.size(), _locations.data());
OPENGL_CALL(
glDrawBuffers(_locations.size(), _locations.data())
);
return getWriteBuffers();
}
@@ -230,7 +267,9 @@ std::shared_ptr<Texture> WriteFrameBuffer::setWriteBuffer(GLenum attch_) {
bind();
if (attch_ == GL_NONE) {
std::vector<GLenum> tmp(_locations.size(), GL_NONE);
glDrawBuffers(tmp.size(), tmp.data());
OPENGL_CALL(
glDrawBuffers(tmp.size(), tmp.data())
);
_locations = {};
return nullptr;
}
@@ -241,13 +280,17 @@ std::shared_ptr<Texture> WriteFrameBuffer::setWriteBuffer(GLenum attch_) {
fRGBA WriteFrameBuffer::clearColorValue() const {
bind();
float rgba[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
OPENGL_CALL(
glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba)
);
return fRGBA{rgba[0], rgba[1], rgba[2], rgba[3]};
}
fRGBA WriteFrameBuffer::clearColorValue(const fRGBA& color) {
declare();
glClearColor(color.r, color.g, color.b, color.a);
OPENGL_CALL(
glClearColor(color.r, color.g, color.b, color.a)
);
return color;
}
@@ -258,32 +301,42 @@ fRGBA WriteFrameBuffer::clearColorValue(float r, float g, float b, float a) {
double WriteFrameBuffer::clearDepthValue() const {
bind();
double ret;
glGetDoublev(GL_DEPTH_CLEAR_VALUE, &ret);
OPENGL_CALL(
glGetDoublev(GL_DEPTH_CLEAR_VALUE, &ret)
);
return ret;
}
double WriteFrameBuffer::clearDepthValue(double d_) {
declare();
glClearDepth(d_);
OPENGL_CALL(
glClearDepth(d_)
);
return d_;
}
GLint WriteFrameBuffer::clearStencilValue() const {
bind();
GLint ret;
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &ret);
OPENGL_CALL(
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &ret)
);
return ret;
}
GLint WriteFrameBuffer::clearStencilValue(GLint s_) {
declare();
glClearStencil(s_);
OPENGL_CALL(
glClearStencil(s_)
);
return s_;
}
void WriteFrameBuffer::clear(GLbitfield mask_) const {
bind();
glClear(mask_);
OPENGL_CALL(
glClear(mask_)
);
}
void WriteFrameBuffer::clearDepth() const {
@@ -292,7 +345,9 @@ void WriteFrameBuffer::clearDepth() const {
void WriteFrameBuffer::clearDepth(float val_) const {
bind();
glClearBufferfv(GL_DEPTH, 0, &val_);
OPENGL_CALL(
glClearBufferfv(GL_DEPTH, 0, &val_)
);
}
void WriteFrameBuffer::clearStencil() const {
@@ -301,7 +356,9 @@ void WriteFrameBuffer::clearStencil() const {
void WriteFrameBuffer::clearStencil(GLint val_) const {
bind();
glClearBufferiv(GL_STENCIL, 0, &val_);
OPENGL_CALL(
glClearBufferiv(GL_STENCIL, 0, &val_)
);
}
void WriteFrameBuffer::clearDepthStencil() const {
@@ -310,7 +367,9 @@ void WriteFrameBuffer::clearDepthStencil() const {
void WriteFrameBuffer::clearDepthStencil(float d_, GLint s_) const {
bind();
glClearBufferfi(GL_DEPTH_STENCIL, 0, d_, s_);
OPENGL_CALL(
glClearBufferfi(GL_DEPTH_STENCIL, 0, d_, s_)
);
}
FrameBuffer::FrameBuffer()