Open Broadcaster Software
Free, open source software for live streaming and recording
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
45 };
46 
47 /* ------------------------------------------------------------------------- */
48 
50  char *name;
52 
54 
55  bool changed;
56  DARRAY(uint8_t) cur_val;
57  DARRAY(uint8_t) default_val;
58 
61 
62  /*char *full_name;
63  float scroller_min, scroller_max, scroller_inc, scroller_mul;*/
64 };
65 
66 static inline void effect_param_init(struct gs_effect_param *param)
67 {
68  memset(param, 0, sizeof(struct gs_effect_param));
69 }
70 
71 static inline void effect_param_free(struct gs_effect_param *param)
72 {
73  bfree(param->name);
74  //bfree(param->full_name);
75  da_free(param->cur_val);
76  da_free(param->default_val);
77 }
78 
80  const char *property);
81 
82 /* ------------------------------------------------------------------------- */
83 
87 };
88 
90  char *name;
92 
95  DARRAY(struct pass_shaderparam) vertshader_params;
96  DARRAY(struct pass_shaderparam) pixelshader_params;
97 };
98 
99 static inline void effect_pass_init(struct gs_effect_pass *pass)
100 {
101  memset(pass, 0, sizeof(struct gs_effect_pass));
102 }
103 
104 static inline void effect_pass_free(struct gs_effect_pass *pass)
105 {
106  bfree(pass->name);
107  da_free(pass->vertshader_params);
108  da_free(pass->pixelshader_params);
111 }
112 
113 /* ------------------------------------------------------------------------- */
114 
116  char *name;
118  struct gs_effect *effect;
119 
120  DARRAY(struct gs_effect_pass) passes;
121 };
122 
123 static inline void effect_technique_init(struct gs_effect_technique *t)
124 {
125  memset(t, 0, sizeof(struct gs_effect_technique));
126 }
127 
128 static inline void effect_technique_free(struct gs_effect_technique *t)
129 {
130  size_t i;
131  for (i = 0; i < t->passes.num; i++)
132  effect_pass_free(t->passes.array+i);
133  da_free(t->passes);
134  bfree(t->name);
135 }
136 
137 /* ------------------------------------------------------------------------- */
138 
139 struct gs_effect {
141  bool cached;
142  char *effect_path, *effect_dir;
143 
144  DARRAY(struct gs_effect_param) params;
145  DARRAY(struct gs_effect_technique) techniques;
146 
147  struct gs_effect_technique *cur_technique;
148  struct gs_effect_pass *cur_pass;
149 
150  gs_eparam_t *view_proj, *world, *scale;
151  graphics_t *graphics;
152 
153  struct gs_effect *next;
154 
155  size_t loop_pass;
156  bool looping;
157 };
158 
159 static inline void effect_init(gs_effect_t *effect)
160 {
161  memset(effect, 0, sizeof(struct gs_effect));
162 }
163 
164 static inline void effect_free(gs_effect_t *effect)
165 {
166  size_t i;
167  for (i = 0; i < effect->params.num; i++)
168  effect_param_free(effect->params.array+i);
169  for (i = 0; i < effect->techniques.num; i++)
170  effect_technique_free(effect->techniques.array+i);
171 
172  da_free(effect->params);
173  da_free(effect->techniques);
174 
175  bfree(effect->effect_path);
176  bfree(effect->effect_dir);
177  effect->effect_path = NULL;
178  effect->effect_dir = NULL;
179 }
180 
181 EXPORT void effect_upload_params(gs_effect_t *effect, bool changed_only);
183  gs_shader_t *shader, struct darray *pass_params,
184  bool changed_only);
185 
186 #ifdef __cplusplus
187 }
188 #endif
EXPORT void gs_shader_destroy(gs_shader_t *shader)
bool changed
Definition: effect.h:55
EXPORT void effect_upload_params(gs_effect_t *effect, bool changed_only)
struct gs_shader gs_shader_t
Definition: graphics.h:266
gs_shader_t * pixelshader
Definition: effect.h:94
Definition: darray.h:41
gs_effect_t * effect
Definition: effect.h:59
struct gs_shader_param gs_sparam_t
Definition: graphics.h:267
unsigned char uint8_t
Definition: vc_stdint.h:27
struct gs_effect_param * eparam
Definition: effect.h:85
Definition: effect.h:43
DARRAY(uint8_t) cur_val
#define EXPORT
Definition: c99defs.h:49
char * effect_dir
Definition: effect.h:142
Definition: graphics-internal.h:275
gs_shader_t * vertshader
Definition: effect.h:93
char * effect_path
Definition: effect.h:142
Definition: effect.h:139
gs_shader_param_type
Definition: graphics.h:278
bool processing
Definition: effect.h:140
Definition: effect.h:89
Definition: effect.h:41
enum effect_section section
Definition: effect.h:51
#define da_free(v)
Definition: darray.h:456
char * name
Definition: effect.h:90
struct gs_effect * effect
Definition: effect.h:118
enum gs_shader_param_type type
Definition: effect.h:53
EXPORT void effect_param_parse_property(gs_eparam_t *param, const char *property)
struct gs_sampler_state gs_samplerstate_t
Definition: graphics.h:263
Definition: effect.h:42
Definition: effect.h:84
EXPORT void effect_upload_shader_params(gs_effect_t *effect, gs_shader_t *shader, struct darray *pass_params, bool changed_only)
gs_samplerstate_t * next_sampler
Definition: effect.h:60
char * name
Definition: effect.h:116
effect_section
Definition: effect.h:40
Definition: effect.h:44
Definition: effect.h:49
bool cached
Definition: effect.h:141
gs_sparam_t * sparam
Definition: effect.h:86
char * name
Definition: effect.h:50
Definition: effect.h:115
EXPORT void bfree(void *ptr)