Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/util_gpu.c
| Show First 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| GPUTexture *IMB_create_gpu_texture(const char *name, | GPUTexture *IMB_create_gpu_texture(const char *name, | ||||
| ImBuf *ibuf, | ImBuf *ibuf, | ||||
| bool use_high_bitdepth, | bool use_high_bitdepth, | ||||
| bool use_premult) | bool use_premult) | ||||
| { | { | ||||
| GPUTexture *tex = NULL; | GPUTexture *tex = NULL; | ||||
| const int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)}; | int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)}; | ||||
| bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]); | bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]); | ||||
| #ifdef WITH_DDS | #ifdef WITH_DDS | ||||
| if (ibuf->ftype == IMB_FTYPE_DDS) { | if (ibuf->ftype == IMB_FTYPE_DDS) { | ||||
| eGPUTextureFormat compressed_format; | eGPUTextureFormat compressed_format; | ||||
| if (!IMB_gpu_get_compressed_format(ibuf, &compressed_format)) { | if (!IMB_gpu_get_compressed_format(ibuf, &compressed_format)) { | ||||
| fprintf(stderr, "Unable to find a suitable DXT compression,"); | fprintf(stderr, "Unable to find a suitable DXT compression,"); | ||||
| } | } | ||||
| Show All 24 Lines | #endif | ||||
| eGPUDataFormat data_format; | eGPUDataFormat data_format; | ||||
| eGPUTextureFormat tex_format; | eGPUTextureFormat tex_format; | ||||
| imb_gpu_get_format(ibuf, use_high_bitdepth, &data_format, &tex_format); | imb_gpu_get_format(ibuf, use_high_bitdepth, &data_format, &tex_format); | ||||
| const bool compress_as_srgb = (tex_format == GPU_SRGB8_A8); | const bool compress_as_srgb = (tex_format == GPU_SRGB8_A8); | ||||
| bool freebuf = false; | bool freebuf = false; | ||||
| void *data = imb_gpu_get_data(ibuf, do_rescale, size, compress_as_srgb, use_premult, &freebuf); | |||||
| /* Create Texture. */ | /* Create Texture. */ | ||||
| tex = GPU_texture_create_2d(name, UNPACK2(size), 9999, tex_format, NULL); | tex = GPU_texture_create_2d(name, UNPACK2(size), 9999, tex_format, NULL); | ||||
| if (tex == NULL) { | |||||
| size[0] = max_ii(1, size[0] / 2); | |||||
| size[1] = max_ii(1, size[1] / 2); | |||||
| tex = GPU_texture_create_2d(name, UNPACK2(size), 9999, tex_format, NULL); | |||||
| do_rescale = true; | |||||
| } | |||||
| BLI_assert(tex != NULL); | |||||
| void *data = imb_gpu_get_data(ibuf, do_rescale, size, compress_as_srgb, use_premult, &freebuf); | |||||
| GPU_texture_update(tex, data_format, data); | GPU_texture_update(tex, data_format, data); | ||||
| GPU_texture_anisotropic_filter(tex, true); | GPU_texture_anisotropic_filter(tex, true); | ||||
| if (freebuf) { | if (freebuf) { | ||||
| MEM_freeN(data); | MEM_freeN(data); | ||||
| } | } | ||||
| return tex; | return tex; | ||||
| } | } | ||||