(libretro-test-gl) Add internal resolution core option

This commit is contained in:
twinaphex 2013-07-01 11:53:10 +02:00
parent c86d4813db
commit 5fb8594215

View File

@ -23,6 +23,19 @@ static struct retro_hw_render_callback hw_render;
#include <GL/glext.h>
#endif
#define BASE_WIDTH 320
#define BASE_HEIGHT 240
#ifdef GLES
#define MAX_WIDTH 1024
#define MAX_HEIGHT 1024
#else
#define MAX_WIDTH 1920
#define MAX_HEIGHT 1600
#endif
static unsigned width = BASE_WIDTH;
static unsigned height = BASE_HEIGHT;
#if defined(GLES) || defined(__APPLE__)
#define pglCreateProgram glCreateProgram
#define pglCreateShader glCreateShader
@ -197,10 +210,10 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
};
info->geometry = (struct retro_game_geometry) {
.base_width = 512,
.base_height = 512,
.max_width = 512,
.max_height = 512,
.base_width = BASE_WIDTH,
.base_height = BASE_HEIGHT,
.max_width = MAX_WIDTH,
.max_height = MAX_HEIGHT,
.aspect_ratio = 4.0 / 3.0,
};
}
@ -216,8 +229,19 @@ void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;
struct retro_variable variables[] = {
{ "resolution",
#ifdef GLES
"Internal resolution; 320x240|360x480|480x272|512x384|512x512|640x240|640x448|640x480|720x576|800x600|960x720|1024x768" },
#else
"Internal resolution; 320x240|360x480|480x272|512x384|512x512|640x240|640x448|640x480|720x576|800x600|960x720|1024x768|1024x1024|1280x720|1280x960|1600x1200|1920x1080|1920x1440|1920x1600" },
#endif
{ NULL, NULL },
};
bool no_rom = true;
cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &no_rom);
cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables);
}
void retro_set_audio_sample(retro_audio_sample_t cb)
@ -245,13 +269,159 @@ void retro_set_video_refresh(retro_video_refresh_t cb)
video_cb = cb;
}
static void update_variables(void)
{
struct retro_variable var;
var.key = "resolution";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "320x200") == 0)
{
width = 320;
height = 200;
}
else if (strcmp(var.value, "320x240") == 0)
{
width = 320;
height = 240;
}
else if (strcmp(var.value, "320x480") == 0)
{
width = 320;
height = 480;
}
else if (strcmp(var.value, "360x200") == 0)
{
width = 360;
height = 200;
}
else if (strcmp(var.value, "360x240") == 0)
{
width = 360;
height = 240;
}
else if (strcmp(var.value, "360x400") == 0)
{
width = 360;
height = 400;
}
else if (strcmp(var.value, "360x480") == 0)
{
width = 360;
height = 480;
}
else if (strcmp(var.value, "400x224") == 0)
{
width = 400;
height = 224;
}
else if (strcmp(var.value, "480x272") == 0)
{
width = 480;
height = 272;
}
else if (strcmp(var.value, "512x224") == 0)
{
width = 512;
height = 224;
}
else if (strcmp(var.value, "512x384") == 0)
{
width = 512;
height = 384;
}
else if (strcmp(var.value, "640x240") == 0)
{
width = 640;
height = 240;
}
else if (strcmp(var.value, "640x448") == 0)
{
width = 640;
height = 448;
}
else if (strcmp(var.value, "640x480") == 0)
{
width = 640;
height = 480;
}
else if (strcmp(var.value, "720x576") == 0)
{
width = 720;
height = 576;
}
else if (strcmp(var.value, "800x480") == 0)
{
width = 800;
height = 480;
}
else if (strcmp(var.value, "800x600") == 0)
{
width = 800;
height = 600;
}
else if (strcmp(var.value, "960x720") == 0)
{
width = 960;
height = 720;
}
else if (strcmp(var.value, "1024x768") == 0)
{
width = 1024;
height = 768;
}
else if (strcmp(var.value, "1024x1024") == 0)
{
width = 1024;
height = 1024;
}
else if (strcmp(var.value, "1280x720") == 0)
{
width = 1280;
height = 720;
}
else if (strcmp(var.value, "1280x1024") == 0)
{
width = 1280;
height = 1024;
}
else if (strcmp(var.value, "1600x1080") == 0)
{
width = 1600;
height = 1080;
}
else if (strcmp(var.value, "1920x1080") == 0)
{
width = 1920;
height = 1080;
}
else if (strcmp(var.value, "1920x1440") == 0)
{
width = 1920;
height = 1440;
}
else if (strcmp(var.value, "1920x1600") == 0)
{
width = 1920;
height = 1600;
}
}
}
void retro_run(void)
{
bool updated = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
update_variables();
input_poll_cb();
pglBindFramebuffer(GL_FRAMEBUFFER, hw_render.get_current_framebuffer());
glClearColor(0.3, 0.4, 0.5, 1.0);
glViewport(0, 0, 512, 512);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pglUseProgram(prog);
@ -300,7 +470,7 @@ void retro_run(void)
pglUseProgram(0);
video_cb(RETRO_HW_FRAME_BUFFER_VALID, 512, 512, 0);
video_cb(RETRO_HW_FRAME_BUFFER_VALID, width, height, 0);
}
static void context_reset(void)
@ -311,8 +481,11 @@ static void context_reset(void)
setup_vao();
}
bool retro_load_game(const struct retro_game_info *info)
{
update_variables();
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888;
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
{