68 *r_texture_format = is_grayscale ?
69 (use_high_bitdepth ? blender::gpu::TextureFormat::SFLOAT_32 :
70 blender::gpu::TextureFormat::SFLOAT_16) :
71 (use_high_bitdepth ? blender::gpu::TextureFormat::SFLOAT_32_32_32_32 :
72 blender::gpu::TextureFormat::SFLOAT_16_16_16_16);
79 *r_texture_format = (is_grayscale) ? blender::gpu::TextureFormat::UNORM_8 :
80 blender::gpu::TextureFormat::UNORM_8_8_8_8;
84 *r_texture_format = (is_grayscale) ? blender::gpu::TextureFormat::SFLOAT_16 :
85 blender::gpu::TextureFormat::SRGBA_8_8_8_8;
89 *r_texture_format = (is_grayscale) ? blender::gpu::TextureFormat::SFLOAT_16 :
90 blender::gpu::TextureFormat::SFLOAT_16_16_16_16;
110 *r_texture_format = (use_srgb) ? blender::gpu::TextureFormat::SRGB_DXT1 :
111 blender::gpu::TextureFormat::SNORM_DXT1;
114 *r_texture_format = (use_srgb) ? blender::gpu::TextureFormat::SRGB_DXT3 :
115 blender::gpu::TextureFormat::SNORM_DXT3;
118 *r_texture_format = (use_srgb) ? blender::gpu::TextureFormat::SRGB_DXT5 :
119 blender::gpu::TextureFormat::SNORM_DXT5;
132 const bool do_rescale,
133 const int rescale_size[2],
134 const bool store_premultiplied,
135 const bool allow_grayscale,
143 bool freedata =
false;
149 if (ibuf->
channels != 4 || !store_premultiplied) {
151 *r_freedata = freedata =
true;
153 if (data_rect ==
nullptr) {
158 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
173 data_rect =
MEM_mallocN((is_grayscale ?
sizeof(
float[4]) :
sizeof(
uchar[4])) *
176 *r_freedata = freedata =
true;
178 if (data_rect ==
nullptr) {
190 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
191 is_float_rect =
true;
195 (
uchar *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
201 *r_freedata = freedata =
true;
202 is_float_rect =
true;
204 if (data_rect ==
nullptr) {
214 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
219 const uint8_t *rect = (is_float_rect) ?
nullptr : (uint8_t *)data_rect;
220 const float *rect_float = (is_float_rect) ? (
float *)data_rect :
nullptr;
231 *r_freedata = freedata =
true;
240 void *src_rect = data_rect;
242 if (freedata ==
false) {
245 *r_freedata = freedata =
true;
248 if (data_rect ==
nullptr) {
252 size_t buffer_size = do_rescale ? size_t(rescale_size[0]) * size_t(rescale_size[1]) :
253 size_t(ibuf->
x) * size_t(ibuf->
y);
255 for (
size_t i = 0;
i < buffer_size;
i++) {
256 ((
float *)data_rect)[
i] = ((
float *)src_rect)[
i * 4];
260 for (
size_t i = 0;
i < buffer_size;
i++) {
275 bool use_high_bitdepth,
303 bool use_high_bitdepth,
307 const bool do_rescale = (ibuf->
x !=
w || ibuf->
y != h);
308 const int size[2] = {
w, h};
313 bool freebuf =
false;
317 ibuf, do_rescale,
size, use_premult, use_grayscale, &freebuf, &data_format);
329 bool use_high_bitdepth,
334 bool do_rescale = (ibuf->
x !=
size[0]) || (ibuf->
y !=
size[1]);
337 if (do_rescale && ibuf->
x != ibuf->
y) {
339 size[1] = int(ibuf->
y * (
float(
size[0]) / ibuf->
x));
342 size[0] = int(ibuf->
x * (
float(
size[1]) / ibuf->
y));
349 CLOG_WARN(&
LOG,
"Unable to find a suitable DXT compression");
351 else if (do_rescale) {
359 CLOG_WARN(&
LOG,
"Unable to load non-power-of-two DXT image resolution");
370 if (tex !=
nullptr) {
383 bool freebuf =
false;
389 if (tex ==
nullptr) {
416 return gpu_texture_format;
421 const float half_min = -65504;
422 const float half_max = 65504;
429 int rect_float_len = image_buffer->
x * image_buffer->
y *
432 for (
int i = 0;
i < rect_float_len;
i++) {
433 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)
#define CLOG_WARN(clg_ref,...)
int GPU_texture_size_with_limit(int res)
void GPU_texture_swizzle_set(blender::gpu::Texture *texture, const char swizzle[4])
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)
blender::gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_anisotropic_filter(blender::gpu::Texture *texture, bool use_aniso)
blender::gpu::Texture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_GENERAL
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_update(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
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(const ColorSpace *colorspace)
bool IMB_colormanagement_space_is_data(const 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)
bool IMB_colormanagement_space_is_srgb(const ColorSpace *colorspace)
float * IMB_steal_float_buffer(ImBuf *ibuf)
uint8_t * IMB_steal_byte_buffer(ImBuf *ibuf)
ImBuf * IMB_allocFromBuffer(const uint8_t *byte_buffer, const float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
void IMB_freeImBuf(ImBuf *ibuf)
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
bool IMB_scale(ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded=true)
Read Guarded memory(de)allocation.
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void * MEM_mallocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImbFormatOptions foptions
ImBufByteBuffer byte_buffer
static void imb_gpu_get_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale, blender::gpu::TextureFormat *r_texture_format)
blender::gpu::Texture * IMB_create_gpu_texture(const char *name, ImBuf *ibuf, bool use_high_bitdepth, bool use_premult)
static bool imb_is_grayscale_texture_format_compatible(const ImBuf *ibuf)
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)
void IMB_update_gpu_texture_sub(blender::gpu::Texture *tex, ImBuf *ibuf, int x, int y, int z, int w, int h, bool use_high_bitdepth, bool use_grayscale, bool use_premult)
blender::gpu::Texture * IMB_touch_gpu_texture(const char *name, ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth, bool use_grayscale)
blender::gpu::TextureFormat IMB_gpu_get_texture_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale)
bool IMB_gpu_get_compressed_format(const ImBuf *ibuf, blender::gpu::TextureFormat *r_texture_format)
void IMB_gpu_clamp_half_float(ImBuf *image_buffer)