mirror of https://github.com/mgba-emu/mgba.git
SDL: More video refactoring, fix scaling and aspect ratio locking
This commit is contained in:
parent
b325376f05
commit
3863513b2a
|
@ -34,7 +34,6 @@ static bool _GBCoreInit(struct mCore* core) {
|
|||
LR35902Init(cpu);
|
||||
|
||||
GBVideoSoftwareRendererCreate(&gbcore->renderer);
|
||||
GBVideoAssociateRenderer(&gb->video, &gbcore->renderer.d);
|
||||
|
||||
gb->keySource = &gbcore->keys;
|
||||
|
||||
|
@ -110,6 +109,9 @@ static void _GBCoreUnloadROM(struct mCore* core) {
|
|||
}
|
||||
|
||||
static void _GBCoreReset(struct mCore* core) {
|
||||
struct GBCore* gbcore = (struct GBCore*) core;
|
||||
struct GB* gb = (struct GB*) core->board;
|
||||
GBVideoAssociateRenderer(&gb->video, &gbcore->renderer.d);
|
||||
LR35902Reset(core->cpu);
|
||||
}
|
||||
|
||||
|
@ -184,6 +186,7 @@ static void _GBCoreSetRTC(struct mCore* core, struct mRTCSource* rtc) {
|
|||
struct mCore* GBCoreCreate(void) {
|
||||
struct GBCore* gbcore = malloc(sizeof(*gbcore));
|
||||
struct mCore* core = &gbcore->d;
|
||||
memset(&core->opts, 0, sizeof(core->opts));
|
||||
core->cpu = 0;
|
||||
core->board = 0;
|
||||
core->init = _GBCoreInit;
|
||||
|
|
|
@ -34,15 +34,12 @@ static bool _GBACoreInit(struct mCore* core) {
|
|||
core->cpu = cpu;
|
||||
core->board = gba;
|
||||
|
||||
memset(&core->opts, 0, sizeof(core->opts));
|
||||
|
||||
GBACreate(gba);
|
||||
// TODO: Restore debugger and cheats
|
||||
ARMSetComponents(cpu, &gba->d, 0, 0);
|
||||
ARMInit(cpu);
|
||||
|
||||
GBAVideoSoftwareRendererCreate(&gbacore->renderer);
|
||||
GBAVideoAssociateRenderer(&gba->video, &gbacore->renderer.d);
|
||||
|
||||
gba->keySource = &gbacore->keys;
|
||||
|
||||
|
@ -140,7 +137,9 @@ static void _GBACoreUnloadROM(struct mCore* core) {
|
|||
}
|
||||
|
||||
static void _GBACoreReset(struct mCore* core) {
|
||||
struct GBACore* gbacore = (struct GBACore*) core;
|
||||
struct GBA* gba = (struct GBA*) core->board;
|
||||
GBAVideoAssociateRenderer(&gba->video, &gbacore->renderer.d);
|
||||
ARMReset(core->cpu);
|
||||
if (core->opts.skipBios) {
|
||||
GBASkipBIOS(core->board);
|
||||
|
@ -220,6 +219,7 @@ static void _GBACoreSetRTC(struct mCore* core, struct mRTCSource* rtc) {
|
|||
struct mCore* GBACoreCreate(void) {
|
||||
struct GBACore* gbacore = malloc(sizeof(*gbacore));
|
||||
struct mCore* core = &gbacore->d;
|
||||
memset(&core->opts, 0, sizeof(core->opts));
|
||||
core->cpu = 0;
|
||||
core->board = 0;
|
||||
core->init = _GBACoreInit;
|
||||
|
|
|
@ -54,10 +54,10 @@ static void GBAGLContextResized(struct VideoBackend* v, unsigned w, unsigned h)
|
|||
unsigned drawW = w;
|
||||
unsigned drawH = h;
|
||||
if (v->lockAspectRatio) {
|
||||
if (w * 2 > h * 3) {
|
||||
drawW = h * 3 / 2;
|
||||
} else if (w * 2 < h * 3) {
|
||||
drawH = w * 2 / 3;
|
||||
if (w * v->height > h * v->width) {
|
||||
drawW = h * v->width / v->height;
|
||||
} else if (w * v->height < h * v->width) {
|
||||
drawH = w * v->height / v->width;
|
||||
}
|
||||
}
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
|
|
@ -20,72 +20,33 @@ static void _doViewport(int w, int h, struct VideoBackend* v) {
|
|||
v->clear(v);
|
||||
}
|
||||
|
||||
#ifdef M_CORE_GBA
|
||||
#include "gba/gba.h"
|
||||
|
||||
static bool mSDLGLInitGBA(struct mSDLRenderer* renderer);
|
||||
#endif
|
||||
#ifdef M_CORE_GB
|
||||
#include "gb/gb.h"
|
||||
|
||||
static bool mSDLGLInitGB(struct mSDLRenderer* renderer);
|
||||
#endif
|
||||
|
||||
static bool mSDLGLInit(struct mSDLRenderer* renderer);
|
||||
static void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user);
|
||||
static void mSDLGLDeinit(struct mSDLRenderer* renderer);
|
||||
|
||||
#ifdef M_CORE_GBA
|
||||
void mSDLGLCreateGBA(struct mSDLRenderer* renderer) {
|
||||
renderer->init = mSDLGLInitGBA;
|
||||
void mSDLGLCreate(struct mSDLRenderer* renderer) {
|
||||
renderer->init = mSDLGLInit;
|
||||
renderer->deinit = mSDLGLDeinit;
|
||||
renderer->runloop = mSDLGLRunloop;
|
||||
}
|
||||
|
||||
bool mSDLGLInitGBA(struct mSDLRenderer* renderer) {
|
||||
bool mSDLGLInit(struct mSDLRenderer* renderer) {
|
||||
mSDLGLCommonInit(renderer);
|
||||
|
||||
renderer->outputBuffer = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL);
|
||||
memset(renderer->outputBuffer, 0, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL);
|
||||
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, VIDEO_HORIZONTAL_PIXELS);
|
||||
renderer->outputBuffer = malloc(renderer->width * renderer->height * BYTES_PER_PIXEL);
|
||||
memset(renderer->outputBuffer, 0, renderer->width * renderer->height * BYTES_PER_PIXEL);
|
||||
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, renderer->width);
|
||||
|
||||
GBAGLContextCreate(&renderer->gl);
|
||||
renderer->gl.d.user = renderer;
|
||||
renderer->gl.d.lockAspectRatio = renderer->lockAspectRatio;
|
||||
renderer->gl.d.filter = renderer->filter;
|
||||
renderer->gl.d.swap = mSDLGLCommonSwap;
|
||||
renderer->gl.d.init(&renderer->gl.d, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, 0);
|
||||
renderer->gl.d.init(&renderer->gl.d, renderer->width, renderer->height, 0);
|
||||
|
||||
_doViewport(renderer->viewportWidth, renderer->viewportHeight, &renderer->gl.d);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef M_CORE_GB
|
||||
void mSDLGLCreateGB(struct mSDLRenderer* renderer) {
|
||||
renderer->init = mSDLGLInitGB;
|
||||
renderer->deinit = mSDLGLDeinit;
|
||||
renderer->runloop = mSDLGLRunloop;
|
||||
}
|
||||
|
||||
bool mSDLGLInitGB(struct mSDLRenderer* renderer) {
|
||||
mSDLGLCommonInit(renderer);
|
||||
|
||||
// TODO: Pass texture size along
|
||||
renderer->outputBuffer = malloc(GB_VIDEO_HORIZONTAL_PIXELS * GB_VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL);
|
||||
memset(renderer->outputBuffer, 0, GB_VIDEO_HORIZONTAL_PIXELS * GB_VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL);
|
||||
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, GB_VIDEO_HORIZONTAL_PIXELS);
|
||||
|
||||
GBAGLContextCreate(&renderer->gl);
|
||||
renderer->gl.d.user = renderer;
|
||||
renderer->gl.d.lockAspectRatio = renderer->lockAspectRatio;
|
||||
renderer->gl.d.filter = renderer->filter;
|
||||
renderer->gl.d.swap = mSDLGLCommonSwap;
|
||||
renderer->gl.d.init(&renderer->gl.d, GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS, 0);
|
||||
|
||||
_doViewport(renderer->viewportWidth, renderer->viewportHeight, &renderer->gl.d);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user) {
|
||||
struct mCoreThread* context = user;
|
||||
|
|
|
@ -57,8 +57,6 @@ int main(int argc, char** argv) {
|
|||
struct mSDLRenderer renderer = {};
|
||||
|
||||
struct mCoreOptions opts = {
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
.useBios = true,
|
||||
.rewindEnable = true,
|
||||
.audioBuffers = 512,
|
||||
|
@ -75,12 +73,12 @@ int main(int argc, char** argv) {
|
|||
bool parsed = parseArguments(&args, argc, argv, &subparser);
|
||||
if (!parsed || args.showHelp) {
|
||||
usage(argv[0], subparser.usage);
|
||||
mCoreConfigFreeOpts(&opts);
|
||||
freeArguments(&args);
|
||||
return !parsed;
|
||||
}
|
||||
if (args.showVersion) {
|
||||
version(argv[0]);
|
||||
mCoreConfigFreeOpts(&opts);
|
||||
freeArguments(&args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -91,21 +89,16 @@ int main(int argc, char** argv) {
|
|||
if (!vf) {
|
||||
printf("Could not open game. Are you sure the file exists?\n");
|
||||
freeArguments(&args);
|
||||
mCoreConfigFreeOpts(&opts);
|
||||
return 1;
|
||||
}
|
||||
#ifdef M_CORE_GBA
|
||||
else if (GBAIsROM(vf)) {
|
||||
platform = PLATFORM_GBA;
|
||||
if (!opts.width) {
|
||||
opts.width = VIDEO_HORIZONTAL_PIXELS;
|
||||
}
|
||||
if (!opts.height) {
|
||||
opts.height = VIDEO_VERTICAL_PIXELS;
|
||||
}
|
||||
renderer.width = VIDEO_HORIZONTAL_PIXELS;
|
||||
renderer.height = VIDEO_VERTICAL_PIXELS;
|
||||
renderer.core = GBACoreCreate();
|
||||
#ifdef BUILD_GL
|
||||
mSDLGLCreateGBA(&renderer);
|
||||
mSDLGLCreate(&renderer);
|
||||
#elif defined(BUILD_GLES2) || defined(USE_EPOXY)
|
||||
mSDLGLES2Create(&renderer);
|
||||
#else
|
||||
|
@ -116,15 +109,11 @@ int main(int argc, char** argv) {
|
|||
#ifdef M_CORE_GB
|
||||
else if (GBIsROM(vf)) {
|
||||
platform = PLATFORM_GB;
|
||||
if (!opts.width) {
|
||||
opts.width = GB_VIDEO_HORIZONTAL_PIXELS;
|
||||
}
|
||||
if (!opts.height) {
|
||||
opts.height = GB_VIDEO_VERTICAL_PIXELS;
|
||||
}
|
||||
renderer.width = GB_VIDEO_HORIZONTAL_PIXELS;
|
||||
renderer.height = GB_VIDEO_VERTICAL_PIXELS;
|
||||
renderer.core = GBCoreCreate();
|
||||
#ifdef BUILD_GL
|
||||
mSDLGLCreateGB(&renderer);
|
||||
mSDLGLCreate(&renderer);
|
||||
#elif defined(BUILD_GLES2) || defined(USE_EPOXY)
|
||||
mSDLGLES2CreateGB(&renderer);
|
||||
#else
|
||||
|
@ -135,48 +124,47 @@ int main(int argc, char** argv) {
|
|||
else {
|
||||
printf("Could not run game. Are you sure the file exists and is a compatible game?\n");
|
||||
freeArguments(&args);
|
||||
mCoreConfigFreeOpts(&opts);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
renderer.ratio = graphicsOpts.multiplier;
|
||||
if (renderer.ratio == 0) {
|
||||
renderer.ratio = 1;
|
||||
}
|
||||
opts.width = renderer.width * renderer.ratio;
|
||||
opts.height = renderer.height * renderer.ratio;
|
||||
|
||||
if (!renderer.core->init(renderer.core)) {
|
||||
freeArguments(&args);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mInputMapInit(&renderer.core->inputMap, &GBAInputInfo);
|
||||
mCoreInitConfig(renderer.core, PORT);
|
||||
applyArguments(&args, &subparser, &renderer.core->config);
|
||||
|
||||
mCoreConfigLoadDefaults(&renderer.core->config, &opts);
|
||||
mCoreLoadConfig(renderer.core);
|
||||
|
||||
// TODO: Load from config
|
||||
renderer.viewportWidth = opts.width;
|
||||
renderer.viewportHeight = opts.height;
|
||||
renderer.viewportWidth = renderer.core->opts.width;
|
||||
renderer.viewportHeight = renderer.core->opts.height;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
renderer.player.fullscreen = opts.fullscreen;
|
||||
renderer.player.fullscreen = renderer.core->opts.fullscreen;
|
||||
renderer.player.windowUpdated = 0;
|
||||
#else
|
||||
renderer.fullscreen = opts.fullscreen;
|
||||
renderer.fullscreen = renderer.core->opts.fullscreen;
|
||||
#endif
|
||||
|
||||
renderer.ratio = graphicsOpts.multiplier;
|
||||
if (renderer.ratio == 0) {
|
||||
renderer.ratio = 1;
|
||||
}
|
||||
|
||||
renderer.lockAspectRatio = opts.lockAspectRatio;
|
||||
renderer.filter = opts.resampleVideo;
|
||||
renderer.lockAspectRatio = renderer.core->opts.lockAspectRatio;
|
||||
renderer.filter = renderer.core->opts.resampleVideo;
|
||||
|
||||
if (!mSDLInit(&renderer)) {
|
||||
freeArguments(&args);
|
||||
mCoreConfigFreeOpts(&opts);
|
||||
mCoreConfigDeinit(&renderer.core->config);
|
||||
renderer.core->deinit(renderer.core);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (renderer.core) {
|
||||
// TODO: Check return code
|
||||
renderer.core->init(renderer.core);
|
||||
}
|
||||
mCoreLoadConfig(renderer.core);
|
||||
|
||||
renderer.player.bindings = &renderer.core->inputMap;
|
||||
mSDLInitBindingsGBA(&renderer.core->inputMap);
|
||||
mSDLInitEvents(&renderer.events);
|
||||
|
|
|
@ -62,6 +62,8 @@ struct mSDLRenderer {
|
|||
bool fullscreen;
|
||||
#endif
|
||||
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
int viewportWidth;
|
||||
int viewportHeight;
|
||||
int ratio;
|
||||
|
@ -98,8 +100,7 @@ struct mSDLRenderer {
|
|||
void mSDLSWCreate(struct mSDLRenderer* renderer);
|
||||
|
||||
#ifdef BUILD_GL
|
||||
void mSDLGLCreateGBA(struct mSDLRenderer* renderer);
|
||||
void mSDLGLCreateGB(struct mSDLRenderer* renderer);
|
||||
void mSDLGLCreate(struct mSDLRenderer* renderer);
|
||||
#endif
|
||||
|
||||
#if defined(BUILD_GLES2) || defined(USE_EPOXY)
|
||||
|
|
Loading…
Reference in New Issue