renderer_gl: Implement semi proper clears

This commit is contained in:
GPUCode 2023-07-26 22:34:39 +03:00
parent 50bcf3b617
commit c6c71bb9b2
4 changed files with 71 additions and 40 deletions

View file

@ -333,18 +333,18 @@ namespace OpenGL {
void bind(FramebufferTypes target) const { bind(static_cast<GLenum>(target)); }
void free() { glDeleteFramebuffers(1, &m_handle); }
void createWithTexture(Texture& tex, GLenum mode = GL_FRAMEBUFFER, GLenum textureType = GL_TEXTURE_2D) {
void createWithTexture(Texture& tex, GLenum mode = GL_FRAMEBUFFER, GLenum attachment = GL_COLOR_ATTACHMENT0, GLenum textureType = GL_TEXTURE_2D) {
m_textureType = textureType;
create();
bind(mode);
glFramebufferTexture2D(mode, GL_COLOR_ATTACHMENT0, textureType, tex.handle(), 0);
glFramebufferTexture2D(mode, attachment, textureType, tex.handle(), 0);
}
void createWithReadTexture(Texture& tex, GLenum textureType = GL_TEXTURE_2D) {
createWithTexture(tex, GL_READ_FRAMEBUFFER, textureType);
void createWithReadTexture(Texture& tex, GLenum attachment = GL_COLOR_ATTACHMENT0, GLenum textureType = GL_TEXTURE_2D) {
createWithTexture(tex, GL_READ_FRAMEBUFFER, attachment, textureType);
}
void createWithDrawTexture(Texture& tex, GLenum textureType = GL_TEXTURE_2D) {
createWithTexture(tex, GL_DRAW_FRAMEBUFFER, textureType);
void createWithDrawTexture(Texture& tex, GLenum attachment = GL_COLOR_ATTACHMENT0, GLenum textureType = GL_TEXTURE_2D) {
createWithTexture(tex, GL_DRAW_FRAMEBUFFER, attachment, textureType);
}
void createWithTextureMSAA(Texture& tex, GLenum mode = GL_FRAMEBUFFER) {

View file

@ -86,6 +86,7 @@ struct DepthBuffer {
Interval<u32> range;
// OpenGL texture used for storing depth/stencil
OpenGL::Texture texture;
OpenGL::Framebuffer fbo;
DepthBuffer() : valid(false) {}
@ -127,6 +128,11 @@ struct DepthBuffer {
texture.setMagFilter(OpenGL::Nearest);
glBindTexture(GL_TEXTURE_2D, prevTexture);
fbo.createWithDrawTexture(texture, fmt == GL_DEPTH_STENCIL ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
Helpers::panic("Incomplete framebuffer");
}
void free() {
@ -144,4 +150,4 @@ struct DepthBuffer {
size_t sizeInBytes() {
return (size_t)size.x() * (size_t)size.y() * PICA::sizePerPixel(format);
}
};
};