diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-13 23:32:00 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-13 23:32:00 +0200 |
commit | 12f48046b2606fc77a1312a6d5e5fc7ff9feff88 (patch) | |
tree | 644f4abd6785a5f0c066c7fbadcfc5e820a41ebf /engine/src/renderer/mod.rs | |
parent | cfa73b1ea42fa491ff9e00bb5efb5e5a5d860578 (diff) |
refactor(engine): move uses of OpenGL to OpenGL module
Diffstat (limited to 'engine/src/renderer/mod.rs')
-rw-r--r-- | engine/src/renderer/mod.rs | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index a23d5a0..4ed3c0a 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -3,14 +3,13 @@ use std::process::abort; use glfw::WindowSize; -use crate::renderer::vertex_array::{PrimitiveKind, VertexArray}; -use crate::renderer::vertex_buffer::{BufferUsage, VertexBuffer}; +use crate::opengl::shader::Program as ShaderProgram; +use crate::opengl::vertex_array::{PrimitiveKind, VertexArray}; +use crate::opengl::vertex_buffer::{BufferUsage, VertexBuffer}; +use crate::opengl::{clear_buffers, BufferClearMask}; use crate::vector::Vec2; use crate::vertex::Vertex; -mod vertex_array; -mod vertex_buffer; - pub fn initialize(window: &glfw::Window) -> Result<(), Error> { gl::load_with(|symbol| { @@ -38,9 +37,7 @@ pub fn initialize(window: &glfw::Window) -> Result<(), Error> pub fn render<'renderable>(renderables: impl IntoIterator<Item = &'renderable Renderable>) { - unsafe { - gl::Clear(gl::COLOR_BUFFER_BIT); - } + clear_buffers(BufferClearMask::COLOR); for renderable in renderables { renderable.shader_program.activate(); @@ -51,10 +48,15 @@ pub fn render<'renderable>(renderables: impl IntoIterator<Item = &'renderable Re } } +pub fn set_viewport(position: &Vec2<u32>, size: &WindowSize) +{ + crate::opengl::set_viewport(position, size); +} + #[derive(Debug)] pub struct Renderable { - shader_program: crate::shader::Program, + shader_program: ShaderProgram, vertex_arr: VertexArray, /// Vertex buffer has to live as long as the vertex array @@ -63,7 +65,7 @@ pub struct Renderable impl Renderable { - pub fn new(shader_program: crate::shader::Program, vertices: &[Vertex]) -> Self + pub fn new(shader_program: ShaderProgram, vertices: &[Vertex]) -> Self { let vertex_arr = VertexArray::new(); let vertex_buffer = VertexBuffer::new(); @@ -84,19 +86,6 @@ impl Renderable } } -pub fn set_viewport(position: &Vec2<u32>, size: &WindowSize) -{ - unsafe { - #[allow(clippy::cast_possible_wrap)] - gl::Viewport( - position.x as i32, - position.y as i32, - size.width as i32, - size.height as i32, - ); - } -} - /// Renderer error. #[derive(Debug, thiserror::Error)] pub enum Error |