Blender V4.3
smaa_precomputed_textures.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <memory>
6
7#include "BLI_smaa_textures.h"
8
9#include "GPU_shader.hh"
10#include "GPU_texture.hh"
11
13
15
16/* ------------------------------------------------------------------------------------------------
17 * SMAA Precomputed Textures.
18 */
19
21{
22 search_texture_ = GPU_texture_create_2d("SMAA Search",
25 1,
26 GPU_R8,
28 nullptr);
30 GPU_texture_filter_mode(search_texture_, true);
31
32 area_texture_ = GPU_texture_create_2d("SMAA Area",
35 1,
36 GPU_RG8,
38 nullptr);
40 GPU_texture_filter_mode(area_texture_, true);
41}
42
48
50 const char *sampler_name) const
51{
52 const int texture_image_unit = GPU_shader_get_sampler_binding(shader, sampler_name);
53 GPU_texture_bind(search_texture_, texture_image_unit);
54}
55
60
61void SMAAPrecomputedTextures::bind_area_texture(GPUShader *shader, const char *sampler_name) const
62{
63 const int texture_image_unit = GPU_shader_get_sampler_binding(shader, sampler_name);
64 GPU_texture_bind(area_texture_, texture_image_unit);
65}
66
71
72/* ------------------------------------------------------------------------------------------------
73 * SMAA Precomputed Textures Container.
74 */
75
77{
78 /* First, delete the textures if they are no longer needed. */
79 if (textures_ && !textures_->needed) {
80 textures_.reset();
81 }
82
83 /* Second, if they were not deleted, reset their needed status to false to ready them to track
84 * their needed status for the next evaluation. */
85 if (textures_) {
86 textures_->needed = false;
87 }
88}
89
91{
92 if (!textures_) {
93 textures_ = std::make_unique<SMAAPrecomputedTextures>();
94 }
95
96 textures_->needed = true;
97 return *textures_;
98}
99
100} // namespace blender::realtime_compositor
#define SEARCHTEX_HEIGHT
const unsigned char searchTexBytes[]
#define SEARCHTEX_WIDTH
#define AREATEX_HEIGHT
const unsigned char areaTexBytes[]
#define AREATEX_WIDTH
int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name)
void GPU_texture_bind(GPUTexture *texture, int unit)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
void GPU_texture_unbind(GPUTexture *texture)
@ GPU_DATA_UBYTE
@ GPU_TEXTURE_USAGE_SHADER_READ
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
@ GPU_RG8
@ GPU_R8
void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
struct GPUShader GPUShader
void bind_search_texture(GPUShader *shader, const char *sampler_name) const
void bind_area_texture(GPUShader *shader, const char *sampler_name) const