Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shader.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <SDL.h>
7 #include <SDL_opengl.h> // for GL_FALSE, GL_FLOAT, GL_INT
8 #include <limits.h> // for USHRT_MAX
9 #include <string.h> // for memcpy, memset, NULL
10 #include <algorithm> // for min
11 
12 #include "SDL_opengl.h" // for GL_FLOAT_VEC4, GL_BOOL, GL_...
13 #include "inexor/engine/glexts.hpp" // for glUniform4fv_, glUniform1f_
14 #include "inexor/network/SharedVar.hpp" // for SharedVar
15 #include "inexor/shared/cube_loops.hpp" // for i, loopi, loopv
16 #include "inexor/shared/cube_tools.hpp" // for DELETEA
17 #include "inexor/shared/cube_types.hpp" // for ushort, uint, uchar
18 #include "inexor/shared/cube_vector.hpp" // for vector
19 #include "inexor/shared/geom.hpp" // for plane, vec::(anonymous)
20 
22 {
23  const char *name;
24  union
25  {
26  float fval[32];
27  int ival[32];
28  uint uval[32];
29  uchar buf[32*sizeof(float)];
30  };
31  int version;
32 
33  static int nextversion;
34 
35  void resetversions();
36 
37  void changed()
38  {
39  if(++nextversion < 0) resetversions();
41  }
42 };
43 
45 {
46  int loc, size;
48 };
49 
51 {
52 
54  int version;
55 
56  void flush()
57  {
58  if(version == param->version) return;
59  switch(format)
60  {
61  case GL_BOOL:
62  case GL_FLOAT: glUniform1fv_(loc, size, param->fval); break;
63  case GL_BOOL_VEC2:
64  case GL_FLOAT_VEC2: glUniform2fv_(loc, size, param->fval); break;
65  case GL_BOOL_VEC3:
66  case GL_FLOAT_VEC3: glUniform3fv_(loc, size, param->fval); break;
67  case GL_BOOL_VEC4:
68  case GL_FLOAT_VEC4: glUniform4fv_(loc, size, param->fval); break;
69  case GL_INT: glUniform1iv_(loc, size, param->ival); break;
70  case GL_INT_VEC2: glUniform2iv_(loc, size, param->ival); break;
71  case GL_INT_VEC3: glUniform3iv_(loc, size, param->ival); break;
72  case GL_INT_VEC4: glUniform4iv_(loc, size, param->ival); break;
73  case GL_FLOAT_MAT2: glUniformMatrix2fv_(loc, 1, GL_FALSE, param->fval); break;
74  case GL_FLOAT_MAT3: glUniformMatrix3fv_(loc, 1, GL_FALSE, param->fval); break;
75  case GL_FLOAT_MAT4: glUniformMatrix4fv_(loc, 1, GL_FALSE, param->fval); break;
76  }
78  }
79 };
80 
82 {
83  const char *name;
84 };
85 
87 {
88  const char *name;
89  int loc;
90  float val[4];
91 };
92 
94 {
95  float val[4];
96 
99  {
100  name = p.name;
101  loc = -1;
102  size = 1;
103  format = GL_FLOAT_VEC4;
104  memcpy(val, p.val, sizeof(val));
105  }
106 };
107 
108 enum
109 {
114 
117 };
118 
119 #define MAXSHADERDETAIL 3
120 #define MAXVARIANTROWS 5
121 
123 
124 class Slot;
125 class VSlot;
126 
128 {
129  const char *name, *blockname;
131  void *data;
132  UniformLoc(const char *name = nullptr, const char *blockname = nullptr, int binding = -1, int stride = -1) : name(name), blockname(blockname), loc(-1), version(-1), binding(binding), stride(stride), offset(-1), size(-1), data(nullptr) {}
133 };
134 
135 struct AttribLoc
136 {
137  const char *name;
138  int loc;
139  AttribLoc(const char *name = nullptr, int loc = -1) : name(name), loc(loc) {}
140 };
141 
142 struct Shader
143 {
145 
146  char *name, *vsstr, *psstr, *defer;
147  int type;
160  const void *owner;
161 
162  Shader() : name(nullptr), vsstr(nullptr), psstr(nullptr), defer(nullptr), type(SHADER_DEFAULT), program(0), vsobj(0), psobj(0), detailshader(nullptr), variantshader(nullptr), altshader(nullptr), variantrows(nullptr), standard(false), forced(false), used(false), reusevs(nullptr), reuseps(nullptr), owner(nullptr)
163  {
164  loopi(MAXSHADERDETAIL) fastshader[i] = this;
165  }
166 
168  {
169  DELETEA(name);
170  DELETEA(vsstr);
171  DELETEA(psstr);
172  DELETEA(defer);
174  }
175 
176  void fixdetailshader(bool force = true, bool recurse = true);
177  void allocparams(Slot *slot = nullptr);
178  void setslotparams(Slot &slot);
179  void setslotparams(Slot &slot, VSlot &vslot);
180  void bindprograms();
181 
182  void flushparams(Slot *slot = nullptr)
183  {
184  if(!used) { allocparams(slot); used = true; }
185  loopv(globalparams) globalparams[i].flush();
186  }
187 
188  void force();
189 
190  bool invalid() const { return (type&SHADER_INVALID)!=0; }
191  bool deferred() const { return (type&SHADER_DEFERRED)!=0; }
192  bool loaded() const { return detailshader!=nullptr; }
193 
194  static inline bool isnull(const Shader *s) { return !s; }
195 
196  bool isnull() const { return isnull(this); }
197 
198  int numvariants(int row) const
199  {
200  if(row < 0 || row >= MAXVARIANTROWS || !variantrows) return 0;
201  return variantrows[row+1] - variantrows[row];
202  }
203 
204  Shader *getvariant(int col, int row) const
205  {
206  if(row < 0 || row >= MAXVARIANTROWS || col < 0 || !variantrows) return nullptr;
207  int start = variantrows[row], end = variantrows[row+1];
208  return col < end - start ? variants[start + col] : nullptr;
209  }
210 
211  bool hasoption(int row)
212  {
213  if(detailshader)
214  {
215  Shader *s = getvariant(0, row);
216  if(s) return (s->type&SHADER_OPTION)!=0;
217  }
218  return false;
219  }
220 
221  void addvariant(int row, Shader *s)
222  {
223  if(row < 0 || row >= MAXVARIANTROWS || variants.length() >= USHRT_MAX) return;
224  if(!variantrows) { variantrows = new ushort[MAXVARIANTROWS+1]; memset(variantrows, 0, (MAXVARIANTROWS+1)*sizeof(ushort)); }
225  variants.insert(variantrows[row+1], s);
226  for(int i = row+1; i <= MAXVARIANTROWS; ++i) ++variantrows[i];
227  }
228 
229  void setvariant_(int col, int row, Shader *fallbackshader)
230  {
231  Shader *s = fallbackshader;
233  {
234  int start = detailshader->variantrows[row], end = detailshader->variantrows[row+1];
235  for(col = std::min(start + col, end-1); col >= start; --col)
236  {
237  if(!detailshader->variants[col]->invalid()) { s = detailshader->variants[col]; break; }
238  }
239  }
240  if(lastshader!=s) s->bindprograms();
241  }
242 
243  void setvariant(int col, int row, Shader *fallbackshader)
244  {
245  if(isnull() || !loaded()) return;
246  setvariant_(col, row, fallbackshader);
248  }
249 
250  void setvariant(int col, int row)
251  {
252  if(isnull() || !loaded()) return;
253  setvariant_(col, row, detailshader);
255  }
256 
257  void setvariant(int col, int row, Slot &slot, VSlot &vslot, Shader *fallbackshader)
258  {
259  if(isnull() || !loaded()) return;
260  setvariant_(col, row, fallbackshader);
261  lastshader->flushparams(&slot);
262  lastshader->setslotparams(slot, vslot);
263  }
264 
265  void setvariant(int col, int row, Slot &slot, VSlot &vslot)
266  {
267  if(isnull() || !loaded()) return;
268  setvariant_(col, row, detailshader);
269  lastshader->flushparams(&slot);
270  lastshader->setslotparams(slot, vslot);
271  }
272 
273  void set_()
274  {
276  }
277 
278  void set()
279  {
280  if(isnull() || !loaded()) return;
281  set_();
283  }
284 
285  void set(Slot &slot, VSlot &vslot)
286  {
287  if(isnull() || !loaded()) return;
288  set_();
289  lastshader->flushparams(&slot);
290  lastshader->setslotparams(slot, vslot);
291  }
292 
293  bool compile();
294  void cleanup(bool invalid = false);
295 
296  static int uniformlocversion();
297 };
298 
300 {
301  const char *name;
303 
304  GlobalShaderParam(const char *name) : name(name), param(nullptr) {}
305 
307  {
308  extern GlobalShaderParamState *getglobalparam(const char *name);
309  if(!param) param = getglobalparam(name);
310  param->changed();
311  return param;
312  }
313 
314  void setf(float x = 0, float y = 0, float z = 0, float w = 0)
315  {
317  g->fval[0] = x;
318  g->fval[1] = y;
319  g->fval[2] = z;
320  g->fval[3] = w;
321  }
322  void set(const vec &v, float w = 0) { setf(v.x, v.y, v.z, w); }
323  void set(const vec2 &v, float z = 0, float w = 0) { setf(v.x, v.y, z, w); }
324  void set(const vec4 &v) { setf(v.x, v.y, v.z, v.w); }
325  void set(const plane &p) { setf(p.x, p.y, p.z, p.offset); }
326  void set(const matrix2 &m) { memcpy(resolve()->fval, m.a.v, sizeof(m)); }
327  void set(const matrix3 &m) { memcpy(resolve()->fval, m.a.v, sizeof(m)); }
328  void set(const matrix4 &m) { memcpy(resolve()->fval, m.a.v, sizeof(m)); }
329 
330  template<class T>
331  void setv(const T *v, int n = 1) { memcpy(resolve()->buf, v, n*sizeof(T)); }
332 
333  void seti(int x = 0, int y = 0, int z = 0, int w = 0)
334  {
336  g->ival[0] = x;
337  g->ival[1] = y;
338  g->ival[2] = z;
339  g->ival[3] = w;
340  }
341  void set(const ivec &v, int w = 0) { seti(v.x, v.y, v.z, w); }
342  void set(const ivec2 &v, int z = 0, int w = 0) { seti(v.x, v.y, z, w); }
343  void set(const ivec4 &v) { seti(v.x, v.y, v.z, v.w); }
344 
345  void setu(uint x = 0, uint y = 0, uint z = 0, uint w = 0)
346  {
348  g->uval[0] = x;
349  g->uval[1] = y;
350  g->uval[2] = z;
351  g->uval[3] = w;
352  }
353 
354  template<class T>
355  T *reserve(int n = 1) { return (T *)resolve()->buf; }
356 };
357 
359 {
360  const char *name;
361  int loc;
362 
363  LocalShaderParam(const char *name) : name(name), loc(-1) {}
364 
366  {
368  if(!s) return nullptr;
369  if(!s->localparamremap.inrange(loc))
370  {
371  extern int getlocalparam(const char *name);
372  if(loc == -1) loc = getlocalparam(name);
373  if(!s->localparamremap.inrange(loc)) return nullptr;
374  }
375  uchar remap = s->localparamremap[loc];
376  return s->localparams.inrange(remap) ? &s->localparams[remap] : nullptr;
377  }
378 
379  void setf(float x = 0, float y = 0, float z = 0, float w = 0)
380  {
382  if(b) switch(b->format)
383  {
384  case GL_BOOL:
385  case GL_FLOAT: glUniform1f_(b->loc, x); break;
386  case GL_BOOL_VEC2:
387  case GL_FLOAT_VEC2: glUniform2f_(b->loc, x, y); break;
388  case GL_BOOL_VEC3:
389  case GL_FLOAT_VEC3: glUniform3f_(b->loc, x, y, z); break;
390  case GL_BOOL_VEC4:
391  case GL_FLOAT_VEC4: glUniform4f_(b->loc, x, y, z, w); break;
392  case GL_INT: glUniform1i_(b->loc, int(x)); break;
393  case GL_INT_VEC2: glUniform2i_(b->loc, int(x), int(y)); break;
394  case GL_INT_VEC3: glUniform3i_(b->loc, int(x), int(y), int(z)); break;
395  case GL_INT_VEC4: glUniform4i_(b->loc, int(x), int(y), int(z), int(w)); break;
396  }
397  }
398  void set(const vec &v, float w = 0) { setf(v.x, v.y, v.z, w); }
399  void set(const vec2 &v, float z = 0, float w = 0) { setf(v.x, v.y, z, w); }
400  void set(const vec4 &v) { setf(v.x, v.y, v.z, v.w); }
401  void set(const plane &p) { setf(p.x, p.y, p.z, p.offset); }
402  void setv(const float *f, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform1fv_(b->loc, n, f); }
403  void setv(const vec *v, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform3fv_(b->loc, n, v->v); }
404  void setv(const vec2 *v, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform2fv_(b->loc, n, v->v); }
405  void setv(const vec4 *v, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform4fv_(b->loc, n, v->v); }
406  void setv(const plane *p, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform4fv_(b->loc, n, p->v); }
407  void setv(const matrix2 *m, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniformMatrix2fv_(b->loc, n, GL_FALSE, m->a.v); }
408  void setv(const matrix3 *m, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniformMatrix3fv_(b->loc, n, GL_FALSE, m->a.v); }
409  void setv(const matrix4 *m, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniformMatrix4fv_(b->loc, n, GL_FALSE, m->a.v); }
410  void set(const matrix2 &m) { setv(&m); }
411  void set(const matrix3 &m) { setv(&m); }
412  void set(const matrix4 &m) { setv(&m); }
413 
414  template<class T>
415  void sett(T x, T y, T z, T w)
416  {
418  if(b) switch(b->format)
419  {
420  case GL_FLOAT: glUniform1f_(b->loc, x); break;
421  case GL_FLOAT_VEC2: glUniform2f_(b->loc, x, y); break;
422  case GL_FLOAT_VEC3: glUniform3f_(b->loc, x, y, z); break;
423  case GL_FLOAT_VEC4: glUniform4f_(b->loc, x, y, z, w); break;
424  case GL_BOOL:
425  case GL_INT: glUniform1i_(b->loc, x); break;
426  case GL_BOOL_VEC2:
427  case GL_INT_VEC2: glUniform2i_(b->loc, x, y); break;
428  case GL_BOOL_VEC3:
429  case GL_INT_VEC3: glUniform3i_(b->loc, x, y, z); break;
430  case GL_BOOL_VEC4:
431  case GL_INT_VEC4: glUniform4i_(b->loc, x, y, z, w); break;
432  }
433  }
434  void seti(int x = 0, int y = 0, int z = 0, int w = 0) { sett<int>(x, y, z, w); }
435  void set(const ivec &v, int w = 0) { seti(v.x, v.y, v.z, w); }
436  void set(const ivec2 &v, int z = 0, int w = 0) { seti(v.x, v.y, z, w); }
437  void set(const ivec4 &v) { seti(v.x, v.y, v.z, v.w); }
438  void setv(const int *i, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform1iv_(b->loc, n, i); }
439  void setv(const ivec *v, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform3iv_(b->loc, n, v->v); }
440  void setv(const ivec2 *v, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform2iv_(b->loc, n, v->v); }
441  void setv(const ivec4 *v, int n = 1) { ShaderParamBinding *b = resolve(); if(b) glUniform4iv_(b->loc, n, v->v); }
442 };
443 
444 #define LOCALPARAM(name, vals) do { static LocalShaderParam param( #name ); param.set(vals); } while(0)
445 #define LOCALPARAMF(name, ...) do { static LocalShaderParam param( #name ); param.setf(__VA_ARGS__); } while(0)
446 #define LOCALPARAMI(name, ...) do { static LocalShaderParam param( #name ); param.seti(__VA_ARGS__); } while(0)
447 #define LOCALPARAMV(name, vals, num) do { static LocalShaderParam param( #name ); param.setv(vals, num); } while(0)
448 #define GLOBALPARAM(name, vals) do { static GlobalShaderParam param( #name ); param.set(vals); } while(0)
449 #define GLOBALPARAMF(name, ...) do { static GlobalShaderParam param( #name ); param.setf(__VA_ARGS__); } while(0)
450 #define GLOBALPARAMI(name, ...) do { static GlobalShaderParam param( #name ); param.seti(__VA_ARGS__); } while(0)
451 #define GLOBALPARAMV(name, vals, num) do { static GlobalShaderParam param( #name ); param.setv(vals, num); } while(0)
452 
453 #define SETSHADER(name, ...) \
454  do { \
455  static Shader *name##shader = NULL; \
456  if(!name##shader) name##shader = lookupshaderbyname(#name); \
457  name##shader->set(__VA_ARGS__); \
458  } while(0)
459 #define SETVARIANT(name, ...) \
460  do { \
461  static Shader *name##shader = NULL; \
462  if(!name##shader) name##shader = lookupshaderbyname(#name); \
463  name##shader->setvariant(__VA_ARGS__); \
464  } while(0)
465 
468 
469 extern Shader *lookupshaderbyname(const char *name);
470 extern Shader *useshaderbyname(const char *name);
471 extern Shader *generateshader(const char *name, const char *cmd, ...);
472 extern void resetslotshader();
473 extern void setslotshader(Slot &s);
474 extern void linkslotshader(Slot &s, bool load = true);
475 extern void linkvslotshader(VSlot &s, bool load = true);
476 extern void linkslotshaders();
477 extern const char *getshaderparamname(const char *name, bool insert = true);
478 
479 #define MAXDYNLIGHTS 5
480 #define DYNLIGHTBITS 6
481 #define DYNLIGHTMASK ((1<<DYNLIGHTBITS)-1)
482 
483 #define MAXBLURRADIUS 7
484 
485 extern void setupblurkernel(int radius, float sigma, float *weights, float *offsets);
486 extern void setblurshader(int pass, int size, int radius, float *weights, float *offsets);
487 
488 // TODO
489 extern Slot dummyslot;
490 extern VSlot dummyvslot;
491 
492 extern void loadshaders();
493 extern void renderpostfx();
const char * name
Definition: shader.hpp:301
PFNGLUNIFORM3FPROC glUniform3f_
Definition: rendergl.cpp:155
#define MAXVARIANTROWS
Definition: shader.hpp:120
int loc
Definition: shader.hpp:46
vector< uchar > localparamremap
Definition: shader.hpp:152
LocalShaderParamState * resolve()
Definition: shader.hpp:365
const char * name
Definition: shader.hpp:129
Definition: shader.hpp:299
Definition: shader.hpp:127
void setvariant(int col, int row, Slot &slot, VSlot &vslot)
Definition: shader.hpp:265
typedef GLenum(APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC)(GLenum target)
bool invalid() const
Definition: shader.hpp:190
vector< GlobalShaderParamUse > globalparams
Definition: shader.hpp:150
PFNGLUNIFORM2IVPROC glUniform2iv_
Definition: rendergl.cpp:166
void setv(const int *i, int n=1)
Definition: shader.hpp:438
Definition: shader.hpp:112
vec2 a
Definition: geom.hpp:1889
GLuint program
Definition: shader.hpp:148
unsigned int uint
Definition: cube_types.hpp:9
void setv(const vec *v, int n=1)
Definition: shader.hpp:403
void setvariant_(int col, int row, Shader *fallbackshader)
Definition: shader.hpp:229
const char * name
Definition: shader.hpp:360
void setv(const matrix2 *m, int n=1)
Definition: shader.hpp:407
T * reserve(int n=1)
Definition: shader.hpp:355
void set(Slot &slot, VSlot &vslot)
Definition: shader.hpp:285
void allocparams(Slot *slot=nullptr)
Definition: shader.cpp:330
A virtual Slot.
Definition: slot.hpp:37
SlotShaderParamState(const SlotShaderParam &p)
Definition: shader.hpp:98
void changed()
Definition: shader.hpp:37
int type
Definition: shader.hpp:147
void flush()
Definition: shader.hpp:56
char * vsstr
Definition: shader.hpp:146
float offset
Definition: geom.hpp:1123
void set(const ivec4 &v)
Definition: shader.hpp:437
PFNGLUNIFORM3IVPROC glUniform3iv_
Definition: rendergl.cpp:167
GlobalShaderParamState * getglobalparam(const char *name)
Definition: shader.cpp:244
PFNGLUNIFORM2IPROC glUniform2i_
Definition: rendergl.cpp:162
void set(const matrix2 &m)
Definition: shader.hpp:410
Definition: shader.hpp:116
void set(const matrix3 &m)
Definition: shader.hpp:327
void setv(const plane *p, int n=1)
Definition: shader.hpp:406
void setv(const vec2 *v, int n=1)
Definition: shader.hpp:404
2-dimensional float vectors
Definition: geom.hpp:38
void set(const vec2 &v, float z=0, float w=0)
Definition: shader.hpp:323
Shader * detailshader
Definition: shader.hpp:153
void setv(const ivec *v, int n=1)
Definition: shader.hpp:439
void set_()
Definition: shader.hpp:273
SharedVar< int > maxfsuniforms
UniformLoc(const char *name=nullptr, const char *blockname=nullptr, int binding=-1, int stride=-1)
Definition: shader.hpp:132
Definition: shader.hpp:86
PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv_
Definition: rendergl.cpp:170
void setv(const ivec2 *v, int n=1)
Definition: shader.hpp:440
const char * name
Definition: shader.hpp:83
void set(const plane &p)
Definition: shader.hpp:401
float val[4]
Definition: shader.hpp:90
Definition: shader.hpp:93
Definition: shader.hpp:113
Shader * foggednotextureshader
Definition: shader.cpp:33
GlobalShaderParamState * param
Definition: shader.hpp:302
PFNGLUNIFORM2FPROC glUniform2f_
Definition: rendergl.cpp:154
Shader * reuseps
Definition: shader.hpp:157
int binding
Definition: shader.hpp:130
void set(const ivec4 &v)
Definition: shader.hpp:343
void seti(int x=0, int y=0, int z=0, int w=0)
Definition: shader.hpp:333
void linkslotshaders()
Definition: slot.cpp:733
void seti(int x=0, int y=0, int z=0, int w=0)
Definition: shader.hpp:434
Shader()
Definition: shader.hpp:162
void linkvslotshader(VSlot &s, bool load=true)
Definition: shader.cpp:1172
const char * getshaderparamname(const char *name, bool insert=true)
Definition: shader.cpp:1216
Shader * variantshader
Definition: shader.hpp:153
vector< LocalShaderParamState > localparams
Definition: shader.hpp:151
void fixdetailshader(bool force=true, bool recurse=true)
Definition: shader.cpp:1031
PFNGLUNIFORM4IVPROC glUniform4iv_
Definition: rendergl.cpp:168
Definition: geom.hpp:668
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv_
Definition: rendergl.cpp:171
void set(const matrix3 &m)
Definition: shader.hpp:411
void setvariant(int col, int row, Shader *fallbackshader)
Definition: shader.hpp:243
Shader * getvariant(int col, int row) const
Definition: shader.hpp:204
void resetslotshader()
Definition: shader.cpp:1126
static bool isnull(const Shader *s)
Definition: shader.hpp:194
void set(const matrix2 &m)
Definition: shader.hpp:326
PFNGLUNIFORMMATRIX2FVPROC glUniformMatrix2fv_
Definition: rendergl.cpp:169
void setf(float x=0, float y=0, float z=0, float w=0)
Definition: shader.hpp:314
int loc
Definition: shader.hpp:130
int numvariants(int row) const
Definition: shader.hpp:198
int offset
Definition: shader.hpp:130
Definition: shader.hpp:358
void set(const vec &v, float w=0)
Definition: shader.hpp:322
ICOMMAND * f(float *a, float *b), floatret(*a **b)
Definition: shader.hpp:111
4-dimensional float vector all methods stay basicly the same but with an extra dimension ...
Definition: geom.hpp:343
void setf(float x=0, float y=0, float z=0, float w=0)
Definition: shader.hpp:379
bool inrange(size_t i) const
safety check: tests if index i exists in this vector
Definition: cube_vector.hpp:123
vec4 a
Definition: geom.hpp:1574
void setblurshader(int pass, int size, int radius, float *weights, float *offsets)
Definition: shader.cpp:1489
void setv(const vec4 *v, int n=1)
Definition: shader.hpp:405
typedef GLuint(APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC)(GLuint program
unsigned short ushort
Definition: cube_types.hpp:8
const void * owner
Definition: shader.hpp:160
char * defer
Definition: shader.hpp:146
void setvariant(int col, int row)
Definition: shader.hpp:250
else loopi(numargs)
Definition: command.cpp:3019
Shader * lookupshaderbyname(const char *name)
Definition: shader.cpp:73
~Shader()
Definition: shader.hpp:167
static Shader * lastshader
Definition: shader.hpp:144
Shader * textureshader
Definition: shader.cpp:33
bool standard
Definition: shader.hpp:156
PFNGLUNIFORM1FPROC glUniform1f_
Definition: rendergl.cpp:153
PFNGLUNIFORM3IPROC glUniform3i_
Definition: rendergl.cpp:163
int size
Definition: shader.hpp:46
#define MAXSHADERDETAIL
Definition: shader.hpp:119
T & insert(int i, const T &e)
insertion functions
Definition: cube_vector.hpp:310
void set(const ivec2 &v, int z=0, int w=0)
Definition: shader.hpp:342
PFNGLUNIFORM2FVPROC glUniform2fv_
Definition: rendergl.cpp:158
PFNGLUNIFORM1FVPROC glUniform1fv_
Definition: rendergl.cpp:157
Shader * fastshader[MAXSHADERDETAIL]
Definition: shader.hpp:153
bool hasoption(int row)
Definition: shader.hpp:211
void start(const char *filename, int videofps, int videow, int videoh, bool sound)
Definition: movie.cpp:975
void setv(const T *v, int n=1)
Definition: shader.hpp:331
ushort * variantrows
Definition: shader.hpp:155
PFNGLUNIFORM1IPROC glUniform1i_
Definition: rendergl.cpp:161
void bindprograms()
Definition: shader.cpp:487
vector with 3 floats and some useful methods.
Definition: geom.hpp:110
#define DELETEA(p)
Delete Array, Wrapper around delete[], sets pointer to NULL afterwards(!).
Definition: cube_tools.hpp:31
Shader * nocolorshader
Definition: shader.cpp:33
void addvariant(int row, Shader *s)
Definition: shader.hpp:221
void set(const vec &v, float w=0)
Definition: shader.hpp:398
VSlot dummyvslot
vector< SlotShaderParamState > defaultparams
Definition: shader.hpp:149
Shader * stdworldshader
Definition: shader.cpp:33
void setv(const float *f, int n=1)
Definition: shader.hpp:402
GLenum format
Definition: shader.hpp:47
int loc
Definition: shader.hpp:138
Definition: shader.hpp:21
bool compile()
Definition: shader.cpp:496
Definition: geom.hpp:1887
const T & min(const inexor::rpc::SharedVar< T > &a, const T &b)
Definition: SharedVar.hpp:210
Slot dummyslot
Definition: slot.cpp:42
void cleanup(bool invalid=false)
Definition: shader.cpp:506
vector< UniformLoc > uniformlocs
Definition: shader.hpp:158
SlotShaderParamState()
Definition: shader.hpp:97
void setvariant(int col, int row, Slot &slot, VSlot &vslot, Shader *fallbackshader)
Definition: shader.hpp:257
Definition: geom.hpp:1572
vector< AttribLoc > attriblocs
Definition: shader.hpp:159
void setv(const ivec4 *v, int n=1)
Definition: shader.hpp:441
2 dimensional integer vector.
Definition: geom.hpp:1304
void renderpostfx()
Definition: shader.cpp:1300
Shader * generateshader(const char *name, const char *cmd,...)
Definition: shader.cpp:79
char * psstr
Definition: shader.hpp:146
vec a
Definition: geom.hpp:670
PFNGLUNIFORM4FVPROC glUniform4fv_
Definition: rendergl.cpp:160
Shader * notextureshader
Definition: shader.cpp:33
int version
Definition: shader.hpp:31
void setv(const matrix3 *m, int n=1)
Definition: shader.hpp:408
PFNGLUNIFORM4FPROC glUniform4f_
Definition: rendergl.cpp:156
int length() const
return size of used memory
Definition: cube_vector.hpp:146
void setslotparams(Slot &slot)
Definition: shader.cpp:464
Definition: shader.hpp:115
void force()
Definition: shader.cpp:987
void setu(uint x=0, uint y=0, uint z=0, uint w=0)
Definition: shader.hpp:345
void setv(const matrix4 *m, int n=1)
Definition: shader.hpp:409
Definition: shader.hpp:110
void * data
Definition: shader.hpp:131
Definition: shader.hpp:142
void sett(T x, T y, T z, T w)
Definition: shader.hpp:415
int size
Definition: shader.hpp:130
unsigned char uchar
Basic type definitions.
Definition: cube_types.hpp:7
const char * name
Definition: shader.hpp:88
void set(const vec4 &v)
Definition: shader.hpp:324
bool deferred() const
Definition: shader.hpp:191
void set(const ivec &v, int w=0)
Definition: shader.hpp:435
GlobalShaderParamState * resolve()
Definition: shader.hpp:306
int end()
Definition: glemu.cpp:256
Shader * nullshader
Definition: shader.cpp:33
GLuint GLuint GLintptr GLsizeiptr size
Definition: glexts.hpp:412
void set(const vec2 &v, float z=0, float w=0)
Definition: shader.hpp:399
GLintptr offset
Definition: glexts.hpp:354
4 dimensional integer vector.
Definition: geom.hpp:1365
Shader * reusevs
Definition: shader.hpp:157
void set(const matrix4 &m)
Definition: shader.hpp:412
int version
Definition: shader.hpp:130
SharedVar< int > maxvsuniforms
Definition: shader.hpp:50
bool used
Definition: shader.hpp:156
Definition: slot.hpp:81
char * name
Definition: shader.hpp:146
bool loaded() const
Definition: shader.hpp:192
int getlocalparam(const char *name)
Definition: shader.cpp:221
void set(const matrix4 &m)
Definition: shader.hpp:328
PFNGLUNIFORM1IVPROC glUniform1iv_
Definition: rendergl.cpp:165
Definition: shader.hpp:135
SharedVar wrapper for primitive/immutable objects.
Definition: SharedVar.hpp:55
GLuint vsobj
Definition: shader.hpp:148
LocalShaderParam(const char *name)
Definition: shader.hpp:363
void flushparams(Slot *slot=nullptr)
Definition: shader.hpp:182
const char * blockname
Definition: shader.hpp:129
GlobalShaderParam(const char *name)
Definition: shader.hpp:304
void linkslotshader(Slot &s, bool load=true)
Definition: shader.cpp:1163
Shader * hudshader
Definition: shader.cpp:33
Shader * hudnotextureshader
Definition: shader.cpp:33
void setupblurkernel(int radius, float sigma, float *weights, float *offsets)
Definition: shader.cpp:1466
const char * name
Definition: shader.hpp:137
const char * name
Definition: shader.hpp:23
static int nextversion
Definition: shader.hpp:33
vector< Shader * > variants
Definition: shader.hpp:154
void set(const plane &p)
Definition: shader.hpp:325
int stride
Definition: shader.hpp:130
float val[4]
Definition: shader.hpp:95
mathmatics for vectors, matrices, quaterions and more
PFNGLUNIFORM3FVPROC glUniform3fv_
Definition: rendergl.cpp:159
static int uniformlocversion()
Definition: shader.cpp:1020
void set(const ivec &v, int w=0)
Definition: shader.hpp:341
Definition: geom.hpp:1121
Shader * foggedshader
Definition: shader.cpp:33
SharedVar< int > reservevpparams
3-dimensional INTEGER vectors
Definition: geom.hpp:1226
int loc
Definition: shader.hpp:361
Definition: shader.hpp:81
#define loopv(v)
Definition: cube_loops.hpp:21
void setslotshader(Slot &s)
Definition: shader.cpp:1132
Shader * altshader
Definition: shader.hpp:153
void loadshaders()
Definition: shader.cpp:48
void set()
Definition: shader.hpp:278
int loc
Definition: shader.hpp:89
GLuint psobj
Definition: shader.hpp:148
void set(const ivec2 &v, int z=0, int w=0)
Definition: shader.hpp:436
GlobalShaderParamState * param
Definition: shader.hpp:53
bool isnull() const
Definition: shader.hpp:196
void resetversions()
Definition: shader.cpp:376
void set(const vec4 &v)
Definition: shader.hpp:400
Definition: shader.hpp:44
PFNGLUNIFORM4IPROC glUniform4i_
Definition: rendergl.cpp:164
SharedVar< int > shaderdetail
AttribLoc(const char *name=nullptr, int loc=-1)
Definition: shader.hpp:139
bool forced
Definition: shader.hpp:156
Shader * useshaderbyname(const char *name)
Definition: shader.cpp:1051
int version
Definition: shader.hpp:54