diff options
author | Jeroen Bakker <jbakker> | 2022-01-28 10:37:12 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-01-28 10:37:45 +0300 |
commit | bdd74e1e9338b18e4f80458f284d0c6a4d100f30 (patch) | |
tree | 86daecf79b6a9d0896482d7fe8d85da9a6becc81 /source/blender/draw/engines/image/image_private.hh | |
parent | 0a32ac02e976a4723802ed09bed64c0625e889a2 (diff) |
DrawManager: Image engine support huge images.
Adding better support for drawing huge images in the image/uv editor. Also solved tearing artifacts.
The approach is that for each image/uv editor a screen space gpu texture is created that only contains
the visible pixels. When zooming or panning the gpu texture is rebuild.
Although the solution isn't memory intensive other parts of blender memory usage scales together with
the image size.
* Due to complexity we didn't implement partial updates when drawing images tiled (wrap repeat).
This could be added, but is complicated as a change in the source could mean many different
changes on the GPU texture. The work around for now is to tag all gpu textures to be dirty when
changes are detected.
Original plan was to have 4 screen space images to support panning without gpu texture creation.
For now we don't see the need to implement it as the solution is already fast. Especially when
GPU memory is shared with CPU ram.
Reviewed By: fclem
Maniphest Tasks: T92525, T92903
Differential Revision: https://developer.blender.org/D13424
Diffstat (limited to 'source/blender/draw/engines/image/image_private.hh')
-rw-r--r-- | source/blender/draw/engines/image/image_private.hh | 135 |
1 files changed, 9 insertions, 126 deletions
diff --git a/source/blender/draw/engines/image/image_private.hh b/source/blender/draw/engines/image/image_private.hh index fc3ce72d0aa..05ed2881145 100644 --- a/source/blender/draw/engines/image/image_private.hh +++ b/source/blender/draw/engines/image/image_private.hh @@ -24,6 +24,11 @@ #include <optional> +#include "BKE_image.h" + +#include "image_instance_data.hh" +#include "image_texture_info.hh" + /* Forward declarations */ extern "C" { struct GPUTexture; @@ -35,32 +40,13 @@ struct Image; namespace blender::draw::image_engine { -/* GPUViewport.storage - * Is freed every time the viewport engine changes. */ -struct IMAGE_PassList { - DRWPass *image_pass; -}; - -struct IMAGE_PrivateData { - void *lock; - struct ImBuf *ibuf; - struct Image *image; - struct DRWView *view; - - struct GPUTexture *texture; - bool owns_texture; -}; - -struct IMAGE_StorageList { - IMAGE_PrivateData *pd; -}; - struct IMAGE_Data { void *engine_type; DRWViewportEmptyList *fbl; DRWViewportEmptyList *txl; - IMAGE_PassList *psl; - IMAGE_StorageList *stl; + DRWViewportEmptyList *psl; + DRWViewportEmptyList *stl; + IMAGE_InstanceData *instance_data; }; /* Shader parameters. */ @@ -69,105 +55,6 @@ struct IMAGE_Data { #define IMAGE_DRAW_FLAG_SHUFFLING (1 << 2) #define IMAGE_DRAW_FLAG_DEPTH (1 << 3) #define IMAGE_DRAW_FLAG_DO_REPEAT (1 << 4) -#define IMAGE_DRAW_FLAG_USE_WORLD_POS (1 << 5) - -struct ShaderParameters { - constexpr static float color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - - int flags = 0; - float shuffle[4]; - float far_near[2]; - bool use_premul_alpha = false; - - ShaderParameters() - { - copy_v4_fl(shuffle, 1.0f); - copy_v2_fl2(far_near, 100.0f, 0.0f); - } -}; - -/** - * Space accessor. - * - * Image engine is used to draw the images inside multiple spaces \see SpaceLink. - * The AbstractSpaceAccessor is an interface to communicate with a space. - */ -class AbstractSpaceAccessor { - public: - virtual ~AbstractSpaceAccessor() = default; - - /** - * Return the active image of the space. - * - * The returned image will be drawn in the space. - * - * The return value is optional. - */ - virtual Image *get_image(Main *bmain) = 0; - - /** - * Return the #ImageUser of the space. - * - * The return value is optional. - */ - virtual ImageUser *get_image_user() = 0; - - /** - * Acquire the image buffer of the image. - * - * \param image: Image to get the buffer from. Image is the same as returned from the #get_image - * member. - * \param lock: pointer to a lock object. - * \return Image buffer of the given image. - */ - virtual ImBuf *acquire_image_buffer(Image *image, void **lock) = 0; - - /** - * Release a previous locked image from #acquire_image_buffer. - */ - virtual void release_buffer(Image *image, ImBuf *image_buffer, void *lock) = 0; - - /** - * Update the r_shader_parameters with space specific settings. - * - * Only update the #ShaderParameters.flags and #ShaderParameters.shuffle. Other parameters - * are updated inside the image engine. - */ - virtual void get_shader_parameters(ShaderParameters &r_shader_parameters, - ImBuf *image_buffer, - bool is_tiled) = 0; - - /** - * Retrieve the gpu textures to draw. - */ - virtual void get_gpu_textures(Image *image, - ImageUser *iuser, - ImBuf *image_buffer, - GPUTexture **r_gpu_texture, - bool *r_owns_texture, - GPUTexture **r_tex_tile_data) = 0; - - /** - * Does this space override the view. - * When so this member should return true and the create_view_override must return the view to - * use during drawing. - */ - virtual bool has_view_override() const = 0; - - /** - * Override the view for drawing. - * Should match #has_view_override. - */ - virtual DRWView *create_view_override(const ARegion *UNUSED(region)) = 0; - - /** - * Initialize the matrix that will be used to draw the image. The matrix will be send as object - * matrix to the drawing pipeline. - */ - virtual void get_image_mat(const ImBuf *image_buffer, - const ARegion *region, - float r_mat[4][4]) const = 0; -}; // namespace blender::draw::image_engine /** * Abstract class for a drawing mode of the image engine. @@ -179,11 +66,7 @@ class AbstractDrawingMode { public: virtual ~AbstractDrawingMode() = default; virtual void cache_init(IMAGE_Data *vedata) const = 0; - virtual void cache_image(AbstractSpaceAccessor *space, - IMAGE_Data *vedata, - Image *image, - ImageUser *iuser, - ImBuf *image_buffer) const = 0; + virtual void cache_image(IMAGE_Data *vedata, Image *image, ImageUser *iuser) const = 0; virtual void draw_scene(IMAGE_Data *vedata) const = 0; virtual void draw_finish(IMAGE_Data *vedata) const = 0; }; |