From ab95cdaba970a30127d804bd1e66ad25ab021ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 5 Sep 2020 17:33:56 +0200 Subject: GPUTexture: Change texture creation API This is to modernize the API: - Add meaningful name to all textures (except DRW textures). - Remove unused err_out argument: only used for offscreen python. - Add mipmap count to creation functions for future changes. - Clarify the data usage in creation functions. This is a cleanup commit, there is no functional change. # Conflicts: # source/blender/gpu/GPU_texture.h --- source/blender/blenfont/intern/blf_glyph.c | 2 +- source/blender/blenkernel/intern/image_gpu.c | 7 +- source/blender/blenkernel/intern/movieclip.c | 2 +- source/blender/blenkernel/intern/studiolight.c | 6 +- .../blender/draw/engines/eevee/eevee_lightcache.c | 22 +- .../blender/draw/engines/eevee/eevee_motion_blur.c | 2 +- .../draw/engines/gpencil/gpencil_antialiasing.c | 5 +- source/blender/draw/engines/select/select_engine.c | 3 +- .../workbench/workbench_effect_antialiasing.c | 4 +- .../draw/engines/workbench/workbench_render.c | 4 +- .../draw/engines/workbench/workbench_volume.c | 6 +- source/blender/draw/intern/draw_cache_impl_hair.c | 10 +- .../draw/intern/draw_cache_impl_particles.c | 14 +- .../blender/draw/intern/draw_cache_impl_volume.c | 9 +- source/blender/draw/intern/draw_common.c | 5 +- source/blender/draw/intern/draw_fluid.c | 10 +- source/blender/draw/intern/draw_hair.c | 2 +- source/blender/draw/intern/draw_manager.c | 2 +- source/blender/draw/intern/draw_manager_texture.c | 18 +- source/blender/editors/interface/interface_icons.c | 12 +- source/blender/editors/screen/glutil.c | 2 +- source/blender/editors/sculpt_paint/paint_cursor.c | 6 +- source/blender/editors/space_clip/clip_draw.c | 3 +- .../editors/space_sequencer/sequencer_draw.c | 3 +- source/blender/gpu/GPU_texture.h | 66 ++---- source/blender/gpu/intern/gpu_extensions.cc | 2 +- source/blender/gpu/intern/gpu_framebuffer.cc | 5 +- source/blender/gpu/intern/gpu_material.c | 5 +- source/blender/gpu/intern/gpu_texture.cc | 261 +++++++-------------- source/blender/gpu/intern/gpu_texture_private.hh | 79 +++++++ source/blender/gpu/intern/gpu_viewport.c | 19 +- source/blender/imbuf/IMB_imbuf.h | 5 +- source/blender/imbuf/intern/util_gpu.c | 22 +- source/blender/windowmanager/intern/wm_operators.c | 3 +- 34 files changed, 313 insertions(+), 313 deletions(-) (limited to 'source') diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index b06037cf6ec..773d3409905 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -508,7 +508,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl if (gc->texture) { GPU_texture_free(gc->texture); } - gc->texture = GPU_texture_create_1d_array(w, h, GPU_R8, false, NULL); + gc->texture = GPU_texture_create_1d_array(__func__, w, h, 1, GPU_R8, NULL); gc->bitmap_len_landed = 0; } diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c index 0a6015a3933..183129bf9b6 100644 --- a/source/blender/blenkernel/intern/image_gpu.c +++ b/source/blender/blenkernel/intern/image_gpu.c @@ -95,7 +95,7 @@ static GPUTexture *gpu_texture_create_tile_mapping(Image *ima, const int multivi tile_info[3] = tile->runtime.tilearray_size[1] / array_h; } - GPUTexture *tex = GPU_texture_create_1d_array(width, 2, GPU_RGBA32F, data, NULL); + GPUTexture *tex = GPU_texture_create_1d_array(ima->id.name + 2, width, 2, 1, GPU_RGBA32F, data); GPU_texture_mipmap_mode(tex, false, false); MEM_freeN(data); @@ -180,7 +180,7 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH); /* Create Texture without content. */ GPUTexture *tex = IMB_touch_gpu_texture( - main_ibuf, arraywidth, arrayheight, arraylayers, use_high_bitdepth); + ima->id.name + 2, main_ibuf, arraywidth, arrayheight, arraylayers, use_high_bitdepth); /* Upload each tile one by one. */ LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { @@ -316,7 +316,8 @@ static GPUTexture *image_get_gpu_texture(Image *ima, (ima ? (ima->alpha_mode != IMA_ALPHA_STRAIGHT) : false) : (ima ? (ima->alpha_mode == IMA_ALPHA_PREMUL) : true); - *tex = IMB_create_gpu_texture(ibuf_intern, use_high_bitdepth, store_premultiplied); + *tex = IMB_create_gpu_texture( + ima->id.name + 2, ibuf_intern, use_high_bitdepth, store_premultiplied); if (GPU_mipmap_enabled()) { GPU_texture_generate_mipmap(*tex); diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 55e43a2b8ed..3865407b0a7 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -1924,7 +1924,7 @@ GPUTexture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser) /* This only means RGBA16F instead of RGBA32F. */ const bool high_bitdepth = false; const bool store_premultiplied = ibuf->rect_float ? false : true; - *tex = IMB_create_gpu_texture(ibuf, high_bitdepth, store_premultiplied); + *tex = IMB_create_gpu_texture(clip->id.name + 2, ibuf, high_bitdepth, store_premultiplied); /* Do not generate mips for movieclips... too slow. */ GPU_texture_mipmap_mode(*tex, false, true); diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c index e08d301e5a6..95186d2311a 100644 --- a/source/blender/blenkernel/intern/studiolight.c +++ b/source/blender/blenkernel/intern/studiolight.c @@ -500,7 +500,7 @@ static void studiolight_create_equirect_radiance_gputexture(StudioLight *sl) ImBuf *ibuf = sl->equirect_radiance_buffer; sl->equirect_radiance_gputexture = GPU_texture_create_2d( - ibuf->x, ibuf->y, GPU_RGBA16F, ibuf->rect_float, NULL); + "studiolight_radiance", ibuf->x, ibuf->y, 1, GPU_RGBA16F, ibuf->rect_float); GPUTexture *tex = sl->equirect_radiance_gputexture; GPU_texture_filter_mode(tex, true); GPU_texture_wrap_mode(tex, true, true); @@ -520,7 +520,7 @@ static void studiolight_create_matcap_gputexture(StudioLightImage *sli) copy_v3_v3(*offset3, *offset4); } - sli->gputexture = GPU_texture_create_2d(ibuf->x, ibuf->y, GPU_R11F_G11F_B10F, NULL, NULL); + sli->gputexture = GPU_texture_create_2d("matcap", ibuf->x, ibuf->y, 1, GPU_R11F_G11F_B10F, NULL); GPU_texture_update(sli->gputexture, GPU_DATA_FLOAT, gpu_matcap_3components); MEM_SAFE_FREE(gpu_matcap_3components); @@ -555,7 +555,7 @@ static void studiolight_create_equirect_irradiance_gputexture(StudioLight *sl) BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECT_IRRADIANCE_IMAGE_CALCULATED); ImBuf *ibuf = sl->equirect_irradiance_buffer; sl->equirect_irradiance_gputexture = GPU_texture_create_2d( - ibuf->x, ibuf->y, GPU_RGBA16F, ibuf->rect_float, NULL); + "studiolight_irradiance", ibuf->x, ibuf->y, 1, GPU_RGBA16F, ibuf->rect_float); GPUTexture *tex = sl->equirect_irradiance_gputexture; GPU_texture_filter_mode(tex, true); GPU_texture_wrap_mode(tex, true, true); diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c index 2d846ccd1d6..49d68481045 100644 --- a/source/blender/draw/engines/eevee/eevee_lightcache.c +++ b/source/blender/draw/engines/eevee/eevee_lightcache.c @@ -402,7 +402,7 @@ static bool eevee_lightcache_static_load(LightCache *lcache) if (lcache->grid_tx.tex == NULL) { lcache->grid_tx.tex = GPU_texture_create_2d_array( - UNPACK3(lcache->grid_tx.tex_size), IRRADIANCE_FORMAT, NULL, NULL); + "lightcache_irradiance", UNPACK3(lcache->grid_tx.tex_size), 1, IRRADIANCE_FORMAT, NULL); GPU_texture_update(lcache->grid_tx.tex, GPU_DATA_UNSIGNED_BYTE, lcache->grid_tx.data); if (lcache->grid_tx.tex == NULL) { @@ -415,17 +415,19 @@ static bool eevee_lightcache_static_load(LightCache *lcache) if (lcache->cube_tx.tex == NULL) { if (GPU_arb_texture_cube_map_array_is_supported()) { - lcache->cube_tx.tex = GPU_texture_create_cube_array(lcache->cube_tx.tex_size[0], + lcache->cube_tx.tex = GPU_texture_create_cube_array("lightcache_cubemaps", + lcache->cube_tx.tex_size[0], lcache->cube_tx.tex_size[2] / 6, + lcache->mips_len + 1, GPU_R11F_G11F_B10F, - NULL, NULL); - GPU_texture_update(lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, lcache->cube_tx.data); } else { - lcache->cube_tx.tex = GPU_texture_create_2d_array( - UNPACK3(lcache->cube_tx.tex_size), GPU_R11F_G11F_B10F, NULL, NULL); - GPU_texture_update(lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, lcache->cube_tx.data); + lcache->cube_tx.tex = GPU_texture_create_2d_array("lightcache_cubemaps_fallback", + UNPACK3(lcache->cube_tx.tex_size), + lcache->mips_len + 1, + GPU_R11F_G11F_B10F, + NULL); } if (lcache->cube_tx.tex == NULL) { @@ -433,9 +435,9 @@ static bool eevee_lightcache_static_load(LightCache *lcache) return false; } - for (int mip = 0; mip < lcache->mips_len; mip++) { - GPU_texture_add_mipmap( - lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, mip + 1, lcache->cube_mips[mip].data); + for (int mip = 0; mip <= lcache->mips_len; mip++) { + const void *data = (mip == 0) ? lcache->cube_tx.data : lcache->cube_mips[mip - 1].data; + GPU_texture_update_mipmap(lcache->cube_tx.tex, mip, GPU_DATA_10_11_11_REV, data); } GPU_texture_mipmap_mode(lcache->cube_tx.tex, true, true); } diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.c b/source/blender/draw/engines/eevee/eevee_motion_blur.c index f10a3f42077..e10c627494a 100644 --- a/source/blender/draw/engines/eevee/eevee_motion_blur.c +++ b/source/blender/draw/engines/eevee/eevee_motion_blur.c @@ -468,7 +468,7 @@ void EEVEE_motion_blur_cache_finish(EEVEE_Data *vedata) GPU_vertbuf_use(mb_hair->psys[i].hair_pos[mb_step]); mb_hair->psys[i].hair_pos_tx[mb_step] = GPU_texture_create_from_vertbuf( - mb_hair->psys[i].hair_pos[mb_step]); + "hair_pos_motion_blur", mb_hair->psys[i].hair_pos[mb_step]); } } break; diff --git a/source/blender/draw/engines/gpencil/gpencil_antialiasing.c b/source/blender/draw/engines/gpencil/gpencil_antialiasing.c index ac96a599eb6..511f09db247 100644 --- a/source/blender/draw/engines/gpencil/gpencil_antialiasing.c +++ b/source/blender/draw/engines/gpencil/gpencil_antialiasing.c @@ -57,10 +57,11 @@ void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata) if (txl->smaa_search_tx == NULL) { txl->smaa_search_tx = GPU_texture_create_2d( - SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, GPU_R8, NULL, NULL); + "smaa_search", SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, 1, GPU_R8, NULL); GPU_texture_update(txl->smaa_search_tx, GPU_DATA_UNSIGNED_BYTE, searchTexBytes); - txl->smaa_area_tx = GPU_texture_create_2d(AREATEX_WIDTH, AREATEX_HEIGHT, GPU_RG8, NULL, NULL); + txl->smaa_area_tx = GPU_texture_create_2d( + "smaa_area", AREATEX_WIDTH, AREATEX_HEIGHT, 1, GPU_RG8, NULL); GPU_texture_update(txl->smaa_area_tx, GPU_DATA_UNSIGNED_BYTE, areaTexBytes); GPU_texture_filter_mode(txl->smaa_search_tx, true); diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c index 0ce8937687a..ec6e4c73043 100644 --- a/source/blender/draw/engines/select/select_engine.c +++ b/source/blender/draw/engines/select/select_engine.c @@ -79,7 +79,8 @@ static void select_engine_framebuffer_setup(void) GPU_framebuffer_texture_attach(e_data.framebuffer_select_id, dtxl->depth, 0, 0); if (e_data.texture_u32 == NULL) { - e_data.texture_u32 = GPU_texture_create_2d(size[0], size[1], GPU_R32UI, NULL, NULL); + e_data.texture_u32 = GPU_texture_create_2d( + "select_buf_ids", size[0], size[1], 1, GPU_R32UI, NULL); GPU_framebuffer_texture_attach(e_data.framebuffer_select_id, e_data.texture_u32, 0, 0); GPU_framebuffer_check_valid(e_data.framebuffer_select_id, NULL); diff --git a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c index 9d5ff47fc82..20c30d9ce68 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c +++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.c @@ -243,11 +243,11 @@ void workbench_antialiasing_engine_init(WORKBENCH_Data *vedata) /* TODO could be shared for all viewports. */ if (txl->smaa_search_tx == NULL) { txl->smaa_search_tx = GPU_texture_create_2d( - SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, GPU_R8, NULL, NULL); + "smaa_search", SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, 1, GPU_R8, NULL); GPU_texture_update(txl->smaa_search_tx, GPU_DATA_UNSIGNED_BYTE, searchTexBytes); txl->smaa_area_tx = GPU_texture_create_2d( - AREATEX_WIDTH, AREATEX_HEIGHT, GPU_RG8, NULL, NULL); + "smaa_area", AREATEX_WIDTH, AREATEX_HEIGHT, 1, GPU_RG8, NULL); GPU_texture_update(txl->smaa_area_tx, GPU_DATA_UNSIGNED_BYTE, areaTexBytes); GPU_texture_filter_mode(txl->smaa_search_tx, true); diff --git a/source/blender/draw/engines/workbench/workbench_render.c b/source/blender/draw/engines/workbench/workbench_render.c index 77e16327a43..8760f2651ee 100644 --- a/source/blender/draw/engines/workbench/workbench_render.c +++ b/source/blender/draw/engines/workbench/workbench_render.c @@ -79,8 +79,8 @@ static bool workbench_render_framebuffers_init(void) * the other views will reuse these buffers */ if (dtxl->color == NULL) { BLI_assert(dtxl->depth == NULL); - dtxl->color = GPU_texture_create_2d(size[0], size[1], GPU_RGBA16F, NULL, NULL); - dtxl->depth = GPU_texture_create_2d(size[0], size[1], GPU_DEPTH24_STENCIL8, NULL, NULL); + dtxl->color = GPU_texture_create_2d("txl.color", UNPACK2(size), 1, GPU_RGBA16F, NULL); + dtxl->depth = GPU_texture_create_2d("txl.depth", UNPACK2(size), 1, GPU_DEPTH24_STENCIL8, NULL); } if (!(dtxl->depth && dtxl->color)) { diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c index f71e77d5da5..7aa089d440f 100644 --- a/source/blender/draw/engines/workbench/workbench_volume.c +++ b/source/blender/draw/engines/workbench/workbench_volume.c @@ -45,9 +45,9 @@ void workbench_volume_engine_init(WORKBENCH_Data *vedata) if (txl->dummy_volume_tx == NULL) { const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; const float one[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - txl->dummy_volume_tx = GPU_texture_create_3d(1, 1, 1, GPU_RGBA8, zero, NULL); - txl->dummy_shadow_tx = GPU_texture_create_3d(1, 1, 1, GPU_RGBA8, one, NULL); - txl->dummy_coba_tx = GPU_texture_create_1d(1, GPU_RGBA8, zero, NULL); + txl->dummy_volume_tx = GPU_texture_create_3d("dummy_volume", 1, 1, 1, 1, GPU_RGBA8, zero); + txl->dummy_shadow_tx = GPU_texture_create_3d("dummy_shadow", 1, 1, 1, 1, GPU_RGBA8, one); + txl->dummy_coba_tx = GPU_texture_create_1d("dummy_coba", 1, 1, GPU_RGBA8, zero); } } diff --git a/source/blender/draw/intern/draw_cache_impl_hair.c b/source/blender/draw/intern/draw_cache_impl_hair.c index 007f6258184..327a92a997e 100644 --- a/source/blender/draw/intern/draw_cache_impl_hair.c +++ b/source/blender/draw/intern/draw_cache_impl_hair.c @@ -192,7 +192,7 @@ static void hair_batch_cache_ensure_procedural_pos(Hair *hair, ParticleHairCache /* Create vbo immediately to bind to texture buffer. */ GPU_vertbuf_use(cache->proc_point_buf); - cache->point_tex = GPU_texture_create_from_vertbuf(cache->proc_point_buf); + cache->point_tex = GPU_texture_create_from_vertbuf("hair_point", cache->proc_point_buf); } static void hair_batch_cache_fill_strands_data(Hair *hair, @@ -230,10 +230,11 @@ static void hair_batch_cache_ensure_procedural_strand_data(Hair *hair, ParticleH /* Create vbo immediately to bind to texture buffer. */ GPU_vertbuf_use(cache->proc_strand_buf); - cache->strand_tex = GPU_texture_create_from_vertbuf(cache->proc_strand_buf); + cache->strand_tex = GPU_texture_create_from_vertbuf("hair_strand", cache->proc_strand_buf); GPU_vertbuf_use(cache->proc_strand_seg_buf); - cache->strand_seg_tex = GPU_texture_create_from_vertbuf(cache->proc_strand_seg_buf); + cache->strand_seg_tex = GPU_texture_create_from_vertbuf("hair_strand_seg", + cache->proc_strand_seg_buf); } static void hair_batch_cache_ensure_procedural_final_points(ParticleHairCache *cache, int subdiv) @@ -252,7 +253,8 @@ static void hair_batch_cache_ensure_procedural_final_points(ParticleHairCache *c /* Create vbo immediately to bind to texture buffer. */ GPU_vertbuf_use(cache->final[subdiv].proc_buf); - cache->final[subdiv].proc_tex = GPU_texture_create_from_vertbuf(cache->final[subdiv].proc_buf); + cache->final[subdiv].proc_tex = GPU_texture_create_from_vertbuf("hair_proc", + cache->final[subdiv].proc_buf); } static void hair_batch_cache_fill_segments_indices(Hair *hair, diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c index 3ecdbff1e96..52d1fcfdb80 100644 --- a/source/blender/draw/intern/draw_cache_impl_particles.c +++ b/source/blender/draw/intern/draw_cache_impl_particles.c @@ -809,7 +809,8 @@ static void particle_batch_cache_ensure_procedural_final_points(ParticleHairCach /* Create vbo immediately to bind to texture buffer. */ GPU_vertbuf_use(cache->final[subdiv].proc_buf); - cache->final[subdiv].proc_tex = GPU_texture_create_from_vertbuf(cache->final[subdiv].proc_buf); + cache->final[subdiv].proc_tex = GPU_texture_create_from_vertbuf("part_proc", + cache->final[subdiv].proc_buf); } static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit, @@ -1008,18 +1009,19 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit /* Create vbo immediately to bind to texture buffer. */ GPU_vertbuf_use(cache->proc_strand_buf); - cache->strand_tex = GPU_texture_create_from_vertbuf(cache->proc_strand_buf); + cache->strand_tex = GPU_texture_create_from_vertbuf("part_strand", cache->proc_strand_buf); GPU_vertbuf_use(cache->proc_strand_seg_buf); - cache->strand_seg_tex = GPU_texture_create_from_vertbuf(cache->proc_strand_seg_buf); + cache->strand_seg_tex = GPU_texture_create_from_vertbuf("part_strand_seg", + cache->proc_strand_seg_buf); for (int i = 0; i < cache->num_uv_layers; i++) { GPU_vertbuf_use(cache->proc_uv_buf[i]); - cache->uv_tex[i] = GPU_texture_create_from_vertbuf(cache->proc_uv_buf[i]); + cache->uv_tex[i] = GPU_texture_create_from_vertbuf("part_uv", cache->proc_uv_buf[i]); } for (int i = 0; i < cache->num_col_layers; i++) { GPU_vertbuf_use(cache->proc_col_buf[i]); - cache->col_tex[i] = GPU_texture_create_from_vertbuf(cache->proc_col_buf[i]); + cache->col_tex[i] = GPU_texture_create_from_vertbuf("part_col", cache->proc_col_buf[i]); } } @@ -1109,7 +1111,7 @@ static void particle_batch_cache_ensure_procedural_pos(PTCacheEdit *edit, /* Create vbo immediately to bind to texture buffer. */ GPU_vertbuf_use(cache->proc_point_buf); - cache->point_tex = GPU_texture_create_from_vertbuf(cache->proc_point_buf); + cache->point_tex = GPU_texture_create_from_vertbuf("part_point", cache->proc_point_buf); } static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit, diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c index a74e557cc29..3b9c127abc3 100644 --- a/source/blender/draw/intern/draw_cache_impl_volume.c +++ b/source/blender/draw/intern/draw_cache_impl_volume.c @@ -258,12 +258,9 @@ static DRWVolumeGrid *volume_grid_cache_get(Volume *volume, BKE_volume_grid_dense_voxels(volume, grid, dense_min, dense_max, voxels); /* Create GPU texture. */ - cache_grid->texture = GPU_texture_create_3d(resolution[0], - resolution[1], - resolution[2], - (channels == 3) ? GPU_RGB16F : GPU_R16F, - voxels, - NULL); + eGPUTextureFormat format = (channels == 3) ? GPU_RGB16F : GPU_R16F; + cache_grid->texture = GPU_texture_create_3d( + "volume_grid", UNPACK3(resolution), 1, format, voxels); GPU_texture_swizzle_set(cache_grid->texture, (channels == 3) ? "rgb1" : "rrr1"); GPU_texture_wrap_mode(cache_grid->texture, false, false); diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index f80b5bd71fd..ea5421f3965 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -238,7 +238,7 @@ void DRW_globals_update(void) BKE_colorband_evaluate_table_rgba(&ramp, &colors, &col_size); - G_draw.ramp = GPU_texture_create_1d(col_size, GPU_RGBA8, colors, NULL); + G_draw.ramp = GPU_texture_create_1d("ramp", col_size, 1, GPU_RGBA8, colors); MEM_freeN(colors); } @@ -503,12 +503,11 @@ static void DRW_evaluate_weight_to_color(const float weight, float result[4]) static GPUTexture *DRW_create_weight_colorramp_texture(void) { - char error[256]; float pixels[256][4]; for (int i = 0; i < 256; i++) { DRW_evaluate_weight_to_color(i / 255.0f, pixels[i]); pixels[i][3] = 1.0f; } - return GPU_texture_create_1d(256, GPU_SRGB8_A8, pixels[0], error); + return GPU_texture_create_1d("weight_color_ramp", 256, 1, GPU_SRGB8_A8, pixels[0]); } diff --git a/source/blender/draw/intern/draw_fluid.c b/source/blender/draw/intern/draw_fluid.c index 9b63b50db61..af14f11e6e9 100644 --- a/source/blender/draw/intern/draw_fluid.c +++ b/source/blender/draw/intern/draw_fluid.c @@ -117,7 +117,7 @@ static GPUTexture *create_transfer_function(int type, const struct ColorBand *co break; } - GPUTexture *tex = GPU_texture_create_1d(TFUNC_WIDTH, GPU_SRGB8_A8, data, NULL); + GPUTexture *tex = GPU_texture_create_1d("transf_func", TFUNC_WIDTH, 1, GPU_SRGB8_A8, data); MEM_freeN(data); @@ -184,7 +184,7 @@ static GPUTexture *create_volume_texture(const int dim[3], int final_dim[3] = {UNPACK3(dim)}; while (1) { - tex = GPU_texture_create_3d(UNPACK3(final_dim), format, NULL, NULL); + tex = GPU_texture_create_3d("volume", UNPACK3(final_dim), 1, format, NULL); if (tex != NULL) { break; @@ -462,9 +462,9 @@ void DRW_smoke_ensure_velocity(FluidModifierData *fmd) } if (!fds->tex_velocity_x) { - fds->tex_velocity_x = GPU_texture_create_3d(UNPACK3(fds->res), GPU_R16F, vel_x, NULL); - fds->tex_velocity_y = GPU_texture_create_3d(UNPACK3(fds->res), GPU_R16F, vel_y, NULL); - fds->tex_velocity_z = GPU_texture_create_3d(UNPACK3(fds->res), GPU_R16F, vel_z, NULL); + fds->tex_velocity_x = GPU_texture_create_3d("velx", UNPACK3(fds->res), 1, GPU_R16F, vel_x); + fds->tex_velocity_y = GPU_texture_create_3d("vely", UNPACK3(fds->res), 1, GPU_R16F, vel_y); + fds->tex_velocity_z = GPU_texture_create_3d("velz", UNPACK3(fds->res), 1, GPU_R16F, vel_z); } } #endif /* WITH_FLUID */ diff --git a/source/blender/draw/intern/draw_hair.c b/source/blender/draw/intern/draw_hair.c index 1992b1d291e..9b503e00b36 100644 --- a/source/blender/draw/intern/draw_hair.c +++ b/source/blender/draw/intern/draw_hair.c @@ -120,7 +120,7 @@ void DRW_hair_init(void) /* Create vbo immediately to bind to texture buffer. */ GPU_vertbuf_use(g_dummy_vbo); - g_dummy_texture = GPU_texture_create_from_vertbuf(g_dummy_vbo); + g_dummy_texture = GPU_texture_create_from_vertbuf("hair_dummy_attr", g_dummy_vbo); } } diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 6e0ce87b1b8..09ce16efcc2 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -1929,7 +1929,7 @@ static void draw_select_framebuffer_depth_only_setup(const int size[2]) if (g_select_buffer.texture_depth == NULL) { g_select_buffer.texture_depth = GPU_texture_create_2d( - size[0], size[1], GPU_DEPTH_COMPONENT24, NULL, NULL); + "select_depth", size[0], size[1], 1, GPU_DEPTH_COMPONENT24, NULL); GPU_framebuffer_texture_attach( g_select_buffer.framebuffer_depth_only, g_select_buffer.texture_depth, 0, 0); diff --git a/source/blender/draw/intern/draw_manager_texture.c b/source/blender/draw/intern/draw_manager_texture.c index 083d5224e16..8562a5ba8fb 100644 --- a/source/blender/draw/intern/draw_manager_texture.c +++ b/source/blender/draw/intern/draw_manager_texture.c @@ -81,7 +81,8 @@ GPUTexture *DRW_texture_create_1d(int w, DRWTextureFlag flags, const float *fpixels) { - GPUTexture *tex = GPU_texture_create_1d(w, format, fpixels, NULL); + int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1; + GPUTexture *tex = GPU_texture_create_1d(__func__, w, mips, format, fpixels); drw_texture_set_parameters(tex, flags); return tex; @@ -90,7 +91,8 @@ GPUTexture *DRW_texture_create_1d(int w, GPUTexture *DRW_texture_create_2d( int w, int h, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels) { - GPUTexture *tex = GPU_texture_create_2d(w, h, format, fpixels, NULL); + int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1; + GPUTexture *tex = GPU_texture_create_2d(__func__, w, h, mips, format, fpixels); drw_texture_set_parameters(tex, flags); return tex; @@ -99,7 +101,8 @@ GPUTexture *DRW_texture_create_2d( GPUTexture *DRW_texture_create_2d_array( int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels) { - GPUTexture *tex = GPU_texture_create_2d_array(w, h, d, format, fpixels, NULL); + int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1; + GPUTexture *tex = GPU_texture_create_2d_array(__func__, w, h, d, mips, format, fpixels); drw_texture_set_parameters(tex, flags); return tex; @@ -108,7 +111,8 @@ GPUTexture *DRW_texture_create_2d_array( GPUTexture *DRW_texture_create_3d( int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels) { - GPUTexture *tex = GPU_texture_create_3d(w, h, d, format, fpixels, NULL); + int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1; + GPUTexture *tex = GPU_texture_create_3d(__func__, w, h, d, mips, format, fpixels); drw_texture_set_parameters(tex, flags); return tex; @@ -119,7 +123,8 @@ GPUTexture *DRW_texture_create_cube(int w, DRWTextureFlag flags, const float *fpixels) { - GPUTexture *tex = GPU_texture_create_cube(w, format, fpixels, NULL); + int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1; + GPUTexture *tex = GPU_texture_create_cube(__func__, w, mips, format, fpixels); drw_texture_set_parameters(tex, flags); return tex; } @@ -127,7 +132,8 @@ GPUTexture *DRW_texture_create_cube(int w, GPUTexture *DRW_texture_create_cube_array( int w, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels) { - GPUTexture *tex = GPU_texture_create_cube_array(w, d, format, fpixels, NULL); + int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1; + GPUTexture *tex = GPU_texture_create_cube_array(__func__, w, d, mips, format, fpixels); drw_texture_set_parameters(tex, flags); return tex; } diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 8801d2956bb..cadc2264bf4 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -866,16 +866,16 @@ void UI_icons_reload_internal_textures(void) icongltex.invw = 1.0f / b32buf->x; icongltex.invh = 1.0f / b32buf->y; - icongltex.tex[0] = GPU_texture_create_2d(b32buf->x, b32buf->y, GPU_RGBA8, NULL, NULL); - GPU_texture_add_mipmap(icongltex.tex[0], GPU_DATA_UNSIGNED_BYTE, 0, b32buf->rect); - GPU_texture_add_mipmap(icongltex.tex[0], GPU_DATA_UNSIGNED_BYTE, 1, b16buf->rect); + icongltex.tex[0] = GPU_texture_create_2d("icons", b32buf->x, b32buf->y, 2, GPU_RGBA8, NULL); + GPU_texture_update_mipmap(icongltex.tex[0], 0, GPU_DATA_UNSIGNED_BYTE, b32buf->rect); + GPU_texture_update_mipmap(icongltex.tex[0], 1, GPU_DATA_UNSIGNED_BYTE, b16buf->rect); } if (need_icons_with_border && icongltex.tex[1] == NULL) { icongltex.tex[1] = GPU_texture_create_2d( - b32buf_border->x, b32buf_border->y, GPU_RGBA8, NULL, NULL); - GPU_texture_add_mipmap(icongltex.tex[1], GPU_DATA_UNSIGNED_BYTE, 0, b32buf_border->rect); - GPU_texture_add_mipmap(icongltex.tex[1], GPU_DATA_UNSIGNED_BYTE, 1, b16buf_border->rect); + "icons_border", b32buf_border->x, b32buf_border->y, 2, GPU_RGBA8, NULL); + GPU_texture_update_mipmap(icongltex.tex[1], 0, GPU_DATA_UNSIGNED_BYTE, b32buf_border->rect); + GPU_texture_update_mipmap(icongltex.tex[1], 1, GPU_DATA_UNSIGNED_BYTE, b16buf_border->rect); } } diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index bcbb735d93d..33b918e6d4d 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -132,7 +132,7 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, eGPUDataFormat gpu_data = (use_float_data) ? GPU_DATA_FLOAT : GPU_DATA_UNSIGNED_BYTE; size_t stride = components * ((use_float_data) ? sizeof(float) : sizeof(uchar)); - GPUTexture *tex = GPU_texture_create_2d(tex_w, tex_h, gpu_format, NULL, NULL); + GPUTexture *tex = GPU_texture_create_2d("immDrawPixels", tex_w, tex_h, 1, gpu_format, NULL); GPU_texture_filter_mode(tex, use_filter); GPU_texture_wrap_mode(tex, false, true); diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 4d885364440..08733a26187 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -348,7 +348,8 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima if (!target->overlay_texture) { eGPUTextureFormat format = col ? GPU_RGBA8 : GPU_R8; - target->overlay_texture = GPU_texture_create_2d(size, size, format, NULL, NULL); + target->overlay_texture = GPU_texture_create_2d( + "paint_cursor_overlay", size, size, 1, format, NULL); GPU_texture_update(target->overlay_texture, GPU_DATA_UNSIGNED_BYTE, buffer); if (!col) { @@ -466,7 +467,8 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) BLI_task_parallel_range(0, size, &data, load_tex_cursor_task_cb, &settings); if (!cursor_snap.overlay_texture) { - cursor_snap.overlay_texture = GPU_texture_create_2d(size, size, GPU_R8, NULL, NULL); + cursor_snap.overlay_texture = GPU_texture_create_2d( + "cursor_snap_overaly", size, size, 1, GPU_R8, NULL); GPU_texture_update(cursor_snap.overlay_texture, GPU_DATA_UNSIGNED_BYTE, buffer); GPU_texture_swizzle_set(cursor_snap.overlay_texture, "rrrr"); diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 8fbf9fa2144..e12e4eb2231 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -1211,7 +1211,8 @@ static void draw_plane_marker_image(Scene *scene, GPU_blend(GPU_BLEND_ALPHA); } - GPUTexture *texture = GPU_texture_create_2d(ibuf->x, ibuf->y, GPU_RGBA8, NULL, NULL); + GPUTexture *texture = GPU_texture_create_2d( + "plane_marker_image", ibuf->x, ibuf->y, 1, GPU_RGBA8, NULL); GPU_texture_update(texture, GPU_DATA_UNSIGNED_BYTE, display_buffer); GPU_texture_filter_mode(texture, false); diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 9504ed88bb1..70735a8ec82 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1639,7 +1639,8 @@ static void sequencer_draw_display_buffer(const bContext *C, GPU_matrix_identity_projection_set(); } - GPUTexture *texture = GPU_texture_create_2d(ibuf->x, ibuf->y, format, NULL, NULL); + GPUTexture *texture = GPU_texture_create_2d( + "seq_display_buf", ibuf->x, ibuf->y, 1, format, NULL); GPU_texture_update(texture, data, display_buffer); GPU_texture_filter_mode(texture, false); diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index 9316b803f30..78a4c9d0ac9 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -183,54 +183,40 @@ typedef enum eGPUDataFormat { unsigned int GPU_texture_memory_usage_get(void); -/* TODO make it static function again. (create function with eGPUDataFormat exposed) */ -GPUTexture *GPU_texture_create_nD(int w, - int h, - int d, - int n, - const void *pixels, - eGPUTextureFormat tex_format, - eGPUDataFormat gpu_data_format, - int samples, - const bool can_rescale, - char err_out[256]); -GPUTexture *GPU_texture_cube_create(int w, - int d, - const void *pixels, - eGPUTextureFormat tex_format, - eGPUDataFormat gpu_data_format, - char err_out[256]); - -GPUTexture *GPU_texture_create_1d(int w, - eGPUTextureFormat tex_format, - const float *pixels, - char err_out[256]); +/** + * \note \a data is expected to be float. If the \a format is not compatible with float data or if + * the data is not in float format, use GPU_texture_update to upload the data with the right data + * format. + * \a mips is the number of mip level to allocate. It must be >= 1. + */ +GPUTexture *GPU_texture_create_1d( + const char *name, int w, int mips, eGPUTextureFormat format, const float *data); GPUTexture *GPU_texture_create_1d_array( - int w, int h, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]); + const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data); GPUTexture *GPU_texture_create_2d( - int w, int h, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]); + const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data); GPUTexture *GPU_texture_create_2d_array( - int w, int h, int d, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]); + const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data); GPUTexture *GPU_texture_create_3d( - int w, int h, int d, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]); -GPUTexture *GPU_texture_create_cube(int w, - eGPUTextureFormat tex_format, - const float *pixels, - char err_out[256]); + const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data); +GPUTexture *GPU_texture_create_cube( + const char *name, int w, int mips, eGPUTextureFormat format, const float *data); GPUTexture *GPU_texture_create_cube_array( - int w, int d, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]); - -GPUTexture *GPU_texture_create_from_vertbuf(struct GPUVertBuf *vert); - -GPUTexture *GPU_texture_create_compressed( - int w, int h, int miplen, eGPUTextureFormat format, const void *data); + const char *name, int w, int d, int mips, eGPUTextureFormat format, const float *data); +/* Special textures. */ +GPUTexture *GPU_texture_create_from_vertbuf(const char *name, struct GPUVertBuf *vert); +/** + * \a data should hold all the data for all mipmaps. + */ +GPUTexture *GPU_texture_create_compressed_2d( + const char *name, int w, int h, int miplen, eGPUTextureFormat format, const void *data); GPUTexture *GPU_texture_create_error(int dimension, bool array); -void GPU_texture_add_mipmap(GPUTexture *tex, - eGPUDataFormat gpu_data_format, - int miplvl, - const void *pixels); +void GPU_texture_update_mipmap(GPUTexture *tex, + int miplvl, + eGPUDataFormat gpu_data_format, + const void *pixels); void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *pixels); void GPU_texture_update_sub(GPUTexture *tex, diff --git a/source/blender/gpu/intern/gpu_extensions.cc b/source/blender/gpu/intern/gpu_extensions.cc index 7583d20c362..ac7748e6430 100644 --- a/source/blender/gpu/intern/gpu_extensions.cc +++ b/source/blender/gpu/intern/gpu_extensions.cc @@ -108,7 +108,7 @@ static void gpu_detect_mip_render_workaround(void) float *source_pix = (float *)MEM_callocN(sizeof(float[4][6]) * cube_size * cube_size, __func__); float clear_color[4] = {1.0f, 0.5f, 0.0f, 0.0f}; - GPUTexture *tex = GPU_texture_create_cube(cube_size, GPU_RGBA16F, source_pix, NULL); + GPUTexture *tex = GPU_texture_create_cube(__func__, cube_size, 2, GPU_RGBA16F, source_pix); MEM_freeN(source_pix); GPU_texture_bind(tex, 0); diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc index 7fb9d787125..a74f48d15ce 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.cc +++ b/source/blender/gpu/intern/gpu_framebuffer.cc @@ -577,13 +577,14 @@ GPUOffScreen *GPU_offscreen_create( width = max_ii(1, width); ofs->color = GPU_texture_create_2d( - width, height, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL, err_out); + "ofs_color", width, height, 1, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL); if (depth) { - ofs->depth = GPU_texture_create_2d(width, height, GPU_DEPTH24_STENCIL8, NULL, err_out); + ofs->depth = GPU_texture_create_2d("ofs_depth", width, height, 1, GPU_DEPTH24_STENCIL8, NULL); } if ((depth && !ofs->depth) || !ofs->color) { + BLI_snprintf(err_out, 256, "GPUTexture: Texture allocation failed."); GPU_offscreen_free(ofs); return NULL; } diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 1016e766140..0bb9acf257f 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -157,7 +157,7 @@ static void gpu_material_ramp_texture_build(GPUMaterial *mat) GPUColorBandBuilder *builder = mat->coba_builder; mat->coba_tex = GPU_texture_create_1d_array( - CM_TABLE + 1, builder->current_layer, GPU_RGBA16F, (float *)builder->pixels, NULL); + "mat_ramp", CM_TABLE + 1, builder->current_layer, 1, GPU_RGBA16F, (float *)builder->pixels); MEM_freeN(builder); mat->coba_builder = NULL; @@ -546,7 +546,8 @@ struct GPUUniformBuf *GPU_material_sss_profile_get(GPUMaterial *material, GPU_texture_free(material->sss_tex_profile); } - material->sss_tex_profile = GPU_texture_create_1d(64, GPU_RGBA16F, translucence_profile, NULL); + material->sss_tex_profile = GPU_texture_create_1d( + "sss_tex_profile", 64, 1, GPU_RGBA16F, translucence_profile); MEM_freeN(translucence_profile); diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc index f3d1d4fdb42..914aa8617a9 100644 --- a/source/blender/gpu/intern/gpu_texture.cc +++ b/source/blender/gpu/intern/gpu_texture.cc @@ -181,7 +181,7 @@ void Texture::update(eGPUDataFormat format, const void *data) using namespace blender; using namespace blender::gpu; -/* ------ Memory Management ------- */ +/* ------ Memory Management ------ */ uint GPU_texture_memory_usage_get(void) { @@ -189,31 +189,35 @@ uint GPU_texture_memory_usage_get(void) return 0; } -/* -------------------------------- */ +/* ------ Texture Creation ------ */ -GPUTexture *GPU_texture_create_nD(int w, - int h, - int d, - int n, - const void *pixels, - eGPUTextureFormat tex_format, - eGPUDataFormat data_format, - int UNUSED(samples), - const bool UNUSED(can_rescale), - char UNUSED(err_out[256])) +static inline GPUTexture *gpu_texture_create(const char *name, + const int w, + const int h, + const int d, + const eGPUTextureType type, + int UNUSED(mips), + eGPUTextureFormat tex_format, + const float *fpixels) { - Texture *tex = GPUBackend::get()->texture_alloc("nD"); + Texture *tex = GPUBackend::get()->texture_alloc(name); bool success = false; - switch (n) { - case 1: + switch (type) { + case GPU_TEXTURE_1D: + case GPU_TEXTURE_1D_ARRAY: success = tex->init_1D(w, h, tex_format); break; - case 2: + case GPU_TEXTURE_2D: + case GPU_TEXTURE_2D_ARRAY: success = tex->init_2D(w, h, d, tex_format); break; - case 3: + case GPU_TEXTURE_3D: success = tex->init_3D(w, h, d, tex_format); break; + case GPU_TEXTURE_CUBE: + case GPU_TEXTURE_CUBE_ARRAY: + success = tex->init_cubemap(w, d, tex_format); + break; default: break; } @@ -222,37 +226,59 @@ GPUTexture *GPU_texture_create_nD(int w, delete tex; return NULL; } - if (pixels) { - tex->update(data_format, pixels); + if (fpixels) { + tex->update(GPU_DATA_FLOAT, fpixels); } return reinterpret_cast(tex); } -GPUTexture *GPU_texture_cube_create(int w, - int d, - const void *pixels, - eGPUTextureFormat tex_format, - eGPUDataFormat data_format, - char UNUSED(err_out[256])) +GPUTexture *GPU_texture_create_1d( + const char *name, int w, int mips, eGPUTextureFormat format, const float *data) { - Texture *tex = GPUBackend::get()->texture_alloc("Cube"); - bool success = tex->init_cubemap(w, d, tex_format); + return gpu_texture_create(name, w, 0, 0, GPU_TEXTURE_1D, mips, format, data); +} - if (!success) { - delete tex; - return NULL; - } - if (pixels) { - tex->update(data_format, pixels); - } - return reinterpret_cast(tex); +GPUTexture *GPU_texture_create_1d_array( + const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data) +{ + return gpu_texture_create(name, w, h, 0, GPU_TEXTURE_1D_ARRAY, mips, format, data); +} + +GPUTexture *GPU_texture_create_2d( + const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data) +{ + return gpu_texture_create(name, w, h, 0, GPU_TEXTURE_2D, mips, format, data); +} + +GPUTexture *GPU_texture_create_2d_array( + const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data) +{ + return gpu_texture_create(name, w, h, d, GPU_TEXTURE_2D_ARRAY, mips, format, data); +} + +GPUTexture *GPU_texture_create_3d( + const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data) +{ + return gpu_texture_create(name, w, h, d, GPU_TEXTURE_3D, mips, format, data); +} + +GPUTexture *GPU_texture_create_cube( + const char *name, int w, int mips, eGPUTextureFormat format, const float *data) +{ + return gpu_texture_create(name, w, w, 0, GPU_TEXTURE_CUBE, mips, format, data); +} + +GPUTexture *GPU_texture_create_cube_array( + const char *name, int w, int d, int mips, eGPUTextureFormat format, const float *data) +{ + return gpu_texture_create(name, w, w, d, GPU_TEXTURE_CUBE_ARRAY, mips, format, data); } /* DDS texture loading. Return NULL if support is not available. */ -GPUTexture *GPU_texture_create_compressed( - int w, int h, int miplen, eGPUTextureFormat tex_format, const void *data) +GPUTexture *GPU_texture_create_compressed_2d( + const char *name, int w, int h, int miplen, eGPUTextureFormat tex_format, const void *data) { - Texture *tex = GPUBackend::get()->texture_alloc("Cube"); + Texture *tex = GPUBackend::get()->texture_alloc(name); bool success = tex->init_2D(w, h, 0, tex_format); if (!success) { @@ -274,100 +300,10 @@ GPUTexture *GPU_texture_create_compressed( return reinterpret_cast(tex); } -/* Create an error texture that will bind an invalid texture (pink) at draw time. */ -GPUTexture *GPU_texture_create_error(int dimension, bool is_array) -{ - float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f}; - int w = 1; - int h = (dimension < 2 && !is_array) ? 0 : 1; - int d = (dimension < 3 && !is_array) ? 0 : 1; - - fprintf(stderr, "GPUTexture: Blender Texture Not Loaded!"); - return GPU_texture_create_nD( - w, h, d, dimension, pixel, GPU_RGBA8, GPU_DATA_FLOAT, 0, false, NULL); -} - -static inline eGPUTextureFormat to_texture_format(const GPUVertFormat *format) -{ - if (format->attr_len > 1 || format->attr_len == 0) { - BLI_assert(!"Incorrect vertex format for buffer texture"); - return GPU_DEPTH_COMPONENT24; - } - switch (format->attrs[0].comp_len) { - case 1: - switch (format->attrs[0].comp_type) { - case GPU_COMP_I8: - return GPU_R8I; - case GPU_COMP_U8: - return GPU_R8UI; - case GPU_COMP_I16: - return GPU_R16I; - case GPU_COMP_U16: - return GPU_R16UI; - case GPU_COMP_I32: - return GPU_R32I; - case GPU_COMP_U32: - return GPU_R32UI; - case GPU_COMP_F32: - return GPU_R32F; - default: - break; - } - break; - case 2: - switch (format->attrs[0].comp_type) { - case GPU_COMP_I8: - return GPU_RG8I; - case GPU_COMP_U8: - return GPU_RG8UI; - case GPU_COMP_I16: - return GPU_RG16I; - case GPU_COMP_U16: - return GPU_RG16UI; - case GPU_COMP_I32: - return GPU_RG32I; - case GPU_COMP_U32: - return GPU_RG32UI; - case GPU_COMP_F32: - return GPU_RG32F; - default: - break; - } - break; - case 3: - /* Not supported until GL 4.0 */ - break; - case 4: - switch (format->attrs[0].comp_type) { - case GPU_COMP_I8: - return GPU_RGBA8I; - case GPU_COMP_U8: - return GPU_RGBA8UI; - case GPU_COMP_I16: - return GPU_RGBA16I; - case GPU_COMP_U16: - return GPU_RGBA16UI; - case GPU_COMP_I32: - return GPU_RGBA32I; - case GPU_COMP_U32: - return GPU_RGBA32UI; - case GPU_COMP_F32: - return GPU_RGBA32F; - default: - break; - } - break; - default: - break; - } - BLI_assert(!"Unsupported vertex format for buffer texture"); - return GPU_DEPTH_COMPONENT24; -} - -GPUTexture *GPU_texture_create_from_vertbuf(GPUVertBuf *vert) +GPUTexture *GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert) { eGPUTextureFormat tex_format = to_texture_format(&vert->format); - Texture *tex = GPUBackend::get()->texture_alloc("Cube"); + Texture *tex = GPUBackend::get()->texture_alloc(name); bool success = tex->init_buffer(vert, tex_format); if (!success) { @@ -377,56 +313,26 @@ GPUTexture *GPU_texture_create_from_vertbuf(GPUVertBuf *vert) return reinterpret_cast(tex); } -GPUTexture *GPU_texture_create_1d(int w, - eGPUTextureFormat format, - const float *pixels, - char out[256]) -{ - return GPU_texture_create_nD(w, 0, 0, 1, pixels, format, GPU_DATA_FLOAT, 0, false, out); -} - -GPUTexture *GPU_texture_create_1d_array( - int w, int h, eGPUTextureFormat format, const float *pixels, char out[256]) -{ - return GPU_texture_create_nD(w, h, 0, 1, pixels, format, GPU_DATA_FLOAT, 0, false, out); -} - -GPUTexture *GPU_texture_create_2d( - int w, int h, eGPUTextureFormat format, const float *pixels, char out[256]) -{ - return GPU_texture_create_nD(w, h, 0, 2, pixels, format, GPU_DATA_FLOAT, 0, false, out); -} - -GPUTexture *GPU_texture_create_2d_array( - int w, int h, int d, eGPUTextureFormat format, const float *pixels, char out[256]) -{ - return GPU_texture_create_nD(w, h, d, 2, pixels, format, GPU_DATA_FLOAT, 0, false, out); -} - -GPUTexture *GPU_texture_create_3d( - int w, int h, int d, eGPUTextureFormat format, const float *pixels, char out[256]) +/* Create an error texture that will bind an invalid texture (pink) at draw time. */ +GPUTexture *GPU_texture_create_error(int dimension, bool is_array) { - return GPU_texture_create_nD(w, h, d, 3, pixels, format, GPU_DATA_FLOAT, 0, true, out); -} + float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f}; + int w = 1; + int h = (dimension < 2 && !is_array) ? 0 : 1; + int d = (dimension < 3 && !is_array) ? 0 : 1; -GPUTexture *GPU_texture_create_cube(int w, - eGPUTextureFormat format, - const float *fpixels, - char out[256]) -{ - return GPU_texture_cube_create(w, 0, fpixels, format, GPU_DATA_FLOAT, out); -} + eGPUTextureType type = GPU_TEXTURE_3D; + type = (dimension == 2) ? (is_array ? GPU_TEXTURE_2D_ARRAY : GPU_TEXTURE_2D) : type; + type = (dimension == 1) ? (is_array ? GPU_TEXTURE_1D_ARRAY : GPU_TEXTURE_1D) : type; -GPUTexture *GPU_texture_create_cube_array( - int w, int d, eGPUTextureFormat format, const float *fpixels, char out[256]) -{ - return GPU_texture_cube_create(w, d, fpixels, format, GPU_DATA_FLOAT, out); + fprintf(stderr, "GPUTexture: Blender Texture Not Loaded!"); + return gpu_texture_create("invalid_tex", w, h, d, type, 1, GPU_RGBA8, pixel); } -void GPU_texture_add_mipmap(GPUTexture *tex_, - eGPUDataFormat gpu_data_format, - int miplvl, - const void *pixels) +void GPU_texture_update_mipmap(GPUTexture *tex_, + int miplvl, + eGPUDataFormat gpu_data_format, + const void *pixels) { Texture *tex = reinterpret_cast(tex_); int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0}; @@ -468,6 +374,7 @@ void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void * reinterpret_cast(tex)->clear(data_format, data); } +/* NOTE: Updates only mip 0. */ void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data) { reinterpret_cast(tex)->update(data_format, data); @@ -517,11 +424,7 @@ void GPU_texture_unbind_all(void) void GPU_texture_generate_mipmap(GPUTexture *tex) { - // gpu_texture_memory_footprint_remove(tex); - reinterpret_cast(tex)->generate_mipmap(); - - // gpu_texture_memory_footprint_add(tex); } /* Copy a texture content to a similar texture. Only Mip 0 is copied. */ diff --git a/source/blender/gpu/intern/gpu_texture_private.hh b/source/blender/gpu/intern/gpu_texture_private.hh index 207f3919a50..de639d0c435 100644 --- a/source/blender/gpu/intern/gpu_texture_private.hh +++ b/source/blender/gpu/intern/gpu_texture_private.hh @@ -25,6 +25,8 @@ #include "BLI_assert.h" +#include "GPU_vertex_buffer.h" + #include "gpu_framebuffer_private.hh" namespace blender { @@ -460,5 +462,82 @@ inline eGPUFrameBufferBits to_framebuffer_bits(eGPUTextureFormat tex_format) } } +static inline eGPUTextureFormat to_texture_format(const GPUVertFormat *format) +{ + if (format->attr_len > 1 || format->attr_len == 0) { + BLI_assert(!"Incorrect vertex format for buffer texture"); + return GPU_DEPTH_COMPONENT24; + } + switch (format->attrs[0].comp_len) { + case 1: + switch (format->attrs[0].comp_type) { + case GPU_COMP_I8: + return GPU_R8I; + case GPU_COMP_U8: + return GPU_R8UI; + case GPU_COMP_I16: + return GPU_R16I; + case GPU_COMP_U16: + return GPU_R16UI; + case GPU_COMP_I32: + return GPU_R32I; + case GPU_COMP_U32: + return GPU_R32UI; + case GPU_COMP_F32: + return GPU_R32F; + default: + break; + } + break; + case 2: + switch (format->attrs[0].comp_type) { + case GPU_COMP_I8: + return GPU_RG8I; + case GPU_COMP_U8: + return GPU_RG8UI; + case GPU_COMP_I16: + return GPU_RG16I; + case GPU_COMP_U16: + return GPU_RG16UI; + case GPU_COMP_I32: + return GPU_RG32I; + case GPU_COMP_U32: + return GPU_RG32UI; + case GPU_COMP_F32: + return GPU_RG32F; + default: + break; + } + break; + case 3: + /* Not supported until GL 4.0 */ + break; + case 4: + switch (format->attrs[0].comp_type) { + case GPU_COMP_I8: + return GPU_RGBA8I; + case GPU_COMP_U8: + return GPU_RGBA8UI; + case GPU_COMP_I16: + return GPU_RGBA16I; + case GPU_COMP_U16: + return GPU_RGBA16UI; + case GPU_COMP_I32: + return GPU_RGBA32I; + case GPU_COMP_U32: + return GPU_RGBA32UI; + case GPU_COMP_F32: + return GPU_RGBA32F; + default: + break; + } + break; + default: + break; + } + BLI_assert(!"Unsupported vertex format for buffer texture"); + return GPU_DEPTH_COMPONENT24; +} + } // namespace gpu } // namespace blender diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c index fd1265dc2a6..bc3c30ea1c8 100644 --- a/source/blender/gpu/intern/gpu_viewport.c +++ b/source/blender/gpu/intern/gpu_viewport.c @@ -380,7 +380,7 @@ GPUTexture *GPU_viewport_texture_pool_query( } } - tex = GPU_texture_create_2d(width, height, format, NULL, NULL); + tex = GPU_texture_create_2d("temp_from_pool", width, height, 1, format, NULL); /* Doing filtering for depth does not make sense when not doing shadow mapping, * and enabling texture filtering on integer texture make them unreadable. */ bool do_filter = !GPU_texture_depth(tex) && !GPU_texture_integer(tex); @@ -453,16 +453,21 @@ static void gpu_viewport_default_fb_create(GPUViewport *viewport) int *size = viewport->size; bool ok = true; - dtxl->color = GPU_texture_create_2d(size[0], size[1], GPU_RGBA16F, NULL, NULL); - dtxl->color_overlay = GPU_texture_create_2d(size[0], size[1], GPU_SRGB8_A8, NULL, NULL); - if (((viewport->flag & GPU_VIEWPORT_STEREO) != 0)) { - dtxl->color_stereo = GPU_texture_create_2d(size[0], size[1], GPU_RGBA16F, NULL, NULL); - dtxl->color_overlay_stereo = GPU_texture_create_2d(size[0], size[1], GPU_SRGB8_A8, NULL, NULL); + dtxl->color = GPU_texture_create_2d("dtxl_color", UNPACK2(size), 1, GPU_RGBA16F, NULL); + dtxl->color_overlay = GPU_texture_create_2d( + "dtxl_color_overlay", UNPACK2(size), 1, GPU_SRGB8_A8, NULL); + + if (viewport->flag & GPU_VIEWPORT_STEREO) { + dtxl->color_stereo = GPU_texture_create_2d( + "dtxl_color_stereo", UNPACK2(size), 1, GPU_RGBA16F, NULL); + dtxl->color_overlay_stereo = GPU_texture_create_2d( + "dtxl_color_overlay_stereo", UNPACK2(size), 1, GPU_SRGB8_A8, NULL); } /* Can be shared with GPUOffscreen. */ if (dtxl->depth == NULL) { - dtxl->depth = GPU_texture_create_2d(size[0], size[1], GPU_DEPTH24_STENCIL8, NULL, NULL); + dtxl->depth = GPU_texture_create_2d( + "dtxl_depth", UNPACK2(size), 1, GPU_DEPTH24_STENCIL8, NULL); } if (!dtxl->depth || !dtxl->color) { diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 8e243559a69..839b0b12b83 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -736,11 +736,12 @@ const char *IMB_ffmpeg_last_error(void); * * \attention defined in util_gpu.c */ -struct GPUTexture *IMB_create_gpu_texture(struct ImBuf *ibuf, +struct GPUTexture *IMB_create_gpu_texture(const char *name, + struct ImBuf *ibuf, bool use_high_bitdepth, bool use_premult); struct GPUTexture *IMB_touch_gpu_texture( - struct ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth); + const char *name, struct ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth); void IMB_update_gpu_texture_sub(struct GPUTexture *tex, struct ImBuf *ibuf, int x, diff --git a/source/blender/imbuf/intern/util_gpu.c b/source/blender/imbuf/intern/util_gpu.c index e538e8e1659..73532a1825e 100644 --- a/source/blender/imbuf/intern/util_gpu.c +++ b/source/blender/imbuf/intern/util_gpu.c @@ -159,7 +159,8 @@ static void *imb_gpu_get_data(const ImBuf *ibuf, /* The ibuf is only here to detect the storage type. The produced texture will have undefined * content. It will need to be populated by using IMB_update_gpu_texture_sub(). */ -GPUTexture *IMB_touch_gpu_texture(ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth) +GPUTexture *IMB_touch_gpu_texture( + const char *name, ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth) { eGPUDataFormat data_format; eGPUTextureFormat tex_format; @@ -167,10 +168,10 @@ GPUTexture *IMB_touch_gpu_texture(ImBuf *ibuf, int w, int h, int layers, bool us GPUTexture *tex; if (layers > 0) { - tex = GPU_texture_create_2d_array(w, h, layers, tex_format, NULL, NULL); + tex = GPU_texture_create_2d_array(name, w, h, layers, 1, tex_format, NULL); } else { - tex = GPU_texture_create_2d(w, h, tex_format, NULL, NULL); + tex = GPU_texture_create_2d(name, w, h, 9999, tex_format, NULL); } GPU_texture_anisotropic_filter(tex, true); @@ -210,7 +211,10 @@ void IMB_update_gpu_texture_sub(GPUTexture *tex, } } -GPUTexture *IMB_create_gpu_texture(ImBuf *ibuf, bool use_high_bitdepth, bool use_premult) +GPUTexture *IMB_create_gpu_texture(const char *name, + ImBuf *ibuf, + bool use_high_bitdepth, + bool use_premult) { GPUTexture *tex = NULL; const int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)}; @@ -229,8 +233,12 @@ GPUTexture *IMB_create_gpu_texture(ImBuf *ibuf, bool use_high_bitdepth, bool use fprintf(stderr, "Unable to load non-power-of-two DXT image resolution,"); } else { - tex = GPU_texture_create_compressed( - ibuf->x, ibuf->y, ibuf->dds_data.nummipmaps, compressed_format, ibuf->dds_data.data); + tex = GPU_texture_create_compressed_2d(name, + ibuf->x, + ibuf->y, + ibuf->dds_data.nummipmaps, + compressed_format, + ibuf->dds_data.data); if (tex != NULL) { return tex; @@ -253,7 +261,7 @@ GPUTexture *IMB_create_gpu_texture(ImBuf *ibuf, bool use_high_bitdepth, bool use void *data = imb_gpu_get_data(ibuf, do_rescale, size, compress_as_srgb, use_premult, &freebuf); /* Create Texture. */ - tex = GPU_texture_create_2d(UNPACK2(size), tex_format, NULL, NULL); + tex = GPU_texture_create_2d(name, UNPACK2(size), 9999, tex_format, NULL); GPU_texture_update(tex, data_format, data); GPU_texture_anisotropic_filter(tex, true); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index de4dffd6d07..98beae69672 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2217,7 +2217,8 @@ static void radial_control_set_tex(RadialControl *rc) rc->use_secondary_tex, !ELEM(rc->subtype, PROP_NONE, PROP_PIXEL, PROP_DISTANCE)))) { - rc->texture = GPU_texture_create_2d(ibuf->x, ibuf->y, GPU_R8, ibuf->rect_float, NULL); + rc->texture = GPU_texture_create_2d( + "radial_control", ibuf->x, ibuf->y, 1, GPU_R8, ibuf->rect_float); GPU_texture_filter_mode(rc->texture, true); GPU_texture_swizzle_set(rc->texture, "111r"); -- cgit v1.2.3