Blender  V3.3
image_space_image.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 "image_private.hh"
11 
13 
15  SpaceImage *sima;
16 
17  public:
18  SpaceImageAccessor(SpaceImage *sima) : sima(sima)
19  {
20  }
21 
22  Image *get_image(Main *UNUSED(bmain)) override
23  {
24  return ED_space_image(sima);
25  }
26 
28  {
29  return &sima->iuser;
30  }
31 
33  {
34  return ED_space_image_acquire_buffer(sima, lock, 0);
35  }
36 
37  void release_buffer(Image *UNUSED(image), ImBuf *image_buffer, void *lock) override
38  {
39  ED_space_image_release_buffer(sima, image_buffer, lock);
40  }
41 
42  void get_shader_parameters(ShaderParameters &r_shader_parameters, ImBuf *image_buffer) override
43  {
44  const int sima_flag = sima->flag & ED_space_image_get_display_channel_mask(image_buffer);
45  if ((sima_flag & SI_USE_ALPHA) != 0) {
46  /* Show RGBA */
48  }
49  else if ((sima_flag & SI_SHOW_ALPHA) != 0) {
50  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
51  copy_v4_fl4(r_shader_parameters.shuffle, 0.0f, 0.0f, 0.0f, 1.0f);
52  }
53  else if ((sima_flag & SI_SHOW_ZBUF) != 0) {
54  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_DEPTH | IMAGE_DRAW_FLAG_SHUFFLING;
55  copy_v4_fl4(r_shader_parameters.shuffle, 1.0f, 0.0f, 0.0f, 0.0f);
56  }
57  else if ((sima_flag & SI_SHOW_R) != 0) {
58  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
59  if (IMB_alpha_affects_rgb(image_buffer)) {
60  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
61  }
62  copy_v4_fl4(r_shader_parameters.shuffle, 1.0f, 0.0f, 0.0f, 0.0f);
63  }
64  else if ((sima_flag & SI_SHOW_G) != 0) {
65  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
66  if (IMB_alpha_affects_rgb(image_buffer)) {
67  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
68  }
69  copy_v4_fl4(r_shader_parameters.shuffle, 0.0f, 1.0f, 0.0f, 0.0f);
70  }
71  else if ((sima_flag & SI_SHOW_B) != 0) {
72  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
73  if (IMB_alpha_affects_rgb(image_buffer)) {
74  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
75  }
76  copy_v4_fl4(r_shader_parameters.shuffle, 0.0f, 0.0f, 1.0f, 0.0f);
77  }
78  else /* RGB */ {
79  if (IMB_alpha_affects_rgb(image_buffer)) {
80  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
81  }
82  }
83  }
84 
86  ImageUser *iuser,
87  ImBuf *image_buffer,
88  GPUTexture **r_gpu_texture,
89  bool *r_owns_texture,
90  GPUTexture **r_tex_tile_data) override
91  {
92  if (image->rr != nullptr) {
93  /* Update multi-index and pass for the current eye. */
95  }
96  else {
98  }
99 
100  if (image_buffer == nullptr) {
101  return;
102  }
103 
104  if (image_buffer->rect == nullptr && image_buffer->rect_float == nullptr) {
105  /* This code-path is only supposed to happen when drawing a lazily-allocatable render result.
106  * In all the other cases the `ED_space_image_acquire_buffer()` is expected to return nullptr
107  * as an image buffer when it has no pixels. */
108 
110 
111  float zero[4] = {0, 0, 0, 0};
112  *r_gpu_texture = GPU_texture_create_2d(__func__, 1, 1, 0, GPU_RGBA16F, zero);
113  *r_owns_texture = true;
114  return;
115  }
116 
117  const int sima_flag = sima->flag & ED_space_image_get_display_channel_mask(image_buffer);
118  if (sima_flag & SI_SHOW_ZBUF &&
119  (image_buffer->zbuf || image_buffer->zbuf_float || (image_buffer->channels == 1))) {
120  if (image_buffer->zbuf) {
121  BLI_assert_msg(0, "Integer based depth buffers not supported");
122  }
123  else if (image_buffer->zbuf_float) {
124  *r_gpu_texture = GPU_texture_create_2d(
125  __func__, image_buffer->x, image_buffer->y, 0, GPU_R16F, image_buffer->zbuf_float);
126  *r_owns_texture = true;
127  }
128  else if (image_buffer->rect_float && image_buffer->channels == 1) {
129  *r_gpu_texture = GPU_texture_create_2d(
130  __func__, image_buffer->x, image_buffer->y, 0, GPU_R16F, image_buffer->rect_float);
131  *r_owns_texture = true;
132  }
133  }
134  else if (image->source == IMA_SRC_TILED) {
135  *r_gpu_texture = BKE_image_get_gpu_tiles(image, iuser, image_buffer);
136  *r_tex_tile_data = BKE_image_get_gpu_tilemap(image, iuser, nullptr);
137  *r_owns_texture = false;
138  }
139  else {
140  *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, image_buffer);
141  *r_owns_texture = false;
142  }
143  }
144 
145  bool use_tile_drawing() const override
146  {
147  return (sima->flag & SI_DRAW_TILE) != 0;
148  }
149 
150  void init_ss_to_texture_matrix(const ARegion *region,
151  const float UNUSED(image_resolution[2]),
152  float r_uv_to_texture[4][4]) const override
153  {
154  unit_m4(r_uv_to_texture);
155  float scale_x = 1.0 / BLI_rctf_size_x(&region->v2d.cur);
156  float scale_y = 1.0 / BLI_rctf_size_y(&region->v2d.cur);
157  float translate_x = scale_x * -region->v2d.cur.xmin;
158  float translate_y = scale_y * -region->v2d.cur.ymin;
159 
160  r_uv_to_texture[0][0] = scale_x;
161  r_uv_to_texture[1][1] = scale_y;
162  r_uv_to_texture[3][0] = translate_x;
163  r_uv_to_texture[3][1] = translate_y;
164  }
165 };
166 
167 } // namespace blender::draw::image_engine
struct GPUTexture * BKE_image_get_gpu_tiles(struct Image *image, struct ImageUser *iuser, struct ImBuf *ibuf)
Definition: image_gpu.cc:443
struct RenderPass * BKE_image_multilayer_index(struct RenderResult *rr, struct ImageUser *iuser)
void BKE_image_multiview_index(const struct Image *ima, struct ImageUser *iuser)
struct GPUTexture * BKE_image_get_gpu_texture(struct Image *image, struct ImageUser *iuser, struct ImBuf *ibuf)
Definition: image_gpu.cc:438
struct GPUTexture * BKE_image_get_gpu_tilemap(struct Image *image, struct ImageUser *iuser, struct ImBuf *ibuf)
Definition: image_gpu.cc:448
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
void unit_m4(float m[4][4])
Definition: rct.c:1090
MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:194
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:198
#define UNUSED(x)
@ IMA_SRC_TILED
@ IMA_TYPE_R_RESULT
@ SI_DRAW_TILE
@ SI_SHOW_ZBUF
@ SI_SHOW_R
@ SI_USE_ALPHA
@ SI_SHOW_G
@ SI_SHOW_B
@ SI_SHOW_ALPHA
void ED_space_image_release_buffer(struct SpaceImage *sima, struct ImBuf *ibuf, void *lock)
Definition: image_edit.c:158
struct Image * ED_space_image(const struct SpaceImage *sima)
int ED_space_image_get_display_channel_mask(struct ImBuf *ibuf)
Definition: image_edit.c:165
struct ImBuf * ED_space_image_acquire_buffer(struct SpaceImage *sima, void **r_lock, int tile)
Definition: image_edit.c:118
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:291
@ GPU_R16F
Definition: GPU_texture.h:113
bool IMB_alpha_affects_rgb(const struct ImBuf *ibuf)
volatile int lock
void get_shader_parameters(ShaderParameters &r_shader_parameters, ImBuf *image_buffer) override
ImBuf * acquire_image_buffer(Image *UNUSED(image), void **lock) override
void release_buffer(Image *UNUSED(image), ImBuf *image_buffer, void *lock) override
Image * get_image(Main *UNUSED(bmain)) override
bool use_tile_drawing() const override
Is (wrap) repeat option enabled in the space.
void get_gpu_textures(Image *image, ImageUser *iuser, ImBuf *image_buffer, GPUTexture **r_gpu_texture, bool *r_owns_texture, GPUTexture **r_tex_tile_data) override
void init_ss_to_texture_matrix(const ARegion *region, const float UNUSED(image_resolution[2]), float r_uv_to_texture[4][4]) const override
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
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
#define IMAGE_DRAW_FLAG_SHOW_ALPHA
#define IMAGE_DRAW_FLAG_SHUFFLING
#define IMAGE_DRAW_FLAG_APPLY_ALPHA
#define IMAGE_DRAW_FLAG_DEPTH
float * zbuf_float
int channels
unsigned int * rect
float * rect_float
int * zbuf
Definition: BKE_main.h:121
struct ImageUser iuser
float xmin
Definition: DNA_vec_types.h:69
float ymin
Definition: DNA_vec_types.h:70