summaryrefslogtreecommitdiff
path: root/src/video/opengl.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-02-21 00:35:35 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-22 22:16:07 +0100
commit5ad545dcc16a27cdabd8636f4970ee12b9cec54b (patch)
tree561181a7db959808c8f6cb04d49ab9032a175453 /src/video/opengl.cpp
parent3a77ade6b25d34890f51931e874fbe0e3b48a744 (diff)
downloadopenttd-5ad545dcc16a27cdabd8636f4970ee12b9cec54b.tar.xz
Codechange: [OpenGL] Only update the dirty parts of the video buffer texture.
Diffstat (limited to 'src/video/opengl.cpp')
-rw-r--r--src/video/opengl.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp
index dbb5ee01a..7fc9c33b0 100644
--- a/src/video/opengl.cpp
+++ b/src/video/opengl.cpp
@@ -24,6 +24,7 @@
#include "opengl.h"
#include "../core/mem_func.hpp"
+#include "../core/geometry_func.hpp"
#include "../gfx_func.h"
#include "../debug.h"
@@ -292,8 +293,9 @@ bool OpenGLBackend::Resize(int w, int h, bool force)
/**
* Render video buffer to the screen.
+ * @param update_rect Rectangle encompassing the dirty region of the video buffer.
*/
-void OpenGLBackend::Paint()
+void OpenGLBackend::Paint(Rect update_rect)
{
assert(this->vid_buffer != nullptr);
@@ -301,8 +303,10 @@ void OpenGLBackend::Paint()
/* Update changed rect of the video buffer texture. */
glBindTexture(GL_TEXTURE_2D, this->vid_texture);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, _screen.pitch);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _screen.width, _screen.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, this->vid_buffer);
+ if (!IsEmptyRect(update_rect)) {
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, _screen.pitch);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, update_rect.left, update_rect.top, update_rect.right - update_rect.left, update_rect.bottom - update_rect.top, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (uint32 *)this->vid_buffer + update_rect.top * _screen.pitch + update_rect.left);
+ }
/* Blit video buffer to screen. */
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);