OpenGL: Cleaner video output size changing

This commit is contained in:
Vicki Pfau 2017-08-20 23:08:35 -07:00
parent a714774a25
commit 323a6326cd
8 changed files with 19 additions and 19 deletions

View File

@ -200,7 +200,7 @@ static void _GBCoreLoadConfig(struct mCore* core, const struct mCoreConfig* conf
static void _GBCoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) {
struct GB* gb = core->board;
if (!gb || gb->model != GB_MODEL_SGB || !gb->video.sgbBorders) {
if (gb && (gb->model != GB_MODEL_SGB || !gb->video.sgbBorders)) {
*width = GB_VIDEO_HORIZONTAL_PIXELS;
*height = GB_VIDEO_VERTICAL_PIXELS;
} else {

View File

@ -110,12 +110,12 @@ void mGLContextPostFrame(struct VideoBackend* v, const void* frame) {
glBindTexture(GL_TEXTURE_2D, context->tex);
#ifdef COLOR_16_BIT
#ifdef COLOR_5_6_5
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, toPow2(v->width), v->height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, frame);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, v->width, v->height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, frame);
#else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, toPow2(v->width), v->height, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, frame);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, v->width, v->height, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, frame);
#endif
#else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, toPow2(v->width), v->height, GL_RGBA, GL_UNSIGNED_BYTE, frame);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, v->width, v->height, GL_RGBA, GL_UNSIGNED_BYTE, frame);
#endif
}

View File

@ -318,7 +318,6 @@ void mGLES2ContextDrawFrame(struct VideoBackend* v) {
void mGLES2ContextPostFrame(struct VideoBackend* v, const void* frame) {
struct mGLES2Context* context = (struct mGLES2Context*) v;
glBindTexture(GL_TEXTURE_2D, context->tex);
glPixelStorei(GL_UNPACK_ROW_LENGTH, toPow2(v->width));
#ifdef COLOR_16_BIT
#ifdef COLOR_5_6_5
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, v->width, v->height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, frame);

View File

@ -40,8 +40,8 @@ CoreController::CoreController(mCore* core, QObject* parent)
m_threadContext.userData = this;
QSize size(256, 512);
m_buffers[0].resize(toPow2(size.width()) * size.height() * sizeof(color_t));
m_buffers[1].resize(toPow2(size.width()) * size.height() * sizeof(color_t));
m_buffers[0].resize(size.width() * size.height() * sizeof(color_t));
m_buffers[1].resize(size.width() * size.height() * sizeof(color_t));
m_buffers[0].fill(0xFF);
m_buffers[1].fill(0xFF);
m_activeBuffer = &m_buffers[0];
@ -86,13 +86,13 @@ CoreController::CoreController(mCore* core, QObject* parent)
controller->m_resetActions.clear();
QSize size = controller->screenDimensions();
controller->m_buffers[0].resize(toPow2(size.width()) * size.height() * sizeof(color_t));
controller->m_buffers[1].resize(toPow2(size.width()) * size.height() * sizeof(color_t));
controller->m_buffers[0].resize(size.width() * size.height() * sizeof(color_t));
controller->m_buffers[1].resize(size.width() * size.height() * sizeof(color_t));
controller->m_buffers[0].fill(0xFF);
controller->m_buffers[1].fill(0xFF);
controller->m_activeBuffer = &controller->m_buffers[0];
context->core->setVideoBuffer(context->core, reinterpret_cast<color_t*>(controller->m_activeBuffer->data()), toPow2(size.width()));
context->core->setVideoBuffer(context->core, reinterpret_cast<color_t*>(controller->m_activeBuffer->data()), size.width());
controller->finishFrame();
};
@ -736,7 +736,7 @@ void CoreController::finishFrame() {
if (m_activeBuffer == m_completeBuffer) {
m_activeBuffer = &m_buffers[1];
}
m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), toPow2(screenDimensions().width()));
m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), screenDimensions().width());
for (auto& action : m_frameActions) {
action();

View File

@ -391,7 +391,7 @@ void PainterGL::enqueue(const uint32_t* backing) {
buffer = m_free.takeLast();
}
QSize size = m_context->screenDimensions();
memcpy(buffer, backing, toPow2(size.width()) * size.height() * BYTES_PER_PIXEL);
memcpy(buffer, backing, size.width() * size.height() * BYTES_PER_PIXEL);
m_queue.enqueue(buffer);
m_mutex.unlock();
}

View File

@ -57,12 +57,12 @@ void DisplayQt::framePosted() {
}
#ifdef COLOR_16_BIT
#ifdef COLOR_5_6_5
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), toPow2(m_width), m_height, QImage::Format_RGB16);
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), m_width, m_height, QImage::Format_RGB16);
#else
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), toPow2(m_width), m_height, QImage::Format_RGB555);
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), m_width, m_height, QImage::Format_RGB555);
#endif
#else
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), toPow2(m_width), m_height, QImage::Format_ARGB32);
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), m_width, m_height, QImage::Format_ARGB32);
m_backing = m_backing.convertToFormat(QImage::Format_RGB32);
#endif
}

View File

@ -33,10 +33,10 @@ void mSDLGLCreate(struct mSDLRenderer* renderer) {
bool mSDLGLInit(struct mSDLRenderer* renderer) {
mSDLGLCommonInit(renderer);
size_t size = toPow2(renderer->width) * toPow2(renderer->height) * BYTES_PER_PIXEL;
size_t size = renderer->width * renderer->height * BYTES_PER_PIXEL;
renderer->outputBuffer = malloc(size);
memset(renderer->outputBuffer, 0, size);
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, toPow2(renderer->width));
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, renderer->width);
mGLContextCreate(&renderer->gl);
renderer->gl.d.user = renderer;
@ -69,6 +69,7 @@ void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user) {
#endif
}
if (renderer->width != v->width || renderer->height != v->height) {
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, renderer->width);
v->setDimensions(v, renderer->width, renderer->height);
}

View File

@ -98,14 +98,14 @@ bool mSDLGLES2Init(struct mSDLRenderer* renderer) {
mSDLGLCommonInit(renderer);
#endif
size_t size = toPow2(renderer->width) * toPow2(renderer->height) * BYTES_PER_PIXEL;
size_t size = renderer->width * renderer->height * BYTES_PER_PIXEL;
#ifndef __APPLE__
renderer->outputBuffer = memalign(16, size);
#else
posix_memalign((void**) &renderer->outputBuffer, 16, size);
#endif
memset(renderer->outputBuffer, 0, size);
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, toPow2(renderer->width));
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, renderer->width);
mGLES2ContextCreate(&renderer->gl2);
renderer->gl2.d.user = renderer;