45 state.do_shader_unbind =
true;
56 const bool use_filter,
64 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
65 const float draw_width = img_w * scaleX * xzoom;
66 const float draw_height = img_h * scaleY * yzoom;
70 const bool use_mipmap = use_filter && ((draw_width < img_w) || (draw_height < img_h));
71 const int mip_len = use_mipmap ? 9999 : 1;
113 if (
state->do_shader_unbind) {
137 const float color[4])
139 int subpart_x, subpart_y, tex_w = 256, tex_h = 256;
151 int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y;
153 const bool use_clipping = ((clip_min_x < clip_max_x) && (clip_min_y < clip_max_y));
154 const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
172 size_t stride = components * ((use_float_data) ?
sizeof(float) :
sizeof(
uchar));
183 seamless = ((tex_w < img_w || tex_h < img_h) && tex_w > 2 && tex_h > 2) ? 2 : 0;
185 offset_x = tex_w - seamless;
186 offset_y = tex_h - seamless;
188 nsubparts_x = (img_w + (offset_x - 1)) / (offset_x);
189 nsubparts_y = (img_h + (offset_y - 1)) / (offset_y);
196 immUniformColor4fv((color) ? color : white);
201 for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) {
202 for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) {
203 int remainder_x = img_w - subpart_x * offset_x;
204 int remainder_y = img_h - subpart_y * offset_y;
205 int subpart_w = (remainder_x < tex_w) ? remainder_x : tex_w;
206 int subpart_h = (remainder_y < tex_h) ? remainder_y : tex_h;
207 int offset_left = (seamless && subpart_x != 0) ? 1 : 0;
208 int offset_bot = (seamless && subpart_y != 0) ? 1 : 0;
209 int offset_right = (seamless && remainder_x > tex_w) ? 1 : 0;
210 int offset_top = (seamless && remainder_y > tex_h) ? 1 : 0;
211 float rast_x =
x + subpart_x * offset_x * xzoom;
212 float rast_y =
y + subpart_y * offset_y * yzoom;
214 if (subpart_w <= seamless || subpart_h <= seamless) {
218 int right = subpart_w - offset_right;
219 int top = subpart_h - offset_top;
220 int bottom = 0 + offset_bot;
221 int left = 0 + offset_left;
224 if (rast_x + right * xzoom * scaleX < clip_min_x ||
225 rast_y +
top * yzoom * scaleY < clip_min_y)
229 if (rast_x +
left * xzoom > clip_max_x || rast_y + bottom * yzoom > clip_max_y) {
235 int src_y = subpart_y * offset_y;
236 int src_x = subpart_x * offset_x;
238#define DATA(_y, _x) (static_cast<const char *>(rect) + stride * (size_t(_y) * img_w + (_x)))
240 const void *
data =
DATA(src_y, src_x);
245 if (subpart_w < tex_w) {
246 const void *
data =
DATA(src_y, src_x + subpart_w - 1);
247 const int offset[2] = {subpart_w, 0};
248 const int extent[2] = {1, subpart_h};
251 if (subpart_h < tex_h) {
252 const void *
data =
DATA(src_y + subpart_h - 1, src_x);
253 const int offset[2] = {0, subpart_h};
254 const int extent[2] = {subpart_w, 1};
258 if (subpart_w < tex_w && subpart_h < tex_h) {
259 const void *
data =
DATA(src_y + subpart_h - 1, src_x + subpart_w - 1);
260 const int offset[2] = {subpart_w, subpart_h};
261 const int extent[2] = {1, 1};
270 immAttr2f(texco,
left /
float(tex_w), bottom /
float(tex_h));
271 immVertex2f(
pos, rast_x + offset_left * xzoom, rast_y + offset_bot * yzoom);
273 immAttr2f(texco, right /
float(tex_w), bottom /
float(tex_h));
274 immVertex2f(
pos, rast_x + right * xzoom * scaleX, rast_y + offset_bot * yzoom);
276 immAttr2f(texco, right /
float(tex_w),
top /
float(tex_h));
277 immVertex2f(
pos, rast_x + right * xzoom * scaleX, rast_y +
top * yzoom * scaleY);
285 if (
state->do_shader_unbind) {
308 const float color[4])
339 const float color[4])
374 const float color[4])
410 bool force_fallback =
false;
411 bool need_fallback =
true;
419 force_fallback |= ibuf->
channels == 1;
425 if (force_fallback ==
false) {
430 state.do_shader_unbind =
false;
444 view_settings, display_settings, ibuf->
dither,
true);
467 BLI_assert_msg(0,
"Incompatible number of channels for GLSL display");
509 need_fallback =
false;
515 uchar *display_buffer;
519 ibuf, view_settings, display_settings, &cache_handle);
521 if (display_buffer) {
599 const bContext *
C,
ImBuf *ibuf,
float x,
float y,
bool use_filter,
float zoom_x,
float zoom_y)
601 ED_draw_imbuf_ctx_clipping(
C, ibuf,
x,
y, use_filter, 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y);
609 const size_t threshold =
sizeof(
float[4]) * 2048 * 2048;
611 const size_t size = size_t(ibuf->
x) * size_t(ibuf->
y) * size_t(ibuf->
channels) * data_size;
615 return U.image_draw_method;
#define BLI_assert_msg(a, msg)
MINLINE float min_ff(float a, float b)
@ IMAGE_DRAW_METHOD_2DTEXTURE
eGPUBackendType GPU_backend_get_type()
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
GPUShader * GPU_shader_get_builtin_shader(eGPUBuiltinShader shader)
@ GPU_SHADER_3D_IMAGE_COLOR
void GPU_texture_bind(GPUTexture *texture, int unit)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
void GPU_texture_unbind(GPUTexture *texture)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
void GPU_texture_update_sub(GPUTexture *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_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter)
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
void GPU_texture_update_mipmap_chain(GPUTexture *texture)
void GPU_unpack_row_length_set(uint len)
void GPU_texture_update(GPUTexture *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 immDrawPixelsTexTiled_scaling_clipping(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, eGPUTextureFormat 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])
void ED_draw_imbuf_ctx(const bContext *C, ImBuf *ibuf, float x, float y, bool use_filter, float zoom_x, float zoom_y)
void immDrawPixelsTexTiled_scaling(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, eGPUTextureFormat gpu_format, bool use_filter, const void *rect, float scaleX, float scaleY, float xzoom, float yzoom, const float color[4])
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 immDrawPixelsTexTiled_clipping(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, eGPUTextureFormat 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 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(IMMDrawPixelsTexState *state, float x, float y, int img_w, int img_h, eGPUTextureFormat gpu_format, bool use_filter, const void *rect, float xzoom, float yzoom, const float color[4])
int ED_draw_imbuf_method(const ImBuf *ibuf)
void immDrawPixelsTexScaledFullSize(const IMMDrawPixelsTexState *state, const float x, const float y, const int img_w, const int img_h, const eGPUTextureFormat 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])
IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin)
static void immDrawPixelsTexSetupAttributes(IMMDrawPixelsTexState *state)
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer