From b53bb2c6acce9ab44b48d18c76a9059261e97548 Mon Sep 17 00:00:00 2001 From: "R. Belmont" Date: Wed, 13 Jan 2010 04:01:20 +0000 Subject: SDLMAME initial import [R. Belmont, Couriersud] --- src/osd/sdl/gl_shader_mgr.c | 282 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 src/osd/sdl/gl_shader_mgr.c (limited to 'src/osd/sdl/gl_shader_mgr.c') diff --git a/src/osd/sdl/gl_shader_mgr.c b/src/osd/sdl/gl_shader_mgr.c new file mode 100644 index 00000000000..0707ed47656 --- /dev/null +++ b/src/osd/sdl/gl_shader_mgr.c @@ -0,0 +1,282 @@ + +#include "osdcomm.h" +#include "osdcore.h" +#include "osdepend.h" + +#include "gl_shader_mgr.h" + +#define GLSL_VERTEX_SHADER_INT_NUMBER 1 // general +#define GLSL_VERTEX_SHADER_MAX_NUMBER 2 // general + custom +#define GLSL_VERTEX_SHADER_CUSTOM 1 // custom idx + +#ifdef GLSL_SOURCE_ON_DISK + +static const char * glsl_mamebm_vsh_files [GLSL_VERTEX_SHADER_INT_NUMBER] = +{ + "/tmp/glsl_general.vsh" // general +}; + +static const char * glsl_mamebm_fsh_files [GLSL_SHADER_TYPE_NUMBER][GLSL_SHADER_FEAT_INT_NUMBER] = +{ + {"/tmp/glsl_plain_idx16_lut.fsh", // idx16 lut plain + "/tmp/glsl_bilinear_idx16_lut.fsh" // idx16 lut bilinear + }, + + {"/tmp/glsl_plain_rgb32_lut.fsh", // rgb32 lut plain + "/tmp/glsl_bilinear_rgb32_lut.fsh" // rgb32 lut bilinear + }, + + {"/tmp/glsl_plain_rgb32_dir.fsh", // rgb32 dir plain + "/tmp/glsl_bilinear_rgb32_dir.fsh" // rgb32 dir bilinear + } +}; + +#else // GLSL_SOURCE_ON_DISK + +#include "shader/glsl_general.vsh.c" + +#include "shader/glsl_plain_idx16_lut.fsh.c" +#include "shader/glsl_bilinear_idx16_lut.fsh.c" + +#include "shader/glsl_plain_rgb32_lut.fsh.c" +#include "shader/glsl_bilinear_rgb32_lut.fsh.c" + +#include "shader/glsl_plain_rgb32_dir.fsh.c" +#include "shader/glsl_bilinear_rgb32_dir.fsh.c" + +static const char * glsl_mamebm_vsh_sources [GLSL_VERTEX_SHADER_INT_NUMBER] = +{ + glsl_general_vsh_src // general +}; + +static const char * glsl_mamebm_fsh_sources [GLSL_SHADER_TYPE_NUMBER][GLSL_SHADER_FEAT_INT_NUMBER] = +{ + {glsl_plain_idx16_lut_fsh_src, // idx16 lut plain + glsl_bilinear_idx16_lut_fsh_src // idx16 lut bilinear + }, + + {glsl_plain_rgb32_lut_fsh_src, // rgb32 lut plain + glsl_bilinear_rgb32_lut_fsh_src // rgb32 lut bilinear + }, + + {glsl_plain_rgb32_dir_fsh_src, // rgb32 dir plain + glsl_bilinear_rgb32_dir_fsh_src // rgb32 dir bilinear + } +}; + +#endif // GLSL_SOURCE_ON_DISK + +static const char * glsl_mamebm_filter_names [GLSL_SHADER_FEAT_MAX_NUMBER] = +{ + "plain", + "bilinear", + "custom" +}; + +static GLhandleARB glsl_mamebm_programs [GLSL_SHADER_TYPE_NUMBER][GLSL_SHADER_FEAT_MAX_NUMBER+9] = +{ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* idx16 lut: plain, bilinear, custom0-9, .. */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* rgb32 lut: plain, bilinear, custom0-9, .. */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* rgb32 dir: plain, bilinear, custom0-9, .. */ +}; + +/** + * fragment shader -> vertex shader mapping + */ +static int glsl_mamebm_fsh2vsh[GLSL_SHADER_FEAT_MAX_NUMBER] = +{ + 0, // plain -> general + 0, // bilinear -> general + 1, // custom -> custom +}; + +static GLhandleARB glsl_mamebm_vsh_shader[GLSL_VERTEX_SHADER_MAX_NUMBER+9] = +{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* general, custom0-9 */ + +static GLhandleARB glsl_mamebm_fsh_shader [GLSL_SHADER_TYPE_NUMBER][GLSL_SHADER_FEAT_MAX_NUMBER+9] = +{ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* idx16 lut: plain, bilinear, custom0-9 */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* rgb32 lut: plain, bilinear, custom0-9 */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* rgb32 dir: plain, bilinear, custom0-9 */ +}; + +static GLhandleARB glsl_scrn_programs [10] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* rgb32: custom0-9, .. */ +}; + +static GLhandleARB glsl_scrn_vsh_shader[10] = +{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* custom0-9 */ + +static GLhandleARB glsl_scrn_fsh_shader [10] = +{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* rgb32: custom0-9 */ + +const char * glsl_shader_get_filter_name_mamebm(int glslShaderFeature) +{ + if ( !(0 <= glslShaderFeature && glslShaderFeature < GLSL_SHADER_FEAT_MAX_NUMBER) ) + return "illegal shader feature"; + + return glsl_mamebm_filter_names[glslShaderFeature]; +} + +GLhandleARB glsl_shader_get_program_mamebm(int glslShaderType, int glslShaderFeature, int idx) +{ + if ( !(0 <= glslShaderType && glslShaderType < GLSL_SHADER_TYPE_NUMBER) ) + return 0; + + if ( !(0 <= glslShaderFeature && glslShaderFeature < GLSL_SHADER_FEAT_MAX_NUMBER) ) + return 0; + + return glsl_mamebm_programs[glslShaderType][glslShaderFeature+idx]; +} + +GLhandleARB glsl_shader_get_program_scrn(int idx) +{ + if ( !(0 <= idx && idx < 10) ) + return 0; + + return glsl_scrn_programs[idx]; +} + +glsl_shader_info *glsl_shader_init(void) +{ + int i,j, err; + + err = gl_shader_loadExtention((PFNGLGETPROCADDRESSOS)SDL_GL_GetProcAddress); + if(err) return NULL; + + for (i=0; !err && i