GBA Video: Start GL renderer

This commit is contained in:
Vicki Pfau 2019-05-10 11:14:37 -07:00
parent 82ef919ee2
commit 618ddac387
3 changed files with 120 additions and 15 deletions

View File

@ -17,6 +17,7 @@
#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 @@ 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);

90
src/gba/renderers/gl.c Normal file
View File

@ -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) {
}

View File

@ -287,13 +287,18 @@ void PainterGL::resizeContext() {
return;
}
if (!m_active) {
m_gl->makeCurrent();
#if defined(_WIN32) && defined(USE_EPOXY)
epoxy_handle_external_wglMakeCurrent();
#endif
}
QSize size = m_context->screenDimensions();
m_backend->setDimensions(m_backend, size.width(), size.height());
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();
#if defined(_WIN32) && defined(USE_EPOXY)
epoxy_handle_external_wglMakeCurrent();
#endif
}
if (m_shader.passes) {
mGLES2ShaderDetach(reinterpret_cast<mGLES2Context*>(m_backend));
mGLES2ShaderFree(&m_shader);
@ -476,7 +478,9 @@ void PainterGL::setShaders(struct VDir* dir) {
if (m_started) {
mGLES2ShaderAttach(reinterpret_cast<mGLES2Context*>(m_backend), static_cast<mGLES2Shader*>(m_shader.passes), m_shader.nPasses);
}
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();
#if defined(_WIN32) && defined(USE_EPOXY)
epoxy_handle_external_wglMakeCurrent();
#endif
}
if (m_shader.passes) {
mGLES2ShaderDetach(reinterpret_cast<mGLES2Context*>(m_backend));
mGLES2ShaderFree(&m_shader);
}
if (!m_active) {
m_gl->doneCurrent();
}
#endif
}