Blender V4.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
9#include "MEM_guardedalloc.h"
10
11#include "RNA_blender_cpp.hh"
12
14
15#include "util/thread.h"
16#include "util/unique_ptr.h"
17#include "util/vector.h"
18
19typedef struct GPUContext GPUContext;
20typedef struct GPUFence GPUFence;
21typedef struct GPUShader GPUShader;
22
24
25/* Base class of shader used for display driver rendering. */
27 public:
28 static constexpr const char *position_attribute_name = "pos";
29 static constexpr const char *tex_coord_attribute_name = "texCoord";
30
31 /* Create shader implementation suitable for the given render engine and scene configuration. */
32 static unique_ptr<BlenderDisplayShader> create(BL::RenderEngine &b_engine, BL::Scene &b_scene);
33
35 virtual ~BlenderDisplayShader() = default;
36
37 virtual GPUShader *bind(int width, int height) = 0;
38 virtual void unbind() = 0;
39
40 /* Get attribute location for position and texture coordinate respectively.
41 * NOTE: The shader needs to be bound to have access to those. */
42 virtual int get_position_attrib_location();
44
45 protected:
46 /* Get program of this display shader.
47 * NOTE: The shader needs to be bound to have access to this. */
49
50 /* Cached values of various OpenGL resources. */
53};
54
55/* Implementation of display rendering shader used in the case when render engine does not support
56 * display space shader. */
58 public:
59 virtual GPUShader *bind(int width, int height) override;
60 virtual void unbind() override;
61
62 protected:
63 virtual GPUShader *get_shader_program() override;
64
66 void destroy_shader();
67
71
72 /* Shader compilation attempted. Which means, that if the shader program is 0 then compilation or
73 * linking has failed. Do not attempt to re-compile the shader. */
75};
76
78 public:
79 BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene);
80
81 virtual GPUShader *bind(int width, int height) override;
82 virtual void unbind() override;
83
84 protected:
85 virtual GPUShader *get_shader_program() override;
86
87 BL::RenderEngine b_engine_;
88 BL::Scene &b_scene_;
89
90 /* Cached values of various OpenGL resources. */
92};
93
94/* Display driver implementation which is specific for Blender viewport integration. */
96 public:
97 BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background);
99
100 virtual void graphics_interop_activate() override;
101 virtual void graphics_interop_deactivate() override;
102
103 virtual void clear() override;
104
105 void set_zoom(float zoom_x, float zoom_y);
106
107 protected:
108 virtual void next_tile_begin() override;
109
110 virtual bool update_begin(const Params &params, int texture_width, int texture_height) override;
111 virtual void update_end() override;
112
113 virtual half4 *map_texture_buffer() override;
114 virtual void unmap_texture_buffer() override;
115
116 virtual GraphicsInterop graphics_interop_get() override;
117
118 virtual void draw(const Params &params) override;
119
120 virtual void flush() override;
121
122 /* Helper function which allocates new GPU context. */
123 void gpu_context_create();
124 bool gpu_context_enable();
125 void gpu_context_disable();
126 void gpu_context_destroy();
127 void gpu_context_lock();
128 void gpu_context_unlock();
129
130 /* Create GPU resources used by the display driver. */
132
133 /* Destroy all GPU resources which are being used by this object. */
135
136 BL::RenderEngine b_engine_;
138
139 /* Content of the display is to be filled with zeroes. */
140 std::atomic<bool> need_clear_ = true;
141
142 unique_ptr<BlenderDisplayShader> display_shader_;
143
144 /* Opaque storage for an internal state and data for tiles. */
145 struct Tiles;
146 unique_ptr<Tiles> tiles_;
147
150
151 float2 zoom_ = make_float2(1.0f, 1.0f);
152};
153
Read Guarded memory(de)allocation.
struct GPUContext GPUContext
struct GPUShader GPUShader
struct GPUFence GPUFence
virtual half4 * map_texture_buffer() override
virtual void unmap_texture_buffer() override
virtual void clear() override
virtual bool update_begin(const Params &params, int texture_width, int texture_height) override
std::atomic< bool > need_clear_
virtual void graphics_interop_activate() override
virtual GraphicsInterop graphics_interop_get() override
virtual void draw(const Params &params) override
void set_zoom(float zoom_x, float zoom_y)
virtual void flush() override
virtual void update_end() override
unique_ptr< BlenderDisplayShader > display_shader_
virtual void graphics_interop_deactivate() override
virtual void next_tile_begin() override
BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background)
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
virtual GPUShader * bind(int width, int height)=0
static constexpr const char * position_attribute_name
BlenderDisplayShader()=default
virtual void unbind()=0
virtual int get_tex_coord_attrib_location()
virtual ~BlenderDisplayShader()=default
virtual GPUShader * get_shader_program() override
BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene)
virtual GPUShader * bind(int width, int height) override
virtual GPUShader * bind(int width, int height) override
virtual GPUShader * get_shader_program() override
#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:61