Blender V5.0
image_texture_info.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_math_matrix.hh"
12#include "BLI_rect.h"
13
14#include "GPU_batch.hh"
15#include "GPU_texture.hh"
16
17#include "DRW_gpu_wrapper.hh"
18#include "DRW_render.hh"
19
20namespace blender::image_engine {
21using namespace blender::draw;
22
30
35
36 /* Which tile of the screen is used with this texture. Used to safely calculate the correct
37 * offset of the textures. */
39
47 gpu::Batch *batch = nullptr;
48
52 Texture texture = {"Image.Tile"};
53
55
56 TextureInfo() = default;
57 TextureInfo(TextureInfo &&other) = default;
58
60 {
61 if (batch != nullptr) {
63 batch = nullptr;
64 }
65 }
66
73 int2 offset() const
74 {
75 return int2(clipping_bounds.xmin, clipping_bounds.ymin);
76 }
77
78 void ensure_gpu_texture(int2 texture_size)
79 {
80 const bool is_allocated = texture.is_valid();
81 const bool resolution_changed = assign_if_different(last_texture_size, texture_size);
82 const bool should_be_freed = is_allocated && resolution_changed;
83 const bool should_be_created = !is_allocated || resolution_changed;
84
85 if (should_be_freed) {
86 texture.free();
87 }
88
89 if (should_be_created) {
90 texture.ensure_2d(
91 gpu::TextureFormat::SFLOAT_16_16_16_16, texture_size, GPU_TEXTURE_USAGE_SHADER_READ);
92 }
93 need_full_update |= should_be_created;
94 }
95};
96
97} // namespace blender::image_engine
void GPU_batch_discard(blender::gpu::Batch *batch)
@ GPU_TEXTURE_USAGE_SHADER_READ
NonCopyable(const NonCopyable &other)=delete
bool assign_if_different(T &old_value, T new_value)
VecBase< int32_t, 2 > int2
rctf clipping_uv_bounds
uv area of the texture in screen space.
TextureInfo(TextureInfo &&other)=default
int2 offset() const
return the offset of the texture with the area.
rcti clipping_bounds
area of the texture in screen space.
gpu::Batch * batch
Batch to draw the associated text on the screen.
void ensure_gpu_texture(int2 texture_size)
bool need_full_update
does this texture need a full update.
Texture texture
GPU Texture for a partial region of the image editor.