-
-
Notifications
You must be signed in to change notification settings - Fork 516
/
gfx_api_gl.cpp
4397 lines (3920 loc) · 152 KB
/
gfx_api_gl.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
/*
This file is part of Warzone 2100.
Copyright (C) 2017-2020 Warzone 2100 Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lib/framework/frame.h"
#include "lib/framework/wzapp.h"
#include "screen.h"
#include "gfx_api_gl.h"
#include "lib/exceptionhandler/dumpinfo.h"
#include "lib/framework/physfs_ext.h"
#include "lib/framework/wzpaths.h"
#include "piemode.h"
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <limits>
#include <typeindex>
#include <sstream>
#include <glm/gtc/type_ptr.hpp>
#ifndef GL_GENERATE_MIPMAP
#define GL_GENERATE_MIPMAP 0x8191
#endif
struct OPENGL_DATA
{
char vendor[256] = {};
char renderer[256] = {};
char version[256] = {};
char GLSLversion[256] = {};
};
OPENGL_DATA opengl;
static GLuint perfpos[PERF_COUNT] = {};
static bool perfStarted = false;
#if defined(WZ_DEBUG_GFX_API_LEAKS)
static std::unordered_set<const gl_texture*> debugLiveTextures;
#endif
PFNGLDRAWARRAYSINSTANCEDPROC wz_dyn_glDrawArraysInstanced = nullptr;
PFNGLDRAWELEMENTSINSTANCEDPROC wz_dyn_glDrawElementsInstanced = nullptr;
PFNGLVERTEXATTRIBDIVISORPROC wz_dyn_glVertexAttribDivisor = nullptr;
static const GLubyte* wzSafeGlGetString(GLenum name);
static GLenum to_gl_internalformat(const gfx_api::pixel_format& format, bool gles)
{
switch (format)
{
// UNCOMPRESSED FORMATS
case gfx_api::pixel_format::FORMAT_RGBA8_UNORM_PACK8:
return GL_RGBA8;
case gfx_api::pixel_format::FORMAT_BGRA8_UNORM_PACK8:
return GL_RGBA8; // must store as RGBA8
case gfx_api::pixel_format::FORMAT_RGB8_UNORM_PACK8:
return GL_RGB8;
case gfx_api::pixel_format::FORMAT_RG8_UNORM:
if (gles && GLAD_GL_EXT_texture_rg)
{
// the internal format is GL_RG_EXT
return GL_RG_EXT;
}
else
{
// for Desktop OpenGL, use GL_RG8 for the internal format
return GL_RG8;
}
case gfx_api::pixel_format::FORMAT_R8_UNORM:
if ((!gles && GLAD_GL_VERSION_3_0) || (gles && GLAD_GL_ES_VERSION_3_0))
{
// OpenGL 3.0+ or OpenGL ES 3.0+
return GL_R8;
}
else
{
// older version fallback
// use GL_LUMINANCE because:
// (a) it's available and
// (b) it ensures the single channel value ends up in "red" so the shaders don't have to care
return GL_LUMINANCE;
}
// COMPRESSED FORMAT
case gfx_api::pixel_format::FORMAT_RGB_BC1_UNORM:
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
case gfx_api::pixel_format::FORMAT_RGBA_BC2_UNORM:
return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
case gfx_api::pixel_format::FORMAT_RGBA_BC3_UNORM:
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
case gfx_api::pixel_format::FORMAT_R_BC4_UNORM:
return GL_COMPRESSED_RED_RGTC1;
case gfx_api::pixel_format::FORMAT_RG_BC5_UNORM:
return GL_COMPRESSED_RG_RGTC2;
case gfx_api::pixel_format::FORMAT_RGBA_BPTC_UNORM:
return GL_COMPRESSED_RGBA_BPTC_UNORM_ARB; // same value as GL_COMPRESSED_RGBA_BPTC_UNORM_EXT
case gfx_api::pixel_format::FORMAT_RGB8_ETC1:
return GL_ETC1_RGB8_OES;
case gfx_api::pixel_format::FORMAT_RGB8_ETC2:
return GL_COMPRESSED_RGB8_ETC2;
case gfx_api::pixel_format::FORMAT_RGBA8_ETC2_EAC:
return GL_COMPRESSED_RGBA8_ETC2_EAC;
case gfx_api::pixel_format::FORMAT_R11_EAC:
return GL_COMPRESSED_R11_EAC;
case gfx_api::pixel_format::FORMAT_RG11_EAC:
return GL_COMPRESSED_RG11_EAC;
case gfx_api::pixel_format::FORMAT_ASTC_4x4_UNORM:
return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
default:
debug(LOG_FATAL, "Unrecognised pixel format");
}
return GL_INVALID_ENUM;
}
static GLenum to_gl_format(const gfx_api::pixel_format& format, bool gles)
{
switch (format)
{
// UNCOMPRESSED FORMATS
case gfx_api::pixel_format::FORMAT_RGBA8_UNORM_PACK8:
return GL_RGBA;
case gfx_api::pixel_format::FORMAT_BGRA8_UNORM_PACK8:
return GL_BGRA;
case gfx_api::pixel_format::FORMAT_RGB8_UNORM_PACK8:
return GL_RGB;
case gfx_api::pixel_format::FORMAT_RG8_UNORM:
if (gles && GLAD_GL_EXT_texture_rg)
{
// the internal format is GL_RG_EXT
return GL_RG_EXT;
}
else
{
// for Desktop OpenGL, use GL_RG for the format
return GL_RG;
}
case gfx_api::pixel_format::FORMAT_R8_UNORM:
if ((!gles && GLAD_GL_VERSION_3_0) || (gles && GLAD_GL_ES_VERSION_3_0))
{
// OpenGL 3.0+ or OpenGL ES 3.0+
return GL_RED;
}
else
{
// older version fallback
// use GL_LUMINANCE because:
// (a) it's available and
// (b) it ensures the single channel value ends up in "red" so the shaders don't have to care
return GL_LUMINANCE;
}
// COMPRESSED FORMAT
default:
return to_gl_internalformat(format, gles);
}
return GL_INVALID_ENUM;
}
static GLenum to_gl(const gfx_api::context::buffer_storage_hint& hint)
{
switch (hint)
{
case gfx_api::context::buffer_storage_hint::static_draw:
return GL_STATIC_DRAW;
case gfx_api::context::buffer_storage_hint::dynamic_draw:
return GL_DYNAMIC_DRAW;
case gfx_api::context::buffer_storage_hint::stream_draw:
return GL_STREAM_DRAW;
default:
debug(LOG_FATAL, "Unsupported buffer hint");
}
return GL_INVALID_ENUM;
}
static GLenum to_gl(const gfx_api::buffer::usage& usage)
{
switch (usage)
{
case gfx_api::buffer::usage::index_buffer:
return GL_ELEMENT_ARRAY_BUFFER;
case gfx_api::buffer::usage::vertex_buffer:
return GL_ARRAY_BUFFER;
default:
debug(LOG_FATAL, "Unrecognised buffer usage");
}
return GL_INVALID_ENUM;
}
static GLenum to_gl(const gfx_api::primitive_type& primitive)
{
switch (primitive)
{
case gfx_api::primitive_type::lines:
return GL_LINES;
case gfx_api::primitive_type::line_strip:
return GL_LINE_STRIP;
case gfx_api::primitive_type::triangles:
return GL_TRIANGLES;
case gfx_api::primitive_type::triangle_strip:
return GL_TRIANGLE_STRIP;
default:
debug(LOG_FATAL, "Unrecognised primitive type");
}
return GL_INVALID_ENUM;
}
static GLenum to_gl(const gfx_api::index_type& index)
{
switch (index)
{
case gfx_api::index_type::u16:
return GL_UNSIGNED_SHORT;
case gfx_api::index_type::u32:
return GL_UNSIGNED_INT;
default:
debug(LOG_FATAL, "Unrecognised index type");
}
return GL_INVALID_ENUM;
}
static GLenum to_gl(const gfx_api::context::context_value property)
{
switch (property)
{
case gfx_api::context::context_value::MAX_ELEMENTS_VERTICES:
return GL_MAX_ELEMENTS_VERTICES;
case gfx_api::context::context_value::MAX_ELEMENTS_INDICES:
return GL_MAX_ELEMENTS_INDICES;
case gfx_api::context::context_value::MAX_TEXTURE_SIZE:
return GL_MAX_TEXTURE_SIZE;
case gfx_api::context::context_value::MAX_SAMPLES:
return GL_MAX_SAMPLES;
case gfx_api::context::context_value::MAX_ARRAY_TEXTURE_LAYERS:
return GL_MAX_ARRAY_TEXTURE_LAYERS;
case gfx_api::context::context_value::MAX_VERTEX_ATTRIBS:
return GL_MAX_VERTEX_ATTRIBS;
default:
debug(LOG_FATAL, "Unrecognised property type");
}
return GL_INVALID_ENUM;
}
// MARK: gl_gpurendered_texture
gl_gpurendered_texture::gl_gpurendered_texture()
{
glGenTextures(1, &_id);
}
gl_gpurendered_texture::~gl_gpurendered_texture()
{
glDeleteTextures(1, &_id);
}
void gl_gpurendered_texture::bind()
{
glBindTexture((_isArray) ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D, _id);
}
GLenum gl_gpurendered_texture::target() const
{
return (_isArray) ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
}
unsigned gl_gpurendered_texture::id() const
{
return _id;
}
size_t gl_gpurendered_texture::backend_internal_value() const
{
// not currently used in GL backend
return 0;
}
void gl_gpurendered_texture::unbind()
{
glBindTexture((_isArray) ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D, 0);
}
// MARK: gl_texture
gl_texture::gl_texture()
{
glGenTextures(1, &_id);
#if defined(WZ_DEBUG_GFX_API_LEAKS)
debugLiveTextures.insert(this);
#endif
}
gl_texture::~gl_texture()
{
glDeleteTextures(1, &_id);
#if defined(WZ_DEBUG_GFX_API_LEAKS)
debugLiveTextures.erase(this);
#endif
}
void gl_texture::bind()
{
glBindTexture(GL_TEXTURE_2D, _id);
}
size_t gl_texture::backend_internal_value() const
{
// not currently used in GL backend
return 0;
}
void gl_texture::unbind()
{
glBindTexture(GL_TEXTURE_2D, 0);
}
bool gl_texture::upload_internal(const size_t& mip_level, const size_t& offset_x, const size_t& offset_y, const iV_BaseImage& image)
{
ASSERT_OR_RETURN(false, image.data() != nullptr, "Attempt to upload image without data");
ASSERT_OR_RETURN(false, image.pixel_format() == internal_format, "Uploading image to texture with different format");
size_t width = image.width();
size_t height = image.height();
ASSERT(width > 0 && height > 0, "Attempt to upload texture with width or height of 0 (width: %zu, height: %zu)", width, height);
ASSERT(mip_level <= static_cast<size_t>(std::numeric_limits<GLint>::max()), "mip_level (%zu) exceeds GLint max", mip_level);
ASSERT(offset_x <= static_cast<size_t>(std::numeric_limits<GLint>::max()), "offset_x (%zu) exceeds GLint max", offset_x);
ASSERT(offset_y <= static_cast<size_t>(std::numeric_limits<GLint>::max()), "offset_y (%zu) exceeds GLint max", offset_y);
ASSERT(width <= static_cast<size_t>(std::numeric_limits<GLsizei>::max()), "width (%zu) exceeds GLsizei max", width);
ASSERT(height <= static_cast<size_t>(std::numeric_limits<GLsizei>::max()), "height (%zu) exceeds GLsizei max", height);
ASSERT(image.data_size() <= static_cast<size_t>(std::numeric_limits<GLsizei>::max()), "data_size (%zu) exceeds GLsizei max", image.data_size());
bind();
ASSERT(gfx_api::format_memory_size(image.pixel_format(), width, height) == image.data_size(), "data_size (%zu) does not match expected format_memory_size(%s, %zu, %zu)=%zu", image.data_size(), gfx_api::format_to_str(image.pixel_format()), width, height, gfx_api::format_memory_size(image.pixel_format(), width, height));
if (is_uncompressed_format(image.pixel_format()))
{
glTexSubImage2D(GL_TEXTURE_2D, static_cast<GLint>(mip_level), static_cast<GLint>(offset_x), static_cast<GLint>(offset_y), static_cast<GLsizei>(width), static_cast<GLsizei>(height), to_gl_format(image.pixel_format(), gles), GL_UNSIGNED_BYTE, image.data());
}
else
{
ASSERT_OR_RETURN(false, offset_x == 0 && offset_y == 0, "Trying to upload compressed sub texture");
GLenum glFormat = to_gl_internalformat(image.pixel_format(), gles);
glCompressedTexImage2D(GL_TEXTURE_2D, static_cast<GLint>(mip_level), glFormat, static_cast<GLsizei>(width), static_cast<GLsizei>(height), 0, static_cast<GLsizei>(image.data_size()), image.data());
}
unbind();
return true;
}
bool gl_texture::upload(const size_t& mip_level, const iV_BaseImage& image)
{
return upload_internal(mip_level, 0, 0, image);
}
bool gl_texture::upload_sub(const size_t& mip_level, const size_t& offset_x, const size_t& offset_y, const iV_Image& image)
{
return upload_internal(mip_level, offset_x, offset_y, image);
}
unsigned gl_texture::id()
{
return _id;
}
// MARK: texture_array_mip_level_buffer
struct texture_array_mip_level_buffer
{
public:
struct MipLevel
{
std::vector<uint8_t> buffer;
size_t width = 0;
size_t height = 0;
size_t memorySizePerLayer = 0;
};
private:
size_t mip_levels;
size_t layer_count;
size_t width;
size_t height;
gfx_api::pixel_format internal_format;
std::unordered_map<size_t, MipLevel> mipLevelDataBuffer;
private:
MipLevel& getMipLevel(size_t mip_level)
{
auto it = mipLevelDataBuffer.find(mip_level);
if (it != mipLevelDataBuffer.end())
{
return it->second;
}
MipLevel& level = mipLevelDataBuffer[mip_level];
level.width = std::max<size_t>(1, width >> mip_level);
level.height = std::max<size_t>(1, height >> mip_level);
level.memorySizePerLayer = gfx_api::format_memory_size(internal_format, level.width, level.height);
size_t mipLevelBufferSize = mipLevelDataBuffer[mip_level].memorySizePerLayer * layer_count;
level.buffer.resize(mipLevelBufferSize);
return level;
}
public:
texture_array_mip_level_buffer(const size_t& _mipmap_count, const size_t& _layer_count, const size_t& _width, const size_t& _height, const gfx_api::pixel_format& _internal_format)
: mip_levels(_mipmap_count)
, layer_count(_layer_count)
, width(_width)
, height(_height)
, internal_format(_internal_format)
{ }
public:
bool copy_data_to_buffer(size_t mip_level, size_t layer, const void* data, size_t data_size)
{
ASSERT_OR_RETURN(false, mip_level < mip_levels, "Invalid mip_level (%zu)", mip_level);
ASSERT_OR_RETURN(false, layer < layer_count, "Invalid layer (%zu)", layer);
MipLevel& level = getMipLevel(mip_level);
ASSERT_OR_RETURN(false, data_size == level.memorySizePerLayer, "Invalid data_size (%zu, expecting: %zu)", data_size, level.memorySizePerLayer);
size_t startingBufferOffset = level.memorySizePerLayer * layer;
memcpy(&(level.buffer[startingBufferOffset]), data, data_size);
return true;
}
const MipLevel* get_mip_level(size_t mip_level) const
{
auto it = mipLevelDataBuffer.find(mip_level);
if (it == mipLevelDataBuffer.end())
{
return nullptr;
}
return &(it->second);
}
const uint8_t* get_read_pointer(size_t mip_level) const
{
auto it = mipLevelDataBuffer.find(mip_level);
if (it == mipLevelDataBuffer.end())
{
return nullptr;
}
return it->second.buffer.data();
}
size_t get_buffer_size(size_t mip_level, size_t layer) const
{
auto it = mipLevelDataBuffer.find(mip_level);
if (it == mipLevelDataBuffer.end())
{
return 0;
}
return it->second.memorySizePerLayer;
}
void clear()
{
mipLevelDataBuffer.clear();
}
};
// MARK: gl_texture_array
gl_texture_array::gl_texture_array()
{
glGenTextures(1, &_id);
}
gl_texture_array::~gl_texture_array()
{
glDeleteTextures(1, &_id);
delete pInternalBuffer;
}
void gl_texture_array::bind()
{
glBindTexture(GL_TEXTURE_2D_ARRAY, _id);
}
void gl_texture_array::unbind()
{
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
}
size_t gl_texture_array::backend_internal_value() const
{
// not currently used in GL backend
return 0;
}
bool gl_texture_array::upload_internal(const size_t& layer, const size_t& mip_level, const size_t& offset_x, const size_t& offset_y, const iV_BaseImage& image)
{
ASSERT_OR_RETURN(false, image.data() != nullptr, "Attempt to upload image without data");
ASSERT_OR_RETURN(false, image.pixel_format() == internal_format, "Uploading image to texture with different format");
ASSERT_OR_RETURN(false, mip_level < mip_count, "mip_level (%zu) >= mip_count (%zu)", mip_level, mip_count);
size_t width = image.width();
size_t height = image.height();
ASSERT(width > 0 && height > 0, "Attempt to upload texture with width or height of 0 (width: %zu, height: %zu)", width, height);
ASSERT(layer <= static_cast<size_t>(std::numeric_limits<GLint>::max()), "layer (%zu) exceeds GLint max", layer);
ASSERT(mip_level <= static_cast<size_t>(std::numeric_limits<GLint>::max()), "mip_level (%zu) exceeds GLint max", mip_level);
ASSERT(offset_x <= static_cast<size_t>(std::numeric_limits<GLint>::max()), "offset_x (%zu) exceeds GLint max", offset_x);
ASSERT(offset_y <= static_cast<size_t>(std::numeric_limits<GLint>::max()), "offset_y (%zu) exceeds GLint max", offset_y);
ASSERT(width <= static_cast<size_t>(std::numeric_limits<GLsizei>::max()), "width (%zu) exceeds GLsizei max", width);
ASSERT(height <= static_cast<size_t>(std::numeric_limits<GLsizei>::max()), "height (%zu) exceeds GLsizei max", height);
ASSERT(image.data_size() <= static_cast<size_t>(std::numeric_limits<GLsizei>::max()), "data_size (%zu) exceeds GLsizei max", image.data_size());
bind();
ASSERT(gfx_api::format_memory_size(image.pixel_format(), width, height) == image.data_size(), "data_size (%zu) does not match expected format_memory_size(%s, %zu, %zu)=%zu", image.data_size(), gfx_api::format_to_str(image.pixel_format()), width, height, gfx_api::format_memory_size(image.pixel_format(), width, height));
// Copy to an internal buffer for upload on flush
ASSERT_OR_RETURN(false, offset_x == 0 && offset_y == 0, "Trying to upload compressed sub texture");
pInternalBuffer->copy_data_to_buffer(mip_level, layer, image.data(), image.data_size());
unbind();
return true;
}
bool gl_texture_array::upload_layer(const size_t& layer, const size_t& mip_level, const iV_BaseImage& image)
{
return upload_internal(layer, mip_level, 0, 0, image);
}
unsigned gl_texture_array::id()
{
return _id;
}
void gl_texture_array::flush()
{
if (pInternalBuffer)
{
// If compressed texture, upload each mip level with glCompressedTexImage3D from the client-side buffer
bind();
for (size_t i = 0; i < mip_count; ++i)
{
const texture_array_mip_level_buffer::MipLevel* pLevel = pInternalBuffer->get_mip_level(i);
if (!pLevel)
{
continue;
}
if (is_uncompressed_format(internal_format))
{
glTexImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(i), to_gl_internalformat(internal_format, gles), static_cast<GLsizei>(pLevel->width), static_cast<GLsizei>(pLevel->height), static_cast<GLsizei>(layer_count), 0, to_gl_format(internal_format, gles), GL_UNSIGNED_BYTE, pLevel->buffer.data());
}
else
{
glCompressedTexImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(i), to_gl_internalformat(internal_format, gles), static_cast<GLsizei>(pLevel->width), static_cast<GLsizei>(pLevel->height), static_cast<GLsizei>(layer_count), 0, static_cast<GLsizei>(pLevel->buffer.size()), pLevel->buffer.data());
}
}
unbind();
pInternalBuffer->clear();
}
}
// MARK: gl_buffer
gl_buffer::gl_buffer(const gfx_api::buffer::usage& usage, const gfx_api::context::buffer_storage_hint& hint)
: usage(usage)
, hint(hint)
{
glGenBuffers(1, &buffer);
}
gl_buffer::~gl_buffer()
{
glDeleteBuffers(1, &buffer);
}
void gl_buffer::bind()
{
glBindBuffer(to_gl(usage), buffer);
}
void gl_buffer::unbind()
{
glBindBuffer(to_gl(usage), 0);
}
void gl_buffer::upload(const size_t & size, const void * data)
{
size_t current_FrameNum = gfx_api::context::get().current_FrameNum();
#if defined(DEBUG)
ASSERT(lastUploaded_FrameNum != current_FrameNum, "Attempt to upload to buffer more than once per frame");
#endif
lastUploaded_FrameNum = current_FrameNum;
ASSERT(size > 0, "Attempt to upload buffer of size 0");
glBindBuffer(to_gl(usage), buffer);
glBufferData(to_gl(usage), size, data, to_gl(hint));
buffer_size = size;
glBindBuffer(to_gl(usage), 0);
}
void gl_buffer::update(const size_t & start, const size_t & size, const void * data, const update_flag flag)
{
size_t current_FrameNum = gfx_api::context::get().current_FrameNum();
#if defined(DEBUG)
ASSERT(flag == update_flag::non_overlapping_updates_promise || (lastUploaded_FrameNum != current_FrameNum), "Attempt to upload to buffer more than once per frame");
#endif
lastUploaded_FrameNum = current_FrameNum;
ASSERT(start < buffer_size, "Starting offset (%zu) is past end of buffer (length: %zu)", start, buffer_size);
ASSERT(start + size <= buffer_size, "Attempt to write past end of buffer");
if (size == 0)
{
debug(LOG_WARNING, "Attempt to update buffer with 0 bytes of new data");
return;
}
glBindBuffer(to_gl(usage), buffer);
glBufferSubData(to_gl(usage), start, size, data);
glBindBuffer(to_gl(usage), 0);
}
// MARK: gl_pipeline_state_object
struct program_data
{
std::string friendly_name;
std::string vertex_file;
std::string fragment_file;
std::vector<std::string> uniform_names;
std::vector<std::tuple<std::string, GLint>> additional_samplers = {};
};
static const std::map<SHADER_MODE, program_data> shader_to_file_table =
{
std::make_pair(SHADER_COMPONENT, program_data{ "Component program", "shaders/tcmask.vert", "shaders/tcmask.frag",
{
// per-frame global uniforms
"ProjectionMatrix", "ViewMatrix", "ShadowMapMVPMatrix", "lightPosition", "sceneColor", "ambient", "diffuse", "specular", "fogColor", "fogEnd", "fogStart", "graphicsCycle", "fogEnabled",
// per-mesh uniforms
"tcmask", "normalmap", "specularmap", "hasTangents",
// per-instance uniforms
"ModelViewMatrix", "NormalMatrix", "colour", "teamcolour", "stretch", "animFrameNumber", "ecmEffect", "alphaTest"
} }),
std::make_pair(SHADER_COMPONENT_INSTANCED, program_data{ "Component program", "shaders/tcmask_instanced.vert", "shaders/tcmask_instanced.frag",
{
// per-frame global uniforms
"ProjectionMatrix", "ViewMatrix", "ShadowMapMVPMatrix", "lightPosition", "sceneColor", "ambient", "diffuse", "specular", "fogColor", "ShadowMapCascadeSplits", "ShadowMapSize", "fogEnd", "fogStart", "graphicsCycle", "fogEnabled",
// per-mesh uniforms
"tcmask", "normalmap", "specularmap", "hasTangents"
},
{
{"shadowMap", 4}
} }),
std::make_pair(SHADER_COMPONENT_DEPTH_INSTANCED, program_data{ "Component program", "shaders/tcmask_depth_instanced.vert", "shaders/tcmask_depth_instanced.frag",
{
// per-frame global uniforms
"ProjectionMatrix", "ViewMatrix"
} }),
std::make_pair(SHADER_NOLIGHT, program_data{ "Plain program", "shaders/nolight.vert", "shaders/nolight.frag",
{
// per-frame global uniforms
"ProjectionMatrix", "ViewMatrix", "ShadowMapMVPMatrix", "lightPosition", "sceneColor", "ambient", "diffuse", "specular", "fogColor", "fogEnd", "fogStart", "graphicsCycle", "fogEnabled",
// per-mesh uniforms
"tcmask", "normalmap", "specularmap", "hasTangents",
// per-instance uniforms
"ModelViewMatrix", "NormalMatrix", "colour", "teamcolour", "stretch", "animFrameNumber", "ecmEffect", "alphaTest"
} }),
std::make_pair(SHADER_NOLIGHT_INSTANCED, program_data{ "Plain program", "shaders/nolight_instanced.vert", "shaders/nolight_instanced.frag",
{
// per-frame global uniforms
"ProjectionMatrix", "ViewMatrix", "ShadowMapMVPMatrix", "lightPosition", "sceneColor", "ambient", "diffuse", "specular", "fogColor", "ShadowMapCascadeSplits", "ShadowMapSize", "fogEnd", "fogStart", "graphicsCycle", "fogEnabled",
// per-mesh uniforms
"tcmask", "normalmap", "specularmap", "hasTangents",
},
{
{"shadowMap", 4}
} }),
std::make_pair(SHADER_TERRAIN, program_data{ "terrain program", "shaders/terrain.vert", "shaders/terrain.frag",
{ "ModelViewProjectionMatrix", "paramx1", "paramy1", "paramx2", "paramy2", "tex", "lightmap_tex", "textureMatrix1", "textureMatrix2",
"fogColor", "fogEnabled", "fogEnd", "fogStart" } }),
std::make_pair(SHADER_TERRAIN_DEPTH, program_data{ "terrain_depth program", "shaders/terrain_depth.vert", "shaders/terraindepth.frag",
{ "ModelViewProjectionMatrix", "paramx2", "paramy2", "lightmap_tex", "paramx2", "paramy2", "fogEnabled", "fogEnd", "fogStart" } }),
std::make_pair(SHADER_TERRAIN_DEPTHMAP, program_data{ "terrain_depthmap program", "shaders/terrain_depth_only.vert", "shaders/terrain_depth_only.frag",
{ "ModelViewProjectionMatrix", "fogEnabled", "fogEnd", "fogStart" } }),
std::make_pair(SHADER_DECALS, program_data{ "decals program", "shaders/decals.vert", "shaders/decals.frag",
{ "ModelViewProjectionMatrix", "lightTextureMatrix", "paramxlight", "paramylight",
"fogColor", "fogEnabled", "fogEnd", "fogStart", "tex", "lightmap_tex" } }),
std::make_pair(SHADER_TERRAIN_COMBINED_CLASSIC, program_data{ "terrain decals program", "shaders/terrain_combined.vert", "shaders/terrain_combined_classic.frag",
{ "ModelViewProjectionMatrix", "ViewMatrix", "ModelUVLightmapMatrix", "ShadowMapMVPMatrix", "groundScale",
"cameraPos", "sunPos", "emissiveLight", "ambientLight", "diffuseLight", "specularLight",
"fogColor", "ShadowMapCascadeSplits", "ShadowMapSize", "fogEnabled", "fogEnd", "fogStart", "quality",
"lightmap_tex",
"groundTex", "groundNormal", "groundSpecular", "groundHeight",
"decalTex", "decalNormal", "decalSpecular", "decalHeight", "shadowMap" } }),
std::make_pair(SHADER_TERRAIN_COMBINED_MEDIUM, program_data{ "terrain decals program", "shaders/terrain_combined.vert", "shaders/terrain_combined_medium.frag",
{ "ModelViewProjectionMatrix", "ViewMatrix", "ModelUVLightmapMatrix", "ShadowMapMVPMatrix", "groundScale",
"cameraPos", "sunPos", "emissiveLight", "ambientLight", "diffuseLight", "specularLight",
"fogColor", "ShadowMapCascadeSplits", "ShadowMapSize", "fogEnabled", "fogEnd", "fogStart", "quality",
"lightmap_tex",
"groundTex", "groundNormal", "groundSpecular", "groundHeight",
"decalTex", "decalNormal", "decalSpecular", "decalHeight", "shadowMap" } }),
std::make_pair(SHADER_TERRAIN_COMBINED_HIGH, program_data{ "terrain decals program", "shaders/terrain_combined.vert", "shaders/terrain_combined_high.frag",
{ "ModelViewProjectionMatrix", "ViewMatrix", "ModelUVLightmapMatrix", "ShadowMapMVPMatrix", "groundScale",
"cameraPos", "sunPos", "emissiveLight", "ambientLight", "diffuseLight", "specularLight",
"fogColor", "ShadowMapCascadeSplits", "ShadowMapSize", "fogEnabled", "fogEnd", "fogStart", "quality",
"lightmap_tex",
"groundTex", "groundNormal", "groundSpecular", "groundHeight",
"decalTex", "decalNormal", "decalSpecular", "decalHeight", "shadowMap" } }),
std::make_pair(SHADER_WATER, program_data{ "water program", "shaders/terrain_water.vert", "shaders/water.frag",
{ "ModelViewProjectionMatrix", "ModelUVLightmapMatrix", "ModelUV1Matrix", "ModelUV2Matrix",
"cameraPos", "sunPos",
"emissiveLight", "ambientLight", "diffuseLight", "specularLight",
"fogColor", "fogEnabled", "fogEnd", "fogStart", "timeSec",
"tex1", "tex2", "lightmap_tex" } }),
std::make_pair(SHADER_WATER_HIGH, program_data{ "high water program", "shaders/terrain_water_high.vert", "shaders/terrain_water_high.frag",
{ "ModelViewProjectionMatrix", "ModelUVLightmapMatrix", "ModelUV1Matrix", "ModelUV2Matrix",
"cameraPos", "sunPos",
"emissiveLight", "ambientLight", "diffuseLight", "specularLight",
"fogColor", "fogEnabled", "fogEnd", "fogStart", "timeSec",
"tex", "tex_nm", "tex_sm", "lightmap_tex" } }),
std::make_pair(SHADER_WATER_CLASSIC, program_data{ "classic water program", "shaders/terrain_water_classic.vert", "shaders/terrain_water_classic.frag",
{ "ModelViewProjectionMatrix", "ModelUVLightmapMatrix", "ShadowMapMVPMatrix", "ModelUV1Matrix", "ModelUV2Matrix",
"cameraPos", "sunPos",
"fogColor", "fogEnabled", "fogEnd", "fogStart", "timeSec",
"lightmap_tex", "tex2"} }),
std::make_pair(SHADER_RECT, program_data{ "Rect program", "shaders/rect.vert", "shaders/rect.frag",
{ "transformationMatrix", "color" } }),
std::make_pair(SHADER_RECT_INSTANCED, program_data{ "Rect program", "shaders/rect_instanced.vert", "shaders/rect_instanced.frag",
{ "ProjectionMatrix" } }),
std::make_pair(SHADER_TEXRECT, program_data{ "Textured rect program", "shaders/rect.vert", "shaders/texturedrect.frag",
{ "transformationMatrix", "tuv_offset", "tuv_scale", "color", "texture" } }),
std::make_pair(SHADER_GFX_COLOUR, program_data{ "gfx_color program", "shaders/gfx.vert", "shaders/gfx.frag",
{ "posMatrix" } }),
std::make_pair(SHADER_GFX_TEXT, program_data{ "gfx_text program", "shaders/gfx.vert", "shaders/texturedrect.frag",
{ "posMatrix", "color", "texture" } }),
std::make_pair(SHADER_SKYBOX, program_data{ "skybox program", "shaders/skybox.vert", "shaders/skybox.frag",
{ "posMatrix", "color", "fog_color", "fog_enabled" } }),
std::make_pair(SHADER_GENERIC_COLOR, program_data{ "generic color program", "shaders/generic.vert", "shaders/rect.frag",{ "ModelViewProjectionMatrix", "color" } }),
std::make_pair(SHADER_LINE, program_data{ "line program", "shaders/line.vert", "shaders/rect.frag",{ "from", "to", "color", "ModelViewProjectionMatrix" } }),
std::make_pair(SHADER_TEXT, program_data{ "Text program", "shaders/rect.vert", "shaders/text.frag",
{ "transformationMatrix", "tuv_offset", "tuv_scale", "color", "texture" } }),
std::make_pair(SHADER_DEBUG_TEXTURE2D_QUAD, program_data{ "Debug texture quad program", "shaders/quad_texture2d.vert", "shaders/quad_texture2d.frag",
{ "transformationMatrix", "uvTransformMatrix", "swizzle", "color", "texture" } }),
std::make_pair(SHADER_DEBUG_TEXTURE2DARRAY_QUAD, program_data{ "Debug texture array quad program", "shaders/quad_texture2darray.vert", "shaders/quad_texture2darray.frag",
{ "transformationMatrix", "uvTransformMatrix", "swizzle", "color", "layer", "texture" } }),
std::make_pair(SHADER_WORLD_TO_SCREEN, program_data{ "World to screen quad program", "shaders/world_to_screen.vert", "shaders/world_to_screen.frag",
{ "gamma" } })
};
enum SHADER_VERSION
{
VERSION_120,
VERSION_130,
VERSION_140,
VERSION_150_CORE,
VERSION_330_CORE,
VERSION_400_CORE,
VERSION_410_CORE,
VERSION_FIXED_IN_FILE,
VERSION_AUTODETECT_FROM_LEVEL_LOAD
};
enum SHADER_VERSION_ES
{
VERSION_ES_100,
VERSION_ES_300
};
const char * shaderVersionString(SHADER_VERSION version)
{
switch(version)
{
case VERSION_120:
return "#version 120\n";
case VERSION_130:
return "#version 130\n";
case VERSION_140:
return "#version 140\n";
case VERSION_150_CORE:
return "#version 150 core\n";
case VERSION_330_CORE:
return "#version 330 core\n";
case VERSION_400_CORE:
return "#version 400 core\n";
case VERSION_410_CORE:
return "#version 410 core\n";
case VERSION_AUTODETECT_FROM_LEVEL_LOAD:
return "";
case VERSION_FIXED_IN_FILE:
return "";
// Deliberately omit "default:" case to trigger a compiler warning if the SHADER_VERSION enum is expanded but the new cases aren't handled here
}
return ""; // Should not not reach here - silence a GCC warning
}
const char * shaderVersionString(SHADER_VERSION_ES version)
{
switch(version)
{
case VERSION_ES_100:
return "#version 100\n";
case VERSION_ES_300:
return "#version 300 es\n";
// Deliberately omit "default:" case to trigger a compiler warning if the SHADER_VERSION_ES enum is expanded but the new cases aren't handled here
}
return ""; // Should not reach here - silence a GCC warning
}
GLint wz_GetGLIntegerv(GLenum pname, GLint defaultValue = 0)
{
GLint retVal = defaultValue;
ASSERT_OR_RETURN(retVal, glGetIntegerv != nullptr, "glGetIntegerv is null");
if (glGetError != nullptr)
{
while(glGetError() != GL_NO_ERROR) { } // clear the OpenGL error queue
}
glGetIntegerv(pname, &retVal);
GLenum err = GL_NO_ERROR;
if (glGetError != nullptr)
{
err = glGetError();
}
if (err != GL_NO_ERROR)
{
retVal = defaultValue;
}
return retVal;
}
SHADER_VERSION getMinimumShaderVersionForCurrentGLContext()
{
// Determine the shader version directive we should use by examining the current OpenGL context
GLint gl_majorversion = wz_GetGLIntegerv(GL_MAJOR_VERSION, 0);
GLint gl_minorversion = wz_GetGLIntegerv(GL_MINOR_VERSION, 0);
SHADER_VERSION version = VERSION_120; // for OpenGL < 3.2, we default to VERSION_120 shaders
if ((gl_majorversion > 3) || ((gl_majorversion == 3) && (gl_minorversion >= 2)))
{
// OpenGL 3.2+
// Since WZ only supports Core contexts with OpenGL 3.2+, we cannot use the version_120 directive
// (which only works in compatibility contexts). Instead, use GLSL version "150 core".
version = VERSION_150_CORE;
}
return version;
}
SHADER_VERSION getMaximumShaderVersionForCurrentGLContext(SHADER_VERSION minSupportedShaderVersion = VERSION_120, SHADER_VERSION maxSupportedShaderVersion = VERSION_410_CORE)
{
ASSERT(minSupportedShaderVersion <= maxSupportedShaderVersion, "minSupportedShaderVersion > maxSupportedShaderVersion");
// Instead of querying the GL_SHADING_LANGUAGE_VERSION string and trying to parse it,
// which is rife with difficulties because drivers can report very different strings (and formats),
// use the known (and explicit) mapping table between OpenGL version and supported GLSL version.
GLint gl_majorversion = wz_GetGLIntegerv(GL_MAJOR_VERSION, 0);
GLint gl_minorversion = wz_GetGLIntegerv(GL_MINOR_VERSION, 0);
// For OpenGL < 3.2, default to VERSION_120 shaders
SHADER_VERSION version = VERSION_120;
if(gl_majorversion == 3)
{
switch(gl_minorversion)
{
case 0: // 3.0 => 1.30
version = VERSION_130;
break;
case 1: // 3.1 => 1.40
version = VERSION_140;
break;
case 2: // 3.2 => 1.50
version = VERSION_150_CORE;
break;
case 3: // 3.3 => 3.30
version = VERSION_330_CORE;
break;
default:
// Return the 3.3 value
version = VERSION_330_CORE;
break;
}
}
else if (gl_majorversion == 4)
{
switch(gl_minorversion)
{
case 0: // 4.0 => 4.00
version = VERSION_400_CORE;
break;
case 1: // 4.1 => 4.10
version = VERSION_410_CORE;
break;
default:
// Return the 4.1 value
// NOTE: Nothing above OpenGL 4.1 is supported on macOS
version = VERSION_410_CORE;
break;
}
}
else if (gl_majorversion > 4)
{
// Return the OpenGL 4.1 value (for now)
version = VERSION_410_CORE;
}
version = std::max(version, minSupportedShaderVersion);
version = std::min(version, maxSupportedShaderVersion);
return version;
}
SHADER_VERSION_ES getMaximumShaderVersionForCurrentGLESContext(SHADER_VERSION_ES minSupportedShaderVersion = VERSION_ES_100, SHADER_VERSION_ES maxSupportedShaderVersion = VERSION_ES_300)
{
ASSERT(minSupportedShaderVersion <= maxSupportedShaderVersion, "minSupportedShaderVersion > maxSupportedShaderVersion");
// Instead of querying the GL_SHADING_LANGUAGE_VERSION string and trying to parse it,
// which is rife with difficulties because drivers can report very different strings (and formats),
// use the known (and explicit) mapping table between OpenGL version and supported GLSL version.
GLint gl_majorversion = wz_GetGLIntegerv(GL_MAJOR_VERSION, 0);
//GLint gl_minorversion = wz_GetGLIntegerv(GL_MINOR_VERSION, 0);
// For OpenGL ES < 3.0, default to VERSION_ES_100 shaders
SHADER_VERSION_ES version = VERSION_ES_100;
if(gl_majorversion == 3)
{
return VERSION_ES_300;
}
else if (gl_majorversion > 3)
{
// Return the OpenGL ES 3.0 value (for now)
version = VERSION_ES_300;
}
version = std::max(version, minSupportedShaderVersion);
version = std::min(version, maxSupportedShaderVersion);
return version;
}
template<SHADER_MODE shader>
typename std::pair<std::type_index, std::function<void(const void*, size_t)>> gl_pipeline_state_object::uniform_binding_entry()
{
return std::make_pair(std::type_index(typeid(gfx_api::constant_buffer_type<shader>)), [this](const void* buffer, size_t buflen) {
ASSERT_OR_RETURN(, buflen == sizeof(const gfx_api::constant_buffer_type<shader>), "Unexpected buffer size; received %zu, expecting %zu", buflen, sizeof(const gfx_api::constant_buffer_type<shader>));
this->set_constants(*reinterpret_cast<const gfx_api::constant_buffer_type<shader>*>(buffer));
});
}
template<typename T>
typename std::pair<std::type_index, std::function<void(const void*, size_t)>>gl_pipeline_state_object::uniform_setting_func()
{
return std::make_pair(std::type_index(typeid(T)), [this](const void* buffer, size_t buflen) {
ASSERT_OR_RETURN(, buflen == sizeof(const T), "Unexpected buffer size; received %zu, expecting %zu", buflen, sizeof(const T));
this->set_constants(*reinterpret_cast<const T*>(buffer));
});
}
gl_pipeline_state_object::gl_pipeline_state_object(bool gles, bool fragmentHighpFloatAvailable, bool fragmentHighpIntAvailable, bool patchFragmentShaderMipLodBias, const gfx_api::pipeline_create_info& createInfo, optional<float> mipLodBias, const gfx_api::shadow_constants& shadowConstants) :
desc(createInfo.state_desc), vertex_buffer_desc(createInfo.attribute_descriptions)
{
std::string vertexShaderHeader;
std::string fragmentShaderHeader;
if (!gles)
{
// Determine the shader version directive we should use by examining the current OpenGL context
// (The built-in shaders support (and have been tested with) VERSION_120, VERSION_150_CORE, VERSION_330_CORE)
const char *shaderVersionStr = shaderVersionString(getMaximumShaderVersionForCurrentGLContext(VERSION_120, VERSION_330_CORE));
vertexShaderHeader = shaderVersionStr;
fragmentShaderHeader = shaderVersionStr;
}
else
{
// Determine the shader version directive we should use by examining the current OpenGL ES context
// (The built-in shaders support (and have been tested with) VERSION_ES_100 and VERSION_ES_300)
const char *shaderVersionStr = shaderVersionString(getMaximumShaderVersionForCurrentGLESContext(VERSION_ES_100, VERSION_ES_300));
vertexShaderHeader = shaderVersionStr;
// OpenGL ES Shading Language - 4. Variables and Types - pp. 35-36
// https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf?#page=41
//
// > The fragment language has no default precision qualifier for floating point types.
// > Hence for float, floating point vector and matrix variable declarations, either the
// > declaration must include a precision qualifier or the default float precision must
// > have been previously declared.
fragmentShaderHeader = std::string(shaderVersionStr) + "#if GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\nprecision highp int;\n#else\nprecision mediump float;\n#endif\n";
fragmentShaderHeader += "#if __VERSION__ >= 300 || defined(GL_EXT_texture_array)\nprecision lowp sampler2DArray;\n#endif\n";
fragmentShaderHeader += "#if __VERSION__ >= 300\nprecision lowp sampler2DShadow;\nprecision lowp sampler2DArrayShadow;\n#endif\n";
}
build_program(fragmentHighpFloatAvailable, fragmentHighpIntAvailable, patchFragmentShaderMipLodBias,
shader_to_file_table.at(createInfo.shader_mode).friendly_name,
vertexShaderHeader.c_str(),
shader_to_file_table.at(createInfo.shader_mode).vertex_file,
fragmentShaderHeader.c_str(),
shader_to_file_table.at(createInfo.shader_mode).fragment_file,