Skip to content

Commit

Permalink
Get building
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-xr committed Jun 14, 2024
1 parent 88bd7ef commit 781ea18
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 30 deletions.
3 changes: 2 additions & 1 deletion runtime/functor-runtime-common/src/geometry/cylinder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::f32::consts::PI;

use cgmath::{vec2, vec3, Vector2, Vector3};
use cgmath::{Vector2, Vector3};

use super::mesh::{self, Mesh};

Expand All @@ -9,6 +9,7 @@ pub struct Cylinder;
#[derive(Debug, Clone, Copy)]
struct Vertex {
position: Vector3<f32>,
#[allow(dead_code)]
normal: Vector3<f32>,
tex_coords: Vector2<f32>,
}
Expand Down
8 changes: 3 additions & 5 deletions runtime/functor-runtime-common/src/geometry/mesh.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use glow::{Buffer, HasContext, VertexArray};
use glow::{HasContext, VertexArray};

use super::Geometry;

struct HydratedContext {
vbo: Buffer,
vao: VertexArray,
triangle_count: i32,
}
Expand All @@ -24,7 +23,7 @@ pub fn create(vertices: Vec<f32>) -> Mesh {
impl Geometry for Mesh {
fn draw(&mut self, gl: &glow::Context) {
if self.hydrated_context.is_none() {
let (vbo, vao) = unsafe {
let vao = unsafe {
let vertices_u8: &[u8] = core::slice::from_raw_parts(
self.vertices.as_ptr() as *const u8,
self.vertices.len() * core::mem::size_of::<f32>(),
Expand Down Expand Up @@ -61,12 +60,11 @@ impl Geometry for Mesh {
// VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary.
gl.bind_buffer(glow::ARRAY_BUFFER, None);
gl.bind_vertex_array(None);
(vbo, vao)
vao
};

self.hydrated_context = Some(HydratedContext {
vao,
vbo,
triangle_count: (self.vertices.len() / 5) as i32,
});
}
Expand Down
2 changes: 0 additions & 2 deletions runtime/functor-runtime-common/src/geometry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use glow::*;

pub trait Geometry {
fn draw(&mut self, gl: &glow::Context);
}
Expand Down
1 change: 1 addition & 0 deletions runtime/functor-runtime-common/src/geometry/sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Sphere;
#[derive(Debug, Clone, Copy)]
struct Vertex {
position: Vector3<f32>,
#[allow(dead_code)]
normal: Vector3<f32>,
tex_coords: Vector2<f32>,
}
Expand Down
1 change: 0 additions & 1 deletion runtime/functor-runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![cfg_attr(feature = "strict", deny(warnings))]

use serde::*;
use std::any::Any;

#[cfg(target_arch = "wasm32")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use cgmath::Matrix4;

use std::sync::OnceLock;

use crate::shader_program::ShaderProgram;
use crate::shader_program::UniformLocation;
use crate::RenderContext;

Expand Down Expand Up @@ -48,7 +45,7 @@ use crate::shader::Shader;
use crate::shader::ShaderType;

impl Material for BasicMaterial {
fn initialize(&mut self, ctx: &RenderContext) {}
fn initialize(&mut self, _ctx: &RenderContext) {}
// let _ = SHADER_PROGRAM.get_or_init(|| {
// // build and compile our shader program
// // ------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion runtime/functor-runtime-common/src/material/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub trait Material {
) -> bool;
fn draw_transparent(
&self,
ctx: &RenderContext,
_ctx: &RenderContext,
_projection_matrix: &Matrix4<f32>,
_view_matrix: &Matrix4<f32>,
_world_matrix: &Matrix4<f32>,
Expand All @@ -26,6 +26,7 @@ mod basic_material;
mod color_material;

pub use basic_material::*;
#[allow(unused_imports)]
pub use color_material::*;

use crate::RenderContext;
2 changes: 1 addition & 1 deletion runtime/functor-runtime-common/src/scene3d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cgmath::{vec3, Matrix4, SquareMatrix};
use serde::{Deserialize, Serialize};

use fable_library_rust::{List_, NativeArray_::Array};
use fable_library_rust::NativeArray_::Array;

use crate::{
geometry::{self, Geometry},
Expand Down
1 change: 0 additions & 1 deletion runtime/functor-runtime-common/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl Shader {

let shader;
unsafe {
let mut success = 0;
let shader_source = convert(shader_contents, opengl_version);
shader = gl
.create_shader(gl_shader_type)
Expand Down
28 changes: 14 additions & 14 deletions runtime/functor-runtime-common/src/shader_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ impl ShaderProgram {
fragment_shader: &Shader,
) -> ShaderProgram {
unsafe {
let mut success = 0;
let program_id = gl.create_program().expect("Cannot create program");
gl.attach_shader(program_id, vertex_shader.shader_id);
gl.attach_shader(program_id, fragment_shader.shader_id);
Expand Down Expand Up @@ -52,19 +51,20 @@ impl ShaderProgram {
}
}

// pub fn set_uniform_vec3(
// &self,
// gl: &glow::Context,
// uniform_location: &UniformLocation,
// vec: &Vector3<f32>,
// ) {
// unsafe {
// gl.uniform_3_f32_slice(
// Some(&uniform_location.native_uniform_location),
// &[vec.x, vec.y, vec.z],
// )
// }
// }
#[allow(dead_code)]
pub fn set_uniform_vec3(
&self,
gl: &glow::Context,
uniform_location: &UniformLocation,
vec: &Vector3<f32>,
) {
unsafe {
gl.uniform_3_f32_slice(
Some(&uniform_location.native_uniform_location),
&[vec.x, vec.y, vec.z],
)
}
}

pub fn set_uniform_matrix4(
&self,
Expand Down

0 comments on commit 781ea18

Please sign in to comment.