all repos — mgba @ 618ddac38731b79933b7d39d4c1b50342d011d73

mGBA Game Boy Advance Emulator

GBA Video: Start GL renderer
Vicki Pfau vi@endrift.com
Fri, 10 May 2019 11:14:37 -0700
commit

618ddac38731b79933b7d39d4c1b50342d011d73

parent

82ef919ee27e93f684d260dd147f71f601806b64

3 files changed, 120 insertions(+), 15 deletions(-)

jump to
M src/gba/core.csrc/gba/core.c

@@ -17,6 +17,7 @@ #include <mgba/internal/gba/overrides.h>

#ifndef DISABLE_THREADING #include <mgba/feature/thread-proxy.h> #endif +#include <mgba/internal/gba/renderers/gl.h> #include <mgba/internal/gba/renderers/proxy.h> #include <mgba/internal/gba/renderers/video-software.h> #include <mgba/internal/gba/savedata.h>

@@ -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 @@ mRTCGenericSourceInit(&core->rtc, core);

gba->rtcSource = &core->rtc.d; GBAVideoSoftwareRendererCreate(&gbacore->renderer); + GBAVideoGLRendererCreate(&gbacore->glRenderer); gbacore->renderer.outputBuffer = NULL; #ifndef DISABLE_THREADING

@@ -251,6 +254,7 @@

#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 @@ struct GBACore* gbacore = (struct GBACore*) core;

struct GBA* gba = (struct GBA*) core->board; if (gbacore->renderer.outputBuffer) { struct GBAVideoRenderer* renderer = &gbacore->renderer.d; + int fakeBool; #ifndef DISABLE_THREADING - int fakeBool; 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);
A 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 <mgba/internal/gba/renderers/gl.h> + +#include <mgba/core/cache-set.h> +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/gba/io.h> +#include <mgba/internal/gba/renderers/cache-set.h> + +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) { + +} +
M src/platform/qt/DisplayGL.cppsrc/platform/qt/DisplayGL.cpp

@@ -287,13 +287,18 @@ if (!m_context) {

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 @@ mGLES2ShaderAttach(reinterpret_cast<mGLES2Context*>(m_backend), static_cast<mGLES2Shader*>(m_shader.passes), m_shader.nPasses);

} #endif - m_gl->doneCurrent(); m_active = true; m_started = true; }

@@ -383,10 +387,6 @@

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<mGLES2Context*>(m_backend)); mGLES2ShaderFree(&m_shader);

@@ -476,7 +478,9 @@ mGLES2ShaderLoad(&m_shader, dir);

if (m_started) { mGLES2ShaderAttach(reinterpret_cast<mGLES2Context*>(m_backend), static_cast<mGLES2Shader*>(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<mGLES2Context*>(m_backend)); mGLES2ShaderFree(&m_shader); } - m_gl->doneCurrent(); + if (!m_active) { + m_gl->doneCurrent(); + } #endif }