From f0254c2dcf7594bb87f4dc44ccc7c4f449aaa205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 22 Jul 2025 09:48:10 +0200 Subject: [PATCH] Refactor: GPU: Remove unnecessary C wrappers for textures This is the first step into merging `DRW_gpu_wrapper.hh` into the GPU module. This is very similar to #119825. Pull Request: https://projects.blender.org/blender/blender/pulls/142732 --- intern/cycles/blender/display_driver.cpp | 2 +- source/blender/blenfont/intern/blf_font.cc | 4 +- .../blenfont/intern/blf_internal_types.hh | 2 +- source/blender/blenkernel/BKE_image.hh | 26 +- .../blenkernel/BKE_image_partial_update.hh | 4 +- source/blender/blenkernel/BKE_movieclip.h | 8 +- .../blender/blenkernel/BKE_preview_image.hh | 6 +- source/blender/blenkernel/BKE_studiolight.h | 8 +- source/blender/blenkernel/intern/image.cc | 4 +- source/blender/blenkernel/intern/image_gpu.cc | 57 +-- .../blenkernel/intern/image_partial_update.cc | 4 +- source/blender/blenkernel/intern/movieclip.cc | 12 +- .../blender/blenkernel/intern/studiolight.cc | 2 +- source/blender/compositor/COM_result.hh | 12 +- .../algorithms/intern/parallel_reduction.cc | 6 +- .../cached_resources/COM_cached_image.hh | 2 +- .../COM_smaa_precomputed_textures.hh | 4 +- .../ocio_color_space_conversion_shader.cc | 25 +- source/blender/compositor/intern/result.cc | 7 +- .../engines/compositor/compositor_engine.cc | 4 +- .../engines/eevee/eevee_depth_of_field.cc | 8 +- .../engines/eevee/eevee_depth_of_field.hh | 12 +- .../blender/draw/engines/eevee/eevee_film.cc | 14 +- .../blender/draw/engines/eevee/eevee_film.hh | 8 +- .../draw/engines/eevee/eevee_gbuffer.hh | 6 +- .../draw/engines/eevee/eevee_hizbuffer.hh | 10 +- .../engines/eevee/eevee_lightprobe_sphere.hh | 4 +- .../draw/engines/eevee/eevee_lookdev.cc | 2 +- .../draw/engines/eevee/eevee_material.cc | 2 +- .../draw/engines/eevee/eevee_motion_blur.cc | 2 +- .../draw/engines/eevee/eevee_motion_blur.hh | 6 +- .../draw/engines/eevee/eevee_pipeline.cc | 20 +- .../draw/engines/eevee/eevee_pipeline.hh | 20 +- .../draw/engines/eevee/eevee_raytrace.cc | 2 +- .../draw/engines/eevee/eevee_raytrace.hh | 30 +- .../draw/engines/eevee/eevee_shadow.hh | 2 +- .../draw/engines/eevee/eevee_subsurface.cc | 4 +- .../draw/engines/eevee/eevee_subsurface.hh | 8 +- .../blender/draw/engines/eevee/eevee_view.cc | 6 +- .../blender/draw/engines/eevee/eevee_view.hh | 2 +- .../draw/engines/eevee/eevee_volume.hh | 22 +- .../engines/gpencil/gpencil_cache_utils.cc | 4 +- .../draw/engines/gpencil/gpencil_draw_data.cc | 8 +- .../draw/engines/gpencil/gpencil_engine_c.cc | 8 +- .../engines/gpencil/gpencil_engine_private.hh | 20 +- .../draw/engines/image/image_drawing_mode.cc | 2 +- .../draw/engines/overlay/overlay_armature.hh | 2 +- .../draw/engines/overlay/overlay_camera.hh | 16 +- .../draw/engines/overlay/overlay_empty.hh | 2 +- .../draw/engines/overlay/overlay_grid.hh | 6 +- .../draw/engines/overlay/overlay_mesh.hh | 2 +- .../draw/engines/overlay/overlay_paint.hh | 2 +- .../draw/engines/overlay/overlay_wireframe.hh | 2 +- .../engines/select/select_debug_engine.cc | 2 +- .../draw/engines/select/select_engine.cc | 4 +- .../draw/engines/select/select_engine.hh | 2 +- .../workbench_effect_antialiasing.cc | 2 +- .../engines/workbench/workbench_engine.cc | 18 +- .../engines/workbench/workbench_private.hh | 10 +- .../engines/workbench/workbench_shadow.cc | 2 +- source/blender/draw/intern/DRW_gpu_wrapper.hh | 100 ++--- source/blender/draw/intern/DRW_render.hh | 4 +- source/blender/draw/intern/draw_cache.hh | 4 +- .../draw/intern/draw_cache_impl_particles.cc | 2 +- .../draw/intern/draw_color_management.hh | 4 +- source/blender/draw/intern/draw_command.hh | 8 +- source/blender/draw/intern/draw_common_c.hh | 4 +- source/blender/draw/intern/draw_context.cc | 4 +- source/blender/draw/intern/draw_fluid.cc | 34 +- .../blender/draw/intern/draw_hair_private.hh | 4 +- source/blender/draw/intern/draw_manager.cc | 4 +- source/blender/draw/intern/draw_manager.hh | 4 +- source/blender/draw/intern/draw_pass.hh | 36 +- source/blender/draw/intern/draw_view_data.hh | 12 +- source/blender/draw/intern/draw_volume.cc | 11 +- source/blender/editors/include/ED_view3d.hh | 2 +- source/blender/editors/screen/glutil.cc | 4 +- .../editors/sculpt_paint/paint_cursor.cc | 8 +- .../blender/editors/space_clip/clip_draw.cc | 14 +- .../space_sequencer/sequencer_preview_draw.cc | 26 +- .../space_sequencer/sequencer_thumbnails.cc | 6 +- .../editors/space_view3d/view3d_draw.cc | 6 +- source/blender/gpu/GPU_framebuffer.hh | 31 +- source/blender/gpu/GPU_immediate.hh | 4 +- source/blender/gpu/GPU_material.hh | 8 +- source/blender/gpu/GPU_texture.hh | 240 +++++------ source/blender/gpu/GPU_texture_pool.hh | 18 +- source/blender/gpu/GPU_viewport.hh | 6 +- source/blender/gpu/intern/gpu_framebuffer.cc | 27 +- .../gpu/intern/gpu_framebuffer_private.hh | 8 +- source/blender/gpu/intern/gpu_immediate.cc | 4 +- source/blender/gpu/intern/gpu_material.cc | 14 +- source/blender/gpu/intern/gpu_node_graph.cc | 9 +- source/blender/gpu/intern/gpu_node_graph.hh | 12 +- source/blender/gpu/intern/gpu_texture.cc | 385 +++++++++--------- source/blender/gpu/intern/gpu_texture_pool.cc | 23 +- .../blender/gpu/intern/gpu_texture_private.hh | 18 +- source/blender/gpu/intern/gpu_viewport.cc | 20 +- source/blender/gpu/metal/mtl_context.mm | 16 +- source/blender/gpu/metal/mtl_framebuffer.mm | 14 +- source/blender/gpu/metal/mtl_texture.hh | 6 +- source/blender/gpu/metal/mtl_texture.mm | 14 +- source/blender/gpu/metal/mtl_texture_util.mm | 20 +- source/blender/gpu/metal/mtl_vertex_buffer.hh | 2 +- source/blender/gpu/metal/mtl_vertex_buffer.mm | 3 +- source/blender/gpu/opengl/gl_framebuffer.cc | 8 +- source/blender/gpu/opengl/gl_texture.cc | 9 +- source/blender/gpu/opengl/gl_texture.hh | 5 +- source/blender/gpu/opengl/gl_vertex_buffer.hh | 2 +- source/blender/gpu/tests/compute_test.cc | 4 +- source/blender/gpu/tests/framebuffer_test.cc | 23 +- source/blender/gpu/tests/shader_test.cc | 6 +- source/blender/gpu/tests/state_blend_test.cc | 2 +- source/blender/gpu/tests/texture_test.cc | 55 +-- .../blender/gpu/tests/vertex_buffer_test.cc | 2 +- source/blender/gpu/vulkan/vk_context.hh | 2 +- source/blender/gpu/vulkan/vk_texture.cc | 5 +- source/blender/gpu/vulkan/vk_texture.hh | 5 +- source/blender/imbuf/IMB_imbuf.hh | 29 +- source/blender/imbuf/IMB_imbuf_types.hh | 6 +- source/blender/imbuf/intern/util_gpu.cc | 28 +- .../intern/gpu_shader_binder_internal.hh | 10 +- source/blender/makesdna/DNA_fluid_types.h | 35 +- source/blender/makesdna/DNA_image_types.h | 9 +- .../blender/makesdna/DNA_lightprobe_types.h | 12 +- source/blender/makesdna/DNA_movieclip_types.h | 10 +- .../blender/makesrna/intern/rna_image_api.cc | 2 +- .../blender/python/gpu/gpu_py_framebuffer.cc | 17 +- source/blender/python/gpu/gpu_py_offscreen.cc | 4 +- source/blender/python/gpu/gpu_py_shader.cc | 4 +- .../python/gpu/gpu_py_shader_create_info.cc | 3 +- source/blender/python/gpu/gpu_py_texture.cc | 51 ++- source/blender/python/gpu/gpu_py_texture.hh | 10 +- source/blender/render/RE_pipeline.h | 7 +- .../render/hydra/render_task_delegate.cc | 6 +- .../render/hydra/render_task_delegate.hh | 6 +- .../blender/render/hydra/viewport_engine.cc | 4 +- .../blender/render/hydra/viewport_engine.hh | 6 +- source/blender/render/intern/compositor.cc | 6 +- source/blender/render/intern/render_result.cc | 2 +- .../gizmo/intern/wm_gizmo_map.cc | 2 +- .../blender/windowmanager/intern/wm_draw.cc | 10 +- .../windowmanager/intern/wm_operators.cc | 2 +- .../windowmanager/intern/wm_playanim.cc | 2 +- source/blender/windowmanager/wm_draw.hh | 6 +- 145 files changed, 1114 insertions(+), 1009 deletions(-) diff --git a/intern/cycles/blender/display_driver.cpp b/intern/cycles/blender/display_driver.cpp index 44202fff733..817f192ae78 100644 --- a/intern/cycles/blender/display_driver.cpp +++ b/intern/cycles/blender/display_driver.cpp @@ -261,7 +261,7 @@ class DisplayGPUTexture { /* Texture resource allocated by the GPU module. * * NOTE: Allocated on the render engine's context. */ - GPUTexture *gpu_texture = nullptr; + blender::gpu::Texture *gpu_texture = nullptr; /* Dimensions of the texture in pixels. */ int width = 0; diff --git a/source/blender/blenfont/intern/blf_font.cc b/source/blender/blenfont/intern/blf_font.cc index 0e9e49f0ca6..9543ad358f5 100644 --- a/source/blender/blenfont/intern/blf_font.cc +++ b/source/blender/blenfont/intern/blf_font.cc @@ -283,7 +283,7 @@ void blf_batch_draw_begin(FontBLF *font) } } -static GPUTexture *blf_batch_cache_texture_load() +static blender::gpu::Texture *blf_batch_cache_texture_load() { GlyphCacheBLF *gc = g_batch.glyph_cache; BLI_assert(gc); @@ -336,7 +336,7 @@ void blf_batch_draw() blf_draw_cache_flush(); } - GPUTexture *texture = blf_batch_cache_texture_load(); + blender::gpu::Texture *texture = blf_batch_cache_texture_load(); GPU_vertbuf_data_len_set(*g_batch.verts, g_batch.glyph_len); GPU_vertbuf_use(g_batch.verts); /* Send data. */ diff --git a/source/blender/blenfont/intern/blf_internal_types.hh b/source/blender/blenfont/intern/blf_internal_types.hh index 09538fe6901..cef1ef67571 100644 --- a/source/blender/blenfont/intern/blf_internal_types.hh +++ b/source/blender/blenfont/intern/blf_internal_types.hh @@ -165,7 +165,7 @@ struct GlyphCacheBLF { blender::Map> glyphs; /** Texture array, to draw the glyphs. */ - GPUTexture *texture; + blender::gpu::Texture *texture; char *bitmap_result; int bitmap_len; int bitmap_len_landed; diff --git a/source/blender/blenkernel/BKE_image.hh b/source/blender/blenkernel/BKE_image.hh index d2584e35ef8..7fdd00fc231 100644 --- a/source/blender/blenkernel/BKE_image.hh +++ b/source/blender/blenkernel/BKE_image.hh @@ -13,9 +13,12 @@ #include #include +namespace blender::gpu { +class Texture; +} // namespace blender::gpu + struct rcti; struct Depsgraph; -struct GPUTexture; struct ID; struct ImBuf; struct MovieReader; @@ -564,7 +567,7 @@ ImBuf *BKE_image_get_first_ibuf(Image *image); /** * Not to be use directly. */ -GPUTexture *BKE_image_create_gpu_texture_from_ibuf(Image *image, ImBuf *ibuf); +blender::gpu::Texture *BKE_image_create_gpu_texture_from_ibuf(Image *image, ImBuf *ibuf); /** * Ensure that the cached GPU texture inside the image matches the pass, layer, and view of the @@ -581,7 +584,7 @@ GPUTexture *BKE_image_create_gpu_texture_from_ibuf(Image *image, ImBuf *ibuf); void BKE_image_ensure_gpu_texture(Image *image, ImageUser *iuser); /** - * Get the #GPUTexture for a given `Image`. + * Get the #blender::gpu::Texture for a given `Image`. * * * @@ -594,20 +597,20 @@ void BKE_image_ensure_gpu_texture(Image *image, ImageUser *iuser); * calling BKE_image_ensure_gpu_texture. This is a workaround until image can support a more * complete caching system. */ -GPUTexture *BKE_image_get_gpu_texture(Image *image, ImageUser *iuser); +blender::gpu::Texture *BKE_image_get_gpu_texture(Image *image, ImageUser *iuser); /* * Like BKE_image_get_gpu_texture, but can also get render or compositing result. */ -GPUTexture *BKE_image_get_gpu_viewer_texture(Image *image, ImageUser *iuser); +blender::gpu::Texture *BKE_image_get_gpu_viewer_texture(Image *image, ImageUser *iuser); /* * Like BKE_image_get_gpu_texture, but can also return array and tile mapping texture for UDIM * tiles as used in material shaders. */ struct ImageGPUTextures { - GPUTexture **texture; - GPUTexture **tile_mapping; + blender::gpu::Texture **texture; + blender::gpu::Texture **tile_mapping; }; ImageGPUTextures BKE_image_get_gpu_material_texture(Image *image, @@ -620,7 +623,7 @@ ImageGPUTextures BKE_image_get_gpu_material_texture_try(Image *image, const bool use_tile_mapping); /** - * Is the alpha of the `GPUTexture` for a given image/ibuf premultiplied. + * Is the alpha of the `blender::gpu::Texture` for a given image/ibuf premultiplied. */ bool BKE_image_has_gpu_texture_premultiplied_alpha(Image *image, ImBuf *ibuf); @@ -631,9 +634,10 @@ bool BKE_image_has_gpu_texture_premultiplied_alpha(Image *image, ImBuf *ibuf); void BKE_image_update_gputexture(Image *ima, ImageUser *iuser, int x, int y, int w, int h); /** - * Mark areas on the #GPUTexture that needs to be updated. The areas are marked in chunks. - * The next time the #GPUTexture is used these tiles will be refreshes. This saves time - * when writing to the same place multiple times This happens for during foreground rendering. + * Mark areas on the #blender::gpu::Texture that needs to be updated. The areas are marked in + * chunks. The next time the #blender::gpu::Texture is used these tiles will be refreshes. This + * saves time when writing to the same place multiple times This happens for during foreground + * rendering. */ void BKE_image_update_gputexture_delayed( Image *ima, ImageTile *image_tile, ImBuf *ibuf, int x, int y, int w, int h); diff --git a/source/blender/blenkernel/BKE_image_partial_update.hh b/source/blender/blenkernel/BKE_image_partial_update.hh index da92ba2e2d2..649ba4441ec 100644 --- a/source/blender/blenkernel/BKE_image_partial_update.hh +++ b/source/blender/blenkernel/BKE_image_partial_update.hh @@ -9,8 +9,8 @@ * image that are changed. These areas are organized in chunks. Changes that happen over time are * organized in changesets. * - * A common use case is to update #GPUTexture for drawing where only that part is uploaded that - * only changed. + * A common use case is to update #blender::gpu::Texture for drawing where only that part is + * uploaded that only changed. */ #pragma once diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index e4453a2c3e1..c4505d392ee 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -16,6 +16,10 @@ struct MovieClipScopes; struct MovieClipUser; struct MovieDistortion; +namespace blender::gpu { +class Texture; +} // namespace blender::gpu + /** * Checks if image was already loaded, then returns same image otherwise creates new. * does not load ibuf itself pass on optional frame for `filepath` images. @@ -119,8 +123,8 @@ bool BKE_movieclip_put_frame_if_possible(struct MovieClip *clip, const struct MovieClipUser *user, struct ImBuf *ibuf); -struct GPUTexture *BKE_movieclip_get_gpu_texture(struct MovieClip *clip, - struct MovieClipUser *cuser); +blender::gpu::Texture *BKE_movieclip_get_gpu_texture(struct MovieClip *clip, + struct MovieClipUser *cuser); void BKE_movieclip_free_gputexture(struct MovieClip *clip); diff --git a/source/blender/blenkernel/BKE_preview_image.hh b/source/blender/blenkernel/BKE_preview_image.hh index aede55e724f..36d7e7bbb80 100644 --- a/source/blender/blenkernel/BKE_preview_image.hh +++ b/source/blender/blenkernel/BKE_preview_image.hh @@ -16,7 +16,9 @@ struct BlendDataReader; struct BlendWriter; -struct GPUTexture; +namespace blender::gpu { +class Texture; +} struct ID; struct ImBuf; struct PreviewImage; @@ -32,7 +34,7 @@ struct PreviewImageRuntime { int icon_id = 0; int16_t tag = 0; - std::array gputexture = {}; + std::array gputexture = {}; /** Used to store data to defer the loading of the preview. If empty, loading is not deferred. */ std::unique_ptr deferred_loading_data; diff --git a/source/blender/blenkernel/BKE_studiolight.h b/source/blender/blenkernel/BKE_studiolight.h index e5ccdb68930..876a14d95d0 100644 --- a/source/blender/blenkernel/BKE_studiolight.h +++ b/source/blender/blenkernel/BKE_studiolight.h @@ -27,7 +27,9 @@ struct ImBuf; #define STUDIOLIGHT_ICON_SIZE 96 -struct GPUTexture; +namespace blender::gpu { +class Texture; +} // namespace blender::gpu struct StudioLight; /** #StudioLight.flag */ @@ -58,7 +60,7 @@ typedef void StudioLightFreeFunction(struct StudioLight *, void *data); typedef struct StudioLightImage { struct ImBuf *ibuf; - struct GPUTexture *gputexture; + blender::gpu::Texture *gputexture; } StudioLightImage; typedef struct StudioLight { @@ -75,7 +77,7 @@ typedef struct StudioLight { StudioLightImage matcap_diffuse; StudioLightImage matcap_specular; struct ImBuf *equirect_radiance_buffer; - struct GPUTexture *equirect_radiance_gputexture; + blender::gpu::Texture *equirect_radiance_gputexture; SolidLight light[STUDIOLIGHT_MAX_LIGHT]; float light_ambient[3]; diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index 6fb34d8074b..524fad85f17 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -248,14 +248,14 @@ static void image_foreach_cache(ID *id, auto gputexture_offset = [image](int target, int eye) { constexpr size_t base_offset = offsetof(Image, gputexture); - GPUTexture **first = &image->gputexture[0][0]; + blender::gpu::Texture **first = &image->gputexture[0][0]; const size_t array_offset = sizeof(*first) * (&image->gputexture[target][eye] - first); return base_offset + array_offset; }; for (int eye = 0; eye < 2; eye++) { for (int a = 0; a < TEXTARGET_COUNT; a++) { - GPUTexture *texture = image->gputexture[a][eye]; + blender::gpu::Texture *texture = image->gputexture[a][eye]; if (texture == nullptr) { continue; } diff --git a/source/blender/blenkernel/intern/image_gpu.cc b/source/blender/blenkernel/intern/image_gpu.cc index 9257b00818f..62047bf967e 100644 --- a/source/blender/blenkernel/intern/image_gpu.cc +++ b/source/blender/blenkernel/intern/image_gpu.cc @@ -76,9 +76,9 @@ static int smaller_power_of_2_limit(int num) return power_of_2_min_i(GPU_texture_size_with_limit(num)); } -static GPUTexture *gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye) +static blender::gpu::Texture *gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye) { - GPUTexture *tilearray = ima->gputexture[TEXTARGET_2D_ARRAY][multiview_eye]; + blender::gpu::Texture *tilearray = ima->gputexture[TEXTARGET_2D_ARRAY][multiview_eye]; if (tilearray == nullptr) { return nullptr; @@ -110,7 +110,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( + blender::gpu::Texture *tex = GPU_texture_create_1d_array( ima->id.name + 2, width, 2, 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_SHADER_READ, data); GPU_texture_mipmap_mode(tex, false, false); @@ -133,7 +133,7 @@ static int compare_packtile(const void *a, const void *b) return tile_a->pack_score < tile_b->pack_score; } -static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) +static blender::gpu::Texture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) { int arraywidth = 0, arrayheight = 0; ListBase boxes = {nullptr}; @@ -200,13 +200,13 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH); const bool use_grayscale = planes <= 8; /* Create Texture without content. */ - GPUTexture *tex = IMB_touch_gpu_texture(ima->id.name + 2, - main_ibuf, - arraywidth, - arrayheight, - arraylayers, - use_high_bitdepth, - use_grayscale); + blender::gpu::Texture *tex = IMB_touch_gpu_texture(ima->id.name + 2, + main_ibuf, + arraywidth, + arrayheight, + arraylayers, + use_high_bitdepth, + use_grayscale); /* Upload each tile one by one. */ LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { @@ -259,9 +259,9 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) /** \name Regular gpu texture * \{ */ -static GPUTexture **get_image_gpu_texture_ptr(Image *ima, - eGPUTextureTarget textarget, - const int multiview_eye) +static blender::gpu::Texture **get_image_gpu_texture_ptr(Image *ima, + eGPUTextureTarget textarget, + const int multiview_eye) { const bool in_range = (int(textarget) >= 0) && (textarget < TEXTARGET_COUNT); BLI_assert(in_range); @@ -273,9 +273,9 @@ static GPUTexture **get_image_gpu_texture_ptr(Image *ima, return nullptr; } -static GPUTexture *image_gpu_texture_error_create(eGPUTextureTarget textarget) +static blender::gpu::Texture *image_gpu_texture_error_create(eGPUTextureTarget textarget) { - fprintf(stderr, "GPUTexture: Blender Texture Not Loaded!\n"); + fprintf(stderr, "blender::gpu::Texture: Blender Texture Not Loaded!\n"); switch (textarget) { case TEXTARGET_2D_ARRAY: return GPU_texture_create_error(2, true); @@ -483,12 +483,12 @@ static ImageGPUTextures image_get_gpu_texture(Image *ima, return result; } -GPUTexture *BKE_image_get_gpu_texture(Image *image, ImageUser *iuser) +blender::gpu::Texture *BKE_image_get_gpu_texture(Image *image, ImageUser *iuser) { return *image_get_gpu_texture(image, iuser, false, false, false).texture; } -GPUTexture *BKE_image_get_gpu_viewer_texture(Image *image, ImageUser *iuser) +blender::gpu::Texture *BKE_image_get_gpu_viewer_texture(Image *image, ImageUser *iuser) { return *image_get_gpu_texture(image, iuser, true, false, false).texture; } @@ -528,7 +528,8 @@ static void gpu_free_unused_buffers() std::scoped_lock lock(gpu_texture_queue_mutex); while (gpu_texture_free_queue != nullptr) { - GPUTexture *tex = static_cast(BLI_linklist_pop(&gpu_texture_free_queue)); + blender::gpu::Texture *tex = static_cast( + BLI_linklist_pop(&gpu_texture_free_queue)); GPU_texture_free(tex); } } @@ -673,7 +674,7 @@ static ImBuf *update_do_scale(const uchar *rect, return ibuf; } -static void gpu_texture_update_scaled(GPUTexture *tex, +static void gpu_texture_update_scaled(blender::gpu::Texture *tex, const uchar *rect, const float *rect_float, int full_w, @@ -712,7 +713,7 @@ static void gpu_texture_update_scaled(GPUTexture *tex, IMB_freeImBuf(ibuf); } -static void gpu_texture_update_unscaled(GPUTexture *tex, +static void gpu_texture_update_unscaled(blender::gpu::Texture *tex, uchar *rect, float *rect_float, int x, @@ -742,8 +743,14 @@ static void gpu_texture_update_unscaled(GPUTexture *tex, GPU_unpack_row_length_set(0); } -static void gpu_texture_update_from_ibuf( - GPUTexture *tex, Image *ima, ImBuf *ibuf, ImageTile *tile, int x, int y, int w, int h) +static void gpu_texture_update_from_ibuf(blender::gpu::Texture *tex, + Image *ima, + ImBuf *ibuf, + ImageTile *tile, + int x, + int y, + int w, + int h) { bool scaled; if (tile != nullptr) { @@ -880,7 +887,7 @@ static void image_update_gputexture_ex( Image *ima, ImageTile *tile, ImBuf *ibuf, int x, int y, int w, int h) { const int eye = 0; - GPUTexture *tex = ima->gputexture[TEXTARGET_2D][eye]; + blender::gpu::Texture *tex = ima->gputexture[TEXTARGET_2D][eye]; /* Check if we need to update the main gputexture. */ if (tex != nullptr && tile == ima->tiles.first) { gpu_texture_update_from_ibuf(tex, ima, ibuf, nullptr, x, y, w, h); @@ -925,7 +932,7 @@ void BKE_image_paint_set_mipmap(Main *bmain, bool mipmap) for (int a = 0; a < TEXTARGET_COUNT; a++) { if (ELEM(a, TEXTARGET_2D, TEXTARGET_2D_ARRAY)) { for (int eye = 0; eye < 2; eye++) { - GPUTexture *tex = ima->gputexture[a][eye]; + blender::gpu::Texture *tex = ima->gputexture[a][eye]; if (tex != nullptr) { GPU_texture_mipmap_mode(tex, mipmap, true); } diff --git a/source/blender/blenkernel/intern/image_partial_update.cc b/source/blender/blenkernel/intern/image_partial_update.cc index a6c918b1558..11d9cd95d8a 100644 --- a/source/blender/blenkernel/intern/image_partial_update.cc +++ b/source/blender/blenkernel/intern/image_partial_update.cc @@ -9,8 +9,8 @@ * image that are changed. These areas are organized in chunks. Changes that happen over time are * organized in changesets. * - * A common use case is to update #GPUTexture for drawing where only that part is uploaded that - * only changed. + * A common use case is to update #blender::gpu::Texture for drawing where only that part is + * uploaded that only changed. * * Usage: * diff --git a/source/blender/blenkernel/intern/movieclip.cc b/source/blender/blenkernel/intern/movieclip.cc index 732f46a4127..8eb0bd25db0 100644 --- a/source/blender/blenkernel/intern/movieclip.cc +++ b/source/blender/blenkernel/intern/movieclip.cc @@ -1981,9 +1981,9 @@ void BKE_movieclip_eval_update(Depsgraph *depsgraph, Main *bmain, MovieClip *cli /** \name GPU textures * \{ */ -static GPUTexture **movieclip_get_gputexture_ptr(MovieClip *clip, - MovieClipUser *cuser, - eGPUTextureTarget textarget) +static blender::gpu::Texture **movieclip_get_gputexture_ptr(MovieClip *clip, + MovieClipUser *cuser, + eGPUTextureTarget textarget) { /* Check if we have an existing entry for that clip user. */ MovieClip_RuntimeGPUTexture *tex; @@ -2010,13 +2010,13 @@ static GPUTexture **movieclip_get_gputexture_ptr(MovieClip *clip, return &tex->gputexture[textarget]; } -GPUTexture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser) +blender::gpu::Texture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser) { if (clip == nullptr) { return nullptr; } - GPUTexture **tex = movieclip_get_gputexture_ptr(clip, cuser, TEXTARGET_2D); + blender::gpu::Texture **tex = movieclip_get_gputexture_ptr(clip, cuser, TEXTARGET_2D); if (*tex) { return *tex; } @@ -2024,7 +2024,7 @@ GPUTexture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser) /* check if we have a valid image buffer */ ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, cuser); if (ibuf == nullptr) { - fprintf(stderr, "GPUTexture: Blender Texture Not Loaded!\n"); + fprintf(stderr, "blender::gpu::Texture: Blender Texture Not Loaded!\n"); *tex = GPU_texture_create_error(2, false); return *tex; } diff --git a/source/blender/blenkernel/intern/studiolight.cc b/source/blender/blenkernel/intern/studiolight.cc index ca2db43b403..09debe836e9 100644 --- a/source/blender/blenkernel/intern/studiolight.cc +++ b/source/blender/blenkernel/intern/studiolight.cc @@ -442,7 +442,7 @@ static void studiolight_create_equirect_radiance_gputexture(StudioLight *sl) GPU_RGBA16F, GPU_TEXTURE_USAGE_SHADER_READ, ibuf->float_buffer.data); - GPUTexture *tex = sl->equirect_radiance_gputexture; + blender::gpu::Texture *tex = sl->equirect_radiance_gputexture; GPU_texture_filter_mode(tex, true); GPU_texture_extend_mode(tex, GPU_SAMPLER_EXTEND_MODE_REPEAT); } diff --git a/source/blender/compositor/COM_result.hh b/source/blender/compositor/COM_result.hh index 52cfb3f4bb5..197729386a8 100644 --- a/source/blender/compositor/COM_result.hh +++ b/source/blender/compositor/COM_result.hh @@ -53,7 +53,7 @@ enum class ResultPrecision : uint8_t { /* The type of storage used to hold the result data. */ enum class ResultStorageType : uint8_t { - /* Stored as a GPUTexture on the GPU. */ + /* Stored as a blender::gpu::Texture on the GPU. */ GPU, /* Stored as a buffer on the CPU and wrapped in a GMutableSpan. */ CPU, @@ -112,7 +112,7 @@ class Result { * value of which will be identical to that of the value member. See class description for more * information. */ union { - GPUTexture *gpu_texture_ = nullptr; + blender::gpu::Texture *gpu_texture_ = nullptr; GMutableSpan cpu_data_; }; /* The number of users that currently needs this result. Operations initializes this by calling @@ -195,7 +195,7 @@ class Result { static const char *type_name(const ResultType type); /* Implicit conversion to the internal GPU texture. */ - operator GPUTexture *() const; + operator blender::gpu::Texture *() const; /* Returns the CPP type of the result. */ const CPPType &get_cpp_type() const; @@ -271,7 +271,7 @@ class Result { * size as the texture, and the texture will be set to the given texture. See the is_external_ * member for more information. The given texture should have the same format as the result and * is assumed to have a lifetime that covers the evaluation of the compositor. */ - void wrap_external(GPUTexture *texture); + void wrap_external(blender::gpu::Texture *texture); /* Identical to GPU variant of wrap_external but wraps a CPU buffer instead. */ void wrap_external(void *data, int2 size); @@ -344,7 +344,7 @@ class Result { /* Computes the number of channels of the result based on its type. */ int64_t channels_count() const; - GPUTexture *gpu_texture() const; + blender::gpu::Texture *gpu_texture() const; GSpan cpu_data() const; GMutableSpan cpu_data(); @@ -502,7 +502,7 @@ BLI_INLINE_METHOD int64_t Result::channels_count() const return 4; } -BLI_INLINE_METHOD GPUTexture *Result::gpu_texture() const +BLI_INLINE_METHOD blender::gpu::Texture *Result::gpu_texture() const { BLI_assert(storage_type_ == ResultStorageType::GPU); return gpu_texture_; diff --git a/source/blender/compositor/algorithms/intern/parallel_reduction.cc b/source/blender/compositor/algorithms/intern/parallel_reduction.cc index a99c42013a2..d09c2babe84 100644 --- a/source/blender/compositor/algorithms/intern/parallel_reduction.cc +++ b/source/blender/compositor/algorithms/intern/parallel_reduction.cc @@ -35,19 +35,19 @@ namespace blender::compositor { * to be derived from the compositor_parallel_reduction.glsl shader, see that file for more * information. Also see the compositor_parallel_reduction_info.hh file for example shader * definitions. */ -static float *parallel_reduction_dispatch(GPUTexture *texture, +static float *parallel_reduction_dispatch(blender::gpu::Texture *texture, GPUShader *shader, eGPUTextureFormat format) { GPU_shader_uniform_1b(shader, "is_initial_reduction", true); - GPUTexture *texture_to_reduce = texture; + blender::gpu::Texture *texture_to_reduce = texture; int2 size_to_reduce = int2(GPU_texture_width(texture), GPU_texture_height(texture)); /* Dispatch the reduction shader until the texture reduces to a single pixel. */ while (size_to_reduce != int2(1)) { const int2 reduced_size = math::divide_ceil(size_to_reduce, int2(16)); - GPUTexture *reduced_texture = gpu::TexturePool::get().acquire_texture( + blender::gpu::Texture *reduced_texture = gpu::TexturePool::get().acquire_texture( reduced_size.x, reduced_size.y, format, GPU_TEXTURE_USAGE_GENERAL); GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH); diff --git a/source/blender/compositor/cached_resources/COM_cached_image.hh b/source/blender/compositor/cached_resources/COM_cached_image.hh index bc7173b1f42..a27c521111e 100644 --- a/source/blender/compositor/cached_resources/COM_cached_image.hh +++ b/source/blender/compositor/cached_resources/COM_cached_image.hh @@ -50,7 +50,7 @@ class CachedImage : public CachedResource { private: /* For GPU, the result wraps an external GPU texture that is generated by the IMB module and * stored in this member to be freed when the cached resource is deleted. */ - GPUTexture *texture_ = nullptr; + blender::gpu::Texture *texture_ = nullptr; public: CachedImage(Context &context, Image *image, ImageUser *image_user, const char *pass_name); diff --git a/source/blender/compositor/cached_resources/COM_smaa_precomputed_textures.hh b/source/blender/compositor/cached_resources/COM_smaa_precomputed_textures.hh index 23547953ea5..07420ce8cc6 100644 --- a/source/blender/compositor/cached_resources/COM_smaa_precomputed_textures.hh +++ b/source/blender/compositor/cached_resources/COM_smaa_precomputed_textures.hh @@ -30,8 +30,8 @@ class SMAAPrecomputedTextures : public CachedResource { private: /* GPU storage, unused for CPU execution device. */ - GPUTexture *search_texture_ = nullptr; - GPUTexture *area_texture_ = nullptr; + blender::gpu::Texture *search_texture_ = nullptr; + blender::gpu::Texture *area_texture_ = nullptr; public: SMAAPrecomputedTextures(Context &context); diff --git a/source/blender/compositor/cached_resources/intern/ocio_color_space_conversion_shader.cc b/source/blender/compositor/cached_resources/intern/ocio_color_space_conversion_shader.cc index cffd024f0bf..85fabff7a3c 100644 --- a/source/blender/compositor/cached_resources/intern/ocio_color_space_conversion_shader.cc +++ b/source/blender/compositor/cached_resources/intern/ocio_color_space_conversion_shader.cc @@ -230,7 +230,7 @@ class GPUShaderCreator : public OCIO::GpuShaderCreator { * resource names, instead, use the name that is stored in resource_names_. */ const std::string &resource_name = *resource_names_[resource_names_.size() - 1]; - GPUTexture *texture; + blender::gpu::Texture *texture; const eGPUTextureFormat base_format = (channel == TEXTURE_RGB_CHANNEL) ? GPU_RGB32F : GPU_R32F; const eGPUTextureFormat texture_format = Result::gpu_texture_format(base_format, precision_); /* A height of 1 indicates a 1D texture according to the OCIO API. */ @@ -270,14 +270,15 @@ class GPUShaderCreator : public OCIO::GpuShaderCreator { const std::string &resource_name = *resource_names_[resource_names_.size() - 1]; shader_create_info_.sampler(textures_.size() + 1, ImageType::Float3D, resource_name); - GPUTexture *texture = GPU_texture_create_3d(texture_name, - size, - size, - size, - 1, - Result::gpu_texture_format(GPU_RGB32F, precision_), - GPU_TEXTURE_USAGE_SHADER_READ, - values); + blender::gpu::Texture *texture = GPU_texture_create_3d( + texture_name, + size, + size, + size, + 1, + Result::gpu_texture_format(GPU_RGB32F, precision_), + GPU_TEXTURE_USAGE_SHADER_READ, + values); GPU_texture_filter_mode(texture, interpolation != OCIO::INTERP_NEAREST); textures_.add(sampler_name, texture); @@ -370,7 +371,7 @@ class GPUShaderCreator : public OCIO::GpuShaderCreator { GPU_uniformbuf_free(buffer); } - for (GPUTexture *texture : textures_.values()) { + for (blender::gpu::Texture *texture : textures_.values()) { GPU_texture_unbind(texture); } @@ -389,7 +390,7 @@ class GPUShaderCreator : public OCIO::GpuShaderCreator { ~GPUShaderCreator() override { - for (GPUTexture *texture : textures_.values()) { + for (blender::gpu::Texture *texture : textures_.values()) { GPU_texture_free(texture); } @@ -423,7 +424,7 @@ class GPUShaderCreator : public OCIO::GpuShaderCreator { /* A map that associates the name of a sampler with its corresponding texture. Initialized in the * addTexture() and add3DTexture() methods. */ - Map textures_; + Map textures_; /* A vector set that stores the names of all the resources used by the shader. This is used to: * 1. Check for name collisions when adding new resources. diff --git a/source/blender/compositor/intern/result.cc b/source/blender/compositor/intern/result.cc index 8e4a81ff6d6..2d8b445ab43 100644 --- a/source/blender/compositor/intern/result.cc +++ b/source/blender/compositor/intern/result.cc @@ -350,7 +350,7 @@ const char *Result::type_name(const ResultType type) return ""; } -Result::operator GPUTexture *() const +Result::operator blender::gpu::Texture *() const { return this->gpu_texture(); } @@ -521,7 +521,8 @@ void Result::steal_data(Result &source) /* Returns true if the given GPU texture is compatible with the type and precision of the given * result. */ -[[maybe_unused]] static bool is_compatible_texture(const GPUTexture *texture, const Result &result) +[[maybe_unused]] static bool is_compatible_texture(const blender::gpu::Texture *texture, + const Result &result) { /* Float3 types are an exception, see the documentation on the get_gpu_texture_format method for * more information. */ @@ -535,7 +536,7 @@ void Result::steal_data(Result &source) return GPU_texture_format(texture) == result.get_gpu_texture_format(); } -void Result::wrap_external(GPUTexture *texture) +void Result::wrap_external(blender::gpu::Texture *texture) { BLI_assert(is_compatible_texture(texture, *this)); BLI_assert(!this->is_allocated()); diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc index 6d882f406d0..86c798f21a2 100644 --- a/source/blender/draw/engines/compositor/compositor_engine.cc +++ b/source/blender/draw/engines/compositor/compositor_engine.cc @@ -158,14 +158,14 @@ class Context : public compositor::Context { /* The combined pass is a special case where we return the viewport color texture, because it * includes Grease Pencil objects since GP is drawn using their own engine. */ if (STREQ(pass_name, RE_PASSNAME_COMBINED)) { - GPUTexture *combined_texture = DRW_context_get()->viewport_texture_list_get()->color; + gpu::Texture *combined_texture = DRW_context_get()->viewport_texture_list_get()->color; compositor::Result pass = compositor::Result(*this, GPU_texture_format(combined_texture)); pass.wrap_external(combined_texture); return pass; } /* Return the pass that was written by the engine if such pass was found. */ - GPUTexture *pass_texture = DRW_viewport_pass_texture_get(pass_name).gpu_texture(); + gpu::Texture *pass_texture = DRW_viewport_pass_texture_get(pass_name).gpu_texture(); if (pass_texture) { compositor::Result pass = compositor::Result(*this, GPU_texture_format(pass_texture)); pass.wrap_external(pass_texture); diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.cc b/source/blender/draw/engines/eevee/eevee_depth_of_field.cc index 271238b0f50..e1d841d2b86 100644 --- a/source/blender/draw/engines/eevee/eevee_depth_of_field.cc +++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.cc @@ -505,8 +505,8 @@ void DepthOfField::update_sample_table() } void DepthOfField::render(View &view, - GPUTexture **input_tx, - GPUTexture **output_tx, + gpu::Texture **input_tx, + gpu::Texture **output_tx, DepthOfFieldBuffer &dof_buffer) { if (fx_radius_ == 0.0f) { @@ -613,8 +613,8 @@ void DepthOfField::render(View &view, /* Outputs to reduced_*_tx_ mip 0. */ drw.submit(stabilize_ps_, view); - /* WATCH(fclem): Swap Texture an TextureFromPool internal GPUTexture in order to reuse - * the one that we just consumed. */ + /* WATCH(fclem): Swap Texture an TextureFromPool internal gpu::Texture in order to + * reuse the one that we just consumed. */ TextureFromPool::swap(stabilize_output_tx_, dof_buffer.stabilize_history_tx_); /* Used by stabilize pass. */ diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.hh b/source/blender/draw/engines/eevee/eevee_depth_of_field.hh index 0cc3c018817..4e723e55f58 100644 --- a/source/blender/draw/engines/eevee/eevee_depth_of_field.hh +++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.hh @@ -45,8 +45,8 @@ class DepthOfField { class Instance &inst_; /** Input/Output texture references. */ - GPUTexture *input_color_tx_ = nullptr; - GPUTexture *output_color_tx_ = nullptr; + gpu::Texture *input_color_tx_ = nullptr; + gpu::Texture *output_color_tx_ = nullptr; /** Bokeh LUT precompute pass. */ TextureFromPool bokeh_gather_lut_tx_ = {"dof_bokeh_gather_lut"}; @@ -66,7 +66,7 @@ class DepthOfField { /** Stabilization (flicker attenuation) of Color and CoC output of the setup pass. */ TextureFromPool stabilize_output_tx_ = {"dof_taa"}; - GPUTexture *stabilize_input_ = nullptr; + gpu::Texture *stabilize_input_ = nullptr; bool32_t stabilize_valid_history_ = false; int3 dispatch_stabilize_size_ = int3(-1); PassSimple stabilize_ps_ = {"Stabilize"}; @@ -124,7 +124,7 @@ class DepthOfField { PassSimple scatter_bg_ps_ = {"ScatterBg"}; /** Recombine the results and also perform a slight out of focus gather. */ - GPUTexture *resolve_stable_color_tx_ = nullptr; + gpu::Texture *resolve_stable_color_tx_ = nullptr; int3 dispatch_resolve_size_ = int3(-1); PassSimple resolve_ps_ = {"Resolve"}; @@ -167,8 +167,8 @@ class DepthOfField { * is in input_tx. */ void render(View &view, - GPUTexture **input_tx, - GPUTexture **output_tx, + gpu::Texture **input_tx, + gpu::Texture **output_tx, DepthOfFieldBuffer &dof_buffer); bool postfx_enabled() const diff --git a/source/blender/draw/engines/eevee/eevee_film.cc b/source/blender/draw/engines/eevee/eevee_film.cc index 9957f7dec3b..74502fff3ac 100644 --- a/source/blender/draw/engines/eevee/eevee_film.cc +++ b/source/blender/draw/engines/eevee/eevee_film.cc @@ -99,7 +99,7 @@ void Film::init_aovs(const Set &passes_used_by_viewport_compositor) float *Film::read_aov(ViewLayerAOV *aov) { - GPUTexture *pass_tx = this->get_aov_texture(aov); + gpu::Texture *pass_tx = this->get_aov_texture(aov); if (pass_tx == nullptr) { return nullptr; @@ -110,7 +110,7 @@ float *Film::read_aov(ViewLayerAOV *aov) return (float *)GPU_texture_read(pass_tx, GPU_DATA_FLOAT, 0); } -GPUTexture *Film::get_aov_texture(ViewLayerAOV *aov) +gpu::Texture *Film::get_aov_texture(ViewLayerAOV *aov) { bool is_value = (aov->type == AOV_TYPE_VALUE); Texture &accum_tx = is_value ? value_accum_tx_ : color_accum_tx_; @@ -833,7 +833,7 @@ void Film::update_sample_table() } } -void Film::accumulate(View &view, GPUTexture *combined_final_tx) +void Film::accumulate(View &view, gpu::Texture *combined_final_tx) { if (inst_.is_viewport()) { DefaultFramebufferList *dfbl = inst_.draw_ctx->viewport_framebuffer_list_get(); @@ -898,7 +898,7 @@ void Film::cryptomatte_sort() float *Film::read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset) { - GPUTexture *pass_tx = this->get_pass_texture(pass_type, layer_offset); + gpu::Texture *pass_tx = this->get_pass_texture(pass_type, layer_offset); GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE); @@ -915,7 +915,7 @@ float *Film::read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset) return result; } -GPUTexture *Film::get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset) +gpu::Texture *Film::get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset) { ePassStorageType storage_type = pass_storage_type(pass_type); const bool is_value = storage_type == PASS_STORAGE_VALUE; @@ -996,7 +996,7 @@ void Film::write_viewport_compositor_passes() Vector pass_names = Film::pass_to_render_pass_names(pass_type, inst_.view_layer); for (const int64_t pass_offset : IndexRange(pass_names.size())) { - GPUTexture *pass_texture = this->get_pass_texture(pass_type, pass_offset); + gpu::Texture *pass_texture = this->get_pass_texture(pass_type, pass_offset); if (!pass_texture) { continue; } @@ -1028,7 +1028,7 @@ void Film::write_viewport_compositor_passes() if ((aov->flag & AOV_CONFLICT) != 0) { continue; } - GPUTexture *pass_texture = this->get_aov_texture(aov); + gpu::Texture *pass_texture = this->get_aov_texture(aov); if (!pass_texture) { continue; } diff --git a/source/blender/draw/engines/eevee/eevee_film.hh b/source/blender/draw/engines/eevee/eevee_film.hh index 738ee21fd2b..05767f1b0b0 100644 --- a/source/blender/draw/engines/eevee/eevee_film.hh +++ b/source/blender/draw/engines/eevee/eevee_film.hh @@ -67,7 +67,7 @@ class Film { Instance &inst_; /** Incoming combined buffer with post FX applied (motion blur + depth of field). */ - GPUTexture *combined_final_tx_ = nullptr; + gpu::Texture *combined_final_tx_ = nullptr; /** Are we using the compute shader/pipeline. */ bool use_compute_; @@ -121,7 +121,7 @@ class Film { } /** Accumulate the newly rendered sample contained in #RenderBuffers and blit to display. */ - void accumulate(View &view, GPUTexture *combined_final_tx); + void accumulate(View &view, gpu::Texture *combined_final_tx); /** Sort and normalize cryptomatte samples. */ void cryptomatte_sort(); @@ -132,8 +132,8 @@ class Film { float *read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset); float *read_aov(ViewLayerAOV *aov); - GPUTexture *get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset); - GPUTexture *get_aov_texture(ViewLayerAOV *aov); + gpu::Texture *get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset); + gpu::Texture *get_aov_texture(ViewLayerAOV *aov); void write_viewport_compositor_passes(); diff --git a/source/blender/draw/engines/eevee/eevee_gbuffer.hh b/source/blender/draw/engines/eevee/eevee_gbuffer.hh index 3dbd121ef4f..285c9d48bab 100644 --- a/source/blender/draw/engines/eevee/eevee_gbuffer.hh +++ b/source/blender/draw/engines/eevee/eevee_gbuffer.hh @@ -142,9 +142,9 @@ struct GBuffer { * These will point to either the dummy textures bellow or to a layer range view of the above * textures. In the later case, these layers are written with imageStore instead of being part * of the #Framebuffer. */ - GPUTexture *closure_opt_layers_ = nullptr; - GPUTexture *normal_opt_layers_ = nullptr; - GPUTexture *header_opt_layers_ = nullptr; + gpu::Texture *closure_opt_layers_ = nullptr; + gpu::Texture *normal_opt_layers_ = nullptr; + gpu::Texture *header_opt_layers_ = nullptr; /* Textures used to fulfill the GBuffer optional layers binding when textures do not have enough * layers for the optional layers image views. The shader are then expected to never write to diff --git a/source/blender/draw/engines/eevee/eevee_hizbuffer.hh b/source/blender/draw/engines/eevee/eevee_hizbuffer.hh index dc29a8eac8e..d74116f100f 100644 --- a/source/blender/draw/engines/eevee/eevee_hizbuffer.hh +++ b/source/blender/draw/engines/eevee/eevee_hizbuffer.hh @@ -31,7 +31,7 @@ class HiZBuffer { /** Contains depth pyramid of the current pass and the previous pass. */ SwapChain hiz_tx_; /** References to the mip views of the current (front) HiZ texture. */ - std::array hiz_mip_ref_; + std::array hiz_mip_ref_; /** * Atomic counter counting the number of tile that have finished down-sampling. @@ -48,8 +48,8 @@ class HiZBuffer { /** Dirty flag to check if the update is necessary. */ bool is_dirty_ = true; /** Reference to the depth texture to downsample. */ - GPUTexture *src_tx_ = nullptr; - GPUTexture **src_tx_ptr_ = nullptr; + gpu::Texture *src_tx_ = nullptr; + gpu::Texture **src_tx_ptr_ = nullptr; HiZData &data_; @@ -66,7 +66,7 @@ class HiZBuffer { * Need to be called once at the start of a pipeline or view. * Tag the buffer as dirty. */ - void set_source(GPUTexture **texture, int layer = -1) + void set_source(gpu::Texture **texture, int layer = -1) { src_tx_ptr_ = texture; layer_id_ = layer; @@ -107,7 +107,7 @@ class HiZBuffer { /* Back is Previous layer depth (ex: For refraction). Front for current layer depth. */ struct { /** References to the textures in the swap-chain. */ - GPUTexture *ref_tx_ = nullptr; + gpu::Texture *ref_tx_ = nullptr; template void bind_resources(PassType &pass) { diff --git a/source/blender/draw/engines/eevee/eevee_lightprobe_sphere.hh b/source/blender/draw/engines/eevee/eevee_lightprobe_sphere.hh index 515877a62fb..d7d8be12461 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobe_sphere.hh +++ b/source/blender/draw/engines/eevee/eevee_lightprobe_sphere.hh @@ -47,9 +47,9 @@ class SphereProbeModule { /** Convolve the octahedral map to fill the Mip-map levels. */ PassSimple convolve_ps_ = {"Probe.Convolve"}; /** Input mip level for the convolution. */ - GPUTexture *convolve_input_ = nullptr; + gpu::Texture *convolve_input_ = nullptr; /** Output mip level for the convolution. */ - GPUTexture *convolve_output_ = nullptr; + gpu::Texture *convolve_output_ = nullptr; int convolve_lod_ = 0; /* True if we extract spherical harmonic during `remap_ps_`. */ bool extract_sh_ = false; diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.cc b/source/blender/draw/engines/eevee/eevee_lookdev.cc index 25bd48d8aa7..4be21ff58e5 100644 --- a/source/blender/draw/engines/eevee/eevee_lookdev.cc +++ b/source/blender/draw/engines/eevee/eevee_lookdev.cc @@ -107,7 +107,7 @@ bool LookdevWorld::sync(const LookdevParameters &new_parameters) STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); if (sl) { BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE); - GPUTexture *texture = sl->equirect_radiance_gputexture; + gpu::Texture *texture = sl->equirect_radiance_gputexture; if (texture != nullptr) { GPU_texture_ref(texture); image->gputexture[TEXTARGET_2D][0] = texture; diff --git a/source/blender/draw/engines/eevee/eevee_material.cc b/source/blender/draw/engines/eevee/eevee_material.cc index 025663485c3..817df091f4f 100644 --- a/source/blender/draw/engines/eevee/eevee_material.cc +++ b/source/blender/draw/engines/eevee/eevee_material.cc @@ -220,7 +220,7 @@ void MaterialModule::end_sync() BKE_image_tag_time(tex->ima); } - /* Upload to the GPU (create GPUTexture). This part still requires a valid GPU context and + /* Upload to the GPU (create gpu::Texture). This part still requires a valid GPU context and * is not easily parallelized. */ for (GPUMaterialTexture *tex : texture_loading_queue_) { BLI_assert(tex->ima); diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.cc b/source/blender/draw/engines/eevee/eevee_motion_blur.cc index 4f4d436fe00..2b7dfeb74df 100644 --- a/source/blender/draw/engines/eevee/eevee_motion_blur.cc +++ b/source/blender/draw/engines/eevee/eevee_motion_blur.cc @@ -186,7 +186,7 @@ void MotionBlurModule::sync() } } -void MotionBlurModule::render(View &view, GPUTexture **input_tx, GPUTexture **output_tx) +void MotionBlurModule::render(View &view, gpu::Texture **input_tx, gpu::Texture **output_tx) { if (!motion_blur_fx_enabled_) { return; diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.hh b/source/blender/draw/engines/eevee/eevee_motion_blur.hh index f7219134392..5d9e835d89e 100644 --- a/source/blender/draw/engines/eevee/eevee_motion_blur.hh +++ b/source/blender/draw/engines/eevee/eevee_motion_blur.hh @@ -92,8 +92,8 @@ class MotionBlurModule { /** Velocity tiles used to guide and speedup the gather pass. */ TextureFromPool tiles_tx_; - GPUTexture *input_color_tx_ = nullptr; - GPUTexture *output_color_tx_ = nullptr; + gpu::Texture *input_color_tx_ = nullptr; + gpu::Texture *output_color_tx_ = nullptr; PassSimple motion_blur_ps_ = {"MotionBlur"}; @@ -120,7 +120,7 @@ class MotionBlurModule { return motion_blur_fx_enabled_; } - void render(View &view, GPUTexture **input_tx, GPUTexture **output_tx); + void render(View &view, gpu::Texture **input_tx, gpu::Texture **output_tx); private: float shutter_time_to_scene_time(float time); diff --git a/source/blender/draw/engines/eevee/eevee_pipeline.cc b/source/blender/draw/engines/eevee/eevee_pipeline.cc index c4a30ddc857..f89d67a39d6 100644 --- a/source/blender/draw/engines/eevee/eevee_pipeline.cc +++ b/source/blender/draw/engines/eevee/eevee_pipeline.cc @@ -811,14 +811,14 @@ PassMain::Sub *DeferredLayer::material_add(::Material *blender_mat, GPUMaterial return material_pass; } -GPUTexture *DeferredLayer::render(View &main_view, - View &render_view, - Framebuffer &prepass_fb, - Framebuffer &combined_fb, - Framebuffer &gbuffer_fb, - int2 extent, - RayTraceBuffer &rt_buffer, - GPUTexture *radiance_behind_tx) +gpu::Texture *DeferredLayer::render(View &main_view, + View &render_view, + Framebuffer &prepass_fb, + Framebuffer &combined_fb, + Framebuffer &gbuffer_fb, + int2 extent, + RayTraceBuffer &rt_buffer, + gpu::Texture *radiance_behind_tx) { if (closure_count_ == 0) { return nullptr; @@ -997,7 +997,7 @@ void DeferredPipeline::render(View &main_view, RayTraceBuffer &rt_buffer_opaque_layer, RayTraceBuffer &rt_buffer_refract_layer) { - GPUTexture *feedback_tx = nullptr; + gpu::Texture *feedback_tx = nullptr; GPU_debug_group_begin("Deferred.Opaque"); feedback_tx = opaque_layer_.render(main_view, @@ -1445,7 +1445,7 @@ PassMain::Sub *PlanarProbePipeline::material_add(::Material *blender_mat, GPUMat } void PlanarProbePipeline::render(View &view, - GPUTexture *depth_layer_tx, + gpu::Texture *depth_layer_tx, Framebuffer &gbuffer_fb, Framebuffer &combined_fb, int2 extent) diff --git a/source/blender/draw/engines/eevee/eevee_pipeline.hh b/source/blender/draw/engines/eevee/eevee_pipeline.hh index 5508f466789..3bdfe3be86d 100644 --- a/source/blender/draw/engines/eevee/eevee_pipeline.hh +++ b/source/blender/draw/engines/eevee/eevee_pipeline.hh @@ -292,7 +292,7 @@ class DeferredLayer : DeferredLayerBase { /* Used when there is no indirect radiance buffer. */ Texture dummy_black = {"dummy_black"}; /* Reference to ray-tracing results. */ - GPUTexture *radiance_feedback_tx_ = nullptr; + gpu::Texture *radiance_feedback_tx_ = nullptr; /** * Tile texture containing several bool per tile indicating presence of feature. @@ -343,14 +343,14 @@ class DeferredLayer : DeferredLayerBase { static bool do_split_direct_indirect_radiance(const Instance &inst); /* Returns the radiance buffer to feed the next layer. */ - GPUTexture *render(View &main_view, - View &render_view, - Framebuffer &prepass_fb, - Framebuffer &combined_fb, - Framebuffer &gbuffer_fb, - int2 extent, - RayTraceBuffer &rt_buffer, - GPUTexture *radiance_behind_tx); + gpu::Texture *render(View &main_view, + View &render_view, + Framebuffer &prepass_fb, + Framebuffer &combined_fb, + Framebuffer &gbuffer_fb, + int2 extent, + RayTraceBuffer &rt_buffer, + gpu::Texture *radiance_behind_tx); }; class DeferredPipeline { @@ -600,7 +600,7 @@ class PlanarProbePipeline : DeferredLayerBase { PassMain::Sub *material_add(::Material *blender_mat, GPUMaterial *gpumat); void render(View &view, - GPUTexture *depth_layer_tx, + gpu::Texture *depth_layer_tx, Framebuffer &gbuffer, Framebuffer &combined_fb, int2 extent); diff --git a/source/blender/draw/engines/eevee/eevee_raytrace.cc b/source/blender/draw/engines/eevee/eevee_raytrace.cc index 23068360893..19b38634f4c 100644 --- a/source/blender/draw/engines/eevee/eevee_raytrace.cc +++ b/source/blender/draw/engines/eevee/eevee_raytrace.cc @@ -391,7 +391,7 @@ void RayTraceModule::debug_pass_sync() {} void RayTraceModule::debug_draw(View & /*view*/, GPUFrameBuffer * /*view_fb*/) {} RayTraceResult RayTraceModule::render(RayTraceBuffer &rt_buffer, - GPUTexture *screen_radiance_back_tx, + gpu::Texture *screen_radiance_back_tx, eClosureBits active_closures, /* TODO(fclem): Maybe wrap these two in some other class. */ View &main_view, diff --git a/source/blender/draw/engines/eevee/eevee_raytrace.hh b/source/blender/draw/engines/eevee/eevee_raytrace.hh index a3230142ee2..6f36fdc2c14 100644 --- a/source/blender/draw/engines/eevee/eevee_raytrace.hh +++ b/source/blender/draw/engines/eevee/eevee_raytrace.hh @@ -66,7 +66,7 @@ struct RayTraceBuffer { */ float4x4 history_persmat; - GPUTexture *feedback_ensure(bool is_dummy, int2 extent) + gpu::Texture *feedback_ensure(bool is_dummy, int2 extent) { eGPUTextureUsage usage_rw = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_SHADER_WRITE; if (radiance_feedback_tx.ensure_2d(GPU_RGBA16F, is_dummy ? int2(1) : extent, usage_rw)) { @@ -86,7 +86,7 @@ class RayTraceResultTexture { /** Result is in a temporary texture that needs to be released. */ TextureFromPool *result_ = nullptr; /** Value of `result_->tx_` that can be referenced in advance. */ - GPUTexture *tx_ = nullptr; + gpu::Texture *tx_ = nullptr; /** History buffer to swap the temporary texture that does not need to be released. */ Texture *history_ = nullptr; @@ -96,13 +96,13 @@ class RayTraceResultTexture { RayTraceResultTexture(TextureFromPool &result, Texture &history) : result_(result.ptr()), tx_(result), history_(history.ptr()){}; - operator GPUTexture *() const + operator gpu::Texture *() const { BLI_assert(tx_ != nullptr); return tx_; } - GPUTexture **operator&() + gpu::Texture **operator&() { return &tx_; } @@ -177,7 +177,7 @@ class RayTraceModule { /** Indirect dispatch denoise full-resolution tiles. */ DispatchIndirectBuf horizon_denoise_dispatch_buf_ = {"horizon_denoise_dispatch_buf_"}; /** Pointer to the texture to store the result of horizon scan in. */ - GPUTexture *horizon_scan_output_tx_[3] = {nullptr}; + gpu::Texture *horizon_scan_output_tx_[3] = {nullptr}; /** Tile buffer that contains tile coordinates. */ RayTraceTileBuf raytrace_tracing_tiles_buf_ = {"raytrace_tracing_tiles_buf_"}; RayTraceTileBuf raytrace_denoise_tiles_buf_ = {"raytrace_denoise_tiles_buf_"}; @@ -197,9 +197,9 @@ class RayTraceModule { /** Texture containing the view space normal. The BSDF normal is arbitrarily chosen. */ TextureFromPool downsampled_in_normal_tx_ = {"downsampled_in_normal_tx_"}; /** Textures containing the ray hit radiance denoised (full-res). One of them is result_tx. */ - GPUTexture *denoised_spatial_tx_ = nullptr; - GPUTexture *denoised_temporal_tx_ = nullptr; - GPUTexture *denoised_bilateral_tx_ = nullptr; + gpu::Texture *denoised_spatial_tx_ = nullptr; + gpu::Texture *denoised_temporal_tx_ = nullptr; + gpu::Texture *denoised_bilateral_tx_ = nullptr; /** Ray hit depth for temporal denoising. Output of spatial denoise. */ TextureFromPool hit_depth_tx_ = {"hit_depth_tx_"}; /** Ray hit variance for temporal denoising. Output of spatial denoise. */ @@ -207,18 +207,18 @@ class RayTraceModule { /** Temporally stable variance for temporal denoising. Output of temporal denoise. */ TextureFromPool denoise_variance_tx_ = {"denoise_variance_tx_"}; /** Persistent texture reference for temporal denoising input. */ - GPUTexture *radiance_history_tx_ = nullptr; - GPUTexture *variance_history_tx_ = nullptr; - GPUTexture *tilemask_history_tx_ = nullptr; + gpu::Texture *radiance_history_tx_ = nullptr; + gpu::Texture *variance_history_tx_ = nullptr; + gpu::Texture *tilemask_history_tx_ = nullptr; /** Radiance input for screen space tracing. */ - GPUTexture *screen_radiance_front_tx_ = nullptr; - GPUTexture *screen_radiance_back_tx_ = nullptr; + gpu::Texture *screen_radiance_front_tx_ = nullptr; + gpu::Texture *screen_radiance_back_tx_ = nullptr; Texture radiance_dummy_black_tx_ = {"radiance_dummy_black_tx"}; /** Dummy texture when the tracing is disabled. */ TextureFromPool dummy_result_tx_ = {"dummy_result_tx"}; /** Pointer to `inst_.render_buffers.depth_tx` updated before submission. */ - GPUTexture *renderbuf_depth_view_ = nullptr; + gpu::Texture *renderbuf_depth_view_ = nullptr; /** Copy of the scene options to avoid changing parameters during motion blur. */ RaytraceEEVEE ray_tracing_options_; @@ -256,7 +256,7 @@ class RayTraceModule { * \arg force_no_tracing will run the pipeline without any tracing, relying only on local probes. */ RayTraceResult render(RayTraceBuffer &rt_buffer, - GPUTexture *screen_radiance_back_tx, + gpu::Texture *screen_radiance_back_tx, eClosureBits active_closures, /* TODO(fclem): Maybe wrap these two in some other class. */ View &main_view, diff --git a/source/blender/draw/engines/eevee/eevee_shadow.hh b/source/blender/draw/engines/eevee/eevee_shadow.hh index 66974c6bf39..386accd287d 100644 --- a/source/blender/draw/engines/eevee/eevee_shadow.hh +++ b/source/blender/draw/engines/eevee/eevee_shadow.hh @@ -219,7 +219,7 @@ class ShadowModule { PassMain::Sub *tilemap_usage_transparent_ps_ = nullptr; gpu::Batch *box_batch_ = nullptr; /* Source texture for depth buffer analysis. */ - GPUTexture *src_depth_tx_ = nullptr; + gpu::Texture *src_depth_tx_ = nullptr; Framebuffer usage_tag_fb; diff --git a/source/blender/draw/engines/eevee/eevee_subsurface.cc b/source/blender/draw/engines/eevee/eevee_subsurface.cc index 1baf14673f9..2a21c92d937 100644 --- a/source/blender/draw/engines/eevee/eevee_subsurface.cc +++ b/source/blender/draw/engines/eevee/eevee_subsurface.cc @@ -68,8 +68,8 @@ void SubsurfaceModule::end_sync() } } -void SubsurfaceModule::render(GPUTexture *direct_diffuse_light_tx, - GPUTexture *indirect_diffuse_light_tx, +void SubsurfaceModule::render(gpu::Texture *direct_diffuse_light_tx, + gpu::Texture *indirect_diffuse_light_tx, eClosureBits active_closures, View &view) { diff --git a/source/blender/draw/engines/eevee/eevee_subsurface.hh b/source/blender/draw/engines/eevee/eevee_subsurface.hh index 6d5262303f5..9d1ad7517a0 100644 --- a/source/blender/draw/engines/eevee/eevee_subsurface.hh +++ b/source/blender/draw/engines/eevee/eevee_subsurface.hh @@ -36,8 +36,8 @@ struct SubsurfaceModule { /** Contains samples locations. */ SubsurfaceData &data_; /** Scene diffuse irradiance. Pointer binded at sync time, set at render time. */ - GPUTexture *direct_light_tx_; - GPUTexture *indirect_light_tx_; + gpu::Texture *direct_light_tx_; + gpu::Texture *indirect_light_tx_; /** Input radiance packed with surface ID. */ TextureFromPool radiance_tx_; TextureFromPool object_id_tx_; @@ -63,8 +63,8 @@ struct SubsurfaceModule { /* Process the direct & indirect diffuse light buffers using screen space subsurface scattering. * Result is stored in the direct light texture. */ - void render(GPUTexture *direct_diffuse_light_tx, - GPUTexture *indirect_diffuse_light_tx, + void render(gpu::Texture *direct_diffuse_light_tx, + gpu::Texture *indirect_diffuse_light_tx, eClosureBits active_closures, View &view); diff --git a/source/blender/draw/engines/eevee/eevee_view.cc b/source/blender/draw/engines/eevee/eevee_view.cc index fbd70ff88a8..a2b87e7baee 100644 --- a/source/blender/draw/engines/eevee/eevee_view.cc +++ b/source/blender/draw/engines/eevee/eevee_view.cc @@ -157,7 +157,7 @@ void ShadingView::render() inst_.sphere_probes.viewport_draw(render_view_, combined_fb_); inst_.planar_probes.viewport_draw(render_view_, combined_fb_); - GPUTexture *combined_final_tx = render_postfx(rbufs.combined_tx); + gpu::Texture *combined_final_tx = render_postfx(rbufs.combined_tx); inst_.film.accumulate(jitter_view_, combined_final_tx); rbufs.release(); @@ -180,7 +180,7 @@ void ShadingView::render_transparent_pass(RenderBuffers &rbufs) } } -GPUTexture *ShadingView::render_postfx(GPUTexture *input_tx) +gpu::Texture *ShadingView::render_postfx(gpu::Texture *input_tx) { if (!inst_.depth_of_field.postfx_enabled() && !inst_.motion_blur.postfx_enabled()) { return input_tx; @@ -196,7 +196,7 @@ GPUTexture *ShadingView::render_postfx(GPUTexture *input_tx) postfx_tx_.clear(float4(0.0f)); } - GPUTexture *output_tx = postfx_tx_; + gpu::Texture *output_tx = postfx_tx_; /* Swapping is done internally. Actual output is set to the next input. */ inst_.motion_blur.render(render_view_, &input_tx, &output_tx); diff --git a/source/blender/draw/engines/eevee/eevee_view.hh b/source/blender/draw/engines/eevee/eevee_view.hh index f2757426402..c4e898c61c3 100644 --- a/source/blender/draw/engines/eevee/eevee_view.hh +++ b/source/blender/draw/engines/eevee/eevee_view.hh @@ -82,7 +82,7 @@ class ShadingView { private: void render_transparent_pass(RenderBuffers &rbufs); - GPUTexture *render_postfx(GPUTexture *input_tx); + gpu::Texture *render_postfx(gpu::Texture *input_tx); void update_view(); }; diff --git a/source/blender/draw/engines/eevee/eevee_volume.hh b/source/blender/draw/engines/eevee/eevee_volume.hh index 4d32e59d679..d21a3548628 100644 --- a/source/blender/draw/engines/eevee/eevee_volume.hh +++ b/source/blender/draw/engines/eevee/eevee_volume.hh @@ -175,8 +175,8 @@ class VolumeModule { /* Final occupancy after resolve. Used by object volume material evaluation. */ struct { /** References to the textures in the module. */ - GPUTexture *scattering_tx_ = nullptr; - GPUTexture *transmittance_tx_ = nullptr; + gpu::Texture *scattering_tx_ = nullptr; + gpu::Texture *transmittance_tx_ = nullptr; template void bind_resources(PassType &pass) { @@ -188,12 +188,12 @@ class VolumeModule { /* Volume property buffers that are populated by objects or world volume shaders. */ struct { /** References to the textures in the module. */ - GPUTexture *scattering_tx_ = nullptr; - GPUTexture *extinction_tx_ = nullptr; - GPUTexture *emission_tx_ = nullptr; - GPUTexture *phase_tx_ = nullptr; - GPUTexture *phase_weight_tx_ = nullptr; - GPUTexture *occupancy_tx_ = nullptr; + gpu::Texture *scattering_tx_ = nullptr; + gpu::Texture *extinction_tx_ = nullptr; + gpu::Texture *emission_tx_ = nullptr; + gpu::Texture *phase_tx_ = nullptr; + gpu::Texture *phase_weight_tx_ = nullptr; + gpu::Texture *occupancy_tx_ = nullptr; template void bind_resources(PassType &pass) { @@ -209,9 +209,9 @@ class VolumeModule { /* Textures used for object volume occupancy computation. */ struct { /** References to the textures in the module. */ - GPUTexture *occupancy_tx_ = nullptr; - GPUTexture *hit_depth_tx_ = nullptr; - GPUTexture *hit_count_tx_ = nullptr; + gpu::Texture *occupancy_tx_ = nullptr; + gpu::Texture *hit_depth_tx_ = nullptr; + gpu::Texture *hit_count_tx_ = nullptr; template void bind_resources(PassType &pass) { diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc b/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc index 616c2fec140..6c9e955ffcc 100644 --- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc +++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.cc @@ -439,8 +439,8 @@ tLayer *grease_pencil_layer_cache_add(Instance *inst, PassSimple &pass = *tgp_layer->geom_ps; - GPUTexture **depth_tex = (is_in_front) ? &inst->dummy_depth : &inst->scene_depth_tx; - GPUTexture **mask_tex = (is_masked) ? &inst->mask_tx : &inst->dummy_tx; + gpu::Texture **depth_tex = (is_in_front) ? &inst->dummy_depth : &inst->scene_depth_tx; + gpu::Texture **mask_tex = (is_masked) ? &inst->mask_tx : &inst->dummy_tx; DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_BLEND_ALPHA_PREMUL; /* For 2D mode, we render all strokes with uniform depth (increasing with stroke id). */ diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.cc b/source/blender/draw/engines/gpencil/gpencil_draw_data.cc index 0f89770a05f..d4035ee36c2 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_data.cc +++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.cc @@ -42,10 +42,10 @@ static MaterialPool *gpencil_material_pool_add(Instance *inst) return matpool; } -static GPUTexture *gpencil_image_texture_get(::Image *image, bool *r_alpha_premult) +static gpu::Texture *gpencil_image_texture_get(::Image *image, bool *r_alpha_premult) { ImageUser iuser = {nullptr}; - GPUTexture *gpu_tex = nullptr; + gpu::Texture *gpu_tex = nullptr; gpu_tex = BKE_image_get_gpu_texture(image, &iuser); *r_alpha_premult = (gpu_tex) ? (image->alpha_mode == IMA_ALPHA_PREMUL) : false; @@ -302,8 +302,8 @@ MaterialPool *gpencil_material_pool_create(Instance *inst, void gpencil_material_resources_get(MaterialPool *first_pool, int mat_id, - GPUTexture **r_tex_stroke, - GPUTexture **r_tex_fill, + gpu::Texture **r_tex_stroke, + gpu::Texture **r_tex_fill, GPUUniformBuf **r_ubo_mat) { MaterialPool *matpool = first_pool; diff --git a/source/blender/draw/engines/gpencil/gpencil_engine_c.cc b/source/blender/draw/engines/gpencil/gpencil_engine_c.cc index cc3e4126617..7f2f06aa902 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine_c.cc +++ b/source/blender/draw/engines/gpencil/gpencil_engine_c.cc @@ -350,8 +350,8 @@ tObject *Instance::object_sync_do(Object *ob, ResourceHandleRange res_handle) int mat_ofs = 0; MaterialPool *matpool = gpencil_material_pool_create(this, ob, &mat_ofs, is_vertex_mode); - GPUTexture *tex_fill = this->dummy_tx; - GPUTexture *tex_stroke = this->dummy_tx; + gpu::Texture *tex_fill = this->dummy_tx; + gpu::Texture *tex_stroke = this->dummy_tx; gpu::Batch *iter_geom = nullptr; PassSimple *last_pass = nullptr; @@ -503,8 +503,8 @@ tObject *Instance::object_sync_do(Object *ob, ResourceHandleRange res_handle) } GPUUniformBuf *new_ubo_mat; - GPUTexture *new_tex_fill = nullptr; - GPUTexture *new_tex_stroke = nullptr; + gpu::Texture *new_tex_fill = nullptr; + gpu::Texture *new_tex_stroke = nullptr; gpencil_material_resources_get( matpool, mat_ofs + material_index, &new_tex_stroke, &new_tex_fill, &new_ubo_mat); diff --git a/source/blender/draw/engines/gpencil/gpencil_engine_private.hh b/source/blender/draw/engines/gpencil/gpencil_engine_private.hh index c5df691c60d..e82b766f486 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine_private.hh +++ b/source/blender/draw/engines/gpencil/gpencil_engine_private.hh @@ -45,14 +45,14 @@ namespace blender::draw::gpencil { struct MaterialPool { /* Single linked-list. */ - struct MaterialPool *next; + MaterialPool *next; /* GPU representation of materials. */ gpMaterial mat_data[GPENCIL_MATERIAL_BUFFER_LEN]; /* Matching ubo. */ - struct GPUUniformBuf *ubo; + GPUUniformBuf *ubo; /* Texture per material. NULL means none. */ - struct GPUTexture *tex_fill[GPENCIL_MATERIAL_BUFFER_LEN]; - struct GPUTexture *tex_stroke[GPENCIL_MATERIAL_BUFFER_LEN]; + gpu::Texture *tex_fill[GPENCIL_MATERIAL_BUFFER_LEN]; + gpu::Texture *tex_stroke[GPENCIL_MATERIAL_BUFFER_LEN]; /* Number of material used in this pool. */ int used_count; }; @@ -209,13 +209,13 @@ struct Instance final : public DrawEngine { * pass rendering to avoid generating infinite lists. */ bool is_sorted; /* Pointer to dtxl->depth */ - GPUTexture *scene_depth_tx; + gpu::Texture *scene_depth_tx; GPUFrameBuffer *scene_fb; /* Used for render accumulation antialiasing. */ Texture accumulation_tx = {"gp_accumulation_tx"}; Framebuffer accumulation_fb = {"gp_accumulation_fb"}; /* Copy of txl->dummy_tx */ - GPUTexture *dummy_tx; + gpu::Texture *dummy_tx; /* Copy of v3d->shading.single_color. */ float v3d_single_color[3]; /* Copy of v3d->shading.color_type or -1 to ignore. */ @@ -353,8 +353,8 @@ struct Instance final : public DrawEngine { struct VfxFramebufferRef { /* These may not be allocated yet, use address of future pointer. */ GPUFrameBuffer **fb; - GPUTexture **color_tx; - GPUTexture **reveal_tx; + gpu::Texture **color_tx; + gpu::Texture **reveal_tx; }; SwapChain vfx_swapchain_; @@ -425,8 +425,8 @@ MaterialPool *gpencil_material_pool_create(Instance *inst, bool is_vertex_mode); void gpencil_material_resources_get(MaterialPool *first_pool, int mat_id, - struct GPUTexture **r_tex_stroke, - struct GPUTexture **r_tex_fill, + gpu::Texture **r_tex_stroke, + gpu::Texture **r_tex_fill, struct GPUUniformBuf **r_ubo_mat); void gpencil_light_ambient_add(LightPool *lightpool, const float color[3]); diff --git a/source/blender/draw/engines/image/image_drawing_mode.cc b/source/blender/draw/engines/image/image_drawing_mode.cc index a72ba1d70da..bf7c32271df 100644 --- a/source/blender/draw/engines/image/image_drawing_mode.cc +++ b/source/blender/draw/engines/image/image_drawing_mode.cc @@ -148,7 +148,7 @@ void ScreenSpaceDrawingMode::do_partial_update( if (info.need_full_update) { continue; } - GPUTexture *texture = info.texture; + gpu::Texture *texture = info.texture; const float texture_width = GPU_texture_width(texture); const float texture_height = GPU_texture_height(texture); /* TODO: early bound check. */ diff --git a/source/blender/draw/engines/overlay/overlay_armature.hh b/source/blender/draw/engines/overlay/overlay_armature.hh index 364c6d0c5d1..3c685921ce7 100644 --- a/source/blender/draw/engines/overlay/overlay_armature.hh +++ b/source/blender/draw/engines/overlay/overlay_armature.hh @@ -163,7 +163,7 @@ class Armatures : Overlay { /* Draw bone outlines and custom shape wire with a specific alpha. */ const bool use_wire_alpha = (wire_alpha < 1.0f); - GPUTexture **depth_tex = (state.xray_enabled) ? &res.depth_tx : &res.dummy_depth_tx; + gpu::Texture **depth_tex = (state.xray_enabled) ? &res.depth_tx : &res.dummy_depth_tx; armature_ps_.init(); armature_ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf); diff --git a/source/blender/draw/engines/overlay/overlay_camera.hh b/source/blender/draw/engines/overlay/overlay_camera.hh index 434515525d4..15d79563a41 100644 --- a/source/blender/draw/engines/overlay/overlay_camera.hh +++ b/source/blender/draw/engines/overlay/overlay_camera.hh @@ -588,7 +588,7 @@ class Cameras : Overlay { float4x4 mat; /* retrieve the image we want to show, continue to next when no image could be found */ - GPUTexture *tex = image_camera_background_texture_get( + gpu::Texture *tex = image_camera_background_texture_get( bgpic, state, res, aspect, use_alpha_premult, use_view_transform); if (tex) { @@ -680,17 +680,17 @@ class Cameras : Overlay { rmat = translate * rotate * scale; } - GPUTexture *image_camera_background_texture_get(const CameraBGImage *bgpic, - const State &state, - Resources &res, - float &r_aspect, - bool &r_use_alpha_premult, - bool &r_use_view_transform) + gpu::Texture *image_camera_background_texture_get(const CameraBGImage *bgpic, + const State &state, + Resources &res, + float &r_aspect, + bool &r_use_alpha_premult, + bool &r_use_view_transform) { ::Image *image = bgpic->ima; ImageUser *iuser = (ImageUser *)&bgpic->iuser; MovieClip *clip = nullptr; - GPUTexture *tex = nullptr; + gpu::Texture *tex = nullptr; float aspect_x, aspect_y; int width, height; int ctime = int(DEG_get_ctime(state.depsgraph)); diff --git a/source/blender/draw/engines/overlay/overlay_empty.hh b/source/blender/draw/engines/overlay/overlay_empty.hh index 37b283c7ffd..ee397e3e9f9 100644 --- a/source/blender/draw/engines/overlay/overlay_empty.hh +++ b/source/blender/draw/engines/overlay/overlay_empty.hh @@ -265,7 +265,7 @@ class Empties : Overlay { EmptyInstanceBuf &empty_image_buf) { Object *ob = ob_ref.object; - GPUTexture *tex = nullptr; + gpu::Texture *tex = nullptr; ::Image *ima = static_cast<::Image *>(ob_ref.object->data); float4x4 mat; diff --git a/source/blender/draw/engines/overlay/overlay_grid.hh b/source/blender/draw/engines/overlay/overlay_grid.hh index c266cb75d64..7f8dd46b2e2 100644 --- a/source/blender/draw/engines/overlay/overlay_grid.hh +++ b/source/blender/draw/engines/overlay/overlay_grid.hh @@ -56,9 +56,9 @@ class Grid : Overlay { return; } - GPUTexture **depth_tx = state.xray_enabled ? &res.xray_depth_tx : &res.depth_tx; - GPUTexture **depth_infront_tx = state.use_in_front ? &res.depth_target_in_front_tx : - &res.dummy_depth_tx; + gpu::Texture **depth_tx = state.xray_enabled ? &res.xray_depth_tx : &res.depth_tx; + gpu::Texture **depth_infront_tx = state.use_in_front ? &res.depth_target_in_front_tx : + &res.dummy_depth_tx; grid_ps_.init(); grid_ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf); diff --git a/source/blender/draw/engines/overlay/overlay_mesh.hh b/source/blender/draw/engines/overlay/overlay_mesh.hh index d8b0a278d05..0709845c06e 100644 --- a/source/blender/draw/engines/overlay/overlay_mesh.hh +++ b/source/blender/draw/engines/overlay/overlay_mesh.hh @@ -134,7 +134,7 @@ class Meshes : Overlay { * Doing so lets us distinguish back-faces from front-faces. */ DRWState face_culling = (show_retopology_) ? DRW_STATE_CULL_BACK : DRWState(0); - GPUTexture **depth_tex = (state.xray_flag_enabled) ? &res.depth_tx : &res.dummy_depth_tx; + gpu::Texture **depth_tex = (state.xray_flag_enabled) ? &res.depth_tx : &res.dummy_depth_tx; { auto &pass = edit_mesh_prepass_ps_; diff --git a/source/blender/draw/engines/overlay/overlay_paint.hh b/source/blender/draw/engines/overlay/overlay_paint.hh index 408140f10ab..50e9fb14a76 100644 --- a/source/blender/draw/engines/overlay/overlay_paint.hh +++ b/source/blender/draw/engines/overlay/overlay_paint.hh @@ -139,7 +139,7 @@ class Paints : Overlay { if (show_paint_mask_) { const bool mask_premult = (paint_settings.stencil->alpha_mode == IMA_ALPHA_PREMUL); const bool mask_inverted = (paint_settings.flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV); - GPUTexture *mask_texture = BKE_image_get_gpu_texture(paint_settings.stencil, nullptr); + gpu::Texture *mask_texture = BKE_image_get_gpu_texture(paint_settings.stencil, nullptr); auto &pass = paint_mask_ps_; pass.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA, diff --git a/source/blender/draw/engines/overlay/overlay_wireframe.hh b/source/blender/draw/engines/overlay/overlay_wireframe.hh index 2f9026e46f0..50cf90884e2 100644 --- a/source/blender/draw/engines/overlay/overlay_wireframe.hh +++ b/source/blender/draw/engines/overlay/overlay_wireframe.hh @@ -62,7 +62,7 @@ class Wireframe : Overlay { const bool is_transform = (G.moving & G_TRANSFORM_OBJ) != 0; const float wire_threshold = wire_discard_threshold_get(state.overlay.wireframe_threshold); - GPUTexture **depth_tex = (state.xray_enabled) ? &res.depth_tx : &tmp_depth_tx_; + gpu::Texture **depth_tex = (state.xray_enabled) ? &res.depth_tx : &tmp_depth_tx_; if (is_selection) { depth_tex = &res.dummy_depth_tx; } diff --git a/source/blender/draw/engines/select/select_debug_engine.cc b/source/blender/draw/engines/select/select_debug_engine.cc index 6ff68fd7777..7e770ad7828 100644 --- a/source/blender/draw/engines/select/select_debug_engine.cc +++ b/source/blender/draw/engines/select/select_debug_engine.cc @@ -63,7 +63,7 @@ class Instance : public DrawEngine { void draw(blender::draw::Manager &manager) final { - GPUTexture *texture_u32 = DRW_engine_select_texture_get(); + gpu::Texture *texture_u32 = DRW_engine_select_texture_get(); if (texture_u32 == nullptr) { return; } diff --git a/source/blender/draw/engines/select/select_engine.cc b/source/blender/draw/engines/select/select_engine.cc index bf6b6105427..55feef2a93d 100644 --- a/source/blender/draw/engines/select/select_engine.cc +++ b/source/blender/draw/engines/select/select_engine.cc @@ -63,7 +63,7 @@ struct Instance : public DrawEngine { public: struct StaticData { GPUFrameBuffer *framebuffer_select_id; - GPUTexture *texture_u32; + blender::gpu::Texture *texture_u32; struct Shaders { /* Depth Pre Pass */ @@ -521,7 +521,7 @@ GPUFrameBuffer *DRW_engine_select_framebuffer_get() return e_data.framebuffer_select_id; } -GPUTexture *DRW_engine_select_texture_get() +blender::gpu::Texture *DRW_engine_select_texture_get() { Instance::StaticData &e_data = Instance::StaticData::get(); return e_data.texture_u32; diff --git a/source/blender/draw/engines/select/select_engine.hh b/source/blender/draw/engines/select/select_engine.hh index 1c2b4a7ea16..b5fb5fd95b7 100644 --- a/source/blender/draw/engines/select/select_engine.hh +++ b/source/blender/draw/engines/select/select_engine.hh @@ -29,7 +29,7 @@ struct Engine : public DrawEngine::Pointer { struct SELECTID_Context *DRW_select_engine_context_get(); struct GPUFrameBuffer *DRW_engine_select_framebuffer_get(); -struct GPUTexture *DRW_engine_select_texture_get(); +blender::gpu::Texture *DRW_engine_select_texture_get(); /* select_instance.cc */ diff --git a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc index 23888013bb5..1ee777cb34d 100644 --- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc +++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc @@ -241,7 +241,7 @@ void AntiAliasingPass::draw(const DRWContext *draw_ctx, View &view, const SceneState &scene_state, SceneResources &resources, - GPUTexture *depth_in_front_tx) + gpu::Texture *depth_in_front_tx) { if (resources.depth_in_front_tx.is_valid() && scene_state.sample == 0) { overlay_depth_fb_.ensure(GPU_ATTACHMENT_TEXTURE(resources.depth_tx)); diff --git a/source/blender/draw/engines/workbench/workbench_engine.cc b/source/blender/draw/engines/workbench/workbench_engine.cc index 9409878b20d..eaf6f01ab6c 100644 --- a/source/blender/draw/engines/workbench/workbench_engine.cc +++ b/source/blender/draw/engines/workbench/workbench_engine.cc @@ -434,9 +434,9 @@ class Instance : public DrawEngine { } void draw(Manager &manager, - GPUTexture *depth_tx, - GPUTexture *depth_in_front_tx, - GPUTexture *color_tx) + gpu::Texture *depth_tx, + gpu::Texture *depth_in_front_tx, + gpu::Texture *color_tx) { int2 resolution = scene_state_.resolution; @@ -492,9 +492,9 @@ class Instance : public DrawEngine { } void draw_viewport(Manager &manager, - GPUTexture *depth_tx, - GPUTexture *depth_in_front_tx, - GPUTexture *color_tx) + gpu::Texture *depth_tx, + gpu::Texture *depth_in_front_tx, + gpu::Texture *color_tx) { this->draw(manager, depth_tx, depth_in_front_tx, color_tx); @@ -518,9 +518,9 @@ class Instance : public DrawEngine { } void draw_image_render(Manager &manager, - GPUTexture *depth_tx, - GPUTexture *depth_in_front_tx, - GPUTexture *color_tx, + gpu::Texture *depth_tx, + gpu::Texture *depth_in_front_tx, + gpu::Texture *color_tx, RenderEngine *engine = nullptr) { if (scene_state_.render_finished) { diff --git a/source/blender/draw/engines/workbench/workbench_private.hh b/source/blender/draw/engines/workbench/workbench_private.hh index 48c943f0dd9..4be7dff0784 100644 --- a/source/blender/draw/engines/workbench/workbench_private.hh +++ b/source/blender/draw/engines/workbench/workbench_private.hh @@ -279,7 +279,7 @@ struct SceneResources { class MeshPass : public PassMain { private: struct TextureSubPassKey { - GPUTexture *texture; + gpu::Texture *texture; GPUSamplerState sampler_state; eGeometryType geom_type; @@ -332,7 +332,7 @@ class OpaquePass { TextureFromPool gbuffer_material_tx = {"gbuffer_material_tx"}; Texture shadow_depth_stencil_tx = {"shadow_depth_stencil_tx"}; - GPUTexture *deferred_ps_stencil_tx = nullptr; + gpu::Texture *deferred_ps_stencil_tx = nullptr; MeshPass gbuffer_ps_ = {"Opaque.Gbuffer"}; MeshPass gbuffer_in_front_ps_ = {"Opaque.GbufferInFront"}; @@ -441,7 +441,7 @@ class ShadowPass { void draw(Manager &manager, View &view, SceneResources &resources, - GPUTexture &depth_stencil_tx, + gpu::Texture &depth_stencil_tx, /* Needed when there are opaque "In Front" objects in the scene */ bool force_fail_method); @@ -458,7 +458,7 @@ class VolumePass { Texture dummy_volume_tx_ = {"Volume.Dummy Volume Tx"}; Texture dummy_coba_tx_ = {"Volume.Dummy Coba Tx"}; - GPUTexture *stencil_tx_ = nullptr; + gpu::Texture *stencil_tx_ = nullptr; public: void sync(SceneResources &resources); @@ -600,7 +600,7 @@ class AntiAliasingPass { SceneResources &resources, /** Passed directly since we may need to copy back the results from the first sample, * and resources.depth_in_front_tx is only valid when mesh passes have to draw to it. */ - GPUTexture *depth_in_front_tx); + gpu::Texture *depth_in_front_tx); }; } // namespace blender::workbench diff --git a/source/blender/draw/engines/workbench/workbench_shadow.cc b/source/blender/draw/engines/workbench/workbench_shadow.cc index aa701bf9098..393091affdb 100644 --- a/source/blender/draw/engines/workbench/workbench_shadow.cc +++ b/source/blender/draw/engines/workbench/workbench_shadow.cc @@ -428,7 +428,7 @@ void ShadowPass::object_sync(SceneState &scene_state, void ShadowPass::draw(Manager &manager, View &view, SceneResources &resources, - GPUTexture &depth_stencil_tx, + gpu::Texture &depth_stencil_tx, bool force_fail_method) { if (!enabled_) { diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh index 615e4774edd..e18933b90be 100644 --- a/source/blender/draw/intern/DRW_gpu_wrapper.hh +++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh @@ -41,17 +41,17 @@ * Data can be accessed just like a normal T object. * * `draw::Texture` - * A simple wrapper to #GPUTexture. A #draw::Texture can be created without allocation. - * The `ensure_[1d|2d|3d|cube][_array]()` method is here to make sure the underlying texture - * will meet the requirements and create (or recreate) the #GPUTexture if needed. + * A simple wrapper to #gpu::Texture. A #draw::Texture can be created without + * allocation. The `ensure_[1d|2d|3d|cube][_array]()` method is here to make sure the underlying + * texture will meet the requirements and create (or recreate) the #gpu::Texture if + * needed. * * `draw::TextureFromPool` - * A GPUTexture from the viewport texture pool. This texture can be shared with other engines - * and its content is undefined when acquiring it. - * A #draw::TextureFromPool is acquired for rendering using `acquire()` and released once the - * rendering is done using `release()`. The same texture can be acquired & released multiple - * time in one draw loop. - * The `sync()` method *MUST* be called once during the cache populate (aka: Sync) phase. + * A gpu::Texture from the viewport texture pool. This texture can be shared with other + * engines and its content is undefined when acquiring it. A #draw::TextureFromPool is acquired for + * rendering using `acquire()` and released once the rendering is done using `release()`. The same + * texture can be acquired & released multiple time in one draw loop. The `sync()` method *MUST* be + * called once during the cache populate (aka: Sync) phase. * * `draw::Framebuffer` * Simple wrapper to #GPUFramebuffer that can be moved. @@ -524,11 +524,11 @@ class StorageBuffer : public T, public detail::StorageCommon class Texture : NonCopyable { protected: - GPUTexture *tx_ = nullptr; - GPUTexture *stencil_view_ = nullptr; - Vector mip_views_; - Vector layer_views_; - GPUTexture *layer_range_view_ = nullptr; + gpu::Texture *tx_ = nullptr; + gpu::Texture *stencil_view_ = nullptr; + Vector mip_views_; + Vector layer_views_; + gpu::Texture *layer_range_view_ = nullptr; const char *name_; public: @@ -599,25 +599,25 @@ class Texture : NonCopyable { free(); } - GPUTexture *gpu_texture() + gpu::Texture *gpu_texture() { return tx_; } /* To be able to use it with DRW_shgroup_uniform_texture(). */ - operator GPUTexture *() const + operator gpu::Texture *() const { BLI_assert(tx_ != nullptr); return tx_; } /* To be able to use it with DRW_shgroup_uniform_texture_ref(). */ - GPUTexture **operator&() + gpu::Texture **operator&() { return &tx_; } - /** WORKAROUND: used when needing a ref to the Texture and not the GPUTexture. */ + /** WORKAROUND: used when needing a ref to the Texture and not the gpu::Texture. */ Texture *ptr() { return this; @@ -749,7 +749,7 @@ class Texture : NonCopyable { { int mip_len = GPU_texture_mip_count(tx_); if (mip_views_.size() != mip_len) { - for (GPUTexture *&view : mip_views_) { + for (gpu::Texture *&view : mip_views_) { GPU_TEXTURE_FREE_SAFE(view); } eGPUTextureFormat format = GPU_texture_format(tx_); @@ -762,7 +762,7 @@ class Texture : NonCopyable { return false; } - GPUTexture *mip_view(int miplvl) + gpu::Texture *mip_view(int miplvl) { BLI_assert_msg(miplvl < mip_views_.size(), "Incorrect mip level requested. " @@ -784,7 +784,7 @@ class Texture : NonCopyable { { int layer_len = GPU_texture_layer_count(tx_); if (layer_views_.size() != layer_len) { - for (GPUTexture *&view : layer_views_) { + for (gpu::Texture *&view : layer_views_) { GPU_TEXTURE_FREE_SAFE(view); } eGPUTextureFormat format = GPU_texture_format(tx_); @@ -797,12 +797,12 @@ class Texture : NonCopyable { return false; } - GPUTexture *layer_view(int layer) + gpu::Texture *layer_view(int layer) { return layer_views_[layer]; } - GPUTexture *stencil_view(bool cube_as_array = false) + gpu::Texture *stencil_view(bool cube_as_array = false) { if (stencil_view_ == nullptr) { eGPUTextureFormat format = GPU_texture_format(tx_); @@ -821,7 +821,7 @@ class Texture : NonCopyable { * IMPORTANT: It is not recreated if the layer_start is different from the last call. * IMPORTANT: If this view is recreated any reference to it should be updated. */ - GPUTexture *layer_range_view(int layer_start, int layer_len, bool cube_as_array = false) + gpu::Texture *layer_range_view(int layer_start, int layer_len, bool cube_as_array = false) { BLI_assert(this->is_valid()); /* Make sure the range is valid as the GPU_texture_layer_count only returns the effective @@ -986,10 +986,10 @@ class Texture : NonCopyable { protected: void free_texture_views() { - for (GPUTexture *&view : mip_views_) { + for (gpu::Texture *&view : mip_views_) { GPU_TEXTURE_FREE_SAFE(view); } - for (GPUTexture *&view : layer_views_) { + for (gpu::Texture *&view : layer_views_) { GPU_TEXTURE_FREE_SAFE(view); } GPU_TEXTURE_FREE_SAFE(stencil_view_); @@ -1031,15 +1031,15 @@ class Texture : NonCopyable { return false; } - GPUTexture *create(int w, - int h, - int d, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data, - bool layered, - bool cubemap) + gpu::Texture *create(int w, + int h, + int d, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data, + bool layered, + bool cubemap) { if (h == 0) { return GPU_texture_create_1d(name_, w, mip_len, format, usage, data); @@ -1110,7 +1110,7 @@ class TextureFromPool : public Texture, NonMovable { Texture::swap(a, b); } - /** WORKAROUND: used when needing a ref to the Texture and not the GPUTexture. */ + /** WORKAROUND: used when needing a ref to the Texture and not the gpu::Texture. */ TextureFromPool *ptr() { return this; @@ -1128,9 +1128,9 @@ class TextureFromPool : public Texture, NonMovable { delete; void filter_mode(bool) = delete; void free() = delete; - GPUTexture *mip_view(int) = delete; - GPUTexture *layer_view(int) = delete; - GPUTexture *stencil_view() = delete; + gpu::Texture *mip_view(int) = delete; + gpu::Texture *layer_view(int) = delete; + gpu::Texture *stencil_view() = delete; }; class TextureRef : public Texture { @@ -1142,7 +1142,7 @@ class TextureRef : public Texture { this->tx_ = nullptr; } - void wrap(GPUTexture *tex) + void wrap(gpu::Texture *tex) { if (assign_if_different(this->tx_, tex)) { free_texture_views(); @@ -1159,35 +1159,35 @@ class TextureRef : public Texture { bool ensure_cube_array(int, int, int, eGPUTextureFormat, const float *) = delete; void filter_mode(bool) = delete; void free() = delete; - GPUTexture *mip_view(int) = delete; - GPUTexture *layer_view(int) = delete; - GPUTexture *stencil_view() = delete; + gpu::Texture *mip_view(int) = delete; + gpu::Texture *layer_view(int) = delete; + gpu::Texture *stencil_view() = delete; }; /** * Dummy type to bind texture as image. - * It is just a GPUTexture in disguise. + * It is just a gpu::Texture in disguise. */ class Image {}; -static inline Image *as_image(GPUTexture *tex) +static inline Image *as_image(gpu::Texture *tex) { return reinterpret_cast(tex); } -static inline Image **as_image(GPUTexture **tex) +static inline Image **as_image(gpu::Texture **tex) { return reinterpret_cast(tex); } -static inline GPUTexture *as_texture(Image *img) +static inline gpu::Texture *as_texture(Image *img) { - return reinterpret_cast(img); + return reinterpret_cast(img); } -static inline GPUTexture **as_texture(Image **img) +static inline gpu::Texture **as_texture(Image **img) { - return reinterpret_cast(img); + return reinterpret_cast(img); } /** \} */ diff --git a/source/blender/draw/intern/DRW_render.hh b/source/blender/draw/intern/DRW_render.hh index 1911b0b7c6b..4090dfd5791 100644 --- a/source/blender/draw/intern/DRW_render.hh +++ b/source/blender/draw/intern/DRW_render.hh @@ -22,7 +22,8 @@ namespace blender::gpu { class Batch; -} +class Texture; +} // namespace blender::gpu struct ARegion; struct bContext; struct Depsgraph; @@ -31,7 +32,6 @@ struct DefaultTextureList; struct DupliObject; struct GPUMaterial; struct GPUShader; -struct GPUTexture; struct GPUUniformBuf; struct Mesh; struct Object; diff --git a/source/blender/draw/intern/draw_cache.hh b/source/blender/draw/intern/draw_cache.hh index 38f1d80d482..7a3133883c6 100644 --- a/source/blender/draw/intern/draw_cache.hh +++ b/source/blender/draw/intern/draw_cache.hh @@ -14,8 +14,8 @@ #include "BKE_volume_grid_fwd.hh" struct GPUMaterial; -struct GPUTexture; namespace blender::gpu { +class Texture; class Batch; class VertBuf; } // namespace blender::gpu @@ -129,7 +129,7 @@ struct DRWVolumeGrid { char *name; /* 3D texture. */ - GPUTexture *texture; + gpu::Texture *texture; /* Transform between 0..1 texture space and object space. */ float4x4 texture_to_object; diff --git a/source/blender/draw/intern/draw_cache_impl_particles.cc b/source/blender/draw/intern/draw_cache_impl_particles.cc index b27b0731377..ce6b7025b2a 100644 --- a/source/blender/draw/intern/draw_cache_impl_particles.cc +++ b/source/blender/draw/intern/draw_cache_impl_particles.cc @@ -938,7 +938,7 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit MEM_SAFE_FREE(cache->col_layer_names); cache->proc_col_buf = MEM_calloc_arrayN(cache->num_col_layers, "proc_col_buf"); - cache->col_tex = MEM_calloc_arrayN(cache->num_col_layers, "col_tex"); + cache->col_tex = MEM_calloc_arrayN(cache->num_col_layers, "col_tex"); cache->col_layer_names = MEM_calloc_arrayN(cache->num_col_layers, "col_layer_names"); diff --git a/source/blender/draw/intern/draw_color_management.hh b/source/blender/draw/intern/draw_color_management.hh index 7494ad7fe5b..206faea18d8 100644 --- a/source/blender/draw/intern/draw_color_management.hh +++ b/source/blender/draw/intern/draw_color_management.hh @@ -8,7 +8,9 @@ #pragma once -struct GPUTexture; +namespace blender::gpu { +class Texture; +} struct GPUViewport; struct DRWContext; diff --git a/source/blender/draw/intern/draw_command.hh b/source/blender/draw/intern/draw_command.hh index e977d0f9b2a..bdd4fb3a7a9 100644 --- a/source/blender/draw/intern/draw_command.hh +++ b/source/blender/draw/intern/draw_command.hh @@ -184,8 +184,8 @@ struct ResourceBind { GPUStorageBuf *storage_buf; GPUStorageBuf **storage_buf_ref; /** NOTE: Texture is used for both Sampler and Image binds. */ - GPUTexture *texture; - GPUTexture **texture_ref; + gpu::Texture *texture; + gpu::Texture **texture_ref; gpu::VertBuf *vertex_buf; gpu::VertBuf **vertex_buf_ref; gpu::IndexBuf *index_buf; @@ -218,9 +218,9 @@ struct ResourceBind { : slot(slot_), is_reference(false), type(Type::Image), texture(draw::as_texture(res)){}; ResourceBind(int slot_, draw::Image **res) : slot(slot_), is_reference(true), type(Type::Image), texture_ref(draw::as_texture(res)){}; - ResourceBind(int slot_, GPUTexture *res, GPUSamplerState state) + ResourceBind(int slot_, gpu::Texture *res, GPUSamplerState state) : sampler(state), slot(slot_), is_reference(false), type(Type::Sampler), texture(res){}; - ResourceBind(int slot_, GPUTexture **res, GPUSamplerState state) + ResourceBind(int slot_, gpu::Texture **res, GPUSamplerState state) : sampler(state), slot(slot_), is_reference(true), type(Type::Sampler), texture_ref(res){}; ResourceBind(int slot_, gpu::VertBuf *res) : slot(slot_), is_reference(false), type(Type::BufferSampler), vertex_buf(res){}; diff --git a/source/blender/draw/intern/draw_common_c.hh b/source/blender/draw/intern/draw_common_c.hh index cb204dbe73e..bba37db268b 100644 --- a/source/blender/draw/intern/draw_common_c.hh +++ b/source/blender/draw/intern/draw_common_c.hh @@ -10,12 +10,12 @@ struct FluidModifierData; struct GPUMaterial; -struct GPUTexture; struct GPUUniformBuf; namespace blender::gpu { +class Texture; class VertBuf; -} +} // namespace blender::gpu struct ModifierData; struct Object; struct ParticleSystem; diff --git a/source/blender/draw/intern/draw_context.cc b/source/blender/draw/intern/draw_context.cc index 598c17279f0..34394814649 100644 --- a/source/blender/draw/intern/draw_context.cc +++ b/source/blender/draw/intern/draw_context.cc @@ -1577,7 +1577,7 @@ void DRW_render_set_time(RenderEngine *engine, Depsgraph *depsgraph, int frame, static struct DRWSelectBuffer { GPUFrameBuffer *framebuffer_depth_only; - GPUTexture *texture_depth; + blender::gpu::Texture *texture_depth; } g_select_buffer = {nullptr}; static void draw_select_framebuffer_depth_only_setup(const int size[2]) @@ -1820,7 +1820,7 @@ void DRW_draw_depth_loop(Depsgraph *depsgraph, }); /* Setup frame-buffer. */ - GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); + blender::gpu::Texture *depth_tx = GPU_viewport_depth_texture(viewport); GPUFrameBuffer *depth_fb = nullptr; GPU_framebuffer_ensure_config(&depth_fb, { diff --git a/source/blender/draw/intern/draw_fluid.cc b/source/blender/draw/intern/draw_fluid.cc index 6e94d6da428..d2860161044 100644 --- a/source/blender/draw/intern/draw_fluid.cc +++ b/source/blender/draw/intern/draw_fluid.cc @@ -92,7 +92,7 @@ static void create_color_ramp(const ColorBand *coba, float *data) } } -static GPUTexture *create_transfer_function(int type, const ColorBand *coba) +static blender::gpu::Texture *create_transfer_function(int type, const ColorBand *coba) { float *data = (float *)MEM_mallocN(sizeof(float[4]) * TFUNC_WIDTH, __func__); @@ -105,7 +105,7 @@ static GPUTexture *create_transfer_function(int type, const ColorBand *coba) break; } - GPUTexture *tex = GPU_texture_create_1d( + blender::gpu::Texture *tex = GPU_texture_create_1d( "transf_func", TFUNC_WIDTH, 1, GPU_SRGB8_A8, GPU_TEXTURE_USAGE_SHADER_READ, data); MEM_freeN(data); @@ -113,7 +113,7 @@ static GPUTexture *create_transfer_function(int type, const ColorBand *coba) return tex; } -static void swizzle_texture_channel_single(GPUTexture *tex) +static void swizzle_texture_channel_single(blender::gpu::Texture *tex) { /* Swizzle texture channels so that we get useful RGBA values when sampling * a texture with fewer channels, e.g. when using density as color. */ @@ -165,12 +165,12 @@ static float *rescale_3d(const int dim[3], } /* Will resize input to fit GL system limits. */ -static GPUTexture *create_volume_texture(const int dim[3], - eGPUTextureFormat texture_format, - eGPUDataFormat data_format, - const void *data) +static blender::gpu::Texture *create_volume_texture(const int dim[3], + eGPUTextureFormat texture_format, + eGPUDataFormat data_format, + const void *data) { - GPUTexture *tex = nullptr; + blender::gpu::Texture *tex = nullptr; blender::int3 final_dim = {UNPACK3(dim)}; if (data == nullptr) { @@ -223,7 +223,7 @@ static GPUTexture *create_volume_texture(const int dim[3], return tex; } -static GPUTexture *create_field_texture(FluidDomainSettings *fds, bool single_precision) +static blender::gpu::Texture *create_field_texture(FluidDomainSettings *fds, bool single_precision) { void *field = nullptr; eGPUDataFormat data_format = GPU_DATA_FLOAT; @@ -309,12 +309,12 @@ static GPUTexture *create_field_texture(FluidDomainSettings *fds, bool single_pr return nullptr; } - GPUTexture *tex = create_volume_texture(fds->res, texture_format, data_format, field); + blender::gpu::Texture *tex = create_volume_texture(fds->res, texture_format, data_format, field); swizzle_texture_channel_single(tex); return tex; } -static GPUTexture *create_density_texture(FluidDomainSettings *fds, int highres) +static blender::gpu::Texture *create_density_texture(FluidDomainSettings *fds, int highres) { int *dim = (highres) ? fds->res_noise : fds->res; @@ -330,12 +330,12 @@ static GPUTexture *create_density_texture(FluidDomainSettings *fds, int highres) return nullptr; } - GPUTexture *tex = create_volume_texture(dim, GPU_R8, GPU_DATA_FLOAT, data); + blender::gpu::Texture *tex = create_volume_texture(dim, GPU_R8, GPU_DATA_FLOAT, data); swizzle_texture_channel_single(tex); return tex; } -static GPUTexture *create_color_texture(FluidDomainSettings *fds, int highres) +static blender::gpu::Texture *create_color_texture(FluidDomainSettings *fds, int highres) { const bool has_color = (highres) ? manta_noise_has_colors(fds->fluid) : manta_smoke_has_colors(fds->fluid); @@ -359,14 +359,14 @@ static GPUTexture *create_color_texture(FluidDomainSettings *fds, int highres) manta_smoke_get_rgba(fds->fluid, data, 0); } - GPUTexture *tex = create_volume_texture(dim, GPU_RGBA8, GPU_DATA_FLOAT, data); + blender::gpu::Texture *tex = create_volume_texture(dim, GPU_RGBA8, GPU_DATA_FLOAT, data); MEM_freeN(data); return tex; } -static GPUTexture *create_flame_texture(FluidDomainSettings *fds, int highres) +static blender::gpu::Texture *create_flame_texture(FluidDomainSettings *fds, int highres) { float *source = nullptr; const bool has_fuel = (highres) ? manta_noise_has_fuel(fds->fluid) : @@ -384,7 +384,7 @@ static GPUTexture *create_flame_texture(FluidDomainSettings *fds, int highres) source = manta_smoke_get_flame(fds->fluid); } - GPUTexture *tex = create_volume_texture(dim, GPU_R8, GPU_DATA_FLOAT, source); + blender::gpu::Texture *tex = create_volume_texture(dim, GPU_R8, GPU_DATA_FLOAT, source); swizzle_texture_channel_single(tex); return tex; } @@ -565,7 +565,7 @@ void DRW_smoke_exit(DRWData *drw_data) * modifier is not used for display. We should share them for * all viewport in a redraw at least. */ LISTBASE_FOREACH (LinkData *, link, &drw_data->smoke_textures) { - GPU_TEXTURE_FREE_SAFE(*(GPUTexture **)link->data); + GPU_TEXTURE_FREE_SAFE(*(blender::gpu::Texture **)link->data); } BLI_freelistN(&drw_data->smoke_textures); } diff --git a/source/blender/draw/intern/draw_hair_private.hh b/source/blender/draw/intern/draw_hair_private.hh index c84eea3fc8f..aa2de04b13c 100644 --- a/source/blender/draw/intern/draw_hair_private.hh +++ b/source/blender/draw/intern/draw_hair_private.hh @@ -106,11 +106,11 @@ struct ParticleHairCache { blender::gpu::VertBuf *proc_strand_seg_buf; blender::gpu::VertBuf *proc_uv_buf[MAX_MTFACE]; - GPUTexture *uv_tex[MAX_MTFACE]; + blender::gpu::Texture *uv_tex[MAX_MTFACE]; char uv_layer_names[MAX_MTFACE][MAX_LAYER_NAME_CT][MAX_LAYER_NAME_LEN]; blender::gpu::VertBuf **proc_col_buf; - GPUTexture **col_tex; + blender::gpu::Texture **col_tex; char (*col_layer_names)[MAX_LAYER_NAME_CT][MAX_LAYER_NAME_LEN]; int num_uv_layers; diff --git a/source/blender/draw/intern/draw_manager.cc b/source/blender/draw/intern/draw_manager.cc index 89811e37fd3..82268fa7e77 100644 --- a/source/blender/draw/intern/draw_manager.cc +++ b/source/blender/draw/intern/draw_manager.cc @@ -27,7 +27,7 @@ std::atomic Manager::global_sync_counter_ = 1; Manager::~Manager() { - for (GPUTexture *texture : acquired_textures) { + for (gpu::Texture *texture : acquired_textures) { /* Decrease refcount and free if 0. */ GPU_texture_free(texture); } @@ -49,7 +49,7 @@ void Manager::begin_sync(Object *object_active) /* TODO: This means the reference is kept until further redraw or manager tear-down. Instead, * they should be released after each draw loop. But for now, mimics old DRW behavior. */ - for (GPUTexture *texture : acquired_textures) { + for (gpu::Texture *texture : acquired_textures) { /* Decrease refcount and free if 0. */ GPU_texture_free(texture); } diff --git a/source/blender/draw/intern/draw_manager.hh b/source/blender/draw/intern/draw_manager.hh index aef10b4ed64..b19d85c3163 100644 --- a/source/blender/draw/intern/draw_manager.hh +++ b/source/blender/draw/intern/draw_manager.hh @@ -99,7 +99,7 @@ class Manager { * List of textures coming from Image data-blocks. * They need to be reference-counted in order to avoid being freed in another thread. */ - Vector acquired_textures; + Vector acquired_textures; private: /** Number of sync done by managers. Used for fingerprint. */ @@ -283,7 +283,7 @@ class Manager { * Will acquire the texture using ref counting and release it after drawing. To be used for * texture coming from blender Image. */ - void acquire_texture(GPUTexture *texture) + void acquire_texture(gpu::Texture *texture) { GPU_texture_ref(texture); acquired_textures.append(texture); diff --git a/source/blender/draw/intern/draw_pass.hh b/source/blender/draw/intern/draw_pass.hh index fc0339c0727..45fb99b5221 100644 --- a/source/blender/draw/intern/draw_pass.hh +++ b/source/blender/draw/intern/draw_pass.hh @@ -346,16 +346,18 @@ class PassBase { * \note Variations using slot will not query a shader interface and can be used before * binding a shader. */ - void bind_image(const char *name, GPUTexture *image); - void bind_image(const char *name, GPUTexture **image); - void bind_image(int slot, GPUTexture *image); - void bind_image(int slot, GPUTexture **image); - void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state = sampler_auto); - void bind_texture(const char *name, GPUTexture **texture, GPUSamplerState state = sampler_auto); + void bind_image(const char *name, gpu::Texture *image); + void bind_image(const char *name, gpu::Texture **image); + void bind_image(int slot, gpu::Texture *image); + void bind_image(int slot, gpu::Texture **image); + void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state = sampler_auto); + void bind_texture(const char *name, + gpu::Texture **texture, + GPUSamplerState state = sampler_auto); void bind_texture(const char *name, gpu::VertBuf *buffer); void bind_texture(const char *name, gpu::VertBuf **buffer); - void bind_texture(int slot, GPUTexture *texture, GPUSamplerState state = sampler_auto); - void bind_texture(int slot, GPUTexture **texture, GPUSamplerState state = sampler_auto); + void bind_texture(int slot, gpu::Texture *texture, GPUSamplerState state = sampler_auto); + void bind_texture(int slot, gpu::Texture **texture, GPUSamplerState state = sampler_auto); void bind_texture(int slot, gpu::VertBuf *buffer); void bind_texture(int slot, gpu::VertBuf **buffer); void bind_ssbo(const char *name, GPUStorageBuf *buffer); @@ -1241,7 +1243,9 @@ template inline void PassBase::bind_ubo(const char *name, GPUUniform } template -inline void PassBase::bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state) +inline void PassBase::bind_texture(const char *name, + gpu::Texture *texture, + GPUSamplerState state) { BLI_assert(texture != nullptr); this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), texture, state); @@ -1259,7 +1263,7 @@ template inline void PassBase::bind_texture(const char *name, gpu::V this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), buffer); } -template inline void PassBase::bind_image(const char *name, GPUTexture *image) +template inline void PassBase::bind_image(const char *name, gpu::Texture *image) { BLI_assert(image != nullptr); this->bind_image(GPU_shader_get_sampler_binding(shader_, name), image); @@ -1320,7 +1324,7 @@ template inline void PassBase::bind_ubo(int slot, GPUUniformBuf *buf } template -inline void PassBase::bind_texture(int slot, GPUTexture *texture, GPUSamplerState state) +inline void PassBase::bind_texture(int slot, gpu::Texture *texture, GPUSamplerState state) { BLI_assert(texture != nullptr); create_command(Type::ResourceBind).resource_bind = {slot, texture, state}; @@ -1338,7 +1342,7 @@ template inline void PassBase::bind_texture(int slot, gpu::VertBuf * create_command(Type::ResourceBind).resource_bind = {slot, buffer}; } -template inline void PassBase::bind_image(int slot, GPUTexture *image) +template inline void PassBase::bind_image(int slot, gpu::Texture *image) { BLI_assert(image != nullptr); create_command(Type::ResourceBind).resource_bind = {slot, as_image(image)}; @@ -1358,14 +1362,14 @@ template inline void PassBase::bind_ubo(const char *name, GPUUniform template inline void PassBase::bind_texture(const char *name, - GPUTexture **texture, + gpu::Texture **texture, GPUSamplerState state) { BLI_assert(texture != nullptr); this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), texture, state); } -template inline void PassBase::bind_image(const char *name, GPUTexture **image) +template inline void PassBase::bind_image(const char *name, gpu::Texture **image) { BLI_assert(image != nullptr); this->bind_image(GPU_shader_get_sampler_binding(shader_, name), image); @@ -1385,13 +1389,13 @@ template inline void PassBase::bind_ubo(int slot, GPUUniformBuf **bu } template -inline void PassBase::bind_texture(int slot, GPUTexture **texture, GPUSamplerState state) +inline void PassBase::bind_texture(int slot, gpu::Texture **texture, GPUSamplerState state) { BLI_assert(texture != nullptr); create_command(Type::ResourceBind).resource_bind = {slot, texture, state}; } -template inline void PassBase::bind_image(int slot, GPUTexture **image) +template inline void PassBase::bind_image(int slot, gpu::Texture **image) { BLI_assert(image != nullptr); create_command(Type::ResourceBind).resource_bind = {slot, as_image(image)}; diff --git a/source/blender/draw/intern/draw_view_data.hh b/source/blender/draw/intern/draw_view_data.hh index 2536d6b591f..d8607be0e46 100644 --- a/source/blender/draw/intern/draw_view_data.hh +++ b/source/blender/draw/intern/draw_view_data.hh @@ -35,7 +35,9 @@ class Manager; struct DRWTextStore; struct GPUFrameBuffer; -struct GPUTexture; +namespace blender::gpu { +class Texture; +} struct GPUViewport; struct ListBase; @@ -50,10 +52,10 @@ struct DefaultFramebufferList { }; struct DefaultTextureList { - GPUTexture *color; - GPUTexture *color_overlay; - GPUTexture *depth; - GPUTexture *depth_in_front; + blender::gpu::Texture *color; + blender::gpu::Texture *color_overlay; + blender::gpu::Texture *depth; + blender::gpu::Texture *depth_in_front; }; struct DRWViewData { diff --git a/source/blender/draw/intern/draw_volume.cc b/source/blender/draw/intern/draw_volume.cc index c0ba02aca0b..2a2d87fa4a4 100644 --- a/source/blender/draw/intern/draw_volume.cc +++ b/source/blender/draw/intern/draw_volume.cc @@ -77,7 +77,7 @@ struct VolumeModule { GPU_texture_extend_mode(dummy_one, GPU_SAMPLER_EXTEND_MODE_REPEAT); } - GPUTexture *grid_default_texture(eGPUDefaultValue default_value) + gpu::Texture *grid_default_texture(eGPUDefaultValue default_value) { switch (default_value) { case GPU_DEFAULT_0: @@ -155,11 +155,12 @@ PassType *volume_object_grids_init(PassType &ps, * - Grid exists and texture was loaded -> use texture. * - Grid exists but has zero size or failed to load -> use zero. * - Grid does not exist -> use default value. */ - const GPUTexture *grid_tex = (drw_grid) ? drw_grid->texture : - (volume_grid) ? module.dummy_zero : - module.grid_default_texture(attr->default_value); + const gpu::Texture *grid_tex = (drw_grid) ? drw_grid->texture : + (volume_grid) ? + module.dummy_zero : + module.grid_default_texture(attr->default_value); /* TODO(@pragma37): bind_texture const support ? */ - sub->bind_texture(attr->input_name, (GPUTexture *)grid_tex); + sub->bind_texture(attr->input_name, (gpu::Texture *)grid_tex); volume_infos.grids_xform[grid_id++] = drw_grid ? float4x4(drw_grid->object_to_texture) : float4x4::identity(); diff --git a/source/blender/editors/include/ED_view3d.hh b/source/blender/editors/include/ED_view3d.hh index 486303f8a9c..12950c6bec7 100644 --- a/source/blender/editors/include/ED_view3d.hh +++ b/source/blender/editors/include/ED_view3d.hh @@ -963,7 +963,7 @@ bool ED_view3d_depth_read_cached_seg(const ViewDepths *vd, * Returns viewport color in linear space, matching #ED_space_node_color_sample(). */ class ViewportColorSampleSession { - GPUTexture *tex = nullptr; + blender::gpu::Texture *tex = nullptr; blender::ushort4 *data = nullptr; int tex_w, tex_h; rcti valid_rect; diff --git a/source/blender/editors/screen/glutil.cc b/source/blender/editors/screen/glutil.cc index 6b92a394522..357d2ea7de8 100644 --- a/source/blender/editors/screen/glutil.cc +++ b/source/blender/editors/screen/glutil.cc @@ -71,7 +71,7 @@ void immDrawPixelsTexScaledFullSize(const IMMDrawPixelsTexState *state, const bool use_mipmap = use_filter && ((draw_width < img_w) || (draw_height < img_h)); const int mip_len = use_mipmap ? 9999 : 1; - GPUTexture *tex = GPU_texture_create_2d( + blender::gpu::Texture *tex = GPU_texture_create_2d( "immDrawPixels", img_w, img_h, mip_len, gpu_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr); const bool use_float_data = ELEM(gpu_format, GPU_RGBA16F, GPU_RGB16F, GPU_R16F); @@ -172,7 +172,7 @@ void immDrawPixelsTexTiled_scaling_clipping(IMMDrawPixelsTexState *state, eGPUDataFormat gpu_data = (use_float_data) ? GPU_DATA_FLOAT : GPU_DATA_UBYTE; size_t stride = components * ((use_float_data) ? sizeof(float) : sizeof(uchar)); - GPUTexture *tex = GPU_texture_create_2d( + blender::gpu::Texture *tex = GPU_texture_create_2d( "immDrawPixels", tex_w, tex_h, 1, gpu_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr); GPU_texture_filter_mode(tex, use_filter); diff --git a/source/blender/editors/sculpt_paint/paint_cursor.cc b/source/blender/editors/sculpt_paint/paint_cursor.cc index 8a2f856c0a8..50deaefc277 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.cc +++ b/source/blender/editors/sculpt_paint/paint_cursor.cc @@ -87,7 +87,7 @@ */ struct TexSnapshot { - GPUTexture *overlay_texture; + blender::gpu::Texture *overlay_texture; int winx; int winy; int old_size; @@ -96,7 +96,7 @@ struct TexSnapshot { }; struct CursorSnapshot { - GPUTexture *overlay_texture; + blender::gpu::Texture *overlay_texture; int size; int zoom; int curve_preset; @@ -693,8 +693,8 @@ static bool paint_draw_tex_overlay(Paint *paint, mul_v4_fl(final_color, overlay_alpha * 0.01f); immUniformColor4fv(final_color); - GPUTexture *texture = (primary) ? primary_snap.overlay_texture : - secondary_snap.overlay_texture; + blender::gpu::Texture *texture = (primary) ? primary_snap.overlay_texture : + secondary_snap.overlay_texture; GPUSamplerExtendMode extend_mode = (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) ? GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER : diff --git a/source/blender/editors/space_clip/clip_draw.cc b/source/blender/editors/space_clip/clip_draw.cc index 32d822cdc6d..de52aa30113 100644 --- a/source/blender/editors/space_clip/clip_draw.cc +++ b/source/blender/editors/space_clip/clip_draw.cc @@ -1223,13 +1223,13 @@ static void draw_plane_marker_image(Scene *scene, GPU_blend(GPU_BLEND_ALPHA); } - GPUTexture *texture = GPU_texture_create_2d("plane_marker_image", - ibuf->x, - ibuf->y, - 1, - GPU_RGBA8, - GPU_TEXTURE_USAGE_SHADER_READ, - nullptr); + blender::gpu::Texture *texture = GPU_texture_create_2d("plane_marker_image", + ibuf->x, + ibuf->y, + 1, + GPU_RGBA8, + GPU_TEXTURE_USAGE_SHADER_READ, + nullptr); GPU_texture_update(texture, GPU_DATA_UBYTE, display_buffer); GPU_texture_filter_mode(texture, false); diff --git a/source/blender/editors/space_sequencer/sequencer_preview_draw.cc b/source/blender/editors/space_sequencer/sequencer_preview_draw.cc index ad228be4ec0..0136cfa3a7f 100644 --- a/source/blender/editors/space_sequencer/sequencer_preview_draw.cc +++ b/source/blender/editors/space_sequencer/sequencer_preview_draw.cc @@ -739,7 +739,7 @@ static void sequencer_draw_scopes(const SpaceSeq &space_sequencer, ARegion ®i eGPUTextureFormat format = GPU_RGBA8; eGPUDataFormat data = GPU_DATA_UBYTE; eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "seq_display_buf", scope_image->x, scope_image->y, 1, format, usage, nullptr); GPU_texture_update(texture, data, scope_image->byte_buffer.data); GPU_texture_filter_mode(texture, false); @@ -1193,7 +1193,7 @@ static void preview_draw_overlay_begin(ARegion ®ion) * The position denotes coordinates of a rectangle used to display the texture. * The texture_coord contains UV coordinates of the input texture which are mapped to the corners * of the rectangle. */ -static void preview_draw_texture_simple(GPUTexture &texture, +static void preview_draw_texture_simple(blender::gpu::Texture &texture, const rctf &position, const rctf &texture_coord) { @@ -1220,7 +1220,7 @@ static void preview_draw_texture_simple(GPUTexture &texture, * The position denotes coordinates of a rectangle used to display the texture. * The texture_coord contains UV coordinates of the input texture which are mapped to the corners * of the rectangle. */ -static void preview_draw_texture_to_linear(GPUTexture &texture, +static void preview_draw_texture_to_linear(blender::gpu::Texture &texture, const char *texture_colorspace_name, const bool predivide, const rctf &position, @@ -1375,19 +1375,19 @@ static int get_reference_frame_offset(const Editing &editing, const RenderData & return editing.overlay_frame_ofs; } -/* Create GPUTexture from the given image buffer for drawing rendered sequencer frame on the - * color render frame buffer. +/* Create blender::gpu::Texture from the given image buffer for drawing rendered sequencer frame on + * the color render frame buffer. * * The texture format and color space matches the CPU-side buffer. * * If both float and byte buffers are missing nullptr is returned. * If channel configuration is incompatible with the texture nullptr is returned. */ -static GPUTexture *create_texture(const ImBuf &ibuf) +static blender::gpu::Texture *create_texture(const ImBuf &ibuf) { const eGPUTextureUsage texture_usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT; - GPUTexture *texture = nullptr; + blender::gpu::Texture *texture = nullptr; if (ibuf.float_buffer.data) { eGPUTextureFormat texture_format; @@ -1456,9 +1456,9 @@ static void sequencer_preview_draw_color_render(const SpaceSeq &space_sequencer, const Editing &editing, ARegion ®ion, const ImBuf *current_ibuf, - GPUTexture *current_texture, + blender::gpu::Texture *current_texture, const ImBuf *reference_ibuf, - GPUTexture *reference_texture) + blender::gpu::Texture *reference_texture) { preview_draw_color_render_begin(region); @@ -1505,8 +1505,8 @@ static void sequencer_preview_draw_overlays(const bContext *C, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings, ARegion ®ion, - GPUTexture *current_texture, - GPUTexture *reference_texture, + blender::gpu::Texture *current_texture, + blender::gpu::Texture *reference_texture, const ImBuf *overlay_ibuf, const int timeline_frame) { @@ -1667,8 +1667,8 @@ void sequencer_preview_region_draw(const bContext *C, ARegion *region) * * When non-nullptr they are to be drawn (in other words, when they are non-nullptr the * corresponding draw_current_frame and draw_reference_frame is true). */ - GPUTexture *current_texture = nullptr; - GPUTexture *reference_texture = nullptr; + blender::gpu::Texture *current_texture = nullptr; + blender::gpu::Texture *reference_texture = nullptr; /* Get image buffers before setting up GPU state for drawing. This is because * sequencer_ibuf_get() might not properly restore the state. diff --git a/source/blender/editors/space_sequencer/sequencer_thumbnails.cc b/source/blender/editors/space_sequencer/sequencer_thumbnails.cc index d0bbd09e05a..efa371726be 100644 --- a/source/blender/editors/space_sequencer/sequencer_thumbnails.cc +++ b/source/blender/editors/space_sequencer/sequencer_thumbnails.cc @@ -211,13 +211,13 @@ struct ThumbsDrawBatch { GPUUniformBuf *ubo_thumbs_ = nullptr; GPUShader *shader_ = nullptr; gpu::Batch *batch_ = nullptr; - GPUTexture *atlas_ = nullptr; + blender::gpu::Texture *atlas_ = nullptr; int binding_context_ = 0; int binding_thumbs_ = 0; int binding_image_ = 0; int thumbs_count_ = 0; - ThumbsDrawBatch(StripsDrawBatch &strips_batch, GPUTexture *atlas) + ThumbsDrawBatch(StripsDrawBatch &strips_batch, blender::gpu::Texture *atlas) : strips_batch_(strips_batch), thumbs_(GPU_SEQ_STRIP_DRAW_DATA_LEN), atlas_(atlas) { shader_ = GPU_shader_get_builtin_shader(GPU_SHADER_SEQUENCER_THUMBS); @@ -373,7 +373,7 @@ void draw_strip_thumbnails(TimelineDrawContext *ctx, IMB_freeImBuf(info.ibuf); info.ibuf = nullptr; } - GPUTexture *atlas = GPU_texture_create_2d( + blender::gpu::Texture *atlas = GPU_texture_create_2d( "thumb_atlas", tex_width, tex_height, 1, GPU_RGBA8, GPU_TEXTURE_USAGE_SHADER_READ, nullptr); GPU_texture_update(atlas, GPU_DATA_UBYTE, tex_data.data()); GPU_texture_filter_mode(atlas, true); diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index f4fbda2bda5..dd2889509cb 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -2353,7 +2353,7 @@ static void validate_object_select_id(Depsgraph *depsgraph, * synchronization (which can be very slow). */ static void view3d_gpu_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data) { - GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); + blender::gpu::Texture *depth_tx = GPU_viewport_depth_texture(viewport); GPUFrameBuffer *depth_read_fb = nullptr; GPU_framebuffer_ensure_config(&depth_read_fb, @@ -2438,7 +2438,7 @@ static ViewDepths *view3d_depths_create(ARegion *region) ViewDepths *d = MEM_callocN("ViewDepths"); GPUViewport *viewport = WM_draw_region_get_viewport(region); - GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); + blender::gpu::Texture *depth_tx = GPU_viewport_depth_texture(viewport); d->w = GPU_texture_width(depth_tx); d->h = GPU_texture_height(depth_tx); d->depths = static_cast(GPU_texture_read(depth_tx, GPU_DATA_FLOAT, 0)); @@ -2842,7 +2842,7 @@ bool ViewportColorSampleSession::init(ARegion *region) return false; } - GPUTexture *color_tex = GPU_viewport_color_texture(viewport, 0); + blender::gpu::Texture *color_tex = GPU_viewport_color_texture(viewport, 0); if (color_tex == nullptr) { return false; } diff --git a/source/blender/gpu/GPU_framebuffer.hh b/source/blender/gpu/GPU_framebuffer.hh index f3314502d9f..c8a560c24c4 100644 --- a/source/blender/gpu/GPU_framebuffer.hh +++ b/source/blender/gpu/GPU_framebuffer.hh @@ -15,11 +15,11 @@ * `GPU_framebuffer_check_valid` is called. This means the context the `GPUFramebuffer` is bound * with is the one active when `GPU_framebuffer_bind` is called. * - * When a `GPUTexture` is attached to a `GPUFramebuffer` a reference is created. Deleting either - * does not require any unbinding. + * When a `gpu::Texture` is attached to a `GPUFramebuffer` a reference is created. + * Deleting either does not require any unbinding. * * A `GPUOffScreen` is a convenience type that holds a `GPUFramebuffer` and its associated - * `GPUTexture`s. It is useful for quick drawing surface configuration. + * `gpu::Texture`s. It is useful for quick drawing surface configuration. */ #pragma once @@ -27,7 +27,9 @@ #include "GPU_common_types.hh" #include "GPU_texture.hh" -struct GPUTexture; +namespace blender::gpu { +class Texture; +} enum eGPUFrameBufferBits { GPU_COLOR_BIT = (1 << 0), @@ -41,7 +43,7 @@ ENUM_OPERATORS(eGPUFrameBufferBits, GPU_STENCIL_BIT) constexpr static int GPU_MAX_VIEWPORTS = 16; struct GPUAttachment { - GPUTexture *tex; + blender::gpu::Texture *tex; int layer, mip; }; @@ -309,7 +311,10 @@ void GPU_framebuffer_config_array(GPUFrameBuffer *fb, const GPUAttachment *confi * DEPRECATED: Prefer using multiple #GPUFrameBuffer with different configurations with * `GPU_framebuffer_config_array()`. */ -void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *texture, int slot, int mip); +void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, + blender::gpu::Texture *texture, + int slot, + int mip); /** * Attach a single layer of an array texture mip level to a #GPUFrameBuffer. @@ -321,7 +326,7 @@ void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *texture, int * `GPU_framebuffer_config_array()`. */ void GPU_framebuffer_texture_layer_attach( - GPUFrameBuffer *fb, GPUTexture *texture, int slot, int layer, int mip); + GPUFrameBuffer *fb, blender::gpu::Texture *texture, int slot, int layer, int mip); /** * Attach a single cube-face of an cube-map texture mip level to a #GPUFrameBuffer. @@ -333,7 +338,7 @@ void GPU_framebuffer_texture_layer_attach( * `GPU_framebuffer_config_array()`. */ void GPU_framebuffer_texture_cubeface_attach( - GPUFrameBuffer *fb, GPUTexture *texture, int slot, int face, int mip); + GPUFrameBuffer *fb, blender::gpu::Texture *texture, int slot, int face, int mip); /** * Detach a texture from a #GPUFrameBuffer. The texture must be attached. @@ -341,7 +346,7 @@ void GPU_framebuffer_texture_cubeface_attach( * DEPRECATED: Prefer using multiple #GPUFrameBuffer with different configurations with * `GPU_framebuffer_config_array()`. */ -void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *texture); +void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, blender::gpu::Texture *texture); /** * Checks a framebuffer current configuration for errors. @@ -630,7 +635,7 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *fb, /** \name GPU OffScreen * * A `GPUOffScreen` is a convenience type that holds a `GPUFramebuffer` and its associated - * `GPUTexture`s. It is useful for quick drawing surface configuration. + * `blender::gpu::Texture`s. It is useful for quick drawing surface configuration. * NOTE: They are still limited by the same single context limitation as #GPUFrameBuffer. * \{ */ @@ -705,7 +710,7 @@ int GPU_offscreen_height(const GPUOffScreen *offscreen); * Return the color texture of a #GPUOffScreen. Does not give ownership. * \note only to be used by viewport code! */ -GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *offscreen); +blender::gpu::Texture *GPU_offscreen_color_texture(const GPUOffScreen *offscreen); /** * Return the texture format of a #GPUOffScreen. @@ -718,7 +723,7 @@ eGPUTextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen); */ void GPU_offscreen_viewport_data_get(GPUOffScreen *offscreen, GPUFrameBuffer **r_fb, - GPUTexture **r_color, - GPUTexture **r_depth); + blender::gpu::Texture **r_color, + blender::gpu::Texture **r_depth); /** \} */ diff --git a/source/blender/gpu/GPU_immediate.hh b/source/blender/gpu/GPU_immediate.hh index f5e2f5b0fcc..945c7a7333a 100644 --- a/source/blender/gpu/GPU_immediate.hh +++ b/source/blender/gpu/GPU_immediate.hh @@ -107,8 +107,8 @@ void immUniform4fv(const char *name, const float data[4]); void immUniformArray4fv(const char *bare_name, const float *data, int count); void immUniformMatrix4fv(const char *name, const float data[4][4]); -void immBindTexture(const char *name, GPUTexture *tex); -void immBindTextureSampler(const char *name, GPUTexture *tex, GPUSamplerState state); +void immBindTexture(const char *name, blender::gpu::Texture *tex); +void immBindTextureSampler(const char *name, blender::gpu::Texture *tex, GPUSamplerState state); void immBindUniformBuf(const char *name, GPUUniformBuf *ubo); /* Convenience functions for setting "uniform vec4 color". */ diff --git a/source/blender/gpu/GPU_material.hh b/source/blender/gpu/GPU_material.hh index 3b1e7253b93..c41bcfdfeab 100644 --- a/source/blender/gpu/GPU_material.hh +++ b/source/blender/gpu/GPU_material.hh @@ -22,7 +22,9 @@ struct GPUMaterial; struct GPUNodeLink; struct GPUNodeStack; struct GPUPass; -struct GPUTexture; +namespace blender::gpu { +class Texture; +} struct GPUUniformBuf; struct Image; struct ImageUser; @@ -232,8 +234,8 @@ struct GPUMaterialTexture { Image *ima; ImageUser iuser; bool iuser_available; - GPUTexture **colorband; - GPUTexture **sky; + blender::gpu::Texture **colorband; + blender::gpu::Texture **sky; char sampler_name[32]; /* Name of sampler in GLSL. */ char tiled_mapping_name[32]; /* Name of tile mapping sampler in GLSL. */ int users; diff --git a/source/blender/gpu/GPU_texture.hh b/source/blender/gpu/GPU_texture.hh index db4e4f478d4..d1c58a91cff 100644 --- a/source/blender/gpu/GPU_texture.hh +++ b/source/blender/gpu/GPU_texture.hh @@ -5,7 +5,7 @@ /** \file * \ingroup gpu * - * A `GPUTexture` is a wrapper around backend specific texture objects. + * A `blender::gpu::Texture` is a wrapper around backend specific texture objects. * It allows, creation of diverse texture format and types, update, read, reference counting, * internal sampler state tracking and texture binding. */ @@ -803,8 +803,9 @@ ENUM_OPERATORS(eGPUTextureUsage, GPU_TEXTURE_USAGE_GENERAL); /** \name Creation * \{ */ -/** Opaque type hiding blender::gpu::Texture. */ -struct GPUTexture; +namespace blender::gpu { +class Texture; +} // namespace blender::gpu /** * \note \a data is expected to be float. If the \a format is not compatible with float data or if @@ -816,80 +817,81 @@ struct GPUTexture; * * flag. \a mips is the number of mip level to allocate. It must be >= 1. */ -GPUTexture *GPU_texture_create_1d(const char *name, - int width, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data); -GPUTexture *GPU_texture_create_1d_array(const char *name, - int width, - int layer_len, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data); -GPUTexture *GPU_texture_create_2d(const char *name, - int width, - int height, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data); -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); -GPUTexture *GPU_texture_create_3d(const char *name, - int width, - int height, - int depth, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const void *data); -GPUTexture *GPU_texture_create_cube(const char *name, - int width, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data); -GPUTexture *GPU_texture_create_cube_array(const char *name, - int width, - int layer_len, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data); -/** - * DDS texture loading. Return nullptr if compressed texture support is not available. - * \a data should hold all the data for \a mip_len mipmaps. - * The data is expected to be in compressed form. This isn't going to compress un-compress data. - */ -GPUTexture *GPU_texture_create_compressed_2d(const char *name, +blender::gpu::Texture *GPU_texture_create_1d(const char *name, + int width, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data); +blender::gpu::Texture *GPU_texture_create_1d_array(const char *name, + int width, + int layer_len, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data); +blender::gpu::Texture *GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, + const float *data); +blender::gpu::Texture *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); +blender::gpu::Texture *GPU_texture_create_3d(const char *name, + int width, + int height, + int depth, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, const void *data); +blender::gpu::Texture *GPU_texture_create_cube(const char *name, + int width, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data); +blender::gpu::Texture *GPU_texture_create_cube_array(const char *name, + int width, + int layer_len, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data); +/** + * DDS texture loading. Return nullptr if compressed texture support is not available. + * \a data should hold all the data for \a mip_len mipmaps. + * The data is expected to be in compressed form. This isn't going to compress un-compress data. + */ +blender::gpu::Texture *GPU_texture_create_compressed_2d(const char *name, + int width, + int height, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const void *data); /** * Create a buffer texture that allow access to a buffer \a vertex_buf through a sampler of type * `(FLOAT/INT/UINT)_BUFFER`. */ -GPUTexture *GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vertex_buf); +blender::gpu::Texture *GPU_texture_create_from_vertbuf(const char *name, + blender::gpu::VertBuf *vertex_buf); /** * Create an error texture that will bind an pink texture at draw time. * \a dimension is the number of number of dimension of the texture (1, 2, or 3). * \a array if set to true, will make the texture be an array (layered). */ -GPUTexture *GPU_texture_create_error(int dimension, bool array); +blender::gpu::Texture *GPU_texture_create_error(int dimension, bool array); /** \} */ @@ -903,13 +905,14 @@ GPUTexture *GPU_texture_create_error(int dimension, bool array); * This avoids the texture being free between the time it is referenced by the drawing logic and * the time it is actually dereferenced. */ -void GPU_texture_ref(GPUTexture *texture); +void GPU_texture_ref(blender::gpu::Texture *texture); /** * This internally decrement the reference counter. - * If the reference counter is 1 when calling this function the #GPUTexture will be freed. + * If the reference counter is 1 when calling this function the #blender::gpu::Texture will be + * freed. */ -void GPU_texture_free(GPUTexture *texture); +void GPU_texture_free(blender::gpu::Texture *texture); #define GPU_TEXTURE_FREE_SAFE(texture) \ do { \ @@ -949,15 +952,15 @@ void GPU_texture_free(GPUTexture *texture); * * TODO(fclem): Target conversion (ex: Texture 2D as Texture 2D Array) is not implemented yet. */ -GPUTexture *GPU_texture_create_view(const char *name, - GPUTexture *source_texture, - eGPUTextureFormat view_format, - int mip_start, - int mip_len, - int layer_start, - int layer_len, - bool cube_as_array, - bool use_stencil); +blender::gpu::Texture *GPU_texture_create_view(const char *name, + blender::gpu::Texture *source_texture, + eGPUTextureFormat view_format, + int mip_start, + int mip_len, + int layer_start, + int layer_len, + bool cube_as_array, + bool use_stencil); /** \} */ @@ -982,7 +985,9 @@ void GPU_unpack_row_length_set(uint len); * \note This function only update the content of mip 0. Either specify other mips or use * `GPU_texture_update_mipmap_chain` to generate them if needed. */ -void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data); +void GPU_texture_update(blender::gpu::Texture *texture, + eGPUDataFormat data_format, + const void *data); /** * Update the content of a region of a texture's base mip-map level (mip 0). @@ -995,7 +1000,7 @@ void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const v * \a offset_x , \a offset_y , \a offset_z specify the bottom left corner of the updated region. * \a width , \a height , \a depth specify the extent of the updated region. */ -void GPU_texture_update_sub(GPUTexture *texture, +void GPU_texture_update_sub(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, @@ -1011,7 +1016,7 @@ void GPU_texture_update_sub(GPUTexture *texture, * texture storage. * The \a data should be the size of the entire \a mip_level. */ -void GPU_texture_update_mipmap(GPUTexture *texture, +void GPU_texture_update_mipmap(blender::gpu::Texture *texture, int mip_level, eGPUDataFormat data_format, const void *pixels); @@ -1024,19 +1029,21 @@ void GPU_texture_update_mipmap(GPUTexture *texture, * \note The format is float for UNORM textures. * \param data: 1 pixel worth of data to fill the texture with. */ -void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data); +void GPU_texture_clear(blender::gpu::Texture *texture, + eGPUDataFormat data_format, + const void *data); /** * Copy a \a src texture content to a similar \a dst texture. Only MIP 0 is copied. * Textures needs to match in size and format. */ -void GPU_texture_copy(GPUTexture *dst, GPUTexture *src); +void GPU_texture_copy(blender::gpu::Texture *dst, blender::gpu::Texture *src); /** * Update the mip-map levels using the mip 0 data. * \note this doesn't work on depth or compressed textures. */ -void GPU_texture_update_mipmap_chain(GPUTexture *texture); +void GPU_texture_update_mipmap_chain(blender::gpu::Texture *texture); /** * Read the content of a \a mip_level from a \a tex and returns a copy of its data. @@ -1044,7 +1051,7 @@ void GPU_texture_update_mipmap_chain(GPUTexture *texture); * \note synchronization of shader writes via `imageStore()` needs to be explicitly done using * `GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH)`. */ -void *GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_level); +void *GPU_texture_read(blender::gpu::Texture *texture, eGPUDataFormat data_format, int mip_level); /** \} */ @@ -1055,16 +1062,16 @@ void *GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_ /** * Bind a texture to a texture sampling image units using the texture internal sampler state. */ -void GPU_texture_bind(GPUTexture *texture, int unit); +void GPU_texture_bind(blender::gpu::Texture *texture, int unit); /** * Bind a texture to a texture sampling image units using the explicit sampler state. */ -void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit); +void GPU_texture_bind_ex(blender::gpu::Texture *texture, GPUSamplerState state, int unit); /** * Unbind \a tex from a texture sampling image unit. * \note this isn't strictly required but it is better for debugging purpose. */ -void GPU_texture_unbind(GPUTexture *texture); +void GPU_texture_unbind(blender::gpu::Texture *texture); /** * Unbind all texture from all texture sampling image units. */ @@ -1075,12 +1082,12 @@ void GPU_texture_unbind_all(); * It correspond to a `gpu::shader::ShaderCreateInfo::image()` declaration. * \note this overrides any previous bind on the same unit. */ -void GPU_texture_image_bind(GPUTexture *texture, int unit); +void GPU_texture_image_bind(blender::gpu::Texture *texture, int unit); /** * Unbind \a tex from an arbitrary load/store image unit. * \note this isn't strictly required but it is better for debugging purpose. */ -void GPU_texture_image_unbind(GPUTexture *texture); +void GPU_texture_image_unbind(blender::gpu::Texture *texture); /** * Unbind all texture from all arbitrary load/store image units. */ @@ -1095,7 +1102,7 @@ void GPU_texture_image_unbind_all(); /** * Set \a tex texture depth comparison mode. Only works on depth format. */ -void GPU_texture_compare_mode(GPUTexture *texture, bool use_compare); +void GPU_texture_compare_mode(blender::gpu::Texture *texture, bool use_compare); /** * Set \a tex texture filter usage. @@ -1103,7 +1110,7 @@ void GPU_texture_compare_mode(GPUTexture *texture, bool use_compare); * \note Does not work on non-normalized integer textures. * \note Does not modify the mip-map usage state. */ -void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter); +void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter); /** * Set \a tex texture filter and mip-map usage. @@ -1112,31 +1119,31 @@ void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter); * If both are set to true, the texture will use linear interpolation between mip-map levels. * \note Does not work on non-normalized integer textures. */ -void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter); +void GPU_texture_mipmap_mode(blender::gpu::Texture *texture, bool use_mipmap, bool use_filter); /** * Set anisotropic filter usage. Filter sample count is determined globally by * `U.anisotropic_filter` and updated when `GPU_samplers_update` is called. */ -void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso); +void GPU_texture_anisotropic_filter(blender::gpu::Texture *texture, bool use_aniso); /** * Set \a tex texture sampling method for coordinates outside of the [0..1] uv range along the x * axis. See GPUSamplerExtendMode for the available and meaning of different extend modes. */ -void GPU_texture_extend_mode_x(GPUTexture *texture, GPUSamplerExtendMode extend_mode); +void GPU_texture_extend_mode_x(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode); /** * Set \a tex texture sampling method for coordinates outside of the [0..1] uv range along the y * axis. See GPUSamplerExtendMode for the available and meaning of different extend modes. */ -void GPU_texture_extend_mode_y(GPUTexture *texture, GPUSamplerExtendMode extend_mode); +void GPU_texture_extend_mode_y(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode); /** * Set \a tex texture sampling method for coordinates outside of the [0..1] uv range along both the * x and y axis. See GPUSamplerExtendMode for the available and meaning of different extend modes. */ -void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode); +void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode); /** * Set \a tex texture swizzle state for swizzling sample components. @@ -1154,7 +1161,7 @@ void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mo * - '0': will make the component value to always return 0. * - '1': will make the component value to always return 1. */ -void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4]); +void GPU_texture_swizzle_set(blender::gpu::Texture *texture, const char swizzle[4]); /** \} */ @@ -1166,90 +1173,90 @@ void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4]); * Return the number of dimensions of the texture ignoring dimension of layers (1, 2 or 3). * Cube textures are considered 2D. */ -int GPU_texture_dimensions(const GPUTexture *texture); +int GPU_texture_dimensions(const blender::gpu::Texture *texture); /** * Return the width of \a tex. */ -int GPU_texture_width(const GPUTexture *texture); +int GPU_texture_width(const blender::gpu::Texture *texture); /** * Return the height of \a tex. Correspond to number of layers for 1D array texture. */ -int GPU_texture_height(const GPUTexture *texture); +int GPU_texture_height(const blender::gpu::Texture *texture); /** * Return the depth of \a tex . Correspond to number of layers for 2D array texture. * NOTE: return 0 for 1D & 2D textures. */ -int GPU_texture_depth(const GPUTexture *texture); +int GPU_texture_depth(const blender::gpu::Texture *texture); /** * Return the number of layers of \a tex. Return 1 if the texture is not layered. */ -int GPU_texture_layer_count(const GPUTexture *texture); +int GPU_texture_layer_count(const blender::gpu::Texture *texture); /** * Return the number of mip-map level inside this texture. */ -int GPU_texture_mip_count(const GPUTexture *texture); +int GPU_texture_mip_count(const blender::gpu::Texture *texture); /** * Return the texture format of \a tex. */ -eGPUTextureFormat GPU_texture_format(const GPUTexture *texture); +eGPUTextureFormat GPU_texture_format(const blender::gpu::Texture *texture); /** * Return the usage flags of \a tex. */ -eGPUTextureUsage GPU_texture_usage(const GPUTexture *texture); +eGPUTextureUsage GPU_texture_usage(const blender::gpu::Texture *texture); /** * Return true if the texture is an array texture type (has layers). */ -bool GPU_texture_is_array(const GPUTexture *texture); +bool GPU_texture_is_array(const blender::gpu::Texture *texture); /** * Return true if the texture is an cube-map texture type. */ -bool GPU_texture_is_cube(const GPUTexture *texture); +bool GPU_texture_is_cube(const blender::gpu::Texture *texture); /** * Return true if the texture format has a depth component. */ -bool GPU_texture_has_depth_format(const GPUTexture *texture); +bool GPU_texture_has_depth_format(const blender::gpu::Texture *texture); /** * Return true if the texture format has a stencil component. */ -bool GPU_texture_has_stencil_format(const GPUTexture *texture); +bool GPU_texture_has_stencil_format(const blender::gpu::Texture *texture); /** * Return true if the texture format is an integer type (non-normalized integers). */ -bool GPU_texture_has_integer_format(const GPUTexture *texture); +bool GPU_texture_has_integer_format(const blender::gpu::Texture *texture); /** * Return true if the texture format is a float type. */ -bool GPU_texture_has_float_format(const GPUTexture *texture); +bool GPU_texture_has_float_format(const blender::gpu::Texture *texture); /** * Return true if the texture format is an integer normalized type. */ -bool GPU_texture_has_normalized_format(const GPUTexture *texture); +bool GPU_texture_has_normalized_format(const blender::gpu::Texture *texture); /** * Return true if the texture format is a signed type. */ -bool GPU_texture_has_signed_format(const GPUTexture *texture); +bool GPU_texture_has_signed_format(const blender::gpu::Texture *texture); /** * Returns the pixel dimensions of a texture's mip-map level. * \a size is expected to be a pointer to a vector of dimension matching the texture's dimension * (including the array dimension). */ -void GPU_texture_get_mipmap_size(GPUTexture *texture, int mip_level, int *r_size); +void GPU_texture_get_mipmap_size(blender::gpu::Texture *texture, int mip_level, int *r_size); /** \} */ @@ -1263,19 +1270,20 @@ void GPU_texture_get_mipmap_size(GPUTexture *texture, int mip_level, int *r_size /** * Width & Height (of source data), optional. * WORKAROUND: Calling #BKE_image_get_size may free the texture. Store the source image size - * (before down-scaling) inside the #GPUTexture to retrieve the original size later (Ref #59347). + * (before down-scaling) inside the #blender::gpu::Texture to retrieve the original size later (Ref + * #59347). */ -int GPU_texture_original_width(const GPUTexture *texture); -int GPU_texture_original_height(const GPUTexture *texture); -void GPU_texture_original_size_set(GPUTexture *texture, int width, int height); +int GPU_texture_original_width(const blender::gpu::Texture *texture); +int GPU_texture_original_height(const blender::gpu::Texture *texture); +void GPU_texture_original_size_set(blender::gpu::Texture *texture, int width, int height); /** * Reference of a pointer that needs to be cleaned when deallocating the texture. * Points to #BPyGPUTexture.tex */ #ifndef GPU_NO_USE_PY_REFERENCES -void **GPU_texture_py_reference_get(GPUTexture *texture); -void GPU_texture_py_reference_set(GPUTexture *texture, void **py_ref); +void **GPU_texture_py_reference_get(blender::gpu::Texture *texture); +void GPU_texture_py_reference_set(blender::gpu::Texture *texture, void **py_ref); #endif /** \} */ @@ -1376,7 +1384,7 @@ GPUPixelBufferNativeHandle GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pi * The \a pix_buf data is expected to be contiguous and big enough to fill the described * sub-region. */ -void GPU_texture_update_sub_from_pixel_buffer(GPUTexture *texture, +void GPU_texture_update_sub_from_pixel_buffer(blender::gpu::Texture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, diff --git a/source/blender/gpu/GPU_texture_pool.hh b/source/blender/gpu/GPU_texture_pool.hh index 3620308df54..fa7eb48a87d 100644 --- a/source/blender/gpu/GPU_texture_pool.hh +++ b/source/blender/gpu/GPU_texture_pool.hh @@ -24,7 +24,7 @@ class TexturePool { static constexpr int max_unused_cycles_ = 8; struct TextureHandle { - GPUTexture *texture; + blender::gpu::Texture *texture; /* Counts the number of `reset()` call since the last use. * The texture memory is deallocated after a certain number of cycles. */ int unused_cycles; @@ -33,7 +33,7 @@ class TexturePool { /* Pool of texture ready to be reused. */ blender::Vector pool_; /* List of textures that are currently being used. Tracked to check memory leak. */ - blender::Vector acquired_; + blender::Vector acquired_; public: ~TexturePool(); @@ -43,17 +43,17 @@ class TexturePool { static TexturePool &get(); /* Acquire a texture from the pool with the given characteristics. */ - GPUTexture *acquire_texture(int width, - int height, - eGPUTextureFormat format, - eGPUTextureUsage usage); + blender::gpu::Texture *acquire_texture(int width, + int height, + eGPUTextureFormat format, + eGPUTextureUsage usage); /* Release the texture so that its memory can be reused at some other point. */ - void release_texture(GPUTexture *tmp_tex); + void release_texture(blender::gpu::Texture *tmp_tex); /* Transfer ownership of a texture from the pool to the caller. */ - void take_texture_ownership(GPUTexture *tex); + void take_texture_ownership(blender::gpu::Texture *tex); /* Transfer back ownership to the pool. The texture will become part of the pool. */ - void give_texture_ownership(GPUTexture *tex); + void give_texture_ownership(blender::gpu::Texture *tex); /* Ensure no texture is still acquired and release unused textures. * If `force_free` is true, free all the texture memory inside the pool. diff --git a/source/blender/gpu/GPU_viewport.hh b/source/blender/gpu/GPU_viewport.hh index d786b646776..37c5e044b29 100644 --- a/source/blender/gpu/GPU_viewport.hh +++ b/source/blender/gpu/GPU_viewport.hh @@ -84,9 +84,9 @@ bool GPU_viewport_do_update(GPUViewport *viewport); int GPU_viewport_active_view_get(GPUViewport *viewport); bool GPU_viewport_is_stereo_get(GPUViewport *viewport); -GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport, int view); -GPUTexture *GPU_viewport_overlay_texture(GPUViewport *viewport, int view); -GPUTexture *GPU_viewport_depth_texture(GPUViewport *viewport); +blender::gpu::Texture *GPU_viewport_color_texture(GPUViewport *viewport, int view); +blender::gpu::Texture *GPU_viewport_overlay_texture(GPUViewport *viewport, int view); +blender::gpu::Texture *GPU_viewport_depth_texture(GPUViewport *viewport); /** * Color render and overlay frame-buffers for drawing outside of DRW module. diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc index 83dcdf8cda9..c88ad7124d2 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.cc +++ b/source/blender/gpu/intern/gpu_framebuffer.cc @@ -376,29 +376,32 @@ static void gpu_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, unwrap(gpu_fb)->attachment_set(type, attachment); } -void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip) +void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, + blender::gpu::Texture *tex, + int slot, + int mip) { GPUAttachment attachment = GPU_ATTACHMENT_TEXTURE_MIP(tex, mip); gpu_framebuffer_texture_attach_ex(fb, attachment, slot); } void GPU_framebuffer_texture_layer_attach( - GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip) + GPUFrameBuffer *fb, blender::gpu::Texture *tex, int slot, int layer, int mip) { GPUAttachment attachment = GPU_ATTACHMENT_TEXTURE_LAYER_MIP(tex, layer, mip); gpu_framebuffer_texture_attach_ex(fb, attachment, slot); } void GPU_framebuffer_texture_cubeface_attach( - GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip) + GPUFrameBuffer *fb, blender::gpu::Texture *tex, int slot, int face, int mip) { GPUAttachment attachment = GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(tex, face, mip); gpu_framebuffer_texture_attach_ex(fb, attachment, slot); } -void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex) +void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, blender::gpu::Texture *tex) { - unwrap(tex)->detach_from(unwrap(fb)); + tex->detach_from(unwrap(fb)); } void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb, @@ -579,7 +582,7 @@ void GPU_framebuffer_blit(GPUFrameBuffer *gpu_fb_read, FrameBuffer *prev_fb = Context::get()->active_fb; #ifndef NDEBUG - GPUTexture *read_tex, *write_tex; + blender::gpu::Texture *read_tex, *write_tex; if (blit_buffers & (GPU_DEPTH_BIT | GPU_STENCIL_BIT)) { read_tex = fb_read->depth_tex(); write_tex = fb_write->depth_tex(); @@ -680,8 +683,8 @@ struct GPUOffScreen { GPUFrameBuffer *fb; } framebuffers[MAX_CTX_FB_LEN]; - GPUTexture *color; - GPUTexture *depth; + blender::gpu::Texture *color; + blender::gpu::Texture *depth; }; /** @@ -753,7 +756,7 @@ GPUOffScreen *GPU_offscreen_create(int width, } if ((with_depth_buffer && !ofs->depth) || !ofs->color) { - const char error[] = "GPUTexture: Texture allocation failed."; + const char error[] = "blender::gpu::Texture: Texture allocation failed."; if (err_out) { BLI_strncpy(err_out, error, 256); } @@ -868,7 +871,7 @@ int GPU_offscreen_height(const GPUOffScreen *offscreen) return GPU_texture_height(offscreen->color); } -GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *offscreen) +blender::gpu::Texture *GPU_offscreen_color_texture(const GPUOffScreen *offscreen) { return offscreen->color; } @@ -880,8 +883,8 @@ eGPUTextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen) void GPU_offscreen_viewport_data_get(GPUOffScreen *offscreen, GPUFrameBuffer **r_fb, - GPUTexture **r_color, - GPUTexture **r_depth) + blender::gpu::Texture **r_color, + blender::gpu::Texture **r_depth) { *r_fb = gpu_offscreen_fb_get(offscreen); *r_color = offscreen->color; diff --git a/source/blender/gpu/intern/gpu_framebuffer_private.hh b/source/blender/gpu/intern/gpu_framebuffer_private.hh index fda01dd69c8..b15abf028c8 100644 --- a/source/blender/gpu/intern/gpu_framebuffer_private.hh +++ b/source/blender/gpu/intern/gpu_framebuffer_private.hh @@ -15,7 +15,9 @@ #include "GPU_framebuffer.hh" -struct GPUTexture; +namespace blender::gpu { +class Texture; +} enum GPUAttachmentType : int { GPU_FB_DEPTH_ATTACHMENT = 0, @@ -231,7 +233,7 @@ class FrameBuffer { scissor_set(scissor_rect); } - GPUTexture *depth_tex() const + blender::gpu::Texture *depth_tex() const { if (attachments_[GPU_FB_DEPTH_ATTACHMENT].tex) { return attachments_[GPU_FB_DEPTH_ATTACHMENT].tex; @@ -239,7 +241,7 @@ class FrameBuffer { return attachments_[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex; }; - GPUTexture *color_tex(int slot) const + blender::gpu::Texture *color_tex(int slot) const { return attachments_[GPU_FB_COLOR_ATTACHMENT0 + slot].tex; }; diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index 3c3bb691992..244f490299b 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -628,13 +628,13 @@ void immUniform1i(const char *name, int x) GPU_shader_uniform_1i(imm->shader, name, x); } -void immBindTexture(const char *name, GPUTexture *tex) +void immBindTexture(const char *name, blender::gpu::Texture *tex) { int binding = GPU_shader_get_sampler_binding(imm->shader, name); GPU_texture_bind(tex, binding); } -void immBindTextureSampler(const char *name, GPUTexture *tex, GPUSamplerState state) +void immBindTextureSampler(const char *name, blender::gpu::Texture *tex, GPUSamplerState state) { int binding = GPU_shader_get_sampler_binding(imm->shader, name); GPU_texture_bind_ex(tex, state, binding); diff --git a/source/blender/gpu/intern/gpu_material.cc b/source/blender/gpu/intern/gpu_material.cc index 69ff26ccab7..223ad1c2485 100644 --- a/source/blender/gpu/intern/gpu_material.cc +++ b/source/blender/gpu/intern/gpu_material.cc @@ -80,11 +80,11 @@ struct GPUMaterial { /* Source material, might be null. */ Material *source_material = nullptr; /* 1D Texture array containing all color bands. */ - GPUTexture *coba_tex = nullptr; + blender::gpu::Texture *coba_tex = nullptr; /* Builder for coba_tex. */ GPUColorBandBuilder *coba_builder = nullptr; /* 2D Texture array containing all sky textures. */ - GPUTexture *sky_tex = nullptr; + blender::gpu::Texture *sky_tex = nullptr; /* Builder for sky_tex. */ GPUSkyBuilder *sky_builder = nullptr; /* Low level node graph(s). Also contains resources needed by the material. */ @@ -408,7 +408,7 @@ GPUNodeGraph *gpu_material_node_graph(GPUMaterial *material) /* Resources */ -GPUTexture **gpu_material_sky_texture_layer_set( +blender::gpu::Texture **gpu_material_sky_texture_layer_set( GPUMaterial *mat, int width, int height, const float *pixels, float *row) { /* In order to put all sky textures into one 2D array texture, @@ -437,10 +437,10 @@ GPUTexture **gpu_material_sky_texture_layer_set( return &mat->sky_tex; } -GPUTexture **gpu_material_ramp_texture_row_set(GPUMaterial *mat, - int size, - const float *pixels, - float *r_row) +blender::gpu::Texture **gpu_material_ramp_texture_row_set(GPUMaterial *mat, + int size, + const float *pixels, + float *r_row) { /* In order to put all the color-bands into one 1D array texture, * we need them to be the same size. */ diff --git a/source/blender/gpu/intern/gpu_node_graph.cc b/source/blender/gpu/intern/gpu_node_graph.cc index 84b72fdecfa..5d31cad97b2 100644 --- a/source/blender/gpu/intern/gpu_node_graph.cc +++ b/source/blender/gpu/intern/gpu_node_graph.cc @@ -485,8 +485,8 @@ static GPULayerAttr *gpu_node_graph_add_layer_attribute(GPUNodeGraph *graph, con static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph, Image *ima, ImageUser *iuser, - GPUTexture **colorband, - GPUTexture **sky, + blender::gpu::Texture **colorband, + blender::gpu::Texture **sky, bool is_tiled, GPUSamplerState sampler_state) { @@ -670,7 +670,8 @@ GPUNodeLink *GPU_image_sky(GPUMaterial *mat, float *layer, GPUSamplerState sampler_state) { - GPUTexture **sky = gpu_material_sky_texture_layer_set(mat, width, height, pixels, layer); + blender::gpu::Texture **sky = gpu_material_sky_texture_layer_set( + mat, width, height, pixels, layer); GPUNodeGraph *graph = gpu_material_node_graph(mat); GPUNodeLink *link = gpu_node_link_create(); @@ -702,7 +703,7 @@ void GPU_image_tiled(GPUMaterial *mat, GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *r_row) { - GPUTexture **colorband = gpu_material_ramp_texture_row_set(mat, size, pixels, r_row); + blender::gpu::Texture **colorband = gpu_material_ramp_texture_row_set(mat, size, pixels, r_row); MEM_freeN(pixels); GPUNodeGraph *graph = gpu_material_node_graph(mat); diff --git a/source/blender/gpu/intern/gpu_node_graph.hh b/source/blender/gpu/intern/gpu_node_graph.hh index 187ef187770..9d3921028d0 100644 --- a/source/blender/gpu/intern/gpu_node_graph.hh +++ b/source/blender/gpu/intern/gpu_node_graph.hh @@ -85,7 +85,7 @@ struct GPUNodeLink { /* GPU_NODE_LINK_CONSTANT | GPU_NODE_LINK_UNIFORM */ const float *data; /* GPU_NODE_LINK_COLORBAND */ - GPUTexture **colorband; + blender::gpu::Texture **colorband; /* GPU_NODE_LINK_OUTPUT */ GPUOutput *output; /* GPU_NODE_LINK_ATTR */ @@ -216,12 +216,12 @@ GPUNodeGraph *gpu_material_node_graph(GPUMaterial *material); /** * Returns the address of the future pointer to coba_tex. */ -GPUTexture **gpu_material_ramp_texture_row_set(GPUMaterial *mat, - int size, - const float *pixels, - float *r_row); +blender::gpu::Texture **gpu_material_ramp_texture_row_set(GPUMaterial *mat, + int size, + const float *pixels, + float *r_row); /** * Returns the address of the future pointer to sky_tex */ -GPUTexture **gpu_material_sky_texture_layer_set( +blender::gpu::Texture **gpu_material_sky_texture_layer_set( GPUMaterial *mat, int width, int height, const float *pixels, float *row); diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc index 3a06c0ea858..3149bd0ef0f 100644 --- a/source/blender/gpu/intern/gpu_texture.cc +++ b/source/blender/gpu/intern/gpu_texture.cc @@ -130,7 +130,7 @@ bool Texture::init_buffer(VertBuf *vbo, eGPUTextureFormat format) return this->init_internal(vbo); } -bool Texture::init_view(GPUTexture *src_, +bool Texture::init_view(Texture *src, eGPUTextureFormat format, eGPUTextureType type, int mip_start, @@ -140,7 +140,6 @@ bool Texture::init_view(GPUTexture *src_, bool cube_as_array, bool use_stencil) { - const Texture *src = unwrap(src_); w_ = src->w_; h_ = src->h_; d_ = src->d_; @@ -171,7 +170,7 @@ bool Texture::init_view(GPUTexture *src_, type_ = (type_ & ~GPU_TEXTURE_CUBE) | GPU_TEXTURE_2D_ARRAY; } sampler_state = src->sampler_state; - return this->init_internal(src_, mip_start, layer_start, use_stencil); + return this->init_internal(src, mip_start, layer_start, use_stencil); } void Texture::usage_set(eGPUTextureUsage usage_flags) @@ -250,16 +249,16 @@ uint GPU_texture_memory_usage_get() /* ------ Creation ------ */ -static inline GPUTexture *gpu_texture_create(const char *name, - const int w, - const int h, - const int d, - const eGPUTextureType type, - int mip_len, - eGPUTextureFormat tex_format, - eGPUTextureUsage usage, - const void *pixels, - eGPUDataFormat data_format = GPU_DATA_FLOAT) +static inline gpu::Texture *gpu_texture_create(const char *name, + const int w, + const int h, + const int d, + const eGPUTextureType type, + int mip_len, + eGPUTextureFormat tex_format, + eGPUTextureUsage usage, + const void *pixels, + eGPUDataFormat data_format = GPU_DATA_FLOAT) { BLI_assert(mip_len > 0); Texture *tex = GPUBackend::get()->texture_alloc(name); @@ -293,97 +292,97 @@ static inline GPUTexture *gpu_texture_create(const char *name, if (pixels) { tex->update(data_format, pixels); } - return reinterpret_cast(tex); + return reinterpret_cast(tex); } -GPUTexture *GPU_texture_create_1d(const char *name, - int width, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data) -{ - return gpu_texture_create(name, width, 0, 0, GPU_TEXTURE_1D, mip_len, format, usage, data); -} - -GPUTexture *GPU_texture_create_1d_array(const char *name, - int width, - int layer_len, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data) -{ - return gpu_texture_create( - name, width, layer_len, 0, GPU_TEXTURE_1D_ARRAY, mip_len, format, usage, data); -} - -GPUTexture *GPU_texture_create_2d(const char *name, - int width, - int height, - int mip_len, - eGPUTextureFormat format, - eGPUTextureUsage usage, - const float *data) -{ - return gpu_texture_create(name, width, height, 0, GPU_TEXTURE_2D, mip_len, format, usage, data); -} - -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) -{ - return gpu_texture_create( - name, width, height, layer_len, GPU_TEXTURE_2D_ARRAY, mip_len, format, usage, data); -} - -GPUTexture *GPU_texture_create_3d(const char *name, - int width, - int height, - int depth, - int mip_len, - eGPUTextureFormat texture_format, - eGPUTextureUsage usage, - const void *data) -{ - return gpu_texture_create( - name, width, height, depth, GPU_TEXTURE_3D, mip_len, texture_format, usage, data); -} - -GPUTexture *GPU_texture_create_cube(const char *name, +gpu::Texture *GPU_texture_create_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data) { - return gpu_texture_create(name, width, width, 0, GPU_TEXTURE_CUBE, mip_len, format, usage, data); + return gpu_texture_create(name, width, 0, 0, GPU_TEXTURE_1D, mip_len, format, usage, data); } -GPUTexture *GPU_texture_create_cube_array(const char *name, +gpu::Texture *GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data) +{ + return gpu_texture_create( + name, width, layer_len, 0, GPU_TEXTURE_1D_ARRAY, mip_len, format, usage, data); +} + +gpu::Texture *GPU_texture_create_2d(const char *name, + int width, + int height, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data) +{ + return gpu_texture_create(name, width, height, 0, GPU_TEXTURE_2D, mip_len, format, usage, data); +} + +gpu::Texture *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) +{ + return gpu_texture_create( + name, width, height, layer_len, GPU_TEXTURE_2D_ARRAY, mip_len, format, usage, data); +} + +gpu::Texture *GPU_texture_create_3d(const char *name, + int width, + int height, + int depth, + int mip_len, + eGPUTextureFormat texture_format, + eGPUTextureUsage usage, + const void *data) +{ + return gpu_texture_create( + name, width, height, depth, GPU_TEXTURE_3D, mip_len, texture_format, usage, data); +} + +gpu::Texture *GPU_texture_create_cube(const char *name, + int width, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data) +{ + return gpu_texture_create(name, width, width, 0, GPU_TEXTURE_CUBE, mip_len, format, usage, data); +} + +gpu::Texture *GPU_texture_create_cube_array(const char *name, + int width, + int layer_len, + int mip_len, + eGPUTextureFormat format, + eGPUTextureUsage usage, + const float *data) { return gpu_texture_create( name, width, width, layer_len, GPU_TEXTURE_CUBE_ARRAY, mip_len, format, usage, data); } -GPUTexture *GPU_texture_create_compressed_2d(const char *name, - int width, - int height, - int mip_len, - eGPUTextureFormat tex_format, - eGPUTextureUsage usage, - const void *data) +gpu::Texture *GPU_texture_create_compressed_2d(const char *name, + int width, + int height, + int mip_len, + eGPUTextureFormat tex_format, + eGPUTextureUsage usage, + const void *data) { Texture *tex = GPUBackend::get()->texture_alloc(name); tex->usage_set(usage); @@ -405,10 +404,10 @@ GPUTexture *GPU_texture_create_compressed_2d(const char *name, ofs += size; } } - return reinterpret_cast(tex); + return reinterpret_cast(tex); } -GPUTexture *GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vert) +gpu::Texture *GPU_texture_create_from_vertbuf(const char *name, gpu::VertBuf *vert) { #ifndef NDEBUG /* Vertex buffers used for texture buffers must be flagged with: @@ -425,10 +424,10 @@ GPUTexture *GPU_texture_create_from_vertbuf(const char *name, blender::gpu::Vert delete tex; return nullptr; } - return reinterpret_cast(tex); + return reinterpret_cast(tex); } -GPUTexture *GPU_texture_create_error(int dimension, bool is_array) +gpu::Texture *GPU_texture_create_error(int dimension, bool is_array) { const float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f}; int w = 1; @@ -443,15 +442,15 @@ GPUTexture *GPU_texture_create_error(int dimension, bool is_array) "invalid_tex", w, h, d, type, 1, GPU_RGBA8, GPU_TEXTURE_USAGE_GENERAL, pixel); } -GPUTexture *GPU_texture_create_view(const char *name, - GPUTexture *source_texture, - eGPUTextureFormat view_format, - int mip_start, - int mip_len, - int layer_start, - int layer_len, - bool cube_as_array, - bool use_stencil) +gpu::Texture *GPU_texture_create_view(const char *name, + gpu::Texture *source_texture, + eGPUTextureFormat view_format, + int mip_start, + int mip_len, + int layer_start, + int layer_len, + bool cube_as_array, + bool use_stencil) { BLI_assert(mip_len > 0); BLI_assert(layer_len > 0); @@ -466,18 +465,18 @@ GPUTexture *GPU_texture_create_view(const char *name, Texture *view = GPUBackend::get()->texture_alloc(name); view->init_view(source_texture, view_format, - unwrap(source_texture)->type_get(), + source_texture->type_get(), mip_start, mip_len, layer_start, layer_len, cube_as_array, use_stencil); - return wrap(view); + return view; } /* ------ Usage ------ */ -eGPUTextureUsage GPU_texture_usage(const GPUTexture *texture_) +eGPUTextureUsage GPU_texture_usage(const gpu::Texture *texture_) { const Texture *tex = reinterpret_cast(texture_); return tex->usage_get(); @@ -485,17 +484,17 @@ eGPUTextureUsage GPU_texture_usage(const GPUTexture *texture_) /* ------ Update ------ */ -void GPU_texture_update_mipmap(GPUTexture *texture, +void GPU_texture_update_mipmap(gpu::Texture *texture, int mip_level, eGPUDataFormat data_format, const void *pixels) { int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0}; - unwrap(texture)->mip_size_get(mip_level, extent); - unwrap(texture)->update_sub(mip_level, offset, extent, data_format, pixels); + texture->mip_size_get(mip_level, extent); + texture->update_sub(mip_level, offset, extent, data_format, pixels); } -void GPU_texture_update_sub(GPUTexture *tex, +void GPU_texture_update_sub(gpu::Texture *tex, eGPUDataFormat data_format, const void *pixels, int offset_x, @@ -507,10 +506,10 @@ void GPU_texture_update_sub(GPUTexture *tex, { int offset[3] = {offset_x, offset_y, offset_z}; int extent[3] = {width, height, depth}; - unwrap(tex)->update_sub(0, offset, extent, data_format, pixels); + tex->update_sub(0, offset, extent, data_format, pixels); } -void GPU_texture_update_sub_from_pixel_buffer(GPUTexture *texture, +void GPU_texture_update_sub_from_pixel_buffer(gpu::Texture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, @@ -522,27 +521,27 @@ void GPU_texture_update_sub_from_pixel_buffer(GPUTexture *texture, { int offset[3] = {offset_x, offset_y, offset_z}; int extent[3] = {width, height, depth}; - unwrap(texture)->update_sub(offset, extent, data_format, pixel_buf); + texture->update_sub(offset, extent, data_format, pixel_buf); } -void *GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_level) +void *GPU_texture_read(gpu::Texture *texture, eGPUDataFormat data_format, int mip_level) { BLI_assert_msg( GPU_texture_usage(texture) & GPU_TEXTURE_USAGE_HOST_READ, "The host-read usage flag must be specified up-front. Only textures which require data " "reads should be flagged, allowing the backend to make certain optimizations."); - return unwrap(texture)->read(mip_level, data_format); + return texture->read(mip_level, data_format); } -void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data) +void GPU_texture_clear(gpu::Texture *tex, eGPUDataFormat data_format, const void *data) { BLI_assert(data != nullptr); /* Do not accept nullptr as parameter. */ - unwrap(tex)->clear(data_format, data); + tex->clear(data_format, data); } -void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data) +void GPU_texture_update(gpu::Texture *tex, eGPUDataFormat data_format, const void *data) { - unwrap(tex)->update(data_format, data); + tex->update(data_format, data); } void GPU_unpack_row_length_set(uint len) @@ -552,22 +551,22 @@ void GPU_unpack_row_length_set(uint len) /* ------ Binding ------ */ -void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit) +void GPU_texture_bind_ex(gpu::Texture *texture, GPUSamplerState state, int unit) { - Texture *tex = unwrap(texture); + Texture *tex = texture; state = (state.type == GPU_SAMPLER_STATE_TYPE_INTERNAL) ? tex->sampler_state : state; Context::get()->state_manager->texture_bind(tex, state, unit); } -void GPU_texture_bind(GPUTexture *texture, int unit) +void GPU_texture_bind(gpu::Texture *texture, int unit) { - Texture *tex = unwrap(texture); + Texture *tex = texture; Context::get()->state_manager->texture_bind(tex, tex->sampler_state, unit); } -void GPU_texture_unbind(GPUTexture *texture) +void GPU_texture_unbind(gpu::Texture *texture) { - Texture *tex = unwrap(texture); + Texture *tex = texture; Context::get()->state_manager->texture_unbind(tex); } @@ -576,14 +575,14 @@ void GPU_texture_unbind_all() Context::get()->state_manager->texture_unbind_all(); } -void GPU_texture_image_bind(GPUTexture *tex, int unit) +void GPU_texture_image_bind(gpu::Texture *tex, int unit) { - Context::get()->state_manager->image_bind(unwrap(tex), unit); + Context::get()->state_manager->image_bind(tex, unit); } -void GPU_texture_image_unbind(GPUTexture *tex) +void GPU_texture_image_unbind(gpu::Texture *tex) { - Context::get()->state_manager->image_unbind(unwrap(tex)); + Context::get()->state_manager->image_unbind(tex); } void GPU_texture_image_unbind_all() @@ -591,21 +590,21 @@ void GPU_texture_image_unbind_all() Context::get()->state_manager->image_unbind_all(); } -void GPU_texture_update_mipmap_chain(GPUTexture *tex) +void GPU_texture_update_mipmap_chain(gpu::Texture *tex) { - unwrap(tex)->generate_mipmap(); + tex->generate_mipmap(); } -void GPU_texture_copy(GPUTexture *dst_, GPUTexture *src_) +void GPU_texture_copy(gpu::Texture *dst_, gpu::Texture *src_) { - Texture *src = unwrap(src_); - Texture *dst = unwrap(dst_); + Texture *src = src_; + Texture *dst = dst_; src->copy_to(dst); } -void GPU_texture_compare_mode(GPUTexture *texture, bool use_compare) +void GPU_texture_compare_mode(gpu::Texture *texture, bool use_compare) { - Texture *tex = unwrap(texture); + Texture *tex = texture; /* Only depth formats does support compare mode. */ BLI_assert(!(use_compare) || (tex->format_flag_get() & GPU_FORMAT_DEPTH)); @@ -614,18 +613,18 @@ void GPU_texture_compare_mode(GPUTexture *texture, bool use_compare) tex->sampler_state.custom_type = GPU_SAMPLER_CUSTOM_COMPARE; } -void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter) +void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter) { - Texture *tex = unwrap(texture); + Texture *tex = texture; /* Stencil and integer format does not support filtering. */ BLI_assert(!(use_filter) || !(tex->format_flag_get() & (GPU_FORMAT_STENCIL | GPU_FORMAT_INTEGER))); tex->sampler_state.set_filtering_flag_from_test(GPU_SAMPLER_FILTERING_LINEAR, use_filter); } -void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter) +void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter) { - Texture *tex = unwrap(texture); + Texture *tex = texture; /* Stencil and integer format does not support filtering. */ BLI_assert(!(use_filter || use_mipmap) || !(tex->format_flag_get() & (GPU_FORMAT_STENCIL | GPU_FORMAT_INTEGER))); @@ -633,43 +632,43 @@ void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filt tex->sampler_state.set_filtering_flag_from_test(GPU_SAMPLER_FILTERING_LINEAR, use_filter); } -void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso) +void GPU_texture_anisotropic_filter(gpu::Texture *texture, bool use_aniso) { - Texture *tex = unwrap(texture); + Texture *tex = texture; /* Stencil and integer format does not support filtering. */ BLI_assert(!(use_aniso) || !(tex->format_flag_get() & (GPU_FORMAT_STENCIL | GPU_FORMAT_INTEGER))); tex->sampler_state.set_filtering_flag_from_test(GPU_SAMPLER_FILTERING_ANISOTROPIC, use_aniso); } -void GPU_texture_extend_mode_x(GPUTexture *texture, GPUSamplerExtendMode extend_mode) +void GPU_texture_extend_mode_x(gpu::Texture *texture, GPUSamplerExtendMode extend_mode) { - unwrap(texture)->sampler_state.extend_x = extend_mode; + texture->sampler_state.extend_x = extend_mode; } -void GPU_texture_extend_mode_y(GPUTexture *texture, GPUSamplerExtendMode extend_mode) +void GPU_texture_extend_mode_y(gpu::Texture *texture, GPUSamplerExtendMode extend_mode) { - unwrap(texture)->sampler_state.extend_yz = extend_mode; + texture->sampler_state.extend_yz = extend_mode; } -void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode) +void GPU_texture_extend_mode(gpu::Texture *texture, GPUSamplerExtendMode extend_mode) { - unwrap(texture)->sampler_state.extend_x = extend_mode; - unwrap(texture)->sampler_state.extend_yz = extend_mode; + texture->sampler_state.extend_x = extend_mode; + texture->sampler_state.extend_yz = extend_mode; } -void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4]) +void GPU_texture_swizzle_set(gpu::Texture *texture, const char swizzle[4]) { - unwrap(texture)->swizzle_set(swizzle); + texture->swizzle_set(swizzle); } -void GPU_texture_free(GPUTexture *texture) +void GPU_texture_free(gpu::Texture *texture) { - Texture *tex = unwrap(texture); + Texture *tex = texture; tex->refcount--; if (tex->refcount < 0) { - fprintf(stderr, "GPUTexture: negative refcount\n"); + fprintf(stderr, "gpu::Texture: negative refcount\n"); } if (tex->refcount == 0) { @@ -677,14 +676,14 @@ void GPU_texture_free(GPUTexture *texture) } } -void GPU_texture_ref(GPUTexture *texture) +void GPU_texture_ref(gpu::Texture *texture) { - unwrap(texture)->refcount++; + texture->refcount++; } -int GPU_texture_dimensions(const GPUTexture *texture) +int GPU_texture_dimensions(const gpu::Texture *texture) { - eGPUTextureType type = unwrap(texture)->type_get(); + eGPUTextureType type = texture->type_get(); if (type & GPU_TEXTURE_1D) { return 1; } @@ -701,50 +700,50 @@ int GPU_texture_dimensions(const GPUTexture *texture) return 1; } -int GPU_texture_width(const GPUTexture *texture) +int GPU_texture_width(const gpu::Texture *texture) { - return unwrap(texture)->width_get(); + return texture->width_get(); } -int GPU_texture_height(const GPUTexture *texture) +int GPU_texture_height(const gpu::Texture *texture) { - return unwrap(texture)->height_get(); + return texture->height_get(); } -int GPU_texture_depth(const GPUTexture *texture) +int GPU_texture_depth(const gpu::Texture *texture) { - return unwrap(texture)->depth_get(); + return texture->depth_get(); } -int GPU_texture_layer_count(const GPUTexture *texture) +int GPU_texture_layer_count(const gpu::Texture *texture) { - return unwrap(texture)->layer_count(); + return texture->layer_count(); } -int GPU_texture_mip_count(const GPUTexture *texture) +int GPU_texture_mip_count(const gpu::Texture *texture) { - return unwrap(texture)->mip_count(); + return texture->mip_count(); } -int GPU_texture_original_width(const GPUTexture *texture) +int GPU_texture_original_width(const gpu::Texture *texture) { - return unwrap(texture)->src_w; + return texture->src_w; } -int GPU_texture_original_height(const GPUTexture *texture) +int GPU_texture_original_height(const gpu::Texture *texture) { - return unwrap(texture)->src_h; + return texture->src_h; } -void GPU_texture_original_size_set(GPUTexture *texture, int w, int h) +void GPU_texture_original_size_set(gpu::Texture *texture, int w, int h) { - unwrap(texture)->src_w = w; - unwrap(texture)->src_h = h; + texture->src_w = w; + texture->src_h = h; } -eGPUTextureFormat GPU_texture_format(const GPUTexture *texture) +eGPUTextureFormat GPU_texture_format(const gpu::Texture *texture) { - return unwrap(texture)->format_get(); + return texture->format_get(); } const char *GPU_texture_format_name(eGPUTextureFormat texture_format) @@ -886,62 +885,62 @@ const char *GPU_texture_format_name(eGPUTextureFormat texture_format) return ""; } -bool GPU_texture_has_depth_format(const GPUTexture *texture) +bool GPU_texture_has_depth_format(const gpu::Texture *texture) { - return (unwrap(texture)->format_flag_get() & GPU_FORMAT_DEPTH) != 0; + return (texture->format_flag_get() & GPU_FORMAT_DEPTH) != 0; } -bool GPU_texture_has_stencil_format(const GPUTexture *texture) +bool GPU_texture_has_stencil_format(const gpu::Texture *texture) { - return (unwrap(texture)->format_flag_get() & GPU_FORMAT_STENCIL) != 0; + return (texture->format_flag_get() & GPU_FORMAT_STENCIL) != 0; } -bool GPU_texture_has_integer_format(const GPUTexture *texture) +bool GPU_texture_has_integer_format(const gpu::Texture *texture) { - return (unwrap(texture)->format_flag_get() & GPU_FORMAT_INTEGER) != 0; + return (texture->format_flag_get() & GPU_FORMAT_INTEGER) != 0; } -bool GPU_texture_has_float_format(const GPUTexture *texture) +bool GPU_texture_has_float_format(const gpu::Texture *texture) { - return (unwrap(texture)->format_flag_get() & GPU_FORMAT_FLOAT) != 0; + return (texture->format_flag_get() & GPU_FORMAT_FLOAT) != 0; } -bool GPU_texture_has_normalized_format(const GPUTexture *texture) +bool GPU_texture_has_normalized_format(const gpu::Texture *texture) { - return (unwrap(texture)->format_flag_get() & GPU_FORMAT_NORMALIZED_INTEGER) != 0; + return (texture->format_flag_get() & GPU_FORMAT_NORMALIZED_INTEGER) != 0; } -bool GPU_texture_has_signed_format(const GPUTexture *texture) +bool GPU_texture_has_signed_format(const gpu::Texture *texture) { - return (unwrap(texture)->format_flag_get() & GPU_FORMAT_SIGNED) != 0; + return (texture->format_flag_get() & GPU_FORMAT_SIGNED) != 0; } -bool GPU_texture_is_cube(const GPUTexture *texture) +bool GPU_texture_is_cube(const gpu::Texture *texture) { - return (unwrap(texture)->type_get() & GPU_TEXTURE_CUBE) != 0; + return (texture->type_get() & GPU_TEXTURE_CUBE) != 0; } -bool GPU_texture_is_array(const GPUTexture *texture) +bool GPU_texture_is_array(const gpu::Texture *texture) { - return (unwrap(texture)->type_get() & GPU_TEXTURE_ARRAY) != 0; + return (texture->type_get() & GPU_TEXTURE_ARRAY) != 0; } #ifndef GPU_NO_USE_PY_REFERENCES -void **GPU_texture_py_reference_get(GPUTexture *texture) +void **GPU_texture_py_reference_get(gpu::Texture *texture) { - return unwrap(texture)->py_ref; + return texture->py_ref; } -void GPU_texture_py_reference_set(GPUTexture *texture, void **py_ref) +void GPU_texture_py_reference_set(gpu::Texture *texture, void **py_ref) { - BLI_assert(py_ref == nullptr || unwrap(texture)->py_ref == nullptr); - unwrap(texture)->py_ref = py_ref; + BLI_assert(py_ref == nullptr || texture->py_ref == nullptr); + texture->py_ref = py_ref; } #endif -void GPU_texture_get_mipmap_size(GPUTexture *texture, int mip_level, int *r_size) +void GPU_texture_get_mipmap_size(gpu::Texture *texture, int mip_level, int *r_size) { - unwrap(texture)->mip_size_get(mip_level, r_size); + texture->mip_size_get(mip_level, r_size); } /** \} */ diff --git a/source/blender/gpu/intern/gpu_texture_pool.cc b/source/blender/gpu/intern/gpu_texture_pool.cc index 88140ed267f..8cb3685b01b 100644 --- a/source/blender/gpu/intern/gpu_texture_pool.cc +++ b/source/blender/gpu/intern/gpu_texture_pool.cc @@ -17,7 +17,7 @@ namespace blender::gpu { TexturePool::~TexturePool() { - for (GPUTexture *tex : acquired_) { + for (blender::gpu::Texture *tex : acquired_) { GPU_texture_free(tex); } for (TextureHandle &tex : pool_) { @@ -25,15 +25,15 @@ TexturePool::~TexturePool() } } -GPUTexture *TexturePool::acquire_texture(int width, - int height, - eGPUTextureFormat format, - eGPUTextureUsage usage) +blender::gpu::Texture *TexturePool::acquire_texture(int width, + int height, + eGPUTextureFormat format, + eGPUTextureUsage usage) { int64_t match_index = -1; /* Search released texture first. */ for (auto i : pool_.index_range()) { - GPUTexture *tex = pool_[i].texture; + blender::gpu::Texture *tex = pool_[i].texture; /* TODO(@fclem): We could reuse texture using texture views if the formats are compatible. */ if ((GPU_texture_format(tex) == format) && (GPU_texture_width(tex) == width) && (GPU_texture_height(tex) == height) && (GPU_texture_usage(tex) == usage)) @@ -44,7 +44,7 @@ GPUTexture *TexturePool::acquire_texture(int width, } if (match_index != -1) { - GPUTexture *tex = pool_[match_index].texture; + blender::gpu::Texture *tex = pool_[match_index].texture; pool_.remove_and_reorder(match_index); acquired_.append(tex); return tex; @@ -57,23 +57,24 @@ GPUTexture *TexturePool::acquire_texture(int width, int texture_id = pool_.size(); SNPRINTF(name, "TexFromPool_%d", texture_id); } - GPUTexture *tex = GPU_texture_create_2d(name, width, height, 1, format, usage, nullptr); + blender::gpu::Texture *tex = GPU_texture_create_2d( + name, width, height, 1, format, usage, nullptr); acquired_.append(tex); return tex; } -void TexturePool::release_texture(GPUTexture *tex) +void TexturePool::release_texture(blender::gpu::Texture *tex) { acquired_.remove_first_occurrence_and_reorder(tex); pool_.append({tex, 0}); } -void TexturePool::take_texture_ownership(GPUTexture *tex) +void TexturePool::take_texture_ownership(blender::gpu::Texture *tex) { acquired_.remove_first_occurrence_and_reorder(tex); } -void TexturePool::give_texture_ownership(GPUTexture *tex) +void TexturePool::give_texture_ownership(blender::gpu::Texture *tex) { acquired_.append(tex); } diff --git a/source/blender/gpu/intern/gpu_texture_private.hh b/source/blender/gpu/intern/gpu_texture_private.hh index 4a5b844aebb..affd0fcb9d1 100644 --- a/source/blender/gpu/intern/gpu_texture_private.hh +++ b/source/blender/gpu/intern/gpu_texture_private.hh @@ -132,7 +132,7 @@ class Texture { bool init_3D(int w, int h, int d, int mip_len, eGPUTextureFormat format); bool init_cubemap(int w, int layers, int mip_len, eGPUTextureFormat format); bool init_buffer(VertBuf *vbo, eGPUTextureFormat format); - bool init_view(GPUTexture *src, + bool init_view(blender::gpu::Texture *src, eGPUTextureFormat format, eGPUTextureType type, int mip_start, @@ -311,26 +311,12 @@ class Texture { protected: virtual bool init_internal() = 0; virtual bool init_internal(VertBuf *vbo) = 0; - virtual bool init_internal(GPUTexture *src, + virtual bool init_internal(blender::gpu::Texture *src, int mip_offset, int layer_offset, bool use_stencil) = 0; }; -/* Syntactic sugar. */ -static inline GPUTexture *wrap(Texture *vert) -{ - return reinterpret_cast(vert); -} -static inline Texture *unwrap(GPUTexture *vert) -{ - return reinterpret_cast(vert); -} -static inline const Texture *unwrap(const GPUTexture *vert) -{ - return reinterpret_cast(vert); -} - /* GPU pixel Buffer. */ class PixelBuffer { protected: diff --git a/source/blender/gpu/intern/gpu_viewport.cc b/source/blender/gpu/intern/gpu_viewport.cc index 4cc56d79520..5767064caff 100644 --- a/source/blender/gpu/intern/gpu_viewport.cc +++ b/source/blender/gpu/intern/gpu_viewport.cc @@ -60,10 +60,10 @@ struct GPUViewport { /* Viewport Resources. */ DRWData *draw_data; /** Color buffers, one for each stereo view. Only one if not stereo viewport. */ - GPUTexture *color_render_tx[2]; - GPUTexture *color_overlay_tx[2]; + blender::gpu::Texture *color_render_tx[2]; + blender::gpu::Texture *color_overlay_tx[2]; /** Depth buffer. Can be shared with GPUOffscreen. */ - GPUTexture *depth_tx; + blender::gpu::Texture *depth_tx; /** Compositing framebuffer for stereo viewport. */ GPUFrameBuffer *stereo_comp_fb; /** Color render and overlay frame-buffers for drawing outside of DRW module. @@ -217,7 +217,7 @@ void GPU_viewport_bind(GPUViewport *viewport, int view, const rcti *rect) void GPU_viewport_bind_from_offscreen(GPUViewport *viewport, GPUOffScreen *ofs, bool is_xr_surface) { - GPUTexture *color, *depth; + blender::gpu::Texture *color, *depth; GPUFrameBuffer *fb; viewport->size[0] = GPU_offscreen_width(ofs); viewport->size[1] = GPU_offscreen_height(ofs); @@ -439,8 +439,8 @@ static void gpu_viewport_draw_colormanaged(GPUViewport *viewport, bool display_colorspace, bool do_overlay_merge) { - GPUTexture *color = viewport->color_render_tx[view]; - GPUTexture *color_overlay = viewport->color_overlay_tx[view]; + blender::gpu::Texture *color = viewport->color_render_tx[view]; + blender::gpu::Texture *color_overlay = viewport->color_overlay_tx[view]; bool use_ocio = false; bool use_hdr = GPU_hdr_support() && @@ -495,7 +495,7 @@ void GPU_viewport_draw_to_screen_ex(GPUViewport *viewport, bool display_colorspace, bool do_overlay_merge) { - GPUTexture *color = viewport->color_render_tx[view]; + blender::gpu::Texture *color = viewport->color_render_tx[view]; if (color == nullptr) { return; @@ -594,17 +594,17 @@ bool GPU_viewport_is_stereo_get(GPUViewport *viewport) return (viewport->flag & GPU_VIEWPORT_STEREO) != 0; } -GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport, int view) +blender::gpu::Texture *GPU_viewport_color_texture(GPUViewport *viewport, int view) { return viewport->color_render_tx[view]; } -GPUTexture *GPU_viewport_overlay_texture(GPUViewport *viewport, int view) +blender::gpu::Texture *GPU_viewport_overlay_texture(GPUViewport *viewport, int view) { return viewport->color_overlay_tx[view]; } -GPUTexture *GPU_viewport_depth_texture(GPUViewport *viewport) +blender::gpu::Texture *GPU_viewport_depth_texture(GPUViewport *viewport) { return viewport->depth_tx; } diff --git a/source/blender/gpu/metal/mtl_context.mm b/source/blender/gpu/metal/mtl_context.mm index 9f4b4fd8812..5680fa28d0c 100644 --- a/source/blender/gpu/metal/mtl_context.mm +++ b/source/blender/gpu/metal/mtl_context.mm @@ -113,9 +113,9 @@ void MTLContext::set_ghost_context(GHOST_ContextHandle ghostCtxHandle) /* Check if the GHOST Context provides a default framebuffer: */ if (default_fbo_mtltexture_) { - /* Release old GPUTexture handle */ + /* Release old gpu::Texture handle */ if (default_fbo_gputexture_) { - GPU_texture_free(wrap(static_cast(default_fbo_gputexture_))); + GPU_texture_free(default_fbo_gputexture_); default_fbo_gputexture_ = nullptr; } @@ -138,8 +138,8 @@ void MTLContext::set_ghost_context(GHOST_ContextHandle ghostCtxHandle) /* Add default texture for cases where no other framebuffer is bound */ if (!default_fbo_gputexture_) { - default_fbo_gputexture_ = static_cast(unwrap(GPU_texture_create_2d( - __func__, 16, 16, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, nullptr))); + default_fbo_gputexture_ = static_cast(GPU_texture_create_2d( + __func__, 16, 16, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, nullptr)); } mtl_back_left->add_color_attachment(default_fbo_gputexture_, 0, 0, 0); @@ -289,7 +289,7 @@ MTLContext::~MTLContext() /* Release context textures. */ if (default_fbo_gputexture_) { - GPU_texture_free(wrap(static_cast(default_fbo_gputexture_))); + GPU_texture_free(default_fbo_gputexture_); default_fbo_gputexture_ = nullptr; } if (default_fbo_mtltexture_) { @@ -630,7 +630,7 @@ gpu::MTLTexture *MTLContext::get_dummy_texture(eGPUTextureType type, } /* Create dummy texture based on desired type. */ - GPUTexture *tex = nullptr; + gpu::Texture *tex = nullptr; eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL; switch (type) { case GPU_TEXTURE_1D: @@ -697,8 +697,8 @@ void MTLContext::free_dummy_resources() for (int format = 0; format < GPU_SAMPLER_TYPE_MAX; format++) { for (int tex = 0; tex < GPU_TEXTURE_BUFFER; tex++) { if (dummy_textures_[format][tex]) { - GPU_texture_free( - reinterpret_cast(static_cast(dummy_textures_[format][tex]))); + GPU_texture_free(reinterpret_cast( + static_cast(dummy_textures_[format][tex]))); dummy_textures_[format][tex] = nullptr; } } diff --git a/source/blender/gpu/metal/mtl_framebuffer.mm b/source/blender/gpu/metal/mtl_framebuffer.mm index 77f2b855c9d..c41035be64a 100644 --- a/source/blender/gpu/metal/mtl_framebuffer.mm +++ b/source/blender/gpu/metal/mtl_framebuffer.mm @@ -486,7 +486,7 @@ void MTLFrameBuffer::subpass_transition_impl(const GPUAttachmentState /*depth_at * need to avoid bind-point collisions for image/texture resources. */ for (int i : color_attachment_states.index_range()) { GPUAttachmentType type = GPU_FB_COLOR_ATTACHMENT0 + i; - GPUTexture *attach_tex = this->attachments_[type].tex; + gpu::Texture *attach_tex = this->attachments_[type].tex; if (color_attachment_states[i] == GPU_ATTACHMENT_READ) { GPU_texture_image_bind(attach_tex, i); } @@ -682,14 +682,14 @@ void MTLFrameBuffer::update_attachments(bool /*update_viewport*/) MTLAttachment depth_attachment_prev = this->get_depth_attachment(); this->remove_depth_attachment(); this->add_depth_attachment( - static_cast(unwrap(attach.tex)), attach.mip, attach.layer); + static_cast(attach.tex), attach.mip, attach.layer); this->set_depth_attachment_clear_value(depth_attachment_prev.clear_value.depth); this->set_depth_loadstore_op(depth_attachment_prev.load_action, depth_attachment_prev.store_action); } else { this->add_depth_attachment( - static_cast(unwrap(attach.tex)), attach.mip, attach.layer); + static_cast(attach.tex), attach.mip, attach.layer); } /* Check stencil component -- if supplied texture format supports stencil. */ @@ -701,7 +701,7 @@ void MTLFrameBuffer::update_attachments(bool /*update_viewport*/) MTLAttachment stencil_attachment_prev = this->get_stencil_attachment(); this->remove_stencil_attachment(); this->add_stencil_attachment( - static_cast(unwrap(attach.tex)), attach.mip, attach.layer); + static_cast(attach.tex), attach.mip, attach.layer); this->set_stencil_attachment_clear_value( stencil_attachment_prev.clear_value.stencil); this->set_stencil_loadstore_op(stencil_attachment_prev.load_action, @@ -709,7 +709,7 @@ void MTLFrameBuffer::update_attachments(bool /*update_viewport*/) } else { this->add_stencil_attachment( - static_cast(unwrap(attach.tex)), attach.mip, attach.layer); + static_cast(attach.tex), attach.mip, attach.layer); } } @@ -746,7 +746,7 @@ void MTLFrameBuffer::update_attachments(bool /*update_viewport*/) MTLAttachment color_attachment_prev = this->get_color_attachment(color_slot_ind); this->remove_color_attachment(color_slot_ind); - this->add_color_attachment(static_cast(unwrap(attach.tex)), + this->add_color_attachment(static_cast(attach.tex), color_slot_ind, attach.mip, attach.layer); @@ -757,7 +757,7 @@ void MTLFrameBuffer::update_attachments(bool /*update_viewport*/) color_attachment_prev.store_action); } else { - this->add_color_attachment(static_cast(unwrap(attach.tex)), + this->add_color_attachment(static_cast(attach.tex), color_slot_ind, attach.mip, attach.layer); diff --git a/source/blender/gpu/metal/mtl_texture.hh b/source/blender/gpu/metal/mtl_texture.hh index f8ff0733b6a..dccb2910819 100644 --- a/source/blender/gpu/metal/mtl_texture.hh +++ b/source/blender/gpu/metal/mtl_texture.hh @@ -227,10 +227,10 @@ class MTLTexture : public Texture { * * Texture views can also point to external textures, rather than the owned * texture if MTL_TEXTURE_MODE_TEXTURE_VIEW is used. - * If this mode is used, source_texture points to a GPUTexture from which + * If this mode is used, source_texture points to a gpu::Texture from which * we pull their texture handle as a root. */ - const GPUTexture *source_texture_ = nullptr; + const gpu::Texture *source_texture_ = nullptr; enum TextureViewDirtyState { TEXTURE_VIEW_NOT_DIRTY = 0, @@ -322,7 +322,7 @@ class MTLTexture : public Texture { protected: bool init_internal() override; bool init_internal(VertBuf *vbo) override; - bool init_internal(GPUTexture *src, + bool init_internal(gpu::Texture *src, int mip_offset, int layer_offset, bool use_stencil) override; /* Texture View */ diff --git a/source/blender/gpu/metal/mtl_texture.mm b/source/blender/gpu/metal/mtl_texture.mm index b8237c6f311..547962338ee 100644 --- a/source/blender/gpu/metal/mtl_texture.mm +++ b/source/blender/gpu/metal/mtl_texture.mm @@ -142,7 +142,7 @@ void gpu::MTLTexture::bake_mip_swizzle_view() * check should only validate the range */ const gpu::Texture *tex_view_src = this; if (resource_mode_ == MTL_TEXTURE_MODE_TEXTURE_VIEW) { - tex_view_src = unwrap(source_texture_); + tex_view_src = source_texture_; } /* Determine num slices */ @@ -397,7 +397,7 @@ void gpu::MTLTexture::blit(gpu::MTLTexture *dst, GPU_shader_uniform_2f(shader, "size", width, height); GPU_shader_uniform_1i(shader, "mip", src_mip); - GPU_batch_texture_bind(quad, "imageTexture", wrap(this)); + GPU_batch_texture_bind(quad, "imageTexture", this); /* Caching previous pipeline state. */ bool depth_write_prev = GPU_depth_mask_get(); @@ -458,8 +458,7 @@ GPUFrameBuffer *gpu::MTLTexture::get_blit_framebuffer(int dst_slice, uint dst_mi /* DEPTH TEX */ GPU_framebuffer_ensure_config( &blit_fb_, - {GPU_ATTACHMENT_TEXTURE_LAYER_MIP( - wrap(static_cast(this)), int(dst_slice), int(dst_mip)), + {GPU_ATTACHMENT_TEXTURE_LAYER_MIP(this, int(dst_slice), int(dst_mip)), GPU_ATTACHMENT_NONE}); } else { @@ -467,8 +466,7 @@ GPUFrameBuffer *gpu::MTLTexture::get_blit_framebuffer(int dst_slice, uint dst_mi GPU_framebuffer_ensure_config( &blit_fb_, {GPU_ATTACHMENT_NONE, - GPU_ATTACHMENT_TEXTURE_LAYER_MIP( - wrap(static_cast(this)), int(dst_slice), int(dst_mip))}); + GPU_ATTACHMENT_TEXTURE_LAYER_MIP(this, int(dst_slice), int(dst_mip))}); } blit_fb_slice_ = dst_slice; blit_fb_mip_ = dst_mip; @@ -2150,7 +2148,7 @@ bool gpu::MTLTexture::init_internal(VertBuf *vbo) return true; } -bool gpu::MTLTexture::init_internal(GPUTexture *src, +bool gpu::MTLTexture::init_internal(gpu::Texture *src, int mip_offset, int layer_offset, bool use_stencil) @@ -2171,7 +2169,7 @@ bool gpu::MTLTexture::init_internal(GPUTexture *src, internal_gpu_image_usage_flags_ = GPU_texture_usage(src); /* Assign texture as view. */ - gpu::MTLTexture *mtltex = static_cast(unwrap(src)); + gpu::MTLTexture *mtltex = static_cast(src); mtltex->ensure_baked(); texture_ = mtltex->texture_; BLI_assert(texture_); diff --git a/source/blender/gpu/metal/mtl_texture_util.mm b/source/blender/gpu/metal/mtl_texture_util.mm index 1fdf56e4f7b..3cbb56c0d77 100644 --- a/source/blender/gpu/metal/mtl_texture_util.mm +++ b/source/blender/gpu/metal/mtl_texture_util.mm @@ -606,22 +606,22 @@ void gpu::MTLTexture::update_sub_depth_2d( } /* Push contents into an r32_tex and render contents to depth using a shader. */ - GPUTexture *r32_tex_tmp = GPU_texture_create_2d("depth_intermediate_copy_tex", - w_, - h_, - 1, - format, - GPU_TEXTURE_USAGE_SHADER_READ | - GPU_TEXTURE_USAGE_ATTACHMENT, - nullptr); + gpu::Texture *r32_tex_tmp = GPU_texture_create_2d("depth_intermediate_copy_tex", + w_, + h_, + 1, + format, + GPU_TEXTURE_USAGE_SHADER_READ | + GPU_TEXTURE_USAGE_ATTACHMENT, + nullptr); GPU_texture_filter_mode(r32_tex_tmp, false); GPU_texture_extend_mode(r32_tex_tmp, GPU_SAMPLER_EXTEND_MODE_EXTEND); - gpu::MTLTexture *mtl_tex = static_cast(unwrap(r32_tex_tmp)); + gpu::MTLTexture *mtl_tex = static_cast(r32_tex_tmp); mtl_tex->update_sub(mip, offset, extent, type, data); GPUFrameBuffer *restore_fb = GPU_framebuffer_active_get(); GPUFrameBuffer *depth_fb_temp = GPU_framebuffer_create("depth_intermediate_copy_fb"); - GPU_framebuffer_texture_attach(depth_fb_temp, wrap(static_cast(this)), 0, mip); + GPU_framebuffer_texture_attach(depth_fb_temp, this, 0, mip); GPU_framebuffer_bind(depth_fb_temp); if (extent[0] == w_ && extent[1] == h_) { /* Skip load if the whole texture is being updated. */ diff --git a/source/blender/gpu/metal/mtl_vertex_buffer.hh b/source/blender/gpu/metal/mtl_vertex_buffer.hh index f49fe95e209..533a91aab8c 100644 --- a/source/blender/gpu/metal/mtl_vertex_buffer.hh +++ b/source/blender/gpu/metal/mtl_vertex_buffer.hh @@ -28,7 +28,7 @@ class MTLVertBuf : public VertBuf { /** Metal buffer allocation. */ gpu::MTLBuffer *vbo_ = nullptr; /** Texture used if the buffer is bound as buffer texture. Init on first use. */ - ::GPUTexture *buffer_texture_ = nullptr; + gpu::Texture *buffer_texture_ = nullptr; /** Defines whether the buffer handle is wrapped by this MTLVertBuf, i.e. we do not own it and * should not free it. */ bool is_wrapper_ = false; diff --git a/source/blender/gpu/metal/mtl_vertex_buffer.mm b/source/blender/gpu/metal/mtl_vertex_buffer.mm index fbacf34efb3..3df13fe61dd 100644 --- a/source/blender/gpu/metal/mtl_vertex_buffer.mm +++ b/source/blender/gpu/metal/mtl_vertex_buffer.mm @@ -263,8 +263,7 @@ void MTLVertBuf::bind_as_texture(uint binding) /* If vertex buffer updated, release existing texture and re-create. */ id buf = this->get_metal_buffer(); if (buffer_texture_ != nullptr) { - gpu::MTLTexture *mtl_buffer_tex = static_cast( - unwrap(this->buffer_texture_)); + gpu::MTLTexture *mtl_buffer_tex = static_cast(this->buffer_texture_); id tex_buf = mtl_buffer_tex->get_vertex_buffer(); if (tex_buf != buf) { GPU_TEXTURE_FREE_SAFE(buffer_texture_); diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index 5a8cd2c83cf..9323a38c884 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -165,7 +165,7 @@ void GLFrameBuffer::update_attachments() glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, 0, 0); continue; } - GLuint gl_tex = static_cast(unwrap(attach.tex))->tex_id_; + GLuint gl_tex = static_cast(attach.tex)->tex_id_; if (attach.layer > -1 && GPU_texture_is_cube(attach.tex) && !GPU_texture_is_array(attach.tex)) { /* Could be avoided if ARB_direct_state_access is required. In this case @@ -195,7 +195,7 @@ void GLFrameBuffer::update_attachments() GPUAttachmentType type = GPU_FB_COLOR_ATTACHMENT0 + i; GPUAttachment &attach = attachments_[type]; if (attach.tex != nullptr) { - gl_tex = static_cast(unwrap(attach.tex))->tex_id_; + gl_tex = static_cast(attach.tex)->tex_id_; } else if (gl_tex != 0) { GLenum gl_attachment = to_gl(type); @@ -253,7 +253,7 @@ void GLFrameBuffer::subpass_transition_impl(const GPUAttachmentState depth_attac GLenum attachments[GPU_FB_MAX_COLOR_ATTACHMENT] = {GL_NONE}; for (int i : color_attachment_states.index_range()) { GPUAttachmentType type = GPU_FB_COLOR_ATTACHMENT0 + i; - GPUTexture *attach_tex = this->attachments_[type].tex; + gpu::Texture *attach_tex = this->attachments_[type].tex; if (color_attachment_states[i] == GPU_ATTACHMENT_READ) { tmp_detached_[type] = this->attachments_[type]; /* Bypass feedback loop check. */ GPU_texture_bind_ex(attach_tex, GPUSamplerState::default_sampler(), i); @@ -287,7 +287,7 @@ void GLFrameBuffer::subpass_transition_impl(const GPUAttachmentState depth_attac } else if (color_attachment_states[i] == GPU_ATTACHMENT_READ) { tmp_detached_[type] = this->attachments_[type]; - unwrap(tmp_detached_[type].tex)->detach_from(this); + tmp_detached_[type].tex->detach_from(this); GPU_texture_bind_ex(tmp_detached_[type].tex, GPUSamplerState::default_sampler(), i); } } diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc index 79636143d07..6e7ccc9e8dd 100644 --- a/source/blender/gpu/opengl/gl_texture.cc +++ b/source/blender/gpu/opengl/gl_texture.cc @@ -114,9 +114,12 @@ bool GLTexture::init_internal(VertBuf *vbo) return true; } -bool GLTexture::init_internal(GPUTexture *src, int mip_offset, int layer_offset, bool use_stencil) +bool GLTexture::init_internal(gpu::Texture *src, + int mip_offset, + int layer_offset, + bool use_stencil) { - const GLTexture *gl_src = static_cast(unwrap(src)); + const GLTexture *gl_src = static_cast(src); GLenum internal_format = to_gl_internal_format(format_); target_ = to_gl_target(type_); @@ -455,7 +458,7 @@ FrameBuffer *GLTexture::framebuffer_get() } BLI_assert(!(type_ & GPU_TEXTURE_1D)); framebuffer_ = unwrap(GPU_framebuffer_create(name_)); - framebuffer_->attachment_set(this->attachment_type(0), GPU_ATTACHMENT_TEXTURE(wrap(this))); + framebuffer_->attachment_set(this->attachment_type(0), GPU_ATTACHMENT_TEXTURE(this)); has_pixels_ = true; return framebuffer_; } diff --git a/source/blender/gpu/opengl/gl_texture.hh b/source/blender/gpu/opengl/gl_texture.hh index e11bb04bf68..c667710d55e 100644 --- a/source/blender/gpu/opengl/gl_texture.hh +++ b/source/blender/gpu/opengl/gl_texture.hh @@ -115,7 +115,10 @@ class GLTexture : public Texture { /** Return true on success. */ bool init_internal(VertBuf *vbo) override; /** Return true on success. */ - bool init_internal(GPUTexture *src, int mip_offset, int layer_offset, bool use_stencil) override; + bool init_internal(gpu::Texture *src, + int mip_offset, + int layer_offset, + bool use_stencil) override; private: bool proxy_check(int mip); diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.hh b/source/blender/gpu/opengl/gl_vertex_buffer.hh index e9792d4ab39..11c9aa65d38 100644 --- a/source/blender/gpu/opengl/gl_vertex_buffer.hh +++ b/source/blender/gpu/opengl/gl_vertex_buffer.hh @@ -25,7 +25,7 @@ class GLVertBuf : public VertBuf { /** OpenGL buffer handle. Init on first upload. Immutable after that. */ GLuint vbo_id_ = 0; /** Texture used if the buffer is bound as buffer texture. Init on first use. */ - ::GPUTexture *buffer_texture_ = nullptr; + gpu::Texture *buffer_texture_ = nullptr; /** Defines whether the buffer handle is wrapped by this GLVertBuf, i.e. we do not own it and * should not free it. */ bool is_wrapper_ = false; diff --git a/source/blender/gpu/tests/compute_test.cc b/source/blender/gpu/tests/compute_test.cc index 2a983967f8c..84a624d6c85 100644 --- a/source/blender/gpu/tests/compute_test.cc +++ b/source/blender/gpu/tests/compute_test.cc @@ -24,7 +24,7 @@ static void test_compute_direct() EXPECT_NE(shader, nullptr); /* Create texture to store result and attach to shader. */ - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "gpu_shader_compute_2d", SIZE, SIZE, 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); EXPECT_NE(texture, nullptr); @@ -61,7 +61,7 @@ static void test_compute_indirect() EXPECT_NE(shader, nullptr); /* Create texture to store result and attach to shader. */ - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "gpu_shader_compute_2d", SIZE, SIZE, 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); EXPECT_NE(texture, nullptr); GPU_texture_clear(texture, GPU_DATA_FLOAT, float4(0.0f)); diff --git a/source/blender/gpu/tests/framebuffer_test.cc b/source/blender/gpu/tests/framebuffer_test.cc index e235235ab9a..cca58a578d2 100644 --- a/source/blender/gpu/tests/framebuffer_test.cc +++ b/source/blender/gpu/tests/framebuffer_test.cc @@ -24,7 +24,7 @@ static void test_framebuffer_clear_color_single_attachment() { const int2 size(1, 1); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_RGBA32F, usage, nullptr); GPUFrameBuffer *framebuffer = GPU_framebuffer_create(__func__); @@ -51,9 +51,9 @@ static void test_framebuffer_clear_color_multiple_attachments() { const int2 size(1, 1); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture1 = GPU_texture_create_2d( + blender::gpu::Texture *texture1 = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_RGBA32F, usage, nullptr); - GPUTexture *texture2 = GPU_texture_create_2d( + blender::gpu::Texture *texture2 = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_RGBA32UI, usage, nullptr); GPUFrameBuffer *framebuffer = GPU_framebuffer_create(__func__); @@ -92,9 +92,9 @@ static void test_framebuffer_clear_multiple_color_multiple_attachments() { const int2 size(1, 1); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture1 = GPU_texture_create_2d( + blender::gpu::Texture *texture1 = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_RGBA32F, usage, nullptr); - GPUTexture *texture2 = GPU_texture_create_2d( + blender::gpu::Texture *texture2 = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_RGBA32F, usage, nullptr); GPUFrameBuffer *framebuffer = GPU_framebuffer_create(__func__); @@ -130,7 +130,7 @@ static void test_framebuffer_clear_depth() { const int2 size(1, 1); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_DEPTH_COMPONENT32F, usage, nullptr); GPUFrameBuffer *framebuffer = GPU_framebuffer_create(__func__); @@ -158,7 +158,7 @@ static void test_framebuffer_scissor_test() { const int2 size(2, 2); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_RGBA32F, usage, nullptr); GPUFrameBuffer *framebuffer = GPU_framebuffer_create(__func__); @@ -201,7 +201,8 @@ static void test_framebuffer_cube() GPU_render_begin(); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_cube("tex", SIZE, 1, GPU_RGBA32F, usage, nullptr); + blender::gpu::Texture *tex = GPU_texture_create_cube( + "tex", SIZE, 1, GPU_RGBA32F, usage, nullptr); const float4 clear_colors[6] = { {0.5f, 0.0f, 0.0f, 1.0f}, @@ -259,7 +260,7 @@ static void test_framebuffer_multi_viewport() const int2 size(4, 4); const int layers = 256; eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture = GPU_texture_create_2d_array( + blender::gpu::Texture *texture = GPU_texture_create_2d_array( __func__, UNPACK2(size), layers, 1, GPU_RG32I, usage, nullptr); GPUFrameBuffer *framebuffer = GPU_framebuffer_create(__func__); @@ -336,9 +337,9 @@ static void test_framebuffer_subpass_input() const int2 size(1, 1); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture_a = GPU_texture_create_2d( + blender::gpu::Texture *texture_a = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_R32I, usage, nullptr); - GPUTexture *texture_b = GPU_texture_create_2d( + blender::gpu::Texture *texture_b = GPU_texture_create_2d( __func__, UNPACK2(size), 1, GPU_R32I, usage, nullptr); GPUFrameBuffer *framebuffer = GPU_framebuffer_create(__func__); diff --git a/source/blender/gpu/tests/shader_test.cc b/source/blender/gpu/tests/shader_test.cc index f753792611e..62ef39f25b7 100644 --- a/source/blender/gpu/tests/shader_test.cc +++ b/source/blender/gpu/tests/shader_test.cc @@ -41,7 +41,7 @@ static void test_shader_compute_2d() EXPECT_NE(shader, nullptr); /* Create texture to store result and attach to shader. */ - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "gpu_shader_compute_2d", SIZE, SIZE, 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); EXPECT_NE(texture, nullptr); @@ -80,7 +80,7 @@ static void test_shader_compute_1d() EXPECT_NE(shader, nullptr); /* Construct Texture. */ - GPUTexture *texture = GPU_texture_create_1d( + blender::gpu::Texture *texture = GPU_texture_create_1d( "gpu_shader_compute_1d", SIZE, 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); EXPECT_NE(texture, nullptr); @@ -359,7 +359,7 @@ static void gpu_shader_lib_test(const char *test_src_name, const char *additiona int test_output_px_len = divide_ceil_u(sizeof(TestOutput), 4 * 4); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_2d( + blender::gpu::Texture *tex = GPU_texture_create_2d( "tx", test_output_px_len, test_count, 1, GPU_RGBA32UI, usage, nullptr); GPUFrameBuffer *fb = GPU_framebuffer_create("test_fb"); GPU_framebuffer_ensure_config(&fb, {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(tex)}); diff --git a/source/blender/gpu/tests/state_blend_test.cc b/source/blender/gpu/tests/state_blend_test.cc index e1e62693d35..41c3b2ec4b3 100644 --- a/source/blender/gpu/tests/state_blend_test.cc +++ b/source/blender/gpu/tests/state_blend_test.cc @@ -31,7 +31,7 @@ void blend_test(float4 source_a, float4 source_b, float4 expected_result) nullptr); BLI_assert(offscreen != nullptr); GPU_offscreen_bind(offscreen, false); - GPUTexture *color_texture = GPU_offscreen_color_texture(offscreen); + blender::gpu::Texture *color_texture = GPU_offscreen_color_texture(offscreen); GPU_texture_clear(color_texture, GPU_DATA_FLOAT, source_a); Batch *batch = GPU_batch_preset_quad(); diff --git a/source/blender/gpu/tests/texture_test.cc b/source/blender/gpu/tests/texture_test.cc index 1da0e0040f7..0d6053b84cc 100644 --- a/source/blender/gpu/tests/texture_test.cc +++ b/source/blender/gpu/tests/texture_test.cc @@ -32,9 +32,12 @@ static void test_texture_read() GPU_render_begin(); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *rgba32u = GPU_texture_create_2d("rgba32u", 1, 1, 1, GPU_RGBA32UI, usage, nullptr); - GPUTexture *rgba16u = GPU_texture_create_2d("rgba16u", 1, 1, 1, GPU_RGBA16UI, usage, nullptr); - GPUTexture *rgba32f = GPU_texture_create_2d("rgba32f", 1, 1, 1, GPU_RGBA32F, usage, nullptr); + blender::gpu::Texture *rgba32u = GPU_texture_create_2d( + "rgba32u", 1, 1, 1, GPU_RGBA32UI, usage, nullptr); + blender::gpu::Texture *rgba16u = GPU_texture_create_2d( + "rgba16u", 1, 1, 1, GPU_RGBA16UI, usage, nullptr); + blender::gpu::Texture *rgba32f = GPU_texture_create_2d( + "rgba32f", 1, 1, 1, GPU_RGBA32F, usage, nullptr); const float4 fcol = {0.0f, 1.3f, -231.0f, 1000.0f}; const uint4 ucol = {0, 1, 2, 12223}; @@ -74,7 +77,7 @@ static void test_texture_1d() eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ | GPU_TEXTURE_USAGE_SHADER_WRITE; - GPUTexture *tex = GPU_texture_create_1d("tex", SIZE, 1, GPU_RGBA32F, usage, nullptr); + blender::gpu::Texture *tex = GPU_texture_create_1d("tex", SIZE, 1, GPU_RGBA32F, usage, nullptr); float4 clear_color(0.9f, 0.7f, 0.2f, 1.0f); GPU_texture_clear(tex, GPU_DATA_FLOAT, clear_color); @@ -103,7 +106,7 @@ static void test_texture_1d_array() eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ | GPU_TEXTURE_USAGE_SHADER_WRITE; - GPUTexture *tex = GPU_texture_create_1d_array( + blender::gpu::Texture *tex = GPU_texture_create_1d_array( "tex", SIZE, LAYERS, 1, GPU_RGBA32F, usage, nullptr); float4 clear_color(1.0f, 0.5f, 0.2f, 1.0f); GPU_texture_clear(tex, GPU_DATA_FLOAT, clear_color); @@ -135,7 +138,7 @@ static void test_texture_1d_array_upload() float *data_in = MEM_calloc_arrayN(total_size, __func__); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_1d_array( + blender::gpu::Texture *tex = GPU_texture_create_1d_array( "tex", SIZE, LAYERS, 1, GPU_RGBA32F, usage, data_in); GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE); @@ -158,7 +161,7 @@ static void test_texture_2d_array() GPU_render_begin(); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_2d_array( + blender::gpu::Texture *tex = GPU_texture_create_2d_array( "tex", SIZE, SIZE, LAYERS, 1, GPU_RGBA32F, usage, nullptr); float4 clear_color(1.0f, 0.5f, 0.2f, 1.0f); GPU_texture_clear(tex, GPU_DATA_FLOAT, clear_color); @@ -187,7 +190,7 @@ static void test_texture_2d_array_upload() float *data_in = MEM_calloc_arrayN(total_size, __func__); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_2d_array( + blender::gpu::Texture *tex = GPU_texture_create_2d_array( "tex", SIZE, SIZE, LAYERS, 1, GPU_RGBA32F, usage, data_in); GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE); @@ -209,7 +212,8 @@ static void test_texture_cube() GPU_render_begin(); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_cube("tex", SIZE, 1, GPU_RGBA32F, usage, nullptr); + blender::gpu::Texture *tex = GPU_texture_create_cube( + "tex", SIZE, 1, GPU_RGBA32F, usage, nullptr); float4 clear_color(1.0f, 0.5f, 0.2f, 1.0f); GPU_texture_clear(tex, GPU_DATA_FLOAT, clear_color); @@ -234,7 +238,7 @@ static void test_texture_cube_array() GPU_render_begin(); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_cube_array( + blender::gpu::Texture *tex = GPU_texture_create_cube_array( "tex", SIZE, LAYERS, 1, GPU_RGBA32F, usage, nullptr); float4 clear_color(1.0f, 0.5f, 0.2f, 1.0f); GPU_texture_clear(tex, GPU_DATA_FLOAT, clear_color); @@ -257,7 +261,8 @@ static void test_texture_3d() GPU_render_begin(); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *tex = GPU_texture_create_3d("tex", SIZE, SIZE, SIZE, 1, GPU_RGBA32F, usage, nullptr); + blender::gpu::Texture *tex = GPU_texture_create_3d( + "tex", SIZE, SIZE, SIZE, 1, GPU_RGBA32F, usage, nullptr); float4 clear_color(1.0f, 0.5f, 0.2f, 1.0f); GPU_texture_clear(tex, GPU_DATA_FLOAT, clear_color); @@ -281,8 +286,10 @@ static void test_texture_copy() GPU_render_begin(); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *src_tx = GPU_texture_create_2d("src", SIZE, SIZE, 1, GPU_RGBA32F, usage, nullptr); - GPUTexture *dst_tx = GPU_texture_create_2d("dst", SIZE, SIZE, 1, GPU_RGBA32F, usage, nullptr); + blender::gpu::Texture *src_tx = GPU_texture_create_2d( + "src", SIZE, SIZE, 1, GPU_RGBA32F, usage, nullptr); + blender::gpu::Texture *dst_tx = GPU_texture_create_2d( + "dst", SIZE, SIZE, 1, GPU_RGBA32F, usage, nullptr); const float4 color(0.0, 1.0f, 2.0f, 123.0f); const float4 clear_color(0.0f); @@ -329,7 +336,7 @@ static void texture_create_upload_read() static_assert(!std::is_same()); static_assert(validate_data_format(DeviceFormat, HostFormat)); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "texture", Size, Size, 1, DeviceFormat, usage, nullptr); if (texture == nullptr) { GTEST_SKIP() << "Platform doesn't support texture format [" << STRINGIFY(DeviceFormat) << "]"; @@ -362,7 +369,7 @@ static void texture_create_upload_read_with_bias(float max_allowed_bias) { static_assert(validate_data_format(DeviceFormat, HostFormat)); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "texture", Size, Size, 1, DeviceFormat, usage, nullptr); if (texture == nullptr) { GTEST_SKIP() << "Platform doesn't support texture format [" << STRINGIFY(DeviceFormat) << "]"; @@ -394,7 +401,7 @@ static void texture_create_upload_read_pixel() using DataType = uint32_t; static_assert(validate_data_format(DeviceFormat, HostFormat)); eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "texture", Size, Size, 1, DeviceFormat, usage, nullptr); ASSERT_NE(texture, nullptr); @@ -1007,7 +1014,7 @@ static void test_texture_update_sub_no_unpack_row_length() const int2 sub_size(256); const int2 sub_offset(256); - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( __func__, UNPACK2(size), 2, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); const float4 clear_color(0.0f, 0.0f, 0.0f, 0.0f); GPU_texture_clear(texture, GPU_DATA_FLOAT, &clear_color); @@ -1061,7 +1068,7 @@ static void test_texture_update_sub_unpack_row_length() const int2 sub_size(256); const int2 sub_offset(256); - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( __func__, UNPACK2(size), 2, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); const float4 clear_color(0.0f, 0.0f, 0.0f, 0.0f); GPU_texture_clear(texture, GPU_DATA_FLOAT, &clear_color); @@ -1134,8 +1141,8 @@ static void test_texture_pool() eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT; auto test_acquire = - [&](int2 size, eGPUTextureFormat format, eGPUTextureUsage usage) -> GPUTexture * { - GPUTexture *tex = pool.acquire_texture(size.x, size.y, format, usage); + [&](int2 size, eGPUTextureFormat format, eGPUTextureUsage usage) -> blender::gpu::Texture * { + blender::gpu::Texture *tex = pool.acquire_texture(size.x, size.y, format, usage); EXPECT_EQ(GPU_texture_format(tex), format); EXPECT_EQ(GPU_texture_width(tex), size.x); EXPECT_EQ(GPU_texture_height(tex), size.y); @@ -1143,10 +1150,10 @@ static void test_texture_pool() }; /* Tests multiple acquire. */ - GPUTexture *tex1 = test_acquire(size1, format1, usage); - GPUTexture *tex2 = test_acquire(size2, format1, usage); - GPUTexture *tex3 = test_acquire(size3, format2, usage); - GPUTexture *tex4 = test_acquire(size3, format3, usage); + blender::gpu::Texture *tex1 = test_acquire(size1, format1, usage); + blender::gpu::Texture *tex2 = test_acquire(size2, format1, usage); + blender::gpu::Texture *tex3 = test_acquire(size3, format2, usage); + blender::gpu::Texture *tex4 = test_acquire(size3, format3, usage); pool.release_texture(tex1); diff --git a/source/blender/gpu/tests/vertex_buffer_test.cc b/source/blender/gpu/tests/vertex_buffer_test.cc index 7dc27c7f36c..523312a52d1 100644 --- a/source/blender/gpu/tests/vertex_buffer_test.cc +++ b/source/blender/gpu/tests/vertex_buffer_test.cc @@ -29,7 +29,7 @@ static void vertex_buffer_fetch_mode(ColorType color) Size, Size, false, GPU_RGBA32F, usage, false, nullptr); BLI_assert(offscreen != nullptr); GPU_offscreen_bind(offscreen, false); - GPUTexture *color_texture = GPU_offscreen_color_texture(offscreen); + blender::gpu::Texture *color_texture = GPU_offscreen_color_texture(offscreen); GPU_texture_clear(color_texture, GPU_DATA_FLOAT, float4(1.0f, 2.0f, 3.0f, 0.0f)); GPUVertFormat format = {0}; diff --git a/source/blender/gpu/vulkan/vk_context.hh b/source/blender/gpu/vulkan/vk_context.hh index 56978dea4de..ed4a61ee1fa 100644 --- a/source/blender/gpu/vulkan/vk_context.hh +++ b/source/blender/gpu/vulkan/vk_context.hh @@ -43,7 +43,7 @@ class VKContext : public Context, NonCopyable { private: VkExtent2D vk_extent_ = {}; VkSurfaceFormatKHR swap_chain_format_ = {}; - GPUTexture *surface_texture_ = nullptr; + gpu::Texture *surface_texture_ = nullptr; void *ghost_context_; /* Reusable data. Stored inside context to limit reallocations. */ diff --git a/source/blender/gpu/vulkan/vk_texture.cc b/source/blender/gpu/vulkan/vk_texture.cc index 3c526c5eb38..e4d509bd7a0 100644 --- a/source/blender/gpu/vulkan/vk_texture.cc +++ b/source/blender/gpu/vulkan/vk_texture.cc @@ -452,7 +452,10 @@ bool VKTexture::init_internal(VertBuf *vbo) return true; } -bool VKTexture::init_internal(GPUTexture *src, int mip_offset, int layer_offset, bool use_stencil) +bool VKTexture::init_internal(gpu::Texture *src, + int mip_offset, + int layer_offset, + bool use_stencil) { BLI_assert(source_texture_ == nullptr); BLI_assert(src); diff --git a/source/blender/gpu/vulkan/vk_texture.hh b/source/blender/gpu/vulkan/vk_texture.hh index 5d63e9b57cd..ad440d1fa3c 100644 --- a/source/blender/gpu/vulkan/vk_texture.hh +++ b/source/blender/gpu/vulkan/vk_texture.hh @@ -144,7 +144,10 @@ class VKTexture : public Texture { protected: bool init_internal() override; bool init_internal(VertBuf *vbo) override; - bool init_internal(GPUTexture *src, int mip_offset, int layer_offset, bool use_stencil) override; + bool init_internal(gpu::Texture *src, + int mip_offset, + int layer_offset, + bool use_stencil) override; private: /** Is this texture a view of another texture. */ diff --git a/source/blender/imbuf/IMB_imbuf.hh b/source/blender/imbuf/IMB_imbuf.hh index 88f6d6d8f8d..3d9a18d28dc 100644 --- a/source/blender/imbuf/IMB_imbuf.hh +++ b/source/blender/imbuf/IMB_imbuf.hh @@ -597,10 +597,10 @@ void IMB_transform(const ImBuf *src, const blender::float3x3 &transform_matrix, const rctf *src_crop); -GPUTexture *IMB_create_gpu_texture(const char *name, - ImBuf *ibuf, - bool use_high_bitdepth, - bool use_premult); +blender::gpu::Texture *IMB_create_gpu_texture(const char *name, + ImBuf *ibuf, + bool use_high_bitdepth, + bool use_premult); eGPUTextureFormat IMB_gpu_get_texture_format(const ImBuf *ibuf, bool high_bitdepth, @@ -617,20 +617,19 @@ void IMB_gpu_clamp_half_float(ImBuf *image_buffer); * 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(const char *name, - ImBuf *ibuf, - int w, - int h, - int layers, - bool use_high_bitdepth, - bool use_grayscale); +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); /** - * Will update a #GPUTexture using the content of the #ImBuf. Only one layer will be updated. - * Will resize the ibuf if needed. - * Z is the layer to update. Unused if the texture is 2D. + * Will update a #blender::gpu::Texture using the content of the #ImBuf. Only one layer will be + * updated. Will resize the ibuf if needed. Z is the layer to update. Unused if the texture is 2D. */ -void IMB_update_gpu_texture_sub(GPUTexture *tex, +void IMB_update_gpu_texture_sub(blender::gpu::Texture *tex, ImBuf *ibuf, int x, int y, diff --git a/source/blender/imbuf/IMB_imbuf_types.hh b/source/blender/imbuf/IMB_imbuf_types.hh index b4f0bc86e09..723a83d4fc4 100644 --- a/source/blender/imbuf/IMB_imbuf_types.hh +++ b/source/blender/imbuf/IMB_imbuf_types.hh @@ -16,7 +16,9 @@ #include "IMB_imbuf_enums.h" struct ColormanageCache; -struct GPUTexture; +namespace blender::gpu { +class Texture; +} struct IDProperty; namespace blender::ocio { @@ -166,7 +168,7 @@ struct ImBufGPU { * De-referencing the ImBuf or its GPU texture can happen from any state. */ /* TODO(sergey): This should become a list of textures, to support having high-res ImBuf on GPU * without hitting hardware limitations. */ - GPUTexture *texture; + blender::gpu::Texture *texture; }; /** \} */ diff --git a/source/blender/imbuf/intern/util_gpu.cc b/source/blender/imbuf/intern/util_gpu.cc index 086be2077b1..516e8c64115 100644 --- a/source/blender/imbuf/intern/util_gpu.cc +++ b/source/blender/imbuf/intern/util_gpu.cc @@ -252,18 +252,18 @@ static void *imb_gpu_get_data(const ImBuf *ibuf, return data_rect; } -GPUTexture *IMB_touch_gpu_texture(const char *name, - ImBuf *ibuf, - int w, - int h, - int layers, - bool use_high_bitdepth, - bool use_grayscale) +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) { eGPUTextureFormat tex_format; imb_gpu_get_format(ibuf, use_high_bitdepth, use_grayscale, &tex_format); - GPUTexture *tex; + blender::gpu::Texture *tex; if (layers > 0) { tex = GPU_texture_create_2d_array( name, w, h, layers, 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr); @@ -278,7 +278,7 @@ GPUTexture *IMB_touch_gpu_texture(const char *name, return tex; } -void IMB_update_gpu_texture_sub(GPUTexture *tex, +void IMB_update_gpu_texture_sub(blender::gpu::Texture *tex, ImBuf *ibuf, int x, int y, @@ -309,12 +309,12 @@ void IMB_update_gpu_texture_sub(GPUTexture *tex, } } -GPUTexture *IMB_create_gpu_texture(const char *name, - ImBuf *ibuf, - bool use_high_bitdepth, - bool use_premult) +blender::gpu::Texture *IMB_create_gpu_texture(const char *name, + ImBuf *ibuf, + bool use_high_bitdepth, + bool use_premult) { - GPUTexture *tex = nullptr; + blender::gpu::Texture *tex = nullptr; 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]); diff --git a/source/blender/imbuf/opencolorio/intern/gpu_shader_binder_internal.hh b/source/blender/imbuf/opencolorio/intern/gpu_shader_binder_internal.hh index b6f956e9b33..b9424b36e15 100644 --- a/source/blender/imbuf/opencolorio/intern/gpu_shader_binder_internal.hh +++ b/source/blender/imbuf/opencolorio/intern/gpu_shader_binder_internal.hh @@ -27,7 +27,9 @@ struct CurveMapping; struct GPUUniformBuf; struct GPUShader; -struct GPUTexture; +namespace blender::gpu { +class Texture; +} namespace blender::ocio { @@ -55,7 +57,7 @@ struct UniformBufferSlot { }; struct GPULutTexture { - GPUTexture *texture = nullptr; + blender::gpu::Texture *texture = nullptr; std::string sampler_name; }; @@ -75,7 +77,7 @@ class GPUTextures : NonCopyable, NonMovable { Vector luts; /* Dummy in case of no overlay. */ - GPUTexture *dummy = nullptr; + blender::gpu::Texture *dummy = nullptr; /* Uniforms */ Vector uniforms; @@ -98,7 +100,7 @@ class GPUCurveMappping : NonCopyable, NonMovable { float *lut = nullptr; GPUUniformBuf *buffer = nullptr; - GPUTexture *texture = nullptr; + blender::gpu::Texture *texture = nullptr; size_t cache_id = 0; ~GPUCurveMappping(); diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h index f0cab244b3e..cfe426e60a1 100644 --- a/source/blender/makesdna/DNA_fluid_types.h +++ b/source/blender/makesdna/DNA_fluid_types.h @@ -10,6 +10,15 @@ #include "DNA_listBase.h" +#ifdef __cplusplus +namespace blender::gpu { +class Texture; +} // namespace blender::gpu +using GPUTexture = blender::gpu::Texture; +#else +typedef struct GPUTexture GPUTexture; +#endif + /** * #FluidDomainSettings.flags * Domain flags. @@ -473,19 +482,19 @@ typedef struct FluidDomainSettings { struct Collection *fluid_group; struct Collection *force_group; /* UNUSED */ struct Collection *effector_group; /* Effector objects group. */ - struct GPUTexture *tex_density; - struct GPUTexture *tex_color; - struct GPUTexture *tex_wt; - struct GPUTexture *tex_shadow; - struct GPUTexture *tex_flame; - struct GPUTexture *tex_flame_coba; - struct GPUTexture *tex_coba; - struct GPUTexture *tex_field; - struct GPUTexture *tex_velocity_x; - struct GPUTexture *tex_velocity_y; - struct GPUTexture *tex_velocity_z; - struct GPUTexture *tex_flags; - struct GPUTexture *tex_range_field; + GPUTexture *tex_density; + GPUTexture *tex_color; + GPUTexture *tex_wt; + GPUTexture *tex_shadow; + GPUTexture *tex_flame; + GPUTexture *tex_flame_coba; + GPUTexture *tex_coba; + GPUTexture *tex_field; + GPUTexture *tex_velocity_x; + GPUTexture *tex_velocity_y; + GPUTexture *tex_velocity_z; + GPUTexture *tex_flags; + GPUTexture *tex_range_field; struct Object *guide_parent; struct EffectorWeights *effector_weights; diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h index 2657d6f6524..2ffae5955c4 100644 --- a/source/blender/makesdna/DNA_image_types.h +++ b/source/blender/makesdna/DNA_image_types.h @@ -17,11 +17,16 @@ namespace blender::bke { struct ImageRuntime; } // namespace blender::bke using ImageRuntimeHandle = blender::bke::ImageRuntime; + +namespace blender::gpu { +class Texture; +} // namespace blender::gpu +using GPUTexture = blender::gpu::Texture; #else typedef struct ImageRuntimeHandle ImageRuntimeHandle; +typedef struct GPUTexture GPUTexture; #endif -struct GPUTexture; struct MovieReader; struct MovieCache; struct PackedFile; @@ -140,7 +145,7 @@ typedef struct Image { /** Not written in file. */ struct MovieCache *cache; /** Not written in file, 2 = stereo eyes. */ - struct GPUTexture *gputexture[/*TEXTARGET_COUNT*/ 3][2]; + GPUTexture *gputexture[/*TEXTARGET_COUNT*/ 3][2]; /* sources from: */ ListBase anims; diff --git a/source/blender/makesdna/DNA_lightprobe_types.h b/source/blender/makesdna/DNA_lightprobe_types.h index 6a5697ba860..16028635a1a 100644 --- a/source/blender/makesdna/DNA_lightprobe_types.h +++ b/source/blender/makesdna/DNA_lightprobe_types.h @@ -16,6 +16,14 @@ struct AnimData; struct Object; +#ifdef __cplusplus +namespace blender::gpu { +class Texture; +} // namespace blender::gpu +using GPUTexture = blender::gpu::Texture; +#else +typedef struct GPUTexture GPUTexture; +#endif typedef struct LightProbe { #ifdef __cplusplus @@ -163,7 +171,7 @@ BLI_STATIC_ASSERT_ALIGN(LightGridCache, 16) /* ------ Eevee Lightcache ------- */ typedef struct LightCacheTexture { - struct GPUTexture *tex; + GPUTexture *tex; /** Copy of GPU data to create GPUTextures on file read. */ char *data; int tex_size[3]; @@ -192,7 +200,7 @@ typedef struct LightCache { LightCacheTexture grid_tx; /** Contains data for mipmap level 0. */ LightCacheTexture cube_tx; - /** Does not contains valid GPUTexture, only data. */ + /** Does not contains valid blender::gpu::Texture, only data. */ LightCacheTexture *cube_mips; /* All light-probes data contained in the cache. */ LightProbeCache *cube_data; diff --git a/source/blender/makesdna/DNA_movieclip_types.h b/source/blender/makesdna/DNA_movieclip_types.h index 265ff2e7f30..b98594227cf 100644 --- a/source/blender/makesdna/DNA_movieclip_types.h +++ b/source/blender/makesdna/DNA_movieclip_types.h @@ -19,6 +19,14 @@ struct MovieClipProxy; struct MovieTrackingMarker; struct MovieTrackingTrack; struct bGPdata; +#ifdef __cplusplus +namespace blender::gpu { +class Texture; +} // namespace blender::gpu +using GPUTexture = blender::gpu::Texture; +#else +typedef struct GPUTexture GPUTexture; +#endif typedef struct MovieClipUser { /** Current frame number. */ @@ -45,7 +53,7 @@ typedef struct MovieClip_RuntimeGPUTexture { void *next, *prev; MovieClipUser user; /** Not written in file. */ - struct GPUTexture *gputexture[/*TEXTARGET_COUNT*/ 3]; + GPUTexture *gputexture[/*TEXTARGET_COUNT*/ 3]; } MovieClip_RuntimeGPUTexture; typedef struct MovieClip_Runtime { diff --git a/source/blender/makesrna/intern/rna_image_api.cc b/source/blender/makesrna/intern/rna_image_api.cc index 05930f1e538..f274794a04f 100644 --- a/source/blender/makesrna/intern/rna_image_api.cc +++ b/source/blender/makesrna/intern/rna_image_api.cc @@ -223,7 +223,7 @@ static int rna_Image_gl_load( BKE_image_multilayer_index(image->rr, &iuser); } - GPUTexture *tex = BKE_image_get_gpu_texture(image, &iuser); + blender::gpu::Texture *tex = BKE_image_get_gpu_texture(image, &iuser); if (tex == nullptr) { BKE_reportf(reports, RPT_ERROR, "Failed to load image texture '%s'", image->id.name + 2); diff --git a/source/blender/python/gpu/gpu_py_framebuffer.cc b/source/blender/python/gpu/gpu_py_framebuffer.cc index 4f1225c27db..65ac70aa425 100644 --- a/source/blender/python/gpu/gpu_py_framebuffer.cc +++ b/source/blender/python/gpu/gpu_py_framebuffer.cc @@ -797,8 +797,8 @@ static PyMethodDef pygpu_framebuffer__tp_methods[] = { # endif #endif -/* Ideally type aliases would de-duplicate: `GPUTexture | dict[str, int | GPUTexture]` - * in this doc-string. */ +/* Ideally type aliases would de-duplicate: `blender::gpu::Texture | dict[str, int | + * blender::gpu::Texture]` in this doc-string. */ PyDoc_STRVAR( /* Wrap. */ pygpu_framebuffer__tp_doc, @@ -809,14 +809,15 @@ PyDoc_STRVAR( "texture is attached to the frame-buffer.\n" " For cube map textures, layer is translated into a cube map face.\n" "\n" - " :arg depth_slot: GPUTexture to attach or a `dict` containing keywords: " + " :arg depth_slot: blender::gpu::Texture to attach or a `dict` containing keywords: " "'texture', 'layer' and 'mip'.\n" - " :type depth_slot: :class:`gpu.types.GPUTexture` | dict[] | None\n" - " :arg color_slots: Tuple where each item can be a GPUTexture or a `dict` " + " :type depth_slot: :class:`gpu.types.blender::gpu::Texture` | dict[] | None\n" + " :arg color_slots: Tuple where each item can be a blender::gpu::Texture or a `dict` " "containing keywords: 'texture', 'layer' and 'mip'.\n" - " :type color_slots: :class:`gpu.types.GPUTexture` | " - "dict[str, int | :class:`gpu.types.GPUTexture`] | " - "Sequence[:class:`gpu.types.GPUTexture` | dict[str, int | :class:`gpu.types.GPUTexture`]] | " + " :type color_slots: :class:`gpu.types.blender::gpu::Texture` | " + "dict[str, int | :class:`gpu.types.blender::gpu::Texture`] | " + "Sequence[:class:`gpu.types.blender::gpu::Texture` | dict[str, int | " + ":class:`gpu.types.blender::gpu::Texture`]] | " "None\n"); PyTypeObject BPyGPUFrameBuffer_Type = { /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0) diff --git a/source/blender/python/gpu/gpu_py_offscreen.cc b/source/blender/python/gpu/gpu_py_offscreen.cc index a82d2a0c8ed..d2fe3f84aef 100644 --- a/source/blender/python/gpu/gpu_py_offscreen.cc +++ b/source/blender/python/gpu/gpu_py_offscreen.cc @@ -356,11 +356,11 @@ PyDoc_STRVAR( pygpu_offscreen_texture_color_doc, "The color texture attached.\n" "\n" - ":type: :class:`gpu.types.GPUTexture`"); + ":type: :class:`gpu.types.blender::gpu::Texture`"); static PyObject *pygpu_offscreen_texture_color_get(BPyGPUOffScreen *self, void * /*type*/) { BPY_GPU_OFFSCREEN_CHECK_OBJ(self); - GPUTexture *texture = GPU_offscreen_color_texture(self->ofs); + blender::gpu::Texture *texture = GPU_offscreen_color_texture(self->ofs); return BPyGPUTexture_CreatePyObject(texture, true); } diff --git a/source/blender/python/gpu/gpu_py_shader.cc b/source/blender/python/gpu/gpu_py_shader.cc index d2c6f2c59d4..f03e327a230 100644 --- a/source/blender/python/gpu/gpu_py_shader.cc +++ b/source/blender/python/gpu/gpu_py_shader.cc @@ -505,7 +505,7 @@ PyDoc_STRVAR( " :arg name: name of the uniform variable whose texture is to be specified.\n" " :type name: str\n" " :arg texture: Texture to attach.\n" - " :type texture: :class:`gpu.types.GPUTexture`\n"); + " :type texture: :class:`gpu.types.blender::gpu::Texture`\n"); static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args) { const char *name; @@ -534,7 +534,7 @@ PyDoc_STRVAR( " :arg name: Name of the image variable to which the texture is to be bound.\n" " :type name: str\n" " :arg texture: Texture to attach.\n" - " :type texture: :class:`gpu.types.GPUTexture`\n"); + " :type texture: :class:`gpu.types.blender::gpu::Texture`\n"); static PyObject *pygpu_shader_image(BPyGPUShader *self, PyObject *args) { const char *name; diff --git a/source/blender/python/gpu/gpu_py_shader_create_info.cc b/source/blender/python/gpu/gpu_py_shader_create_info.cc index 8ad3694fd69..73fa2cf2cf4 100644 --- a/source/blender/python/gpu/gpu_py_shader_create_info.cc +++ b/source/blender/python/gpu/gpu_py_shader_create_info.cc @@ -730,7 +730,8 @@ PyDoc_STRVAR( "\n" " :arg slot: The image resource index.\n" " :type slot: int\n" - " :arg format: The GPUTexture format that is passed to the shader. Possible values are:\n" + " :arg format: The blender::gpu::Texture format that is passed to the shader. Possible " + "values are:\n" "\n" PYDOC_TEX_FORMAT_ITEMS " :type format: str\n" " :arg type: The data type describing how the image is to be read in the shader. " diff --git a/source/blender/python/gpu/gpu_py_texture.cc b/source/blender/python/gpu/gpu_py_texture.cc index 756dee3fbc7..e1be706e654 100644 --- a/source/blender/python/gpu/gpu_py_texture.cc +++ b/source/blender/python/gpu/gpu_py_texture.cc @@ -32,7 +32,7 @@ #include "gpu_py_texture.hh" /* own include */ /* -------------------------------------------------------------------- */ -/** \name GPUTexture Common Utilities +/** \name blender::gpu::Texture Common Utilities * \{ */ const PyC_StringEnumItems pygpu_textureformat_items[] = { @@ -110,7 +110,7 @@ static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex) /** \} */ /* -------------------------------------------------------------------- */ -/** \name GPUTexture Type +/** \name blender::gpu::Texture Type * \{ */ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args, PyObject *kwds) @@ -134,7 +134,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args, "p" /* `is_cubemap` */ "O&" /* `format` */ "O!" /* `data` */ - ":GPUTexture.__new__", + ":blender::gpu::Texture.__new__", _keywords, nullptr, }; @@ -168,12 +168,16 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args, if (PySequence_Check(py_size)) { len = PySequence_Size(py_size); if ((len < 1) || (len > 3)) { - PyErr_Format(PyExc_ValueError, - "GPUTexture.__new__: \"size\" must be between 1 and 3 in length (got %d)", - len); + PyErr_Format( + PyExc_ValueError, + "blender::gpu::Texture.__new__: \"size\" must be between 1 and 3 in length (got %d)", + len); return nullptr; } - if (PyC_AsArray(size, sizeof(*size), py_size, len, &PyLong_Type, "GPUTexture.__new__") == -1) { + if (PyC_AsArray( + size, sizeof(*size), py_size, len, &PyLong_Type, "blender::gpu::Texture.__new__") == + -1) + { return nullptr; } } @@ -181,15 +185,17 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args, size[0] = PyLong_AsLong(py_size); } else { - PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Expected an int or tuple as first arg"); + PyErr_SetString(PyExc_ValueError, + "blender::gpu::Texture.__new__: Expected an int or tuple as first arg"); return nullptr; } void *data = nullptr; if (pybuffer_obj) { if (pybuffer_obj->format != GPU_DATA_FLOAT) { - PyErr_SetString(PyExc_ValueError, - "GPUTexture.__new__: Only Buffer of format `FLOAT` is currently supported"); + PyErr_SetString( + PyExc_ValueError, + "blender::gpu::Texture.__new__: Only Buffer of format `FLOAT` is currently supported"); return nullptr; } @@ -203,13 +209,14 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args, } if (bpygpu_Buffer_size(pybuffer_obj) < data_space_expected) { - PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Buffer size smaller than requested"); + PyErr_SetString(PyExc_ValueError, + "blender::gpu::Texture.__new__: Buffer size smaller than requested"); return nullptr; } data = pybuffer_obj->buf.as_void; } - GPUTexture *tex = nullptr; + blender::gpu::Texture *tex = nullptr; if (is_cubemap && len != 1) { STRNCPY(err_out, "In cubemaps the same dimension represents height, width and depth. No tuple needed"); @@ -558,7 +565,8 @@ static PyMethodDef pygpu_texture__tp_methods[] = { PyDoc_STRVAR( /* Wrap. */ pygpu_texture__tp_doc, - ".. class:: GPUTexture(size, layers=0, is_cubemap=False, format='RGBA8', data=None)\n" + ".. class:: blender::gpu::Texture(size, layers=0, is_cubemap=False, format='RGBA8', " + "data=None)\n" "\n" " This object gives access to off GPU textures.\n" "\n" @@ -618,7 +626,7 @@ PyDoc_STRVAR( " :type data: :class:`gpu.types.Buffer`\n"); PyTypeObject BPyGPUTexture_Type = { /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0) - /*tp_name*/ "GPUTexture", + /*tp_name*/ "blender::gpu::Texture", /*tp_basicsize*/ sizeof(BPyGPUTexture), /*tp_itemsize*/ 0, /*tp_dealloc*/ (destructor)BPyGPUTexture__tp_dealloc, @@ -679,15 +687,16 @@ PyDoc_STRVAR( pygpu_texture_from_image_doc, ".. function:: from_image(image)\n" "\n" - " Get GPUTexture corresponding to an Image datablock. The GPUTexture memory is " + " Get blender::gpu::Texture corresponding to an Image datablock. The blender::gpu::Texture " + "memory is " "shared with Blender.\n" " Note: Colors read from the texture will be in scene linear color space and have " "premultiplied or straight alpha matching the image alpha mode.\n" "\n" " :arg image: The Image datablock.\n" " :type image: :class:`bpy.types.Image`\n" - " :return: The GPUTexture used by the image.\n" - " :rtype: :class:`gpu.types.GPUTexture`\n"); + " :return: The blender::gpu::Texture used by the image.\n" + " :rtype: :class:`gpu.types.blender::gpu::Texture`\n"); static PyObject *pygpu_texture_from_image(PyObject * /*self*/, PyObject *arg) { Image *ima = static_cast(PyC_RNA_AsPointer(arg, "Image")); @@ -697,7 +706,7 @@ static PyObject *pygpu_texture_from_image(PyObject * /*self*/, PyObject *arg) ImageUser iuser; BKE_imageuser_default(&iuser); - GPUTexture *tex = BKE_image_get_gpu_texture(ima, &iuser); + blender::gpu::Texture *tex = BKE_image_get_gpu_texture(ima, &iuser); return BPyGPUTexture_CreatePyObject(tex, true); } @@ -732,7 +741,7 @@ static PyModuleDef pygpu_texture_module_def = { int bpygpu_ParseTexture(PyObject *o, void *p) { if (o == Py_None) { - *(GPUTexture **)p = nullptr; + *(blender::gpu::Texture **)p = nullptr; return 1; } @@ -746,7 +755,7 @@ int bpygpu_ParseTexture(PyObject *o, void *p) return 0; } - *(GPUTexture **)p = ((BPyGPUTexture *)o)->tex; + *(blender::gpu::Texture **)p = ((BPyGPUTexture *)o)->tex; return 1; } @@ -764,7 +773,7 @@ PyObject *bpygpu_texture_init() /** \name Public API * \{ */ -PyObject *BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference) +PyObject *BPyGPUTexture_CreatePyObject(blender::gpu::Texture *tex, bool shared_reference) { BPyGPUTexture *self; diff --git a/source/blender/python/gpu/gpu_py_texture.hh b/source/blender/python/gpu/gpu_py_texture.hh index dc5a8e887c1..49838bb06b3 100644 --- a/source/blender/python/gpu/gpu_py_texture.hh +++ b/source/blender/python/gpu/gpu_py_texture.hh @@ -12,7 +12,9 @@ #include "BLI_compiler_attrs.h" -struct GPUTexture; +namespace blender::gpu { +class Texture; +} extern PyTypeObject BPyGPUTexture_Type; @@ -28,11 +30,11 @@ extern const struct PyC_StringEnumItems pygpu_textureformat_items[]; struct BPyGPUTexture { PyObject_HEAD - GPUTexture *tex; + blender::gpu::Texture *tex; }; [[nodiscard]] int bpygpu_ParseTexture(PyObject *o, void *p); [[nodiscard]] PyObject *bpygpu_texture_init(); -[[nodiscard]] PyObject *BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference) - ATTR_NONNULL(1); +[[nodiscard]] PyObject *BPyGPUTexture_CreatePyObject(blender::gpu::Texture *tex, + bool shared_reference) ATTR_NONNULL(1); diff --git a/source/blender/render/RE_pipeline.h b/source/blender/render/RE_pipeline.h index 00994f245af..fb952920418 100644 --- a/source/blender/render/RE_pipeline.h +++ b/source/blender/render/RE_pipeline.h @@ -12,7 +12,9 @@ #include "DNA_listBase.h" #include "DNA_vec_types.h" -struct GPUTexture; +namespace blender::gpu { +class Texture; +} struct ImBuf; struct Image; struct ImageFormatData; @@ -478,7 +480,8 @@ void RE_pass_set_buffer_data(struct RenderPass *pass, float *data); /** * Ensure a GPU texture corresponding to the render buffer data exists. */ -struct GPUTexture *RE_pass_ensure_gpu_texture_cache(struct Render *re, struct RenderPass *rpass); +blender::gpu::Texture *RE_pass_ensure_gpu_texture_cache(struct Render *re, + struct RenderPass *rpass); /* shaded view or baking options */ #define RE_BAKE_NORMALS 0 diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 895ca83cc3f..5077e70ba5c 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -221,7 +221,7 @@ void GPURenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport) void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) { eGPUTextureFormat format; - GPUTexture **tex; + blender::gpu::Texture **tex; if (aov_key == pxr::HdAovTokens->color) { format = GPU_RGBA32F; tex = &tex_color_; @@ -252,7 +252,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) { - GPUTexture *tex = nullptr; + blender::gpu::Texture *tex = nullptr; int c; if (aov_key == pxr::HdAovTokens->color) { tex = tex_color_; @@ -306,7 +306,7 @@ void GPURenderTaskDelegate::unbind() CLOG_DEBUG(LOG_HYDRA_RENDER, "unbind"); } -GPUTexture *GPURenderTaskDelegate::get_aov_texture(pxr::TfToken const &aov_key) +blender::gpu::Texture *GPURenderTaskDelegate::get_aov_texture(pxr::TfToken const &aov_key) { if (aov_key == pxr::HdAovTokens->color) { return tex_color_; diff --git a/source/blender/render/hydra/render_task_delegate.hh b/source/blender/render/hydra/render_task_delegate.hh index 092843d5d61..52793459fc3 100644 --- a/source/blender/render/hydra/render_task_delegate.hh +++ b/source/blender/render/hydra/render_task_delegate.hh @@ -47,8 +47,8 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate { class GPURenderTaskDelegate : public RenderTaskDelegate { private: GPUFrameBuffer *framebuffer_ = nullptr; - GPUTexture *tex_color_ = nullptr; - GPUTexture *tex_depth_ = nullptr; + blender::gpu::Texture *tex_color_ = nullptr; + blender::gpu::Texture *tex_depth_ = nullptr; unsigned int VAO_ = 0; public: @@ -60,7 +60,7 @@ class GPURenderTaskDelegate : public RenderTaskDelegate { void read_aov(pxr::TfToken const &aov_key, void *data) override; void bind() override; void unbind() override; - GPUTexture *get_aov_texture(pxr::TfToken const &aov_key); + blender::gpu::Texture *get_aov_texture(pxr::TfToken const &aov_key); }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index f056827f280..6a29e1c0448 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -198,7 +198,7 @@ void DrawTexture::create_from_buffer(pxr::HdRenderBuffer *buffer) buffer->Unmap(); } -void DrawTexture::draw(GPUShader *shader, const pxr::GfVec4d &viewport, GPUTexture *tex) +void DrawTexture::draw(GPUShader *shader, const pxr::GfVec4d &viewport, blender::gpu::Texture *tex) { if (!tex) { tex = texture_; @@ -215,7 +215,7 @@ void DrawTexture::draw(GPUShader *shader, const pxr::GfVec4d &viewport, GPUTextu GPU_matrix_pop(); } -GPUTexture *DrawTexture::texture() const +blender::gpu::Texture *DrawTexture::texture() const { return texture_; } diff --git a/source/blender/render/hydra/viewport_engine.hh b/source/blender/render/hydra/viewport_engine.hh index bfabdcf1ff9..1ef638ff702 100644 --- a/source/blender/render/hydra/viewport_engine.hh +++ b/source/blender/render/hydra/viewport_engine.hh @@ -16,7 +16,7 @@ namespace blender::render::hydra { class DrawTexture { private: - GPUTexture *texture_ = nullptr; + blender::gpu::Texture *texture_ = nullptr; gpu::Batch *batch_; public: @@ -24,8 +24,8 @@ class DrawTexture { ~DrawTexture(); void create_from_buffer(pxr::HdRenderBuffer *buffer); - void draw(GPUShader *shader, const pxr::GfVec4d &viewport, GPUTexture *tex = nullptr); - GPUTexture *texture() const; + void draw(GPUShader *shader, const pxr::GfVec4d &viewport, blender::gpu::Texture *tex = nullptr); + blender::gpu::Texture *texture() const; private: }; diff --git a/source/blender/render/intern/compositor.cc b/source/blender/render/intern/compositor.cc index b6d552bd868..7498519d226 100644 --- a/source/blender/render/intern/compositor.cc +++ b/source/blender/render/intern/compositor.cc @@ -91,7 +91,7 @@ class Context : public compositor::Context { /* Cached GPU and CPU passes that the compositor took ownership of. Those had their reference * count incremented when accessed and need to be freed/have their reference count decremented * when destroying the context. */ - Vector cached_gpu_passes_; + Vector cached_gpu_passes_; Vector cached_cpu_passes_; public: @@ -107,7 +107,7 @@ class Context : public compositor::Context { { output_result_.release(); viewer_output_result_.release(); - for (GPUTexture *pass : cached_gpu_passes_) { + for (blender::gpu::Texture *pass : cached_gpu_passes_) { GPU_texture_free(pass); } for (ImBuf *pass : cached_cpu_passes_) { @@ -277,7 +277,7 @@ class Context : public compositor::Context { *this, this->result_type_from_pass(render_pass), compositor::ResultPrecision::Full); if (this->use_gpu()) { - GPUTexture *pass_texture = RE_pass_ensure_gpu_texture_cache(render, render_pass); + blender::gpu::Texture *pass_texture = RE_pass_ensure_gpu_texture_cache(render, render_pass); /* Don't assume render will keep pass data stored, add our own reference. */ GPU_texture_ref(pass_texture); pass.wrap_external(pass_texture); diff --git a/source/blender/render/intern/render_result.cc b/source/blender/render/intern/render_result.cc index ee383794b1e..136694a6c78 100644 --- a/source/blender/render/intern/render_result.cc +++ b/source/blender/render/intern/render_result.cc @@ -462,7 +462,7 @@ void RE_pass_set_buffer_data(RenderPass *pass, float *data) IMB_assign_float_buffer(ibuf, data, IB_TAKE_OWNERSHIP); } -GPUTexture *RE_pass_ensure_gpu_texture_cache(Render *re, RenderPass *rpass) +blender::gpu::Texture *RE_pass_ensure_gpu_texture_cache(Render *re, RenderPass *rpass) { ImBuf *ibuf = rpass->ibuf; diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc index 211db1db171..fe9604e383f 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc @@ -711,7 +711,7 @@ static wmGizmo *gizmo_find_intersected_3d(bContext *C, if (viewport == nullptr) { return nullptr; } - GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); + blender::gpu::Texture *depth_tx = GPU_viewport_depth_texture(viewport); GPUFrameBuffer *depth_read_fb = nullptr; GPU_framebuffer_ensure_config(&depth_read_fb, { diff --git a/source/blender/windowmanager/intern/wm_draw.cc b/source/blender/windowmanager/intern/wm_draw.cc index a1d417ae10b..021eee7d07e 100644 --- a/source/blender/windowmanager/intern/wm_draw.cc +++ b/source/blender/windowmanager/intern/wm_draw.cc @@ -249,7 +249,7 @@ static void wm_software_cursor_draw_bitmap(const float system_scale, float gl_matrix[4][4]; eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL; - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "software_cursor", bitmap->data_size[0], bitmap->data_size[1], 1, GPU_RGBA8, usage, nullptr); GPU_texture_update(texture, GPU_DATA_UBYTE, bitmap->data); GPU_texture_filter_mode(texture, false); @@ -682,7 +682,7 @@ static void wm_draw_region_buffer_free(ARegion *region) static void wm_draw_offscreen_texture_parameters(GPUOffScreen *offscreen) { /* Setup offscreen color texture for drawing. */ - GPUTexture *texture = GPU_offscreen_color_texture(offscreen); + blender::gpu::Texture *texture = GPU_offscreen_color_texture(offscreen); /* No mipmaps or filtering. */ GPU_texture_mipmap_mode(texture, false, false); @@ -822,7 +822,7 @@ static void wm_draw_region_blit(ARegion *region, int view) } } -GPUTexture *wm_draw_region_texture(ARegion *region, int view) +blender::gpu::Texture *wm_draw_region_texture(ARegion *region, int view) { if (!region->runtime->draw_buffer) { return nullptr; @@ -892,7 +892,7 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend) } /* Setup actual texture. */ - GPUTexture *texture = wm_draw_region_texture(region, view); + blender::gpu::Texture *texture = wm_draw_region_texture(region, view); GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR); GPU_shader_bind(shader); @@ -1247,7 +1247,7 @@ static void wm_draw_window(bContext *C, wmWindow *win) nullptr); if (offscreen) { - GPUTexture *texture = GPU_offscreen_color_texture(offscreen); + blender::gpu::Texture *texture = GPU_offscreen_color_texture(offscreen); wm_draw_offscreen_texture_parameters(offscreen); for (int view = 0; view < 2; view++) { diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index 41601bfff67..2a1b15736a3 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -2561,7 +2561,7 @@ struct RadialControl { int slow_mouse[2] = {}; bool slow_mode = false; Dial *dial = nullptr; - GPUTexture *texture = nullptr; + blender::gpu::Texture *texture = nullptr; ListBase orig_paintcursors = {}; bool use_secondary_tex = false; void *cursor = nullptr; diff --git a/source/blender/windowmanager/intern/wm_playanim.cc b/source/blender/windowmanager/intern/wm_playanim.cc index 49b69ec0ff3..14a4102aa7a 100644 --- a/source/blender/windowmanager/intern/wm_playanim.cc +++ b/source/blender/windowmanager/intern/wm_playanim.cc @@ -597,7 +597,7 @@ static void draw_display_buffer(const PlayDisplayContext &display_ctx, /* NOTE: This may fail, especially for large images that exceed the GPU's texture size limit. * Large images could be supported although this isn't so common for animation playback. */ - GPUTexture *texture = GPU_texture_create_2d( + blender::gpu::Texture *texture = GPU_texture_create_2d( "display_buf", ibuf->x, ibuf->y, 1, format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr); if (texture) { diff --git a/source/blender/windowmanager/wm_draw.hh b/source/blender/windowmanager/wm_draw.hh index f9b11d49fa5..e248c3fd934 100644 --- a/source/blender/windowmanager/wm_draw.hh +++ b/source/blender/windowmanager/wm_draw.hh @@ -10,7 +10,9 @@ struct ARegion; struct GPUOffScreen; -struct GPUTexture; +namespace blender::gpu { +class Texture; +} struct GPUViewport; struct ScrArea; struct bContext; @@ -30,4 +32,4 @@ void wm_draw_region_clear(wmWindow *win, ARegion *region); void wm_draw_region_blend(ARegion *region, int view, bool blend); void wm_draw_region_test(bContext *C, ScrArea *area, ARegion *region); -GPUTexture *wm_draw_region_texture(ARegion *region, int view); +blender::gpu::Texture *wm_draw_region_texture(ARegion *region, int view);