-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenGL-Cheatsheet.txt
More file actions
1070 lines (692 loc) · 31.3 KB
/
OpenGL-Cheatsheet.txt
File metadata and controls
1070 lines (692 loc) · 31.3 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
*
* BUFFER *
*
- glClearBufferfv
Description: Clear specified buffer(s) to a specific color.
Use: Rendering
Example:
glClearBufferfv(GL_COLOR, 0, red);
- glCreateBuffers
Description: Create specified number of buffer objects (and so corresponding names).
Use: Startup
Example:
GLuint buffer;
glCreateBuffers(1, &buffer);
- other -
GLuint buffers[2];
glCreateBuffers(2, &buffers[0]);
- glGenBuffers
Description: Create specified number of buffer object names (no buffer objects are associated with the returned buffer object names until they are first bound - in this situation, error occurs if try to allocate memory).
Use: Startup
Example:
See "glCreateBuffers".
- glIsBuffer
Description: Determine if a name corresponds to a buffer object.
Use: All
Example:
glIsBuffer(buffer).
- glBindBuffer
Description: Bind a buffer object to a buffer target (GL_ARRAY_BUFFER, GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, etc.); buffer value zero is reserved (unbinds any buffer object previously bound for specified buffer target).
Use: Rendering
Example:
glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glBindBufferBase
Description: Bind a buffer object to an indexed buffer target (GL_UNIFORM_BUFFER, GL_SHADER_STORAGE_BUFFER, GL_ATOMIC_COUNTER_BUFFER, or GL_TRANSFORM_FEEDBACK_BUFFER) i.e. to both specified indexed buffer target index and its generic binding point (like "glBindBuffer" does).
Use: Rendering
Example:
glBindBufferBase(GL_UNIFORM_BUFFER, 0, buffer);
- glBindBufferRange
Description: Bind a range of a buffer object to an indexed buffer target.
Use: Rendering
Example:
glBindBufferRange(GL_UNIFORM_BUFFER, 0, buffer, 0, 1024);
- glBufferStorage / glNamedBufferStorage
Description: Allocate memory (not need to be initialized) for specified buffer object (by target - matches bound buffer object - or by name). Immutable status (sign a contract with the API that says you will never be allowed to change certain properties of your object).
Use: Startup
Example:
glNamedBufferStorage(buffer,
1024 * 1024,
NULL,
GL_DYNAMIC_STORAGE_BIT & GL_MAP_WRITE_BIT);
- glBufferData / glNamedBufferData
Description: Orphan the old memory and allocate new storage. Can be called multiple times.
Use: Startup
Example:
glNamedBufferData(buffer,
1024 * 1024,
NULL,
GL_DYNAMIC_STORAGE_BIT & GL_MAP_WRITE_BIT);
- glBufferSubData / glNamedBufferSubData
Description: Copy data into a buffer object.
Use: Startup
Example:
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(data), data);
- glClearBufferData / glClearNamedBufferData
Description: Fill a buffer object's data store with a fixed value.
Use: Startup
Example:
glClearNamedBufferSubData(buffer, 0, sizeof(data), data);
- glClearBufferSubData / glClearNamedBufferSubData
Description: Fill all or part of buffer object's data store with a fixed value.
Use: Startup
Example:
glClearNamedBufferSubData(buffer, 0, sizeof(data), data);
- glMapBuffer / glMapNamedBuffer
Description: Map (get a pointer to the data store of) a buffer object.
Use: Startup
Example:
void* ptr = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
- glMapBufferRange / glMapNamedBufferRange
Description: Map only a specific range of the buffer object (grant also additional control). Generally preferred.
Use: Startup
Example:
void* ptr = glMapNamedBufferRange(buffer, 0, sizeof(data), GL_MAP_WRITE_BIT);
- glCopyBufferSubData / glCopyNamedBufferSubData
Description: Copy data between buffers (dedicated GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER targets - use when read and write buffers are bound to same target).
Use: Startup
Example:
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, 1024 * 1024);
- glUnmapBuffer / glUnmapNamedBuffer
Description: Unmap the buffer object.
Use: Startup
Example:
glUnmapNamedBuffer(buffer);
- glDeleteBuffers
Description: Delete specified number of buffer objects.
Use: Shutdown
Example:
glDeleteBuffers(1, &buffer);
- other -
glCreateBuffers(2, &buffers[0]);
*
* TEXTURE / IMAGE *
*
- glCreateTextures
Description: Create texture objects for specified effective texture target (GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.).
Use: Startup
Example:
GLuint texture;
glCreateTextures(GL_TEXTURE_2D, 1, &texture);
- glTexStorage2D / glTextureStorage2D
Description: Specify storage for all levels of a two-dimensional (or one-dimensional array) texture.
Use: Startup
Example:
glTextureStorage2D(texture, // Texture object
1, // 1 mipmap level
GL_RGBA32F, // 32-bit floating-point RGBA data
256, 256); // 256 x 256 texels
- glTexImage2D
Description: Specify a two-dimensional texture image.
Use: Startup
Example:
???
- glTexSubImage2D / glTextureSubImage2D
Description: Specify a two-dimensional texture subimage.
Use: Startup
Example:
glTextureSubImage2D(texture, // Texture object
0, // Level 0
0, 0, // Offset 0, 0
256, 256, // 256 x 256 texels, replace entire image
GL_RGBA, // Four-channel data
GL_FLOAT, // Floating-point data
data); // Pointer to data
- glClearTexImage
Description: Fill all a texture image (any texture type) with a constant value.
Use: Startup / Rendering
Example:
glClearTexImage(texture, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, data);
- glClearTexSubImage
Description: Fill all or part of a texture image with a constant value.
Use: Startup / Rendering
Example:
???
- glTexBuffer / glTextureBuffer
Description: Attach a buffer object's data store to a buffer texture object
Use: Startup
Example:
glTextureBuffer(tbo_[0], GL_RGBA32F, vbo_[kPositionA]);
- glTextureParameter*
Description: Set the parameters of a texture embedded sampler object.
GL_TEXTURE_MAG_FILTER: Magnification filtering mode
GL_TEXTURE_MIN_FILTER: Minification filtering mode
GL_NEAREST: Nearest neighbor filtering using only base mip level
GL_LINEAR: Linear interpolation filtering using only base mip level
GL_NEAREST_MIPMAP_NEAREST: Select nearest mip level and perform nearest neighbor filtering withing in
GL_NEAREST_MIPMAP_LINEAR: Perform linear interpolation between mip levels and perform nearest neighbor filtering withing in
GL_LINEAR_MIPMAP_NEAREST: Select nearest mip level and perform linear interpolation filtering withing in
GL_LINEAR_MIPMAP_LINEAR: Perform linear interpolation between mip levels and perform linear interpolation filtering withing in
GL_TEXTURE_BASE_LEVEL: Base mipmap level to use
GL_TEXTURE_MAX_LEVEL: Maximum mipmap level to use
GL_TEXTURE_WRAP_S: Width component wrapping mode
GL_TEXTURE_WRAP_T: Height component wrapping mode
GL_TEXTURE_WRAP_R: Depth component wrapping mode
GL_REPEAT
GL_MIRRORED_REPEAT
GL_CLAMP_TO_EDGE
GL_CLAMP_TO_BORDER
Use: Startup
Example:
glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glGenerateTextureMipmap
Description: Generate all the mip levels for a texture (require level 0 to be loaded).
Use: Startup
Example:
glGenerateTextureMipmap(texture);
- glBindTexture
Description: Bind a named texture object to a texturing target.
Use: Startup
Example:
glBindTexture(GL_TEXTURE_2D, texture);
- glBindTextureUnit
Description: Bind a named texture object to the specified texture unit.
Use: Startup
Example:
glBindTextureUnit(0, texture);
- glBindImageTexture
Description: Bind a named texture object to the specified image unit (specified format must match the class - number of channels and data type size - of texture internal format; specified access must fit shader code requirements).
Use: Startup
Example:
glBindImageTexture(0, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
- glDeleteTextures
Description: Delete named textures.
Use: Shutdown
Example:
glDeleteTextures(1, &texture);
*
* SAMPLER *
*
- glCreateSamplers
Description: Create sampler objects.
Use: Startup
Example:
GLuint sampler;
glCreateSamplers(1, &sampler);
- glSamplerParameter*
Description: Set the parameters of a sampler object.
Use: Startup
Example:
glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glBindSampler
Description: Bind a sampler object to one of the texture units.
Use: Startup
Example:
glBindSampler(0, sampler);
- glDeleteSamplers
Description: Delete named samplers.
Use: Shutdown
Example:
glDeleteSamplers(1, &sampler);
*
* SHADER *
*
- glCreateShader
Description: Create empty shader object (of specified type: GL_VERTEX_SHADER; GL_FRAGMENT_SHADER; ...), ready to accept source code and be compiled.
Use: Startup
Example:
GLuint vertex_shader;
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource
Description: Hand shader source code to the shader object so that it can keep a copy of it. The shader object stores a copy of our source code.
Use: Startup
Example:
static const GLchar* vertex_shader_source[] =
{
"#version 450 core \n"
" \n"
"void main(void) \n"
"{ \n"
" gl_Position = vec4(0.0, 0.0, 0.5, 1.0); \n"
"} \n"
};
glShaderSource(vertex_shader, 1, vertex_shader_source, NULL);
- glCompileShader
Description: Compile whatever source code is contained in the shader object (creates an intermediate binary representation that is also stored in the shader object).
Use: Startup
Example:
glCompileShader(vertex_shader);
- glDeleteShader
Description: Delete a shader object. Once a shader has been linked into a program object, the program contains the binary code and the shader is no longer needed.
Use: Startup
Example:
glDeleteShader(vertex_shader);
- glGetShaderiv
Description: Get information parameter (GL_SHADER_TYPE, GL_DELETE_STATUS, GL_COMPILE_STATUS, GL_INFO_LOG_LENGTH, GL_SHADER_SOURCE_LENGTH) from a shader object.
Use: Startup
Example:
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
- glGetShaderInfoLog
Description: Get information log from a shader object.
Use: Startup
Example:
glGetShaderInfoLog(shader, infoLogLength, NULL, &infoLog[0]);
*
* PROGRAM *
*
- glCreateProgram
Description: Create a program object to which you can attach shader objects.
Use: Startup
Example:
GLuint program;
program = glCreateProgram();
- glAttachShader
Description: Attach a shader object to a program object. Creates a reference to the shader; we can then delete it, knowing that the program object will hold onto the shader’s contents as long as it needs it.
Use: Startup
Example:
glAttachShader(program, vertex_shader);
- glLinkProgram
Description: Link all of the shader objects attached to a program object together into code that can be run on the graphics processor.
Use: Startup
Example:
glLinkProgram(program);
- glUseProgram
Description: Tell OpenGL to use our program object for rendering.
Use: Rendering
Example:
glUseProgram(program);
- glDeleteProgram
Description: Delete a program object.
Use: Shutdown
Example:
glDeleteProgram(program);
- glGetProgramiv
Description: Get information parameter (GL_ATTACHED_SHADERS, GL_DELETE_STATUS, GL_LINK_STATUS, GL_INFO_LOG_LENGTH, GL_ACTIVE_ATTRIBUTES, etc.) from a program object.
Use: Startup
Example:
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
- glGetProgramInfoLog
Description: Get information log from a program object.
Use: Startup
Example:
glGetProgramInfoLog(program, infoLogLength, NULL, &infoLog[0]);
- glProgramParameteri
Description: Set a parameter (GL_PROGRAM_SEPARABLE, and GL_PROGRAM_BINARY_RETRIEVABLE_HINT) of a program object.
- GL_PROGRAM_SEPARABLE - set a program object in separable mode (tell OpenGL not to eliminate any unused shader output; arrange any internal data layout so last shader in the program object can communicate with first shader in another program object with same input layout).
- GL_PROGRAM_BINARY_RETRIEVABLE_HINT - set a program object in retrievable mode (tell OpenGL you plan to get the binary data back from a program object so it should hang on to that binary and have it ready to pass).
Use: Startup
Example:
glProgramParameteri(program, GL_PROGRAM_SEPARABLE, GL_TRUE);
- glGetProgramInterfaceiv
Description: Query a property (GL_ACTIVE_RESOURCES, GL_MAX_NAME_LENGTH, GL_MAX_NUM_ACTIVE_VARIABLES, and GL_MAX_NUM_COMPATIBLE_SUBROUTINES) of an interface (GL_PROGRAM_INPUT, GL_PROGRAM_OUTPUT, GL_UNIFORM, GL_UNIFORM_BLOCK, GL_SHADER_STORAGE_BLOCK, GL_ATOMIC_COUNTER_BUFFER, etc.) in a program object.
Use: Startup
Example:
GLint outputs;
glGetProgramInterfaceiv(program, GL_PROGRAM_OUTPUT, GL_ACTIVE_RESOURCES, &outputs);
- glGetProgramResourceiv
Description: Query multiple properties (GL_TYPE, GL_ARRAY_SIZE, GL_LOCATION, GL_LOCATION_INDEX, etc.) of a single active resource within an interface in a program object.
Use: Startup
Example:
const GLenum properties[] = { GL_TYPE, GL_LOCATION };
GLint parameters[2];
glGetProgramResourceiv(program, GL_PROGRAM_OUTPUT, 0, 2, properties, sizeof(parameters), NULL, parameters);
- glGetProgramResourceIndex
Description: Query the index of a resource (by name) within an interface in a program object.
Use: Startup
Example:
GLint index = glGetProgramResourceIndex(program, GL_FRAGMENT_SUBROUTINE, "myFunction1");
- glGetProgramResourceName
Description: Query the name of a resource (by index) within an interface in a program object.
Use: Startup
Example:
GLchar name[64];
glGetProgramResourceName(program, GL_PROGRAM_OUTPUT, 0, sizeof(name), NULL, name);
- glGetProgramStageiv
Description: Query a property (GL_ACTIVE_SUBROUTINE_UNIFORMS, GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS, GL_ACTIVE_SUBROUTINES, GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH, and GL_ACTIVE_SUBROUTINE_MAX_LENGTH) of a shader stage in a program object.
Use: Startup
Example:
GLint longestSubroutineUniformNameLength;
glGetProgramStageiv(program, GL_FRAGMENT_SHADER, GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH, &longestSubroutineUniformNameLength);
- glCreateShaderProgramv
Description: Create a program object in separable mode containing compiled and linked shaders for a single stage.
Use: Startup
Example:
glCreateShaderProgramv(GL_FRAGMENT_SHADER, NULL, fragment_shader_source);
- glGetProgramBinary
Description: Return a binary representation of a program object compiled and linked executable source.
Use: Shutdown
Example:
GLint binarySize = 0;
glGetProgramiv(program, GL_PROGRAM_BINARY_SIZE, &binarySize);
unsigned char * binary = new unsigned char [binarySize];
GLenum binaryFormat = GL_NONE;
glGetProgramBinary(program, binarySize, NULL, &binaryFormat, binary);
- glProgramBinary
Description: Load a program object with a program binary.
Use: Shutdown
Example:
glProgramBinary(program, binaryFormat, binary, binarySize);
*
* SUBROUTINE (UNIFORM) *
*
- glGetSubroutineIndex
Description: Query the index of a subroutine (by name) within a shader stage in a program object.
Use: Startup
Example:
GLint subroutineIndex = glGetSubroutineIndex(program, GL_FRAGMENT_SHADER, "myFunction1");
- glGetActiveSubroutineName
Description: Query the name of an active subroutine (by index) within a shader stage in a program object.
Use: Startup
Example:
GLchar activeSubroutineName[64];
glGetActiveSubroutineName(program, GL_FRAGMENT_SHADER, 0, sizeof(activeSubroutineName), NULL, activeSubroutineName);
- glGetSubroutineUniformLocation
Description: Query the location of a subroutine uniform (by name) within a shader stage in a program object.
Use: Startup
Example:
GLint subroutineUniformLocation = glGetSubroutineUniformLocation(program, GL_FRAGMENT_SHADER, "mySubroutineUniform");
- glGetActiveSubroutineUniformiv
Description: Query a property (GL_NUM_COMPATIBLE_SUBROUTINES, GL_COMPATIBLE_SUBROUTINES, GL_UNIFORM_SIZE, and GL_UNIFORM_NAME_LENGTH) of a subroutine uniform (by index) within a shader stage in a program object.
Use: Startup
Example:
GLint activeSubroutineUniformCompatibleSubroutinesNumber;
glGetActiveSubroutineUniformiv(program, GL_FRAGMENT_SHADER, 0, GL_NUM_COMPATIBLE_SUBROUTINES, &activeSubroutineUniformCompatibleSubroutinesNumber);
- glGetActiveSubroutineUniformName
Description: Query the name of an active subroutine uniform (by index) within a shader stage in a program object.
Use: Startup
Example:
GLchar activeSubroutineUniformName[64];
glGetActiveSubroutineUniformName(program, GL_FRAGMENT_SHADER, 0, sizeof(activeSubroutineUniformName), NULL, activeSubroutineUniformName);
*
* PROGRAM PIPELINE *
*
- glCreateProgramPipelines
Description: Create a program pipeline object to which you can attach program objects.
Use: Startup
Example:
GLuint program_pipeline;
glCreateProgramPipelines(1, &program_pipeline);
- glUseProgramStages
Description: Bind stages of a program object (GL_VERTEX_SHADER_BIT, GL_TESS_CONTROL_SHADER_BIT, GL_TESS_EVALUATION_SHADER_BIT, GL_GEOMETRY_SHADER_BIT, GL_FRAGMENT_SHADER_BIT, and GL_COMPUTE_SHADER_BIT) to a program pipeline object.
Use: Startup / Rendering
Example:
glUseProgramStages(program_pipeline, GL_VERTEX_SHADER_BIT, vs_program);
glUseProgramStages(program_pipeline, GL_FRAGMENT_SHADER_BIT, fs_program);
- glBindProgramPipeline
Description: Bind a program pipeline to the current context.
Use: Startup / Rendering
Example:
glBindProgramPipeline(program_pipeline);
- glDeleteProgramPipelines
Description: Delete a program pipeline object.
Use: Shutdown
Example:
glDeleteProgramPipelines(1, &program_pipeline);
*
* UNIFORM *
*
- glGetUniformLocation
Description: Determine the location of a uniform (by name). Passing something that is not the name of a uniform will return -1.
Use: Startup / Rendering
Example:
GLint uniform_location;
uniform_location = glGetUniformLocation(rendering_program, "mvpMatrix");
- glProgramUniform* / glProgramUniformMatrix*
Description: Fill the value of specified uniform from specified program.
Use: Startup / Rendering
Example:
const GLfloat material_color[3] = { 1.0f, 0.0f, 0.5f };
glProgramUniform3fv(rendering_program, uniform_location, 1, material_color);
- glUniform* / glUniformMatrix*
Description: Fill the value of specified uniform from bound program.
Use: Startup / Rendering
Example:
const GLfloat material_color[3] = { 1.0f, 0.0f, 0.5f };
glUniform3fv(uniform_location, 1, material_color);
- glGetUniformIndices
Description: Get the indices of a large set of uniform block members.
Use: Startup / Rendering
Example:
glGetUniformIndices(program, 2, uniform_names, uniform_indices);
- glGetActiveUniformsiv
Description: Get information (GL_UNIFORM_OFFSET, GL_UNIFORM_ARRAY_STRIDE, GL_UNIFORM_MATRIX_STRIDE, etc.) about specific uniform block members.
Use: Startup / Rendering
Example:
glGetActiveUniformsiv(program, 2, uniform_indices, GL_UNIFORM_OFFSET, uniform_offsets);
- glGetUniformBlockIndex
Description: Find the index of a uniform block in a program.
Use: Startup / Rendering
Example:
GLuint uniform_index = glGetUniformBlockIndex(program, "StdLayoutMaterialUniformBlock");
- glUniformBlockBinding
Description: Assign a binding point to a uniform block.
Use: Startup / Rendering
Example:
glUniformBlockBinding(program, uniform_index, 0);
*
* VERTEX *
*
- glCreateVertexArrays
Description: Create a vertex array object (VAO - an object that represents the vertex fetch stage of the OpenGL pipeline; used to supply input to the vertex shader).
Use: Startup
Example:
GLuint vertex_array_object;
glCreateVertexArrays(1, &vertex_array_object);
- glBindVertexArray
Description: Attach (or bind) a VAO to the OpenGL context.
Use: Rendering
Example:
glBindVertexArray(vertex_array_object);
- glDeleteVertexArrays
Description: Delete a VAO.
Use: Shutdown
Example:
glDeleteVertexArrays(1, &vertex_array_object);
- glVertexAttrib*
Description: Fill the (static) value of specified vertex attribute.
Use: Rendering
Example:
GLfloat attrib[] = { (float)sin(currentTime) * 0.5f,
(float)cos(currentTime) * 0.3f,
0.0f, 0.0f };
// Update the value of vertex attribute 0
glVertexAttrib4fv(0, attrib);
- glVertexAttribPointer / glVertexAttribIPointer / glVertexAttribLPointer
Description:
Set up (virtually) format and source buffer information for a vertex attribute.
Warning! At the time this function is called:
A vertex array object (where the configuration being set will be stored) must be bound to the OpenGL context.
A non-zero named (vertex) buffer object (containing corresponding vertex attribute data) must be bound to the GL_ARRAY_BUFFER target.
It internally uses provided index value as both the vertex attribute index and the buffer binding point index (and maps them together). Why? Legacy (when buffer binding points did not exist).
Specified offset represents where data starts in source (vertex) buffer object (base offset) and may include (depending on data layout - interleaved - or base offset definition) corresponding vertex attribute relative offset; (due to legacy background) it must be casted into a void pointer type.
Use: Rendering
Example:
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)sizeof(positions));
glVertexAttribPointer(2, 2, GL_UNSIGNED_SHORT, GL_TRUE, 0, (GLvoid*)(sizeof(positions) + sizeof(normals)));
- glVertexAttribFormat / glVertexAttribIFormat / glVertexAttribLFormat / glVertexArrayAttribFormat / glVertexArrayAttribIFormat / glVertexArrayAttribLFormat
Description:
Describe vertex attribute layout (size and type).
Functions named with "...VertexArray..." save settings into specified vertex array object; others, into active vertex array object.
Functions named with "...I..." describe the layout for integer vertex attributes (normalization not supported); functions named with "...L..." describe the layout for 64-bit vertex attributes; others, describe layout for floating-point vertex attributes (it is possible normalizing integer - signed and unsigned - data).
Relative offset allows interleaving, where different vertex attributes need to offset themselves from the base offset of mapped buffer binding point.
Use: Startup
Example:
glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, GL_FALSE, 0);
- glVertexAttribBinding / glVertexArrayAttribBinding
Description:
Map (by index) a vertex attribute to a buffer binding point; vertex attribute index matches the location modifier used in the shader.
Functions named with "...VertexArray..." save settings into specified vertex array object; others, into active vertex array object.
Use: Startup
Example:
glVertexArrayAttribBinding(vao, 0, 0);
- glBindVertexBuffer / glVertexArrayVertexBuffer
Description:
Bind a (vertex array) buffer object to a (vertex) buffer binding point; tell OpenGL which buffer object our data is in and where (in bytes) in that buffer object the data resides.
Functions named with "...VertexArray..." save settings into specified vertex array object; others, into active vertex array object.
Use: Startup
Example:
glVertexArrayVertexBuffer(vao, 0, buffer, 0, sizeof(float) * 4);
- glVertexAttribDivisor
Description:
Specify (by buffer binding point) the rate at which generic vertex attributes advance during instanced rendering.
Warning! In the OpenGL official documentation it is said the divisor to be specified by vertex attribute index, but it is a mistake.
Use: Rendering
Example:
glVertexAttribDivisor(1, 1);
- glVertexBindingDivisor / glVertexArrayBindingDivisor
Description:
Specify (by buffer binding point) the rate at which generic vertex attributes advance during instanced rendering.
Functions named with "...VertexArray..." save settings into specified vertex array object; others, into active vertex array object.
Use: Rendering
Example:
glVertexArrayBindingDivisor(vao, 1, 1);
- glEnableVertexAttribArray / glDisableVertexAttribArray / glEnableVertexArrayAttrib / glDisableVertexArrayAttrib
Description:
Enable/Disable automatic filling of a vertex attribute; when the attribute is disabled, the vertex shader will be provided with the static information provided with glVertexAttrib*().
Functions named with "...VertexArray..." save settings into specified vertex array object; others, into active vertex array object.
Use: Startup
Example:
glEnableVertexArrayAttrib(vao, 0);
- glGetAttribLocation
Description: Determine the location of a vertex shader input (by name). Passing something that is not the name of a vertex shader input will return -1.
Use: Startup
Example:
GLint attrib_index;
attrib_index = glGetAttribLocation(rendering_program, "position");
*
* PATCH
*
- glPatchParameter*
Description: Set the value of specified patch parameter (GL_PATCH_VERTICES, GL_PATCH_DEFAULT_OUTER_LEVEL or GL_PATCH_DEFAULT_INNER_LEVEL).
Use: Rendering
Example:
glPatchParameteri(GL_PATCH_VERTICES, 4);
- other -
const float outer_levels[] = { 6.0f, 5.0f, 1.0f, 1.0f };
glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL, outer_levels);
*
* DRAWING
*
- glDrawArrays / glMultiDrawArrays (Non-Indexed - Non-Instanced - Direct)
Description: Draw (multidrawing support) sequentially accessed array of vertices with specified primitive type (GL_POINTS, GL_LINES, GL_TRIANGLES, GL_PATCHES, etc.).
Use: Rendering
Example:
glDrawArrays(GL_POINTS, 0, 1);
- glDrawArraysInstanced (Non-Indexed - Instanced - Direct)
Description: Draw multiple copies of sequentially accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glDrawArraysInstancedBaseInstance (Non-Indexed - Instanced (offset) - Direct)
Description: Draw multiple copies (plus offset) of sequentially accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glDrawArraysIndirect / glMultiDrawArraysIndirect (Non-Indexed - Instanced (offset) - Indirect)
Description: Draw (multidrawing support) indirectly multiple copies (plus offset) of sequentially accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glDrawElements / glMultiDrawElements (Indexed - Non-Instanced - Direct)
Description: Draw (multidrawing support) by-index accessed array of vertices with specified primitive type.
Use: Rendering
Example:
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, 0);
- glDrawElementsBaseVertex / glMultiDrawElementsBaseVertex (Indexed (offset) - Non-Instanced - Direct)
Description: Draw (multidrawing support) by-index (plus offset) accessed array of vertices with specified primitive type.
Use: Rendering
Example:
glDrawElementsBaseVertex(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, 0, 0);
- glDrawElementsInstanced (Indexed - Instanced - Direct)
Description: Draw multiple copies of by-index accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glDrawElementsInstancedBaseInstance (Indexed - Instanced (offset) - Direct)
Description: Draw multiple copies (plus offset) of by-index accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glDrawElementsInstancedBaseVertex (Indexed (offset) - Instanced - Direct)
Description: Draw multiple copies of by-index (plus offset) accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glDrawElementsInstancedBaseVertexBaseInstance (Indexed (offset) - Instanced (offset) - Direct)
Description: Draw multiple copies (plus offset) of by-index (plus offset) accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glDrawElementsIndirect / glMultiDrawElementsIndirect (Indexed (offset) - Instanced (offset) - Indirect)
Description: Draw (multidrawing support) indirectly multiple copies (plus offset) of by-index (plus offset) accessed array of vertices with specified primitive type.
Use: Rendering
Example:
???
- glPointSize
Description: Set the diameter (in pixels) of the points.
Use: Rendering
Example:
glPointSize(40.0f);
- glPolygonMode
Description: Determine how to draw (GL_POINT; GL_LINE; GL_FILL) specified polygons (GL_FRONT; GL_BACK; GL_FRONT_AND_BACK).
Use: Rendering
Example:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glFrontFace (+ glEnable(GL_CULL_FACE))
Description: Determine winding order (GL_CW; GL_CCW) of the triangle.
Use: Rendering (Culling)
Example:
glFrontFace(GL_CCW);
- glCullFace (+ glEnable(GL_CULL_FACE))
Description: Determine which types of triangles are culled (GL_FRONT; GL_BACK; GL_FRONT_AND_BACK).
Use: Rendering (Culling)
Example:
glCullFace(GL_BACK);
- glPrimitiveRestartIndex (+ glEnable(GL_PRIMITIVE_RESTART))
Description: Specify the primitive (GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_LINE_STRIP, and GL_LINE_LOOP) restart index.
Use: Rendering
Example:
glPrimitiveRestartIndex(index);
- glViewport
Description: Set the viewport: lower left corner (x,y) - with respect to the window handling OpenGL context; dimensions (width, height) - defaults to the dimensions of the window to which the OpenGL context is initially attached.
Use: Rendering
Example:
glViewport(0, 0, info.windowWidth, info.windowHeight);
*
* TRANSFORM FEEDBACK
*
- glGenTransformFeedbacks / glCreateTransformFeedbacks / glBindTransformFeedback / glDeleteTransformFeedbacks
Description: Create (or just reserve a name), bind (target GL_TRANSFORM_FEEDBACK) and delete transform feedback object, respectively. Warning! Not required if working with default transform feedback object.