libretro: use RGB565 if available

This commit is contained in:
OV2 2012-10-22 21:30:03 +02:00
parent b43623fa7a
commit d7e3fa64a2
2 changed files with 59 additions and 5 deletions

View File

@ -84,6 +84,17 @@ void retro_get_system_info(struct retro_system_info *info)
void retro_get_system_av_info(struct retro_system_av_info *info) void retro_get_system_av_info(struct retro_system_av_info *info)
{ {
int pixel_format = RGB555;
if(environ_cb) {
pixel_format = RGB565;
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
pixel_format = RGB555;
}
S9xGraphicsDeinit();
S9xSetRenderPixelFormat(pixel_format);
S9xGraphicsInit();
memset(info,0,sizeof(retro_system_av_info)); memset(info,0,sizeof(retro_system_av_info));
info->geometry.base_width = SNES_WIDTH; info->geometry.base_width = SNES_WIDTH;
@ -275,7 +286,6 @@ void retro_init()
S9xSetSoundMute(FALSE); S9xSetSoundMute(FALSE);
S9xSetSamplesAvailableCallback(S9xAudioCallback, NULL); S9xSetSamplesAvailableCallback(S9xAudioCallback, NULL);
S9xSetRenderPixelFormat(RGB555);
GFX.Pitch = MAX_SNES_WIDTH * sizeof(uint16); GFX.Pitch = MAX_SNES_WIDTH * sizeof(uint16);
GFX.Screen = (uint16*) calloc(1, GFX.Pitch * MAX_SNES_HEIGHT); GFX.Screen = (uint16*) calloc(1, GFX.Pitch * MAX_SNES_HEIGHT);
S9xGraphicsInit(); S9xGraphicsInit();

View File

@ -3,6 +3,7 @@
#include "snes9x.h" #include "snes9x.h"
#include <stddef.h> #include <stddef.h>
#include <limits.h>
// Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. // Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant.
#ifdef __cplusplus #ifdef __cplusplus
@ -298,7 +299,7 @@ enum retro_key
// Boolean value whether or not the implementation should use overscan, or crop away overscan. // Boolean value whether or not the implementation should use overscan, or crop away overscan.
// //
#define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 // bool * -- #define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 // bool * --
// Boolean value whether or not RetroArch supports frame duping, // Boolean value whether or not frontend supports frame duping,
// passing NULL to video frame callback. // passing NULL to video frame callback.
// //
#define RETRO_ENVIRONMENT_GET_VARIABLE 4 // struct retro_variable * -- #define RETRO_ENVIRONMENT_GET_VARIABLE 4 // struct retro_variable * --
@ -354,14 +355,36 @@ enum retro_key
#define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10 #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
// const enum retro_pixel_format * -- // const enum retro_pixel_format * --
// Sets the internal pixel format used by the implementation. // Sets the internal pixel format used by the implementation.
// The default pixel format is RETRO_PIXEL_FORMAT_XRGB1555. // The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555.
// This pixel format however, is deprecated (see enum retro_pixel_format).
// If the call returns false, the frontend does not support this pixel format. // If the call returns false, the frontend does not support this pixel format.
// This function should be called inside retro_load_game() or retro_get_system_av_info(). // This function should be called inside retro_load_game() or retro_get_system_av_info().
//
#define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11
// const struct retro_input_descriptor * --
// Sets an array of retro_input_descriptors.
// It is up to the frontend to present this in a usable way.
// The array is terminated by retro_input_descriptor::description being set to NULL.
// This function can be called at any time, but it is recommended to call it as early as possible.
enum retro_pixel_format enum retro_pixel_format
{ {
RETRO_PIXEL_FORMAT_0RGB1555 = 0, // 0RGB1555, native endian. 0 bit must be set to 0. // 0RGB1555, native endian. 0 bit must be set to 0.
RETRO_PIXEL_FORMAT_XRGB8888 // XRGB8888, native endian. X bits are ignored. // This pixel format is default for compatibility concerns only.
// If a 15/16-bit pixel format is desired, consider using RGB565.
RETRO_PIXEL_FORMAT_0RGB1555 = 0,
// XRGB8888, native endian. X bits are ignored.
RETRO_PIXEL_FORMAT_XRGB8888 = 1,
// RGB565, native endian. This pixel format is the recommended format to use if a 15/16-bit format is desired
// as it is the pixel format that is typically available on a wide range of low-power devices.
// It is also natively supported in APIs like OpenGL ES.
RETRO_PIXEL_FORMAT_RGB565 = 2,
// Ensure sizeof() == sizeof(int).
RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX
}; };
struct retro_message struct retro_message
@ -370,8 +393,25 @@ struct retro_message
unsigned frames; // Duration in frames of message. unsigned frames; // Duration in frames of message.
}; };
// Describes how the libretro implementation maps a libretro input bind
// to its internal input system through a human readable string.
// This string can be used to better let a user configure input.
struct retro_input_descriptor
{
// Associates given parameters with a description.
unsigned port;
unsigned device;
unsigned index;
unsigned id;
const char *description; // Human readable description for parameters.
// The pointer must remain valid until retro_unload_game() is called.
};
struct retro_system_info struct retro_system_info
{ {
// All pointers are owned by libretro implementation, and pointers must remain valid until retro_deinit() is called.
const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc. const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc.
const char *library_version; // Descriptive version of core. const char *library_version; // Descriptive version of core.
@ -440,6 +480,8 @@ typedef bool (*retro_environment_t)(unsigned cmd, void *data);
// Render a frame. Pixel format is 15-bit 0RGB1555 native endian unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT). // Render a frame. Pixel format is 15-bit 0RGB1555 native endian unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
// Width and height specify dimensions of buffer. // Width and height specify dimensions of buffer.
// Pitch specifices length in bytes between two lines in buffer. // Pitch specifices length in bytes between two lines in buffer.
// For performance reasons, it is highly recommended to have a frame that is packed in memory, i.e. pitch == width * byte_per_pixel.
// Certain graphic APIs, such as OpenGL ES, do not like textures that are not packed in memory.
typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch); typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch);
// Renders a single audio frame. Should only be used if implementation generates a single sample at a time. // Renders a single audio frame. Should only be used if implementation generates a single sample at a time.
@ -479,6 +521,8 @@ void retro_get_system_info(struct retro_system_info *info);
// Gets information about system audio/video timings and geometry. // Gets information about system audio/video timings and geometry.
// Can be called only after retro_load_game() has successfully completed. // Can be called only after retro_load_game() has successfully completed.
// NOTE: The implementation of this function might not initialize every variable if needed.
// E.g. geom.aspect_ratio might not be initialized if core doesn't desire a particular aspect ratio.
void retro_get_system_av_info(struct retro_system_av_info *info); void retro_get_system_av_info(struct retro_system_av_info *info);
// Sets device to be used for player 'port'. // Sets device to be used for player 'port'.