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.rs76
1 files changed, 55 insertions, 21 deletions
diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs
index 629c0ba..f40cb20 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,
+ TexturePixelDataFormat,
TextureUpdate,
POST_RENDER_PHASE,
RENDER_PHASE,
@@ -795,14 +796,19 @@ fn handle_commands(
tracing::error!("Failed to create texture object: {err}");
}
}
- Command::UpdateTexture { obj_id, image, update, offset } => {
+ Command::UpdateTexture {
+ obj_id,
+ pixels,
+ pixel_data_format,
+ update,
+ } => {
if let Err(err) = update_texture_object(
gl_context,
object_store,
obj_id,
- image,
+ pixels,
+ pixel_data_format,
update,
- offset,
) {
tracing::error!("Failed to update texture object: {err}");
}
@@ -1362,9 +1368,9 @@ fn update_texture_object(
curr_gl_ctx: &MaybeCurrentContextWithFns,
object_store: &mut ObjectStore,
texture_object_id: ObjectId,
- texture_image: Image,
+ pixels: Box<[u8]>,
+ pixel_data_format: TexturePixelDataFormat,
update: TextureUpdate,
- offset: Vec2<u32>,
) -> Result<(), GlTextureError>
{
let Some(texture_obj) = object_store.get_obj(&texture_object_id) else {
@@ -1386,22 +1392,17 @@ fn update_texture_object(
let gl_texture = GlTexture::from_raw(texture_obj.as_raw());
match update {
- TextureUpdate::Texture2D => {
+ TextureUpdate::Texture2D { size, offset } => {
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(),
+ size.into(),
+ tex_pixel_data_format_into_gl(pixel_data_format),
+ &pixels,
)?;
}
- TextureUpdate::CubeMap { face } => {
- let image_dimens = texture_image.dimensions();
-
+ TextureUpdate::CubeMap { size, offset, face } => {
gl_texture.store_image_3d(
curr_gl_ctx,
0,
@@ -1411,12 +1412,9 @@ fn update_texture_object(
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(),
+ [size.width, size.height, 1],
+ tex_pixel_data_format_into_gl(pixel_data_format),
+ &pixels,
)?;
}
}
@@ -1462,6 +1460,42 @@ struct ImageDataProperties
is_srgb: bool,
}
+fn tex_pixel_data_format_into_gl(
+ tex_pixel_data_format: TexturePixelDataFormat,
+) -> GlTexturePixelDataFormat
+{
+ match tex_pixel_data_format {
+ TexturePixelDataFormat::Rgb(data_type) => {
+ GlTexturePixelDataFormat::Rgb(match data_type {
+ crate::rendering::RgbTextureDataType::UnsignedByte => {
+ opengl_bindings::texture::RgbDataType::UnsignedByte
+ }
+ })
+ }
+ TexturePixelDataFormat::Srgb(data_type) => {
+ GlTexturePixelDataFormat::Srgb(match data_type {
+ crate::rendering::SrgbTextureDataType::UnsignedByte => {
+ opengl_bindings::texture::SrgbDataType::UnsignedByte
+ }
+ })
+ }
+ TexturePixelDataFormat::Rgba(data_type) => {
+ GlTexturePixelDataFormat::Rgba(match data_type {
+ crate::rendering::RgbaTextureDataType::UnsignedByte => {
+ opengl_bindings::texture::RgbaDataType::UnsignedByte
+ }
+ })
+ }
+ TexturePixelDataFormat::Srgba(data_type) => {
+ GlTexturePixelDataFormat::Srgba(match data_type {
+ crate::rendering::SrgbaTextureDataType::UnsignedByte => {
+ opengl_bindings::texture::SrgbaDataType::UnsignedByte
+ }
+ })
+ }
+ }
+}
+
fn create_pixel_data_format(
image_data_props: ImageDataProperties,
) -> GlTexturePixelDataFormat