-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write release note for PR 10392 (CPU Drawing) #1854
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2f8be20
Write release note for PR 10392 (CPU Drawing)
inodentry 43222d9
Update release-content/0.15/release-notes/10392_CPU_Drawing.md
inodentry 38607dd
Update release-content/0.15/release-notes/10392_CPU_Drawing.md
inodentry ffcc82c
Update release-content/0.15/release-notes/10392_CPU_Drawing.md
inodentry 84118e7
Update release-content/0.15/release-notes/10392_CPU_Drawing.md
inodentry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
There are many situations where you might want to just set the color of pixels | ||
from CPU code. Procedural assets, certain art styles, or simply because | ||
it is easier. No need to bother with shaders and materials, when you just want | ||
to change a few specific pixels! | ||
|
||
In previous versions of Bevy, this was difficult and tedious. Bevy gives you | ||
access to the raw data bytes of an [`Image`], but you had to compute the byte | ||
offset corresponding to your desired pixel coordinate, make sure to encode your | ||
bytes with respect to the [`TextureFormat`], etc. Very low level! | ||
|
||
In Bevy 0.15, there are now user-friendly APIs for reading and writing the | ||
colors of pixels in an [`Image`]. The tricky low-level details are dealt with | ||
for you! You can even use `bevy_color`'s fancy color space APIs! | ||
|
||
```rust | ||
fn my_system(mut images: ResMut<Assets<Image>>, mut commands: Commands) { | ||
// Create a new image. | ||
let mut image = Image::new_fill( | ||
// 64x64 size | ||
Extent3d { | ||
width: 64, | ||
height: 64, | ||
depth_or_array_layers: 1, | ||
}, | ||
TextureDimension::D2, | ||
&Srgba::WHITE.to_u8_array(), | ||
TextureFormat::Rgba8UnormSrgb, | ||
RenderAssetUsages::all(), | ||
); | ||
|
||
// This is new: | ||
|
||
// Make the pixel at x: 23, y: 32 magenta | ||
image.set_color_at(23, 32, Color::srgb(1.0, 0.0, 1.0)) | ||
.expect("Error writing color"); | ||
|
||
// Set the pixel at 10,10 to a color specified using the Oklch color space: | ||
image.set_color_at(10, 10, Color::oklch(0.3, 0.2, 0.5)) | ||
.expect("Error writing color"); | ||
|
||
// read the bytes of the pixel we just wrote: | ||
let bytes = image.pixel_bytes(UVec3::new(10, 10, 0)).unwrap(); | ||
|
||
// read the (approximate) color back (as sRGB): | ||
let color = image.get_color_at(10, 10); | ||
|
||
// We could add our new image to Bevy's assets | ||
// and spawn a sprite to display it: | ||
commands.spawn(Sprite { | ||
image: images.add(image), | ||
..default() | ||
}); | ||
} | ||
``` | ||
|
||
Note: The [`Color`]-based methods are lossy. They have to convert to/from the | ||
[`Image`]'s [`TextureFormat`]. If you read back the color you wrote, it will be slightly different. | ||
|
||
[`Image`]: https://docs.rs/bevy/0.15.0-rc.3/bevy/prelude/struct.Image.html | ||
[`TextureFormat`]: https://docs.rs/bevy/0.15.0-rc.3/bevy/render/render_resource/enum.TextureFormat.html | ||
[`Color`]: https://docs.rs/bevy/0.15.0-rc.3/bevy/color/enum.Color.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably move this down (it's not the most important change), but we need to do a reordering pass anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's up to you.
I just put it at the end of the graphics/rendering related stuff. The order: "Required components (most important change) -> a bunch of graphics/visual related stuff -> this PR (vaguely related to drawing/visuals) -> other stuff" made sense to me. :)
But feel free to reorder it wherever you like.