-
-
Save Milek7/b36475d2635a4f39849bdee52f2d8c20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp | |
index 26f6f4b4d..b2852bbf8 100644 | |
--- a/src/video/opengl.cpp | |
+++ b/src/video/opengl.cpp | |
@@ -1101,8 +1101,8 @@ void *OpenGLBackend::GetVideoBuffer() | |
#endif | |
if (!this->persistent_mapping_supported) { | |
- _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->vid_pbo); | |
- this->vid_buffer = _glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); | |
+ if (this->vid_buffer == nullptr) | |
+ this->vid_buffer = new unsigned char[_screen.pitch * _screen.height * BlitterFactory::GetCurrentBlitter()->GetScreenDepth() / 8]; | |
} else if (this->vid_buffer == nullptr) { | |
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->vid_pbo); | |
this->vid_buffer = _glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, _screen.pitch * _screen.height * BlitterFactory::GetCurrentBlitter()->GetScreenDepth() / 8, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); | |
@@ -1124,8 +1124,8 @@ uint8 *OpenGLBackend::GetAnimBuffer() | |
#endif | |
if (!this->persistent_mapping_supported) { | |
- _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo); | |
- this->anim_buffer = _glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); | |
+ if (this->anim_buffer == nullptr) | |
+ this->anim_buffer = new unsigned char[_screen.pitch * _screen.height]; | |
} else if (this->anim_buffer == nullptr) { | |
_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo); | |
this->anim_buffer = _glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, _screen.pitch * _screen.height, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); | |
@@ -1142,10 +1142,13 @@ void OpenGLBackend::ReleaseVideoBuffer(const Rect &update_rect) | |
{ | |
assert(this->vid_pbo != 0); | |
- _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->vid_pbo); | |
+ unsigned char* mem = 0; | |
+ | |
if (!this->persistent_mapping_supported) { | |
- _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); | |
- this->vid_buffer = nullptr; | |
+ mem = (unsigned char*)this->vid_buffer; | |
+ _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | |
+ } else { | |
+ _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->vid_pbo); | |
} | |
#ifndef NO_GL_BUFFER_SYNC | |
@@ -1162,11 +1165,11 @@ void OpenGLBackend::ReleaseVideoBuffer(const Rect &update_rect) | |
_glPixelStorei(GL_UNPACK_ROW_LENGTH, _screen.pitch); | |
switch (BlitterFactory::GetCurrentBlitter()->GetScreenDepth()) { | |
case 8: | |
- _glTexSubImage2D(GL_TEXTURE_2D, 0, update_rect.left, update_rect.top, update_rect.right - update_rect.left, update_rect.bottom - update_rect.top, GL_RED, GL_UNSIGNED_BYTE, (GLvoid *)(size_t)(update_rect.top * _screen.pitch + update_rect.left)); | |
+ _glTexSubImage2D(GL_TEXTURE_2D, 0, update_rect.left, update_rect.top, update_rect.right - update_rect.left, update_rect.bottom - update_rect.top, GL_RED, GL_UNSIGNED_BYTE, (GLvoid *)(size_t)(mem + update_rect.top * _screen.pitch + update_rect.left)); | |
break; | |
default: | |
- _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, (GLvoid *)(size_t)(update_rect.top * _screen.pitch * 4 + update_rect.left * 4)); | |
+ _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, (GLvoid *)(size_t)(mem + update_rect.top * _screen.pitch * 4 + update_rect.left * 4)); | |
break; | |
} | |
@@ -1184,10 +1187,14 @@ void OpenGLBackend::ReleaseAnimBuffer(const Rect &update_rect) | |
{ | |
if (this->anim_pbo == 0) return; | |
- _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo); | |
+ unsigned char* mem = 0; | |
+ | |
if (!this->persistent_mapping_supported) { | |
- _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); | |
- this->anim_buffer = nullptr; | |
+ mem = (unsigned char*)this->anim_buffer; | |
+ _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | |
+ } | |
+ else { | |
+ _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->anim_pbo); | |
} | |
#ifndef NO_GL_BUFFER_SYNC | |
@@ -1202,7 +1209,7 @@ void OpenGLBackend::ReleaseAnimBuffer(const Rect &update_rect) | |
_glActiveTexture(GL_TEXTURE0); | |
_glBindTexture(GL_TEXTURE_2D, this->anim_texture); | |
_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_RED, GL_UNSIGNED_BYTE, (GLvoid *)(size_t)(update_rect.top * _screen.pitch + update_rect.left)); | |
+ _glTexSubImage2D(GL_TEXTURE_2D, 0, update_rect.left, update_rect.top, update_rect.right - update_rect.left, update_rect.bottom - update_rect.top, GL_RED, GL_UNSIGNED_BYTE, (GLvoid *)(size_t)(mem + update_rect.top * _screen.pitch + update_rect.left)); | |
#ifndef NO_GL_BUFFER_SYNC | |
if (this->persistent_mapping_supported) this->sync_anim_mapping = _glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment