diff --git a/src/gba/core.c b/src/gba/core.c index 95d217ac6..358b9882e 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -17,6 +17,7 @@ #ifndef DISABLE_THREADING #include #endif +#include #include #include #include @@ -123,6 +124,7 @@ struct mVideoLogContext; struct GBACore { struct mCore d; struct GBAVideoSoftwareRenderer renderer; + struct GBAVideoGLRenderer glRenderer; struct GBAVideoProxyRenderer proxyRenderer; struct mVideoLogContext* logContext; struct mCoreCallbacks logCallbacks; @@ -166,6 +168,7 @@ static bool _GBACoreInit(struct mCore* core) { gba->rtcSource = &core->rtc.d; GBAVideoSoftwareRendererCreate(&gbacore->renderer); + GBAVideoGLRendererCreate(&gbacore->glRenderer); gbacore->renderer.outputBuffer = NULL; #ifndef DISABLE_THREADING @@ -251,6 +254,7 @@ static void _GBACoreLoadConfig(struct mCore* core, const struct mCoreConfig* con #ifndef DISABLE_THREADING mCoreConfigCopyValue(&core->config, config, "threadedVideo"); #endif + mCoreConfigCopyValue(&core->config, config, "hwaccelVideo"); } static void _GBACoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) { @@ -390,14 +394,17 @@ static void _GBACoreReset(struct mCore* core) { struct GBA* gba = (struct GBA*) core->board; if (gbacore->renderer.outputBuffer) { struct GBAVideoRenderer* renderer = &gbacore->renderer.d; -#ifndef DISABLE_THREADING int fakeBool; +#ifndef DISABLE_THREADING if (mCoreConfigGetIntValue(&core->config, "threadedVideo", &fakeBool) && fakeBool) { if (!core->videoLogger) { core->videoLogger = &gbacore->threadProxy.d; } } #endif + if (mCoreConfigGetIntValue(&core->config, "hwaccelVideo", &fakeBool) && fakeBool) { + renderer = &gbacore->glRenderer.d; + } if (core->videoLogger) { gbacore->proxyRenderer.logger = core->videoLogger; GBAVideoProxyRendererCreate(&gbacore->proxyRenderer, renderer); diff --git a/src/gba/renderers/gl.c b/src/gba/renderers/gl.c new file mode 100644 index 000000000..54fb85a1f --- /dev/null +++ b/src/gba/renderers/gl.c @@ -0,0 +1,90 @@ +/* Copyright (c) 2013-2019 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +#include +#include +#include +#include + +static void GBAVideoGLRendererInit(struct GBAVideoRenderer* renderer); +static void GBAVideoGLRendererDeinit(struct GBAVideoRenderer* renderer); +static void GBAVideoGLRendererReset(struct GBAVideoRenderer* renderer); +static void GBAVideoGLRendererWriteVRAM(struct GBAVideoRenderer* renderer, uint32_t address); +static void GBAVideoGLRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam); +static void GBAVideoGLRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value); +static uint16_t GBAVideoGLRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value); +static void GBAVideoGLRendererDrawScanline(struct GBAVideoRenderer* renderer, int y); +static void GBAVideoGLRendererFinishFrame(struct GBAVideoRenderer* renderer); +static void GBAVideoGLRendererGetPixels(struct GBAVideoRenderer* renderer, size_t* stride, const void** pixels); +static void GBAVideoGLRendererPutPixels(struct GBAVideoRenderer* renderer, size_t stride, const void* pixels); + +void GBAVideoGLRendererCreate(struct GBAVideoGLRenderer* renderer) { + renderer->d.init = GBAVideoGLRendererInit; + renderer->d.reset = GBAVideoGLRendererReset; + renderer->d.deinit = GBAVideoGLRendererDeinit; + renderer->d.writeVideoRegister = GBAVideoGLRendererWriteVideoRegister; + renderer->d.writeVRAM = GBAVideoGLRendererWriteVRAM; + renderer->d.writeOAM = GBAVideoGLRendererWriteOAM; + renderer->d.writePalette = GBAVideoGLRendererWritePalette; + renderer->d.drawScanline = GBAVideoGLRendererDrawScanline; + renderer->d.finishFrame = GBAVideoGLRendererFinishFrame; + renderer->d.getPixels = GBAVideoGLRendererGetPixels; + renderer->d.putPixels = GBAVideoGLRendererPutPixels; + + renderer->d.disableBG[0] = false; + renderer->d.disableBG[1] = false; + renderer->d.disableBG[2] = false; + renderer->d.disableBG[3] = false; + renderer->d.disableOBJ = false; + + renderer->temporaryBuffer = 0; +} + +void GBAVideoGLRendererInit(struct GBAVideoRenderer* renderer) { + +} + +void GBAVideoGLRendererDeinit(struct GBAVideoRenderer* renderer) { + +} + +void GBAVideoGLRendererReset(struct GBAVideoRenderer* renderer) { + +} + +void GBAVideoGLRendererWriteVRAM(struct GBAVideoRenderer* renderer, uint32_t address) { + +} + +void GBAVideoGLRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam) { + +} + +void GBAVideoGLRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) { + +} + +uint16_t GBAVideoGLRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) { + +} + +void GBAVideoGLRendererDrawScanline(struct GBAVideoRenderer* renderer, int y) { + +} + +void GBAVideoGLRendererFinishFrame(struct GBAVideoRenderer* renderer) { + +} + +void GBAVideoGLRendererGetPixels(struct GBAVideoRenderer* renderer, size_t* stride, const void** pixels) { + +} + +void GBAVideoGLRendererPutPixels(struct GBAVideoRenderer* renderer, size_t stride, const void* pixels) { + +} + diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index c7374f274..722359255 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -287,13 +287,18 @@ void PainterGL::resizeContext() { return; } - m_gl->makeCurrent(); + if (!m_active) { + m_gl->makeCurrent(); #if defined(_WIN32) && defined(USE_EPOXY) - epoxy_handle_external_wglMakeCurrent(); + epoxy_handle_external_wglMakeCurrent(); #endif + } + QSize size = m_context->screenDimensions(); m_backend->setDimensions(m_backend, size.width(), size.height()); - m_gl->doneCurrent(); + if (!m_active) { + m_gl->doneCurrent(); + } } void PainterGL::setMessagePainter(MessagePainter* messagePainter) { @@ -340,7 +345,6 @@ void PainterGL::start() { } #endif - m_gl->doneCurrent(); m_active = true; m_started = true; } @@ -383,10 +387,6 @@ void PainterGL::forceDraw() { void PainterGL::stop() { m_active = false; m_started = false; - m_gl->makeCurrent(); -#if defined(_WIN32) && defined(USE_EPOXY) - epoxy_handle_external_wglMakeCurrent(); -#endif dequeueAll(); m_backend->clear(m_backend); m_backend->swap(m_backend); @@ -463,11 +463,13 @@ void PainterGL::setShaders(struct VDir* dir) { if (!supportsShaders()) { return; } + if (!m_active) { #if !defined(_WIN32) || defined(USE_EPOXY) - m_gl->makeCurrent(); + m_gl->makeCurrent(); #if defined(_WIN32) && defined(USE_EPOXY) - epoxy_handle_external_wglMakeCurrent(); + epoxy_handle_external_wglMakeCurrent(); #endif + } if (m_shader.passes) { mGLES2ShaderDetach(reinterpret_cast(m_backend)); mGLES2ShaderFree(&m_shader); @@ -476,7 +478,9 @@ void PainterGL::setShaders(struct VDir* dir) { if (m_started) { mGLES2ShaderAttach(reinterpret_cast(m_backend), static_cast(m_shader.passes), m_shader.nPasses); } - m_gl->doneCurrent(); + if (!m_active) { + m_gl->doneCurrent(); + } #endif } @@ -484,16 +488,20 @@ void PainterGL::clearShaders() { if (!supportsShaders()) { return; } + if (!m_active) { #if !defined(_WIN32) || defined(USE_EPOXY) - m_gl->makeCurrent(); + m_gl->makeCurrent(); #if defined(_WIN32) && defined(USE_EPOXY) - epoxy_handle_external_wglMakeCurrent(); + epoxy_handle_external_wglMakeCurrent(); #endif + } if (m_shader.passes) { mGLES2ShaderDetach(reinterpret_cast(m_backend)); mGLES2ShaderFree(&m_shader); } - m_gl->doneCurrent(); + if (!m_active) { + m_gl->doneCurrent(); + } #endif }