diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
commit | 9d720593e9f4829e2bb81534ef54545a61b3df00 (patch) | |
tree | 4f3a90fc71132b671bf097388ccd8f17f0c3517e /stockton-render/src/draw/draw_buffers.rs | |
parent | bbcd377cda8a3d99cee8f2f79d58575e00d0aeb8 (diff) |
refactor(render): give some functions less arguments
Diffstat (limited to 'stockton-render/src/draw/draw_buffers.rs')
-rw-r--r-- | stockton-render/src/draw/draw_buffers.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/stockton-render/src/draw/draw_buffers.rs b/stockton-render/src/draw/draw_buffers.rs new file mode 100644 index 0000000..daeea57 --- /dev/null +++ b/stockton-render/src/draw/draw_buffers.rs @@ -0,0 +1,54 @@ +// Copyright (C) Oscar Shrimpton 2019 + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. + +// You should have received a copy of the GNU General Public License along +// with this program. If not, see <http://www.gnu.org/licenses/>. + +use crate::types::*; +use draw::buffer::StagedBuffer; +use draw::UVPoint; +use error::CreationError; +use hal::buffer::Usage; +use std::mem::ManuallyDrop; + +/// Initial size of vertex buffer. TODO: Way of overriding this +pub const INITIAL_VERT_SIZE: u64 = 3 * 3000; + +/// Initial size of index buffer. TODO: Way of overriding this +pub const INITIAL_INDEX_SIZE: u64 = 3000; + +/// The buffers used for drawing, ie index and vertex buffer +pub struct DrawBuffers<'a> { + pub vertex_buffer: ManuallyDrop<StagedBuffer<'a, UVPoint>>, + pub index_buffer: ManuallyDrop<StagedBuffer<'a, (u16, u16, u16)>>, +} + +impl<'a> DrawBuffers<'a> { + pub fn new(device: &mut Device, adapter: &Adapter) -> Result<DrawBuffers<'a>, CreationError> { + let vert = StagedBuffer::new(device, &adapter, Usage::VERTEX, INITIAL_VERT_SIZE)?; + let index = StagedBuffer::new(device, &adapter, Usage::INDEX, INITIAL_INDEX_SIZE)?; + + Ok(DrawBuffers { + vertex_buffer: ManuallyDrop::new(vert), + index_buffer: ManuallyDrop::new(index), + }) + } + + pub fn deactivate(self, device: &mut Device) { + unsafe { + use core::ptr::read; + + ManuallyDrop::into_inner(read(&self.vertex_buffer)).deactivate(device); + ManuallyDrop::into_inner(read(&self.index_buffer)).deactivate(device); + } + } +} |