refactor & fix random deleting texture

This commit is contained in:
MihailRis
2025-05-10 16:13:06 +03:00
parent e158b384fa
commit 8bb03a004f
7 changed files with 65 additions and 64 deletions
+5 -5
View File
@@ -60,17 +60,17 @@ void Batch2D::vertex(
index++;
}
void Batch2D::texture(const Texture* new_texture){
if (currentTexture == new_texture) {
void Batch2D::texture(const Texture* newTexture){
if (currentTexture == newTexture) {
return;
}
flush();
currentTexture = new_texture;
if (new_texture == nullptr) {
currentTexture = newTexture;
if (newTexture == nullptr) {
blank->bind();
region = blank->getUVRegion();
} else {
new_texture->bind();
newTexture->bind();
region = currentTexture->getUVRegion();
}
}
-2
View File
@@ -8,8 +8,6 @@
Batch3D::Batch3D(size_t capacity)
: capacity(capacity) {
buffer = std::make_unique<Batch3DVertex[]>(capacity);
mesh = std::make_unique<Mesh<Batch3DVertex>>(buffer.get(), 0);
index = 0;
+1 -4
View File
@@ -42,9 +42,6 @@ Framebuffer::Framebuffer(uint width, uint height, bool alpha)
// Setup color attachment (texture)
texture = create_texture(width, height, format);
unsigned int attachments[1] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, attachments);
// Setup depth attachment
glGenRenderbuffers(1, &depth);
glBindRenderbuffer(GL_RENDERBUFFER, depth);
@@ -60,7 +57,7 @@ Framebuffer::Framebuffer(uint width, uint height, bool alpha)
Framebuffer::~Framebuffer() {
glDeleteFramebuffers(1, &fbo);
glDeleteTextures(1, &depth);
glDeleteRenderbuffers(1, &depth);
}
void Framebuffer::bind() {
+6 -5
View File
@@ -135,20 +135,21 @@ void PostProcessing::render(
const auto& vp = context.getViewport();
refreshFbos(vp.x, vp.y);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, shadowMap);
if (gbuffer) {
gbuffer->bindBuffers();
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, noiseTexture);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, shadowMap);
glActiveTexture(GL_TEXTURE0);
} else {
glActiveTexture(GL_TEXTURE0);
fbo->getTexture()->bind();
}
glActiveTexture(GL_TEXTURE0);
if (totalPasses == 0) {
auto& effect = assets.require<PostEffect>("default");
auto& shader = effect.use();