diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-09-05 18:33:56 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-09-05 18:49:14 +0300 |
commit | ab95cdaba970a30127d804bd1e66ad25ab021ec1 (patch) | |
tree | d0da883e11f81253cb7b3e5a75288ca69598e437 /source/blender/draw/intern | |
parent | bac4606937514405641659d91a30bf3e6832cdf7 (diff) |
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
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_hair.c | 10 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_particles.c | 14 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_volume.c | 9 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 5 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_fluid.c | 10 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_hair.c | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_texture.c | 18 |
8 files changed, 38 insertions, 32 deletions
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; } |