Blender  V3.3
image_instance_data.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. */
3 
8 #pragma once
9 
10 #include "BKE_image_wrappers.hh"
11 
12 #include "image_batches.hh"
13 #include "image_buffer_cache.hh"
14 #include "image_partial_updater.hh"
15 #include "image_private.hh"
16 #include "image_shader_params.hh"
17 #include "image_texture_info.hh"
18 #include "image_usage.hh"
19 
20 #include "DRW_render.h"
21 
26 
28  struct Image *image;
31 
33 
34  struct DRWView *view;
36  struct {
43  bool do_tile_drawing : 1;
44  } flags;
45 
46  struct {
49  } passes;
50 
55 
57  float ss_to_texture[4][4];
59 
60  public:
61  virtual ~IMAGE_InstanceData() = default;
62 
64  {
65  reset_dirty_flag(false);
66  }
68  {
69  reset_dirty_flag(true);
70  }
71 
73  {
74  for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
75  TextureInfo &info = texture_infos[i];
76  const bool is_allocated = info.texture != nullptr;
77  const bool is_visible = info.visible;
78  const bool resolution_changed = assign_if_different(info.last_viewport_size,
80  const bool should_be_freed = is_allocated && (!is_visible || resolution_changed);
81  const bool should_be_created = is_visible && (!is_allocated || resolution_changed);
82 
83  if (should_be_freed) {
85  info.texture = nullptr;
86  }
87 
88  if (should_be_created) {
90  &info.texture, GPU_RGBA16F, static_cast<DRWTextureFlag>(0));
91  }
92  info.dirty |= should_be_created;
93  }
94  }
95 
97  {
98  for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
99  TextureInfo &info = texture_infos[i];
100  if (!info.dirty) {
101  continue;
102  }
103  BatchUpdater batch_updater(info);
104  batch_updater.update_batch();
105  }
106  }
107 
108  void update_image_usage(const ImageUser *image_user)
109  {
110  ImageUsage usage(image, image_user, flags.do_tile_drawing);
111  if (last_usage != usage) {
112  last_usage = usage;
113  reset_dirty_flag(true);
115  }
116  }
117 
118  private:
120  void reset_dirty_flag(bool new_value)
121  {
122  for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
123  texture_infos[i].dirty = new_value;
124  }
125  }
126 };
DRWTextureFlag
Definition: DRW_render.h:139
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:564
Create GPUBatch for a IMAGE_ScreenSpaceTextureInfo.
void update_batch()
const float * DRW_viewport_size_get(void)
Definition: draw_manager.c:288
void DRW_texture_ensure_fullscreen_2d(GPUTexture **tex, eGPUTextureFormat format, DRWTextureFlag flags)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
constexpr int SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN
max allowed textures to use by the ScreenSpaceDrawingMode.
bool assign_if_different(T &old_value, T new_value)
struct DRWView * view
ShaderParameters sh_params
virtual ~IMAGE_InstanceData()=default
struct IMAGE_InstanceData::@223 passes
void update_image_usage(const ImageUser *image_user)
bool do_tile_drawing
should we perform tiled drawing (wrap repeat).
FloatBufferCache float_buffers
float ss_to_texture[4][4]
Transform matrix to convert a normalized screen space coordinates to texture space.
TextureInfo texture_infos[SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN]
PartialImageUpdater partial_update
struct IMAGE_InstanceData::@222 flags
GPUTexture * texture
GPU Texture for a partial region of the image editor.
bool dirty
does this texture need a full update.
float2 last_viewport_size
bool visible
Is the texture clipped.