GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Shader.hh
Go to the documentation of this file.
1//
2// Copyright (C) 2009 Tero Pulkkinen
3// Released under LGPL License.
4//
5// This file is part of Polygon.
6//
7// Polygon is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Polygon is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Library General Public License
18// along with Polygon. If not, see <http://www.gnu.org/licenses/>.
19//
20
21
22#ifndef SHADER_HH
23#define SHADER_HH
24#include <string>
25#include <vector>
26#include <sstream>
27#include "VectorTools.hh"
28#include <algorithm>
29#include <unordered_map>
30#include "GraphI.hh"
31
32struct Attrib
33{
34 int loc;
35 int id;
36 bool is_int; // true = int, false = float
37};
38
39
41{
42public:
43 virtual std::string Name() const=0;
44 virtual int Count() const=0;
45 virtual std::string Source(int i) const=0;
46};
47
48
50{
51public:
52 SingletonShaderSpec(std::string s, std::string name) : s(s), name(name) { }
53 std::string Name() const { return name; }
54 int Count() const { return 1; }
55 std::string Source(int i) const { return s; }
56private:
57 std::string s;
58 std::string name;
59};
60
61struct ShaderPriv;
62class Shader
63{
64public:
65 Shader(ShaderSpec &spec, bool vertex, bool geom);
66 void print_log() const;
67 ~Shader();
68public:
70
71};
72
73struct ProgramPriv;
75{
76public:
77 Program();
78 Program(const Program &)=delete;
79 Program &operator=(const Program &)=delete;
80 void push_back(const Shader &shader);
81 void detach(const Shader &shader);
82 void link();
83 void use();
84 void unuse();
85 void print_log();
86 ~Program();
87public: // geometry shader specific
88 void GeomTypes(int input, int output); // 0 = points, 1 = lines, 2 = triangles
89 void GeomOutputVertices(int i);
90public: // uniform variable
91 int get_loc(std::string name);
92 void set_var(const char *name, float val);
93 void set_var(int name, float val);
94 void set_var(const char *name, float val1, float val2);
95 void set_var(const char *name, const Point &p);
96 void set_var(const char *name, const Vector &p);
97 void set_var(const char *name, const Color &c);
98 void set_var(const char *name, float val1, float val2, float val3, float val4);
99 void set_var(int name, float val1, float val2, float val3, float val4);
100 void set_var(const char *name, Matrix m);
101 void set_var(const char *name, float *array, int count);
102 void set_var(const char *name, int *array, int count);
103 void set_var(const char *name, int val);
104 void set_var_matrix2(const char *name, const std::vector<float> &v, int start);
105 void set_var_matrix(const char *name, const std::vector<float> &v);
106 void set_var(const char *name, const std::vector<Point> &v);
107 Matrix get_matrix_var(const std::string &name);
108 void bind_attrib(int num, std::string name);
109 void bind_frag(int num, std::string name);
110 Attrib find_attr(const std::string &attr_name, int id);
111 Attrib find_attr_int(const std::string &attr_name, int id);
112 void attr_loc(std::string s, int index);
113 uint32_t unique_id(const char *name);
114 void print_locs();
115 void clean_map();
116public:
118 std::unordered_map<uint32_t, int> locs;
119 std::unordered_map<Low_GLint, Matrix> cache;
120std::unordered_map<Low_GLint,float> g_setvar_cache;
121 std::unordered_map<Low_GLint,int> g_intvar_cache;
122};
123
125{
126public:
127 std::string Name() const { return "testshader"; }
128 int Count() const { return 1; }
129 std::string Source(int i) const { return
130 "void main(void)\n"
131 "{\n"
132 " gl_position = ftransform();\n"
133 "}\n";
134 }
135};
137{
138public:
139 std::string Name() const { return "testfshader"; }
140 int Count() const { return 1; }
141 std::string Source(int i) const { return
142 "void main(void)\n"
143 "{\n"
144 " gl_FragColor=vec4(1.0,0.0,0.0,1.0);\n"
145 "}\n";
146 }
147};
148
149
151{
152public:
153 virtual std::string VertexShader() const=0;
154 virtual std::string FragmentShader() const=0;
155};
156
157
159{
160public:
161 // whole shader
162 virtual std::string VertexShader() const { return VertexGlobals() + "void main() { \n" + VertexMain()+"}\n"; }
163 virtual std::string FragmentShader() const { return FragmentGlobals()+"void main() {\n"+FragmentMain()+"}\n";}
164
165 // Vertex shader
166 virtual std::string VertexGlobals() const { return ""; }
167 virtual std::string VertexMain() const { return VertexDecls()+VertexCode()+VertexAssigns(); }
168
169 // Fragment shader
170 virtual std::string FragmentGlobals() const { return ""; }
171 virtual std::string FragmentMain() const { return FragmentDecls()+FragmentCode()+FragmentAssigns(); }
172
173 // Vertex shader parts
174 virtual std::string VertexDecls() const { return ""; }
175 virtual std::string VertexCode() const { return ""; }
176 virtual std::string VertexAssigns() const { return "gl_Position = " + VertexPosition() + ";"; }
177
178 // Fragment shader parts
179 virtual std::string FragmentDecls() const { return ""; }
180 virtual std::string FragmentCode() const { return ""; }
181 virtual std::string FragmentAssigns() const { return "gl_FragColor = " + FragmentColor() + ";"; }
182
183 // Vertex shader
184 virtual std::string VertexPosition() const { return "ftransform()"; }
185
186 // Fragment shader
187 virtual std::string FragmentColor() const { return "vec4(1.0,0.0,0.0,1.0)"; }
188};
189
191{
192public:
193 VertexShader(ShaderString &shader) : shader(shader) { }
194 std::string Name() const { return "Shader"; }
195 int Count() const { return 1; }
196 std::string Source(int i) const
197 {
198 std::cout << shader.VertexShader() << std::endl;
199 return shader.VertexShader();
200 }
201private:
202 ShaderString &shader;
203};
204
206{
207public:
208 FragmentShader(ShaderString &shader) : shader(shader) { }
209 std::string Name() const { return "Shader"; }
210 int Count() const { return 1; }
211 std::string Source(int i) const
212 {
213 std::cout << shader.FragmentShader() << std::endl;
214 return shader.FragmentShader();
215 }
216private:
217 ShaderString &shader;
218};
219
221{
222public:
224 std::string Name() const { return "Array"; }
225 int Count() const { return shaders.size(); }
226 std::string Source(int i) const
227 {
228 return shaders[i];
229 }
230 void push_back(std::string s) { shaders.push_back(s); }
231private:
232 std::vector<std::string> shaders;
233};
234
236{
237public:
238 virtual void SetParameters(Program &p) const=0;
239};
241{
242public:
243 virtual void SetAttribs(Program &p) const=0;
244};
245
247{
248public:
249 CombineParameters() : p1(0), p2(0) { }
250 CombineParameters(ShaderParameters &p1_, ShaderParameters &p2_) : p1(&p1_), p2(&p2_) { }
251 void SetParameters(Program &p) const
252 {
253 p1->SetParameters(p);
254 p2->SetParameters(p);
255 }
256 void SetValues(ShaderParameters *p1_, ShaderParameters *p2_) { p1 = p1_; p2 = p2_; }
257private:
258 ShaderParameters *p1, *p2;
259};
260
262{
263public:
264 ShaderPair(ShaderString &shader) : /*shader(shader),*/ vs(shader), fs(shader), vertex(vs, true, false), fragment(fs,false, false)
265 {
266 prog.push_back(vertex);
267 prog.push_back(fragment);
268 prog.link();
269 }
270 void use() { prog.use(); }
272 {
273 p.SetParameters(prog);
274 }
276 {
277 p.SetAttribs(prog);
278 }
279 void unuse() { prog.unuse(); }
280 int get_loc(std::string name) { return prog.get_loc(name); }
281private:
282 //ShaderString &shader;
283 Program prog;
284 VertexShader vs;
286 Shader vertex, fragment;
287};
288
290{
291public:
292 PhongParameters(Point viewer, Point light, Color light_color, Color speccolor) : viewer(viewer), light(light), light_color(light_color), speccolor(speccolor) { }
293 virtual void SetParameters(Program &p) const
294 {
295 Point halfway = HalfWay(viewer, light);
296 p.set_var("halfway", halfway);
297 p.set_var("light", light);
298 p.set_var("lightcolor", light_color);
299 p.set_var("speccolor", speccolor);
300 }
301
302 Point HalfWay(Point viewer, Point light) const
303 {
304 Vector p = Vector(viewer)+Vector(light);
305 Vector hw = p/p.Dist();
306 return Point(hw);
307 }
308private:
309 Point viewer, light;
310 Color light_color, speccolor;
311};
312
313//
314// Shader representation
315//
316
326
328{
329public:
330 virtual std::string VertexGlobals() const=0;
331 virtual std::string VertexCodeGen() const=0;
332 virtual std::string FragmentGlobals() const=0;
333 virtual std::string FragmentCodeGen() const=0;
334 virtual void Provides(std::vector<int> &vec) const { }
335 virtual void Config(const std::vector<int> &env) { }
336};
337
338
340{
341public:
342 GouraudPiece() : fragnum(0) { }
343 void Provides(std::vector<int> &vec) const
344 {
345 for(unsigned int i=0;i<vec.size();i++)
346 {
347 if (vec[i]==ReqFragColorRGB) fragnum++;
348 }
349
350 vec.push_back(ReqFragColorRGB);
351 }
352 virtual std::string VertexGlobals() const
353 {
354 return
355 "uniform vec3 halfway;\n"
356 "uniform vec3 light;\n"
357 "uniform vec3 lightcolor;\n"
358 "uniform vec3 speccolor;\n";
359 }
360 virtual std::string VertexCodeGen() const
361 {
362 return
363 "vec3 n = normalize(gl_Normal);\n"
364 "float col = dot(n, halfway);\n"
365 "float col2 = dot(n, light);\n"
366 "col = col*col;\n"
367 "if (col < 0.0) col = 0.0;\n"
368 "if (col > 1.0) col = 1.0;\n"
369 "if (col2 < 0.0) col2 = 0.0;\n"
370 "if (col2 > 1.0) col2 = 1.0;\n"
371 "float r = col*lightcolor.r+col2*speccolor.r;\n"
372 "float g = col*lightcolor.g+col2*speccolor.g;\n"
373 "float b = col*lightcolor.b+col2*speccolor.b;\n"
374 "if (r > 1.0) r=1.0;\n"
375 "if (g > 1.0) g=1.0;\n"
376 "if (b > 1.0) b=1.0;\n"
377 "vec3 vv = vec3(r,g,b);\n"
378 "gl_FrontColor.rgb = vv;\n"
379 "gl_BackColor.rgb = vv;\n";
380 }
381 virtual std::string FragmentGlobals() const
382 {
383 return "";
384 }
385 virtual std::string FragmentCodeGen() const
386 {
387 std::stringstream s;
388 s << fragnum;
389 return
390 std::string("vec4 FragColor") + s.str() + ";\n"
391 "FragColor" + s.str() +".rgb=gl_Color.rgb;\n";
392
393 }
394private:
395 mutable int fragnum;
396};
397
399{
400public:
401 NormalParameters(Point p, float mix_rate) : p(p), mix_rate(mix_rate) { }
402 virtual void SetParameters(Program &pp) const
403 {
404 pp.set_var("normal_center", p);
405 pp.set_var("mix_rate", mix_rate);
406 }
407private:
408 Point p;
409 float mix_rate;
410};
412{
413public:
414 void Provides(std::vector<int> &vec) const
415 {
416 vec.push_back(ReqNormal);
417 }
418 virtual std::string VertexGlobals() const
419 {
420 return
421 "uniform vec3 normal_center;\n"
422 "uniform float mix_rate;\n"
423 "varying vec3 normal;\n";
424 }
425 virtual std::string VertexCodeGen() const
426 {
427 return "vec3 vl = gl_NormalMatrix * gl_Normal;\n"
428 "vec3 vk = (gl_ModelViewMatrix*gl_Vertex).xyz-normal_center;\n"
429 "vl = normalize(vl);\n"
430 "vk = normalize(vk);\n"
431 "normal=mix(vk, vl, mix_rate);\n";
432 }
433 virtual std::string FragmentGlobals() const
434 {
435 return "";
436 }
437 virtual std::string FragmentCodeGen() const
438 {
439 return "";
440 }
441};
442
444{
445public:
446 PhongPiece() : normal(true), fragnum(0) { }
447 virtual void Config(const std::vector<int> &env)
448 {
449 for(std::vector<int>::const_iterator i=env.begin();i!=env.end();i++)
450 {
451 if (*i==ReqNormal) normal = false;
452 }
453 }
454 void Provides(std::vector<int> &vec) const
455 {
456 for(unsigned int i=0;i<vec.size();i++)
457 {
458 if (vec[i]==ReqFragColorRGB) fragnum++;
459 }
460 vec.push_back(ReqFragColorRGB);
461 }
462
463 virtual std::string VertexGlobals() const
464 {
465 if (normal)
466 return "varying vec3 normal;\n";
467 else
468 return "";
469 }
470 virtual std::string VertexCodeGen() const
471 {
472 if (normal)
473 return "normal=gl_NormalMatrix * gl_Normal;\n";
474 else
475 return "";
476 }
477 virtual std::string FragmentGlobals() const
478 {
479 return
480 "varying vec3 normal;\n"
481 "uniform vec3 halfway;\n"
482 "uniform vec3 light;\n"
483 "uniform vec3 lightcolor;\n"
484 "uniform vec3 speccolor;\n";
485 }
486 virtual std::string FragmentCodeGen() const
487 {
488 std::stringstream s;
489 s << fragnum;
490 return
491 std::string(
492 "vec3 n = normalize(normal);\n"
493 "float col = dot(n, halfway);\n"
494 "float col2 = dot(n, light);\n"
495 "col = col*col;\n"
496 "col = col*col;\n"
497 //"col = col*col;\n"
498 //"col = col*col;\n"
499 //"col = col*col;\n"
500 //"col = col*col;\n"
501 "if (col < 0.0) col = 0.0;\n"
502 "if (col > 1.0) col = 1.0;\n"
503 "if (col2 < 0.0) col2 = 0.0;\n"
504 "if (col2 > 1.0) col2 = 1.0;\n"
505 "float r = col*lightcolor.r+col2*speccolor.r;\n"
506 "float g = col*lightcolor.g+col2*speccolor.g;\n"
507 "float b = col*lightcolor.b+col2*speccolor.b;\n"
508 "if (r > 1.0) r=1.0;\n"
509 "if (g > 1.0) g=1.0;\n"
510 "if (b > 1.0) b=1.0;\n"
511 "vec4 FragColor") + s.str() + ";\n"
512 "FragColor" + s.str() + ".r = r;\n"
513 "FragColor" + s.str() + ".g = g;\n"
514 "FragColor" + s.str() + ".b = b;\n";
515 }
516private:
517 bool normal;
518 mutable int fragnum;
519};
521{
522public:
523 virtual std::string VertexGlobals() const
524 {
525 return "";
526 }
527 virtual std::string VertexCodeGen() const
528 {
529 return
530 "gl_Position = ftransform();\n";
531 }
532 virtual std::string FragmentGlobals() const
533 {
534 return "";
535 }
536 virtual std::string FragmentCodeGen() const
537 {
538 return "";
539 }
540};
541
543{
544public:
545 virtual std::string VertexGlobals() const
546 {
547 return "";
548 }
549 virtual std::string VertexCodeGen() const
550 {
551 return
552 "";
553 }
554 virtual std::string FragmentGlobals() const
555 {
556 return "";
557 }
558 virtual std::string FragmentCodeGen() const
559 {
560 return
561 "gl_FragColor.r=1.0;\n"
562 "gl_FragColor.g=0.0;\n"
563 "gl_FragColor.b=0.0;\n";
564 }
565};
566
567
569{
570public:
571 virtual std::string VertexGlobals() const
572 {
573 return "";
574 }
575 virtual std::string VertexCodeGen() const
576 {
577 return
578 "";
579 }
580 virtual std::string FragmentGlobals() const
581 {
582 return "";
583 }
584 virtual std::string FragmentCodeGen() const
585 {
586 return
587 "gl_FragColor.a=1.0;\n";
588 }
589};
590
591
592
593
595{
596public:
597 virtual void Provides(std::vector<int> &vec) const
598 {
599 vec.push_back(ReqFragColorA);
600 }
601 virtual void Config(const std::vector<int> &env) { }
602
603 virtual std::string VertexGlobals() const
604 {
605 return "varying float dis;\n"
606 "attribute float centerx;\n"
607 "attribute float centery;\n"
608 "attribute float centerz;\n";
609 }
610 virtual std::string VertexCodeGen() const
611 {
612 return
613 "vec3 v = vec3(centerx,centery,centerz);\n"
614 "dis = v.x*v.x+v.y*v.y+v.z*v.z;\n";
615 }
616 virtual std::string FragmentGlobals() const
617 {
618 return
619 "varying float dis;\n"
620 "uniform float distance;\n";
621 }
622 virtual std::string FragmentCodeGen() const
623 {
624 return //"if (dis>distance) discard;\n"
625 "gl_FragColor.a = dis-distance;\n";
626 }
627};
628
630{
631public:
632 DiscardParameters(float distance) : distance(distance) { }
633 void SetParameters(Program &p) const
634 {
635 p.set_var("distance", distance);
636 }
637private:
638 float distance;
639};
640
642{
643public:
644 DiscardAttributes(int centerx, int centery, int centerz) : centerx(centerx), centery(centery), centerz(centerz) { }
645 void SetAttribs(Program &p) const
646 {
647 x = p.find_attr("centerx", centerx);
648 y = p.find_attr("centery", centery);
649 z = p.find_attr("centerz", centerz);
650 }
651 void Attr(std::vector<Attrib> &vec)
652 {
653 vec.push_back(x);
654 vec.push_back(y);
655 vec.push_back(z);
656 }
657private:
658 mutable Attrib x,y,z;
659 int centerx, centery, centerz;
660};
661
662// Does not work!!
664{
665public:
666 virtual void Provides(std::vector<int> &vec) const
667 {
668 vec.push_back(ReqPosition);
669 }
670
671 virtual std::string VertexGlobals() const
672 {
673 return
674 "uniform vec3 box;\n"
675 "uniform float time;\n";
676 }
677 virtual std::string VertexCodeGen() const
678 {
679 return
680 " vec3 n = vec3(0.0,0.0,0.0); //noise3(gl_Vertex+vec4(time,time,time,time));\n"
681 " vec4 vertex = gl_Vertex + vec4(box.x*n.x, box.y*n.y, box.z*n.z,0.0);\n"
682 " gl_Position = gl_ModelViewProjectionMatrix * vertex;\n";
683
684 }
685 virtual std::string FragmentGlobals() const
686 {
687 return "";
688 }
689 virtual std::string FragmentCodeGen() const
690 {
691 return "";
692 }
693};
695{
696public:
697 RandomPositionParameters(Point box, float time) : box(box), time(time) { }
698 virtual void SetParameters(Program &p) const
699 {
700 p.set_var("box", box);
701 p.set_var("time", time);
702 }
703
704private:
705 Point box;
706 float time;
707};
708#if 0
709class BlobParameters : public ShaderParameters
710{
711public:
712 BlobParameters(Point center, Point center2, float r) : center(center), center2(center2), r(r) { }
713 void set_points(Point c, Point c2, float r) { center = c; center2=c2; this->r=r; }
714 void SetParameters(Program &p) const
715 {
716 p.set_var("center1x", center.x);
717 p.set_var("center1y", center.y);
718 p.set_var("center1z", center.z);
719 p.set_var("center2x", center2.x);
720 p.set_var("center2y", center2.y);
721 p.set_var("center2z", center2.z);
722 p.set_var("radius", r);
723 }
724 virtual ~BlobParameters() { }
725private:
726 Point center, center2;
727 float r;
728};
729#endif
730
731class BlobPiece : public ShaderPiece
732{
733public:
734 virtual void Provides(std::vector<int> &vec) const
735 {
736 vec.push_back(ReqPosition);
737 }
738
739 virtual std::string VertexGlobals() const
740 {
741 return
742 "vec4 line(float t, vec4 x_0, vec4 x_1) { return x_0+(x_1-x_0)*t; }\n"
743 "float f(vec4 p, vec4 x_0, vec4 x_1, vec4 x_2) { return ((p.x-x_0.x)*(p.x-x_0.x)+(p.y-x_0.y)*(p.y-x_0.y)+(p.z-x_0.z)*(p.z-x_0.z)); }\n"
744 "float g(vec4 p, vec4 x_0, vec4 x_1, vec4 x_2) { return ((p.x-x_2.x)*(p.x-x_2.x)+(p.y-x_2.y)*(p.y-x_2.y)+(p.z-x_2.z)*(p.z-x_2.z)); }\n"
745 "float h(vec4 p, vec4 x_0, vec4 x_1, vec4 x_2, float r)\n"
746 "{\n"
747 " float fp = f(p, x_0, x_1, x_2);\n"
748 " float gp = g(p, x_0, x_1, x_2);\n"
749 " if (fp < 1.0) fp = 1.0;\n"
750 " if (gp < 1.0) gp = 1.0;\n"
751 " return 1.0/(fp)+1.0/(gp)-r;\n"
752 //"return gp; \n"
753 " }\n"
754 "float H(float tt, vec4 x_0, vec4 x_1, vec4 x_2, float r) \n"
755 " { \n"
756 " return h(line(tt, x_0, x_1), x_0, x_1, x_2, r); \n"
757 " }\n"
758 " float t_func(float t_0, float t_1, vec4 x_0, vec4 x_1, vec4 x_2, float r)\n"
759 " {\n"
760 " float t=t_0;\n"
761 " //for(;t<t_1;)\n"
762 " {\n"
763 " float Ht = H(t, x_0, x_1, x_2, r);\n"
764 " if (Ht<0.1) return t;\n"
765 " t+=Ht/20.0;\n"
766 " Ht = H(t, x_0, x_1, x_2, r);\n"
767 " if (Ht<0.1) return t;\n"
768 " t+=Ht/20.0;\n"
769 " Ht = H(t, x_0, x_1, x_2, r);\n"
770 " if (Ht<0.1) return t;\n"
771 " t+=Ht/20.0;\n"
772 " Ht = H(t, x_0, x_1, x_2, r);\n"
773 " if (Ht<0.1) return t;\n"
774 " t+=Ht/20.0;\n"
775 " }\n"
776 " return t;\n"
777 "}\n"
778 "vec4 adjustpoint(vec4 x_0, vec4 x_1, vec4 x_2, float r)\n"
779 "{\n"
780 " float tt = t_func(1.0,5.0, x_0, x_1, x_2, r);\n"
781 " return line(tt, x_0, x_1);\n"
782 //" return gl_Vertex;\n"
783 "}\n"
784 "uniform float center1x;\n"
785 "uniform float center1y;\n"
786 "uniform float center1z;\n"
787 "uniform float center2x;\n"
788 "uniform float center2y;\n"
789 "uniform float center2z;\n"
790 "uniform float radius;\n"
791 ;
792 }
793 virtual std::string VertexCodeGen() const
794 {
795 return
796 "vec4 center1 = vec4(center1x, center1y, center1z,0.0);\n"
797 "vec4 center2 = vec4(center2x, center2y, center2z,0.0);\n"
798 "vec4 vertex = gl_Vertex;\n"
799 "vertex.x += center1.x;\n"
800 "vertex.y += center1.y;\n"
801 "vertex.z += center1.z;\n"
802 "vec4 p = adjustpoint(center1,vertex, center2, radius);\n"
803 "p.x *= 40.0;\n"
804 "p.y *= 40.0;\n"
805 "p.z *= 40.0;\n"
806 "gl_Position = gl_ModelViewProjectionMatrix * p;\n";
807 }
808 virtual std::string FragmentGlobals() const
809 {
810 return "";
811 }
812 virtual std::string FragmentCodeGen() const
813 {
814 return "";
815 }
816};
818{
819public:
820 TextureParameters(int textureunit) : textureunit(textureunit) { }
821 void SetParameters(Program &p) const
822 {
823 p.set_var("tex", textureunit);
824 }
825private:
826 int textureunit;
827};
829{
830public:
831 GlobalTextureParameters(Point p, Vector x, Vector y, Vector z) : p(p), x(x), y(y), z(z) { }
832 void SetParameters(Program &pp) const
833 {
834 pp.set_var("point", p);
835 pp.set_var("x_vec", x);
836 pp.set_var("y_vec", y);
837 //pp.set_var("z_vec", z);
838 }
839private:
840 Point p;
841 Vector x;
842 Vector y;
843 Vector z;
844};
845
847{
848public:
849 virtual void Provides(std::vector<int> &vec) const
850 {
851 vec.push_back(ReqTexCoord0);
852 }
853 virtual std::string VertexGlobals() const
854 {
855 return
856 "uniform vec3 point;\n"
857 "uniform vec3 x_vec;\n"
858 "uniform vec3 y_vec;\n"
859 //"uniform vec3 z_vec;\n"
860 ;
861 }
862 virtual std::string VertexCodeGen() const
863 {
864 return
865 "vec3 c = gl_Vertex.xyz;\n"
866 "vec3 v = c - point;\n"
867 "float d1 = dot(v,x_vec);\n"
868 "float d2 = dot(v,y_vec);\n"
869 //"float d3 = dot(v,z_vec);\n"
870 "float xdist = length(x_vec);\n"
871 "float ydist = length(y_vec);\n"
872 //"float zdist = length(z_vec);\n"
873 "float d1a = d1 / xdist / xdist*512;\n"
874 "float d1b = d2 / ydist / ydist*512;\n"
875 //"float d1c = d3 / zdist / zdist*512;\n"
876 "gl_TexCoord[0] = vec4(d1a, d1b,0.0,0.0);\n";
877 }
878 virtual std::string FragmentGlobals() const
879 {
880 return "";
881 }
882 virtual std::string FragmentCodeGen() const
883 {
884 return
885 "";
886 }
887
888};
890{
891public:
892 FragColorCombinerPiece() : fragnum(0) { }
893 virtual void Config(const std::vector<int> &env)
894 {
895 for(std::vector<int>::const_iterator i=env.begin();i!=env.end();i++)
896 {
897 if (*i == ReqFragColorRGB) fragnum++;
898 }
899 }
900 virtual void Provides(std::vector<int> &vec) const
901 {
902 vec.push_back(ReqFragColorCombiner);
903 }
904 virtual std::string VertexGlobals() const
905 {
906 return "";
907 }
908 virtual std::string VertexCodeGen() const
909 {
910 return "";
911 }
912 virtual std::string FragmentGlobals() const
913 {
914 return "";
915 }
916 virtual std::string FragmentCodeGen() const
917 {
918 std::string s;
919 if (fragnum > 0)
920 {
921 s+= "vec4 f0 = FragColor0;\n";
922 }
923 for(int i=1;i<fragnum;i++)
924 {
925 std::stringstream ss;
926 ss << i;
927 std::stringstream ss1;
928 ss1 << i-1;
929 s += std::string("vec4 f") + ss.str() + " = max(f" + ss1.str() + ",FragColor" + ss.str() + ");\n";
930 }
931 std::stringstream frag;
932 frag << fragnum-1;
933 if (fragnum > 0)
934 {
935 s+=std::string("gl_FragColor.rgb = f") + frag.str() + ".rgb;\n";
936 }
937 return s;
938 }
939
940private:
941 int fragnum;
942};
943
945{
946public:
947 TexturePiece() : coord(true), fragnum(0) { }
948 virtual void Config(const std::vector<int> &env)
949 {
950 for(std::vector<int>::const_iterator i=env.begin();i!=env.end();i++)
951 {
952 if (*i==ReqTexCoord0) coord = false;
953 }
954 }
955 virtual void Provides(std::vector<int> &vec) const
956 {
957 for(unsigned int i=0;i<vec.size();i++)
958 {
959 if (vec[i]==ReqFragColorRGB) fragnum++;
960 }
961 vec.push_back(ReqFragColorRGB);
962 }
963 virtual std::string VertexGlobals() const
964 {
965 return "";
966 }
967 virtual std::string VertexCodeGen() const
968 {
969 if (coord)
970 return "gl_TexCoord[0] = gl_MultiTexCoord0;\n";
971 else
972 return "";
973 }
974 virtual std::string FragmentGlobals() const
975 {
976 return "uniform sampler2D tex;\n";
977 }
978 virtual std::string FragmentCodeGen() const
979 {
980 std::stringstream s;
981 s << fragnum;
982 return
983 std::string("vec4 color = texture2D(tex,gl_TexCoord[0].st);\n"
984 "vec4 FragColor") + s.str() + ";\n"
985 "FragColor" + s.str() + " = color;\n";
986 }
987private:
988 bool coord;
989 mutable int fragnum;
990};
992{
993public:
994 virtual void Provides(std::vector<int> &vec) const
995 {
996 vec.push_back(ReqNormal);
997 vec.push_back(ReqPosition);
998 }
999
1000 virtual std::string VertexGlobals() const
1001 {
1002 return
1003 "float Index(float xx, float yy, float time) {\n"
1004 " float m = 8.0;\n"
1005 " float n = 5.0;\n"
1006 " float lx = cos(m*3.14159*xx);\n"
1007 " float ly = cos(n*3.14159*yy);\n"
1008 " float lt = cos(8.0*time);\n"
1009 " float wave = 0.02*lx*ly*lt;\n"
1010 " float m2 = 7;\n"
1011 " float n2 = 13;\n"
1012 " // waves\n"
1013 " float lx2 = cos(m2*3.14159*xx);\n"
1014 " float ly2 = cos(n2*3.14159*yy);\n"
1015 " float lt2 = cos(18.0*time);\n"
1016 " float wave2 = 0.02*lx2*ly2*lt2;\n"
1017 ""
1018 " return wave+wave2;\n"
1019 "}\n"
1020 "uniform float time;\n"
1021 "attribute float x;\n"
1022 "attribute float y;\n"
1023 "attribute float nx_x;\n"
1024 "attribute float nx_y;\n"
1025 "attribute float nx_z;\n"
1026 "attribute float ny_x;\n"
1027 "attribute float ny_y;\n"
1028 "attribute float ny_z;\n"
1029 "varying vec3 normal;\n"
1030 ;
1031 }
1032 virtual std::string VertexCodeGen() const
1033 {
1034 return
1035 "float wave = Index(x,y,time);\n"
1036 "float wavex = Index(x+0.01,y,time);\n"
1037 "float wavey = Index(x,y+0.01,time);\n"
1038 //"float wave1 = Index(x+0.1,y,time);\n"
1039 //"float wave2 = Index(x,y+0.1,time);\n"
1040 "vec3 n = gl_NormalMatrix * gl_Normal;\n"
1041 "vec3 a = wave*n;\n"
1042 "vec3 ax = wavex*n;\n"
1043 "vec3 ay = wavey*n;\n"
1044 "vec4 v = gl_Vertex+vec4(a.x,a.y,a.z,0.0);\n"
1045 "vec3 vx = vec3(nx_x+ax.x,nx_y+ax.y,nx_z+ax.z);\n"
1046 "vec3 vy = vec3(ny_x+ay.x,ny_y+ay.y,ny_z+ay.z);\n"
1047 "vec3 dx = vx-v.xyz;\n"
1048 "vec3 dy = vy-v.xyz;\n"
1049 "normal = cross(dx,dy);\n"
1050 "gl_Position = gl_ModelViewProjectionMatrix * v;\n"
1051 //"gl_Normal = gl_Normal + vec3(wave1, wave2,0.0);\n"
1052 ;
1053 }
1054 virtual std::string FragmentGlobals() const
1055 {
1056 return "";
1057 }
1058 virtual std::string FragmentCodeGen() const
1059 {
1060 return "";
1061 }
1062};
1064{
1065public:
1066 WaterAttributes(int xid, int yid,
1067 int nx_x, int nx_y, int nx_z,
1068 int ny_x, int ny_y, int ny_z
1069 ) : xid(xid), yid(yid),
1070 nx_x(nx_x), nx_y(nx_y), nx_z(nx_z),
1071 ny_x(ny_x), ny_y(ny_y), ny_z(ny_z)
1072
1073 { }
1074 void SetAttribs(Program &p) const
1075 {
1076 x = p.find_attr("x", xid);
1077 y = p.find_attr("y", yid);
1078 vnx_x = p.find_attr("nx_x", nx_x);
1079 vnx_y = p.find_attr("nx_y", nx_y);
1080 vnx_z = p.find_attr("nx_z", nx_z);
1081 vny_x = p.find_attr("ny_x", ny_x);
1082 vny_y = p.find_attr("ny_y", ny_y);
1083 vny_z = p.find_attr("ny_z", ny_z);
1084 }
1085 void Attr(std::vector<Attrib> &vector)
1086 {
1087 vector.push_back(x);
1088 vector.push_back(y);
1089 vector.push_back(vnx_x);
1090 vector.push_back(vnx_y);
1091 vector.push_back(vnx_z);
1092 vector.push_back(vny_x);
1093 vector.push_back(vny_y);
1094 vector.push_back(vny_z);
1095 }
1096private:
1097 mutable Attrib x, y;
1098 mutable Attrib vnx_x, vnx_y, vnx_z;
1099 mutable Attrib vny_x, vny_y, vny_z;
1100 int xid, yid;
1101 int nx_x, nx_y, nx_z;
1102 int ny_x, ny_y, ny_z;
1103};
1105{
1106public:
1107 WaterParameters(float time) : time(time) { }
1108 void SetParameters(Program &p) const
1109 {
1110 p.set_var("time", time);
1111 }
1112private:
1113 float time;
1114};
1115
1116
1117std::string stringify(int i);
1118
1119
1121{
1122public:
1123 virtual void Provides(std::vector<int> &vec) const
1124 {
1125 vec.push_back(ReqPosition);
1126 }
1127
1128 MoveObjectPiece() { count = 1; }
1129 void set_count(int i) { count = i; }
1130 virtual std::string VertexGlobals() const
1131 {
1132 return
1133 "attribute int object_id;\n"
1134 "uniform float pos_x[" + stringify(count) + "];\n"
1135 "uniform float pos_y[" + stringify(count) + "];\n"
1136 "uniform float pox_z[" + stringify(count) + "];\n";
1137 }
1138 virtual std::string VertexCodeGen() const
1139 {
1140 return
1141 "vec4 v = vec4(pos_x[object_id], pos_y[object_id], pos_z[object_id], 0.0);\n"
1142 "v+=gl_Vertex;\n"
1143 "gl_Position = gl_ModelViewProjectionMatrix * v;\n";
1144 }
1145 virtual std::string FragmentGlobals() const
1146 {
1147 return "";
1148 }
1149 virtual std::string FragmentCodeGen() const
1150 {
1151 return "";
1152 }
1153private:
1154 int count;
1155};
1156class PointCollection;
1158{
1159public:
1160 MoveObjectParameters(const PointCollection &coll) : coll(coll) { }
1161 void SetParameters(Program &p) const;
1162private:
1163 const PointCollection &coll;
1164};
1165
1166
1168{
1169public:
1170 ShaderFromPieces() : configured(false) { }
1171 typedef std::vector<ShaderPiece*>::iterator iterator;
1172 typedef std::vector<ShaderPiece*>::const_iterator const_iterator;
1173 virtual std::string VertexShader() const
1174 {
1175 std::string s;
1176 for(const_iterator i = vec.begin();i!=vec.end();i++)
1177 {
1178 s += (*i)->VertexGlobals();
1179 }
1180 s+="void main() {\n";
1181 for(const_iterator i = vec.begin();i!=vec.end();i++)
1182 {
1183 s += (*i)->VertexCodeGen();
1184 }
1185 s+="}\n";
1186 return s;
1187 }
1188 virtual std::string FragmentShader() const
1189 {
1190 std::string s;
1191 for(const_iterator i = vec.begin();i!=vec.end();i++)
1192 {
1193 s += (*i)->FragmentGlobals();
1194 }
1195 s+="void main() {\n";
1196 for(const_iterator i = vec.begin();i!=vec.end();i++)
1197 {
1198 s += (*i)->FragmentCodeGen();
1199 }
1200 s+="}\n";
1201 return s;
1202 }
1203 void push_back(ShaderPiece* p) { vec.push_back(p); }
1204 void config()
1205 {
1206 if (!configured)
1207 {
1208 configured = true;
1209 std::cout << "Config" << std::endl;
1210 std::vector<int> conf;
1211 for(std::vector<ShaderPiece*>::iterator i=vec.begin();i!=vec.end();i++)
1212 {
1213 (*i)->Provides(conf);
1214 }
1215 std::vector<int>::iterator i1 = std::find(conf.begin(), conf.end(), (int)ReqPosition);
1216 if (i1==conf.end())
1217 vec.push_back(new EmptyVertexPiece);
1218 std::vector<int>::iterator i2 = std::find(conf.begin(), conf.end(), (int)ReqFragColorRGB);
1219 if (i2==conf.end())
1220 vec.push_back(new EmptyRGBPiece);
1221
1222 std::vector<int>::iterator i3 = std::find(conf.begin(), conf.end(), (int)ReqFragColorA);
1223 if (i3==conf.end())
1224 vec.push_back(new EmptyAPiece);
1225
1226 std::vector<int>::iterator i4 = std::find(conf.begin(), conf.end(), (int)ReqFragColorCombiner);
1227 if (i4 == conf.end())
1228 vec.push_back(new FragColorCombinerPiece);
1229
1230 for(std::vector<ShaderPiece*>::iterator i=vec.begin();i!=vec.end();i++)
1231 {
1232 (*i)->Config(conf);
1233 }
1234 }
1235 }
1236private:
1237 std::vector<ShaderPiece*> vec;
1238 bool configured;
1239};
1240
1242{
1243public:
1244 virtual ~ShaderUse() { }
1245 virtual void use()=0;
1246 virtual void set_params(ShaderParameters &p)=0;
1247 virtual void set_attribs(ShaderAttributes &p)=0;
1248 virtual void unuse()=0;
1249};
1251{
1252public:
1253 PieceShader() : pair(0) { }
1254 ~PieceShader() { delete pair; }
1256 { pieces.push_back(p); }
1257 //void push_back(ShaderFunctionCollection *f)
1258 //{
1259 //}
1260 void config()
1261 {
1262 pieces.config();
1263 }
1264 void use()
1265 {
1266 config();
1267 if (pair==0)
1268 {
1269 pair = new ShaderPair(pieces);
1270 }
1271 pair->use();
1272 }
1274 {
1275 config();
1276 if (pair==0)
1277 {
1278 pair = new ShaderPair(pieces);
1279 }
1280 pair->set_params(p);
1281 }
1283 {
1284 config();
1285 if (pair==0)
1286 {
1287 pair = new ShaderPair(pieces);
1288 }
1289 pair->set_attribs(p);
1290 }
1291 void unuse() { pair->unuse(); }
1292 int get_loc(std::string name) { return pair->get_loc(name); }
1293private:
1295 ShaderPair *pair;
1296};
1297
1298
1300{
1301public:
1302 std::string CodeGen() const
1303 {
1304 return
1305 "void main() {\n"
1306 " gl_Position = gl_ModelViewProjectionMatrix * Transform(gl_Vertex);\n"
1307 "}\n";
1308 }
1309};
1311{
1312public:
1313 LinearInterpolationParameters(int startpos_id, int endpos_id, int time_id, Point startpos, Point endpos, float starttime, float endtime, float currenttime) : startpos(startpos), endpos(endpos), starttime(starttime), endtime(endtime), currenttime(currenttime), startpos_id(startpos_id), endpos_id(endpos_id), time_id(time_id) { }
1314 void SetParameters(Program &pp) const
1315 {
1316 pp.set_var(startpos_id, startpos.x, startpos.y, startpos.z, starttime);
1317 pp.set_var(endpos_id, endpos.x, endpos.y, endpos.z, endtime);
1318 pp.set_var(time_id, currenttime);
1319 }
1320private:
1321 Point startpos;
1322 Point endpos;
1323 float starttime;
1324 float endtime;
1325 float currenttime;
1326 int startpos_id;
1327 int endpos_id;
1328 int time_id;
1329};
1330
1332{
1333public:
1334 LinearInterpolationParameters2(Point startpos, Point endpos) : startpos(startpos), endpos(endpos) { }
1335 void SetParameters(Program &pp) const
1336 {
1337 pp.set_var("startpos", startpos );
1338 pp.set_var("endpos", endpos);
1339 }
1340private:
1341 Point startpos;
1342 Point endpos;
1343};
1344
1346{
1347public:
1348 virtual void Provides(std::vector<int> &vec) const
1349 {
1350 vec.push_back(ReqPosition);
1351 }
1352 virtual std::string VertexGlobals() const
1353 {
1354 return
1355 "uniform vec4 startpos;\n"
1356 "uniform vec4 endpos;\n"
1357 "uniform float time;\n";
1358 }
1359 virtual std::string VertexCodeGen() const
1360 {
1361 return
1362 "float t = time - startpos.w;\n"
1363 "t /= endpos.w-startpos.w;\n"
1364 "vec4 p = mix(startpos, endpos, t);\n"//startpos*(1.0-t)+endpos*t;\n"
1365 "vec4 k = p + gl_Vertex;\n"
1366 "k.w = 1.0; \n"
1367 "vec4 res = gl_ModelViewProjectionMatrix * k;\n"
1368 "gl_Position = res;\n";
1369 }
1370 virtual std::string FragmentGlobals() const
1371 {
1372 return "";
1373 }
1374 virtual std::string FragmentCodeGen() const
1375 {
1376 return "";
1377 }
1378private:
1379
1380};
1381
1382
1383// SHADER FUNCTIONS SUPPORT
1384//
1385
1386
1387//class ShaderFunctionCollection : public VectorArray<ShaderFunction*>
1388//{
1389//};
1390
1392{
1393public:
1394 virtual void SetParameters(Program &p) const=0;
1395 virtual std::string Shader() const=0;
1396 virtual bool VertexShader() const=0;
1397};
1398
1400{
1401public:
1402 void Set(Point center, float r_) { c=center; r=r_; }
1403 void Link(std::string s2d, std::string r, std::string c1) { c2d=s2d; rr = r; cc = c1; }
1404 void SetParameters(Program &p) const
1405 {
1406 //p.set_var("r" + rr, r);
1407 //p.set_var("c" + cc, c);
1408 }
1409 std::string Shader() const
1410 {
1411 return
1412 "uniform float r"+rr+";\n"
1413 "uniform vec2 c"+cc+";\n"
1414 "vec2 Curve2d"+c2d+"(float k) {\n"
1415 "vec2 v;\n"
1416 "v.x = r"+rr+"*cos(k) + c"+cc+".x;\n"
1417 "v.y = r"+rr+"*sin(k) + c"+cc+".y;\n"
1418 "return v;\n"
1419 "}\n"
1420 ;
1421 }
1422 bool VertexShader() const { return true; }
1423private:
1424 Point c;
1425 float r;
1426 std::string c2d;
1427 std::string rr;
1428 std::string cc;
1429};
1430
1432{
1433public:
1434 void Set(Plane p) { plane = p; }
1435 void Link(std::string s2d, std::string s3d, std::string pl) { c2d=s2d; c3d=s3d; pll = pl; }
1436 void SetParameters(Program &p) const
1437 {
1438 //p.set_var("plane_u_p" + pll, plane.u_p);
1439 //p.set_var("plane_u_x" + pll, plane.u_x);
1440 //p.set_var("plane_u_y" + pll, plane.u_y);
1441 }
1442 std::string Shader() const
1443 {
1444 return
1445 "uniform vec3 plane_u_p"+pll+";\n"
1446 "uniform vec3 plane_u_x"+pll+";\n"
1447 "uniform vec3 plane_u_y"+pll+";\n"
1448 "vec2 Curve2d"+c2d+"(float x);\n"
1449 "vec3 Curve3d"+c3d+"(float a) {\n"
1450 " vec2 pp = Curve2d(a); \n"
1451 " vec3 pp2 = plane_u_p"+pll+" + pp.x*plane_u_x"+pll+" + pp.y*plane_u_y"+pll+";\n"
1452 " return pp2;\n"
1453 "}\n"
1454 ;
1455 }
1456 bool VertexShader() const { return true; }
1457
1458private:
1459 Plane plane;
1460 std::string c2d;
1461 std::string c3d;
1462 std::string pll;
1463};
1464
1466{
1467public:
1468 ShaderFile();
1469 ShaderFile(std::string filename);
1470 std::string VertexShader(std::string name);
1471 std::string FragmentShader(std::string name);
1472 std::string GeometryShader(std::string name);
1473private:
1474 std::map<std::string, std::string> v_shaders;
1475 std::map<std::string, std::string> f_shaders;
1476 std::map<std::string, std::string> g_shaders;
1477};
1478
1480{
1481public:
1482 ShaderSeq(ShaderFile &file) : file(file) { }
1483 ShaderSeq(const ShaderSeq &) = delete;
1484 ShaderSeq & operator=(const ShaderSeq &) = delete;
1485 ~ShaderSeq() { int s = progs.size();for(int i=0;i<s;i++) delete progs[i]; }
1486 int GetShader(std::string v_format, std::string f_format, std::string g_format, std::vector<std::string> v_vec=std::vector<std::string>(), std::vector<std::string> f_vec=std::vector<std::string>(), bool trans=true, ShaderModule *mod=0, ShaderCall *vertex_c=0, ShaderCall *fragment_c=0, std::string v_defines="", std::string f_defines="", std::string v_shader="", std::string f_shader="");
1487 void link(int i);
1488 void print_log(int i);
1489 void use(int i);
1490 void unuse(int i);
1491 Program *prog(int i);
1492private:
1493 ShaderFile &file;
1494private:
1495 std::vector<Program*> progs;
1496};
1497
1498struct AnimStateI;
1500{
1502 ~AnimState();
1503 AnimStateI *priv;
1504};
1505
1506class VBOState;
1507class Anim;
1508class AnimSelectI;
1509void UpdateAnim(Anim &anim, AnimState &state, const std::vector<Attrib> &attribs=std::vector<Attrib>());
1510
1511void DrawAnim(float start, float end, AnimState &state, const std::vector<Attrib> &attribs=std::vector<Attrib>());
1512
1513
1514std::vector<std::string> replace_c_template_unique_ids(std::string defines, std::string define);
1515
1516#endif
P pieces(int c, EveryApi &ev)
Definition test.cpp:30
struct Envi env
std::string unique_id()
Definition GameApi_shm.cc:50
std::string stringify(int i)
Definition Shader.cc:817
std::vector< std::string > replace_c_template_unique_ids(std::string defines, std::string define)
Definition Shader.cc:5985
ShaderProvides
Definition Shader.hh:318
@ ReqNormal
Definition Shader.hh:319
@ ReqFragColorRGB
Definition Shader.hh:320
@ ReqTexCoord0
Definition Shader.hh:323
@ ReqPosition
Definition Shader.hh:322
@ ReqFragColorA
Definition Shader.hh:321
@ ReqFragColorCombiner
Definition Shader.hh:324
void UpdateAnim(Anim &anim, AnimState &state, const std::vector< Attrib > &attribs=std::vector< Attrib >())
Definition Shader.cc:6821
void DrawAnim(float start, float end, AnimState &state, const std::vector< Attrib > &attribs=std::vector< Attrib >())
Definition Shader.cc:6839
FlexibleCube box(Point p1, float sx, float sy, float sz)
Definition VectorTools.cc:1529
Definition Effect.hh:3454
Definition Effect.hh:3441
int Count() const
Definition Shader.hh:225
std::string Source(int i) const
Definition Shader.hh:226
ArrayShader()
Definition Shader.hh:223
void push_back(std::string s)
Definition Shader.hh:230
std::string Name() const
Definition Shader.hh:224
Definition Shader.hh:732
virtual std::string VertexCodeGen() const
Definition Shader.hh:793
virtual std::string FragmentGlobals() const
Definition Shader.hh:808
virtual std::string VertexGlobals() const
Definition Shader.hh:739
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:734
virtual std::string FragmentCodeGen() const
Definition Shader.hh:812
Definition Shader.hh:1400
void SetParameters(Program &p) const
Definition Shader.hh:1404
void Set(Point center, float r_)
Definition Shader.hh:1402
bool VertexShader() const
Definition Shader.hh:1422
void Link(std::string s2d, std::string r, std::string c1)
Definition Shader.hh:1403
std::string Shader() const
Definition Shader.hh:1409
Definition VectorTools.hh:380
CombineParameters()
Definition Shader.hh:249
void SetParameters(Program &p) const
Definition Shader.hh:251
CombineParameters(ShaderParameters &p1_, ShaderParameters &p2_)
Definition Shader.hh:250
void SetValues(ShaderParameters *p1_, ShaderParameters *p2_)
Definition Shader.hh:256
Definition Shader.hh:1432
void SetParameters(Program &p) const
Definition Shader.hh:1436
bool VertexShader() const
Definition Shader.hh:1456
void Set(Plane p)
Definition Shader.hh:1434
void Link(std::string s2d, std::string s3d, std::string pl)
Definition Shader.hh:1435
std::string Shader() const
Definition Shader.hh:1442
void SetAttribs(Program &p) const
Definition Shader.hh:645
void Attr(std::vector< Attrib > &vec)
Definition Shader.hh:651
DiscardAttributes(int centerx, int centery, int centerz)
Definition Shader.hh:644
DiscardParameters(float distance)
Definition Shader.hh:632
void SetParameters(Program &p) const
Definition Shader.hh:633
Definition Shader.hh:595
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:597
virtual std::string FragmentCodeGen() const
Definition Shader.hh:622
virtual void Config(const std::vector< int > &env)
Definition Shader.hh:601
virtual std::string FragmentGlobals() const
Definition Shader.hh:616
virtual std::string VertexGlobals() const
Definition Shader.hh:603
virtual std::string VertexCodeGen() const
Definition Shader.hh:610
Definition Shader.hh:569
virtual std::string VertexGlobals() const
Definition Shader.hh:571
virtual std::string FragmentCodeGen() const
Definition Shader.hh:584
virtual std::string VertexCodeGen() const
Definition Shader.hh:575
virtual std::string FragmentGlobals() const
Definition Shader.hh:580
Definition Shader.hh:543
virtual std::string FragmentGlobals() const
Definition Shader.hh:554
virtual std::string FragmentCodeGen() const
Definition Shader.hh:558
virtual std::string VertexCodeGen() const
Definition Shader.hh:549
virtual std::string VertexGlobals() const
Definition Shader.hh:545
Definition Shader.hh:521
virtual std::string VertexCodeGen() const
Definition Shader.hh:527
virtual std::string VertexGlobals() const
Definition Shader.hh:523
virtual std::string FragmentGlobals() const
Definition Shader.hh:532
virtual std::string FragmentCodeGen() const
Definition Shader.hh:536
Definition Shader.hh:890
virtual std::string VertexCodeGen() const
Definition Shader.hh:908
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:900
virtual std::string VertexGlobals() const
Definition Shader.hh:904
virtual void Config(const std::vector< int > &env)
Definition Shader.hh:893
virtual std::string FragmentCodeGen() const
Definition Shader.hh:916
FragColorCombinerPiece()
Definition Shader.hh:892
virtual std::string FragmentGlobals() const
Definition Shader.hh:912
Definition Shader.hh:206
FragmentShader(ShaderString &shader)
Definition Shader.hh:208
int Count() const
Definition Shader.hh:210
std::string Name() const
Definition Shader.hh:209
std::string Source(int i) const
Definition Shader.hh:211
void SetParameters(Program &pp) const
Definition Shader.hh:832
GlobalTextureParameters(Point p, Vector x, Vector y, Vector z)
Definition Shader.hh:831
Definition Shader.hh:847
virtual std::string FragmentCodeGen() const
Definition Shader.hh:882
virtual std::string VertexCodeGen() const
Definition Shader.hh:862
virtual std::string VertexGlobals() const
Definition Shader.hh:853
virtual std::string FragmentGlobals() const
Definition Shader.hh:878
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:849
virtual std::string VertexGlobals() const
Definition Shader.hh:352
void Provides(std::vector< int > &vec) const
Definition Shader.hh:343
virtual std::string VertexCodeGen() const
Definition Shader.hh:360
virtual std::string FragmentGlobals() const
Definition Shader.hh:381
virtual std::string FragmentCodeGen() const
Definition Shader.hh:385
GouraudPiece()
Definition Shader.hh:342
LinearInterpolationParameters2(Point startpos, Point endpos)
Definition Shader.hh:1334
void SetParameters(Program &pp) const
Definition Shader.hh:1335
void SetParameters(Program &pp) const
Definition Shader.hh:1314
LinearInterpolationParameters(int startpos_id, int endpos_id, int time_id, Point startpos, Point endpos, float starttime, float endtime, float currenttime)
Definition Shader.hh:1313
Definition Shader.hh:1346
virtual std::string VertexGlobals() const
Definition Shader.hh:1352
virtual std::string FragmentCodeGen() const
Definition Shader.hh:1374
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:1348
virtual std::string FragmentGlobals() const
Definition Shader.hh:1370
virtual std::string VertexCodeGen() const
Definition Shader.hh:1359
Definition VectorTools.hh:279
void SetParameters(Program &p) const
Definition Shader.cc:798
MoveObjectParameters(const PointCollection &coll)
Definition Shader.hh:1160
virtual std::string VertexCodeGen() const
Definition Shader.hh:1138
MoveObjectPiece()
Definition Shader.hh:1128
virtual std::string VertexGlobals() const
Definition Shader.hh:1130
virtual std::string FragmentGlobals() const
Definition Shader.hh:1145
virtual std::string FragmentCodeGen() const
Definition Shader.hh:1149
void set_count(int i)
Definition Shader.hh:1129
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:1123
NormalParameters(Point p, float mix_rate)
Definition Shader.hh:401
virtual void SetParameters(Program &pp) const
Definition Shader.hh:402
Definition Shader.hh:412
virtual std::string FragmentGlobals() const
Definition Shader.hh:433
virtual std::string FragmentCodeGen() const
Definition Shader.hh:437
virtual std::string VertexGlobals() const
Definition Shader.hh:418
virtual std::string VertexCodeGen() const
Definition Shader.hh:425
void Provides(std::vector< int > &vec) const
Definition Shader.hh:414
virtual void SetParameters(Program &p) const
Definition Shader.hh:293
PhongParameters(Point viewer, Point light, Color light_color, Color speccolor)
Definition Shader.hh:292
Point HalfWay(Point viewer, Point light) const
Definition Shader.hh:302
void Provides(std::vector< int > &vec) const
Definition Shader.hh:454
virtual std::string VertexCodeGen() const
Definition Shader.hh:470
virtual void Config(const std::vector< int > &env)
Definition Shader.hh:447
virtual std::string FragmentCodeGen() const
Definition Shader.hh:486
PhongPiece()
Definition Shader.hh:446
virtual std::string VertexGlobals() const
Definition Shader.hh:463
virtual std::string FragmentGlobals() const
Definition Shader.hh:477
void use()
Definition Shader.hh:1264
void config()
Definition Shader.hh:1260
~PieceShader()
Definition Shader.hh:1254
void unuse()
Definition Shader.hh:1291
void set_attribs(ShaderAttributes &p)
Definition Shader.hh:1282
void set_params(ShaderParameters &p)
Definition Shader.hh:1273
void push_back(ShaderPiece *p)
Definition Shader.hh:1255
PieceShader()
Definition Shader.hh:1253
int get_loc(std::string name)
Definition Shader.hh:1292
Definition VectorTools.hh:350
Definition Effect.hh:2456
Definition Shader.hh:75
void clean_map()
Definition Shader.cc:710
void set_var_matrix(const char *name, const std::vector< float > &v)
Definition Shader.cc:658
Attrib find_attr(const std::string &attr_name, int id)
Definition Shader.cc:777
void use()
Definition Shader.cc:331
void print_locs()
Definition Shader.cc:698
void print_log()
Definition Shader.cc:321
void set_var(const char *name, float val)
Definition Shader.cc:358
void set_var_matrix2(const char *name, const std::vector< float > &v, int start)
Definition Shader.cc:630
Matrix get_matrix_var(const std::string &name)
Definition Shader.cc:590
void push_back(const Shader &shader)
Definition Shader.cc:214
Program(const Program &)=delete
ProgramPriv * priv
Definition Shader.hh:117
Program & operator=(const Program &)=delete
Attrib find_attr_int(const std::string &attr_name, int id)
Definition Shader.cc:785
~Program()
Definition Shader.cc:201
void unuse()
Definition Shader.cc:348
std::unordered_map< Low_GLint, int > g_intvar_cache
Definition Shader.hh:121
Program()
Definition Shader.cc:193
void attr_loc(std::string s, int index)
Definition Shader.cc:793
std::unordered_map< Low_GLint, Matrix > cache
Definition Shader.hh:119
void GeomOutputVertices(int i)
Definition Shader.cc:284
std::unordered_map< Low_GLint, float > g_setvar_cache
Definition Shader.hh:120
void bind_attrib(int num, std::string name)
Definition Shader.cc:245
std::unordered_map< uint32_t, int > locs
Definition Shader.hh:118
void link()
Definition Shader.cc:289
void detach(const Shader &shader)
Definition Shader.cc:249
void bind_frag(int num, std::string name)
Definition Shader.cc:239
int get_loc(std::string name)
Definition Shader.cc:485
void GeomTypes(int input, int output)
Definition Shader.cc:258
virtual void SetParameters(Program &p) const
Definition Shader.hh:698
RandomPositionParameters(Point box, float time)
Definition Shader.hh:697
Definition Shader.hh:664
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:666
virtual std::string VertexCodeGen() const
Definition Shader.hh:677
virtual std::string VertexGlobals() const
Definition Shader.hh:671
virtual std::string FragmentGlobals() const
Definition Shader.hh:685
virtual std::string FragmentCodeGen() const
Definition Shader.hh:689
Definition Shader.hh:241
virtual void SetAttribs(Program &p) const =0
Definition GraphI.hh:1981
Definition Shader.hh:1466
ShaderFile()
Definition Shader.cc:5892
std::string GeometryShader(std::string name)
Definition Shader.cc:5981
std::string FragmentShader(std::string name)
Definition Shader.cc:5977
std::string VertexShader(std::string name)
Definition Shader.cc:5973
Definition Shader.hh:1168
virtual std::string VertexShader() const
Definition Shader.hh:1173
virtual std::string FragmentShader() const
Definition Shader.hh:1188
void config()
Definition Shader.hh:1204
ShaderFromPieces()
Definition Shader.hh:1170
std::vector< ShaderPiece * >::iterator iterator
Definition Shader.hh:1171
std::vector< ShaderPiece * >::const_iterator const_iterator
Definition Shader.hh:1172
void push_back(ShaderPiece *p)
Definition Shader.hh:1203
Definition Shader.hh:1392
virtual void SetParameters(Program &p) const =0
virtual std::string Shader() const =0
virtual bool VertexShader() const =0
Definition GraphI.hh:1281
Definition Shader.hh:262
void use()
Definition Shader.hh:270
ShaderPair(ShaderString &shader)
Definition Shader.hh:264
void unuse()
Definition Shader.hh:279
int get_loc(std::string name)
Definition Shader.hh:280
void set_attribs(ShaderAttributes &p)
Definition Shader.hh:275
void set_params(ShaderParameters &p)
Definition Shader.hh:271
Definition Shader.hh:236
virtual void SetParameters(Program &p) const =0
Definition Shader.hh:328
virtual std::string FragmentCodeGen() const =0
virtual std::string FragmentGlobals() const =0
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:334
virtual std::string VertexGlobals() const =0
virtual std::string VertexCodeGen() const =0
virtual void Config(const std::vector< int > &env)
Definition Shader.hh:335
void use(int i)
Definition Shader.cc:6729
ShaderSeq(const ShaderSeq &)=delete
ShaderSeq & operator=(const ShaderSeq &)=delete
void link(int i)
Definition Shader.cc:6722
ShaderSeq(ShaderFile &file)
Definition Shader.hh:1482
void unuse(int i)
Definition Shader.cc:6736
~ShaderSeq()
Definition Shader.hh:1485
Program * prog(int i)
Definition Shader.cc:6743
void print_log(int i)
Definition Shader.cc:6717
int GetShader(std::string v_format, std::string f_format, std::string g_format, std::vector< std::string > v_vec=std::vector< std::string >(), std::vector< std::string > f_vec=std::vector< std::string >(), bool trans=true, ShaderModule *mod=0, ShaderCall *vertex_c=0, ShaderCall *fragment_c=0, std::string v_defines="", std::string f_defines="", std::string v_shader="", std::string f_shader="")
Definition Shader.cc:6583
Definition Shader.hh:41
virtual std::string Source(int i) const =0
virtual int Count() const =0
virtual std::string Name() const =0
Definition Shader.hh:159
virtual std::string VertexMain() const
Definition Shader.hh:167
virtual std::string FragmentShader() const
Definition Shader.hh:163
virtual std::string FragmentGlobals() const
Definition Shader.hh:170
virtual std::string VertexCode() const
Definition Shader.hh:175
virtual std::string FragmentColor() const
Definition Shader.hh:187
virtual std::string VertexDecls() const
Definition Shader.hh:174
virtual std::string FragmentCode() const
Definition Shader.hh:180
virtual std::string FragmentAssigns() const
Definition Shader.hh:181
virtual std::string FragmentMain() const
Definition Shader.hh:171
virtual std::string FragmentDecls() const
Definition Shader.hh:179
virtual std::string VertexAssigns() const
Definition Shader.hh:176
virtual std::string VertexPosition() const
Definition Shader.hh:184
virtual std::string VertexGlobals() const
Definition Shader.hh:166
virtual std::string VertexShader() const
Definition Shader.hh:162
Definition Shader.hh:151
virtual std::string FragmentShader() const =0
virtual std::string VertexShader() const =0
Definition Shader.hh:1242
virtual void set_attribs(ShaderAttributes &p)=0
virtual void use()=0
virtual void unuse()=0
virtual ~ShaderUse()
Definition Shader.hh:1244
virtual void set_params(ShaderParameters &p)=0
Definition Shader.hh:63
ShaderPriv * priv
Definition Shader.hh:69
Shader(ShaderSpec &spec, bool vertex, bool geom)
Definition Shader.cc:109
void print_log() const
Definition Shader.cc:164
~Shader()
Definition Shader.cc:173
SingletonShaderSpec(std::string s, std::string name)
Definition Shader.hh:52
std::string Name() const
Definition Shader.hh:53
int Count() const
Definition Shader.hh:54
std::string Source(int i) const
Definition Shader.hh:55
Definition Shader.hh:137
std::string Name() const
Definition Shader.hh:139
std::string Source(int i) const
Definition Shader.hh:141
int Count() const
Definition Shader.hh:140
Definition Shader.hh:125
std::string Name() const
Definition Shader.hh:127
int Count() const
Definition Shader.hh:128
std::string Source(int i) const
Definition Shader.hh:129
void SetParameters(Program &p) const
Definition Shader.hh:821
TextureParameters(int textureunit)
Definition Shader.hh:820
virtual std::string VertexGlobals() const
Definition Shader.hh:963
TexturePiece()
Definition Shader.hh:947
virtual std::string FragmentGlobals() const
Definition Shader.hh:974
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:955
virtual std::string FragmentCodeGen() const
Definition Shader.hh:978
virtual std::string VertexCodeGen() const
Definition Shader.hh:967
virtual void Config(const std::vector< int > &env)
Definition Shader.hh:948
Definition Effect.hh:10694
Definition VectorTools.hh:125
float Dist() const
Definition VectorTools.cc:141
Definition Shader.hh:1300
std::string CodeGen() const
Definition Shader.hh:1302
Definition Shader.hh:191
std::string Source(int i) const
Definition Shader.hh:196
std::string Name() const
Definition Shader.hh:194
VertexShader(ShaderString &shader)
Definition Shader.hh:193
int Count() const
Definition Shader.hh:195
WaterAttributes(int xid, int yid, int nx_x, int nx_y, int nx_z, int ny_x, int ny_y, int ny_z)
Definition Shader.hh:1066
void SetAttribs(Program &p) const
Definition Shader.hh:1074
void Attr(std::vector< Attrib > &vector)
Definition Shader.hh:1085
WaterParameters(float time)
Definition Shader.hh:1107
void SetParameters(Program &p) const
Definition Shader.hh:1108
Definition Shader.hh:992
virtual std::string VertexCodeGen() const
Definition Shader.hh:1032
virtual std::string FragmentCodeGen() const
Definition Shader.hh:1058
virtual std::string FragmentGlobals() const
Definition Shader.hh:1054
virtual std::string VertexGlobals() const
Definition Shader.hh:1000
virtual void Provides(std::vector< int > &vec) const
Definition Shader.hh:994
iVBORw0KGgoAAAANSUhEUgAAANcAAAB5CAMAAACdtUQZAAAA51BMVEX</div ></div >< div style="padding: 0px 0px; width: 1324px;">< div style="height: 400px; width: 1324px;"></div >< div itemscope itemtype="https: </div><div itemscope itemtype="https:</div >< div itemscope itemtype="https: </div></div><p><div style="padding:0px 0px;width:1324px;"><div></div><div itemscope itemtype="https:< ul >< li >< b > Application name
8AkrcAgqgAs9wqQ0ey2tkAo8gAuuQfeI4hPUH09fXHy8z4+fng4uNKXF/Lz9BzfoAcgpkQMTUAKjAbOT4Qr9AXhJ8Rl7ktMCwTosA...
Definition meshpage.php:1610
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition Shader.hh:1500
AnimStateI * priv
Definition Shader.hh:1503
~AnimState()
Definition Shader.cc:6814
AnimState(ShaderFile &f)
Definition Shader.cc:6808
Definition Shader.hh:33
bool is_int
Definition Shader.hh:36
int loc
Definition Shader.hh:34
int id
Definition Shader.hh:35
Definition Parser.cc:60
Definition Shader.cc:188
Definition Shader.cc:102
num
Definition view.php:2821