summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-26 17:39:17 +0200
committerHampusM <hampus@hampusmat.com>2026-08-26 17:39:17 +0200
commit7abe3894137f55aaa7aa0e0c491795342b6124bc (patch)
tree578cd3bce6cdeeacf0ae82f6c6d727612a1b17d0
parent07171b85b9365bb52b84fd865066d01d885fcbb3 (diff)
feat(engine): add cube map support to UpdateTexture rendering commmand
-rw-r--r--engine/src/rendering.rs18
-rw-r--r--engine/src/rendering/backend/opengl.rs61
-rw-r--r--engine/src/ui/dear_imgui.rs2
3 files changed, 64 insertions, 17 deletions
diff --git a/engine/src/rendering.rs b/engine/src/rendering.rs
index 2a73625..572f045 100644
--- a/engine/src/rendering.rs
+++ b/engine/src/rendering.rs
@@ -25,7 +25,7 @@ use crate::rendering::blending::Config as BlendingConfig;
use crate::rendering::object::{Id as ObjectId, Store as ObjectStore};
use crate::rendering::shader::cursor::Binding as ShaderBinding;
use crate::rendering::shader::Program as ShaderProgram;
-use crate::texture::Texture;
+use crate::texture::{CubeMapFace, Texture};
use crate::vector::Vec2;
use crate::windowing::dpi::PhysicalSize;
use crate::windowing::window::Window;
@@ -216,11 +216,14 @@ pub enum Command
ActivateShader(ObjectId),
SetShaderBinding(ShaderBinding),
CreateTexture(ObjectId, AssetOrValue<Texture>),
- // TODO: Make UpdateTexture command able to handle textures other than 2D textures
UpdateTexture
{
obj_id: ObjectId,
image: Image,
+ update: TextureUpdate,
+
+ /// Specifies texel index offsets in the x and y directions within the texture
+ /// pixels.
offset: Vec2<u32>,
},
RemoveTexture(ObjectId),
@@ -399,6 +402,17 @@ bitflags! {
}
}
+#[derive(Debug, Clone)]
+#[non_exhaustive]
+pub enum TextureUpdate
+{
+ Texture2D,
+ CubeMap
+ {
+ face: CubeMapFace,
+ },
+}
+
/// Rendering command FIFO queue.
#[derive(Debug, Sole)]
pub struct CommandQueue
diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs
index 8d7710a..629c0ba 100644
--- a/engine/src/rendering/backend/opengl.rs
+++ b/engine/src/rendering/backend/opengl.rs
@@ -116,6 +116,7 @@ use crate::rendering::{
Surface,
SurfaceId,
TargetWindow,
+ TextureUpdate,
POST_RENDER_PHASE,
RENDER_PHASE,
};
@@ -794,10 +795,15 @@ fn handle_commands(
tracing::error!("Failed to create texture object: {err}");
}
}
- Command::UpdateTexture { obj_id, image, offset } => {
- if let Err(err) =
- update_texture_object(gl_context, object_store, obj_id, image, offset)
- {
+ Command::UpdateTexture { obj_id, image, update, offset } => {
+ if let Err(err) = update_texture_object(
+ gl_context,
+ object_store,
+ obj_id,
+ image,
+ update,
+ offset,
+ ) {
tracing::error!("Failed to update texture object: {err}");
}
}
@@ -1357,6 +1363,7 @@ fn update_texture_object(
object_store: &mut ObjectStore,
texture_object_id: ObjectId,
texture_image: Image,
+ update: TextureUpdate,
offset: Vec2<u32>,
) -> Result<(), GlTextureError>
{
@@ -1378,17 +1385,41 @@ fn update_texture_object(
let gl_texture = GlTexture::from_raw(texture_obj.as_raw());
- gl_texture.store_image_2d(
- curr_gl_ctx,
- 0,
- offset.into(),
- texture_image.dimensions().into(),
- create_pixel_data_format(ImageDataProperties {
- color_type: texture_image.color_type(),
- is_srgb: texture_image.color_space_is_srgb(),
- }),
- texture_image.as_bytes(),
- )?;
+ match update {
+ TextureUpdate::Texture2D => {
+ gl_texture.store_image_2d(
+ curr_gl_ctx,
+ 0,
+ offset.into(),
+ texture_image.dimensions().into(),
+ create_pixel_data_format(ImageDataProperties {
+ color_type: texture_image.color_type(),
+ is_srgb: texture_image.color_space_is_srgb(),
+ }),
+ texture_image.as_bytes(),
+ )?;
+ }
+ TextureUpdate::CubeMap { face } => {
+ let image_dimens = texture_image.dimensions();
+
+ gl_texture.store_image_3d(
+ curr_gl_ctx,
+ 0,
+ Vec3 {
+ x: offset.x,
+ y: offset.y,
+ z: cube_map_texture_face_to_gl(face) as u32,
+ }
+ .into(),
+ [image_dimens.width, image_dimens.height, 1],
+ create_pixel_data_format(ImageDataProperties {
+ color_type: texture_image.color_type(),
+ is_srgb: texture_image.color_space_is_srgb(),
+ }),
+ texture_image.as_bytes(),
+ )?;
+ }
+ }
gl_texture.generate_mipmap(curr_gl_ctx);
diff --git a/engine/src/ui/dear_imgui.rs b/engine/src/ui/dear_imgui.rs
index e9fc5ff..fbe4ed8 100644
--- a/engine/src/ui/dear_imgui.rs
+++ b/engine/src/ui/dear_imgui.rs
@@ -72,6 +72,7 @@ use crate::rendering::{
ScissorBox,
Surface,
SurfaceId,
+ TextureUpdate,
PRE_RENDER_PHASE,
};
use crate::texture::{Properties as TextureProperties, Tex2D, Texture};
@@ -626,6 +627,7 @@ fn add_drawing_render_pass(
render_pass.commands.push(RenderingCommand::UpdateTexture {
obj_id: *texture_object_id,
image: rect_image,
+ update: TextureUpdate::Texture2D,
offset: Vec2 {
x: rect.rect.x as u32,
y: rect.rect.y as u32,