Skip to content

Commit

Permalink
Rename entity debug to rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
kokosha committed Dec 14, 2024
1 parent 6272741 commit 64948b4
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 57 deletions.
38 changes: 18 additions & 20 deletions korangar/src/graphics/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ struct EngineContext {
point_shadow_indicator_drawer: PointShadowIndicatorDrawer,
light_culling_dispatcher: LightCullingDispatcher,
forward_entity_drawer: ForwardEntityDrawer,
#[cfg(feature = "debug")]
forward_entity_debug_drawer: ForwardEntityDebugDrawer,
forward_indicator_drawer: ForwardIndicatorDrawer,
forward_model_drawer: ForwardModelDrawer,
water_wave_drawer: WaterWaveDrawer,
Expand All @@ -106,6 +104,8 @@ struct EngineContext {
#[cfg(feature = "debug")]
forward_circle_drawer: ForwardCircleDrawer,
#[cfg(feature = "debug")]
forward_rectangle_drawer: ForwardRectangleDrawer,
#[cfg(feature = "debug")]
post_processing_buffer_drawer: PostProcessingBufferDrawer,
#[cfg(feature = "debug")]
picker_marker_drawer: PickerMarkerDrawer,
Expand Down Expand Up @@ -285,16 +285,15 @@ impl GraphicsEngine {
);
let ForwardResources {
forward_entity_drawer,
#[cfg(feature = "debug")]
forward_entity_debug_drawer,
forward_indicator_drawer,
forward_model_drawer,

#[cfg(feature = "debug")]
forward_aabb_drawer,

#[cfg(feature = "debug")]
forward_circle_drawer,
#[cfg(feature = "debug")]
forward_rectangle_drawer,
} = ForwardResources::create(
&self.capabilities,
&self.device,
Expand Down Expand Up @@ -362,8 +361,6 @@ impl GraphicsEngine {
point_shadow_entity_drawer,
light_culling_dispatcher,
forward_entity_drawer,
#[cfg(feature = "debug")]
forward_entity_debug_drawer,
forward_indicator_drawer,
forward_model_drawer,
water_wave_drawer,
Expand All @@ -377,6 +374,8 @@ impl GraphicsEngine {
#[cfg(feature = "debug")]
forward_circle_drawer,
#[cfg(feature = "debug")]
forward_rectangle_drawer,
#[cfg(feature = "debug")]
post_processing_buffer_drawer,
#[cfg(feature = "debug")]
picker_marker_drawer,
Expand Down Expand Up @@ -488,14 +487,14 @@ impl GraphicsEngine {

let ForwardResources {
forward_entity_drawer,
#[cfg(feature = "debug")]
forward_entity_debug_drawer,
forward_indicator_drawer,
forward_model_drawer,
#[cfg(feature = "debug")]
forward_aabb_drawer,
#[cfg(feature = "debug")]
forward_circle_drawer,
#[cfg(feature = "debug")]
forward_rectangle_drawer,
} = ForwardResources::create(
&self.capabilities,
&self.device,
Expand Down Expand Up @@ -539,8 +538,8 @@ impl GraphicsEngine {
{
engine_context.forward_aabb_drawer = forward_aabb_drawer;
engine_context.forward_circle_drawer = forward_circle_drawer;
engine_context.forward_rectangle_drawer = forward_rectangle_drawer;
engine_context.post_processing_buffer_drawer = post_processing_buffer_drawer;
engine_context.forward_entity_debug_drawer = forward_entity_debug_drawer;
}
}
}
Expand Down Expand Up @@ -780,13 +779,12 @@ impl GraphicsEngine {
scope.spawn(|_| {
context.picker_marker_drawer.prepare(&self.device, instruction);
context.forward_aabb_drawer.prepare(&self.device, instruction);
#[cfg(feature = "debug")]
context.forward_entity_debug_drawer.prepare(&self.device, instruction);
});
#[cfg(feature = "debug")]
scope.spawn(|_| {
context.post_processing_buffer_drawer.prepare(&self.device, instruction);
context.forward_circle_drawer.prepare(&self.device, instruction);
context.forward_rectangle_drawer.prepare(&self.device, instruction);
});

context.global_context.prepare(&self.device, instruction);
Expand Down Expand Up @@ -820,10 +818,10 @@ impl GraphicsEngine {

#[cfg(feature = "debug")]
{
visitor.upload(&mut context.forward_entity_debug_drawer);
visitor.upload(&mut context.forward_aabb_drawer);
visitor.upload(&mut context.post_processing_buffer_drawer);
visitor.upload(&mut context.forward_circle_drawer);
visitor.upload(&mut context.forward_rectangle_drawer);
visitor.upload(&mut context.picker_marker_drawer);
}

Expand Down Expand Up @@ -1012,7 +1010,7 @@ impl GraphicsEngine {
{
engine_context.forward_aabb_drawer.draw(&mut render_pass, None);
engine_context.forward_circle_drawer.draw(&mut render_pass, None);
engine_context.forward_entity_debug_drawer.draw(&mut render_pass, None);
engine_context.forward_rectangle_drawer.draw(&mut render_pass, None);
}

if instruction.water.is_some() {
Expand Down Expand Up @@ -1183,15 +1181,15 @@ impl<'a> UploadVisitor<'a> {

struct ForwardResources {
forward_entity_drawer: ForwardEntityDrawer,
#[cfg(feature = "debug")]
forward_entity_debug_drawer: ForwardEntityDebugDrawer,
forward_indicator_drawer: ForwardIndicatorDrawer,
forward_model_drawer: ForwardModelDrawer,

#[cfg(feature = "debug")]
forward_aabb_drawer: ForwardAabbDrawer,
#[cfg(feature = "debug")]
forward_circle_drawer: ForwardCircleDrawer,
#[cfg(feature = "debug")]
forward_rectangle_drawer: ForwardRectangleDrawer,
}

impl ForwardResources {
Expand All @@ -1203,25 +1201,25 @@ impl ForwardResources {
forward_pass_context: &ForwardRenderPassContext,
) -> Self {
let forward_entity_drawer = ForwardEntityDrawer::new(capabilities, device, queue, global_context, forward_pass_context);
#[cfg(feature = "debug")]
let forward_entity_debug_drawer = ForwardEntityDebugDrawer::new(capabilities, device, queue, global_context, forward_pass_context);
let forward_indicator_drawer = ForwardIndicatorDrawer::new(capabilities, device, queue, global_context, forward_pass_context);
let forward_model_drawer = ForwardModelDrawer::new(capabilities, device, queue, global_context, forward_pass_context);
#[cfg(feature = "debug")]
let forward_aabb_drawer = ForwardAabbDrawer::new(capabilities, device, queue, global_context, forward_pass_context);
#[cfg(feature = "debug")]
let forward_circle_drawer = ForwardCircleDrawer::new(capabilities, device, queue, global_context, forward_pass_context);
#[cfg(feature = "debug")]
let forward_rectangle_drawer = ForwardRectangleDrawer::new(capabilities, device, queue, global_context, forward_pass_context);

Self {
forward_entity_drawer,
#[cfg(feature = "debug")]
forward_entity_debug_drawer,
forward_indicator_drawer,
forward_model_drawer,
#[cfg(feature = "debug")]
forward_aabb_drawer,
#[cfg(feature = "debug")]
forward_circle_drawer,
#[cfg(feature = "debug")]
forward_rectangle_drawer,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions korangar/src/graphics/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ pub struct RenderInstruction<'a> {
pub model_batches: &'a [ModelBatch],
pub models: &'a mut [ModelInstruction],
pub entities: &'a mut [EntityInstruction],
#[cfg(feature = "debug")]
pub entities_debug: &'a [DebugEntityInstruction],
pub directional_model_batches: &'a [ModelBatch],
pub directional_shadow_models: &'a [ModelInstruction],
pub directional_shadow_entities: &'a [EntityInstruction],
Expand All @@ -50,6 +48,8 @@ pub struct RenderInstruction<'a> {
#[cfg(feature = "debug")]
pub circles: &'a [DebugCircleInstruction],
#[cfg(feature = "debug")]
pub rectangles: &'a [DebugRectangleInstruction],
#[cfg(feature = "debug")]
pub marker: &'a [MarkerInstruction],
}

Expand Down Expand Up @@ -241,7 +241,7 @@ pub struct DebugCircleInstruction {

#[cfg(feature = "debug")]
#[derive(Copy, Clone, Debug)]
pub struct DebugEntityInstruction {
pub struct DebugRectangleInstruction {
pub world: Matrix4<f32>,
pub color: Color,
}
8 changes: 4 additions & 4 deletions korangar/src/graphics/passes/forward/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ mod aabb;
#[cfg(feature = "debug")]
mod circle;
mod entity;
#[cfg(feature = "debug")]
mod entity_debug;
mod indicator;
mod model;
#[cfg(feature = "debug")]
mod rectangle;

#[cfg(feature = "debug")]
pub(crate) use aabb::ForwardAabbDrawer;
#[cfg(feature = "debug")]
pub(crate) use circle::ForwardCircleDrawer;
pub(crate) use entity::ForwardEntityDrawer;
#[cfg(feature = "debug")]
pub(crate) use entity_debug::ForwardEntityDebugDrawer;
pub(crate) use indicator::ForwardIndicatorDrawer;
pub(crate) use model::ForwardModelDrawer;
#[cfg(feature = "debug")]
pub(crate) use rectangle::ForwardRectangleDrawer;
use wgpu::{
BindGroupLayout, Color, CommandEncoder, Device, LoadOp, Operations, Queue, RenderPass, RenderPassColorAttachment,
RenderPassDepthStencilAttachment, RenderPassDescriptor, StoreOp, TextureFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::graphics::passes::{
use crate::graphics::{Capabilities, GlobalContext, Prepare, RenderInstruction, SimpleVertex};
use crate::Buffer;

const SHADER: ShaderModuleDescriptor = include_wgsl!("shader/entity_debug.wgsl");
const DRAWER_NAME: &str = "forward entity debug";
const SHADER: ShaderModuleDescriptor = include_wgsl!("shader/rectangle.wgsl");
const DRAWER_NAME: &str = "screen rectangle";
const INITIAL_INSTRUCTION_SIZE: usize = 256;
const INDEX_COUNT: usize = 8;

Expand All @@ -29,7 +29,7 @@ struct InstanceData {
color: [f32; 4],
}

pub(crate) struct ForwardEntityDebugDrawer {
pub(crate) struct ForwardRectangleDrawer {
vertex_buffer: Buffer<SimpleVertex>,
index_buffer: Buffer<u16>,
instance_data_buffer: Buffer<InstanceData>,
Expand All @@ -40,7 +40,7 @@ pub(crate) struct ForwardEntityDebugDrawer {
instance_data: Vec<InstanceData>,
}

impl Drawer<{ BindGroupCount::Two }, { ColorAttachmentCount::One }, { DepthAttachmentCount::One }> for ForwardEntityDebugDrawer {
impl Drawer<{ BindGroupCount::Two }, { ColorAttachmentCount::One }, { DepthAttachmentCount::One }> for ForwardRectangleDrawer {
type Context = ForwardRenderPassContext;
type DrawData<'data> = Option<()>;

Expand Down Expand Up @@ -173,17 +173,17 @@ impl Drawer<{ BindGroupCount::Two }, { ColorAttachmentCount::One }, { DepthAttac
}
}

impl Prepare for ForwardEntityDebugDrawer {
impl Prepare for ForwardRectangleDrawer {
fn prepare(&mut self, _device: &Device, instructions: &RenderInstruction) {
self.draw_count = instructions.entities_debug.len();
self.draw_count = instructions.rectangles.len();

if self.draw_count == 0 {
return;
}

self.instance_data.clear();

for instruction in instructions.entities_debug.iter() {
for instruction in instructions.rectangles.iter() {
self.instance_data.push(InstanceData {
world: instruction.world.into(),
color: instruction.color.into(),
Expand All @@ -202,7 +202,7 @@ impl Prepare for ForwardEntityDebugDrawer {
}
}

impl ForwardEntityDebugDrawer {
impl ForwardRectangleDrawer {
fn create_bind_group(device: &Device, bind_group_layout: &BindGroupLayout, instance_data_buffer: &Buffer<InstanceData>) -> BindGroup {
device.create_bind_group(&BindGroupDescriptor {
label: Some(DRAWER_NAME),
Expand Down
22 changes: 11 additions & 11 deletions korangar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ struct Client {
aabb_instructions: Vec<DebugAabbInstruction>,
#[cfg(feature = "debug")]
circle_instructions: Vec<DebugCircleInstruction>,
#[cfg(feature = "debug")]
rectangle_instructions: Vec<DebugRectangleInstruction>,
model_batches: Vec<ModelBatch>,
model_instructions: Vec<ModelInstruction>,
entity_instructions: Vec<EntityInstruction>,
#[cfg(feature = "debug")]
entity_debug_instructions: Vec<DebugEntityInstruction>,
directional_shadow_model_batches: Vec<ModelBatch>,
directional_shadow_model_instructions: Vec<ModelInstruction>,
directional_shadow_entity_instructions: Vec<EntityInstruction>,
Expand Down Expand Up @@ -417,11 +417,11 @@ impl Client {
let aabb_instructions = Vec::default();
#[cfg(feature = "debug")]
let circle_instructions = Vec::default();
#[cfg(feature = "debug")]
let rectangle_instructions = Vec::default();
let model_batches = Vec::default();
let model_instructions = Vec::default();
let entity_instructions = Vec::default();
#[cfg(feature = "debug")]
let entity_debug_instructions = Vec::default();
let directional_shadow_model_batches = Vec::default();
let directional_shadow_model_instructions = Vec::default();
let directional_shadow_entity_instructions = Vec::default();
Expand Down Expand Up @@ -588,11 +588,11 @@ impl Client {
aabb_instructions,
#[cfg(feature = "debug")]
circle_instructions,
#[cfg(feature = "debug")]
rectangle_instructions,
model_batches,
model_instructions,
entity_instructions,
#[cfg(feature = "debug")]
entity_debug_instructions,
directional_shadow_model_batches,
directional_shadow_model_instructions,
directional_shadow_entity_instructions,
Expand Down Expand Up @@ -690,11 +690,11 @@ impl Client {
self.aabb_instructions.clear();
#[cfg(feature = "debug")]
self.circle_instructions.clear();
#[cfg(feature = "debug")]
self.rectangle_instructions.clear();
self.model_batches.clear();
self.model_instructions.clear();
self.entity_instructions.clear();
#[cfg(feature = "debug")]
self.entity_debug_instructions.clear();
self.directional_shadow_model_batches.clear();
self.directional_shadow_model_instructions.clear();
self.directional_shadow_entity_instructions.clear();
Expand Down Expand Up @@ -2105,7 +2105,7 @@ impl Client {
#[cfg(feature = "debug")]
if render_settings.show_entities_debug {
self.map
.render_entities_debug(&mut self.entity_debug_instructions, entities, entity_camera);
.render_entities_debug(&mut self.rectangle_instructions, entities, entity_camera);
}

#[cfg_attr(feature = "debug", korangar_debug::debug_condition(render_settings.show_water))]
Expand Down Expand Up @@ -2280,8 +2280,6 @@ impl Client {
model_batches: &self.model_batches,
models: &mut self.model_instructions,
entities: &mut self.entity_instructions,
#[cfg(feature = "debug")]
entities_debug: &self.entity_debug_instructions,
directional_model_batches: &self.directional_shadow_model_batches,
directional_shadow_models: &self.directional_shadow_model_instructions,
directional_shadow_entities: &self.directional_shadow_entity_instructions,
Expand All @@ -2298,6 +2296,8 @@ impl Client {
#[cfg(feature = "debug")]
circles: &self.circle_instructions,
#[cfg(feature = "debug")]
rectangles: &self.rectangle_instructions,
#[cfg(feature = "debug")]
marker: self.debug_marker_renderer.get_instructions(),
};

Expand Down
Loading

0 comments on commit 64948b4

Please sign in to comment.