euv_engine/renderer/webgl/enum.rs
1use super::*;
2
3/// Which shader stage a GLSL source is compiled for.
4///
5/// WebGL identifies a shader by the raw `VERTEX_SHADER` /
6/// `FRAGMENT_SHADER` enum rather than by a string, and the same raw
7/// `u32` is threaded through the [`GlProgram`] path.
8/// This enum names the two stages so a caller cannot pass a meaningless
9/// value and have the browser reject the compile later.
10#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
11pub enum GlShaderKind {
12 /// The per-vertex stage, which runs once for every vertex of every
13 /// instance.
14 #[default]
15 Vertex,
16 /// The per-fragment stage, which runs once for every surviving
17 /// fragment after rasterization.
18 Fragment,
19}
20
21/// The completeness verdict a framebuffer reports after its attachments
22/// are bound.
23///
24/// WebGL returns a single `u32` status code rather than an error, so the
25/// distinct failure modes a caller must actually react to are lifted
26/// into named variants: one means "an attachment is missing", one means
27/// "the attachments disagree with each other", and one means "this
28/// driver cannot do what you asked for at all".
29#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
30pub enum GlFramebufferStatus {
31 /// `FRAMEBUFFER_COMPLETE`. Every attachment is present, every
32 /// attachment agrees on its dimensions, and the combination is
33 /// renderable.
34 #[default]
35 Complete,
36 /// `FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT`: an attachment enum
37 /// names nothing bound. A binding mistake, almost always.
38 Incomplete,
39 /// `FRAMEBUFFER_INCOMPLETE_DIMENSIONS` or
40 /// `FRAMEBUFFER_INCOMPLETE_MULTISAMPLE`: the attachments disagree on
41 /// size or sample count. A resource-allocation mistake, almost
42 /// always a renderbuffer that was never resized alongside its color
43 /// texture.
44 Unsupported,
45 /// Any other non-complete status the driver reports, including
46 /// `FRAMEBUFFER_UNSUPPORTED` and every implementation-specific code.
47 /// Treated as unsupported because the frame cannot be rendered into.
48 Other,
49}
50
51/// Why a [`WebGl2Backend`] could not be constructed.
52///
53/// WebGL reports context-creation failure by returning `null` rather than
54/// by throwing, so the three ways it fails, a missing canvas, a
55/// non-matching selector, and a browser with no WebGL 2 support, would
56/// otherwise all collapse into one opaque `None`.
57#[derive(Clone, Debug, Eq, Hash, PartialEq)]
58pub enum WebGl2InitError {
59 /// The configured selector matched no element in the document.
60 CanvasNotFound(String),
61 /// The selector could not be evaluated, because the document has no
62 /// body yet or the selector is not valid.
63 CanvasQuery(String),
64 /// `getContext("webgl2")` threw rather than returning `None`.
65 ContextLookup(String),
66 /// `getContext("webgl2")` returned `None`, which means the browser
67 /// has no WebGL 2 support, or the canvas already holds a context of a
68 /// different kind.
69 ContextUnavailable,
70 /// A `webgl2` context was returned but was not a
71 /// `WebGL2RenderingContext`, which should not be reachable.
72 ContextCast,
73}
74
75/// Errors that can occur while building a WebGL shader program.
76///
77/// Each variant carries the browser-provided info log so the caller can
78/// surface the exact GLSL diagnostic without losing fidelity.
79#[derive(Clone, Debug)]
80pub enum WebGlProgramError {
81 /// Vertex or fragment shader compilation failed.
82 ///
83 /// Carries the shader info log returned by `getShaderInfoLog`.
84 ShaderCompile(String),
85 /// Program linking failed (or `createProgram` returned `None`).
86 ///
87 /// Carries the program info log returned by `getProgramInfoLog`.
88 ProgramLink(String),
89}