-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpico_gl.h
7414 lines (6724 loc) · 310 KB
/
pico_gl.h
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
///=============================================================================
/// WARNING: This file was automatically generated on 27/06/2024 15:49:38.
/// DO NOT EDIT!
///============================================================================
/**
@file pico_gl.h
@brief A powerful OpenGL-based graphics library written in C99.
----------------------------------------------------------------------------
Licensing information at end of header
----------------------------------------------------------------------------
Features:
---------
- Written in C99
- Single header library for easy build system integration
- Embeds GLAD for seamless OpenGL function loading
- Simple texture and shader creation
- Default shader and uniforms
- Rendering of dynamic vertex arrays and static vertex buffers
- Render to texture
- Simplified shader uniform setters
- State stack
- Simple and concise API
- Permissive license (zlib or public domain)
Summary:
--------
This library is an advanced 2D renderer built on top of OpenGL. It currently
supports OpenGL 3.0+ and OpenGL ES 3+ as well.
The basic workflow is to initialize the library, create a context, load any
shaders and/or textures needed, specify some geometry (vertices) and draw
the buffer or array of vertices. A vertex consists of position, color, and
uv coordinates.
There is a default shader that makes sensible assumptions about how vertices
and textures will be used. It is likely to be sufficient unless performing
advanced VFX.
The default shader exposes two uniform variables: 1) a projection matrix;
and 2) an affine transformation matrix. These two matrices are multipled
together to form the mapping from vertices to the screen.
State including blend mode, the projection and transform matrices, and
the viewport parameters are managed using the state stack. This enables
state changes to be isolated. Push the current state on the top of the
stack, make some local changes, and pop the stack to restore the original
state.
Uniforms can be set using a simple, fast, and concise API.
Please see the examples for more details.
To use this library in your project, add
> #define PICO_GL_IMPLEMENTATION
> #include "pico_gl.h"
to a source file.
Constants:
--------
- PICO_GL_UNIFORM_NAME_LENGTH (default: 32)
- PICO_GL_MAX_UNIFORMS (default: 32)
- PICO_GL_MAX_STATES (default: 32)
Must be defined before PICO_GL_IMPLEMENTATION
Todo:
-----
- MSAA flag for examples
- Better version handling
- Shader examples
- Scissor
- Indexed buffers
- Multiple texture units
*/
#ifndef PICO_GL_H
#define PICO_GL_H
#include <stdbool.h> // bool, true, false
#include <stdarg.h> // va_list, va_start, va_end
#include <stddef.h> // size_t, NULL
#include <stdint.h> // uint32_t, int32_t, uint64_t
#include <stdio.h> // printf, vprintf
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief OpenGL compatible size type
*/
typedef uint32_t pgl_size_t;
/**
* @brief Runtime error codes
*/
typedef enum
{
PGL_NO_ERROR, //!< No error
PGL_INVALID_ENUM, //!< Invalid enumeration value
PGL_INVALID_VALUE, //!< Invalid value
PGL_INVALID_OPERATION, //!< Invalid operation
PGL_OUT_OF_MEMORY, //!< Out of memory
PGL_INVALID_FRAMEBUFFER_OPERATION, //!< Invalid framebuffer operation
PGL_FRAMEBUFFER_INCOMPLETE, //!< Framebuffer is incomplete
PGL_SHADER_COMPILATION_ERROR, //!< Shader compilation error
PGL_SHADER_LINKING_ERROR, //!< Shader linking error
PGL_INVALID_TEXTURE_SIZE, //!< Invalid texture dimensions
PGL_INVALID_TEXTURE_FORMAT, //!< Invalid texture format
PGL_INVALID_ATTRIBUTE_COUNT, //!< Invalid number of attributes
PGL_INVALID_UNIFORM_COUNT, //!< Invalid number of uniforms
PGL_INVALID_UNIFORM_NAME, //!< Invalid uniform name
PGL_UNKNOWN_ERROR, //!< Unknown error
PGL_ERROR_COUNT
} pgl_error_t;
/**
* @brief OpenGL versions used by the library
*/
typedef enum
{
PGL_GL3,
PGL_GLES3,
PGL_VERSION_UNSUPPORTED
} pgl_version_t;
/**
* @brief Pixel formats
*/
typedef enum
{
PGL_RED, //!< (red, 0, 0, 1)
PGL_RGB, //!< (red, green, blue, 1)
PGL_RGBA, //!< (red, green, blue, alpha)
PGL_BGR, //!< (blue, green, red, 1)
PGL_BGRA, //!< (blue, green, red, alpha)
PGL_FORMAT_COUNT
} pgl_format_t;
/**
* @brief Blend factors
*/
typedef enum
{
PGL_ZERO, //!< (0, 0, 0, 0)
PGL_ONE, //!< (1, 1, 1, 1)
PGL_SRC_COLOR, //!< (src.r, src.g, src.b, src.a)
PGL_ONE_MINUS_SRC_COLOR, //!< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
PGL_DST_COLOR, //!< (dst.r, dst.g, dst.b, dst.a)
PGL_ONE_MINUS_DST_COLOR, //!< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
PGL_SRC_ALPHA, //!< (src.a, src.a, src.a, src.a)
PGL_ONE_MINUS_SRC_ALPHA, //!< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
PGL_DST_ALPHA, //!< (dst.a, dst.a, dst.a, dst.a)
PGL_ONE_MINUS_DST_ALPHA, //!< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
PGL_FACTOR_COUNT
} pgl_blend_factor_t;
/**
* @brief Blend equations
*/
typedef enum
{
PGL_FUNC_ADD, //!< result = src * src_factor + dst * dst_factor
PGL_FUNC_SUBTRACT, //!< result = src * src_factor - dst * dst_factor
PGL_FUNC_REVERSE_SUBTRACT, //!< result = dst * dst_factor - src * src_factor
PGL_MIN, //!< result = min(src, dst)
PGL_MAX, //!< result = max(src, dst)
PGL_EQ_COUNT
} pgl_blend_eq_t;
/**
* @brief Blend mode
*
* Completely describes a blend operation.
*/
typedef struct
{
pgl_blend_factor_t color_src; //!< Color source blending factor
pgl_blend_factor_t color_dst; //!< Color dsestination blending factor
pgl_blend_eq_t color_eq; //!< Equation for blending colors
pgl_blend_factor_t alpha_src; //!< Alpha source blending factor
pgl_blend_factor_t alpha_dst; //!< Alpha destination blending factor
pgl_blend_eq_t alpha_eq; //!< Equation for blending alpha values
} pgl_blend_mode_t;
/**
* @brief Drawing primitives
*/
typedef enum
{
PGL_POINTS, //!< Array of points
PGL_LINES, //!< Each adjacent pair of points forms a line
PGL_LINE_STRIP, //!< Array of points where every pair forms a lines
PGL_TRIANGLES, //!< Each adjacent triple forms an individual triangle
PGL_TRIANGLE_STRIP, //!< Array of points where every triple forms a triangle
} pgl_primitive_t;
/**
* @brief A vertex describes a point and the data associated with it (color and
* texture coordinates)
*/
typedef struct
{
float pos[3];
float color[4];
float uv[2];
} pgl_vertex_t;
/**
* @brief 2D floating point vector
*/
typedef float pgl_v2f_t[2];
/**
* @brief 3D floating point vector
*/
typedef float pgl_v3f_t[3];
/**
* @brief 4D floating point vector
*/
typedef float pgl_v4f_t[4];
/**
* @brief 2D integer vector
*/
typedef int32_t pgl_v2i_t[2];
/**
* @brief 3D integer vector
*/
typedef int32_t pgl_v3i_t[3];
/**
* @brief 4D integer vector
*/
typedef int32_t pgl_v4i_t[4];
/**
* @brief 2x2 floating point matrix
*/
typedef float pgl_m2_t[4];
/**
* @brief 3x3 floating point matrix
*/
typedef float pgl_m3_t[9];
/**
* @brief 4x4 floating point matrix
*/
typedef float pgl_m4_t[16];
/**
* @brief Contains core data/state for an instance of the renderer
*/
typedef struct pgl_ctx_t pgl_ctx_t;
/**
* @brief Contains shader data/state
*/
typedef struct pgl_shader_t pgl_shader_t;
/**
* @brief Contains texture data/state
*/
typedef struct pgl_texture_t pgl_texture_t;
/**
* @brief Contains vertex buffer data/state
*/
typedef struct pgl_buffer_t pgl_buffer_t;
/**
* @brief Defines an OpenGL (GLAD) function loader
*
* @param name The name of the function to load
*/
typedef void* (*pgl_loader_fn)(const char* name);
/**
* @brief Loads all supported OpenGL functions via GLAD
*
* IMPORTANT: A valid OpenGL context must exist for this function to succeed.
* This function must be called before any other PGL functions.
*
* @param loader_fp Function loader (can be NULL except for GLES contexts)
* @param gles Set to \em true if using OpenGL ES
*
* @returns -1 on failure and 0 otherwise
*/
int pgl_global_init(pgl_loader_fn loader_fp, bool gles);
/**
* @brief Returns the current error code
*/
pgl_error_t pgl_get_error(pgl_ctx_t* ctx);
/**
* @brief Returns the string associated with the specified error code
*
* @param code The error code to query
*
* @returns The string representation of the error code
*/
const char* pgl_get_error_str(pgl_error_t code);
/**
* @brief Returns the current OpenGL version in use by the library.
*
* Currently the library does not use OpenGL features outside of 3.0 and ES 3.0.
* This unlikely to change unless there is an incompatibility with more recent
* versions or the library is ported to OpenGL 2.1.
*
* @returns PGL_VERSION_UNSUPPORTED if the version of OpenGL is not supported
*/
pgl_version_t pgl_get_version();
/**
* @brief Prints system info
*/
void pgl_print_info();
/**
* @brief Creates an instance of the renderer
*
* @param w The drawable width of the window in pixels
* @param h The drawable height of the window in pixels
* @param depth Depth test is enabled if true
* @param samples The number of MSAA (anti-alising) samples (disabled if 0)
* @param srgb Enables support for the sRGB colorspace
* @param mem_ctx User data provided to custom allocators
*
* @returns The context pointer or \em NULL on error
*/
pgl_ctx_t* pgl_create_context(uint32_t w, uint32_t h, bool depth,
uint32_t samples, bool srgb,
void* mem_ctx);
/**
* @brief Destroys a renderer context, releasing it's resources
*
* @param ctx A pointer to the context
*/
void pgl_destroy_context(pgl_ctx_t* ctx);
/**
* @brief Resizes the drawable dimensions
*
* @param ctx A pointer to the context
* @param w The drawable width of the window in pixels
* @param h The drawable height of the window in pixels
* @pawram reset_vp Resets the viewport if true
*/
void pgl_resize(pgl_ctx_t* ctx, uint32_t w, uint32_t h, bool reset_vp);
/**
* @brief Creates a shader program
*
* If `vert_src` and `frag_src` are both `NULL`, then the shader is compiled
* from the default vertex and fragment sources. If either `vert_src` or
* `frag_src` are `NULL`, then the shader is compiled from the (respective)
* default vertex or fragment source, together with the non-`NULL` argument.
*
* @param ctx The relevant context
* @param vert_src Vertex shader source
* @param frag_src Fragment shader source
* @returns Pointer to the shader program, or \em NULL on error
*/
pgl_shader_t* pgl_create_shader(pgl_ctx_t* ctx, const char* vert_src,
const char* frag_src);
/**
* @brief Destroys a shader program
*
* @param shader Pointer to the shader program
*/
void pgl_destroy_shader(pgl_shader_t* shader);
/**
* @brief Activates a shader program for rendering
*
* This function sets the context's currently active shader. If `shader` is
* `NULL` the current shader is deactivated.
*
* @param ctx The relevant context
* @param shader The shader program to activate, or `NULL` to deactivate
*/
void pgl_bind_shader(pgl_ctx_t* ctx, pgl_shader_t* shader);
/**
* @brief Return the implementation specific shader ID
*
* @param shader The target shader
*
* @returns An unsigned 64-bit ID value
*/
uint64_t pgl_get_shader_id(const pgl_shader_t* shader);
/**
* @brief Creates an empty texture
*
* @param ctx The relevant context
* @param target If true, the texture can be used as a render target
* @param w The texture's width
* @param h The texture's height
* @param srgb True if the internal format is sRGB
* @param smooth High (true) or low (false) quality filtering
* @param repeat Repeats or clamps when uv coordinates exceed 1.0
*/
pgl_texture_t* pgl_create_texture(pgl_ctx_t* ctx,
bool target,
pgl_format_t fmt, bool srgb,
int32_t w, int32_t h,
bool smooth, bool repeat);
/**
* @brief Creates a texture from a bitmap
*
* @param ctx The relevant context
* @param w The texture's width
* @param h The texture's height
* @param srgb True if the internal format is sRGB
* @param smooth High (true) or low (false) quality filtering
* @param repeat Repeats or clamps when uv coordinates exceed 1.0
* @param bitmap Pixel data in RGBA format
*/
pgl_texture_t* pgl_texture_from_bitmap(pgl_ctx_t* ctx,
pgl_format_t fmt, bool srgb,
int32_t w, int32_t h,
bool smooth, bool repeat,
const uint8_t* bitmap);
/**
* @brief Uploads data from a bitmap into a texture
*
* @param ctx The relevant context
* @param texture The target texture
* @param w The texture's width
* @param h The texture's height
* @param bitmap The pixel data in RGBA
*/
int pgl_upload_texture(pgl_ctx_t* ctx,
pgl_texture_t* texture,
int32_t w, int32_t h,
const uint8_t* bitmap);
/**
* @brief Updates a region of an existing texture
*
* @param ctx The relevant context
* @param texture The texture to update
* @param x The x offset of the region
* @param y The y offset of the region
* @param w The width of the region
* @param h The height of the region
* @param bitmap The pixel data in RGBA
*/
void pgl_update_texture(pgl_ctx_t* ctx,
pgl_texture_t* texture,
int x, int y,
int w, int h,
const uint8_t* bitmap);
/**
* @brief Generate mipmaps for the specified texture
*
* Generates a sequence of smaller pre-filtered / pre-optimized textures
* intended to reduce the effects of aliasing when rendering smaller versions
* of the texture.
*
* @param texture Pointer to the target texture
* @param linear Determines the selection of the which mipmap to blend
*
* @returns 0 on success and -1 on failure
*/
int pgl_generate_mipmap(pgl_texture_t* texture, bool linear);
/**
* @brief Destroys a texture
*
* @param texture Texture to destroy
*/
void pgl_destroy_texture(pgl_texture_t* texture);
/**
* @brief Gets texture size
*
* @param texture The texture
* @param w Pointer to width (output)
* @param h Pointer to height (output)
*/
void pgl_get_texture_size(const pgl_texture_t* texture, int* w, int* h);
/**
* Gets maximum texture size as reported by OpenGL
*
* @param w Pointer to width (output)
* @param h Poineter to height (output)
*/
void pgl_get_max_texture_size(int* w, int* h);
/**
* @brief Return the implementation specific texture ID
*
* @param texture The target texture
*
* @returns An unsigned 64-bit ID value
*/
uint64_t pgl_get_texture_id(const pgl_texture_t* texture);
/**
* @brief Activates a texture for rendering
*
* This function sets the context's currently texture. If `texture` is
* `NULL` the current texture is deactivated.
*
* @param ctx The relevant context
* @param texture The texture to activate, or `NULL` to deactivate
*/
void pgl_bind_texture(pgl_ctx_t* ctx, pgl_texture_t* texture);
/**
* @brief Draw to texture
*
* The function set a texture to be the target for rendering until the texture
* if replaced by another or set to `NULL`.
*
* @param ctx The relevant context
* @param texture The render target
*
* @returns 0 on success and -1 on failure
*/
int pgl_set_render_target(pgl_ctx_t* ctx, pgl_texture_t* texture);
/**
* @brief Clears the framebuffer to the specified color
*
* All of the parameters are in `[0.0, 1.0]`
*/
void pgl_clear(float r, float g, float b, float a);
/**
* Draws primitives according to a vertex array
*
* @param ctx The relevant context
* @param primitive The type of geometry to draw
* @param vertices A vertex array
* @param count The number of vertices
* @param texture The texture to draw from (can be `NULL`)
* @param shader The shader used to draw the array (cannot be `NULL`)
*/
void pgl_draw_array(pgl_ctx_t* ctx,
pgl_primitive_t primitive,
const pgl_vertex_t* vertices,
pgl_size_t count,
pgl_texture_t* texture,
pgl_shader_t* shader);
/**
* Draws primvities according to vertex and index arrays
*
* @param ctx The relevant context
* @param primitive The type of geometry to draw
* @param vertices An array of vertices
* @param vertex_count The number of vertices
* @param indices An array of indices
* @param index_ count The number of indicies
* @param texture The texture to draw from (can be `NULL`)
* @param shader The shader used to draw the array (cannot be `NULL`)
*/
void pgl_draw_indexed_array(pgl_ctx_t* ctx,
pgl_primitive_t primitive,
const pgl_vertex_t* vertices, pgl_size_t vertex_count,
const uint32_t* indices, pgl_size_t index_count,
pgl_texture_t* texture,
pgl_shader_t* shader);
/**
* @brief Creates a buffer in VRAM to store an array of vertices that can then
* be rendered without having upload the vertices every time they are drawn
*
* @param ctx The relevant context
* @param primitive The type of geometry to draw
* @param vertices A vertex array
* @param count The number of vertices to store in the buffer
*
* @returns A pointer to the buffer or `NULL` on error
*/
pgl_buffer_t* pgl_create_buffer(pgl_ctx_t* ctx,
pgl_primitive_t primitive,
const pgl_vertex_t* vertices,
pgl_size_t count);
/**
* @brief Substitutes the data in a buffer with new data
*
* @param ctx The relevant context
* @param buffer The buffer to write to
* @param vertices A vertex array
* @param count The number of vertices to substitute.
*/
void pgl_sub_buffer_data(pgl_ctx_t *ctx,
pgl_buffer_t* buffer,
const pgl_vertex_t* vertices,
pgl_size_t count,
pgl_size_t offset);
/**
* @brief Destroys a previously created buffer
*/
void pgl_destroy_buffer(pgl_buffer_t* buffer);
/**
* @brief Draw a previously created buffer
*
* @param ctx The relevant context
* @param buffer The buffer to draw
* @param start The base vertex index
* @param count The number of vertices to draw from `start`
* @param texture The texture to draw from (can be `NULL`)
* @param shader The shader used to draw the array (cannot be `NULL`)
*/
void pgl_draw_buffer(pgl_ctx_t* ctx,
const pgl_buffer_t* buffer,
pgl_size_t start, pgl_size_t count,
pgl_texture_t* texture,
pgl_shader_t* shader);
/**
* @brief Turns matrix transposition on/off
*/
void pgl_set_transpose(pgl_ctx_t* ctx, bool enabled);
/**
* @brief Set the blending mode
*
* @param ctx The relevant context
* @param mode The blending mode (@see pgl_blend_mode_t)
*/
void pgl_set_blend_mode(pgl_ctx_t* ctx, pgl_blend_mode_t mode);
/**
* @brief Resets the blend mode to standard alpha blending
*
* @param ctx The relevant context
*/
void pgl_reset_blend_mode(pgl_ctx_t* ctx);
/**
* @brief Sets the context's global tranformation matrix
*
* @param ctx The relevant context
* @param matrix The global transform matrix
*/
void pgl_set_transform(pgl_ctx_t* ctx, const pgl_m4_t matrix);
/**
* @brief 3D variant of `pgl_set_transform`
*
* @param ctx The relevant context
* @param matrix The 3D global transform matrix
*/
void pgl_set_transform_3d(pgl_ctx_t* ctx, const pgl_m3_t matrix);
/**
* @brief Resets the context's transform to the identity matrix
*
* @param ctx The relevant context
*/
void pgl_reset_transform(pgl_ctx_t* ctx);
/**
* @brief Sets a context's global projecton matrix
*
* @param ctx The relevant context
* @param matrix The global projection matrix
*/
void pgl_set_projection(pgl_ctx_t* ctx, const pgl_m4_t matrix);
/**
* @brief 3D variant of `pgl_set_projection`
*
* @param ctx The relevant context
* @param matrix The 3D global projection matrix
*/
void pgl_set_projection_3d(pgl_ctx_t* ctx, const pgl_m3_t matrix);
/**
* @brief Resets the context's project to the identity matrix
*
* @param ctx The relevant context
*/
void pgl_reset_projection(pgl_ctx_t* ctx);
/**
* @brief Sets the location and dimensions of the rendering viewport
*
* @param ctx The relevant context
* @param x The left edge of the viewport
* @param y The bottom edge of the viewport
* @param w The width of the viewport
* @param h The height of the viewort
*/
void pgl_set_viewport(pgl_ctx_t* ctx, int32_t x, int32_t y,
int32_t w, int32_t h);
/**
* @brief Reset the viewport to the drawable dimensions of the context
*
* @param ctx The relevant context
*/
void pgl_reset_viewport(pgl_ctx_t* ctx);
/**
@brief Sets the line primitive width
*/
void pgl_set_line_width(pgl_ctx_t* ctx, float line_width);
/**
* @brief Resets the line width to 1.0f
*/
void pgl_reset_line_width(pgl_ctx_t* ctx);
/**
* @brief Resets the current state of the context
*
* Resets the global transform, projection, blend mode, and viewport.
*
* @param ctx The relevant context
*/
void pgl_reset_state(pgl_ctx_t* ctx);
/**
* @brief Pushes the current state onto the state stack, allowing it to be
* restored later
*
* @param ctx The relevant context
*/
void pgl_push_state(pgl_ctx_t* ctx);
/**
* @brief Pops a state off of the state stack and makes it the current state
*
* @param ctx The relevant context
*/
void pgl_pop_state(pgl_ctx_t* ctx);
/**
* @brief Removes all states from the state stack
*
* @param ctx The relevant context
*/
void pgl_clear_stack(pgl_ctx_t* ctx);
/**
* @brief Sets a boolean uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param value The boolean value
*/
void pgl_set_bool(pgl_shader_t* shader, const char* name, bool value);
/**
* @brief Sets an integer uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param value The integer value
*/
void pgl_set_1i(pgl_shader_t* shader, const char* name, int32_t a);
/**
* @brief Sets a 2D integer uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param a The first value
* @param b The second value
*/
void pgl_set_2i(pgl_shader_t* shader, const char* name, int32_t a, int32_t b);
/**
* @brief Sets a 3D integer uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param a The first value
* @param b The second value
* @param c The third value
*/
void pgl_set_3i(pgl_shader_t* shader, const char* name, int32_t a, int32_t b, int32_t c);
/**
* @brief Sets a 4D integer uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param a The first value
* @param b The second value
* @param c The third value
* @param d The fourth value
*/
void pgl_set_4i(pgl_shader_t* shader, const char* name, int32_t a, int32_t b,
int32_t c, int32_t d);
/**
* @brief Sets a 2D integer uniform by vector
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param vec The vector
*/
void pgl_set_v2i(pgl_shader_t* shader, const char* name, const pgl_v2i_t vec);
/**
* @brief Sets a 3D integer uniform by vector
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param vec The vector
*/
void pgl_set_v3i(pgl_shader_t* shader, const char* name, const pgl_v3i_t vec);
/**
* @brief Sets a 4D integer uniform by vector
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param vec The vector
*/
void pgl_set_v4i(pgl_shader_t* shader, const char* name, const pgl_v4i_t vec);
/**
* @brief Sets an floating point uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param x The float value
*/
void pgl_set_1f(pgl_shader_t* shader, const char* name, float x);
/**
* @brief Sets a 2D floating point uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param x The first value
* @param y The second value
*/
void pgl_set_2f(pgl_shader_t* shader, const char* name, float x, float y);
/**
* @brief Sets a 3D floating point uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param x The first value
* @param y The second value
* @param z The third value
*/
void pgl_set_3f(pgl_shader_t* shader, const char* name, float x, float y, float z);
/**
* @brief Sets a 4D floating point uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param x The first value
* @param y The second value
* @param w The third value
* @param z The fourth value
*/
void pgl_set_4f(pgl_shader_t* shader, const char* name, float x, float y,
float z, float w);
/**
* @brief Sets a 2D floating point uniform by vector
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param vec The vector
*/
void pgl_set_v2f(pgl_shader_t* shader, const char* name, const pgl_v2f_t vec);
/**
* @brief Sets a 3D floating point uniform by vector
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param vec The vector
*/
void pgl_set_v3f(pgl_shader_t* shader, const char* name, const pgl_v3f_t vec);
/**
* @brief Sets a 4D floating point uniform by vector
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param vec The vector
*/
void pgl_set_v4f(pgl_shader_t* shader, const char* name, const pgl_v4f_t vec);
/**
* @brief Sends an array of floating point numbers
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param array The array of floats
* @param count The size of the array
*/
void pgl_set_a1f(pgl_shader_t* shader,
const char* name,
const float array[],
pgl_size_t count);
/**
* @brief Sends an array of 2D floating point vectors
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param array The array of vectors
* @param count The size of the array
*/
void pgl_set_a2f(pgl_shader_t* shader,
const char* name,
const pgl_v2f_t array[],
pgl_size_t count);
/**
* @brief Sends an array of 3D floating point vectors
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param array The array of vectors
* @param count The size of the array
*/
void pgl_set_a3f(pgl_shader_t* shader,
const char* name,
const pgl_v3f_t array[],
pgl_size_t count);
/**
* @brief Sends an array of 4D floating point vectors
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param array The array of vectors
* @param count The size of the array
*/
void pgl_set_a4f(pgl_shader_t* shader,
const char* name,
const pgl_v4f_t array[],
pgl_size_t count);
/**
* @brief Sets a 2x2 floating point matrix
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param matrix The matrix
*/
void pgl_set_m2(pgl_shader_t* shader, const char* name, const pgl_m2_t matrix);
/**
* @brief Sets a 3x3 floating point matrix
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param matrix The matrix
*/
void pgl_set_m3(pgl_shader_t* shader, const char* name, const pgl_m3_t matrix);
/**
* @brief Sets a 4x4 floating point matrix
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param matrix The matrix
*/
void pgl_set_m4(pgl_shader_t* shader, const char* name, const pgl_m4_t matrix);
/**
* @brief Sets a 2D sampler uniform
*
* @param shader The uniform's shader program
* @param name The name of the uniform
* @param value The sampler's texture unit
*/
void pgl_set_s2d(pgl_shader_t* shader, const char* name, int32_t value);
#endif // PICO_GL_H