Skip to content

Commit

Permalink
feat: camera is now a collection than a single entity, where the oper…
Browse files Browse the repository at this point in the history
…ations done on camera is done on "main" camera
  • Loading branch information
ElhamAryanpur committed Jul 13, 2024
1 parent 8a6ac06 commit 790dcf8
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 226 deletions.
139 changes: 1 addition & 138 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ winit = { version = "0.29.8", features = ["rwh_05"] }
winit_input_helper = "0.16"
wgpu = { version = "0.20.1" }
bytemuck = { version = "1.16", features = ["derive"] }
color-eyre = "0.6"
eyre = "0.6"
downcast = "0.11"
nalgebra-glm = "0.19"
# debug logs
Expand Down
1 change: 0 additions & 1 deletion examples/shapes/models.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/shapes/square.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use blue_engine::{
StringBuffer,
};

pub fn square(name: impl StringBuffer, engine: &mut Engine) -> color_eyre::Result<()> {
pub fn square(name: impl StringBuffer, engine: &mut Engine) -> eyre::Result<()> {
engine.objects.new_object(
name,
vec![
Expand Down
Binary file removed resources/monkey.glb
Binary file not shown.
10 changes: 5 additions & 5 deletions src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl crate::header::Renderer {
vertex_buffer: VertexBuffers,
texture: Textures,
uniform: Option<UniformBuffers>,
) -> color_eyre::Result<Pipeline> {
) -> eyre::Result<Pipeline> {
Ok(Pipeline {
shader: PipelineData::Data(shader),
vertex_buffer: PipelineData::Data(vertex_buffer),
Expand All @@ -39,7 +39,7 @@ impl crate::header::Renderer {
shader_source: String,
uniform_layout: Option<&BindGroupLayout>,
settings: ShaderSettings,
) -> color_eyre::Result<Shaders> {
) -> eyre::Result<Shaders> {
let shader = self
.device
.create_shader_module(wgpu::ShaderModuleDescriptor {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl crate::header::Renderer {
texture_data: TextureData,
texture_mode: TextureMode,
//texture_format: TextureFormat,
) -> color_eyre::Result<Textures> {
) -> eyre::Result<Textures> {
let mode: wgpu::AddressMode = match texture_mode {
TextureMode::Clamp => wgpu::AddressMode::Repeat,
TextureMode::Repeat => wgpu::AddressMode::MirrorRepeat,
Expand Down Expand Up @@ -260,7 +260,7 @@ impl crate::header::Renderer {
pub fn build_uniform_buffer(
&mut self,
uniforms: &[wgpu::Buffer],
) -> color_eyre::Result<(UniformBuffers, BindGroupLayout)> {
) -> eyre::Result<(UniformBuffers, BindGroupLayout)> {
let mut buffer_entry = Vec::<wgpu::BindGroupEntry>::new();
let mut buffer_layout = Vec::<wgpu::BindGroupLayoutEntry>::new();

Expand Down Expand Up @@ -303,7 +303,7 @@ impl crate::header::Renderer {
&mut self,
vertices: &Vec<Vertex>,
indices: &Vec<u16>,
) -> color_eyre::Result<VertexBuffers> {
) -> eyre::Result<VertexBuffers> {
let vertex_buffer = self
.device
.create_buffer_init(&wgpu::util::BufferInitDescriptor {
Expand Down
25 changes: 20 additions & 5 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub struct Engine {
/// do not have the know-how, or wish to handle all the work of rendering data manually.
pub objects: ObjectStorage,
/// The camera handles the way the scene looks when rendered. You can modify everything there is to camera through this.
pub camera: Camera,
pub camera: CameraContainer,
/// Handles all engine plugins
pub signals: SignalStorage,
}
Expand Down Expand Up @@ -348,7 +348,7 @@ unsafe impl Send for WindowDescriptor {}
unsafe impl Sync for WindowDescriptor {}

/// Container for the projection used by the camera
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum Projection {
/// Perspective projection
///
Expand Down Expand Up @@ -389,13 +389,28 @@ pub struct Camera {
// For checking and rebuilding it's uniform buffer
pub(crate) changed: bool,
/// The uniform data of the camera to be sent to the gpu
pub uniform_data: crate::UniformBuffers,
pub uniform_data: UniformBuffers,
/// The position and target of the camera
pub(crate) add_position_and_target: bool,
}
unsafe impl Send for Camera {}
unsafe impl Sync for Camera {}

/// Container for Cameras
///
/// This allows for different objects have a different camera perspective.
#[derive(Debug)]
pub struct CameraContainer {
/// The list of cameras
// Arc<str> is used instead of String for performance
pub cameras: std::collections::HashMap<std::sync::Arc<str>, Camera>,
}
impl_deref_field!(
CameraContainer,
std::collections::HashMap<std::sync::Arc<str>, Camera>,
cameras
);

/// These definitions are taken from wgpu API docs
#[derive(Debug, Clone, Copy)]
pub struct ShaderSettings {
Expand Down Expand Up @@ -498,7 +513,7 @@ pub trait Signal: Any {
_objects: &mut ObjectStorage,
_events: &crate::Event<()>,
_input: &crate::InputHelper,
_camera: &mut crate::Camera,
_camera: &mut crate::CameraContainer,
) {
}

Expand All @@ -509,7 +524,7 @@ pub trait Signal: Any {
_renderer: &mut crate::Renderer,
_window: &crate::Window,
_objects: &mut ObjectStorage,
_camera: &mut crate::Camera,
_camera: &mut crate::CameraContainer,
_input: &crate::InputHelper,
_encoder: &mut crate::CommandEncoder,
_view: &crate::TextureView,
Expand Down
Loading

0 comments on commit 790dcf8

Please sign in to comment.