2023-06-14 17:39:46 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2018-02-26 19:10:15 +01:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup GHOST
|
2018-02-26 19:10:15 +01:00
|
|
|
* Declaration of GHOST_IContext interface class.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "GHOST_Types.h"
|
|
|
|
|
|
2025-01-26 20:08:09 +01:00
|
|
|
#ifdef WITH_VULKAN_BACKEND
|
|
|
|
|
# include <functional>
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-02-26 19:10:15 +01:00
|
|
|
/**
|
|
|
|
|
* Interface for GHOST context.
|
|
|
|
|
*
|
2021-07-26 12:32:42 +10:00
|
|
|
* You can create a off-screen context (windowless) with the system's
|
|
|
|
|
* #GHOST_ISystem::createOffscreenContext method.
|
2018-02-26 19:10:15 +01:00
|
|
|
* \see GHOST_ISystem#createOffscreenContext
|
|
|
|
|
*/
|
|
|
|
|
class GHOST_IContext {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Destructor.
|
|
|
|
|
*/
|
2025-01-26 20:08:09 +01:00
|
|
|
virtual ~GHOST_IContext() = default;
|
2018-02-26 19:10:15 +01:00
|
|
|
|
2025-04-04 18:14:13 +02:00
|
|
|
/**
|
|
|
|
|
* Returns the thread's currently active drawing context.
|
|
|
|
|
*/
|
|
|
|
|
static GHOST_IContext *getActiveDrawingContext();
|
|
|
|
|
|
2018-02-26 19:10:15 +01:00
|
|
|
/**
|
|
|
|
|
* Activates the drawing context.
|
2020-11-06 14:18:55 +11:00
|
|
|
* \return A boolean success indicator.
|
2018-02-26 19:10:15 +01:00
|
|
|
*/
|
|
|
|
|
virtual GHOST_TSuccess activateDrawingContext() = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Release the drawing context of the calling thread.
|
2020-11-06 14:18:55 +11:00
|
|
|
* \return A boolean success indicator.
|
2018-02-26 19:10:15 +01:00
|
|
|
*/
|
|
|
|
|
virtual GHOST_TSuccess releaseDrawingContext() = 0;
|
|
|
|
|
|
2025-07-01 13:33:54 +10:00
|
|
|
/**
|
|
|
|
|
* Gets the OpenGL frame-buffer associated with the OpenGL context
|
|
|
|
|
* \return The ID of an OpenGL frame-buffer object.
|
|
|
|
|
*/
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
virtual unsigned int getDefaultFramebuffer() = 0;
|
2025-09-11 07:51:30 +02:00
|
|
|
/**
|
|
|
|
|
* Acquire next buffer for drawing.
|
|
|
|
|
* \return A boolean success indicator.
|
|
|
|
|
*/
|
|
|
|
|
virtual GHOST_TSuccess swapBufferAcquire() = 0;
|
|
|
|
|
|
2025-07-01 13:33:54 +10:00
|
|
|
/**
|
|
|
|
|
* Swaps front and back buffers of a window.
|
|
|
|
|
* \return A boolean success indicator.
|
|
|
|
|
*/
|
2025-09-11 07:51:30 +02:00
|
|
|
virtual GHOST_TSuccess swapBufferRelease() = 0;
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
|
2023-08-29 15:05:08 +02:00
|
|
|
#ifdef WITH_VULKAN_BACKEND
|
2023-02-21 15:03:12 +01:00
|
|
|
/**
|
|
|
|
|
* Get Vulkan handles for the given context.
|
|
|
|
|
*
|
|
|
|
|
* These handles are the same for a given context.
|
2023-03-29 14:16:26 +11:00
|
|
|
* Should only be called when using a Vulkan context.
|
2023-02-21 15:03:12 +01:00
|
|
|
* Other contexts will not return any handles and leave the
|
|
|
|
|
* handles where the parameters are referring to unmodified.
|
|
|
|
|
*
|
2025-03-13 11:06:20 +01:00
|
|
|
* \param r_handles: After calling this structure is filled with
|
|
|
|
|
* the vulkan handles of the context.
|
2023-02-21 15:03:12 +01:00
|
|
|
*/
|
2025-03-13 11:06:20 +01:00
|
|
|
virtual GHOST_TSuccess getVulkanHandles(GHOST_VulkanHandles &r_handles) = 0;
|
2023-02-21 15:03:12 +01:00
|
|
|
|
|
|
|
|
/**
|
2025-08-12 10:12:19 +10:00
|
|
|
* Acquire the current swap-chain format.
|
2023-02-21 15:03:12 +01:00
|
|
|
*
|
2023-08-29 15:05:08 +02:00
|
|
|
* \param windowhandle: GHOST window handle to a window to get the resource from.
|
|
|
|
|
* \param r_surface_format: After calling this function the VkSurfaceFormatKHR
|
|
|
|
|
* referenced by this parameter will contain the surface format of the
|
|
|
|
|
* surface. The format is the same as the image returned in the r_image
|
|
|
|
|
* parameter.
|
2023-02-21 15:03:12 +01:00
|
|
|
* \param r_extent: After calling this function the VkExtent2D
|
|
|
|
|
* referenced by this parameter will contain the size of the
|
|
|
|
|
* frame buffer and image in pixels.
|
2022-11-22 11:28:37 +01:00
|
|
|
*/
|
2023-08-29 15:05:08 +02:00
|
|
|
virtual GHOST_TSuccess getVulkanSwapChainFormat(
|
|
|
|
|
GHOST_VulkanSwapChainData *r_swap_chain_data) = 0;
|
2022-11-22 11:28:37 +01:00
|
|
|
|
2023-08-29 15:05:08 +02:00
|
|
|
/**
|
2025-08-12 10:12:19 +10:00
|
|
|
* Set the pre and post callbacks for vulkan swap-chain in the given context.
|
2023-08-29 15:05:08 +02:00
|
|
|
*
|
|
|
|
|
* \param context: GHOST context handle of a vulkan context to
|
|
|
|
|
* get the Vulkan handles from.
|
2025-09-11 07:51:30 +02:00
|
|
|
* \param swap_buffer_draw_callback: Function pointer to be called when acquired swap buffer is
|
|
|
|
|
* released, allowing Vulkan backend to update the swap chain.
|
|
|
|
|
* \param swap_buffer_acquired_callback: Function to be called at when swap buffer is acquired.
|
|
|
|
|
* Allowing Vulkan backend to update the framebuffer. It is also called when no swap chain
|
|
|
|
|
* exists indicating that the window was minimuzed.
|
|
|
|
|
* \param openxr_acquire_image_callback: Function to be called when an image needs to be acquired
|
|
|
|
|
* to be drawn to an OpenXR swap-chain.
|
2025-03-27 16:57:51 +01:00
|
|
|
* \param openxr_release_image_callback: Function to be called after an image has been drawn to
|
2025-08-12 10:12:19 +10:00
|
|
|
* the OpenXR swap-chain.
|
2023-08-29 15:05:08 +02:00
|
|
|
*/
|
|
|
|
|
virtual GHOST_TSuccess setVulkanSwapBuffersCallbacks(
|
2025-09-11 07:51:30 +02:00
|
|
|
std::function<void(const GHOST_VulkanSwapChainData *)> swap_buffer_draw_callback,
|
|
|
|
|
std::function<void(void)> swap_buffer_acquired_callback,
|
2025-03-27 16:57:51 +01:00
|
|
|
std::function<void(GHOST_VulkanOpenXRData *)> openxr_acquire_framebuffer_image_callback,
|
|
|
|
|
std::function<void(GHOST_VulkanOpenXRData *)> openxr_release_framebuffer_image_callback) = 0;
|
2023-08-29 15:05:08 +02:00
|
|
|
#endif
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
|
2018-02-26 19:10:15 +01:00
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IContext")
|
|
|
|
|
};
|