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
//! GPU queries.
//!
//! GPU queries allow to get information about the backend and the GPU in a straight-forward way.

use crate::{
  backend::query::{Query as QueryBackend, QueryError},
  context::GraphicsContext,
};

/// Query object.
///
/// Such an object allows to query various parts of the backend and GPU.
#[derive(Debug)]
pub struct Query<'a, B>
where
  B: ?Sized,
{
  backend: &'a B,
}

impl<'a, B> Query<'a, B>
where
  B: ?Sized + QueryBackend,
{
  /// Create a new [`Query`] for a given context.
  pub fn new(ctxt: &'a mut impl GraphicsContext<Backend = B>) -> Self {
    let backend = ctxt.backend();
    Self { backend }
  }

  /// The implementation author, most of the time referred to as “vendor” or “compagny” responsible for the driver the
  /// implementation uses.
  pub fn backend_author(&self) -> Result<String, QueryError> {
    self.backend.backend_author()
  }

  /// The backend name.
  pub fn backend_name(&self) -> Result<String, QueryError> {
    self.backend.backend_name()
  }

  /// The backend version.
  pub fn backend_version(&self) -> Result<String, QueryError> {
    self.backend.backend_version()
  }

  /// The shading language version.
  pub fn backend_shading_lang_version(&self) -> Result<String, QueryError> {
    self.backend.backend_shading_lang_version()
  }

  /// Maximum number of elements a texture array can hold.
  pub fn max_texture_array_elements(&self) -> Result<usize, QueryError> {
    self.backend.max_texture_array_elements()
  }
}