Vuo  2.0.0
VuoShaderUniforms.h
Go to the documentation of this file.
1 
13 #define SET_UNIFORM(typeName, valueName) \
14  dispatch_semaphore_wait((dispatch_semaphore_t)shader->lock, DISPATCH_TIME_FOREVER); \
15  \
16  /* Is there already a uniform with this identifier? If so, overwrite it. */ \
17  for (int i = 0; i < shader->uniformsCount; ++i) \
18  if (strcmp(shader->uniforms[i].name, uniformIdentifier) == 0) \
19  { \
20  VuoRelease(shader->uniforms[i].type); \
21  shader->uniforms[i].type = VuoText_make(#typeName); \
22  VuoRetain(shader->uniforms[i].type); \
23  \
24  shader->uniforms[i].value.valueName = valueName; \
25  \
26  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock); \
27  return; \
28  } \
29  \
30  /* Otherwise, expand and add another uniform. */ \
31  { \
32  ++shader->uniformsCount; \
33  shader->uniforms = (VuoShaderUniform *)realloc(shader->uniforms, sizeof(VuoShaderUniform) * shader->uniformsCount); \
34  \
35  VuoShaderUniform u; \
36  \
37  u.name = VuoText_make(uniformIdentifier); \
38  VuoRetain(u.name); \
39  \
40  u.type = VuoText_make(#typeName); \
41  VuoRetain(u.type); \
42  \
43  u.value.valueName = valueName; \
44  \
45  u.compiledTextureTarget = 0; \
46  \
47  shader->uniforms[shader->uniformsCount-1] = u; \
48  } \
49  \
50  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock);
51 
55 #define SET_UNIFORM_HEAP(typeName, valueName) \
56  dispatch_semaphore_wait((dispatch_semaphore_t)shader->lock, DISPATCH_TIME_FOREVER); \
57  \
58  /* Is there already a uniform with this identifier? If so, overwrite it. */ \
59  for (int i = 0; i < shader->uniformsCount; ++i) \
60  if (strcmp(shader->uniforms[i].name, uniformIdentifier) == 0) \
61  { \
62  VuoRelease(shader->uniforms[i].type); \
63  shader->uniforms[i].type = VuoText_make(#typeName); \
64  VuoRetain(shader->uniforms[i].type); \
65  \
66  VuoRelease(shader->uniforms[i].value.valueName); \
67  shader->uniforms[i].value.valueName = valueName; \
68  VuoRetain(shader->uniforms[i].value.valueName); \
69  \
70  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock); \
71  return; \
72  } \
73  \
74  /* Otherwise, expand and add another uniform. */ \
75  { \
76  ++shader->uniformsCount; \
77  shader->uniforms = (VuoShaderUniform *)realloc(shader->uniforms, sizeof(VuoShaderUniform) * shader->uniformsCount); \
78  \
79  VuoShaderUniform u; \
80  \
81  u.name = VuoText_make(uniformIdentifier); \
82  VuoRetain(u.name); \
83  \
84  u.type = VuoText_make(#typeName); \
85  VuoRetain(u.type); \
86  \
87  u.value.valueName = valueName; \
88  VuoRetain(u.value.valueName); \
89  \
90  u.compiledTextureTarget = 0; \
91  \
92  shader->uniforms[shader->uniformsCount-1] = u; \
93  } \
94  \
95  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock);
96 
97 
103 void VuoShader_setUniform_VuoImage(VuoShader shader, const char *uniformIdentifier, const VuoImage image)
104 {
105  SET_UNIFORM_HEAP(VuoImage, image);
106 }
107 
113 void VuoShader_setUniform_VuoBoolean(VuoShader shader, const char *uniformIdentifier, const VuoBoolean boolean)
114 {
115  SET_UNIFORM(VuoBoolean, boolean);
116 }
117 
123 void VuoShader_setUniform_VuoInteger(VuoShader shader, const char *uniformIdentifier, const VuoInteger integer)
124 {
125  SET_UNIFORM(VuoInteger, integer);
126 }
127 
133 void VuoShader_setUniform_VuoReal(VuoShader shader, const char *uniformIdentifier, const VuoReal real)
134 {
135  SET_UNIFORM(VuoReal, real);
136 }
137 
143 void VuoShader_setUniform_VuoPoint2d(VuoShader shader, const char *uniformIdentifier, const VuoPoint2d point2d)
144 {
145  SET_UNIFORM(VuoPoint2d, point2d);
146 }
147 
153 void VuoShader_setUniform_VuoPoint3d(VuoShader shader, const char *uniformIdentifier, const VuoPoint3d point3d)
154 {
155  SET_UNIFORM(VuoPoint3d, point3d);
156 }
157 
163 void VuoShader_setUniform_VuoPoint4d(VuoShader shader, const char *uniformIdentifier, const VuoPoint4d point4d)
164 {
165  SET_UNIFORM(VuoPoint4d, point4d);
166 }
167 
176 void VuoShader_setUniform_VuoColor(VuoShader shader, const char *uniformIdentifier, const VuoColor colorUnpremultiplied)
177 {
178  VuoColor color = VuoColor_premultiply(colorUnpremultiplied);
179  SET_UNIFORM(VuoColor, color);
180 }
181 
188 void VuoShader_setUniform_VuoList_VuoBoolean(VuoShader shader, const char *uniformIdentifier, const VuoList_VuoBoolean booleans)
189 {
191 }
192 
199 void VuoShader_setUniform_VuoList_VuoInteger(VuoShader shader, const char *uniformIdentifier, const VuoList_VuoInteger integers)
200 {
202 }
203 
210 void VuoShader_setUniform_VuoList_VuoReal (VuoShader shader, const char *uniformIdentifier, const VuoList_VuoReal reals)
211 {
213 }
214 
221 void VuoShader_setUniform_VuoList_VuoPoint2d(VuoShader shader, const char *uniformIdentifier, const VuoList_VuoPoint2d point2ds)
222 {
224 }
225 
232 void VuoShader_setUniform_VuoList_VuoPoint3d(VuoShader shader, const char *uniformIdentifier, const VuoList_VuoPoint3d point3ds)
233 {
235 }
236 
243 void VuoShader_setUniform_VuoList_VuoPoint4d(VuoShader shader, const char *uniformIdentifier, const VuoList_VuoPoint4d point4ds)
244 {
246 }
247 
257 void VuoShader_setUniform_VuoList_VuoColor(VuoShader shader, const char *uniformIdentifier, const VuoList_VuoColor colorsP)
258 {
259  VuoList_VuoColor colors = VuoListCopy_VuoColor(colorsP);
260  size_t colorCount = VuoListGetCount_VuoColor(colors);
261  VuoColor *colorData = VuoListGetData_VuoColor(colors);
262  for (size_t i = 0; i < colorCount; ++i)
263  colorData[i] = VuoColor_premultiply(colorData[i]);
265 }
266 
273 void VuoShader_setUniform_mat2(VuoShader shader, const char *uniformIdentifier, float *mat2)
274 {
275  SET_UNIFORM_HEAP(mat2, mat2);
276 }
277 
284 void VuoShader_setUniform_mat3(VuoShader shader, const char *uniformIdentifier, float *mat3)
285 {
286  SET_UNIFORM_HEAP(mat3, mat3);
287 }
288 
295 void VuoShader_setUniform_mat4(VuoShader shader, const char *uniformIdentifier, float *mat4)
296 {
297  SET_UNIFORM_HEAP(mat4, mat4);
298 }
299 
304 VuoImage VuoShader_getUniform_VuoImage(VuoShader shader, const char *uniformIdentifier)
305 {
306  dispatch_semaphore_wait((dispatch_semaphore_t)shader->lock, DISPATCH_TIME_FOREVER);
307 
308  for (int i = 0; i < shader->uniformsCount; ++i)
309  if (strcmp(shader->uniforms[i].type, "VuoImage") == 0
310  && strcmp(shader->uniforms[i].name, uniformIdentifier) == 0)
311  {
312  VuoImage image = shader->uniforms[i].value.image;
313  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock);
314  return image;
315  }
316 
317  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock);
318  return NULL;
319 }
320 
326 {
327  dispatch_semaphore_wait((dispatch_semaphore_t)shader->lock, DISPATCH_TIME_FOREVER);
328 
329  for (int i = 0; i < shader->uniformsCount; ++i)
330  if (strcmp(shader->uniforms[i].type, "VuoImage") == 0)
331  {
332  VuoImage image = shader->uniforms[i].value.image;
333  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock);
334  return image;
335  }
336 
337  dispatch_semaphore_signal((dispatch_semaphore_t)shader->lock);
338  return NULL;
339 }