2012-05-26 02:47:24 +00:00
/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright ( C ) 2010 - 2014 - Hans - Kristian Arntzen
2012-05-26 02:47:24 +00:00
*
* RetroArch is free software : you can redistribute it and / or modify it under the terms
* of the GNU General Public License as published by the Free Software Found -
* ation , either version 3 of the License , or ( at your option ) any later version .
*
* RetroArch is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE . See the GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License along with RetroArch .
* If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef __GFX_CONTEXT_H
# define __GFX_CONTEXT_H
# include "../boolean.h"
# include "../driver.h"
# ifdef HAVE_CONFIG_H
# include "../config.h"
# endif
2014-01-22 15:38:42 +00:00
# ifdef __cplusplus
extern " C " {
# endif
2012-10-20 03:08:53 +00:00
# define MAX_EGLIMAGE_TEXTURES 32
2012-09-24 23:26:22 +00:00
enum gfx_ctx_api
{
GFX_CTX_OPENGL_API ,
GFX_CTX_OPENGL_ES_API ,
2012-09-30 15:10:04 +00:00
GFX_CTX_DIRECT3D8_API ,
GFX_CTX_DIRECT3D9_API ,
2012-09-24 23:26:22 +00:00
GFX_CTX_OPENVG_API
} ;
typedef void ( * gfx_ctx_proc_t ) ( void ) ;
2014-03-09 15:50:18 +00:00
// The opaque void* argument should be the overlying driver data (e.g. gl_t for OpenGL contexts).
// This will allow us in the future to have separate contexts to separate gl_t structs (if needed).
// For now, this is only relevant for D3D.
2012-09-24 23:26:22 +00:00
typedef struct gfx_ctx_driver
{
2014-03-09 15:50:18 +00:00
bool ( * init ) ( void * data ) ;
void ( * destroy ) ( void * data ) ;
2012-09-24 23:26:22 +00:00
2014-03-09 15:50:18 +00:00
bool ( * bind_api ) ( void * data , enum gfx_ctx_api , unsigned major , unsigned minor ) ; // Which API to bind to.
2012-09-24 23:26:22 +00:00
// Sets the swap interval.
2014-03-09 15:50:18 +00:00
void ( * swap_interval ) ( void * data , unsigned ) ;
2012-09-24 23:26:22 +00:00
// Sets video mode. Creates a window, etc.
2014-03-09 15:50:18 +00:00
bool ( * set_video_mode ) ( void * , unsigned , unsigned , bool ) ;
2012-09-24 23:26:22 +00:00
// Gets current window size.
// If not initialized yet, it returns current screen size.
2014-03-09 15:50:18 +00:00
void ( * get_video_size ) ( void * , unsigned * , unsigned * ) ;
2012-09-24 23:26:22 +00:00
2012-09-25 11:51:44 +00:00
// Translates a window size to an aspect ratio.
// In most cases this will be just width / height, but
// some contexts will better know which actual aspect ratio is used.
// This can be NULL to assume the default behavior.
2014-03-09 15:50:18 +00:00
float ( * translate_aspect ) ( void * , unsigned , unsigned ) ;
2012-09-25 11:51:44 +00:00
2012-09-24 23:26:22 +00:00
// Asks driver to update window title (FPS, etc).
2014-03-09 15:50:18 +00:00
void ( * update_window_title ) ( void * ) ;
2012-09-24 23:26:22 +00:00
// Queries for resize and quit events.
// Also processes events.
2014-03-09 15:50:18 +00:00
void ( * check_window ) ( void * , bool * , bool * , unsigned * , unsigned * , unsigned ) ;
2012-09-24 23:26:22 +00:00
// Acknowledge a resize event. This is needed for some APIs. Most backends will ignore this.
2014-03-09 15:50:18 +00:00
void ( * set_resize ) ( void * , unsigned , unsigned ) ;
2012-09-24 23:26:22 +00:00
// Checks if window has input focus.
2014-03-09 15:50:18 +00:00
bool ( * has_focus ) ( void * ) ;
2012-09-24 23:26:22 +00:00
// Swaps buffers. VBlank sync depends on earlier calls to swap_interval.
2014-03-09 15:50:18 +00:00
void ( * swap_buffers ) ( void * ) ;
2012-09-24 23:26:22 +00:00
// Most video backends will want to use a certain input driver.
// Checks for it here.
2014-03-09 15:50:18 +00:00
void ( * input_driver ) ( void * , const input_driver_t * * , void * * ) ;
2012-09-24 23:26:22 +00:00
// Wraps whatever gl_proc_address() there is.
2014-03-09 15:50:18 +00:00
// Does not take opaque, to avoid lots of ugly wrapper code.
2012-09-24 23:26:22 +00:00
gfx_ctx_proc_t ( * get_proc_address ) ( const char * ) ;
2013-04-06 17:17:39 +00:00
# ifdef HAVE_EGL
2012-10-20 03:08:53 +00:00
// Returns true if this context supports EGLImage buffers for screen drawing and was initalized correctly.
2014-03-09 15:50:18 +00:00
bool ( * init_egl_image_buffer ) ( void * , const video_info_t * ) ;
2012-10-20 03:08:53 +00:00
// Writes the frame to the EGLImage and sets image_handle to it. Returns true if a new image handle is created.
// Always returns true the first time it's called for a new index. The graphics core must handle a change in the handle correctly.
2014-03-09 15:50:18 +00:00
bool ( * write_egl_image ) ( void * , const void * frame , unsigned width , unsigned height , unsigned pitch , bool rgb32 , unsigned index , void * * image_handle ) ;
2013-04-06 17:17:39 +00:00
# endif
2012-10-18 22:59:56 +00:00
2013-03-29 12:46:11 +00:00
// Shows or hides mouse. Can be NULL if context doesn't have a concept of mouse pointer.
2014-03-09 15:50:18 +00:00
void ( * show_mouse ) ( void * , bool state ) ;
2013-03-29 12:46:11 +00:00
2012-09-24 23:26:22 +00:00
// Human readable string.
const char * ident ;
2014-04-19 13:37:00 +00:00
// Optional. Binds HW-render offscreen context.
void ( * bind_hw_render ) ( void * data , bool enable ) ;
2012-09-24 23:26:22 +00:00
} gfx_ctx_driver_t ;
extern const gfx_ctx_driver_t gfx_ctx_sdl_gl ;
extern const gfx_ctx_driver_t gfx_ctx_x_egl ;
2012-09-29 09:59:08 +00:00
extern const gfx_ctx_driver_t gfx_ctx_glx ;
2014-01-18 17:43:07 +00:00
extern const gfx_ctx_driver_t gfx_ctx_d3d9 ;
2012-09-24 23:26:22 +00:00
extern const gfx_ctx_driver_t gfx_ctx_drm_egl ;
2012-10-08 22:11:11 +00:00
extern const gfx_ctx_driver_t gfx_ctx_android ;
2012-09-24 23:26:22 +00:00
extern const gfx_ctx_driver_t gfx_ctx_ps3 ;
2012-09-30 09:26:26 +00:00
extern const gfx_ctx_driver_t gfx_ctx_wgl ;
2012-09-24 23:26:22 +00:00
extern const gfx_ctx_driver_t gfx_ctx_videocore ;
2013-02-26 00:19:03 +00:00
extern const gfx_ctx_driver_t gfx_ctx_bbqnx ;
2013-07-07 20:24:28 +00:00
extern const gfx_ctx_driver_t gfx_ctx_apple ;
2013-07-18 00:26:01 +00:00
extern const gfx_ctx_driver_t gfx_ctx_emscripten ;
2013-07-04 13:01:38 +00:00
extern const gfx_ctx_driver_t gfx_ctx_null ;
2012-09-24 23:26:22 +00:00
const gfx_ctx_driver_t * gfx_ctx_find_driver ( const char * ident ) ; // Finds driver with ident. Does not initialize.
2014-04-19 14:06:12 +00:00
const gfx_ctx_driver_t * gfx_ctx_init_first ( void * data , enum gfx_ctx_api api , unsigned major , unsigned minor , bool hw_render_ctx ) ; // Finds first suitable driver and initializes.
2012-09-24 23:26:22 +00:00
2014-01-22 15:38:42 +00:00
# ifdef __cplusplus
}
# endif
2012-05-26 02:47:24 +00:00
# endif