[Bf-blender-cvs] [a3a646feb97] temp-gpu-image-engine: Separate space node backdrop from region.
Jeroen Bakker
noreply at git.blender.org
Tue Dec 14 15:03:59 CET 2021
Commit: a3a646feb97287b46919abe98b030dbfdbb7e13a
Author: Jeroen Bakker
Date: Tue Dec 14 15:03:22 2021 +0100
Branches: temp-gpu-image-engine
https://developer.blender.org/rBa3a646feb97287b46919abe98b030dbfdbb7e13a
Separate space node backdrop from region.
===================================================================
M source/blender/draw/engines/image/image_drawing_mode.hh
M source/blender/draw/engines/image/image_engine.cc
M source/blender/draw/engines/image/image_instance_data.hh
M source/blender/draw/engines/image/image_space.hh
M source/blender/draw/engines/image/image_space_image.hh
M source/blender/draw/engines/image/image_space_node.hh
M source/blender/imbuf/intern/transform.cc
===================================================================
diff --git a/source/blender/draw/engines/image/image_drawing_mode.hh b/source/blender/draw/engines/image/image_drawing_mode.hh
index 11802a4d8d5..d2233e78fbb 100644
--- a/source/blender/draw/engines/image/image_drawing_mode.hh
+++ b/source/blender/draw/engines/image/image_drawing_mode.hh
@@ -44,21 +44,6 @@ struct OneTextureMethod {
{
}
- void update_uv_to_texture_matrix(const ARegion *region)
- {
- // TODO: I remember that there was a function for this somewhere.
- unit_m4(instance_data->uv_to_texture);
- float scale_x = 1.0 / BLI_rctf_size_x(®ion->v2d.cur);
- float scale_y = 1.0 / BLI_rctf_size_y(®ion->v2d.cur);
- float translate_x = scale_x * -region->v2d.cur.xmin;
- float translate_y = scale_y * -region->v2d.cur.ymin;
-
- instance_data->uv_to_texture[0][0] = scale_x;
- instance_data->uv_to_texture[1][1] = scale_y;
- instance_data->uv_to_texture[3][0] = translate_x;
- instance_data->uv_to_texture[3][1] = translate_y;
- }
-
/** \brief Update the texture slot uv and screen space bounds. */
void update_screen_space_bounds(const ARegion *region)
{
@@ -352,7 +337,7 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
* Construct a variant of the info_uv_to_texture that adds the texel space
* transformation.*/
float uv_to_texel[4][4];
- copy_m4_m4(uv_to_texel, instance_data.uv_to_texture);
+ copy_m4_m4(uv_to_texel, instance_data.ss_to_texture);
float scale[3] = {static_cast<float>(texture_width) / static_cast<float>(tile_buffer.x),
static_cast<float>(texture_height) / static_cast<float>(tile_buffer.y),
1.0f};
@@ -403,7 +388,6 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
// Step: Find out which screen space textures are needed to draw on the screen. Remove the
// screen space textures that aren't needed.
const ARegion *region = draw_ctx->region;
- method.update_uv_to_texture_matrix(region);
method.update_screen_space_bounds(region);
method.update_uv_bounds(region);
diff --git a/source/blender/draw/engines/image/image_engine.cc b/source/blender/draw/engines/image/image_engine.cc
index 949044f83c2..e3565de7445 100644
--- a/source/blender/draw/engines/image/image_engine.cc
+++ b/source/blender/draw/engines/image/image_engine.cc
@@ -88,21 +88,13 @@ class ImageEngine {
{
IMAGE_InstanceData *instance_data = vedata->instance_data;
drawing_mode.cache_init(vedata);
- const ARegion *region = draw_ctx->region;
/* Setup full screen view matrix. */
+ const ARegion *region = draw_ctx->region;
float winmat[4][4], viewmat[4][4];
orthographic_m4(viewmat, 0.0, region->winx, 0.0, region->winy, 0.0, 1.0);
unit_m4(winmat);
instance_data->view = DRW_view_create(viewmat, winmat, nullptr, nullptr, nullptr);
-
- /*
- * TODO: space can override the uv bounds of the visible region.
- * for image space it would use the region->v2d.cur.
- * for node space it would use the zoom and scaling of the backdrop.
- *
- * This should be stored in the root of the instance data.
- */
}
void cache_populate()
@@ -118,6 +110,13 @@ class ImageEngine {
space->use_tile_drawing();
void *lock;
ImBuf *image_buffer = space->acquire_image_buffer(instance_data->image, &lock);
+
+ /* Setup the matrix to go from screen UV coordinates to UV texture space coordinates. */
+ float image_resolution[2] = {image_buffer ? image_buffer->x : 1024.0f,
+ image_buffer ? image_buffer->y : 1024.0f};
+ space->init_ss_to_texture_matrix(
+ draw_ctx->region, image_resolution, instance_data->ss_to_texture);
+
const Scene *scene = DRW_context_state_get()->scene;
instance_data->sh_params.update(space.get(), scene, instance_data->image, image_buffer);
space->release_buffer(instance_data->image, image_buffer, lock);
@@ -138,7 +137,7 @@ class ImageEngine {
{
drawing_mode.draw_scene(vedata);
}
-};
+}; // namespace blender::draw::image_engine
/* -------------------------------------------------------------------- */
/** \name Engine Callbacks
diff --git a/source/blender/draw/engines/image/image_instance_data.hh b/source/blender/draw/engines/image/image_instance_data.hh
index b48ac2b9fe8..79153b5f7f4 100644
--- a/source/blender/draw/engines/image/image_instance_data.hh
+++ b/source/blender/draw/engines/image/image_instance_data.hh
@@ -59,8 +59,8 @@ struct IMAGE_InstanceData {
DRWPass *image_pass;
} passes;
- /** \brief Transform matrix to convert a normalized uv coordinate to texture space. */
- float uv_to_texture[4][4];
+ /** \brief Transform matrix to convert a normalized screen space coordinates to texture space. */
+ float ss_to_texture[4][4];
TextureInfo texture_infos[SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN];
/**
diff --git a/source/blender/draw/engines/image/image_space.hh b/source/blender/draw/engines/image/image_space.hh
index 84841a76a7a..762f43a7337 100644
--- a/source/blender/draw/engines/image/image_space.hh
+++ b/source/blender/draw/engines/image/image_space.hh
@@ -85,15 +85,15 @@ class AbstractSpaceAccessor {
bool *r_owns_texture,
GPUTexture **r_tex_tile_data) = 0;
+ /** \brief Is (wrap) repeat option enabled in the space. */
+ virtual bool use_tile_drawing() const = 0;
/**
- * Initialize the matrix that will be used to draw the image. The matrix will be send as object
- * matrix to the drawing pipeline.
+ * \brief Initialize r_uv_to_texture matrix to transform from normalized screen space coordinates
+ * (0..1) to texture space UV coordinates.
*/
- virtual void get_image_mat(const ImBuf *image_buffer,
- const ARegion *region,
- float r_mat[4][4]) const = 0;
+ virtual void init_ss_to_texture_matrix(const ARegion *region,
+ const float image_resolution[2],
+ float r_uv_to_texture[4][4]) const = 0;
- /** \brief Is (wrap) repeat option enabled in the space. */
- virtual bool use_tile_drawing() const = 0;
}; // namespace blender::draw::image_engine
diff --git a/source/blender/draw/engines/image/image_space_image.hh b/source/blender/draw/engines/image/image_space_image.hh
index 6b7a31cb81b..120ce8b2673 100644
--- a/source/blender/draw/engines/image/image_space_image.hh
+++ b/source/blender/draw/engines/image/image_space_image.hh
@@ -160,17 +160,28 @@ class SpaceImageAccessor : public AbstractSpaceAccessor {
*r_owns_texture = false;
}
}
- void get_image_mat(const ImBuf *UNUSED(image_buffer),
- const ARegion *UNUSED(region),
- float r_mat[4][4]) const override
- {
- unit_m4(r_mat);
- }
bool use_tile_drawing() const
{
return (sima->flag & SI_DRAW_TILE) != 0;
}
+
+ void init_ss_to_texture_matrix(const ARegion *region,
+ const float UNUSED(image_resolution[2]),
+ float r_uv_to_texture[4][4]) const override
+ {
+ // TODO: I remember that there was a function for this somewhere.
+ unit_m4(r_uv_to_texture);
+ float scale_x = 1.0 / BLI_rctf_size_x(®ion->v2d.cur);
+ float scale_y = 1.0 / BLI_rctf_size_y(®ion->v2d.cur);
+ float translate_x = scale_x * -region->v2d.cur.xmin;
+ float translate_y = scale_y * -region->v2d.cur.ymin;
+
+ r_uv_to_texture[0][0] = scale_x;
+ r_uv_to_texture[1][1] = scale_y;
+ r_uv_to_texture[3][0] = translate_x;
+ r_uv_to_texture[3][1] = translate_y;
+ }
};
} // namespace blender::draw::image_engine
diff --git a/source/blender/draw/engines/image/image_space_node.hh b/source/blender/draw/engines/image/image_space_node.hh
index bd48f912752..d9335e3dd13 100644
--- a/source/blender/draw/engines/image/image_space_node.hh
+++ b/source/blender/draw/engines/image/image_space_node.hh
@@ -54,7 +54,6 @@ class SpaceNodeAccessor : public AbstractSpaceAccessor {
BKE_image_release_ibuf(image, ibuf, lock);
}
-
void get_shader_parameters(ShaderParameters &r_shader_parameters,
ImBuf *ibuf,
bool UNUSED(is_tiled)) override
@@ -107,23 +106,31 @@ class SpaceNodeAccessor : public AbstractSpaceAccessor {
*r_tex_tile_data = nullptr;
}
- void get_image_mat(const ImBuf *image_buffer,
- const ARegion *region,
- float r_mat[4][4]) const override
+ bool use_tile_drawing() const override
{
- unit_m4(r_mat);
- const float ibuf_width = image_buffer->x;
- const float ibuf_height = image_buffer->y;
-
- r_mat[0][0] = ibuf_width * snode->zoom;
- r_mat[1][1] = ibuf_height * snode->zoom;
- r_mat[3][0] = (region->winx - snode->zoom * ibuf_width) / 2 + snode->xof;
- r_mat[3][1] = (region->winy - snode->zoom * ibuf_height) / 2 + snode->yof;
+ return false;
}
- bool use_tile_drawing() const
+ /**
+ * The backdrop of the node editor isn't drawn in screen space UV space. But is locked with the
+ * screen.
+ */
+ void init_ss_to_texture_matrix(const ARegion *region,
+ const float image_resolution[2],
+ float r_uv_to_texture[4][4]) const override
{
- return false;
+ unit_m4(r_uv_to_texture);
+ float display_resolution[2];
+ mul_v2_v2fl(display_resolution, image_resolution, snode->zoom);
+ const float scale_x = display_resolution[0] / region->winx;
+ const float scale_y = display_resolution[1] / region->winy;
+ const float translate_x = 0.5f - 0.5f * scale_x + snode->xof / image_resolution[0];
+ const float translate_y = 0.5 - 0.5f * scale_y + snode->yof / image_resolution[1];
+
+ r_uv_to_texture[0][0] = scale_x;
+ r_uv_to_texture[1][1] = scale_y;
+ r_uv_to_texture[3][0] = translate_x;
+ r_uv_to_texture[3][1] = translate_y;
}
};
diff --git a/source/blender/imbuf/intern/transform.cc b/source/blender/imbuf/intern/transform
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list