Skip to main content

glium/texture/
ty_support.rs

1//! Various functions to detect whether texture types are supported.
2
3use crate::CapabilitiesSource;
4use crate::version::Api;
5use crate::version::Version;
6
7/// Returns true is one-dimensional textures are supported.
8#[inline]
9pub fn is_texture_1d_supported<C: ?Sized>(context: &C) -> bool where C: CapabilitiesSource {
10    context.get_version() >= &Version(Api::Gl, 1, 1)
11}
12
13/// Returns true is two-dimensional textures are supported.
14///
15/// This is a dummy function that always returns true, as 2d textures are always supported. This
16/// function is just here for completeness.
17#[inline]
18pub fn is_texture_2d_supported<C: ?Sized>(_: &C) -> bool where C: CapabilitiesSource {
19    true
20}
21
22/// Returns true is three-dimensional textures are supported.
23#[inline]
24pub fn is_texture_3d_supported<C: ?Sized>(context: &C) -> bool where C: CapabilitiesSource {
25    context.get_version() >= &Version(Api::Gl, 1, 2) ||
26    context.get_version() >= &Version(Api::GlEs, 3, 0) ||
27    context.get_extensions().gl_ext_texture3d ||        // FIXME: functions have an EXT suffix, this isn't handled by glium
28    context.get_extensions().gl_oes_texture_3d        // FIXME: functions have an OES suffix, this isn't handled by glium
29}
30
31/// Returns true is one-dimensional texture arrays are supported.
32#[inline]
33pub fn is_texture_1d_array_supported<C: ?Sized>(context: &C) -> bool where C: CapabilitiesSource {
34    context.get_version() >= &Version(Api::Gl, 3, 0) ||
35    context.get_extensions().gl_ext_texture_array
36}
37
38/// Returns true is two-dimensional texture arrays are supported.
39#[inline]
40pub fn is_texture_2d_array_supported<C: ?Sized>(context: &C) -> bool where C: CapabilitiesSource {
41    context.get_version() >= &Version(Api::Gl, 3, 0) ||
42    context.get_version() >= &Version(Api::GlEs, 3, 0) ||
43    context.get_extensions().gl_ext_texture_array ||
44    context.get_extensions().gl_nv_texture_array        // FIXME: functions have an NV suffix, this isn't handled by glium
45}
46
47/// Returns true is two-dimensional multisample textures are supported.
48#[inline]
49pub fn is_texture_2d_multisample_supported<C: ?Sized>(context: &C) -> bool where C: CapabilitiesSource {
50    context.get_version() >= &Version(Api::Gl, 3, 2) ||
51    context.get_version() >= &Version(Api::GlEs, 3, 1) ||
52    context.get_extensions().gl_arb_texture_multisample
53    // TODO: no gles extension?
54}
55
56/// Returns true is two-dimensional multisample texture arrays are supported.
57#[inline]
58pub fn is_texture_2d_multisample_array_supported<C: ?Sized>(context: &C) -> bool
59                                                    where C: CapabilitiesSource
60{
61    context.get_version() >= &Version(Api::Gl, 3, 2) ||
62    context.get_extensions().gl_arb_texture_multisample ||
63    context.get_extensions().gl_oes_texture_storage_multisample_2d_array      // FIXME: functions have an OES suffix, this isn't handled by glium
64}
65
66/// Returns true is cubemaps are supported.
67#[inline]
68pub fn is_cubemaps_supported<C: ?Sized>(context: &C) -> bool where C: CapabilitiesSource {
69    context.get_version() >= &Version(Api::Gl, 1, 3) ||
70    context.get_version() >= &Version(Api::GlEs, 2, 0) ||
71    context.get_extensions().gl_ext_texture_cube_map ||
72    context.get_extensions().gl_arb_texture_cube_map
73}
74
75/// Returns true is cubemap arrays are supported.
76#[inline]
77pub fn is_cubemap_arrays_supported<C: ?Sized>(context: &C) -> bool where C: CapabilitiesSource {
78    context.get_version() >= &Version(Api::Gl, 4, 0) ||
79    context.get_extensions().gl_arb_texture_cube_map_array ||
80    context.get_extensions().gl_ext_texture_cube_map_array ||
81    context.get_extensions().gl_oes_texture_cube_map_array
82}