32 vert_format,
"pos", blender::gpu::VertAttrType::SFLOAT_32_32);
34 vert_format,
"texCoord", blender::gpu::VertAttrType::SFLOAT_32_32);
46 state.do_shader_unbind =
true;
57 const bool use_filter,
65 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
66 const float draw_width = img_w * scaleX * xzoom;
67 const float draw_height = img_h * scaleY * yzoom;
71 const bool use_mipmap = use_filter && ((draw_width < img_w) || (draw_height < img_h));
72 const int mip_len = use_mipmap ? 9999 : 1;
77 const bool use_float_data =
ELEM(gpu_format,
78 blender::gpu::TextureFormat::SFLOAT_16_16_16_16,
79 blender::gpu::TextureFormat::SFLOAT_16_16_16,
80 blender::gpu::TextureFormat::SFLOAT_16);
117 if (
state->do_shader_unbind) {
141 const float color[4])
143 int subpart_x, subpart_y, tex_w = 256, tex_h = 256;
155 int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y;
157 const bool use_clipping = ((clip_min_x < clip_max_x) && (clip_min_y < clip_max_y));
158 const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
161 blender::gpu::TextureFormat::UNORM_8_8_8_8,
162 blender::gpu::TextureFormat::SFLOAT_16_16_16_16))
166 else if (
ELEM(gpu_format, blender::gpu::TextureFormat::SFLOAT_16_16_16)) {
169 else if (
ELEM(gpu_format,
170 blender::gpu::TextureFormat::UNORM_8,
171 blender::gpu::TextureFormat::SFLOAT_16))
180 const bool use_float_data =
ELEM(gpu_format,
181 blender::gpu::TextureFormat::SFLOAT_16_16_16_16,
182 blender::gpu::TextureFormat::SFLOAT_16_16_16,
183 blender::gpu::TextureFormat::SFLOAT_16);
185 size_t stride = components * ((use_float_data) ?
sizeof(
float) :
sizeof(
uchar));
196 seamless = ((tex_w < img_w || tex_h < img_h) && tex_w > 2 && tex_h > 2) ? 2 : 0;
198 offset_x = tex_w - seamless;
199 offset_y = tex_h - seamless;
201 nsubparts_x = (img_w + (offset_x - 1)) / (offset_x);
202 nsubparts_y = (img_h + (offset_y - 1)) / (offset_y);
209 immUniformColor4fv((color) ? color : white);
214 for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) {
215 for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) {
216 int remainder_x = img_w - subpart_x * offset_x;
217 int remainder_y = img_h - subpart_y * offset_y;
218 int subpart_w = (remainder_x < tex_w) ? remainder_x : tex_w;
219 int subpart_h = (remainder_y < tex_h) ? remainder_y : tex_h;
220 int offset_left = (seamless && subpart_x != 0) ? 1 : 0;
221 int offset_bot = (seamless && subpart_y != 0) ? 1 : 0;
222 int offset_right = (seamless && remainder_x > tex_w) ? 1 : 0;
223 int offset_top = (seamless && remainder_y > tex_h) ? 1 : 0;
224 float rast_x =
x + subpart_x * offset_x * xzoom;
225 float rast_y =
y + subpart_y * offset_y * yzoom;
227 if (subpart_w <= seamless || subpart_h <= seamless) {
231 int right = subpart_w - offset_right;
232 int top = subpart_h - offset_top;
233 int bottom = 0 + offset_bot;
234 int left = 0 + offset_left;
237 if (rast_x + right * xzoom * scaleX < clip_min_x ||
238 rast_y +
top * yzoom * scaleY < clip_min_y)
242 if (rast_x +
left * xzoom > clip_max_x || rast_y + bottom * yzoom > clip_max_y) {
248 int src_y = subpart_y * offset_y;
249 int src_x = subpart_x * offset_x;
251#define DATA(_y, _x) (static_cast<const char *>(rect) + stride * (size_t(_y) * img_w + (_x)))
253 const void *
data =
DATA(src_y, src_x);
258 if (subpart_w < tex_w) {
259 const void *
data =
DATA(src_y, src_x + subpart_w - 1);
260 const int offset[2] = {subpart_w, 0};
261 const int extent[2] = {1, subpart_h};
264 if (subpart_h < tex_h) {
265 const void *
data =
DATA(src_y + subpart_h - 1, src_x);
266 const int offset[2] = {0, subpart_h};
267 const int extent[2] = {subpart_w, 1};
271 if (subpart_w < tex_w && subpart_h < tex_h) {
272 const void *
data =
DATA(src_y + subpart_h - 1, src_x + subpart_w - 1);
273 const int offset[2] = {subpart_w, subpart_h};
274 const int extent[2] = {1, 1};
283 immAttr2f(texco,
left /
float(tex_w), bottom /
float(tex_h));
284 immVertex2f(
pos, rast_x + offset_left * xzoom, rast_y + offset_bot * yzoom);
286 immAttr2f(texco, right /
float(tex_w), bottom /
float(tex_h));
287 immVertex2f(
pos, rast_x + right * xzoom * scaleX, rast_y + offset_bot * yzoom);
289 immAttr2f(texco, right /
float(tex_w),
top /
float(tex_h));
290 immVertex2f(
pos, rast_x + right * xzoom * scaleX, rast_y +
top * yzoom * scaleY);
298 if (
state->do_shader_unbind) {
321 const float color[4])
352 const float color[4])
387 const float color[4])
425 bool force_fallback =
false;
426 bool need_fallback =
true;
434 force_fallback |= ibuf->
channels == 1;
440 if (force_fallback ==
false) {
445 state.do_shader_unbind =
false;
459 view_settings, display_settings, ibuf->
dither,
true);
476 format = TextureFormat::SFLOAT_16_16_16;
479 format = TextureFormat::SFLOAT_16_16_16_16;
482 BLI_assert_msg(0,
"Incompatible number of channels for GLSL display");
510 blender::gpu::TextureFormat::UNORM_8_8_8_8,
524 need_fallback =
false;
530 uchar *display_buffer;
534 ibuf, view_settings, display_settings, &cache_handle);
536 if (display_buffer) {
543 blender::gpu::TextureFormat::UNORM_8_8_8_8,
614 const bContext *
C,
ImBuf *ibuf,
float x,
float y,
bool use_filter,
float zoom_x,
float zoom_y)
616 ED_draw_imbuf_ctx_clipping(
C, ibuf,
x,
y, use_filter, 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y);
624 const size_t threshold =
sizeof(
float[4]) * 2048 * 2048;
626 const size_t size = size_t(ibuf->
x) * size_t(ibuf->
y) * size_t(ibuf->
channels) * data_size;
630 return U.image_draw_method;
#define BLI_assert_msg(a, msg)
MINLINE float min_ff(float a, float b)
@ IMAGE_DRAW_METHOD_2DTEXTURE
GPUBackendType GPU_backend_get_type()
int GPU_shader_get_uniform(blender::gpu::Shader *shader, const char *name)
blender::gpu::Shader * GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
@ GPU_SHADER_3D_IMAGE_COLOR
void GPU_texture_update_sub(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void GPU_texture_update_mipmap_chain(blender::gpu::Texture *texture)
void GPU_texture_unbind(blender::gpu::Texture *texture)
void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_mipmap_mode(blender::gpu::Texture *texture, bool use_mipmap, bool use_filter)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
void GPU_unpack_row_length_set(uint len)
void GPU_texture_bind(blender::gpu::Texture *texture, int unit)
void GPU_texture_free(blender::gpu::Texture *texture)
void GPU_texture_update(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
unsigned char * IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, void **cache_handle)
bool IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float dither, bool predivide)
void IMB_display_buffer_release(void *cache_handle)
void IMB_colormanagement_display_settings_from_ctx(const bContext *C, ColorManagedViewSettings **r_view_settings, ColorManagedDisplaySettings **r_display_settings)
void IMB_colormanagement_finish_glsl_draw()
bool IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const ColorSpace *from_colorspace, float dither, bool predivide, bool do_overlay_merge)
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void ED_draw_imbuf_ctx(const bContext *C, ImBuf *ibuf, float x, float y, bool use_filter, float zoom_x, float zoom_y)
void ED_draw_imbuf_clipping(ImBuf *ibuf, float x, float y, bool use_filter, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y, float zoom_x, float zoom_y)
void ED_draw_imbuf(ImBuf *ibuf, float x, float y, bool use_filter, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float zoom_x, float zoom_y)
void immDrawBorderCorners(uint pos, const rcti *border, float zoomx, float zoomy)
void ED_draw_imbuf_ctx_clipping(const bContext *C, ImBuf *ibuf, float x, float y, bool use_filter, float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y, float zoom_x, float zoom_y)
void immDrawPixelsTexTiled_scaling(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, blender::gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float scaleX, float scaleY, float xzoom, float yzoom, const float color[4])
void immDrawPixelsTexScaledFullSize(const IMMDrawPixelsTexState *state, const float x, const float y, const int img_w, const int img_h, const blender::gpu::TextureFormat gpu_format, const bool use_filter, const void *rect, const float scaleX, const float scaleY, const float xzoom, const float yzoom, const float color[4])
void immDrawPixelsTexTiled(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, blender::gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float xzoom, float yzoom, const float color[4])
void immDrawPixelsTexTiled_clipping(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, blender::gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y, float xzoom, float yzoom, const float color[4])
void immDrawPixelsTexTiled_scaling_clipping(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, blender::gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float scaleX, float scaleY, float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y, float xzoom, float yzoom, const float color[4])
int ED_draw_imbuf_method(const ImBuf *ibuf)
IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin)
static void immDrawPixelsTexSetupAttributes(IMMDrawPixelsTexState *state)
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer