|
1 |
| -use gl::types::*; |
2 |
| -use thiserror::Error; |
3 |
| - |
4 |
| - |
5 |
| -/// The error returned when attempting to convert a raw [`GLenum`] into an actual Rust enum fails. This can happen when |
6 |
| -/// the given `GLenum` value does not match any variants. |
7 |
| -#[derive(Error, Debug)] |
8 |
| -#[error("could not convert `GLenum` value '{original_value:#X}' into enum of type `{attempted_type}`")] |
9 |
| -pub struct EnumConversionError { |
10 |
| - original_value: GLenum, |
11 |
| - attempted_type: &'static str, |
12 |
| -} |
13 |
| - |
14 |
| -impl EnumConversionError { |
15 |
| - pub(crate) const fn new(value: GLenum, name: &'static str) -> Self { |
16 |
| - Self { |
17 |
| - original_value: value, |
18 |
| - attempted_type: name, |
19 |
| - } |
20 |
| - } |
21 |
| -} |
22 |
| - |
23 |
| - |
24 |
| -/// The error returned when attempting to convert a raw [`GLbitfield`] into an actual Rust struct fails. This can happen |
25 |
| -/// when the given `GLbitfield` value does not |
26 |
| -#[derive(Error, Debug)] |
27 |
| -#[error("could not convert `GLbitfield` value '{original_value:#b}' into struct of type `{attempted_type}`")] |
28 |
| -pub struct BitfieldConversionError { |
29 |
| - original_value: GLbitfield, |
30 |
| - attempted_type: &'static str, |
31 |
| -} |
32 |
| - |
33 |
| -impl BitfieldConversionError { |
34 |
| - pub(crate) const fn new(value: GLbitfield, name: &'static str) -> Self { |
35 |
| - Self { |
36 |
| - original_value: value, |
37 |
| - attempted_type: name, |
38 |
| - } |
39 |
| - } |
40 |
| -} |
| 1 | +use std::fmt; |
41 | 2 |
|
| 3 | +use thiserror::Error; |
42 | 4 |
|
43 |
| -/// An error returned when OpenGL itself fails to create an object. |
| 5 | +/// This error is returned when creating an OpenGL "_object_" fails. |
44 | 6 | ///
|
45 |
| -/// This error is returned by several functions, and contains no extra details. It corresponds to when an |
46 |
| -/// object-creation function (e.g., [`glCreateShader`] and [`glCreateProgram`]) returns zero. |
| 7 | +/// This error corresponds to when an object-creation function like [`glCreateShader`] or [`glCreateProgram`] returns a |
| 8 | +/// value of zero. There are no extra details associated with it. |
47 | 9 | ///
|
48 | 10 | /// [`glCreateShader`]: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glCreateShader.xhtml
|
49 | 11 | /// [`glCreateProgram`]: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glCreateProgram.xhtml
|
50 |
| -#[derive(Error, Debug)] |
51 |
| -#[error("OpenGL could not create {0} object")] |
52 |
| -// note: {0} should *include* article ("a shader" object) ("an ..." object) |
53 |
| -pub struct ObjectCreationError(&'static str); |
| 12 | +#[derive(Error, Debug, Clone, Copy)] |
| 13 | +#[error("OpenGL failed to create {0}.")] // note: {0} should *include* article ("an ..." object) |
| 14 | +pub struct ObjectCreationError(ObjectCreationErrorKind); |
54 | 15 |
|
55 | 16 | impl ObjectCreationError {
|
56 |
| - pub(crate) const fn new(type_name: &'static str) -> Self { |
57 |
| - Self(type_name) |
| 17 | + pub(crate) const fn new(kind: ObjectCreationErrorKind) -> Self { |
| 18 | + Self(kind) |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +/// Which object [failed to be created][ObjectCreationError]. |
| 23 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 24 | +pub enum ObjectCreationErrorKind { |
| 25 | + Shader, |
| 26 | + Program, |
| 27 | +} |
| 28 | + |
| 29 | +impl fmt::Display for ObjectCreationErrorKind { |
| 30 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 31 | + f.write_str(match self { |
| 32 | + Self::Shader => "a shader object", |
| 33 | + Self::Program => "a program object", |
| 34 | + }) |
58 | 35 | }
|
59 | 36 | }
|
0 commit comments