From c62ff005801074e15e505a431a4f97c13d5345ac Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 16 Jan 2016 02:29:03 -0800 Subject: [PATCH] OpenGL: Make all buffers expected to be the right width --- src/platform/opengl/gl.c | 6 +++--- src/platform/opengl/gles2.c | 1 - src/platform/qt/DisplayGL.cpp | 2 +- src/platform/qt/DisplayQt.cpp | 6 +++--- src/platform/qt/GameController.cpp | 8 ++++---- src/platform/sdl/gl-sdl.c | 4 ++-- src/platform/sdl/gles2-sdl.c | 4 ++-- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/platform/opengl/gl.c b/src/platform/opengl/gl.c index 5d31b89ae..7ca41e577 100644 --- a/src/platform/opengl/gl.c +++ b/src/platform/opengl/gl.c @@ -99,12 +99,12 @@ void GBAGLContextPostFrame(struct VideoBackend* v, const void* frame) { glBindTexture(GL_TEXTURE_2D, context->tex); #ifdef COLOR_16_BIT #ifdef COLOR_5_6_5 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, frame); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, frame); #else - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, frame); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, frame); #endif #else - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, frame); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, GL_RGBA, GL_UNSIGNED_BYTE, frame); #endif } diff --git a/src/platform/opengl/gles2.c b/src/platform/opengl/gles2.c index f6ce05130..f79d98134 100644 --- a/src/platform/opengl/gles2.c +++ b/src/platform/opengl/gles2.c @@ -278,7 +278,6 @@ void GBAGLES2ContextDrawFrame(struct VideoBackend* v) { void GBAGLES2ContextPostFrame(struct VideoBackend* v, const void* frame) { struct GBAGLES2Context* context = (struct GBAGLES2Context*) v; glBindTexture(GL_TEXTURE_2D, context->tex); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 256); #ifdef COLOR_16_BIT #ifdef COLOR_5_6_5 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, frame); diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index 249fb8f7f..6121c174b 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -366,7 +366,7 @@ void PainterGL::enqueue(const uint32_t* backing) { } else { buffer = m_free.takeLast(); } - memcpy(buffer, backing, 256 * VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL); + memcpy(buffer, backing, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL); m_queue.enqueue(buffer); m_mutex.unlock(); } diff --git a/src/platform/qt/DisplayQt.cpp b/src/platform/qt/DisplayQt.cpp index 71e684055..39502e855 100644 --- a/src/platform/qt/DisplayQt.cpp +++ b/src/platform/qt/DisplayQt.cpp @@ -41,12 +41,12 @@ void DisplayQt::framePosted(const uint32_t* buffer) { } #ifdef COLOR_16_BIT #ifdef COLOR_5_6_5 - m_backing = QImage(reinterpret_cast(buffer), 256, 256, QImage::Format_RGB16); + m_backing = QImage(reinterpret_cast(buffer), VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, QImage::Format_RGB16); #else - m_backing = QImage(reinterpret_cast(buffer), 256, 256, QImage::Format_RGB555); + m_backing = QImage(reinterpret_cast(buffer), VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, QImage::Format_RGB555); #endif #else - m_backing = QImage(reinterpret_cast(buffer), 256, 256, QImage::Format_RGB32); + m_backing = QImage(reinterpret_cast(buffer), VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, QImage::Format_RGB32); #endif } diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 65ad7528f..7588db1a5 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -32,8 +32,8 @@ using namespace std; GameController::GameController(QObject* parent) : QObject(parent) - , m_drawContext(new uint32_t[256 * VIDEO_HORIZONTAL_PIXELS]) - , m_frontBuffer(new uint32_t[256 * 256]) + , m_drawContext(new uint32_t[VIDEO_VERTICAL_PIXELS * VIDEO_HORIZONTAL_PIXELS]) + , m_frontBuffer(new uint32_t[VIDEO_VERTICAL_PIXELS * VIDEO_HORIZONTAL_PIXELS]) , m_threadContext() , m_activeKeys(0) , m_inactiveKeys(0) @@ -62,7 +62,7 @@ GameController::GameController(QObject* parent) m_renderer = new GBAVideoSoftwareRenderer; GBAVideoSoftwareRendererCreate(m_renderer); m_renderer->outputBuffer = (color_t*) m_drawContext; - m_renderer->outputBufferStride = 256; + m_renderer->outputBufferStride = VIDEO_HORIZONTAL_PIXELS; GBACheatDeviceCreate(&m_cheatDevice); @@ -127,7 +127,7 @@ GameController::GameController(QObject* parent) m_threadContext.frameCallback = [](GBAThread* context) { GameController* controller = static_cast(context->userData); - memcpy(controller->m_frontBuffer, controller->m_drawContext, 256 * VIDEO_HORIZONTAL_PIXELS * BYTES_PER_PIXEL); + memcpy(controller->m_frontBuffer, controller->m_drawContext, VIDEO_VERTICAL_PIXELS * VIDEO_HORIZONTAL_PIXELS * BYTES_PER_PIXEL); QMetaObject::invokeMethod(controller, "frameAvailable", Q_ARG(const uint32_t*, controller->m_frontBuffer)); if (controller->m_pauseAfterFrame.testAndSetAcquire(true, false)) { GBAThreadPauseFromThread(context); diff --git a/src/platform/sdl/gl-sdl.c b/src/platform/sdl/gl-sdl.c index bb927bfce..cd5986f96 100644 --- a/src/platform/sdl/gl-sdl.c +++ b/src/platform/sdl/gl-sdl.c @@ -30,8 +30,8 @@ void GBASDLGLCreate(struct SDLSoftwareRenderer* renderer) { bool GBASDLGLInit(struct SDLSoftwareRenderer* renderer) { GBASDLGLCommonInit(renderer); - renderer->d.outputBuffer = malloc(256 * 256 * BYTES_PER_PIXEL); - renderer->d.outputBufferStride = 256; + renderer->d.outputBuffer = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL); + renderer->d.outputBufferStride = VIDEO_HORIZONTAL_PIXELS; GBAGLContextCreate(&renderer->gl); renderer->gl.d.user = renderer; diff --git a/src/platform/sdl/gles2-sdl.c b/src/platform/sdl/gles2-sdl.c index bbdffffe0..4bcbb0f94 100644 --- a/src/platform/sdl/gles2-sdl.c +++ b/src/platform/sdl/gles2-sdl.c @@ -93,8 +93,8 @@ bool GBASDLGLES2Init(struct SDLSoftwareRenderer* renderer) { GBASDLGLCommonInit(renderer); #endif - renderer->d.outputBuffer = memalign(16, 256 * 256 * 4); - renderer->d.outputBufferStride = 256; + renderer->d.outputBuffer = memalign(16, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); + renderer->d.outputBufferStride = VIDEO_HORIZONTAL_PIXELS; GBAGLES2ContextCreate(&renderer->gl2); renderer->gl2.d.user = renderer;