Skip to content

Instantly share code, notes, and snippets.

@michicc
Created March 19, 2021 23:00
Show Gist options
  • Save michicc/966e5e7ff64dae5851953b54ee7fd3c6 to your computer and use it in GitHub Desktop.
Save michicc/966e5e7ff64dae5851953b54ee7fd3c6 to your computer and use it in GitHub Desktop.
Clean anim buffer
From 373b1b9c470e25cab99622947c7d999002a411bf Mon Sep 17 00:00:00 2001
From: Michael Lutz <michi@icosahedron.de>
Date: Fri, 19 Mar 2021 23:55:54 +0100
Subject: Fix: [OpenGL] Clear animation buffer upon creation.
---
src/video/opengl.cpp | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp
index 26f6f4b4d..266434f83 100644
--- a/src/video/opengl.cpp
+++ b/src/video/opengl.cpp
@@ -944,8 +944,19 @@ bool OpenGLBackend::Resize(int w, int h, bool force)
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo);
_glBufferData(GL_PIXEL_UNPACK_BUFFER, pitch * h, nullptr, GL_DYNAMIC_DRAW);
}
- _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+ if (_glClearBufferSubData != nullptr) {
+ byte b = 0;
+ _glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_R8, 0, pitch * h, GL_RED, GL_UNSIGNED_BYTE, &b);
+ } else {
+ byte *buf = (byte *)_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
+ for (int i = 0; i < pitch * h; i++) {
+ *buf++ = 0;
+ }
+ _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
+ }
+
+ _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
_glBindTexture(GL_TEXTURE_2D, this->anim_texture);
_glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, nullptr);
} else {
--
2.21.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment