Blender V4.3
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
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
18
26
31
32 /* Which tile of the screen is used with this texture. Used to safely calculate the correct
33 * offset of the textures. */
35
43 gpu::Batch *batch = nullptr;
44
48 GPUTexture *texture = nullptr;
49
51
53 {
54 if (batch != nullptr) {
56 batch = nullptr;
57 }
58
59 if (texture != nullptr) {
60 GPU_texture_free(texture);
61 texture = nullptr;
62 }
63 }
64
71 int2 offset() const
72 {
74 }
75
76 void ensure_gpu_texture(int2 texture_size)
77 {
78 const bool is_allocated = texture != nullptr;
79 const bool resolution_changed = assign_if_different(last_texture_size, texture_size);
80 const bool should_be_freed = is_allocated && resolution_changed;
81 const bool should_be_created = !is_allocated || resolution_changed;
82
83 if (should_be_freed) {
84 GPU_texture_free(texture);
85 texture = nullptr;
86 }
87
88 if (should_be_created) {
89 texture = DRW_texture_create_2d_ex(UNPACK2(texture_size),
92 static_cast<DRWTextureFlag>(0),
93 nullptr);
94 }
95 need_full_update |= should_be_created;
96 }
97};
98
99} // namespace blender::draw::image_engine
#define UNPACK2(a)
DRWTextureFlag
void GPU_batch_discard(blender::gpu::Batch *batch)
void GPU_texture_free(GPUTexture *texture)
@ GPU_TEXTURE_USAGE_GENERAL
GPUTexture * DRW_texture_create_2d_ex(int w, int h, eGPUTextureFormat format, eGPUTextureUsage usage, DRWTextureFlag flags, const float *fpixels)
bool assign_if_different(T &old_value, T new_value)
VecBase< int32_t, 2 > int2
gpu::Batch * batch
Batch to draw the associated text on the screen.
bool need_full_update
does this texture need a full update.
rcti clipping_bounds
area of the texture in screen space.
int2 offset() const
return the offset of the texture with the area.
rctf clipping_uv_bounds
uv area of the texture in screen space.
int ymin
int xmin