-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy path2d.h
More file actions
1496 lines (1197 loc) · 43.8 KB
/
2d.h
File metadata and controls
1496 lines (1197 loc) · 43.8 KB
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
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#ifndef _GRAPHICS_H
#define _GRAPHICS_H
#include "globalincs/flagset.h"
#include "globalincs/pstypes.h"
#include "bmpman/bmpman.h"
#include "cfile/cfile.h"
#include "graphics/grinternal.h"
#include "graphics/tmapper.h"
#include "io/cursor.h"
#include "math/vecmat.h"
#include "osapi/osapi.h"
#include "utils/id.h"
// Forward definition
namespace graphics {
namespace util {
class UniformBuffer;
class GPUMemoryHeap;
} // namespace util
} // namespace graphics
namespace scripting {
template<typename condition_t>
class OverridableHook;
}
extern const float Default_min_draw_distance;
extern const float Default_max_draw_distance;
extern float Min_draw_distance_cockpit;
extern float Min_draw_distance;
extern float Max_draw_distance;
extern int Gr_inited;
// z-buffering stuff
extern int gr_zbuffering, gr_zbuffering_mode;
extern int gr_global_zbuffering;
extern bool Gr_enable_soft_particles;
FLAG_LIST(FramebufferEffects){Thrusters = 0, Shockwaves, NUM_VALUES};
extern flagset<FramebufferEffects> Gr_framebuffer_effects;
enum class AntiAliasMode {
None = 0,
FXAA_Low = 1,
FXAA_Medium = 2,
FXAA_High = 3,
SMAA_Low = 4,
SMAA_Medium = 5,
SMAA_High = 6,
SMAA_Ultra = 7,
};
extern AntiAliasMode Gr_aa_mode;
extern AntiAliasMode Gr_aa_mode_last_frame;
bool gr_is_fxaa_mode(AntiAliasMode mode);
bool gr_is_smaa_mode(AntiAliasMode mode);
extern bool Gr_post_processing_enabled;
extern bool Gr_enable_vsync;
extern bool Deferred_lighting;
extern bool High_dynamic_range;
extern os::ViewportState Gr_configured_window_state;
extern const std::shared_ptr<scripting::OverridableHook<void>> OnFrameHook;
class material;
class model_material;
class particle_material;
class distortion_material;
class shield_material;
class movie_material;
class batched_bitmap_material;
class nanovg_material;
class decal_material;
class interface_material;
class transform_stack {
matrix4 Current_transform;
SCP_vector<matrix4> Stack;
public:
transform_stack()
{
vm_matrix4_set_identity(&Current_transform);
Stack.clear();
Stack.push_back(Current_transform);
}
const matrix4 &get_transform() const
{
return Current_transform;
}
void clear()
{
vm_matrix4_set_identity(&Current_transform);
Stack.clear();
Stack.push_back(Current_transform);
}
void push_and_replace(const matrix4 &new_transform)
{
Current_transform = new_transform;
Stack.push_back(Current_transform);
}
void push(const vec3d *pos, const matrix *orient, const vec3d *scale = NULL)
{
vec3d new_scale = SCALE_IDENTITY_VECTOR;
matrix new_orient = IDENTITY_MATRIX;
vec3d new_pos = ZERO_VECTOR;
matrix4 current_transform_copy = Current_transform;
matrix4 new_transform;
if ( pos != NULL ) {
new_pos = *pos;
}
if ( orient != NULL ) {
new_orient = *orient;
}
if ( scale != NULL ) {
new_scale = *scale;
}
vm_vec_scale(&new_orient.vec.rvec, new_scale.xyz.x);
vm_vec_scale(&new_orient.vec.uvec, new_scale.xyz.y);
vm_vec_scale(&new_orient.vec.fvec, new_scale.xyz.z);
vm_matrix4_set_transform(&new_transform, &new_orient, &new_pos);
vm_matrix4_x_matrix4(&Current_transform, ¤t_transform_copy, &new_transform);
Stack.push_back(Current_transform);
}
void pop()
{
if ( Stack.size() > 1 ) {
Stack.pop_back();
}
Current_transform = Stack.back();
}
size_t depth() {
return Stack.size();
}
};
enum primitive_type {
PRIM_TYPE_POINTS,
PRIM_TYPE_LINES,
PRIM_TYPE_LINESTRIP,
PRIM_TYPE_TRIS,
PRIM_TYPE_TRISTRIP,
PRIM_TYPE_TRIFAN,
};
enum shader_type {
SDR_TYPE_NONE = -1,
SDR_TYPE_MODEL,
SDR_TYPE_EFFECT_PARTICLE,
SDR_TYPE_EFFECT_DISTORTION,
SDR_TYPE_POST_PROCESS_MAIN,
SDR_TYPE_POST_PROCESS_BLUR,
SDR_TYPE_POST_PROCESS_BLOOM_COMP,
SDR_TYPE_POST_PROCESS_BRIGHTPASS,
SDR_TYPE_POST_PROCESS_FXAA,
SDR_TYPE_POST_PROCESS_FXAA_PREPASS,
SDR_TYPE_POST_PROCESS_LIGHTSHAFTS,
SDR_TYPE_POST_PROCESS_TONEMAPPING,
SDR_TYPE_DEFERRED_LIGHTING,
SDR_TYPE_DEFERRED_CLEAR,
SDR_TYPE_VIDEO_PROCESS,
SDR_TYPE_PASSTHROUGH_RENDER, //!< Shader for doing the old style fixed-function rendering. Only used internally, use
//!< SDR_TYPE_DEFAULT_MATERIAL.
SDR_TYPE_SHIELD_DECAL,
SDR_TYPE_BATCHED_BITMAP,
SDR_TYPE_DEFAULT_MATERIAL,
SDR_TYPE_NANOVG,
SDR_TYPE_DECAL,
SDR_TYPE_SCENE_FOG,
SDR_TYPE_VOLUMETRIC_FOG,
SDR_TYPE_ROCKET_UI,
SDR_TYPE_COPY,
SDR_TYPE_COPY_WORLD,
SDR_TYPE_MSAA_RESOLVE,
SDR_TYPE_POST_PROCESS_SMAA_EDGE,
SDR_TYPE_POST_PROCESS_SMAA_BLENDING_WEIGHT,
SDR_TYPE_POST_PROCESS_SMAA_NEIGHBORHOOD_BLENDING,
SDR_TYPE_ENVMAP_SPHERE_WARP,
SDR_TYPE_IRRADIANCE_MAP_GEN,
SDR_TYPE_SHADOW_MAP,
NUM_SHADER_TYPES
};
// Shader flags
#define SDR_FLAG_PARTICLE_POINT_GEN (1<<0)
#define SDR_FLAG_BLUR_HORIZONTAL (1<<0)
#define SDR_FLAG_BLUR_VERTICAL (1<<1)
#define SDR_FLAG_NANOVG_EDGE_AA (1<<0)
#define SDR_FLAG_DECAL_USE_NORMAL_MAP (1<<0)
#define SDR_FLAG_MSAA_SAMPLES_4 (1 << 0)
#define SDR_FLAG_MSAA_SAMPLES_8 (1 << 1)
#define SDR_FLAG_MSAA_SAMPLES_16 (1 << 2)
#define SDR_FLAG_VOLUMETRICS_DO_EDGE_SMOOTHING (1<<0)
#define SDR_FLAG_VOLUMETRICS_NOISE (1<<1)
#define SDR_FLAG_COPY_FROM_ARRAY (1 << 0)
#define SDR_FLAG_TONEMAPPING_LINEAR_OUT (1 << 0)
#define SDR_FLAG_ENV_MAP (1 << 0)
enum class uniform_block_type {
Lights = 0,
ModelData = 1,
NanoVGData = 2,
DecalInfo = 3,
DecalGlobals = 4,
DeferredGlobals = 5,
Matrices = 6,
MovieData = 7,
GenericData = 8,
NUM_BLOCK_TYPES
};
struct vertex_format_data
{
enum vertex_format {
POSITION4,
POSITION3,
POSITION2,
COLOR3,
COLOR4,
COLOR4F,
TEX_COORD2,
TEX_COORD4,
NORMAL,
TANGENT,
MODEL_ID,
RADIUS,
UVEC,
MATRIX4,
};
vertex_format format_type;
size_t stride;
size_t offset;
size_t divisor;
size_t buffer_number;
vertex_format_data(vertex_format i_format_type, size_t i_stride, size_t i_offset, size_t i_divisor, size_t i_buffer_number) :
format_type(i_format_type), stride(i_stride), offset(i_offset), divisor(i_divisor), buffer_number(i_buffer_number) {}
static inline uint mask(vertex_format v_format) { return 1 << v_format; }
bool operator==(const vertex_format_data& other) const {
return format_type == other.format_type && stride == other.stride && offset == other.offset;
}
};
class vertex_layout
{
SCP_vector<vertex_format_data> Vertex_components;
uint Vertex_mask = 0;
SCP_unordered_map<size_t, size_t> Vertex_stride;
public:
vertex_layout() {}
size_t get_num_vertex_components() const { return Vertex_components.size(); }
const vertex_format_data* get_vertex_component(size_t index) const { return &Vertex_components[index]; }
bool resident_vertex_format(vertex_format_data::vertex_format format_type) const;
void add_vertex_component(vertex_format_data::vertex_format format_type, size_t stride, size_t offset, size_t divisor = 0, size_t buffer_number = 0);
size_t get_vertex_stride(size_t buffer_number = 0) const { return Vertex_stride.at(buffer_number); }
bool operator==(const vertex_layout& other) const;
size_t hash() const;
};
namespace std {
template<> struct hash<vertex_format_data> {
size_t operator()(const vertex_format_data& data) const;
};
template<> struct hash<vertex_layout> {
size_t operator()(const vertex_layout& data) const;
};
}
enum class gr_capability {
CAPABILITY_ENVIRONMENT_MAP,
CAPABILITY_NORMAL_MAP,
CAPABILITY_HEIGHT_MAP,
CAPABILITY_SOFT_PARTICLES,
CAPABILITY_DISTORTION,
CAPABILITY_POST_PROCESSING,
CAPABILITY_DEFERRED_LIGHTING,
CAPABILITY_SHADOWS,
CAPABILITY_THICK_OUTLINE,
CAPABILITY_BATCHED_SUBMODELS,
CAPABILITY_TIMESTAMP_QUERY,
CAPABILITY_SEPARATE_BLEND_FUNCTIONS,
CAPABILITY_PERSISTENT_BUFFER_MAPPING,
CAPABILITY_BPTC,
CAPABILITY_LARGE_SHADER,
CAPABILITY_INSTANCED_RENDERING,
CAPABILITY_QUERIES_REUSABLE
};
struct gr_capability_def {
gr_capability capability;
const char* parse_name;
};
extern gr_capability_def gr_capabilities[];
extern const size_t gr_capabilities_num;
enum class gr_property
{
UNIFORM_BUFFER_OFFSET_ALIGNMENT,
UNIFORM_BUFFER_MAX_SIZE,
MAX_ANISOTROPY
};
struct gr_buffer_handle_tag {
};
using gr_buffer_handle = ::util::ID<gr_buffer_handle_tag, int, -1>;
// stencil buffering stuff
extern int gr_stencil_mode;
/**
* This is a structure used by the shader to keep track
* of the values you want to use in the shade primitive.
*/
typedef struct shader {
ubyte r, g, b, c; // factors and constant
ubyte lookup[256];
} shader;
#define AC_TYPE_NONE 0 // Not an alphacolor
#define AC_TYPE_HUD 1 // Doesn't change hue depending on background. Used for HUD stuff.
#define AC_TYPE_BLEND 2 // Changes hue depending on background. Used for stars, etc.
// NEVER REFERENCE THESE VALUES OUTSIDE OF THE GRAPHICS LIBRARY!!!
// If you need to get the rgb values of a "color" struct call
// gr_get_colors after calling gr_set_colors_fast.
typedef struct color {
int is_alphacolor;
int alphacolor;
int magic;
ubyte red;
ubyte green;
ubyte blue;
ubyte alpha;
ubyte ac_type; // The type of alphacolor. See AC_TYPE_??? defines
ubyte raw8;
} color;
// Used by the team coloring code
typedef struct team_color {
struct {
float r, g, b;
} base;
struct {
float r, g, b;
} stripe;
} team_color;
typedef struct tsb_t {
vec3d tangent;
float scaler;
} tsb_t;
/**
* This should be basicly just like it is in the VB
* a list of triangles and their associated normals
*/
class poly_list {
// helper function struct that let's us sort the indices.
// an instance is fed into std::sort and std::lower_bound.
// overloaded operator() is used for the comparison function.
struct finder {
poly_list* search_list;
bool compare_indices;
vertex* vert_to_find;
vec3d* norm_to_find;
finder(poly_list* _search_list): search_list(_search_list), compare_indices(true), vert_to_find(NULL), norm_to_find(NULL) {}
finder(poly_list* _search_list, vertex* _vert, vec3d* _norm): search_list(_search_list), compare_indices(false), vert_to_find(_vert), norm_to_find(_norm) {}
bool operator()(const uint a, const uint b);
};
public:
poly_list(): n_verts(0), vert(NULL), norm(NULL), tsb(NULL), submodels(NULL), sorted_indices(NULL), currently_allocated(0) {}
~poly_list();
poly_list& operator=(const poly_list&);
void allocate(int size);
void make_index_buffer(SCP_vector<int> &vertex_list);
void calculate_tangent();
int n_verts;
vertex *vert;
vec3d *norm;
tsb_t *tsb;
int *submodels;
uint *sorted_indices;
int find_index(poly_list *plist, int idx);
int find_index_fast(poly_list *plist, int idx);
private:
int currently_allocated;
int find_first_vertex(int idx);
int find_first_vertex_fast(int idx);
void generate_sorted_index_list();
};
class buffer_data
{
public:
int flags;
int texture; // this is the texture the vertex buffer will use
size_t n_verts;
size_t index_offset;
const uint *get_index() const
{
return index;
}
uint i_first, i_last;
void release()
{
if (index) {
delete [] index;
index = NULL;
}
}
void assign(size_t i, uint j)
{
const_cast<uint *>(index)[i] = j;
if (i_first > i_last)
i_first = i_last = j;
else if (i_first > j)
i_first = j;
else if (i_last < j)
i_last = j;
}
// Constructor
buffer_data() :
flags(0), texture(-1), n_verts(0), index_offset(0),
i_first(1), i_last(0), index(NULL)
{
}
explicit buffer_data(size_t n_vrts) :
flags(0), texture(-1), n_verts(n_vrts), index_offset(0),
i_first(1), i_last(0), index(NULL)
{
if ( n_verts > 0 ) {
index = new(std::nothrow) uint[n_verts];
} else {
index = NULL;
}
}
// Copy-constructor
buffer_data(const buffer_data& other)
{
if ( other.index ) {
index = new(std::nothrow) uint[other.n_verts];
for (size_t i=0; i < other.n_verts; i++)
{
index[i] = other.index[i];
}
} else {
index = NULL;
}
flags = other.flags;
texture = other.texture;
n_verts = other.n_verts;
i_first = other.i_first;
i_last = other.i_last;
index_offset = other.index_offset;
}
// Copy-assignment operator
buffer_data& operator=(const buffer_data& rhs)
{
if (this != &rhs)
{
if ( index ) {
delete [] index;
}
if ( rhs.index && rhs.n_verts > 0 ) {
index = new(std::nothrow) uint[rhs.n_verts];
for (size_t i=0; i < rhs.n_verts; i++)
{
index[i] = rhs.index[i];
}
}
flags = rhs.flags;
texture = rhs.texture;
n_verts = rhs.n_verts;
i_first = rhs.i_first;
i_last = rhs.i_last;
index_offset = rhs.index_offset;
}
return *this;
}
// Destructor
~buffer_data()
{
release();
}
private:
uint *index;
};
class vertex_buffer
{
public:
int flags;
size_t stride;
size_t vertex_offset;
size_t vertex_num_offset;
poly_list *model_list;
SCP_vector<buffer_data> tex_buf;
vertex_layout layout;
vertex_buffer() :
flags(0), stride(0), vertex_offset(0), vertex_num_offset(0), model_list(NULL)
{
}
~vertex_buffer()
{
clear();
}
void release()
{
if (model_list) {
delete model_list;
model_list = NULL;
}
for (SCP_vector<buffer_data>::iterator tbi = tex_buf.begin(); tbi != tex_buf.end(); ++tbi) {
tbi->release();
}
}
void clear()
{
release();
tex_buf.clear();
}
};
struct indexed_vertex_source {
void* Vertex_list = nullptr;
void* Index_list = nullptr;
gr_buffer_handle Vbuffer_handle;
size_t Vertex_offset = 0;
size_t Base_vertex_offset = 0;
gr_buffer_handle Ibuffer_handle;
size_t Index_offset = 0;
uint Vertex_list_size = 0;
uint Index_list_size = 0;
};
struct light;
#define FIND_SCALED_NUM(x, x0, x1, y0, y1) ( ((((x) - (x0)) * ((y1) - (y0))) / ((x1) - (x0))) + (y0) )
#define GR_ALPHABLEND_NONE 0 // no blending
#define GR_ALPHABLEND_FILTER 1 // 50/50 mix of foreground, background, using intensity as alpha
#define GR_BITBLT_MODE_NORMAL 0 // Normal bitblting
#define GR_BITBLT_MODE_RLE 1 // RLE would be faster
// fog modes
#define GR_FOGMODE_NONE 0 // set this to turn off fog
#define GR_FOGMODE_FOG 1 // linear fog
enum class QueryType {
Timestamp
};
enum class BufferType {
Vertex,
Index,
Uniform
};
enum class BufferUsageHint { Static, Dynamic, Streaming, PersistentMapping };
/**
* @brief Type of a graphics sync object
*/
typedef void* gr_sync;
typedef struct screen {
int max_w = 0, max_h = 0; // Width and height
int max_w_unscaled = 0, max_h_unscaled = 0;
int max_w_unscaled_zoomed = 0, max_h_unscaled_zoomed = 0;
int center_w = 0, center_h = 0; // Width and height of center monitor
int center_offset_x = 0, center_offset_y = 0;
int save_max_w = 0, save_max_h = 0; // Width and height
int save_max_w_unscaled = 0, save_max_h_unscaled = 0;
int save_max_w_unscaled_zoomed = 0, save_max_h_unscaled_zoomed = 0;
int save_center_w = 0, save_center_h = 0; // Width and height of center monitor
int save_center_offset_x = 0, save_center_offset_y = 0;
int res = 0; // GR_640 or GR_1024
int mode = 0; // What mode gr_init was called with.
float aspect = 0.0f, clip_aspect = 0.0f; // Aspect ratio = 0, aspect of clip_width/clip_height
int rowsize = 0; // What you need to add to go to next row (includes bytes_per_pixel)
int bits_per_pixel = 0; // How many bits per pixel it is. (7,8,15,16,24,32)
int bytes_per_pixel = 0; // How many bytes per pixel (1,2,3,4)
int offset_x = 0, offset_y = 0; // The offsets into the screen
int offset_x_unscaled = 0, offset_y_unscaled = 0; // Offsets into the screen, in unscaled dimensions
int clip_width = 0, clip_height = 0;
int clip_width_unscaled = 0, clip_height_unscaled = 0; // Height and width of clip aread, in unscaled dimensions
// center of clip area
float clip_center_x = 0.0f, clip_center_y = 0.0f;
float fog_near = 0.0f, fog_far = 0.0f;
// the clip_l,r,t,b are used internally. left and top are
// actually always 0, but it's nice to have the code work with
// arbitrary clipping regions.
int clip_left = 0, clip_right = 0, clip_top = 0, clip_bottom = 0;
// same as above except in unscaled dimensions
int clip_left_unscaled = 0, clip_right_unscaled = 0, clip_top_unscaled = 0, clip_bottom_unscaled = 0;
int current_alphablend_mode = 0; // See GR_ALPHABLEND defines above
int current_bitblt_mode = 0; // See GR_BITBLT_MODE defines above
int current_bitmap = 0;
color current_color{};
color current_fog_color{}; // current fog color
color current_clear_color{}; // current clear color
shader current_shader{};
float current_alpha = 0.0f;
bool custom_size = false;
int rendering_to_texture = 0; // wich texture we are rendering to, -1 if the back buffer
int rendering_to_face = 0; // wich face of the texture we are rendering to, -1 if the back buffer
int envmap_render_target = 0;
int irrmap_render_target = -1; // Irradiance map for diffuse env lighting.
float line_width = 0.0f;
// switch onscreen, offscreen
std::function<void()> gf_flip;
std::function<void()> gf_setup_frame;
// sets the clipping region
std::function<void(int x, int y, int w, int h, int resize_mode)> gf_set_clip;
// resets the clipping region to entire screen
std::function<void()> gf_reset_clip;
// clears entire clipping region to current color
std::function<void()> gf_clear;
// dumps the current screen to a file
std::function<void(const char* filename)> gf_print_screen;
// dumps the current screen to a html blob string
std::function<SCP_string()> gf_blob_screen;
// transforms and dumps the current environment map to a file
std::function<void(const char* filename)> gf_dump_envmap;
// generate diffuse irradiance cubemap for IBL.
std::function<void()> gf_calculate_irrmap;
// Retrieves the zbuffer mode.
std::function<int()> gf_zbuffer_get;
// Sets mode. Returns previous mode.
std::function<int(int mode)> gf_zbuffer_set;
// Clears the zbuffer. If use_zbuffer is FALSE, then zbuffering mode is ignored and zbuffer is always off.
std::function<void(int use_zbuffer)> gf_zbuffer_clear;
// Set the stencil buffer mode. Returns previous mode
std::function<int(int mode)> gf_stencil_set;
// Clears the stencil buffer.
std::function<void()> gf_stencil_clear;
std::function<int(int mode, float alpha)> gf_alpha_mask_set;
// Saves screen. Returns an id you pass to restore and free.
std::function<int()> gf_save_screen;
// Resets clip region and copies entire saved screen to the screen.
std::function<void(int id)> gf_restore_screen;
// Frees up a saved screen.
std::function<void(int id)> gf_free_screen;
// grab a region of the screen. assumes data is large enough
std::function<void(int front, int w, int h, ubyte* data)> gf_get_region;
// poly culling
std::function<int(int cull)> gf_set_cull;
// color buffer writes
std::function<int(int mode)> gf_set_color_buffer;
// preload a bitmap into texture memory
std::function<int(int bitmap_num, int is_aabitmap)> gf_preload;
// set the color to be used when clearing the background
std::function<void(int r, int g, int b)> gf_set_clear_color;
// Here be the bitmap functions
std::function<void(bitmap_slot* slot, bool release)> gf_bm_free_data;
std::function<void(bitmap_slot* slot)> gf_bm_create;
std::function<void(bitmap_slot* slot)> gf_bm_init;
std::function<void()> gf_bm_page_in_start;
std::function<bool(int handle, bitmap* bm)> gf_bm_data;
std::function<int(int handle, int* width, int* height, int* bpp, int* mm_lvl, int flags)> gf_bm_make_render_target;
std::function<int(int handle, int face)> gf_bm_set_render_target;
std::function<void(int)> gf_set_texture_addressing;
std::function<gr_buffer_handle(BufferType type, BufferUsageHint usage)> gf_create_buffer;
std::function<void(gr_buffer_handle handle)> gf_delete_buffer;
std::function<void(gr_buffer_handle handle, size_t size, const void* data)> gf_update_buffer_data;
std::function<void(gr_buffer_handle handle, size_t offset, size_t size, const void* data)>
gf_update_buffer_data_offset;
std::function<void*(gr_buffer_handle handle)> gf_map_buffer;
std::function<void(gr_buffer_handle handle, size_t offset, size_t size)> gf_flush_mapped_buffer;
std::function<void(void* data, size_t size)> gf_update_transform_buffer;
// postprocessing effects
std::function<void(const char*, int, const vec3d*)> gf_post_process_set_effect;
std::function<void()> gf_post_process_set_defaults;
std::function<void()> gf_post_process_begin;
std::function<void()> gf_post_process_end;
std::function<void()> gf_post_process_save_zbuffer;
std::function<void()> gf_post_process_restore_zbuffer;
std::function<void(bool clearNonColorBufs)> gf_deferred_lighting_begin;
std::function<void()> gf_deferred_lighting_msaa;
std::function<void()> gf_deferred_lighting_end;
std::function<void()> gf_deferred_lighting_finish;
std::function<void()> gf_scene_texture_begin;
std::function<void()> gf_scene_texture_end;
std::function<void()> gf_copy_effect_texture;
std::function<void(int zbias)> gf_zbias;
std::function<void(int)> gf_set_fill_mode;
std::function<void(float width)> gf_set_line_width;
std::function<void(material* material_def, float rad)> gf_sphere;
std::function<int(shader_type type, unsigned int flags)> gf_maybe_create_shader;
std::function<void(const std::function<void(size_t, size_t)>& progress_callback)> gf_recompile_all_shaders;
std::function<void()> gf_clear_states;
std::function<void(int bitmap_handle, int bpp, const ubyte* data, int width, int height)> gf_update_texture;
std::function<void(void* data_out, int bitmap_num)> gf_get_bitmap_from_texture;
std::function<void(matrix4* shadow_view_matrix, const matrix* light_matrix, vec3d* eye_pos)> gf_shadow_map_start;
std::function<void()> gf_shadow_map_end;
std::function<void()> gf_start_decal_pass;
std::function<void()> gf_stop_decal_pass;
// new drawing functions
std::function<
void(model_material* material_info, indexed_vertex_source* vert_source, vertex_buffer* bufferp, size_t texi)>
gf_render_model;
std::function<void(shield_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
gr_buffer_handle buffer_handle,
int n_verts)>
gf_render_shield_impact;
std::function<void(material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int offset,
int n_verts,
gr_buffer_handle buffer_handle,
size_t buffer_offset)>
gf_render_primitives;
std::function<void(particle_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int offset,
int n_verts,
gr_buffer_handle buffer_handle)>
gf_render_primitives_particle;
std::function<void(distortion_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int offset,
int n_verts,
gr_buffer_handle buffer_handle)>
gf_render_primitives_distortion;
std::function<void(movie_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int n_verts,
gr_buffer_handle buffer,
size_t buffer_offset)>
gf_render_movie;
std::function<void(batched_bitmap_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int offset,
int n_verts,
gr_buffer_handle buffer_handle)>
gf_render_primitives_batched;
std::function<void(nanovg_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int offset,
int n_verts,
gr_buffer_handle buffer_handle)>
gf_render_nanovg;
std::function<void(decal_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int num_elements,
const indexed_vertex_source& buffers,
const gr_buffer_handle& instance_buffer,
int num_instances)>
gf_render_decals;
void (*gf_render_rocket_primitives)(interface_material* material_info,
primitive_type prim_type,
vertex_layout* layout,
int n_indices,
gr_buffer_handle vertex_buffer,
gr_buffer_handle index_buffer);
std::function<bool(gr_capability capability)> gf_is_capable;
std::function<bool(gr_property property, void* destination)> gf_get_property;
std::function<void(const char* name)> gf_push_debug_group;
std::function<void()> gf_pop_debug_group;
std::function<int()> gf_create_query_object;
std::function<void(int obj, QueryType type)> gf_query_value;
std::function<bool(int obj)> gf_query_value_available;
std::function<uint64_t(int obj)> gf_get_query_value;
std::function<void(int obj)> gf_delete_query_object;
std::unique_ptr<os::Viewport> (*gf_create_viewport)(const os::ViewPortProperties& props);
std::function<void(os::Viewport* view)> gf_use_viewport;
std::function<void(uniform_block_type bind_point, size_t offset, size_t size, gr_buffer_handle buffer)>
gf_bind_uniform_buffer;
std::function<gr_sync()> gf_sync_fence;
std::function<bool(gr_sync sync, uint64_t timeoutns)> gf_sync_wait;
std::function<void(gr_sync sync)> gf_sync_delete;
std::function<void(int x, int y, int width, int height)> gf_set_viewport;
std::function<void(bool set_override)> gf_override_fog;
// ImGui backend integration
std::function<void()> gf_imgui_new_frame;
std::function<void()> gf_imgui_render_draw_data;
//OpenXR functions
std::function<SCP_vector<const char*>()> gf_openxr_get_extensions;
std::function<bool()> gf_openxr_test_capabilities;
std::function<bool()> gf_openxr_create_session;
std::function<int64_t(const SCP_vector<int64_t>&)> gf_openxr_get_swapchain_format;
std::function<bool()> gf_openxr_acquire_swapchain_buffers;
std::function<bool()> gf_openxr_flip;
} screen;
/**
* @brief Scripting context render values
*/
typedef struct lua_screen {
bool active = false;
bool force_fso_context = false;
color current_color = {
0, // is_alphacolor
0, // alphacolor
0, // magic
255, // red
255, // green
255, // blue
255, // alpha
0, // ac_type
0 // raw8
};
float line_width = 1.0f;
int current_font_index = 0;
} lua_screen;
extern lua_screen gr_lua_screen;
bool gr_lua_context_active();
// Macros to easily choose been which context to use for color and line width
// Note that font is handled slightly differently for the normal game context by using it's own global in the FontManager namespace
// So FontManager::getCurrentFontIndex() is effectively its own macro
// Gets the current color between the game context and the lua context if active
#define GR_CURRENT_COLOR (gr_lua_context_active() ? gr_lua_screen.current_color : gr_screen.current_color)
// Gets the current line width between the game context and the lua contet if active
#define GR_CURRENT_LINE_WIDTH (gr_lua_context_active() ? gr_lua_screen.line_width : gr_screen.line_width)
// handy macro
#define GR_MAYBE_CLEAR_RES(bmap) do { int bmw = -1; int bmh = -1; if(bmap != -1){ bm_get_info( bmap, &bmw, &bmh, NULL, NULL, NULL); if((bmw != gr_screen.max_w) || (bmh != gr_screen.max_h)){gr_clear();} } else {gr_clear();} } while(false);
//Window's interface to set up graphics:
//--------------------------------------
// Call this at application startup
// # Software Re-added by Kazan --- THIS HAS TO STAY -- It is used by standalone!
#define GR_DEFAULT (-1) // set to use default settings
#define GR_STUB (100)
#define GR_OPENGL (104) // Use OpenGl hardware renderer
#define GR_VULKAN (105) // Use Vulkan hardware renderer