summaryrefslogtreecommitdiff
path: root/engine/src/rendering/backend/opengl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/rendering/backend/opengl.rs')
-rw-r--r--engine/src/rendering/backend/opengl.rs61
1 files changed, 46 insertions, 15 deletions
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);