Blender  V3.3
image_space_node.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  SpaceNode *snode;
16 
17  public:
18  SpaceNodeAccessor(SpaceNode *snode) : snode(snode)
19  {
20  }
21 
22  Image *get_image(Main *bmain) override
23  {
24  return BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
25  }
26 
28  {
29  return nullptr;
30  }
31 
33  {
34  return BKE_image_acquire_ibuf(image, nullptr, lock);
35  }
36 
37  void release_buffer(Image *image, ImBuf *ibuf, void *lock) override
38  {
40  }
41 
42  void get_shader_parameters(ShaderParameters &r_shader_parameters, ImBuf *ibuf) override
43  {
44  if ((snode->flag & SNODE_USE_ALPHA) != 0) {
45  /* Show RGBA */
47  }
48  else if ((snode->flag & SNODE_SHOW_ALPHA) != 0) {
49  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
50  copy_v4_fl4(r_shader_parameters.shuffle, 0.0f, 0.0f, 0.0f, 1.0f);
51  }
52  else if ((snode->flag & SNODE_SHOW_R) != 0) {
53  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
54  if (IMB_alpha_affects_rgb(ibuf)) {
55  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
56  }
57  copy_v4_fl4(r_shader_parameters.shuffle, 1.0f, 0.0f, 0.0f, 0.0f);
58  }
59  else if ((snode->flag & SNODE_SHOW_G) != 0) {
60  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
61  if (IMB_alpha_affects_rgb(ibuf)) {
62  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
63  }
64  copy_v4_fl4(r_shader_parameters.shuffle, 0.0f, 1.0f, 0.0f, 0.0f);
65  }
66  else if ((snode->flag & SNODE_SHOW_B) != 0) {
67  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHUFFLING;
68  if (IMB_alpha_affects_rgb(ibuf)) {
69  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
70  }
71  copy_v4_fl4(r_shader_parameters.shuffle, 0.0f, 0.0f, 1.0f, 0.0f);
72  }
73  else /* RGB */ {
74  if (IMB_alpha_affects_rgb(ibuf)) {
75  r_shader_parameters.flags |= IMAGE_DRAW_FLAG_APPLY_ALPHA;
76  }
77  }
78  }
79 
81  ImageUser *iuser,
82  ImBuf *ibuf,
83  GPUTexture **r_gpu_texture,
84  bool *r_owns_texture,
85  GPUTexture **r_tex_tile_data) override
86  {
87  *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, ibuf);
88  *r_owns_texture = false;
89  *r_tex_tile_data = nullptr;
90  }
91 
92  bool use_tile_drawing() const override
93  {
94  return false;
95  }
96 
101  void init_ss_to_texture_matrix(const ARegion *region,
102  const float image_resolution[2],
103  float r_uv_to_texture[4][4]) const override
104  {
105  unit_m4(r_uv_to_texture);
106  float display_resolution[2];
107  mul_v2_v2fl(display_resolution, image_resolution, snode->zoom);
108  const float scale_x = display_resolution[0] / region->winx;
109  const float scale_y = display_resolution[1] / region->winy;
110  const float translate_x = ((region->winx - display_resolution[0]) * 0.5f + snode->xof) /
111  region->winx;
112  const float translate_y = ((region->winy - display_resolution[1]) * 0.5f + snode->yof) /
113  region->winy;
114 
115  r_uv_to_texture[0][0] = scale_x;
116  r_uv_to_texture[1][1] = scale_y;
117  r_uv_to_texture[3][0] = translate_x;
118  r_uv_to_texture[3][1] = translate_y;
119  }
120 };
121 
122 } // namespace blender::draw::image_engine
void BKE_image_release_ibuf(struct Image *ima, struct ImBuf *ibuf, void *lock)
struct ImBuf * BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock)
struct Image * BKE_image_ensure_viewer(struct Main *bmain, int type, const char *name)
struct GPUTexture * BKE_image_get_gpu_texture(struct Image *image, struct ImageUser *iuser, struct ImBuf *ibuf)
Definition: image_gpu.cc:438
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)
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
@ IMA_TYPE_COMPOSITE
@ SNODE_USE_ALPHA
@ SNODE_SHOW_B
@ SNODE_SHOW_G
@ SNODE_SHOW_R
@ SNODE_SHOW_ALPHA
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
bool IMB_alpha_affects_rgb(const struct ImBuf *ibuf)
volatile int lock
void get_shader_parameters(ShaderParameters &r_shader_parameters, ImBuf *ibuf) override
void init_ss_to_texture_matrix(const ARegion *region, const float image_resolution[2], float r_uv_to_texture[4][4]) const override
bool use_tile_drawing() const override
Is (wrap) repeat option enabled in the space.
void get_gpu_textures(Image *image, ImageUser *iuser, ImBuf *ibuf, GPUTexture **r_gpu_texture, bool *r_owns_texture, GPUTexture **r_tex_tile_data) override
void release_buffer(Image *image, ImBuf *ibuf, void *lock) override
ImBuf * acquire_image_buffer(Image *image, void **lock) 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
#define IMAGE_DRAW_FLAG_SHOW_ALPHA
#define IMAGE_DRAW_FLAG_SHUFFLING
#define IMAGE_DRAW_FLAG_APPLY_ALPHA
Definition: BKE_main.h:121