Blender V5.0
app/opengl/display_driver.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include <atomic>
8#include <functional>
9
10#include "app/opengl/shader.h"
11
13
15
17 public:
18 /* Callbacks for enabling and disabling the OpenGL context. Must be provided to support enabling
19 * the context on the Cycles render thread independent of the main thread. */
20 OpenGLDisplayDriver(const std::function<bool()> &gl_context_enable,
21 const std::function<void()> &gl_context_disable);
23
24 void graphics_interop_activate() override;
25 void graphics_interop_deactivate() override;
26
27 void clear() override;
28
29 void set_zoom(const float zoom_x, const float zoom_y);
30
31 protected:
32 void next_tile_begin() override;
33
34 bool update_begin(const Params &params,
35 const int texture_width,
36 const int texture_height) override;
37 void update_end() override;
38
39 half4 *map_texture_buffer() override;
40 void unmap_texture_buffer() override;
41
43 void graphics_interop_update_buffer() override;
44
45 void draw(const Params &params) override;
46
47 /* Make sure texture is allocated and its initial configuration is performed. */
49
50 /* Ensure all runtime GPU resources needed for drawing are allocated.
51 * Returns true if all resources needed for drawing are available. */
53
54 /* Destroy all GPU resources which are being used by this object. */
56
57 /* Update GPU texture dimensions and content if needed (new pixel data was provided).
58 *
59 * NOTE: The texture needs to be bound. */
61
62 /* Update vertex buffer with new coordinates of vertex positions and texture coordinates.
63 * This buffer is used to render texture in the viewport.
64 *
65 * NOTE: The buffer needs to be bound. */
67
68 /* Texture which contains pixels of the render result. */
69 struct {
70 /* Indicates whether texture creation was attempted and succeeded.
71 * Used to avoid multiple attempts of texture creation on GPU issues or GPU context
72 * misconfiguration. */
73 bool creation_attempted = false;
74 bool is_created = false;
75
76 /* OpenGL resource IDs of the texture itself and Pixel Buffer Object (PBO) used to write
77 * pixels to it.
78 *
79 * NOTE: Allocated on the engine's context. */
82
83 /* Is true when new data was written to the PBO, meaning, the texture might need to be resized
84 * and new data is to be uploaded to the GPU. */
85 bool need_update = false;
86
87 /* Content of the texture is to be filled with zeroes. */
88 std::atomic<bool> need_zero = true;
89
90 /* Dimensions of the texture in pixels. */
91 int width = 0;
92 int height = 0;
93
94 /* Dimensions of the underlying PBO. */
95 int buffer_width = 0;
98
100
101 /* Special track of whether GPU resources were attempted to be created, to avoid attempts of
102 * their re-creation on failure on every redraw. */
105
106 /* Vertex buffer which hold vertices of a triangle fan which is textures with the texture
107 * holding the render result. */
109
110 void *gl_render_sync_ = nullptr;
111 void *gl_upload_sync_ = nullptr;
112
113 float2 zoom_ = make_float2(1.0f, 1.0f);
114
115 std::function<bool()> gl_context_enable_ = nullptr;
116 std::function<void()> gl_context_disable_ = nullptr;
117};
118
unsigned int uint
DisplayDriver()=default
std::atomic< bool > need_zero
void vertex_buffer_update(const Params &params)
~OpenGLDisplayDriver() override
bool update_begin(const Params &params, const int texture_width, const int texture_height) override
std::function< void()> gl_context_disable_
OpenGLDisplayDriver(const std::function< bool()> &gl_context_enable, const std::function< void()> &gl_context_disable)
void graphics_interop_update_buffer() override
GraphicsInteropDevice graphics_interop_get_device() override
void graphics_interop_deactivate() override
std::function< bool()> gl_context_enable_
struct OpenGLDisplayDriver::@156212331323220374276325202330063261145026220273 texture_
half4 * map_texture_buffer() override
void set_zoom(const float zoom_x, const float zoom_y)
void draw(const Params &params) override
#define CCL_NAMESPACE_END
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define make_float2
Definition half.h:60