summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-11-24 21:04:30 +0100
committerHampusM <hampus@hampusmat.com>2024-11-24 21:04:30 +0100
commit09b9f3c1cbd93c75b2fe69257b278ad3f993adf4 (patch)
tree8de3ad13c46ec6856e81dc75c047facc11c747c2
parentb233ff766a2e399a0a48a98e1f2121e960254950 (diff)
refactor(engine): remove 'debug' crate feature flag
-rw-r--r--Cargo.toml2
-rw-r--r--engine/Cargo.toml5
-rw-r--r--engine/src/camera/fly.rs1
-rw-r--r--engine/src/file_format/wavefront/mtl.rs11
-rw-r--r--engine/src/input.rs3
-rw-r--r--engine/src/opengl/mod.rs22
-rw-r--r--engine/src/performance.rs16
-rw-r--r--engine/src/renderer/opengl.rs39
-rw-r--r--engine/src/window.rs2
9 files changed, 47 insertions, 54 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 5eacd0c..18fe135 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,6 @@ edition = "2021"
members = ["glfw", "engine", "ecs", "ecs-macros", "util-macros"]
[dependencies]
-engine = { path = "./engine", features = ["debug"] }
+engine = { path = "./engine" }
tracing = "0.1.39"
tracing-subscriber = "0.3.17"
diff --git a/engine/Cargo.toml b/engine/Cargo.toml
index b3868ac..a2cc7aa 100644
--- a/engine/Cargo.toml
+++ b/engine/Cargo.toml
@@ -3,15 +3,12 @@ name = "engine"
version = "0.1.0"
edition = "2021"
-[features]
-debug = ["dep:tracing"]
-
[dependencies]
glfw = { path = "../glfw", features = ["opengl"] }
thiserror = "1.0.49"
gl = "0.14.0"
bitflags = "2.4.0"
-tracing = { version = "0.1.39", optional = true }
+tracing = "0.1.39"
seq-macro = "0.3.5"
paste = "1.0.14"
ecs = { path = "../ecs" }
diff --git a/engine/src/camera/fly.rs b/engine/src/camera/fly.rs
index b6ba7aa..4c49846 100644
--- a/engine/src/camera/fly.rs
+++ b/engine/src/camera/fly.rs
@@ -87,7 +87,6 @@ fn update(
{
for (mut camera, mut camera_pos, mut fly_camera, _) in &camera_query {
if cursor.has_moved && cursor_flags.is_first_move.flag {
- #[cfg(feature = "debug")]
tracing::debug!("First cursor move");
cursor_state.last_pos = cursor.position;
diff --git a/engine/src/file_format/wavefront/mtl.rs b/engine/src/file_format/wavefront/mtl.rs
index ef6e894..d90dbcf 100644
--- a/engine/src/file_format/wavefront/mtl.rs
+++ b/engine/src/file_format/wavefront/mtl.rs
@@ -44,7 +44,6 @@ pub fn parse(obj_content: &str) -> Result<Vec<NamedMaterial>, Error>
.filter(|(_, statement)| matches!(statement.keyword, Keyword::Newmtl))
.count();
- #[cfg(feature = "debug")]
tracing::debug!("Material count: {material_cnt}");
statements_to_materials(statements, material_cnt)
@@ -93,7 +92,7 @@ pub enum Error
},
}
-#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
+#[tracing::instrument(skip_all)]
fn statements_to_materials(
statements: impl IntoIterator<Item = (usize, Statement<Keyword>)>,
material_cnt: usize,
@@ -110,7 +109,6 @@ fn statements_to_materials(
for (line_no, statement) in statements {
if statement.keyword == Keyword::Newmtl {
if curr_material.ready {
- #[cfg(feature = "debug")]
tracing::debug!("Building material");
let material = curr_material.material_builder.clone().build();
@@ -135,7 +133,6 @@ fn statements_to_materials(
Keyword::Ka => {
let color = get_color_from_statement(&statement, line_no)?;
- #[cfg(feature = "debug")]
tracing::debug!("Adding ambient color");
curr_material.material_builder =
@@ -144,7 +141,6 @@ fn statements_to_materials(
Keyword::Kd => {
let color = get_color_from_statement(&statement, line_no)?;
- #[cfg(feature = "debug")]
tracing::debug!("Adding diffuse color");
curr_material.material_builder =
@@ -153,7 +149,6 @@ fn statements_to_materials(
Keyword::Ks => {
let color = get_color_from_statement(&statement, line_no)?;
- #[cfg(feature = "debug")]
tracing::debug!("Adding specular color");
curr_material.material_builder =
@@ -172,7 +167,6 @@ fn statements_to_materials(
let texture = Texture::open(Path::new(texture_file_path))?;
- #[cfg(feature = "debug")]
tracing::debug!("Adding ambient map");
let texture_id = texture.id();
@@ -185,7 +179,6 @@ fn statements_to_materials(
Keyword::MapKd => {
let texture = get_map_from_texture(&statement, line_no)?;
- #[cfg(feature = "debug")]
tracing::debug!("Adding diffuse map");
let texture_id = texture.id();
@@ -198,7 +191,6 @@ fn statements_to_materials(
Keyword::MapKs => {
let texture = get_map_from_texture(&statement, line_no)?;
- #[cfg(feature = "debug")]
tracing::debug!("Adding specular map");
let texture_id = texture.id();
@@ -213,7 +205,6 @@ fn statements_to_materials(
}
if curr_material.ready {
- #[cfg(feature = "debug")]
tracing::debug!("Building last material");
let material = curr_material.material_builder.build();
diff --git a/engine/src/input.rs b/engine/src/input.rs
index f4166f6..04e5263 100644
--- a/engine/src/input.rs
+++ b/engine/src/input.rs
@@ -194,7 +194,6 @@ fn initialize(
let cursor_flags_weak_ref = cursor_flags.to_weak_ref();
window.set_focus_callback(move |is_focused| {
- #[cfg(feature = "debug")]
tracing::trace!("Window is focused: {is_focused}");
let cursor_flags_ref = cursor_flags_weak_ref.access().expect("No world");
@@ -209,7 +208,6 @@ fn maybe_clear_cursor_is_first_move(
)
{
if cursor_flags.is_first_move.pending_clear {
- #[cfg(feature = "debug")]
tracing::trace!("Clearing is_first_move");
// This flag was set for the whole previous tick so it can be cleared now
@@ -219,7 +217,6 @@ fn maybe_clear_cursor_is_first_move(
}
if cursor.has_moved && cursor_flags.is_first_move.flag {
- #[cfg(feature = "debug")]
tracing::trace!("Setting flag to clear is_first_move next tick");
// Make this system clear is_first_move the next time it runs
diff --git a/engine/src/opengl/mod.rs b/engine/src/opengl/mod.rs
index a4d3959..53e0120 100644
--- a/engine/src/opengl/mod.rs
+++ b/engine/src/opengl/mod.rs
@@ -1,4 +1,5 @@
use bitflags::bitflags;
+use gl::types::GLint;
use crate::data_types::dimens::Dimens;
use crate::vector::Vec2;
@@ -11,7 +12,6 @@ pub mod vertex_array;
mod util;
-#[cfg(feature = "debug")]
pub mod debug;
pub fn set_viewport(position: Vec2<u32>, size: Dimens<u32>)
@@ -48,6 +48,17 @@ pub fn enable(capacity: Capability)
}
}
+pub fn get_context_flags() -> ContextFlags
+{
+ let mut context_flags: GLint = 0;
+
+ unsafe {
+ gl::GetIntegerv(gl::CONTEXT_FLAGS as u32, &mut context_flags);
+ }
+
+ ContextFlags::from_bits_truncate(context_flags as u32)
+}
+
bitflags! {
#[derive(Debug, Clone, Copy)]
pub struct BufferClearMask: u32 {
@@ -106,3 +117,12 @@ impl From<crate::draw_flags::PolygonModeFace> for PolygonModeFace
}
}
}
+
+bitflags! {
+#[derive(Debug, Clone, Copy)]
+pub struct ContextFlags: u32 {
+ const FORWARD_COMPATIBLE = gl::CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
+ const DEBUG = gl::CONTEXT_FLAG_DEBUG_BIT;
+ const ROBUST_ACCESS = gl::CONTEXT_FLAG_ROBUST_ACCESS_BIT;
+}
+}
diff --git a/engine/src/performance.rs b/engine/src/performance.rs
index ffc5c27..3ec8994 100644
--- a/engine/src/performance.rs
+++ b/engine/src/performance.rs
@@ -21,20 +21,6 @@ impl ecs::extension::Extension for Extension
}
}
-#[cfg(feature = "debug")]
-macro_rules! log_perf {
- ($($tt: tt)*) => {
- tracing::info!($($tt)*);
- };
-}
-
-#[cfg(not(feature = "debug"))]
-macro_rules! log_perf {
- ($($tt: tt)*) => {
- println!($($tt)*);
- };
-}
-
fn log_perf(mut state: Local<State>)
{
let Some(last_time) = state.last_time else {
@@ -46,7 +32,7 @@ fn log_perf(mut state: Local<State>)
state.last_time = Some(time_now);
- log_perf!(
+ tracing::info!(
"Frame time: {}us",
time_now.duration_since(last_time).as_micros()
);
diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs
index e7a630b..c036cc0 100644
--- a/engine/src/renderer/opengl.rs
+++ b/engine/src/renderer/opengl.rs
@@ -24,8 +24,15 @@ use crate::material::{Flags as MaterialFlags, Material};
use crate::matrix::Matrix;
use crate::mesh::Mesh;
use crate::opengl::buffer::{Buffer, Usage as BufferUsage};
-#[cfg(feature = "debug")]
-use crate::opengl::debug::{MessageSeverity, MessageSource, MessageType};
+use crate::opengl::debug::{
+ enable_debug_output,
+ set_debug_message_callback,
+ set_debug_message_control,
+ MessageIdsAction,
+ MessageSeverity,
+ MessageSource,
+ MessageType,
+};
use crate::opengl::glsl::{
preprocess as glsl_preprocess,
PreprocessingError as GlslPreprocessingError,
@@ -46,7 +53,14 @@ use crate::opengl::vertex_array::{
PrimitiveKind,
VertexArray,
};
-use crate::opengl::{clear_buffers, enable, BufferClearMask, Capability};
+use crate::opengl::{
+ clear_buffers,
+ enable,
+ get_context_flags as get_opengl_context_flags,
+ BufferClearMask,
+ Capability,
+ ContextFlags,
+};
use crate::projection::{new_perspective_matrix, Projection};
use crate::texture::{Id as TextureId, Texture};
use crate::transform::{Position, Scale};
@@ -101,8 +115,9 @@ fn initialize(window: Single<Window>)
}
});
- #[cfg(feature = "debug")]
- initialize_debug();
+ if get_opengl_context_flags().contains(ContextFlags::DEBUG) {
+ initialize_debug();
+ }
let window_size = window.size().expect("Failed to get window size");
@@ -129,7 +144,6 @@ fn render(
)
{
let Some((camera, camera_pos, _)) = camera_query.iter().next() else {
- #[cfg(feature = "debug")]
tracing::warn!("No current camera. Nothing will be rendered");
return;
};
@@ -249,20 +263,11 @@ fn set_viewport(position: Vec2<u32>, size: Dimens<u32>)
crate::opengl::set_viewport(position, size);
}
-#[cfg(feature = "debug")]
fn initialize_debug()
{
- use crate::opengl::debug::{
- enable_debug_output,
- set_debug_message_callback,
- set_debug_message_control,
- MessageIdsAction,
- };
-
enable_debug_output();
set_debug_message_callback(opengl_debug_message_cb);
-
set_debug_message_control(None, None, None, &[], MessageIdsAction::Disable);
}
@@ -367,10 +372,9 @@ struct GlObjects
impl GlObjects
{
- #[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
+ #[tracing::instrument(skip_all)]
fn new(mesh: &Mesh) -> Self
{
- #[cfg(feature = "debug")]
tracing::trace!(
"Creating vertex array, vertex buffer{}",
if mesh.indices().is_some() {
@@ -692,7 +696,6 @@ fn create_view(camera: &Camera, camera_pos: &Position) -> Matrix<f32, 4, 4>
view
}
-#[cfg(feature = "debug")]
#[tracing::instrument(skip_all)]
fn opengl_debug_message_cb(
source: MessageSource,
diff --git a/engine/src/window.rs b/engine/src/window.rs
index ccc1b8d..b65831a 100644
--- a/engine/src/window.rs
+++ b/engine/src/window.rs
@@ -205,7 +205,7 @@ impl Builder
{
let builder = self.inner.clone().hint(
CreationHint::OpenGLDebugContext,
- CreationHintValue::Bool(cfg!(feature = "debug")),
+ CreationHintValue::Bool(true),
);
let window = builder.create(