65 *r_texture_format = is_grayscale ? (use_high_bitdepth ?
GPU_R32F :
GPU_R16F) :
119 const bool do_rescale,
120 const int rescale_size[2],
121 const bool store_premultiplied,
122 const bool allow_grayscale,
130 bool freedata =
false;
136 if (ibuf->
channels != 4 || !store_premultiplied) {
137 data_rect =
MEM_mallocN(
sizeof(
float[4]) * ibuf->
x * ibuf->
y, __func__);
138 *r_freedata = freedata =
true;
140 if (data_rect ==
nullptr) {
145 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
161 (is_grayscale ?
sizeof(
float[4]) :
sizeof(
uchar[4])) * ibuf->
x * ibuf->
y, __func__);
162 *r_freedata = freedata =
true;
164 if (data_rect ==
nullptr) {
176 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
177 is_float_rect =
true;
181 (
uchar *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
186 data_rect =
MEM_mallocN(
sizeof(
float[4]) * ibuf->
x * ibuf->
y, __func__);
187 *r_freedata = freedata =
true;
188 is_float_rect =
true;
190 if (data_rect ==
nullptr) {
200 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
205 const uint8_t *rect = (is_float_rect) ?
nullptr : (
uint8_t *)data_rect;
206 const float *rect_float = (is_float_rect) ? (
float *)data_rect :
nullptr;
217 *r_freedata = freedata =
true;
226 void *src_rect = data_rect;
228 if (freedata ==
false) {
229 data_rect =
MEM_mallocN((is_float_rect ?
sizeof(
float) :
sizeof(
uchar)) * ibuf->
x * ibuf->
y,
231 *r_freedata = freedata =
true;
234 if (data_rect ==
nullptr) {
238 int buffer_size = do_rescale ? rescale_size[0] * rescale_size[1] : ibuf->
x * ibuf->
y;
240 for (
uint64_t i = 0; i < buffer_size; i++) {
241 ((
float *)data_rect)[i] = ((
float *)src_rect)[i * 4];
245 for (
uint64_t i = 0; i < buffer_size; i++) {
246 ((
uchar *)data_rect)[i] = ((
uchar *)src_rect)[i * 4];
260 bool use_high_bitdepth,
288 bool use_high_bitdepth,
292 const bool do_rescale = (ibuf->
x !=
w || ibuf->
y != h);
293 const int size[2] = {
w, h};
298 bool freebuf =
false;
302 ibuf, do_rescale, size, use_premult, use_grayscale, &freebuf, &data_format);
314 bool use_high_bitdepth,
317 GPUTexture *
tex =
nullptr;
319 bool do_rescale = (ibuf->
x != size[0]) || (ibuf->
y != size[1]);
322 if (do_rescale && ibuf->
x != ibuf->
y) {
323 if (size[0] > size[1]) {
324 size[1] =
int(ibuf->
y * (
float(size[0]) / ibuf->
x));
327 size[0] =
int(ibuf->
x * (
float(size[1]) / ibuf->
y));
334 fprintf(stderr,
"Unable to find a suitable DXT compression,");
336 else if (do_rescale) {
337 fprintf(stderr,
"Unable to load DXT image resolution,");
344 fprintf(stderr,
"Unable to load non-power-of-two DXT image resolution,");
355 if (
tex !=
nullptr) {
359 fprintf(stderr,
"ST3C support not found,");
362 fprintf(stderr,
" falling back to uncompressed (%s, %ix%i).\n", name, ibuf->
x, ibuf->
y);
368 bool freebuf =
false;
374 if (
tex ==
nullptr) {
375 size[0] =
max_ii(1, size[0] / 2);
376 size[1] =
max_ii(1, size[1] / 2);
382 void *data =
imb_gpu_get_data(ibuf, do_rescale, size, use_premult,
true, &freebuf, &data_format);
401 return gpu_texture_format;
406 const float half_min = -65504;
407 const float half_max = 65504;
414 int rect_float_len = image_buffer->
x * image_buffer->
y *
417 for (
int i = 0; i < rect_float_len; i++) {
418 rect_float[i] =
clamp_f(rect_float[i], half_min, half_max);
MINLINE float clamp_f(float value, float min, float max)
MINLINE int max_ii(int a, int b)
MINLINE int is_power_of_2_i(int n)
int GPU_texture_size_with_limit(int res)
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
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_anisotropic_filter(GPUTexture *texture, bool use_aniso)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_GENERAL
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)
GPUTexture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4])
bool IMB_colormanagement_space_is_data(ColorSpace *colorspace)
bool IMB_colormanagement_space_is_srgb(ColorSpace *colorspace)
void IMB_colormanagement_imbuf_to_byte_texture(unsigned char *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
bool IMB_colormanagement_space_is_scene_linear(ColorSpace *colorspace)
void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
float * IMB_steal_float_buffer(ImBuf *ibuf)
uint8_t * IMB_steal_byte_buffer(ImBuf *ibuf)
bool IMB_scale(ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded=true)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
additional_info("compositor_sum_float_shared") .push_constant(Type additional_info("compositor_sum_float_shared") .push_constant(Type GPU_RGBA32F
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
struct ImBuf * IMB_allocFromBuffer(const uint8_t *, const float *, unsigned int, unsigned int, unsigned int)
void IMB_freeImBuf(ImBuf *)
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
unsigned __int64 uint64_t
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
static bool imb_is_grayscale_texture_format_compatible(const ImBuf *ibuf)
static bool IMB_gpu_get_compressed_format(const ImBuf *ibuf, eGPUTextureFormat *r_texture_format)
GPUTexture * IMB_touch_gpu_texture(const char *name, ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth, bool use_grayscale)
static const char * imb_gpu_get_swizzle(const ImBuf *ibuf)
static void * imb_gpu_get_data(const ImBuf *ibuf, const bool do_rescale, const int rescale_size[2], const bool store_premultiplied, const bool allow_grayscale, bool *r_freedata, eGPUDataFormat *r_data_format)
eGPUTextureFormat IMB_gpu_get_texture_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale)
void IMB_update_gpu_texture_sub(GPUTexture *tex, ImBuf *ibuf, int x, int y, int z, int w, int h, bool use_high_bitdepth, bool use_grayscale, bool use_premult)
static void imb_gpu_get_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale, eGPUTextureFormat *r_texture_format)
GPUTexture * IMB_create_gpu_texture(const char *name, ImBuf *ibuf, bool use_high_bitdepth, bool use_premult)
void IMB_gpu_clamp_half_float(ImBuf *image_buffer)