Image Engine: Store image usage to identity changes.
Previous implementation had a copy of the image user, which doesn't contain all the data to identify changes. This patch introduces a new struct to store the data and can be extended with other data as well (color spaces, alpha settings).
This commit is contained in:
parent
1d0d810331
commit
6efdfeb886
|
@ -475,7 +475,7 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
|
|||
method.update_screen_uv_bounds();
|
||||
|
||||
/* Check for changes in the image user compared to the last time. */
|
||||
instance_data->update_image_user(iuser);
|
||||
instance_data->update_image_usage(iuser);
|
||||
|
||||
/* Step: Update the GPU textures based on the changes in the image. */
|
||||
instance_data->update_gpu_texture_allocations();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "image_private.hh"
|
||||
#include "image_shader_params.hh"
|
||||
#include "image_texture_info.hh"
|
||||
#include "image_usage.hh"
|
||||
#include "image_wrappers.hh"
|
||||
|
||||
#include "DRW_render.h"
|
||||
|
@ -40,8 +41,8 @@ constexpr int SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN = 1;
|
|||
|
||||
struct IMAGE_InstanceData {
|
||||
struct Image *image;
|
||||
/** Copy of the last image user to detect iuser differences that require a full update. */
|
||||
struct ImageUser last_image_user;
|
||||
/** Usage data of the previous time, to identify changes that require a full update. */
|
||||
ImageUsage last_usage;
|
||||
|
||||
PartialImageUpdater partial_update;
|
||||
|
||||
|
@ -110,23 +111,11 @@ struct IMAGE_InstanceData {
|
|||
}
|
||||
}
|
||||
|
||||
void update_image_user(const ImageUser *image_user)
|
||||
void update_image_usage(const ImageUser *image_user)
|
||||
{
|
||||
short requested_pass = image_user ? image_user->pass : 0;
|
||||
short requested_layer = image_user ? image_user->layer : 0;
|
||||
short requested_view = image_user ? image_user->multi_index : 0;
|
||||
/* There is room for 2 multiview textures. When a higher number is requested we should always
|
||||
* target the first view slot. This is fine as multi view images aren't used together. */
|
||||
if (requested_view > 1) {
|
||||
requested_view = 0;
|
||||
}
|
||||
|
||||
if (last_image_user.pass != requested_pass || last_image_user.layer != requested_layer ||
|
||||
last_image_user.multi_index != requested_view) {
|
||||
|
||||
last_image_user.pass = requested_pass;
|
||||
last_image_user.layer = requested_layer;
|
||||
last_image_user.multi_index = requested_view;
|
||||
ImageUsage usage(image_user);
|
||||
if (last_usage != usage) {
|
||||
last_usage = usage;
|
||||
reset_dirty_flag(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Copyright 2022, Blender Foundation.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \ingroup draw_engine
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* ImageUsage contains data of the image and image user to identify changes that require a rebuild
|
||||
* of the texture slots.
|
||||
*/
|
||||
struct ImageUsage {
|
||||
/** Render pass of the image that is used. */
|
||||
short pass = 0;
|
||||
/** Layer of the image that is used.*/
|
||||
short layer = 0;
|
||||
/** View of the image that is used. */
|
||||
short view = 0;
|
||||
|
||||
ImageUsage() = default;
|
||||
ImageUsage(const struct ImageUser *image_user)
|
||||
{
|
||||
pass = image_user ? image_user->pass : 0;
|
||||
layer = image_user ? image_user->layer : 0;
|
||||
view = image_user ? image_user->multi_index : 0;
|
||||
}
|
||||
|
||||
bool operator==(const ImageUsage &other) const
|
||||
{
|
||||
return memcmp(this, &other, sizeof(ImageUsage)) == 0;
|
||||
}
|
||||
bool operator!=(const ImageUsage &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue