Blender  V3.3
COM_ReadBufferOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
5 
6 #include "COM_ExecutionGroup.h"
8 
9 namespace blender::compositor {
10 
12 {
13  this->add_output_socket(datatype);
14  single_value_ = false;
15  offset_ = 0;
16  buffer_ = nullptr;
18 }
19 
21 {
22  return buffer_;
23 }
24 
25 void ReadBufferOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
26 {
27  if (memory_proxy_ != nullptr) {
28  WriteBufferOperation *operation = memory_proxy_->get_write_buffer_operation();
29  operation->determine_canvas(preferred_area, r_area);
30  operation->set_canvas(r_area);
31 
33  if (memory_proxy_->get_executor()) {
34  uint resolution[2] = {static_cast<uint>(BLI_rcti_size_x(&r_area)),
35  static_cast<uint>(BLI_rcti_size_y(&r_area))};
36  memory_proxy_->get_executor()->set_resolution(resolution);
37  }
38 
39  single_value_ = operation->is_single_value();
40  }
41 }
43  float x,
44  float y,
46 {
47  if (single_value_) {
48  /* write buffer has a single value stored at (0,0) */
49  buffer_->read(output, 0, 0);
50  }
51  else {
52  switch (sampler) {
54  buffer_->read(output, x, y);
55  break;
57  default:
58  buffer_->read_bilinear(output, x, y);
59  break;
61  buffer_->read_bilinear(output, x, y);
62  break;
63  }
64  }
65 }
66 
68  float x,
69  float y,
71  MemoryBufferExtend extend_x,
72  MemoryBufferExtend extend_y)
73 {
74  if (single_value_) {
75  /* write buffer has a single value stored at (0,0) */
76  buffer_->read(output, 0, 0);
77  }
78  else if (sampler == PixelSampler::Nearest) {
79  buffer_->read(output, x, y, extend_x, extend_y);
80  }
81  else {
82  buffer_->read_bilinear(output, x, y, extend_x, extend_y);
83  }
84 }
85 
87  float output[4], float x, float y, float dx[2], float dy[2])
88 {
89  if (single_value_) {
90  /* write buffer has a single value stored at (0,0) */
91  buffer_->read(output, 0, 0);
92  }
93  else {
94  const float uv[2] = {x, y};
95  const float deriv[2][2] = {{dx[0], dx[1]}, {dy[0], dy[1]}};
96  buffer_->readEWA(output, uv, deriv);
97  }
98 }
99 
101  ReadBufferOperation *read_operation,
102  rcti *output)
103 {
104  if (this == read_operation) {
105  BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax);
106  return true;
107  }
108  return false;
109 }
110 
112 {
113  if (memory_proxy_ != nullptr) {
114  WriteBufferOperation *operation = memory_proxy_->get_write_buffer_operation();
115  this->set_width(operation->get_width());
116  this->set_height(operation->get_height());
117  }
118 }
119 
121 {
122  buffer_ = this->get_memory_proxy()->get_buffer();
123 }
124 
125 } // namespace blender::compositor
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:190
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:417
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:186
unsigned int uint
Definition: BLI_sys_types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void set_resolution(unsigned int resolution[2])
set the resolution of this executiongroup
void read(float *result, int x, int y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip)
void read_bilinear(float *result, float x, float y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip) const
void readEWA(float *result, const float uv[2], const float derivatives[2][2])
ExecutionGroup * get_executor() const
get the ExecutionGroup that can be scheduled to calculate a certain chunk.
WriteBufferOperation * get_write_buffer_operation() const
get the WriteBufferOperation that is responsible for writing to this MemoryProxy
MemoryBuffer * get_buffer()
get the allocated memory
void set_canvas(const rcti &canvas_area)
void add_output_socket(DataType datatype)
void set_width(unsigned int width)
void set_height(unsigned int height)
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
void execute_pixel_extend(float output[4], float x, float y, PixelSampler sampler, MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void execute_pixel_filtered(float output[4], float x, float y, float dx[2], float dy[2]) override
calculate a single pixel using an EWA filter
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
DataType
possible data types for sockets
Definition: COM_defines.h:30
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input