2013-09-30 19:37:13 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 21:24:38 -08:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-09-30 19:37:13 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-10-14 04:21:15 -07:00
|
|
|
#pragma once
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
#include "effect-parser.h"
|
|
|
|
#include "graphics.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Effects introduce a means of bundling together shader text into one
|
|
|
|
* file with shared functions and parameters. This is done because often
|
|
|
|
* shaders must be duplicated when you need to alter minor aspects of the code
|
|
|
|
* that cannot be done via constants. Effects allow developers to easily
|
|
|
|
* switch shaders and set constants that can be used between shaders.
|
|
|
|
*
|
|
|
|
* Effects are built via the effect parser, and shaders are automatically
|
|
|
|
* generated for each technique's pass.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
enum effect_section {
|
|
|
|
EFFECT_PARAM,
|
|
|
|
EFFECT_TECHNIQUE,
|
|
|
|
EFFECT_SAMPLER,
|
|
|
|
EFFECT_PASS
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_effect_param {
|
2013-09-30 19:37:13 -07:00
|
|
|
char *name;
|
|
|
|
enum effect_section section;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
enum gs_shader_param_type type;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
bool changed;
|
|
|
|
DARRAY(uint8_t) cur_val;
|
|
|
|
DARRAY(uint8_t) default_val;
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_effect_t *effect;
|
2016-06-29 04:15:38 -07:00
|
|
|
gs_samplerstate_t *next_sampler;
|
2013-10-17 17:21:42 -07:00
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
/*char *full_name;
|
|
|
|
float scroller_min, scroller_max, scroller_inc, scroller_mul;*/
|
|
|
|
};
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline void effect_param_init(struct gs_effect_param *param)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-08-07 23:42:07 -07:00
|
|
|
memset(param, 0, sizeof(struct gs_effect_param));
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline void effect_param_free(struct gs_effect_param *param)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
bfree(param->name);
|
|
|
|
//bfree(param->full_name);
|
|
|
|
da_free(param->cur_val);
|
|
|
|
da_free(param->default_val);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
EXPORT void effect_param_parse_property(gs_eparam_t *param,
|
2013-09-30 19:37:13 -07:00
|
|
|
const char *property);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct pass_shaderparam {
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_effect_param *eparam;
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_sparam_t *sparam;
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_effect_pass {
|
2013-09-30 19:37:13 -07:00
|
|
|
char *name;
|
|
|
|
enum effect_section section;
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *vertshader;
|
|
|
|
gs_shader_t *pixelshader;
|
2013-09-30 19:37:13 -07:00
|
|
|
DARRAY(struct pass_shaderparam) vertshader_params;
|
|
|
|
DARRAY(struct pass_shaderparam) pixelshader_params;
|
|
|
|
};
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline void effect_pass_init(struct gs_effect_pass *pass)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-08-07 23:42:07 -07:00
|
|
|
memset(pass, 0, sizeof(struct gs_effect_pass));
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline void effect_pass_free(struct gs_effect_pass *pass)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
bfree(pass->name);
|
|
|
|
da_free(pass->vertshader_params);
|
|
|
|
da_free(pass->pixelshader_params);
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_shader_destroy(pass->vertshader);
|
|
|
|
gs_shader_destroy(pass->pixelshader);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_effect_technique {
|
2013-09-30 19:37:13 -07:00
|
|
|
char *name;
|
|
|
|
enum effect_section section;
|
|
|
|
struct gs_effect *effect;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
DARRAY(struct gs_effect_pass) passes;
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline void effect_technique_init(struct gs_effect_technique *t)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-08-07 23:42:07 -07:00
|
|
|
memset(t, 0, sizeof(struct gs_effect_technique));
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline void effect_technique_free(struct gs_effect_technique *t)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < t->passes.num; i++)
|
|
|
|
effect_pass_free(t->passes.array+i);
|
|
|
|
da_free(t->passes);
|
|
|
|
bfree(t->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct gs_effect {
|
|
|
|
bool processing;
|
2015-04-10 09:48:55 -07:00
|
|
|
bool cached;
|
2013-09-30 19:37:13 -07:00
|
|
|
char *effect_path, *effect_dir;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
DARRAY(struct gs_effect_param) params;
|
|
|
|
DARRAY(struct gs_effect_technique) techniques;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_effect_technique *cur_technique;
|
|
|
|
struct gs_effect_pass *cur_pass;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_eparam_t *view_proj, *world, *scale;
|
|
|
|
graphics_t *graphics;
|
2014-11-19 19:12:01 -08:00
|
|
|
|
2015-03-08 06:55:15 -07:00
|
|
|
struct gs_effect *next;
|
|
|
|
|
2014-11-19 19:12:01 -08:00
|
|
|
size_t loop_pass;
|
|
|
|
bool looping;
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static inline void effect_init(gs_effect_t *effect)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
memset(effect, 0, sizeof(struct gs_effect));
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static inline void effect_free(gs_effect_t *effect)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < effect->params.num; i++)
|
|
|
|
effect_param_free(effect->params.array+i);
|
|
|
|
for (i = 0; i < effect->techniques.num; i++)
|
|
|
|
effect_technique_free(effect->techniques.array+i);
|
|
|
|
|
|
|
|
da_free(effect->params);
|
|
|
|
da_free(effect->techniques);
|
|
|
|
|
|
|
|
bfree(effect->effect_path);
|
|
|
|
bfree(effect->effect_dir);
|
|
|
|
effect->effect_path = NULL;
|
|
|
|
effect->effect_dir = NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
EXPORT void effect_upload_params(gs_effect_t *effect, bool changed_only);
|
|
|
|
EXPORT void effect_upload_shader_params(gs_effect_t *effect,
|
|
|
|
gs_shader_t *shader, struct darray *pass_params,
|
|
|
|
bool changed_only);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|