diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-01-17 00:42:14 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-02-22 22:16:07 +0100 |
commit | 86c309ea75aecb47fc3b984462e07d62d0c70168 (patch) | |
tree | d1dc7033a7764ea9b08386aa035fa412f2396c88 /src | |
parent | 94d8acb7d007150606c0756060c6f0cf90ee7f70 (diff) | |
download | openttd-86c309ea75aecb47fc3b984462e07d62d0c70168.tar.xz |
Codechange: [OpenGL] Let OpenGL clear the pixel buffer if possible.
Diffstat (limited to 'src')
-rw-r--r-- | src/video/opengl.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp index c795dcd60..87ce8b7f3 100644 --- a/src/video/opengl.cpp +++ b/src/video/opengl.cpp @@ -54,6 +54,7 @@ static PFNGLBINDBUFFERPROC _glBindBuffer; static PFNGLBUFFERDATAPROC _glBufferData; static PFNGLMAPBUFFERPROC _glMapBuffer; static PFNGLUNMAPBUFFERPROC _glUnmapBuffer; +static PFNGLCLEARBUFFERSUBDATAPROC _glClearBufferSubData; static PFNGLBUFFERSTORAGEPROC _glBufferStorage; static PFNGLMAPBUFFERRANGEPROC _glMapBufferRange; @@ -209,6 +210,12 @@ static bool BindVBOExtension() _glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)GetOGLProcAddress("glUnmapBufferARB"); } + if (IsOpenGLVersionAtLeast(4, 3) || IsOpenGLExtensionSupported("GL_ARB_clear_buffer_object")) { + _glClearBufferSubData = (PFNGLCLEARBUFFERSUBDATAPROC)GetOGLProcAddress("glClearBufferSubData"); + } else { + _glClearBufferSubData = nullptr; + } + return _glGenBuffers != nullptr && _glDeleteBuffers != nullptr && _glBindBuffer != nullptr && _glBufferData != nullptr && _glMapBuffer != nullptr && _glUnmapBuffer != nullptr; } @@ -776,11 +783,15 @@ bool OpenGLBackend::Resize(int w, int h, bool force) if (bpp == 32) { /* Initialize backing store alpha to opaque for 32bpp modes. */ Colour black(0, 0, 0); - uint32 *buf = (uint32 *)_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); - for (int i = 0; i < pitch * h; i++) { - *buf++ = black.data; + if (_glClearBufferSubData != nullptr) { + _glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_RGBA8, 0, pitch * h * bpp / 8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &black.data); + } else { + uint32 *buf = (uint32 *)_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); + for (int i = 0; i < pitch * h; i++) { + *buf++ = black.data; + } + _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); } - _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); } _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |