ombre: Make texture layer counter configurable

8b1b2b973de6d99e3e3215c9debb6c6e63f74e2a
Alexis Sellier committed ago 1 parent 6a430a76
ombre/src/paint/canvas.rs +10 -4
14 14
15 15
/// Default number of vertices in the interface VBO.
16 16
/// Roughly 16MB of VRAM. This number has to be divisible by 3,
17 17
/// given that we are drawing triangles.
18 18
pub const DEFAULT_MAX_VERTICES: usize = 2usize.pow(18) - 1;
19 +
/// Default texture layer size.
20 +
pub const DEFAULT_TEXTURE_LAYER_SIZE: Size<u32> = Size::new(512, 512);
19 21
/// Default number of texture layers used by the rendering pipeline.
20 22
/// This is the maximum number of distinct texture objects available for rendering.
21 23
pub const DEFAULT_MAX_TEXTURE_LAYERS: usize = 16;
22 24
/// Size of the transform stack, in number of transform matrices.
23 25
pub const TRANSFORM_STACK_SIZE: usize = 24;
156 158
/// Configuration options for the canvas rendering system.
157 159
pub struct Config {
158 160
    /// Maximum number of vertices that can be allocated by the renderer.
159 161
    /// Defaults to [`DEFAULT_MAX_VERTICES`].
160 162
    pub max_vertices: usize,
163 +
    /// Maximum size for texture layers. This determines the maximum size of images
164 +
    /// drawn on the canvas.
165 +
    pub max_texture_size: Size<u32>,
161 166
}
162 167
163 168
impl Default for Config {
164 169
    fn default() -> Self {
165 170
        Self {
166 171
            max_vertices: DEFAULT_MAX_VERTICES,
172 +
            max_texture_size: DEFAULT_TEXTURE_LAYER_SIZE,
167 173
        }
168 174
    }
169 175
}
170 176
171 177
/// Builder for configuring and creating a new [`Canvas`] instance.
265 271
            depth_attachment: Some(offscreen_depth),
266 272
        })?;
267 273
268 274
        let layers = self.backend.texture(Texture {
269 275
            data: gfx::Empty,
270 -
            size: Size::new(256, 256),
276 +
            size: self.config.max_texture_size,
271 277
            access: TextureAccess::Static,
272 278
            target: TextureKind::Texture2DArray { arity: 16 },
273 279
            format: TextureFormat::Srgba8,
274 280
            wrap: TextureWrap::Repeat,
275 281
            min_filter: FilterMode::Nearest,
276 282
            mag_filter: FilterMode::Nearest,
277 283
        })?;
278 284
        self.backend.texture_update_layer(
279 285
            layers,
280 286
            0,
281 -
            Rect::origin([256, 256]),
282 -
            &[Rgba8::WHITE; 256 * 256],
287 +
            Rect::origin(self.config.max_texture_size),
288 +
            vec![Rgba8::WHITE; self.config.max_texture_size.area() as usize].as_slice(),
283 289
        )?;
284 290
        let vbo = self.backend.buffer(
285 291
            gfx::BufferKind::Vertex,
286 292
            gfx::BufferUsage::Stream,
287 293
            gfx::BufferSource::<pipeline::Vertex>::empty(self.config.max_vertices),
302 308
                textures: [offscreen_color],
303 309
            },
304 310
        };
305 311
        let layers = TextureInfo {
306 312
            id: layers,
307 -
            size: Size::new(256, 256),
313 +
            size: self.config.max_texture_size,
308 314
        };
309 315
        let render = RenderState::new(layers);
310 316
        let fonts = Fonts {
311 317
            default,
312 318
            loaded: self.fonts,
ombre/src/ui.rs +1 -1
21 21
22 22
pub use context::*;
23 23
pub use gfx::common::{Align, Align2D, Repaint};
24 24
pub use gfx::cursors::CursorDescriptor;
25 25
pub use gfx::text::{PlainText, RichTextStorage, TextAlign};
26 -
pub use interface::{interface, Error, Interface};
26 +
pub use interface::{interface, Config, Error, Interface};
27 27
pub use lazy::Lazy;
28 28
pub use widgets::*;
29 29
pub use widgets::{Widget, WidgetEvent, WidgetExt};
30 30
31 31
#[cfg(test)]
ombre/src/ui/interface.rs +4 -0
40 40
/// Interface configuration.
41 41
pub struct Config {
42 42
    /// Maximum number of vertices that can be allocated by the renderer.
43 43
    /// Defaults to [`canvas::DEFAULT_MAX_VERTICES`].
44 44
    pub max_vertices: usize,
45 +
    /// See [`canvas::Config::max_texture_size`].
46 +
    pub max_texture_size: Size<u32>,
45 47
}
46 48
47 49
impl Default for Config {
48 50
    fn default() -> Self {
49 51
        Self {
50 52
            max_vertices: canvas::DEFAULT_MAX_VERTICES,
53 +
            max_texture_size: canvas::DEFAULT_TEXTURE_LAYER_SIZE,
51 54
        }
52 55
    }
53 56
}
54 57
55 58
/// User interface state. Wraps the root widget with additional state
269 272
        let canvas = self
270 273
            .canvas
271 274
            .scale(self.scale)
272 275
            .config(canvas::Config {
273 276
                max_vertices: self.config.max_vertices,
277 +
                max_texture_size: self.config.max_texture_size,
274 278
            })
275 279
            .build()
276 280
            .map_err(Error::Canvas)?;
277 281
        let window = WindowCtx {
278 282
            title: self.window.get_title().to_owned(),