RetroArch/gfx/ext/rarch_video.h

279 lines
9.0 KiB
C
Raw Normal View History

2011-05-05 20:23:08 +02:00
/////
2012-04-21 23:13:50 +02:00
// API header for external RetroArch video and input plugins.
2011-05-05 20:23:08 +02:00
//
//
2012-04-21 23:25:32 +02:00
#ifndef __RARCH_VIDEO_DRIVER_H
#define __RARCH_VIDEO_DRIVER_H
2011-05-05 20:23:08 +02:00
2011-11-15 15:41:49 +01:00
#include <stddef.h>
2011-05-05 20:23:08 +02:00
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
2012-04-21 23:25:32 +02:00
#ifdef RARCH_DLL_IMPORT
#define RARCH_API_EXPORT __declspec(dllimport)
2011-05-05 20:23:08 +02:00
#else
2012-04-21 23:25:32 +02:00
#define RARCH_API_EXPORT __declspec(dllexport)
2011-05-12 00:33:52 +02:00
#endif
2012-04-21 23:25:32 +02:00
#define RARCH_API_CALLTYPE __cdecl
2011-05-12 00:33:52 +02:00
#else
2012-04-21 23:25:32 +02:00
#define RARCH_API_EXPORT
#define RARCH_API_CALLTYPE
2011-05-05 20:23:08 +02:00
#endif
2012-04-21 23:25:32 +02:00
#define RARCH_GRAPHICS_API_VERSION 2
2011-05-11 18:26:00 +02:00
2011-05-12 01:30:30 +02:00
// Since we don't want to rely on C++ or C99 for a proper boolean type,
2011-11-15 15:41:49 +01:00
// make sure return semantics are perfectly clear ... ;)
2012-04-21 23:25:32 +02:00
#ifndef RARCH_OK
#define RARCH_OK 1
#endif
2012-04-21 23:25:32 +02:00
#ifndef RARCH_ERROR
#define RARCH_ERROR 0
#endif
2012-04-21 23:25:32 +02:00
#ifndef RARCH_TRUE
#define RARCH_TRUE 1
#endif
2012-04-21 23:25:32 +02:00
#ifndef RARCH_FALSE
#define RARCH_FALSE 0
#endif
2011-05-05 20:23:08 +02:00
2012-04-21 23:25:32 +02:00
#define RARCH_COLOR_FORMAT_XRGB1555 0
#define RARCH_COLOR_FORMAT_ARGB8888 1
2011-05-05 20:23:08 +02:00
2012-04-21 23:25:32 +02:00
#define RARCH_INPUT_SCALE_BASE 256
2011-11-13 17:09:49 +01:00
2011-11-15 15:41:49 +01:00
typedef struct py_state py_state_t;
// Create a new runtime for Python.
// py_script: The python script to be loaded. If is_file is true, this will be the full path to a file.
// If false, it will be an UTF-8 encoded string of the script.
// is_file: Tells if py_script is the path to a script, or a script itself.
// py_class: name of the class being instantiated.
typedef py_state_t *(*python_state_new_cb)(const char *py_script, unsigned is_file, const char *py_class);
// Grabs a value from the Python runtime.
// id: The uniform (class method) to be called.
// frame_count: Passes frame_count as an argument to the script.
typedef float (*python_state_get_cb)(py_state_t *handle, const char *id, unsigned frame_count);
// Frees the runtime.
typedef void (*python_state_free_cb)(py_state_t *handle);
2012-04-21 23:25:32 +02:00
typedef struct rarch_video_info
2011-05-05 20:23:08 +02:00
{
// Width of window.
2011-05-12 01:30:30 +02:00
// If fullscreen mode is requested,
// a width of 0 means the resolution of the desktop should be used.
2011-05-05 20:23:08 +02:00
unsigned width;
// Height of window.
2011-05-12 01:30:30 +02:00
// If fullscreen mode is requested,
// a height of 0 means the resolutiof the desktop should be used.
2011-05-05 20:23:08 +02:00
unsigned height;
// If true, start the window in fullscreen mode.
int fullscreen;
// If true, VSync should be enabled.
int vsync;
2011-05-12 01:30:30 +02:00
// If true, the output image should have the aspect ratio
// as set in aspect_ratio.
2011-05-05 20:23:08 +02:00
int force_aspect;
// Aspect ratio. Only takes effect if force_aspect is enabled.
float aspect_ratio;
2011-05-12 01:30:30 +02:00
// Requests that the image is smoothed,
// using bilinear filtering or otherwise.
2011-05-05 20:23:08 +02:00
// If this cannot be implemented efficiently, this can be disregarded.
// If smooth is false, nearest-neighbor scaling is requested.
int smooth;
2011-05-12 01:30:30 +02:00
// input_scale defines the maximum size of the picture that will
// ever be used with the frame callback.
2012-04-21 23:25:32 +02:00
// The maximum resolution is a multiple of 256x256 size (RARCH_INPUT_SCALE_BASE),
2011-05-12 01:30:30 +02:00
// so an input scale of 2
// means you should allocate a texture or of 512x512.
2011-05-05 20:23:08 +02:00
unsigned input_scale;
// Defines the coloring format used of the input frame.
2011-05-12 01:30:30 +02:00
// XRGB1555 format is 16-bit and has byte ordering: 0RRRRRGGGGGBBBBB,
// in native endian.
// ARGB8888 is AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB, native endian.
2011-05-12 01:30:30 +02:00
// Alpha channel should be disregarded.
2011-05-05 20:23:08 +02:00
int color_format;
2011-05-12 01:30:30 +02:00
// If non-NULL, requests the use of an XML shader.
// Can be disregarded.
2011-05-05 20:23:08 +02:00
const char *xml_shader;
2011-05-12 01:30:30 +02:00
// If non-NULL, requests the use of a Cg shader.
// Can be disregarded.
// If both are non-NULL,
// Cg or XML could be used at the discretion of the plugin.
2011-05-11 17:52:16 +02:00
const char *cg_shader;
2011-05-05 20:23:08 +02:00
2011-05-12 01:30:30 +02:00
// Requestes that a certain
// TTF font is used for rendering messages to the screen.
2011-05-05 20:23:08 +02:00
// Can be disregarded.
const char *ttf_font;
2011-05-11 17:52:16 +02:00
unsigned ttf_font_size;
unsigned ttf_font_color; // Font color, in format ARGB8888. Alpha should be disregarded.
// A title that should be displayed in the title bar of the window.
const char *title_hint;
2011-11-15 15:41:49 +01:00
// Functions to peek into the python runtime for shaders.
// Check typedefs above for explanation.
2012-04-21 23:13:50 +02:00
// These may be NULL if RetroArch is not built with Python support.
2011-11-15 15:41:49 +01:00
python_state_new_cb python_state_new;
python_state_get_cb python_state_get;
python_state_free_cb python_state_free;
2012-04-21 23:25:32 +02:00
} rarch_video_info_t;
2011-05-05 20:23:08 +02:00
2011-05-14 20:52:35 +02:00
// Some convenience macros.
// Extract which axes to test for in negative or positive direction.
2012-04-21 23:25:32 +02:00
// May be equal to RARCH_NO_AXIS, which means testing should not occur.
#define RARCH_AXIS_NEG_GET(x) (((unsigned)(x) >> 16) & 0xFFFFU)
#define RARCH_AXIS_POS_GET(x) ((unsigned)(x) & 0xFFFFU)
2011-05-05 20:23:08 +02:00
2011-05-14 20:52:35 +02:00
// I hope no joypad will ever have this many buttons or axes ... ;)
// If joykey is this value, do not check that button.
2012-04-21 23:25:32 +02:00
#define RARCH_NO_AXIS (0xFFFFFFFFU)
#define RARCH_NO_BTN ((unsigned short)0xFFFFU)
2011-05-05 20:23:08 +02:00
2011-05-14 20:52:35 +02:00
// Masks to test on joykey which hat direction is to be tested for.
2012-04-21 23:25:32 +02:00
#define RARCH_HAT_UP_MASK (1 << 15)
#define RARCH_HAT_DOWN_MASK (1 << 14)
#define RARCH_HAT_LEFT_MASK (1 << 13)
#define RARCH_HAT_RIGHT_MASK (1 << 12)
#define RARCH_HAT_MAP(x, hat) ((x & ((1 << 12) - 1)) | hat)
2011-05-05 20:23:08 +02:00
2012-04-21 23:25:32 +02:00
#define RARCH_HAT_MASK (RARCH_HAT_UP_MASK | RARCH_HAT_DOWN_MASK | \
RARCH_HAT_LEFT_MASK | RARCH_HAT_RIGHT_MASK)
2011-05-05 20:23:08 +02:00
2011-05-14 20:52:35 +02:00
// Test this on the joykey. If true, we want to test for a joypad hat
// rather than a button.
2012-04-21 23:25:32 +02:00
#define RARCH_GET_HAT_DIR(x) (x & RARCH_HAT_MASK)
2011-05-14 20:52:35 +02:00
// Gets the joypad hat to be tested for.
2012-04-21 23:25:32 +02:00
// Only valid when RARCH_GET_HAT_DIR() returns true.
#define RARCH_GET_HAT(x) (x & (~RARCH_HAT_MASK))
2011-05-14 20:52:35 +02:00
// key, joykey and joyaxis are all checked at the same time.
// If any one of these are pressed, return 1 in state callback.
2012-04-21 23:25:32 +02:00
struct rarch_keybind
2011-05-05 20:23:08 +02:00
{
2011-05-14 20:52:35 +02:00
// If analog_x is true, we request an analog device to be polled
// rather than normal keys.
2011-05-12 01:30:30 +02:00
// The returned value should be the delta of
// last frame and current frame in the X-axis.
2011-05-05 20:23:08 +02:00
int analog_x;
2011-05-14 20:52:35 +02:00
// If analog_y is true, we request an analog device to be polled
// rather than normal keys.
2011-05-12 01:30:30 +02:00
// The returned value should be the delta of
// last frame and current frame in the Y-axis.
2011-05-05 20:23:08 +02:00
int analog_y;
// Keyboard key. The key values use the SDL 1.2 keysyms,
2011-05-12 01:30:30 +02:00
// which probably need to be transformed to the native format.
2012-04-21 23:13:50 +02:00
// The actual keysyms RetroArch uses are found in input/keysym.h.
2011-05-05 20:23:08 +02:00
unsigned short key;
2011-05-14 20:52:35 +02:00
// Joypad key. Joypad POV (hats) are embedded into this key as well.
2011-05-05 20:23:08 +02:00
unsigned short joykey;
// Joypad axis. Negative and positive axes are embedded into this variable.
unsigned joyaxis;
};
2012-04-21 23:25:32 +02:00
typedef struct rarch_input_driver
2011-05-05 20:23:08 +02:00
{
2011-05-12 01:30:30 +02:00
// Inits input driver.
// Joypad index denotes which joypads are desired for the various players.
// Should an entry be negative,
// do not open joypad for that player.
2011-05-14 20:52:35 +02:00
// Threshold states the minimum offset that a joypad axis
// has to be held for it to be registered.
// The range of this is [0, 1],
// where 0 means any displacement will register,
// and 1 means the axis has to be pressed all the way to register.
2011-11-02 19:31:36 +01:00
void *(*init)(const int joypad_index[5], float axis_threshold);
2011-05-05 20:23:08 +02:00
// Polls input. Called once every frame.
2011-11-02 19:31:36 +01:00
void (*poll)(void *data);
2011-05-05 20:23:08 +02:00
2011-05-12 01:30:30 +02:00
// Queries input state for a certain key on a certain player.
// Players are 1 - 5.
2011-05-11 17:52:16 +02:00
// For digital inputs, pressed key is 1, not pressed key is 0.
// Analog values have same range as a signed 16-bit integer.
2012-04-21 23:25:32 +02:00
int (*input_state)(void *data, const struct rarch_keybind *bind,
2011-05-12 01:30:30 +02:00
unsigned player);
2011-05-05 20:23:08 +02:00
// Frees the input struct.
2011-11-02 19:31:36 +01:00
void (*free)(void *data);
2011-05-05 20:23:08 +02:00
// Human readable indentification string.
const char *ident;
2012-04-21 23:25:32 +02:00
} rarch_input_driver_t;
2011-05-05 20:23:08 +02:00
2012-04-21 23:25:32 +02:00
typedef struct rarch_video_driver
2011-05-05 20:23:08 +02:00
{
// Inits the video driver. Returns an opaque handle pointer to the driver.
// Returns NULL on error.
//
// Should the video driver request that a certain input driver is used,
2011-05-11 21:12:14 +02:00
// it is possible to set the driver to *input.
// If no certain driver is desired, set *input to NULL.
2012-04-21 23:25:32 +02:00
void *(*init)(const rarch_video_info_t *video,
const rarch_input_driver_t **input);
2011-05-12 01:30:30 +02:00
// Updates frame on the screen.
// Frame can be either XRGB1555 or ARGB32 format
2012-04-21 23:25:32 +02:00
// depending on rgb32 setting in rarch_video_info_t.
2011-05-12 01:30:30 +02:00
// Pitch is the distance in bytes between two scanlines in memory.
//
// When msg is non-NULL,
// it's a message that should be displayed to the user.
2011-11-02 19:31:36 +01:00
int (*frame)(void *data, const void *frame,
2011-05-12 01:30:30 +02:00
unsigned width, unsigned height, unsigned pitch, const char *msg);
// Requests nonblocking operation.
// True = VSync is turned off.
// False = VSync is turned on.
2011-11-02 19:31:36 +01:00
void (*set_nonblock_state)(void *data, int toggle);
2011-05-05 20:23:08 +02:00
// This must return false when the user exits the emulator.
int (*alive)(void *data);
// Does the window have focus?
int (*focus)(void *data);
// Frees the video driver.
2011-11-02 19:31:36 +01:00
void (*free)(void *data);
2011-05-05 20:23:08 +02:00
// A human-readable identification of the video driver.
const char *ident;
2011-05-11 18:26:00 +02:00
2012-04-21 23:25:32 +02:00
// Needs to be defined to RARCH_GRAPHICS_API_VERSION.
// This is used to detect API/ABI mismatches.
2011-05-11 18:26:00 +02:00
int api_version;
2012-04-21 23:25:32 +02:00
} rarch_video_driver_t;
2011-05-05 20:23:08 +02:00
2012-04-21 23:13:50 +02:00
// Called by RetroArch on startup to get a driver handle.
2011-05-14 20:52:35 +02:00
// This is NOT dynamically allocated.
2012-04-21 23:25:32 +02:00
RARCH_API_EXPORT const rarch_video_driver_t* RARCH_API_CALLTYPE
rarch_video_init(void);
2011-05-05 20:23:08 +02:00
#ifdef __cplusplus
}
#endif
#endif