Blender V5.0
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(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
42 {
43 return active_context_;
44 }
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*/)
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 {
123 return context_params_.is_stereo_visual;
124 }
125
128 {
129 return context_params_.vsync;
130 }
131
135 virtual bool isUpsideDown() const
136 {
137 return false;
138 }
139
141 unsigned int getDefaultFramebuffer() override
142 {
143 return 0;
144 }
145
146#ifdef WITH_VULKAN_BACKEND
148 virtual GHOST_TSuccess getVulkanHandles(GHOST_VulkanHandles & /* r_handles */) override
149 {
150 return GHOST_kFailure;
151 };
153 virtual GHOST_TSuccess getVulkanSwapChainFormat(
154 GHOST_VulkanSwapChainData * /*r_swap_chain_data*/) override
155 {
156 return GHOST_kFailure;
157 }
158
160 virtual GHOST_TSuccess setVulkanSwapBuffersCallbacks(
161 std::function<void(const GHOST_VulkanSwapChainData *)> /*swap_buffer_draw_callback*/,
162 std::function<void(void)> /*swap_buffer_acquired_callback*/,
163 std::function<void(GHOST_VulkanOpenXRData *)> /*openxr_acquire_framebuffer_image_callback*/,
164 std::function<void(GHOST_VulkanOpenXRData *)> /*openxr_release_framebuffer_image_callback*/)
165 override
166 {
167 return GHOST_kFailure;
168 }
169#endif
170
171 protected:
173
175 void *user_data_ = nullptr;
176
177#ifdef WITH_OPENGL_BACKEND
178 static void initClearGL();
179#endif
180
181 MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_Context")
182};
183
184#ifdef _WIN32
185bool win32_chk(bool result, const char *file = nullptr, int line = 0, const char *text = nullptr);
186bool win32_silent_chk(bool result);
187
188# ifndef NDEBUG
189# define WIN32_CHK(x) win32_chk((x), __FILE__, __LINE__, #x)
190# else
191# define WIN32_CHK(x) win32_chk(x)
192# endif
193
194# define WIN32_CHK_SILENT(x, silent) ((silent) ? win32_silent_chk(x) : WIN32_CHK(x))
195#endif /* _WIN32 */
GHOST_TSuccess
Definition GHOST_Types.h:57
@ GHOST_kFailure
Definition GHOST_Types.h:57
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()
GHOST_TSuccess swapBufferAcquire() override=0
GHOST_TSuccess activateDrawingContext() override=0
void setUserData(void *user_data)
virtual GHOST_TSuccess getSwapInterval(int &)
bool isStereoVisual() const