Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcomputerguy0101 committed Oct 1, 2024
1 parent 973bce5 commit c9d0a98
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 76 deletions.
3 changes: 1 addition & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ fn normalized_format_from_data_type<T: DataType>() -> u32 {
fn format_from_data_type<T: DataType>() -> u32 {
if T::data_type() == crate::context::FLOAT || T::data_type() == crate::context::HALF_FLOAT {
normalized_format_from_data_type::<T>()
}
else {
} else {
match T::size() {
1 => crate::context::RED_INTEGER,
2 => crate::context::RG_INTEGER,
Expand Down
95 changes: 35 additions & 60 deletions src/core/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ pub trait PrimitiveDataType: DataType + Copy + Default + Zero {
type_: UniformType,
);

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
);
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]);

fn internal_format_with_size(size: u32) -> u32;
}
Expand Down Expand Up @@ -56,13 +51,12 @@ impl PrimitiveDataType for u8 {
u32::send_uniform_with_type(context, location, &data, type_)
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
context.clear_buffer_u32_slice(target, buffer, &values.iter().map(|v| *v as u32).collect::<Vec<_>>());
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_u32_slice(
target,
buffer,
&values.iter().map(|v| *v as u32).collect::<Vec<_>>(),
);
}
}
impl PrimitiveDataType for u16 {
Expand Down Expand Up @@ -90,20 +84,19 @@ impl PrimitiveDataType for u16 {
u32::send_uniform_with_type(context, location, &data, type_)
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
context.clear_buffer_u32_slice(target, buffer, &values.iter().map(|v| *v as u32).collect::<Vec<_>>());
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_u32_slice(
target,
buffer,
&values.iter().map(|v| *v as u32).collect::<Vec<_>>(),
);
}
}
impl PrimitiveDataType for u32 {
fn max() -> Self {
Self::MAX
}

fn internal_format_with_size(size: u32) -> u32 {
match size {
1 => crate::context::R32UI,
Expand Down Expand Up @@ -131,12 +124,7 @@ impl PrimitiveDataType for u32 {
}
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_u32_slice(target, buffer, values);
}
}
Expand Down Expand Up @@ -165,13 +153,12 @@ impl PrimitiveDataType for i8 {
i32::send_uniform_with_type(context, location, &data, type_)
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
context.clear_buffer_i32_slice(target, buffer, &values.iter().map(|v| *v as i32).collect::<Vec<_>>());
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_i32_slice(
target,
buffer,
&values.iter().map(|v| *v as i32).collect::<Vec<_>>(),
);
}
}
impl PrimitiveDataType for i16 {
Expand Down Expand Up @@ -199,13 +186,12 @@ impl PrimitiveDataType for i16 {
i32::send_uniform_with_type(context, location, &data, type_)
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
context.clear_buffer_i32_slice(target, buffer, &values.iter().map(|v| *v as i32).collect::<Vec<_>>());
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_i32_slice(
target,
buffer,
&values.iter().map(|v| *v as i32).collect::<Vec<_>>(),
);
}
}
impl PrimitiveDataType for i32 {
Expand Down Expand Up @@ -240,12 +226,7 @@ impl PrimitiveDataType for i32 {
}
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_i32_slice(target, buffer, values);
}
}
Expand Down Expand Up @@ -274,13 +255,12 @@ impl PrimitiveDataType for f16 {
f32::send_uniform_with_type(context, location, &data, type_)
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
context.clear_buffer_f32_slice(target, buffer, &values.iter().map(|v| v.to_f32()).collect::<Vec<_>>());
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_f32_slice(
target,
buffer,
&values.iter().map(|v| v.to_f32()).collect::<Vec<_>>(),
);
}
}
impl PrimitiveDataType for f32 {
Expand Down Expand Up @@ -323,12 +303,7 @@ impl PrimitiveDataType for f32 {
}
}

unsafe fn clear_buffer_with_type(
context: &Context,
target: u32,
buffer: u32,
values: &[Self],
) {
unsafe fn clear_buffer_with_type(context: &Context, target: u32, buffer: u32, values: &[Self]) {
context.clear_buffer_f32_slice(target, buffer, values);
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/core/render_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ impl<'a> RenderTarget<'a> {
///
/// Clears the color and depth of the part of this render target that is inside the given scissor box, in the given data type.
///
pub fn clear_buffer_partially(&self, scissor_box: ScissorBox, clear_state: ClearState<impl PrimitiveDataType>) -> &Self {
pub fn clear_buffer_partially(
&self,
scissor_box: ScissorBox,
clear_state: ClearState<impl PrimitiveDataType>,
) -> &Self {
self.context.set_scissor(scissor_box);
self.bind(crate::context::DRAW_FRAMEBUFFER);
clear_state.apply_buffer(&self.context);
Expand Down Expand Up @@ -208,8 +212,12 @@ impl<'a> RenderTarget<'a> {

///
/// Common function used to implement read_color, read_buffer, and _partially variants
///
fn read_formatted_buffer_partially<T: BufferDataType>(&self, format: u32, scissor_box: ScissorBox) -> Vec<T> {
///
fn read_formatted_buffer_partially<T: BufferDataType>(
&self,
format: u32,
scissor_box: ScissorBox,
) -> Vec<T> {
if self.id.is_some() && self.color.is_none() {
panic!("Cannot read color from a render target without a color target");
}
Expand Down
8 changes: 5 additions & 3 deletions src/core/render_target/clear_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ impl<T: PrimitiveDataType> ClearState<T> {
}
}

pub(in crate::core) fn apply_buffer(&self, context: &Context)
{
pub(in crate::core) fn apply_buffer(&self, context: &Context) {
context.set_write_mask(WriteMask {
red: self.red.is_some(),
green: self.green.is_some(),
Expand All @@ -124,7 +123,10 @@ impl<T: PrimitiveDataType> ClearState<T> {
|| self.blue.is_some()
|| self.alpha.is_some();
if clear_color {
T::clear_buffer_with_type(context, crate::context::COLOR, 0,
T::clear_buffer_with_type(
context,
crate::context::COLOR,
0,
&[
self.red.unwrap_or_else(T::zero),
self.green.unwrap_or_else(T::zero),
Expand Down
6 changes: 5 additions & 1 deletion src/core/render_target/color_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ impl<'a> ColorTarget<'a> {
///
/// Clears the color of the part of this color target that is inside the given scissor box, in the given data type.
///
pub fn clear_buffer_partially(&self, scissor_box: ScissorBox, clear_state: ClearState<impl PrimitiveDataType>) -> &Self {
pub fn clear_buffer_partially(
&self,
scissor_box: ScissorBox,
clear_state: ClearState<impl PrimitiveDataType>,
) -> &Self {
self.as_render_target()
.clear_buffer_partially(scissor_box, clear_state);
self
Expand Down
6 changes: 5 additions & 1 deletion src/core/render_target/color_target_multisample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ impl<C: TextureDataType> ColorTargetMultisample<C> {
///
/// Clears the color of the part of this target that is inside the given scissor box, in the given data type.
///
pub fn clear_buffer_partially(&self, scissor_box: ScissorBox, clear_state: ClearState<impl PrimitiveDataType>) -> &Self {
pub fn clear_buffer_partially(
&self,
scissor_box: ScissorBox,
clear_state: ClearState<impl PrimitiveDataType>,
) -> &Self {
self.as_render_target()
.clear_buffer_partially(scissor_box, clear_state);
self
Expand Down
6 changes: 5 additions & 1 deletion src/core/render_target/depth_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ impl<'a> DepthTarget<'a> {
///
/// Clears the depth of the part of this depth target that is inside the given scissor box.
///
pub fn clear_partially(&self, scissor_box: ScissorBox, clear_state: ClearState<impl PrimitiveDataType>) -> &Self {
pub fn clear_partially(
&self,
scissor_box: ScissorBox,
clear_state: ClearState<impl PrimitiveDataType>,
) -> &Self {
self.as_render_target().clear_partially(
scissor_box,
ClearState {
Expand Down
6 changes: 5 additions & 1 deletion src/core/render_target/depth_target_multisample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ impl<D: DepthTextureDataType> DepthTargetMultisample<D> {
///
/// Clears the color and depth of the part of this target that is inside the given scissor box.
///
pub fn clear_partially(&self, scissor_box: ScissorBox, clear_state: ClearState<impl PrimitiveDataType>) -> &Self {
pub fn clear_partially(
&self,
scissor_box: ScissorBox,
clear_state: ClearState<impl PrimitiveDataType>,
) -> &Self {
self.as_render_target().clear_partially(
scissor_box,
ClearState {
Expand Down
6 changes: 5 additions & 1 deletion src/core/render_target/multisample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ impl<C: TextureDataType, D: DepthTextureDataType> RenderTargetMultisample<C, D>
///
/// Clears the color and depth of the part of this target that is inside the given scissor box, in the given data type.
///
pub fn clear_buffer_partially(&self, scissor_box: ScissorBox, clear_state: ClearState<impl PrimitiveDataType>) -> &Self {
pub fn clear_buffer_partially(
&self,
scissor_box: ScissorBox,
clear_state: ClearState<impl PrimitiveDataType>,
) -> &Self {
self.as_render_target()
.clear_buffer_partially(scissor_box, clear_state);
self
Expand Down
22 changes: 19 additions & 3 deletions src/core/texture/texture_cube_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,15 @@ impl TextureCubeMap {
front_data: &[T],
back_data: &[T],
) {
self.fill_format(right_data, left_data, top_data, bottom_data, front_data, back_data, normalized_format_from_data_type::<T>());
self.fill_format(
right_data,
left_data,
top_data,
bottom_data,
front_data,
back_data,
normalized_format_from_data_type::<T>(),
);
}

///
Expand All @@ -388,9 +396,17 @@ impl TextureCubeMap {
front_data: &[T],
back_data: &[T],
) {
self.fill_format(right_data, left_data, top_data, bottom_data, front_data, back_data, format_from_data_type::<T>());
self.fill_format(
right_data,
left_data,
top_data,
bottom_data,
front_data,
back_data,
format_from_data_type::<T>(),
);
}

fn fill_format<T: BufferDataType>(
&mut self,
right_data: &[T],
Expand Down

0 comments on commit c9d0a98

Please sign in to comment.