Create shader_null.c and make shader_backend less dependent

on GL
This commit is contained in:
twinaphex 2014-10-02 11:11:34 +02:00
parent 2e4352dea4
commit 039a5d7ab3
12 changed files with 185 additions and 47 deletions

View File

@ -117,6 +117,7 @@ OBJ += frontend/frontend.o \
conf/config_file_userdata.o \
screenshot.o \
gfx/scaler/scaler.o \
gfx/shader/shader_null.o \
gfx/shader/shader_common.o \
gfx/shader/shader_parse.o \
gfx/scaler/pixconv.o \

View File

@ -207,13 +207,12 @@ static bool check_fbo_proc(gl_t *gl)
static bool gl_shader_init(gl_t *gl)
{
enum rarch_shader_type type;
bool ret = false;
const gl_shader_backend_t *backend = NULL;
const shader_backend_t *backend = (const shader_backend_t*)&shader_null_backend;
const char *shader_path = (g_settings.video.shader_enable && *g_settings.video.shader_path) ?
g_settings.video.shader_path : NULL;
enum rarch_shader_type type;
if (!gl)
{
@ -306,7 +305,7 @@ static void gl_disable_client_arrays(gl_t *gl)
void gl_shader_set_coords(gl_t *gl,
const struct gl_coords *coords, const math_matrix *mat)
{
gl_shader_backend_t *shader = (gl_shader_backend_t*)gl->shader;
shader_backend_t *shader = (shader_backend_t*)gl->shader;
bool ret_coords = false;
bool ret_mvp = false;
@ -1001,7 +1000,7 @@ static void gl_check_fbo_dimensions(gl_t *gl)
}
}
static void gl_frame_fbo(gl_t *gl, gl_shader_backend_t *shader,
static void gl_frame_fbo(gl_t *gl, shader_backend_t *shader,
const struct gl_tex_info *tex_info)
{
const struct gl_fbo_rect *prev_rect;
@ -1524,7 +1523,7 @@ static bool gl_frame(void *data, const void *frame,
gl_t *gl = (gl_t*)data;
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
gl_shader_backend_t *shader = (gl_shader_backend_t*)gl->shader;
shader_backend_t *shader = (shader_backend_t*)gl->shader;
if (!gl)
return true;
@ -2598,7 +2597,7 @@ static bool gl_set_shader(void *data,
#endif
default:
gl->shader = NULL;
gl->shader = &shader_null_backend;
break;
}

View File

@ -167,7 +167,7 @@ struct gl_coords
unsigned vertices;
};
typedef struct gl_shader_backend gl_shader_backend_t;
typedef struct shader_backend shader_backend_t;
#define MAX_SHADERS 16
#define MAX_TEXTURES 8
@ -175,7 +175,7 @@ typedef struct gl_shader_backend gl_shader_backend_t;
typedef struct gl
{
const gfx_ctx_driver_t *ctx_driver;
const gl_shader_backend_t *shader;
const shader_backend_t *shader;
bool vsync;
GLuint texture[MAX_TEXTURES];

View File

@ -181,9 +181,10 @@ static bool gl_cg_set_mvp(void *data, const math_matrix *mat)
} \
} while(0)
static bool gl_cg_set_coords(const struct gl_coords *coords)
static bool gl_cg_set_coords(const void *data)
{
if (!cg_active)
const struct gl_coords *coords = (const struct gl_coords*)data;
if (!cg_active || !coords)
return false;
SET_COORD(vertex, vertex, 2);
@ -203,13 +204,17 @@ static void gl_cg_set_params(void *data, unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height,
unsigned frame_count,
const struct gl_tex_info *info,
const struct gl_tex_info *prev_info,
const struct gl_tex_info *fbo_info,
const void *_info,
const void *_prev_info,
const void *_fbo_info,
unsigned fbo_info_cnt)
{
(void)data;
const struct gl_tex_info *info = (const struct gl_tex_info*)_info;
const struct gl_tex_info *prev_info = (const struct gl_tex_info*)_prev_info;
const struct gl_tex_info *fbo_info = (const struct gl_tex_info*)_fbo_info;
unsigned i;
(void)data;
if (!cg_active || (active_index == 0) ||
(active_index == GL_SHADER_STOCK_BLEND))
return;
@ -985,7 +990,7 @@ static struct gfx_shader *gl_cg_get_current_shader(void)
return cg_active ? cg_shader : NULL;
}
const gl_shader_backend_t gl_cg_backend = {
const shader_backend_t gl_cg_backend = {
gl_cg_init,
gl_cg_deinit,
gl_cg_set_params,

View File

@ -20,6 +20,4 @@
#include "shader_common.h"
#include <stdint.h>
extern const gl_shader_backend_t gl_cg_backend;
#endif

View File

@ -50,7 +50,9 @@
#define GL_SHADER_STOCK_BLEND (GFX_MAX_SHADERS - 1)
struct gl_shader_backend
#endif
struct shader_backend
{
bool (*init)(void *data, const char *path);
void (*deinit)(void);
@ -58,16 +60,16 @@ struct gl_shader_backend
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height,
unsigned frame_counter,
const struct gl_tex_info *info,
const struct gl_tex_info *prev_info,
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt);
const void *info,
const void *prev_info,
const void *fbo_info, unsigned fbo_info_cnt);
void (*use)(void *data, unsigned index);
unsigned (*num_shaders)(void);
bool (*filter_type)(unsigned index, bool *smooth);
enum gfx_wrap_type (*wrap_type)(unsigned index);
void (*shader_scale)(unsigned index, struct gfx_fbo_scale *scale);
bool (*set_coords)(const struct gl_coords *coords);
bool (*set_coords)(const void *data);
bool (*set_mvp)(void *data, const math_matrix *mat);
unsigned (*get_prev_textures)(void);
bool (*mipmap_input)(unsigned index);
@ -76,7 +78,11 @@ struct gl_shader_backend
enum rarch_shader_type type;
};
#endif
extern const shader_backend_t gl_glsl_backend;
extern const shader_backend_t hlsl_backend;
extern const shader_backend_t gl_cg_backend;
extern const shader_backend_t shader_null_backend;
#ifdef HAVE_OPENGL
void gl_load_texture_data(GLuint obj, const struct texture_image *img,

View File

@ -868,24 +868,26 @@ static void gl_glsl_set_params(void *data, unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height,
unsigned frame_count,
const struct gl_tex_info *info,
const struct gl_tex_info *prev_info,
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
const void *_info,
const void *_prev_info,
const void *_fbo_info, unsigned fbo_info_cnt)
{
GLfloat buffer[512];
struct glsl_attrib attribs[32];
unsigned i;
size_t size = 0, attribs_size = 0;
const struct gl_tex_info *info = (const struct gl_tex_info*)_info;
const struct gl_tex_info *prev_info = (const struct gl_tex_info*)_prev_info;
const struct gl_tex_info *fbo_info = (const struct gl_tex_info*)_fbo_info;
struct glsl_attrib *attr = (struct glsl_attrib*)attribs;
const struct shader_uniforms *uni = (const struct shader_uniforms*)
&gl_uniforms[glsl_active_index];
(void)data;
if (!glsl_enable || (gl_program[glsl_active_index] == 0))
return;
GLfloat buffer[512];
unsigned i;
size_t size = 0;
struct glsl_attrib attribs[32];
size_t attribs_size = 0;
struct glsl_attrib *attr = attribs;
const struct shader_uniforms *uni = &gl_uniforms[glsl_active_index];
float input_size[2] = {(float)width, (float)height};
float output_size[2] = {(float)out_width, (float)out_height};
float texture_size[2] = {(float)tex_width, (float)tex_height};
@ -1067,9 +1069,11 @@ static bool gl_glsl_set_mvp(void *data, const math_matrix *mat)
return true;
}
static bool gl_glsl_set_coords(const struct gl_coords *coords)
static bool gl_glsl_set_coords(const void *data)
{
if (!glsl_enable || !glsl_shader->modern)
const struct gl_coords *coords = (const struct gl_coords*)data;
if (!glsl_enable || !glsl_shader->modern || !coords)
return false;
/* Avoid hitting malloc on every single regular quad draw. */
@ -1239,7 +1243,7 @@ void gl_glsl_set_context_type(bool core_profile,
glsl_minor = minor;
}
const gl_shader_backend_t gl_glsl_backend = {
const shader_backend_t gl_glsl_backend = {
gl_glsl_init,
gl_glsl_deinit,
gl_glsl_set_params,

View File

@ -22,6 +22,4 @@
void gl_glsl_set_get_proc_address(gfx_ctx_proc_t (*proc)(const char*));
void gl_glsl_set_context_type(bool core_profile, unsigned major, unsigned minor);
extern const gl_shader_backend_t gl_glsl_backend;
#endif

View File

@ -101,12 +101,16 @@ static void hlsl_set_params(void *data, unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height,
unsigned frame_counter,
const struct gl_tex_info *info,
const struct gl_tex_info *prev_info,
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
const void *_info,
const void *_prev_info,
const void *_fbo_info, unsigned fbo_info_cnt)
{
d3d_video_t *d3d = (d3d_video_t*)data;
LPDIRECT3DDEVICE d3d_device_ptr = (LPDIRECT3DDEVICE)d3d->dev;
const struct gl_tex_info *info = (const struct gl_tex_info*)_info;
const struct gl_tex_info *prev_info = (const struct gl_tex_info*)_prev_info;
const struct gl_tex_info *fbo_info = (const struct gl_tex_info*)_fbo_info;
if (!hlsl_active)
return;
@ -433,7 +437,7 @@ static struct gfx_shader *hlsl_get_current_shader(void)
return NULL;
}
const gl_shader_backend_t hlsl_backend = {
const shader_backend_t hlsl_backend = {
hlsl_init,
hlsl_deinit,
hlsl_set_params,

View File

@ -25,6 +25,4 @@ void hlsl_set_proj_matrix(XMMATRIX rotation_value);
#define RARCH_HLSL_MAX_SHADERS 16
extern const gl_shader_backend_t hlsl_backend;
#endif

124
gfx/shader/shader_null.c Normal file
View File

@ -0,0 +1,124 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* 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/>.
*/
#include "../../boolean.h"
#include <string.h>
#include "../../general.h"
#include "../../compat/strl.h"
#include "../../compat/posix_string.h"
#include "../state_tracker.h"
#include "../../dynamic.h"
#include "../../file.h"
#include "../math/matrix.h"
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include "../gfx_context.h"
#include "shader_common.h"
#include <stdlib.h>
typedef struct shader_backend shader_backend_t;
static void shader_null_deinit(void) { }
static bool shader_null_init(void *data, const char *path) { return true; }
static void shader_null_set_params(void *data, unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height,
unsigned frame_count,
const void *info,
const void *prev_info,
const void *fbo_info, unsigned fbo_info_cnt)
{
}
static bool shader_null_set_mvp(void *data, const math_matrix *mat)
{
return false;
}
static bool shader_null_set_coords(const void *data)
{
return false;
}
static void shader_null_use(void *data, unsigned index)
{
}
static unsigned shader_null_num(void)
{
return 0;
}
static bool shader_null_filter_type(unsigned index, bool *smooth)
{
return true;
}
static enum gfx_wrap_type shader_null_wrap_type(unsigned index)
{
return RARCH_WRAP_BORDER;
}
static void shader_null_shader_scale(unsigned index,
struct gfx_fbo_scale *scale)
{
}
static unsigned shader_null_get_prev_textures(void)
{
return 0;
}
static bool shader_null_mipmap_input(unsigned index)
{
return false;
}
static struct gfx_shader *shader_null_get_current_shader(void)
{
return NULL;
}
void shader_null_set_get_proc_address(gfx_ctx_proc_t (*proc)(const char*))
{
}
void shader_null_set_context_type(bool core_profile,
unsigned major, unsigned minor)
{
}
const shader_backend_t shader_null_backend = {
shader_null_init,
shader_null_deinit,
shader_null_set_params,
shader_null_use,
shader_null_num,
shader_null_filter_type,
shader_null_wrap_type,
shader_null_shader_scale,
shader_null_set_coords,
shader_null_set_mvp,
shader_null_get_prev_textures,
shader_null_mipmap_input,
shader_null_get_current_shader,
RARCH_SHADER_NONE,
};

View File

@ -148,6 +148,7 @@ VIDEO SHADERS
#ifdef HAVE_SHADERS
#include "../gfx/shader/shader_common.c"
#include "../gfx/shader/shader_parse.c"
#include "../gfx/shader/shader_null.c"
#ifdef HAVE_CG
#include "../gfx/shader/shader_cg.c"