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