Blender V5.3
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.hh"
14
15#include <cstdlib> /* For `nullptr`. */
16
18 protected:
19 static thread_local inline GHOST_Context *active_context_;
20
21 public:
26 GHOST_Context(const GHOST_ContextParams &context_params) : context_params_(context_params) {}
27
31 ~GHOST_Context() override
32 {
33 if (active_context_ == this) {
34 active_context_ = nullptr;
35 }
36 };
37
45
48
51
54
57
63
70 {
71 return GHOST_kFailure;
72 }
73
79
85 virtual GHOST_TSuccess setSwapInterval(int /*interval*/)
86 {
87 return GHOST_kFailure;
88 }
89
95 virtual GHOST_TSuccess getSwapInterval(int & /*interval_out*/)
96 {
97 return GHOST_kFailure;
98 }
99
104 {
105 return user_data_;
106 }
107
111 void setUserData(void *user_data)
112 {
113 user_data_ = user_data;
114 }
115
121 bool isStereoVisual() const
122 {
124 }
125
132 bool hasAlpha() const
133 {
135 }
136
139 {
140 return context_params_.vsync;
141 }
142
146 virtual bool isUpsideDown() const
147 {
148 return false;
149 }
150
152 unsigned int getDefaultFramebuffer() override
153 {
154 return 0;
155 }
156
157#ifdef WITH_VULKAN_BACKEND
159 GHOST_TSuccess getVulkanHandles(GHOST_VulkanHandles & /* r_handles */) override
160 {
161 return GHOST_kFailure;
162 };
164 GHOST_TSuccess getVulkanSwapChainFormat(
165 GHOST_VulkanSwapChainData * /*r_swap_chain_data*/) override
166 {
167 return GHOST_kFailure;
168 }
169
171 GHOST_TSuccess setVulkanSwapBuffersCallbacks(
172 std::function<void(const GHOST_VulkanSwapChainData *, bool)> /*swap_buffer_draw_callback*/,
173 std::function<void(void)> /*swap_buffer_acquired_callback*/,
174 std::function<void(GHOST_VulkanOpenXRData *)> /*openxr_acquire_framebuffer_image_callback*/,
175 std::function<void(GHOST_VulkanOpenXRData *)> /*openxr_release_framebuffer_image_callback*/)
176 override
177 {
178 return GHOST_kFailure;
179 }
180#endif
181
182 protected:
184
186 void *user_data_ = nullptr;
187
188#ifdef WITH_OPENGL_BACKEND
189 static void initClearGL();
190#endif
191
192 MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_Context")
193};
194
195#ifdef _WIN32
196bool win32_chk(bool result, const char *file = nullptr, int line = 0, const char *text = nullptr);
197bool win32_silent_chk(bool result);
198
199# ifndef NDEBUG
200# define WIN32_CHK(x) win32_chk((x), __FILE__, __LINE__, #x)
201# else
202# define WIN32_CHK(x) win32_chk(x)
203# endif
204
205# define WIN32_CHK_SILENT(x, silent) ((silent) ? win32_silent_chk(x) : WIN32_CHK(x))
206#endif /* _WIN32 */
GHOST_TSuccess
@ GHOST_kFailure
GHOST_TVSyncModes
GHOST_TSuccess releaseDrawingContext() override=0
unsigned int getDefaultFramebuffer() override
virtual GHOST_TSuccess releaseNativeHandles()=0
GHOST_TSuccess swapBufferRelease() override=0
virtual GHOST_TSuccess setSwapInterval(int)
GHOST_Context(const GHOST_ContextParams &context_params)
static GHOST_Context * active_context_
~GHOST_Context() override
virtual GHOST_TSuccess updateDrawingContext()
virtual bool isUpsideDown() const
static GHOST_Context * getActiveDrawingContext()
virtual GHOST_TVSyncModes getVSync()
GHOST_ContextParams context_params_
virtual GHOST_TSuccess initializeDrawingContext()=0
void * getUserData()
bool hasAlpha() const
GHOST_TSuccess swapBufferAcquire() override=0
GHOST_TSuccess activateDrawingContext() override=0
void setUserData(void *user_data)
virtual GHOST_TSuccess getSwapInterval(int &)
bool isStereoVisual() const
GHOST_TVSyncModes vsync