Blender V4.3
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
9#include "app/opengl/shader.h"
10
12
13#include "util/function.h"
14#include "util/unique_ptr.h"
15
17
19 public:
20 /* Callbacks for enabling and disabling the OpenGL context. Must be provided to support enabling
21 * the context on the Cycles render thread independent of the main thread. */
22 OpenGLDisplayDriver(const function<bool()> &gl_context_enable,
23 const function<void()> &gl_context_disable);
25
26 virtual void graphics_interop_activate() override;
27 virtual void graphics_interop_deactivate() override;
28
29 virtual void clear() override;
30
31 void set_zoom(float zoom_x, float zoom_y);
32
33 protected:
34 virtual void next_tile_begin() override;
35
36 virtual bool update_begin(const Params &params, int texture_width, int texture_height) override;
37 virtual void update_end() override;
38
39 virtual half4 *map_texture_buffer() override;
40 virtual void unmap_texture_buffer() override;
41
42 virtual GraphicsInterop graphics_interop_get() override;
43
44 virtual void draw(const Params &params) override;
45
46 /* Make sure texture is allocated and its initial configuration is performed. */
48
49 /* Ensure all runtime GPU resources needed for drawing are allocated.
50 * Returns true if all resources needed for drawing are available. */
52
53 /* Destroy all GPU resources which are being used by this object. */
55
56 /* Update GPU texture dimensions and content if needed (new pixel data was provided).
57 *
58 * NOTE: The texture needs to be bound. */
60
61 /* Update vertex buffer with new coordinates of vertex positions and texture coordinates.
62 * This buffer is used to render texture in the viewport.
63 *
64 * NOTE: The buffer needs to be bound. */
66
67 /* Texture which contains pixels of the render result. */
68 struct {
69 /* Indicates whether texture creation was attempted and succeeded.
70 * Used to avoid multiple attempts of texture creation on GPU issues or GPU context
71 * misconfiguration. */
72 bool creation_attempted = false;
73 bool is_created = false;
74
75 /* OpenGL resource IDs of the texture itself and Pixel Buffer Object (PBO) used to write
76 * pixels to it.
77 *
78 * NOTE: Allocated on the engine's context. */
81
82 /* Is true when new data was written to the PBO, meaning, the texture might need to be resized
83 * and new data is to be uploaded to the GPU. */
84 bool need_update = false;
85
86 /* Content of the texture is to be filled with zeroes. */
87 std::atomic<bool> need_clear = true;
88
89 /* Dimensions of the texture in pixels. */
90 int width = 0;
91 int height = 0;
92
93 /* Dimensions of the underlying PBO. */
94 int buffer_width = 0;
97
99
100 /* Special track of whether GPU resources were attempted to be created, to avoid attempts of
101 * their re-creation on failure on every redraw. */
104
105 /* Vertex buffer which hold vertices of a triangle fan which is textures with the texture
106 * holding the render result. */
108
109 void *gl_render_sync_ = nullptr;
110 void *gl_upload_sync_ = nullptr;
111
112 float2 zoom_ = make_float2(1.0f, 1.0f);
113
114 function<bool()> gl_context_enable_ = nullptr;
115 function<void()> gl_context_disable_ = nullptr;
116};
117
unsigned int uint
struct OpenGLDisplayDriver::@1411 texture_
void vertex_buffer_update(const Params &params)
virtual void unmap_texture_buffer() override
virtual void update_end() override
void set_zoom(float zoom_x, float zoom_y)
virtual bool update_begin(const Params &params, int texture_width, int texture_height) override
virtual void graphics_interop_deactivate() override
virtual void graphics_interop_activate() override
function< bool()> gl_context_enable_
virtual half4 * map_texture_buffer() override
function< void()> gl_context_disable_
virtual GraphicsInterop graphics_interop_get() override
virtual void draw(const Params &params) override
std::atomic< bool > need_clear
virtual void clear() override
virtual void next_tile_begin() override
OpenGLDisplayDriver(const function< bool()> &gl_context_enable, const function< void()> &gl_context_disable)
#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