Skip to content

Commit

Permalink
Tinkering
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkleiny committed Jul 6, 2024
1 parent 234e516 commit 3f10610
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sdl = { package = "surreal-backend-sdl", path = "./backends/sdl", optional = tru
audio = { package = "surreal-audio", path = "./modules/audio", optional = true }
graphics = { package = "surreal-graphics", path = "./modules/graphics", optional = true }
input = { package = "surreal-input", path = "./modules/input", optional = true }
scripting = { package = "surreal-scripting", path = "./modules/scripting", optional = true }

[[example]]
name = "hello-world"
Expand Down
18 changes: 9 additions & 9 deletions modules/graphics/src/meshes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Meshes abstract over vertex and index data on the GPU as well, and
//! provide utilities for constructing data from pieces.
use std::{cell::RefCell, rc::Rc};
use std::sync::{Arc, Mutex};

use common::{vec2, Size, Vec2, Vec3};
pub use macros::Vertex;
Expand Down Expand Up @@ -124,7 +124,7 @@ impl Vertex3 {
/// for rendering at any time, provided a valid [`Material`] is available.
#[derive(Clone)]
pub struct Mesh<V> {
state: Rc<RefCell<MeshState<V>>>,
state: Arc<Mutex<MeshState<V>>>,
}

/// The internal state for a mesh.
Expand All @@ -148,7 +148,7 @@ impl<V: Vertex> Mesh<V> {
let indices = Buffer::new(BufferKind::Index, usage).map_err(|_| MeshError::FailedToCreate)?;

Ok(Self {
state: Rc::new(RefCell::new(MeshState {
state: Arc::new(Mutex::new(MeshState {
id: graphics().mesh_create(vertices.id(), indices.id(), V::DESCRIPTORS)?,
vertices,
indices,
Expand Down Expand Up @@ -181,22 +181,22 @@ impl<V: Vertex> Mesh<V> {

/// Returns the identifier of this mesh.
pub fn id(&self) -> MeshId {
self.state.borrow().id
self.state.lock().unwrap().id
}

/// Returns the number of vertices in the mesh.
pub fn vertices(&self) -> usize {
self.state.borrow().vertices.len()
self.state.lock().unwrap().vertices.len()
}

/// Returns the number of indices in the mesh.
pub fn indices(&self) -> usize {
self.state.borrow().indices.len()
self.state.lock().unwrap().indices.len()
}

/// Draws this mesh with the given material and topology.
pub fn draw(&self, material: &Material, topology: PrimitiveTopology) {
let state = self.state.borrow();
let state = self.state.lock().unwrap();

self.draw_sub(material, topology, state.vertices.len(), state.indices.len());
}
Expand All @@ -205,7 +205,7 @@ impl<V: Vertex> Mesh<V> {
pub fn draw_sub(&self, material: &Material, topology: PrimitiveTopology, vertex_count: usize, index_count: usize) {
material.bind();

let state = self.state.borrow();
let state = self.state.lock().unwrap();

graphics()
.mesh_draw(state.id, topology, vertex_count, index_count)
Expand All @@ -216,7 +216,7 @@ impl<V: Vertex> Mesh<V> {

/// Acquires mutable write access the mesh buffers.
pub fn with_buffers(&mut self, body: impl FnOnce(&mut Buffer<V>, &mut Buffer<Index>)) {
let state = &mut self.state.borrow_mut();
let state = &mut self.state.lock().unwrap();
let (vertices, indices) = state.borrow_buffers_mut();

body(vertices, indices);
Expand Down
2 changes: 2 additions & 0 deletions modules/scripting/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
//! Scripting engine for Surreal
pub trait ScriptBackend {}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub extern crate editor;
pub extern crate graphics;
#[cfg(feature = "input")]
pub extern crate input;
#[cfg(feature = "scripting")]
pub extern crate scripting;

pub mod backends {
#[cfg(feature = "sdl")]
Expand Down

0 comments on commit 3f10610

Please sign in to comment.