Skip to content

Commit

Permalink
improve attachment_renderer_object docs and usage (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
jabuwu authored Sep 13, 2023
1 parent 1ca1f0c commit 495a2f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
4 changes: 3 additions & 1 deletion examples/miniquad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! # Texture Creation & Disposal
//!
//! Callbacks must be set to handle texture loading upon loading a [`rusty_spine::Atlas`].
//! Callbacks must first be set to handle texture loading upon loading a [`rusty_spine::Atlas`].
//! See [`SpineTexture`].
//!
//! # Texture Runtime Settings
Expand Down Expand Up @@ -616,6 +616,7 @@ impl EventHandler for Stage {
bindings.index_buffer.update(ctx, &renderable.indices);

// If there is no attachment (and therefore no texture), skip rendering this renderable
// May also be None if a create texture callback was never set.
let Some(attachment_renderer_object) = renderable.attachment_renderer_object else {
continue;
};
Expand Down Expand Up @@ -707,6 +708,7 @@ impl EventHandler for Stage {
}

fn main() {
// These texture callbacks should be set before loading an atlas.
rusty_spine::extension::set_create_texture_cb(|atlas_page, path| {
fn convert_filter(filter: AtlasFilter) -> FilterMode {
match filter {
Expand Down
20 changes: 14 additions & 6 deletions src/draw/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl CombinedDrawer {
unreachable!();
},
|region_attachment| {
let next_attachment_renderer_object = Some(unsafe {
let next_attachment_renderer_object = unsafe {
region_attachment
.renderer_object()
.get_atlas_region()
Expand All @@ -127,13 +127,17 @@ impl CombinedDrawer {
.c_ptr_ref()
.rendererObject
.cast_const()
});
next_attachment_renderer_object
};
if next_attachment_renderer_object.is_null() {
None
} else {
Some(next_attachment_renderer_object)
}
},
)
},
|mesh_attachment| {
let next_attachment_renderer_object = Some(unsafe {
let next_attachment_renderer_object = unsafe {
mesh_attachment
.renderer_object()
.get_atlas_region()
Expand All @@ -142,8 +146,12 @@ impl CombinedDrawer {
.c_ptr_ref()
.rendererObject
.cast_const()
});
next_attachment_renderer_object
};
if next_attachment_renderer_object.is_null() {
None
} else {
Some(next_attachment_renderer_object)
}
},
);

Expand Down
36 changes: 22 additions & 14 deletions src/draw/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,30 +248,38 @@ impl SimpleDrawer {
let attachment_renderer_object =
slot.attachment().and_then(|a| a.as_mesh()).map_or_else(
|| {
slot.attachment().and_then(|a| a.as_region()).map(
slot.attachment().and_then(|a| a.as_region()).and_then(
|region_attachment| unsafe {
region_attachment
let attachment_renderer_object = region_attachment
.renderer_object()
.get_atlas_region()
.unwrap()
.page()
.c_ptr_ref()
.rendererObject
.cast_const()
.cast_const();
if attachment_renderer_object.is_null() {
None
} else {
Some(attachment_renderer_object)
}
},
)
},
|mesh_attachment| {
Some(unsafe {
mesh_attachment
.renderer_object()
.get_atlas_region()
.unwrap()
.page()
.c_ptr_ref()
.rendererObject
.cast_const()
})
|mesh_attachment| unsafe {
let attachment_renderer_object = mesh_attachment
.renderer_object()
.get_atlas_region()
.unwrap()
.page()
.c_ptr_ref()
.rendererObject
.cast_const();
if attachment_renderer_object.is_null() {
None
} else {
Some(attachment_renderer_object)
}
},
);

Expand Down

0 comments on commit 495a2f0

Please sign in to comment.