gl/
info.rs

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
//! This module provide information about the current GL context.
//!
//! The functions provided in here map largely 1:1 to OpenGL calls to [`glGet`]
//! in varying capacities.
//!
//! [`glGet`]: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGet.xhtml
use crate::c::GLenum;
use crate::error::Result;

/// Gets the supported version of OpenGL as defined by the `GL_MAJOR_VERSION`
/// and `GL_MINOR_VERSION` values returned from the current context.
///
/// The first returned value is the major version and the second is the minor.
pub fn supported_version() -> (u32, u32) {
  let mut major = 0;
  let mut minor = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAJOR_VERSION as GLenum, &mut major);
    crate::c::glGetIntegerv(crate::c::GL_MINOR_VERSION as GLenum, &mut minor);
  }
  (major as u32, minor as u32)
}

/// Gets the supported version of OpenGL as defined by the `GL_MAJOR_VERSION`
/// and `GL_MINOR_VERSION` values returned from the current context.
///
/// This function always tests whether an error was returned from [`glGetError`]
/// after.
///
/// [`glGetError`]: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetError.xhtml
#[inline(always)]
pub fn supported_version_checked() -> Result<(u32, u32)> {
  crate::error::check(supported_version)
}

/// Gets the maximum number of layers allowed in an array texture, and must be
/// at least 256.
pub fn max_array_texture_layers() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_ARRAY_TEXTURE_LAYERS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of layers allowed in an array texture, and must be
/// at least 256.
///
/// This function always tests whether an error was returned from [`glGetError`]
/// after.
///
/// [`glGetError`]: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetError.xhtml
#[inline(always)]
pub fn max_array_texture_layers_checked() -> Result<usize> {
  crate::error::check(max_array_texture_layers)
}

/// Gets a rough estimate of the largest 3D texture that the GL can handle. The
/// value must be at least 64.
pub fn max_3d_texture_size() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_3D_TEXTURE_SIZE as GLenum, &mut size);
  }
  size as usize
}

/// Gets a rough estimate of the largest 3D texture that the GL can handle. The
/// value must be at least 64.
///
/// This function always tests whether an error was returned from [`glGetError`]
/// after.
///
/// [`glGetError`]: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetError.xhtml
#[inline(always)]
pub fn max_3d_texture_size_checked() -> Result<usize> {
  crate::error::check(max_3d_texture_size)
}

/// Gets the maximum number of texture units that can be used in a fragment
/// shader.
pub fn max_texture_size() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_TEXTURE_SIZE as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of texture units that can be used in a fragment
/// shader.
///
/// This function always tests whether an error was returned from [`glGetError`]
/// after.
///
/// [`glGetError`]: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetError.xhtml
#[inline(always)]
pub fn max_texture_size_checked() -> Result<usize> {
  crate::error::check(max_texture_size)
}

/// Gets the maximum number of texture units that can be used in a fragment
/// shader.
pub fn max_clip_distances() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_CLIP_DISTANCES as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of samples in a color multisample texture.
pub fn max_color_texture_samples() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_COLOR_TEXTURE_SAMPLES as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of atomic counters available to all active shaders.
pub fn max_combined_atomic_counters() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_COMBINED_ATOMIC_COUNTERS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the number of words for fragment shader uniform variables in all
/// uniform blocks (including default). The value must be at least 1.
pub fn max_combined_fragment_uniform_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the number of words for geometry shader uniform variables in all
/// uniform blocks (including default). The value must be at least 1.
pub fn max_combined_geometry_uniform_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum supported texture image units that can be used to access
/// texture maps from the vertex shader and the fragment processor combined. If
/// both the vertex shader and the fragment processing stage access the same
/// texture image unit, then that counts as using two texture image units
/// against this limit. The value must be at least 48.
pub fn max_combined_texture_image_units() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum number of uniform blocks per program. The value must be at
/// least 70.
pub fn max_combined_uniform_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_COMBINED_UNIFORM_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the number of words for vertex shader uniform variables in all uniform
/// blocks (including default). The value must be at least 1.
pub fn max_combined_vertex_uniform_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum number of color attachments that can be used in a fragment
/// shader.
pub fn max_color_attachments() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_COLOR_ATTACHMENTS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max cube map texture size.
pub fn max_cube_map_texture_size() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_CUBE_MAP_TEXTURE_SIZE as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum depth texture samples.
pub fn max_depth_texture_samples() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_DEPTH_TEXTURE_SAMPLES as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum draw buffers.
pub fn max_draw_buffers() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_DRAW_BUFFERS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum dual-source draw buffers.
pub fn max_dual_source_draw_buffers() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_DUAL_SOURCE_DRAW_BUFFERS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the max elements indices that can be used in a draw call.
pub fn max_elements_indices() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_ELEMENTS_INDICES as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max elements vertices that can be used in a draw call.
pub fn max_elements_vertices() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_ELEMENTS_VERTICES as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum fragment shader storage block.
pub fn max_fragment_shader_storage_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum fragment input components.
pub fn max_fragment_input_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_FRAGMENT_INPUT_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum fragment uniform components.
pub fn max_fragment_uniform_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_FRAGMENT_UNIFORM_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum fragment uniform vectors.
pub fn max_fragment_uniform_vectors() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_FRAGMENT_UNIFORM_VECTORS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum fragment output components.
pub fn max_fragment_uniform_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_FRAGMENT_UNIFORM_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum frame-buffer width.
pub fn max_framebuffer_width() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_FRAMEBUFFER_WIDTH as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum frame-buffer height.
pub fn max_framebuffer_height() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_FRAMEBUFFER_HEIGHT as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum frame-buffer layers.
pub fn max_framebuffer_layers() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_FRAMEBUFFER_LAYERS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum frame-buffer samples.
pub fn max_framebuffer_samples() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_FRAMEBUFFER_SAMPLES as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum atomic counters for geometry shaders.
pub fn max_geometry_atomic_counters() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_ATOMIC_COUNTERS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum geometry shader storage blocks.
pub fn max_geometry_shader_storage_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum geometry input components.
pub fn max_geometry_input_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_INPUT_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum geometry-shader output components.
pub fn max_geometry_output_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_OUTPUT_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum geometry-shader output vertices.
pub fn max_geometry_output_vertices() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_OUTPUT_VERTICES as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum geometry shader texture image units.
pub fn max_geometry_texture_image_units() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum geometry shader uniform blocks.
pub fn max_geometry_uniform_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_UNIFORM_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum geometry shader uniform components.
pub fn max_geometry_uniform_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_GEOMETRY_UNIFORM_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum integer samples.
pub fn max_integer_samples() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_INTEGER_SAMPLES as GLenum, &mut size);
  }
  size as usize
}

/// Gets the min-map buffer alignment.
pub fn min_map_buffer_alignment() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MIN_MAP_BUFFER_ALIGNMENT as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max label length.
pub fn max_label_length() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_LABEL_LENGTH as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max progarm texel offset.
pub fn max_program_texel_offset() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_PROGRAM_TEXEL_OFFSET as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max rectangular texture size.
pub fn max_rectangle_texture_size() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_RECTANGLE_TEXTURE_SIZE as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max render-buffer size.
pub fn max_renderbuffer_size() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_RENDERBUFFER_SIZE as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max sample mask words.
pub fn max_sample_mask_words() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_SAMPLE_MASK_WORDS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max server-wait timeout
pub fn max_server_wait_timeout() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_SERVER_WAIT_TIMEOUT as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max shader storage buffer bindings.
pub fn max_shader_storage_buffer_bindings() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the max tesselation control atomic counters.
pub fn max_tess_control_atomic_counters() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the max tesselation evaluation atomic counters.
pub fn max_tess_evaluation_atomic_counters() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the max tesselation control shader storage blocks.
pub fn max_tess_control_shader_storage_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the max tesselation evaluation shader storage blocks.
pub fn max_tess_evaluation_shader_storage_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the max texture buffer size.
pub fn max_texture_buffer_size() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_TEXTURE_BUFFER_SIZE as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max texture image units.
pub fn max_texture_image_units() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_TEXTURE_IMAGE_UNITS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the max texture LOD bias.
pub fn max_texture_lod_bias() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_TEXTURE_LOD_BIAS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of uniform buffer bindings that can be used in a
/// vertex shader.
pub fn max_uniform_buffer_bindings() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_UNIFORM_BUFFER_BINDINGS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum size in basic machine units of a uniform block.
pub fn max_uniform_block_size() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_UNIFORM_BLOCK_SIZE as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of uniform locations that can be used in a vertex
/// shader.
pub fn max_uniform_locations() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_UNIFORM_LOCATIONS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of vertex shader storage blocks that can be used in
/// a vertex shader.
pub fn max_varying_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VARYING_COMPONENTS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of varying vectors that can be used in a vertex
/// shader.
pub fn max_varying_vectors() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VARYING_VECTORS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of varying floats that can be used.
pub fn max_varying_floats() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VARYING_FLOATS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of vertex attributes that can be used.
pub fn max_vertex_attribs() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VERTEX_ATTRIBS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of vertex shader storage blocks.
pub fn max_vertex_shader_storage_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum number of vertex texture image units.
pub fn max_vertex_texture_image_units() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum number of vertex uniform components.
pub fn max_vertex_uniform_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_VERTEX_UNIFORM_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum number of vertex uniform vectors.
pub fn max_vertex_uniform_vectors() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VERTEX_UNIFORM_VECTORS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of vertex output components.
pub fn max_vertex_output_components() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(
      crate::c::GL_MAX_VERTEX_OUTPUT_COMPONENTS as GLenum,
      &mut size,
    );
  }
  size as usize
}

/// Gets the maximum number of vertex shader uniform blocks.
pub fn max_vertex_uniform_blocks() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VERTEX_UNIFORM_BLOCKS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of dimensions the viewport can have.
pub fn max_viewport_dimensions() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VIEWPORT_DIMS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the maximum number of viewports that can be used.
pub fn max_viewports() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_MAX_VIEWPORTS as GLenum, &mut size);
  }
  size as usize
}

/// Gets the number of extensions supported by the current GL context.
///
/// This function is a convenience wrapper around `glGetIntegerv` with the
/// `GL_NUM_EXTENSIONS` parameter.
pub fn num_extensions() -> usize {
  let mut size = 0;
  unsafe {
    crate::c::glGetIntegerv(crate::c::GL_NUM_EXTENSIONS as GLenum, &mut size);
  }
  size as usize
}

/// Returns the name of the extension at the given index.
///
/// # Parameters
///
/// * `i` - the index of the extension to get
pub fn extension(i: usize) -> Option<&'static str> {
  let ext = unsafe { crate::c::glGetStringi(crate::c::GL_EXTENSIONS as _, i as _) };
  if ext.is_null() {
    None
  } else {
    Some(unsafe { std::ffi::CStr::from_ptr(ext as _).to_str().unwrap() })
  }
}

/// Returns an iterator over all the extensions supported by the current GL
/// context.
pub fn extensions() -> ExtensionIter {
  let count = num_extensions();

  ExtensionIter::new(count)
}

/// Gets a string for the shading language version.
pub fn shading_language_version() -> &'static str {
  let version = unsafe { crate::c::glGetString(crate::c::GL_SHADING_LANGUAGE_VERSION as _) };
  unsafe { std::ffi::CStr::from_ptr(version as _).to_str().unwrap() }
}

/// Gets a string for the vendor name.
pub fn vendor() -> &'static str {
  let vendor = unsafe { crate::c::glGetString(crate::c::GL_VENDOR as _) };
  unsafe { std::ffi::CStr::from_ptr(vendor as _).to_str().unwrap() }
}

/// Gets a string for the renderer name.
pub fn renderer() -> &'static str {
  let renderer = unsafe { crate::c::glGetString(crate::c::GL_RENDERER as _) };
  unsafe { std::ffi::CStr::from_ptr(renderer as _).to_str().unwrap() }
}

/// Gets a string for the version.
pub fn version() -> &'static str {
  let version = unsafe { crate::c::glGetString(crate::c::GL_VERSION as _) };
  unsafe { std::ffi::CStr::from_ptr(version as _).to_str().unwrap() }
}

/// An iterator over the extensions supported by the current GL context.
pub struct ExtensionIter {
  index: usize,
  count: usize,
}

impl ExtensionIter {
  #[inline(always)]
  const fn new(count: usize) -> Self {
    Self { index: 0, count }
  }
}

impl Iterator for ExtensionIter {
  type Item = &'static str;
  fn next(&mut self) -> Option<Self::Item> {
    if self.index < self.count {
      let ext = extension(self.index);
      self.index += 1;
      ext
    } else {
      None
    }
  }
}