-
Notifications
You must be signed in to change notification settings - Fork 12
/
Shader.cpp
1013 lines (800 loc) · 22.1 KB
/
Shader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <Renderer/Shader/Shader.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <assert.h>
// Can update individual indices of uniform array by getting attribute location of each index
Shader::Shader()
: m_progID(0), m_geomID(0), m_vertID(0), m_fragID(0),
m_lastAttachment(0), m_created(false)
{
}
Shader::~Shader()
{
if(m_created)
{
glDeleteProgram(m_progID);
if(m_vertID != 0)
glDeleteShader(m_vertID);
if(m_fragID != 0)
glDeleteShader(m_fragID);
}
}
bool Shader::LoadShader(const std::string &name, unsigned int id)
{
std::ifstream fromFile;
fromFile.open(name);
if(!fromFile.is_open())
{
std::cerr << "Could not open file: " << name << "!" << std::endl;
return false;
}
// Load the shader code into one massive string
std::string fileString((std::istreambuf_iterator<char>(fromFile)), std::istreambuf_iterator<char>());
const char* code = fileString.c_str();
glShaderSource(id, 1, &code, NULL);
glCompileShader(id);
if(CheckLog(id))
{
std::cerr << "- in " << name << std::endl;
return false;
}
return true;
}
bool Shader::LoadGeometryShader(const std::string &name, unsigned int &id)
{
id = glCreateShaderObjectARB(GL_GEOMETRY_SHADER_ARB);
if(!LoadShader(name, id))
{
glDeleteShader(id);
return false;
}
return true;
}
bool Shader::LoadVertexShader(const std::string &name, unsigned int &id)
{
id = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
if(!LoadShader(name, id))
{
glDeleteShader(id);
return false;
}
return true;
}
bool Shader::LoadFragmentShader(const std::string &name, unsigned int &id)
{
id = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
if(!LoadShader(name, id))
{
glDeleteShader(id);
return false;
}
return true;
}
bool Shader::CheckLog(unsigned int id)
{
int result;
glGetShaderiv(id, GL_COMPILE_STATUS, &result);
// If did not compile without error, show the log
if(result == GL_FALSE)
{
int logLength;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &logLength);
if(logLength <= 0)
{
std::cerr << "Unable to compile shader: Error: Invalid log length \"" << logLength << "\": Could not retrieve error log!" << std::endl;
return false;
}
// Allocate the string
char *log = new char[logLength];
glGetShaderInfoLog(id, logLength, &result, log);
// Print the log
std::cerr << "Unable to compile shader: " << log << std::endl;
delete log;
return true;
}
return false;
}
bool Shader::Link(unsigned int id)
{
glLinkProgram(id);
int result;
// Check if linking was successful
glGetProgramiv(id, GL_LINK_STATUS, &result);
if(result == GL_FALSE)
{
// Not validated, print out the log
int logLength;
glGetProgramiv(id, GL_INFO_LOG_LENGTH, &logLength);
if(logLength <= 0)
{
std::cerr << "Unable to link program: Error: Invalid log length \"" << logLength << "\": Could not retrieve error log!" << std::endl;
return false;
}
// Allocate the string
char* log = new char[logLength];
glGetProgramInfoLog(id, logLength, &result, log);
std::cerr << "Unable to link program: " << log << std::endl;
delete log;
return false;
}
return true;
}
bool Shader::Validate(unsigned int id)
{
glValidateProgram(id);
int result;
// Check if validation was successful
glGetProgramiv(id, GL_VALIDATE_STATUS, &result);
if(result == GL_FALSE)
{
// Not validated, print out the log
int logLength;
glGetProgramiv(id, GL_INFO_LOG_LENGTH, &logLength);
if(logLength <= 0)
{
std::cerr << "Unable to validate program: Error: Invalid log length \"" << logLength << "\": Could not retrieve error log!" << std::endl;
return true;
}
// Allocate the string
char* log = new char[logLength];
glGetProgramInfoLog(id, logLength, &result, log);
std::cerr << "Unable to validate program: " << log << std::endl;
delete log;
return false;
}
return true;
}
bool Shader::LoadAsset(const std::string &name)
{
// Name contains vertex shader file name and the fragment shader file name, so extract those
std::istringstream is(name);
std::string geomName, fragName, vertName;
is >> geomName >> vertName >> fragName;
// Load the shaders
if(geomName != "NONE")
if(!LoadGeometryShader(geomName, m_geomID))
{
std::cout << "Could not load geometry shader!" << std::endl;
return false;
}
if(vertName != "NONE")
if(!LoadVertexShader(vertName, m_vertID))
{
std::cout << "Could not load vertex shader!" << std::endl;
return false;
}
if(fragName != "NONE")
if(!LoadFragmentShader(fragName, m_fragID))
{
std::cout << "Could not load fragment shader!" << std::endl;
return false;
}
// Create the main shader
m_progID = glCreateProgramObjectARB();
// Attach the shader components (vertex and fragment) to the program
if(m_geomID != 0)
glAttachObjectARB(m_progID, m_geomID);
if(m_vertID != 0)
glAttachObjectARB(m_progID, m_vertID);
if(m_fragID != 0)
glAttachObjectARB(m_progID, m_fragID);
if(!Link(m_progID))
{
std::cerr << "- in " << name << std::endl;
glDeleteShader(m_progID);
return false;
}
if(CheckForGLError())
{
glDeleteShader(m_progID);
return false;
}
m_created = true;
return true;
}
void Shader::SetShaderTexture(const std::string &name, unsigned int textureID, unsigned int target)
{
assert(m_created);
CheckProgram();
// See if the texture already exists, in which case it is simply updated
std::unordered_map<std::string, TextureAndAttachment>::iterator it = m_textures.find(name);
// If the texture does not already exist
if(it == m_textures.end())
{
// Check that the uniform exists
int baseImageLoc = glGetUniformLocationARB(m_progID, name.c_str());
if(baseImageLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
{
glUniform1iARB(baseImageLoc, m_lastAttachment);
// Add the texture to the hash
m_textures[name] = TextureAndAttachment(textureID, m_lastAttachment, target);
m_lastAttachment++;
}
}
else
{
// Update the existing texture
it->second.m_textureHandle = textureID;
}
}
void Shader::SetShaderTexture(const std::string &name, unsigned int textureAttachment, unsigned int textureID, unsigned int target)
{
assert(m_created);
CheckProgram();
// See if the texture already exists, in which case it is simply updated
std::unordered_map<std::string, TextureAndAttachment>::iterator it = m_textures.find(name);
// If the texture does not already exist
if(it == m_textures.end())
{
// Check that the uniform exists
int baseImageLoc = glGetUniformLocationARB(m_progID, name.c_str());
if(baseImageLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
{
glUniform1iARB(baseImageLoc, textureAttachment);
// Add the texture to the hash
m_textures[name] = TextureAndAttachment(textureID, textureAttachment, target);
}
}
else
{
// Update the existing texture
it->second.m_textureHandle = textureID;
it->second.m_attachment = textureAttachment;
}
}
void Shader::BindShaderTextures()
{
// Bind all textures
for(std::unordered_map<std::string, TextureAndAttachment>::iterator it = m_textures.begin(); it != m_textures.end(); it++)
{
glActiveTexture(GL_TEXTURE0 + it->second.m_attachment);
glBindTexture(it->second.m_target, it->second.m_textureHandle);
}
// Set to normal one
glActiveTexture(GL_TEXTURE0);
}
void Shader::UnbindShaderTextures()
{
// Bind all used textures
for(unsigned int i = 0, size = m_textures.size(); i < size; i++)
{
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, 0);
}
// Set to normal one
glActiveTexture(GL_TEXTURE0);
}
void Shader::Bind()
{
glUseProgramObjectARB(m_progID);
}
void Shader::Unbind()
{
glUseProgramObjectARB(0);
}
int Shader::GetAttributeLocation(const std::string &name)
{
int paramLoc;
std::unordered_map<std::string, int>::iterator it = m_attributeLocations.find(name);
if(it == m_attributeLocations.end())
m_attributeLocations[name] = paramLoc = glGetUniformLocationARB(m_progID, name.c_str());
else
paramLoc = it->second;
return paramLoc;
}
int Shader::SetUniformf(const std::string &name, float param)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform1fARB(paramLoc, param);
#else
glUniform1fARB(paramLoc, param);
#endif
return paramLoc;
}
int Shader::SetUniformv2f(const std::string &name, float param1, float param2)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform2fARB(paramLoc, param1, param2);
#else
glUniform2fARB(paramLoc, param1, param2);
#endif
return paramLoc;
}
int Shader::SetUniformv2f(const std::string &name, const Vec2f ¶m)
{
return SetUniformv2f(name, param.x, param.y);
}
int Shader::SetUniformv3f(const std::string &name, float param1, float param2, float param3)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform3fARB(paramLoc, param1, param2, param3);
#else
glUniform3fARB(paramLoc, param1, param2, param3);
#endif
return paramLoc;
}
int Shader::SetUniformv3f(const std::string &name, const Vec3f ¶m)
{
return SetUniformv3f(name, param.x, param.y, param.z);
}
int Shader::SetUniformv3f(const std::string &name, const Color3f ¶m)
{
return SetUniformv3f(name, param.r, param.g, param.b);
}
int Shader::SetUniformv4f(const std::string &name, float param1, float param2, float param3, float param4)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform4fARB(paramLoc, param1, param2, param3, param4);
#else
glUniform4fARB(paramLoc, param1, param2, param3, param4);
#endif
return paramLoc;
}
int Shader::SetUniformv4f(const std::string &name, const Vec4f ¶m)
{
return SetUniformv4f(name, param.x, param.y, param.z, param.w);
}
int Shader::SetUniformv4f(const std::string &name, const Color4f ¶m)
{
return SetUniformv4f(name, param.r, param.g, param.b, param.a);
}
int Shader::SetUniformi(const std::string &name, int param)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform1iARB(paramLoc, param);
#else
glUniform1iARB(paramLoc, param);
#endif
return paramLoc;
}
int Shader::SetUniformv2i(const std::string &name, int param1, int param2)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform2iARB(paramLoc, param1, param2);
#else
glUniform2iARB(paramLoc, param1, param2);
#endif
return paramLoc;
}
int Shader::SetUniformmat4(const std::string &name, const Matrix4x4f ¶m)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniformMatrix4fvARB(paramLoc, 1, false, param.m_elements);
#else
glUniformMatrix4fvARB(paramLoc, 1, false, param.m_elements);
#endif
return paramLoc;
}
int Shader::SetTextureAttachmentToUniform(const std::string &name, unsigned int attachment)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform1iARB(paramLoc, attachment);
#else
glUniform1iARB(paramLoc, attachment);
#endif
return paramLoc;
}
void Shader::SetTextureAttachmentToUniform(int paramLoc, unsigned int attachment)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform1iARB(paramLoc, attachment);
#else
glUniform1iARB(paramLoc, attachment);
#endif
}
int Shader::SetUniform1iv(const std::string &name, unsigned int numParams, const int* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform1ivARB(paramLoc, numParams, params);
#else
glUniform1ivARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
int Shader::SetUniform2iv(const std::string &name, unsigned int numParams, const int* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform2ivARB(paramLoc, numParams , params);
#else
glUniform2ivARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
int Shader::SetUniform3iv(const std::string &name, unsigned int numParams, const int* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform3ivARB(paramLoc, numParams, params);
#else
glUniform3ivARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
int Shader::SetUniform4iv(const std::string &name, unsigned int numParams, const int* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform4ivARB(paramLoc, numParams, params);
#else
glUniform4ivARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
int Shader::SetUniform1fv(const std::string &name, unsigned int numParams, const float* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform1fvARB(paramLoc, numParams, params);
#else
glUniform1fvARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
int Shader::SetUniform2fv(const std::string &name, unsigned int numParams, const float* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform2fvARB(paramLoc, numParams, params);
#else
glUniform2fvARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
int Shader::SetUniform3fv(const std::string &name, unsigned int numParams, const float* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform3fvARB(paramLoc, numParams, params);
#else
glUniform3fvARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
int Shader::SetUniform4fv(const std::string &name, unsigned int numParams, const float* params)
{
CheckProgram();
int paramLoc = GetAttributeLocation(name);
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform " << name << "!" << std::endl;
else
glUniform4fvARB(paramLoc, numParams, params);
#else
glUniform4fvARB(paramLoc, numParams, params);
#endif
return paramLoc;
}
// -------------------- Attribute Location Versions ----------------------
void Shader::SetUniformf(int paramLoc, float param)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform1fARB(paramLoc, param);
#else
glUniform1fARB(paramLoc, param);
#endif
}
void Shader::SetUniformv2f(int paramLoc, float param1, float param2)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform2fARB(paramLoc, param1, param2);
#else
glUniform2fARB(paramLoc, param1, param2);
#endif
}
void Shader::SetUniformv2f(int paramLoc, const Vec2f ¶m)
{
SetUniformv2f(paramLoc, param.x, param.y);
}
void Shader::SetUniformv3f(int paramLoc, float param1, float param2, float param3)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform3fARB(paramLoc, param1, param2, param3);
#else
glUniform3fARB(paramLoc, param1, param2, param3);
#endif
}
void Shader::SetUniformv3f(int paramLoc, const Vec3f ¶m)
{
SetUniformv3f(paramLoc, param.x, param.y, param.z);
}
void Shader::SetUniformv3f(int paramLoc, const Color3f ¶m)
{
SetUniformv3f(paramLoc, param.r, param.g, param.b);
}
void Shader::SetUniformv4f(int paramLoc, float param1, float param2, float param3, float param4)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform4fARB(paramLoc, param1, param2, param3, param4);
#else
glUniform4fARB(paramLoc, param1, param2, param3, param4);
#endif
}
void Shader::SetUniformv4f(int paramLoc, const Vec4f ¶m)
{
SetUniformv4f(paramLoc, param.x, param.y, param.z, param.w);
}
void Shader::SetUniformv4f(int paramLoc, const Color4f ¶m)
{
SetUniformv4f(paramLoc, param.r, param.g, param.b, param.a);
}
void Shader::SetUniformi(int paramLoc, int param)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform1iARB(paramLoc, param);
#else
glUniform1iARB(paramLoc, param);
#endif
}
void Shader::SetUniformv2i(int paramLoc, int param1, int param2)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform2iARB(paramLoc, param1, param2);
#else
glUniform2iARB(paramLoc, param1, param2);
#endif
}
void Shader::SetUniformmat4(int paramLoc, const Matrix4x4f ¶m)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniformMatrix4fvARB(paramLoc, 1, false, param.m_elements);
#else
glUniformMatrix4fvARB(paramLoc, 1, false, param.m_elements);
#endif
}
void Shader::SetUniform1iv(int paramLoc, unsigned int numParams, const int* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform1ivARB(paramLoc, numParams, params);
#else
glUniform1ivARB(paramLoc, numParams, params);
#endif
}
void Shader::SetUniform2iv(int paramLoc, unsigned int numParams, const int* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform2ivARB(paramLoc, numParams, params);
#else
glUniform2ivARB(paramLoc, numParams, params);
#endif
}
void Shader::SetUniform3iv(int paramLoc, unsigned int numParams, const int* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform3ivARB(paramLoc, numParams, params);
#else
glUniform3ivARB(paramLoc, numParams, params);
#endif
}
void Shader::SetUniform4iv(int paramLoc, unsigned int numParams, const int* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform4ivARB(paramLoc, numParams, params);
#else
glUniform4ivARB(paramLoc, numParams, params);
#endif
}
void Shader::SetUniform1fv(int paramLoc, unsigned int numParams, const float* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform1fvARB(paramLoc, numParams, params);
#else
glUniform1fvARB(paramLoc, numParams, params);
#endif
}
void Shader::SetUniform2fv(int paramLoc, unsigned int numParams, const float* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform2fvARB(paramLoc, numParams, params);
#else
glUniform2fvARB(paramLoc, numParams, params);
#endif
}
void Shader::SetUniform3fv(int paramLoc, unsigned int numParams, const float* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform3fvARB(paramLoc, numParams, params);
#else
glUniform3fvARB(paramLoc, numParams, params);
#endif
}
void Shader::SetUniform4fv(int paramLoc, unsigned int numParams, const float* params)
{
CheckProgram();
// If location was not found
#ifdef DEBUG
if(paramLoc == -1)
std::cerr << "Could not find the uniform at location" << paramLoc << "!" << std::endl;
else
glUniform4fvARB(paramLoc, numParams, params);
#else
glUniform4fvARB(paramLoc, numParams, params);
#endif
}
unsigned int Shader::GetProgID() const
{
return m_progID;
}
Asset* Shader::Asset_Factory()
{
return new Shader();
}
void SetVec3f(std::vector<float> &vals, int index, const Vec3f &vec)
{
int realIndex = index * 3;