Blender V5.3
blender/display_driver.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include <atomic>
8
10
11#include "util/thread.h"
12#include "util/unique_ptr.h"
13
14namespace blender {
15struct GPUContext;
16struct GPUFence;
17struct RenderEngine;
18struct Scene;
19namespace gpu {
20class Shader;
21} // namespace gpu
22} // namespace blender
23
25
26/* Base class of shader used for display driver rendering. */
28 public:
29 static constexpr const char *position_attribute_name = "pos";
30 static constexpr const char *tex_coord_attribute_name = "texCoord";
31
32 /* Create shader implementation suitable for the given render engine and scene configuration. */
34 blender::Scene &b_scene);
35
37 virtual ~BlenderDisplayShader() = default;
38
39 virtual blender::gpu::Shader *bind(const int width, const int height) = 0;
40 virtual void unbind() = 0;
41
42 /* Get attribute location for position and texture coordinate respectively.
43 * NOTE: The shader needs to be bound to have access to those. */
44 virtual int get_position_attrib_location();
46
47 protected:
48 /* Get program of this display shader.
49 * NOTE: The shader needs to be bound to have access to this. */
51
52 /* Cached values of various OpenGL resources. */
55};
56
58 public:
60
61 blender::gpu::Shader *bind(const int width, const int height) override;
62 void unbind() override;
63
64 protected:
66
69
70 /* Cached values of various OpenGL resources. */
72};
73
74/* Display driver implementation which is specific for Blender viewport integration. */
76 public:
78 blender::Scene &b_scene,
80 const bool background);
81 ~BlenderDisplayDriver() override;
82
83 void graphics_interop_activate() override;
84 void graphics_interop_deactivate() override;
85
86 void zero() override;
87
88 void set_zoom(const float zoom_x, const float zoom_y);
89
90 protected:
91 void reset() override;
92 void next_tile_begin() override;
93
94 bool update_begin(const Params &params,
95 const int texture_width,
96 const int texture_height) override;
97 void update_end() override;
98
99 half4 *map_texture_buffer() override;
100 void unmap_texture_buffer() override;
101
103 void graphics_interop_update_buffer() override;
104
105 void draw(const Params &params) override;
106
107 void flush() override;
108
109 /* Helper function which allocates new GPU context. */
110 void gpu_context_create();
111 bool gpu_context_enable();
112 void gpu_context_disable();
113 void gpu_context_destroy();
114 void gpu_context_lock();
115 void gpu_context_unlock();
116
117 /* Create GPU resources used by the display driver. */
119
120 /* Destroy all GPU resources which are being used by this object. */
122
126
127 /* Content of the display is to be filled with zeroes. */
128 std::atomic<bool> need_zero_ = true;
129
131
132 /* Opaque storage for an internal state and data for tiles. */
133 struct Tiles;
135
136 blender::GPUFence *gpu_render_sync_ = nullptr;
137 blender::GPUFence *gpu_upload_sync_ = nullptr;
138
139 float2 zoom_ = make_float2(1.0f, 1.0f);
140
143 bool update_pending_ = true;
144};
145
GraphicsInteropDevice graphics_interop_get_device() override
half4 * map_texture_buffer() override
blender::GPUFence * gpu_upload_sync_
thread_condition_variable has_update_cond_
blender::RegionView3D * b_rv3d_
void graphics_interop_activate() override
std::atomic< bool > need_zero_
unique_ptr< BlenderDisplayShader > display_shader_
void graphics_interop_deactivate() override
blender::GPUFence * gpu_render_sync_
void graphics_interop_update_buffer() override
blender::RenderEngine & b_engine_
bool update_begin(const Params &params, const int texture_width, const int texture_height) override
void set_zoom(const float zoom_x, const float zoom_y)
BlenderDisplayDriver(blender::RenderEngine &b_engine, blender::Scene &b_scene, blender::RegionView3D *b_rv3d, const bool background)
virtual int get_position_attrib_location()
static constexpr const char * tex_coord_attribute_name
static constexpr const char * position_attribute_name
static unique_ptr< BlenderDisplayShader > create(blender::RenderEngine &b_engine, blender::Scene &b_scene)
BlenderDisplayShader()=default
virtual void unbind()=0
virtual blender::gpu::Shader * get_shader_program()=0
virtual blender::gpu::Shader * bind(const int width, const int height)=0
virtual int get_tex_coord_attrib_location()
virtual ~BlenderDisplayShader()=default
blender::gpu::Shader * shader_program_
blender::gpu::Shader * bind(const int width, const int height) override
blender::gpu::Shader * get_shader_program() override
blender::RenderEngine & b_engine_
BlenderDisplaySpaceShader(blender::RenderEngine &b_engine, blender::Scene &b_scene)
DisplayDriver()=default
#define CCL_NAMESPACE_END
BMesh Iterators.
#define make_float2
Definition half.h:53
std::mutex thread_mutex
Definition thread.h:27
std::condition_variable thread_condition_variable
Definition thread.h:29