Open Broadcaster Software
Free, open source software for live streaming and recording
effect.h
Go to the documentation of this file.
1 /******************************************************************************
2  Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17 
18 #pragma once
19 
20 #include "effect-parser.h"
21 #include "graphics.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /*
28  * Effects introduce a means of bundling together shader text into one
29  * file with shared functions and parameters. This is done because often
30  * shaders must be duplicated when you need to alter minor aspects of the code
31  * that cannot be done via constants. Effects allow developers to easily
32  * switch shaders and set constants that can be used between shaders.
33  *
34  * Effects are built via the effect parser, and shaders are automatically
35  * generated for each technique's pass.
36  */
37 
38 /* ------------------------------------------------------------------------- */
39 
46 };
47 
48 /* ------------------------------------------------------------------------- */
49 
51  char *name;
53 
55 
56  bool changed;
57  DARRAY(uint8_t) cur_val;
58  DARRAY(uint8_t) default_val;
59 
62 
63  /*char *full_name;
64  float scroller_min, scroller_max, scroller_inc, scroller_mul;*/
65  DARRAY(struct gs_effect_param) annotations;
66 };
67 
68 static inline void effect_param_init(struct gs_effect_param *param)
69 {
70  memset(param, 0, sizeof(struct gs_effect_param));
71  da_init(param->annotations);
72 }
73 
74 static inline void effect_param_free(struct gs_effect_param *param)
75 {
76  bfree(param->name);
77  //bfree(param->full_name);
78  da_free(param->cur_val);
79  da_free(param->default_val);
80 
81  size_t i;
82  for (i = 0; i < param->annotations.num; i++)
83  effect_param_free(param->annotations.array + i);
84 
85  da_free(param->annotations);
86 }
87 
89  const char *property);
90 
91 /* ------------------------------------------------------------------------- */
92 
96 };
97 
99  char *name;
101 
104  DARRAY(struct pass_shaderparam) vertshader_params;
105  DARRAY(struct pass_shaderparam) pixelshader_params;
106 };
107 
108 static inline void effect_pass_init(struct gs_effect_pass *pass)
109 {
110  memset(pass, 0, sizeof(struct gs_effect_pass));
111 }
112 
113 static inline void effect_pass_free(struct gs_effect_pass *pass)
114 {
115  bfree(pass->name);
116  da_free(pass->vertshader_params);
117  da_free(pass->pixelshader_params);
118 
121 }
122 
123 /* ------------------------------------------------------------------------- */
124 
126  char *name;
128  struct gs_effect *effect;
129 
130  DARRAY(struct gs_effect_pass) passes;
131 };
132 
133 static inline void effect_technique_init(struct gs_effect_technique *t)
134 {
135  memset(t, 0, sizeof(struct gs_effect_technique));
136 }
137 
138 static inline void effect_technique_free(struct gs_effect_technique *t)
139 {
140  size_t i;
141  for (i = 0; i < t->passes.num; i++)
142  effect_pass_free(t->passes.array + i);
143 
144  da_free(t->passes);
145  bfree(t->name);
146 }
147 
148 /* ------------------------------------------------------------------------- */
149 
150 struct gs_effect {
152  bool cached;
154 
155  DARRAY(struct gs_effect_param) params;
156  DARRAY(struct gs_effect_technique) techniques;
157 
160 
163 
164  struct gs_effect *next;
165 
166  size_t loop_pass;
167  bool looping;
168 };
169 
170 static inline void effect_init(gs_effect_t *effect)
171 {
172  memset(effect, 0, sizeof(struct gs_effect));
173 }
174 
175 static inline void effect_free(gs_effect_t *effect)
176 {
177  size_t i;
178  for (i = 0; i < effect->params.num; i++)
179  effect_param_free(effect->params.array + i);
180  for (i = 0; i < effect->techniques.num; i++)
181  effect_technique_free(effect->techniques.array + i);
182 
183  da_free(effect->params);
184  da_free(effect->techniques);
185 
186  bfree(effect->effect_path);
187  bfree(effect->effect_dir);
188  effect->effect_path = NULL;
189  effect->effect_dir = NULL;
190 }
191 
192 EXPORT void effect_upload_params(gs_effect_t *effect, bool changed_only);
194  gs_shader_t *shader,
195  struct darray *pass_params,
196  bool changed_only);
197 
198 #ifdef __cplusplus
199 }
200 #endif
EXPORT void gs_shader_destroy(gs_shader_t *shader)
bool looping
Definition: effect.h:167
bool changed
Definition: effect.h:56
DARRAY(struct pass_shaderparam) vertshader_params
EXPORT void effect_upload_params(gs_effect_t *effect, bool changed_only)
struct gs_shader gs_shader_t
Definition: graphics.h:270
gs_shader_t * pixelshader
Definition: effect.h:103
Definition: darray.h:41
gs_effect_t * effect
Definition: effect.h:60
enum effect_section section
Definition: effect.h:127
struct gs_shader_param gs_sparam_t
Definition: graphics.h:271
unsigned char uint8_t
Definition: vc_stdint.h:27
DARRAY(struct gs_effect_pass) passes
struct gs_effect_param * eparam
Definition: effect.h:94
struct gs_effect_technique * cur_technique
Definition: effect.h:158
Definition: effect.h:43
DARRAY(uint8_t) cur_val
Definition: effect.h:45
struct gs_effect * next
Definition: effect.h:164
#define EXPORT
Definition: c99defs.h:49
char * effect_dir
Definition: effect.h:153
Definition: graphics-internal.h:324
gs_shader_t * vertshader
Definition: effect.h:102
char * effect_path
Definition: effect.h:153
Definition: effect.h:150
gs_shader_param_type
Definition: graphics.h:283
bool processing
Definition: effect.h:151
Definition: effect.h:98
Definition: effect.h:41
enum effect_section section
Definition: effect.h:52
#define da_free(v)
Definition: darray.h:467
char * name
Definition: effect.h:99
struct gs_effect * effect
Definition: effect.h:128
DARRAY(struct gs_effect_param) params
enum gs_shader_param_type type
Definition: effect.h:54
EXPORT void effect_param_parse_property(gs_eparam_t *param, const char *property)
struct gs_sampler_state gs_samplerstate_t
Definition: graphics.h:265
Definition: effect.h:42
Definition: effect.h:93
EXPORT void effect_upload_shader_params(gs_effect_t *effect, gs_shader_t *shader, struct darray *pass_params, bool changed_only)
gs_eparam_t * scale
Definition: effect.h:161
gs_samplerstate_t * next_sampler
Definition: effect.h:61
char * name
Definition: effect.h:126
effect_section
Definition: effect.h:40
gs_eparam_t * world
Definition: effect.h:161
Definition: effect.h:44
Definition: effect.h:50
size_t loop_pass
Definition: effect.h:166
bool cached
Definition: effect.h:152
#define da_init(v)
Definition: darray.h:465
gs_sparam_t * sparam
Definition: effect.h:95
graphics_t * graphics
Definition: effect.h:162
char * name
Definition: effect.h:51
gs_eparam_t * view_proj
Definition: effect.h:161
struct gs_effect_pass * cur_pass
Definition: effect.h:159
Definition: effect.h:125
EXPORT void bfree(void *ptr)
enum effect_section section
Definition: effect.h:100