Blender V5.3
image_drawing_mode_image_space.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Foundation.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "image_instance.hh"
11#include "image_shader.hh"
12
13namespace blender::image_engine {
14
17 gpu::Texture *tile_mapping_texture,
18 const bool owned)
19 : instance_(instance), texture_(texture), tile_mapping_texture_(tile_mapping_texture)
20{
21 if (!owned) {
22 GPU_texture_ref(texture_);
23 if (tile_mapping_texture_) {
24 GPU_texture_ref(tile_mapping_texture_);
25 }
26 }
27}
28
30{
31 GPU_texture_free(texture_);
32 if (tile_mapping_texture_) {
33 GPU_texture_free(tile_mapping_texture_);
34 }
35}
36
38
39void ImageSpaceDrawingMode::image_sync(blender::Image * /*image*/, ImageUser * /*iuser*/) const {}
40
42{
43 PassSimple &pass = instance_.state.image_ps;
44 pass.init();
46 pass.shader_set(tile_mapping_texture_ ? ShaderModule::module_get().image_tiled.get() :
47 ShaderModule::module_get().image.get());
48 pass.push_constant("image_matrix", float4x4(instance_.state.ss_to_texture));
49 pass.push_constant("far_near_distances", instance_.state.sh_params.far_near);
50 pass.push_constant("shuffle", instance_.state.sh_params.shuffle);
51 pass.push_constant("draw_flags", int32_t(instance_.state.sh_params.flags));
52 pass.push_constant("is_image_premultiplied", instance_.state.sh_params.use_premul_alpha);
53
54 /* The shader will discard fragments that are outside of the image if repeating is disabled, so
55 * we just always have repeat mode enabled. */
59
60 if (tile_mapping_texture_) {
61 pass.bind_texture("image_tile_array", texture_, sampler);
62 pass.bind_texture("image_tile_data", tile_mapping_texture_, sampler);
63 }
64 else {
65 pass.push_constant("is_repeated", instance_.state.flags.do_tile_drawing);
66 pass.bind_texture("image_tx", texture_, sampler);
67 }
69 instance_.manager->submit(instance_.state.image_ps, instance_.state.view);
70}
71
72}; // namespace blender::image_engine
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
Definition draw_pass.hh:976
void shader_set(gpu::Shader *shader)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void state_set(DRWState state, int clip_plane_count=0)
void push_constant(const char *name, const float &data)
A running instance of the engine.
void image_sync(blender::Image *image, blender::ImageUser *iuser) const override
ImageSpaceDrawingMode(Instance &instance, gpu::Texture *texture, gpu::Texture *tile_mapping_texture=nullptr, const bool owned=false)
static ShaderModule & module_get()
#define sampler(slot)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
detail::Pass< command::DrawCommandBuf > PassSimple
@ GPU_SAMPLER_EXTEND_MODE_REPEAT
@ GPU_SAMPLER_FILTERING_DEFAULT
MatBase< float, 4, 4 > float4x4
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:32
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:31
@ DRW_STATE_DEPTH_ALWAYS
Definition draw_state.hh:38
void GPU_texture_free(gpu::Texture *texture)
signed int int32_t
Definition BKE_text.h:78
void GPU_texture_ref(gpu::Texture *texture)