Blender V4.5
GHOST_Context.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#pragma once
11
12#include "GHOST_IContext.hh"
13#include "GHOST_Types.h"
14
15#include <cstdlib> // for nullptr
16
18 protected:
19 static thread_local inline GHOST_Context *active_context_;
20
21 public:
26 GHOST_Context(bool stereoVisual) : m_stereoVisual(stereoVisual) {}
27
31 ~GHOST_Context() override
32 {
33 if (active_context_ == this) {
34 active_context_ = nullptr;
35 }
36 };
37
42 {
43 return active_context_;
44 }
45
51
57
63
69
76 {
77 return GHOST_kFailure;
78 }
79
85
91 virtual GHOST_TSuccess setSwapInterval(int /*interval*/)
92 {
93 return GHOST_kFailure;
94 }
95
101 virtual GHOST_TSuccess getSwapInterval(int & /*interval*/)
102 {
103 return GHOST_kFailure;
104 }
105
110 {
111 return m_user_data;
112 }
113
117 void setUserData(void *user_data)
118 {
119 m_user_data = user_data;
120 }
121
127 bool isStereoVisual() const
128 {
129 return m_stereoVisual;
130 }
131
135 virtual bool isUpsideDown() const
136 {
137 return false;
138 }
139
144 unsigned int getDefaultFramebuffer() override
145 {
146 return 0;
147 }
148
149#ifdef WITH_VULKAN_BACKEND
180 virtual GHOST_TSuccess getVulkanHandles(GHOST_VulkanHandles & /* r_handles */) override
181 {
182 return GHOST_kFailure;
183 };
184
185 virtual GHOST_TSuccess getVulkanSwapChainFormat(
186 GHOST_VulkanSwapChainData * /*r_swap_chain_data*/) override
187 {
188 return GHOST_kFailure;
189 }
190
191 virtual GHOST_TSuccess setVulkanSwapBuffersCallbacks(
192 std::function<void(const GHOST_VulkanSwapChainData *)> /*swap_buffers_pre_callback*/,
193 std::function<void(void)> /*swap_buffers_post_callback*/,
194 std::function<void(GHOST_VulkanOpenXRData *)> /*openxr_acquire_framebuffer_image_callback*/,
195 std::function<void(GHOST_VulkanOpenXRData *)> /*openxr_release_framebuffer_image_callback*/)
196 override
197 {
198 return GHOST_kFailure;
199 }
200#endif
201
202 protected:
204
206 void *m_user_data = nullptr;
207
208#ifdef WITH_OPENGL_BACKEND
209 static void initClearGL();
210#endif
211
212 MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_Context")
213};
214
215#ifdef _WIN32
216bool win32_chk(bool result, const char *file = nullptr, int line = 0, const char *text = nullptr);
217bool win32_silent_chk(bool result);
218
219# ifndef NDEBUG
220# define WIN32_CHK(x) win32_chk((x), __FILE__, __LINE__, #x)
221# else
222# define WIN32_CHK(x) win32_chk(x)
223# endif
224
225# define WIN32_CHK_SILENT(x, silent) ((silent) ? win32_silent_chk(x) : WIN32_CHK(x))
226#endif /* _WIN32 */
GHOST_TSuccess
Definition GHOST_Types.h:80
@ GHOST_kFailure
Definition GHOST_Types.h:80
GHOST_TSuccess releaseDrawingContext() override=0
unsigned int getDefaultFramebuffer() override
virtual GHOST_TSuccess releaseNativeHandles()=0
virtual GHOST_TSuccess setSwapInterval(int)
static GHOST_Context * active_context_
~GHOST_Context() override
virtual GHOST_TSuccess updateDrawingContext()
virtual bool isUpsideDown() const
static GHOST_Context * getActiveDrawingContext()
virtual GHOST_TSuccess initializeDrawingContext()=0
void * getUserData()
GHOST_TSuccess activateDrawingContext() override=0
void setUserData(void *user_data)
virtual GHOST_TSuccess getSwapInterval(int &)
bool isStereoVisual() const
GHOST_Context(bool stereoVisual)
GHOST_TSuccess swapBuffers() override=0