Blender V4.5
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
9#include "RNA_blender_cpp.hh"
10
12
13#include "util/unique_ptr.h"
14
15struct GPUContext;
16struct GPUFence;
17struct GPUShader;
18
20
21/* Base class of shader used for display driver rendering. */
23 public:
24 static constexpr const char *position_attribute_name = "pos";
25 static constexpr const char *tex_coord_attribute_name = "texCoord";
26
27 /* Create shader implementation suitable for the given render engine and scene configuration. */
28 static unique_ptr<BlenderDisplayShader> create(BL::RenderEngine &b_engine, BL::Scene &b_scene);
29
31 virtual ~BlenderDisplayShader() = default;
32
33 virtual GPUShader *bind(const int width, const int height) = 0;
34 virtual void unbind() = 0;
35
36 /* Get attribute location for position and texture coordinate respectively.
37 * NOTE: The shader needs to be bound to have access to those. */
38 virtual int get_position_attrib_location();
40
41 protected:
42 /* Get program of this display shader.
43 * NOTE: The shader needs to be bound to have access to this. */
44 virtual GPUShader *get_shader_program() = 0;
45
46 /* Cached values of various OpenGL resources. */
49};
50
51/* Implementation of display rendering shader used in the case when render engine does not support
52 * display space shader. */
54 public:
56
57 GPUShader *bind(const int width, const int height) override;
58 void unbind() override;
59
60 protected:
61 GPUShader *get_shader_program() override;
62
64 void destroy_shader();
65
66 GPUShader *shader_program_ = nullptr;
69
70 /* Shader compilation attempted. Which means, that if the shader program is 0 then compilation or
71 * linking has failed. Do not attempt to re-compile the shader. */
73};
74
76 public:
77 BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene);
78
79 GPUShader *bind(const int width, const int height) override;
80 void unbind() override;
81
82 protected:
83 GPUShader *get_shader_program() override;
84
85 BL::RenderEngine b_engine_;
86 BL::Scene &b_scene_;
87
88 /* Cached values of various OpenGL resources. */
89 GPUShader *shader_program_ = nullptr;
90};
91
92/* Display driver implementation which is specific for Blender viewport integration. */
94 public:
95 BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background);
96 ~BlenderDisplayDriver() override;
97
98 void graphics_interop_activate() override;
99 void graphics_interop_deactivate() override;
100
101 void zero() override;
102
103 void set_zoom(const float zoom_x, const float zoom_y);
104
105 protected:
106 void next_tile_begin() override;
107
108 bool update_begin(const Params &params,
109 const int texture_width,
110 const int texture_height) override;
111 void update_end() override;
112
113 half4 *map_texture_buffer() override;
114 void unmap_texture_buffer() override;
115
117 void graphics_interop_update_buffer() override;
118
119 void draw(const Params &params) override;
120
121 void flush() override;
122
123 /* Helper function which allocates new GPU context. */
124 void gpu_context_create();
125 bool gpu_context_enable();
126 void gpu_context_disable();
127 void gpu_context_destroy();
128 void gpu_context_lock();
129 void gpu_context_unlock();
130
131 /* Create GPU resources used by the display driver. */
133
134 /* Destroy all GPU resources which are being used by this object. */
136
137 BL::RenderEngine b_engine_;
139
140 /* Content of the display is to be filled with zeroes. */
141 std::atomic<bool> need_zero_ = true;
142
144
145 /* Opaque storage for an internal state and data for tiles. */
146 struct Tiles;
148
149 GPUFence *gpu_render_sync_ = nullptr;
150 GPUFence *gpu_upload_sync_ = nullptr;
151
152 float2 zoom_ = make_float2(1.0f, 1.0f);
153};
154
GraphicsInteropDevice graphics_interop_get_device() override
half4 * map_texture_buffer() override
void graphics_interop_activate() override
void draw(const Params &params) override
std::atomic< bool > need_zero_
unique_ptr< BlenderDisplayShader > display_shader_
void graphics_interop_deactivate() override
void graphics_interop_update_buffer() override
BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background)
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)
virtual GPUShader * get_shader_program()=0
virtual int get_position_attrib_location()
static unique_ptr< BlenderDisplayShader > create(BL::RenderEngine &b_engine, BL::Scene &b_scene)
static constexpr const char * tex_coord_attribute_name
static constexpr const char * position_attribute_name
BlenderDisplayShader()=default
virtual void unbind()=0
virtual GPUShader * bind(const int width, const int height)=0
virtual int get_tex_coord_attrib_location()
virtual ~BlenderDisplayShader()=default
GPUShader * get_shader_program() override
BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene)
GPUShader * bind(const int width, const int height) override
GPUShader * bind(const int width, const int height) override
GPUShader * get_shader_program() override
DisplayDriver()=default
#define CCL_NAMESPACE_END
ccl_device_forceinline float2 make_float2(const float x, const float y)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Definition half.h:60