11 #if defined(WITH_GL_EGL)
13 # if defined(WITH_GHOST_X11)
16 # if defined(WITH_GHOST_WAYLAND)
19 #elif defined(WITH_GHOST_X11)
33 const std::vector<int64_t> &gpu_binding_formats,
const std::vector<int64_t> &runtime_formats)
35 if (gpu_binding_formats.empty()) {
39 auto res = std::find_first_of(gpu_binding_formats.begin(),
40 gpu_binding_formats.end(),
41 runtime_formats.begin(),
42 runtime_formats.end());
43 if (res == gpu_binding_formats.end()) {
55 glDeleteFramebuffers(1, &m_fbo);
62 std::string *r_requirement_info)
const override
64 #if defined(WITH_GL_EGL)
66 #elif defined(WITH_GHOST_X11)
71 static PFN_xrGetOpenGLGraphicsRequirementsKHR s_xrGetOpenGLGraphicsRequirementsKHR_fn =
74 XrGraphicsRequirementsOpenGLKHR gpu_requirements = {XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR};
75 const XrVersion gl_version = XR_MAKE_VERSION(
76 ctx_gl.m_contextMajorVersion, ctx_gl.m_contextMinorVersion, 0);
84 s_xrGetOpenGLGraphicsRequirementsKHR_fn =
nullptr;
86 if (!s_xrGetOpenGLGraphicsRequirementsKHR_fn &&
87 XR_FAILED(xrGetInstanceProcAddr(
89 "xrGetOpenGLGraphicsRequirementsKHR",
90 (PFN_xrVoidFunction *)&s_xrGetOpenGLGraphicsRequirementsKHR_fn))) {
91 s_xrGetOpenGLGraphicsRequirementsKHR_fn =
nullptr;
95 s_xrGetOpenGLGraphicsRequirementsKHR_fn(
instance, system_id, &gpu_requirements);
97 if (r_requirement_info) {
98 std::ostringstream strstream;
99 strstream <<
"Min OpenGL version "
100 << XR_VERSION_MAJOR(gpu_requirements.minApiVersionSupported) <<
"."
101 << XR_VERSION_MINOR(gpu_requirements.minApiVersionSupported) << std::endl;
102 strstream <<
"Max OpenGL version "
103 << XR_VERSION_MAJOR(gpu_requirements.maxApiVersionSupported) <<
"."
104 << XR_VERSION_MINOR(gpu_requirements.maxApiVersionSupported) << std::endl;
106 *r_requirement_info = strstream.str();
109 return (gl_version >= gpu_requirements.minApiVersionSupported) &&
110 (gl_version <= gpu_requirements.maxApiVersionSupported);
115 #if defined(WITH_GHOST_X11)
116 # if defined(WITH_GL_EGL)
120 oxr_binding.egl.type = XR_TYPE_GRAPHICS_BINDING_EGL_MNDX;
121 oxr_binding.egl.getProcAddress = eglGetProcAddress;
128 XVisualInfo *visual_info = glXGetVisualFromFBConfig(ctx_glx.m_display, ctx_glx.m_fbconfig);
130 oxr_binding.glx.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
142 oxr_binding.wgl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
147 #if defined(WITH_GHOST_WAYLAND)
150 oxr_binding.wl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR;
151 oxr_binding.wl.display = (
struct wl_display *)ctx_wl_egl.m_nativeDisplay;
156 glGenFramebuffers(1, &m_fbo);
160 GHOST_TXrSwapchainFormat &r_format,
161 bool &r_is_srgb_format)
const override
163 std::vector<int64_t> gpu_binding_formats = {
183 r_format = GHOST_kXrSwapchainFormatRGB10_A2;
186 r_format = GHOST_kXrSwapchainFormatRGBA16;
189 r_format = GHOST_kXrSwapchainFormatRGBA16F;
192 case GL_SRGB8_ALPHA8:
193 r_format = GHOST_kXrSwapchainFormatRGBA8;
196 r_is_srgb_format = (*
result == GL_SRGB8_ALPHA8);
199 r_format = GHOST_kXrSwapchainFormatRGBA8;
200 r_is_srgb_format =
false;
208 std::vector<XrSwapchainImageOpenGLKHR> ogl_images(image_count);
209 std::vector<XrSwapchainImageBaseHeader *> base_images;
213 for (XrSwapchainImageOpenGLKHR &
image : ogl_images) {
214 image.type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR;
215 base_images.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader *
>(&
image));
219 m_image_cache.push_back(std::move(ogl_images));
225 const GHOST_XrDrawViewInfo &draw_info)
override
227 XrSwapchainImageOpenGLKHR &ogl_swapchain_image =
reinterpret_cast<XrSwapchainImageOpenGLKHR &
>(
230 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
232 glFramebufferTexture2D(
233 GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ogl_swapchain_image.image, 0);
235 glBlitFramebuffer(draw_info.ofsx,
237 draw_info.ofsx + draw_info.width,
238 draw_info.ofsy + draw_info.height,
241 draw_info.ofsx + draw_info.width,
242 draw_info.ofsy + draw_info.height,
246 glBindFramebuffer(GL_FRAMEBUFFER, 0);
255 std::list<std::vector<XrSwapchainImageOpenGLKHR>> m_image_cache;
260 static void ghost_format_to_dx_format(GHOST_TXrSwapchainFormat ghost_format,
261 bool expects_srgb_buffer,
266 switch (ghost_format) {
267 case GHOST_kXrSwapchainFormatRGBA8:
271 case GHOST_kXrSwapchainFormatRGBA16:
274 case GHOST_kXrSwapchainFormatRGBA16F:
277 case GHOST_kXrSwapchainFormatRGB10_A2:
294 ~GHOST_XrGraphicsBindingD3D()
296 if (m_shared_resource) {
297 m_ghost_d3d_ctx->disposeSharedOpenGLResource(m_shared_resource);
299 if (m_ghost_d3d_ctx) {
307 XrSystemId system_id,
308 std::string *r_requirement_info)
const override
310 static PFN_xrGetD3D11GraphicsRequirementsKHR s_xrGetD3D11GraphicsRequirementsKHR_fn =
nullptr;
312 XrGraphicsRequirementsD3D11KHR gpu_requirements = {XR_TYPE_GRAPHICS_REQUIREMENTS_D3D11_KHR};
320 s_xrGetD3D11GraphicsRequirementsKHR_fn =
nullptr;
322 if (!s_xrGetD3D11GraphicsRequirementsKHR_fn &&
323 XR_FAILED(xrGetInstanceProcAddr(
325 "xrGetD3D11GraphicsRequirementsKHR",
326 (PFN_xrVoidFunction *)&s_xrGetD3D11GraphicsRequirementsKHR_fn))) {
327 s_xrGetD3D11GraphicsRequirementsKHR_fn =
nullptr;
331 s_xrGetD3D11GraphicsRequirementsKHR_fn(
instance, system_id, &gpu_requirements);
333 if (r_requirement_info) {
334 std::ostringstream strstream;
335 strstream <<
"Minimum DirectX 11 Feature Level " << gpu_requirements.minFeatureLevel
338 *r_requirement_info = std::move(strstream.str());
341 return m_ghost_d3d_ctx->m_device->GetFeatureLevel() >= gpu_requirements.minFeatureLevel;
348 oxr_binding.d3d11.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
349 oxr_binding.d3d11.device = m_ghost_d3d_ctx->m_device;
353 GHOST_TXrSwapchainFormat &r_format,
354 bool &r_is_srgb_format)
const override
356 std::vector<int64_t> gpu_binding_formats = {
376 r_format = GHOST_kXrSwapchainFormatRGB10_A2;
379 r_format = GHOST_kXrSwapchainFormatRGBA16;
382 r_format = GHOST_kXrSwapchainFormatRGBA16F;
386 r_format = GHOST_kXrSwapchainFormatRGBA8;
392 r_format = GHOST_kXrSwapchainFormatRGBA8;
393 r_is_srgb_format =
false;
401 std::vector<XrSwapchainImageD3D11KHR> d3d_images(image_count);
402 std::vector<XrSwapchainImageBaseHeader *> base_images;
406 for (XrSwapchainImageD3D11KHR &
image : d3d_images) {
407 image.type = XR_TYPE_SWAPCHAIN_IMAGE_D3D11_KHR;
408 base_images.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader *
>(&
image));
412 m_image_cache.push_back(std::move(d3d_images));
418 const GHOST_XrDrawViewInfo &draw_info)
override
420 XrSwapchainImageD3D11KHR &d3d_swapchain_image =
reinterpret_cast<XrSwapchainImageD3D11KHR &
>(
430 ID3D11RenderTargetView *rtv;
431 CD3D11_RENDER_TARGET_VIEW_DESC rtv_desc(D3D11_RTV_DIMENSION_TEXTURE2D,
434 m_ghost_ctx->m_device->CreateRenderTargetView(d3d_swapchain_image.texture, &rtv_desc, &rtv);
435 if (!m_shared_resource) {
437 ghost_format_to_dx_format(draw_info.swapchain_format, draw_info.expects_srgb_buffer,
format);
438 m_shared_resource = m_ghost_ctx->createSharedOpenGLResource(
439 draw_info.width, draw_info.height,
format, rtv);
441 m_ghost_ctx->blitFromOpenGLContext(m_shared_resource, draw_info.width, draw_info.height);
443 if (!m_shared_resource) {
445 ghost_format_to_dx_format(draw_info.swapchain_format, draw_info.expects_srgb_buffer,
format);
446 m_shared_resource = m_ghost_d3d_ctx->createSharedOpenGLResource(
447 draw_info.width, draw_info.height,
format);
449 m_ghost_d3d_ctx->blitFromOpenGLContext(m_shared_resource, draw_info.width, draw_info.height);
451 m_ghost_d3d_ctx->m_device_ctx->OMSetRenderTargets(0,
nullptr,
nullptr);
452 m_ghost_d3d_ctx->m_device_ctx->CopyResource(
453 d3d_swapchain_image.texture, m_ghost_d3d_ctx->getSharedTexture2D(m_shared_resource));
459 return m_ghost_d3d_ctx->isUpsideDown();
470 std::list<std::vector<XrSwapchainImageD3D11KHR>> m_image_cache;
478 case GHOST_kXrGraphicsOpenGL:
479 return std::make_unique<GHOST_XrGraphicsBindingOpenGL>();
481 case GHOST_kXrGraphicsD3D11:
482 return std::make_unique<GHOST_XrGraphicsBindingD3D>(
context);
@ DXGI_FORMAT_R16G16B16A16_UNORM
@ DXGI_FORMAT_R10G10B10A2_UNORM
@ DXGI_FORMAT_R16G16B16A16_FLOAT
@ DXGI_FORMAT_R8G8B8A8_UNORM
@ DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
GHOST C-API function and type declarations.
std::unique_ptr< GHOST_IXrGraphicsBinding > GHOST_XrGraphicsBindingCreateFromType(GHOST_TXrGraphicsBinding type, GHOST_Context &context)
static std::optional< int64_t > choose_swapchain_format_from_candidates(const std::vector< int64_t > &gpu_binding_formats, const std::vector< int64_t > &runtime_formats)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object instance
EGLConfig getConfig() const
EGLDisplay getDisplay() const
EGLContext getContext() const
virtual bool isUpsideDown() const
virtual bool needsUpsideDownDrawing(GHOST_Context &ghost_ctx) const =0
virtual bool checkVersionRequirements(class GHOST_Context &ghost_ctx, XrInstance instance, XrSystemId system_id, std::string *r_requirement_info) const =0
virtual std::optional< int64_t > chooseSwapchainFormat(const std::vector< int64_t > &runtime_formats, GHOST_TXrSwapchainFormat &r_format, bool &r_is_rgb_format) const =0
virtual void initFromGhostContext(class GHOST_Context &ghost_ctx)=0
union GHOST_IXrGraphicsBinding::@1290 oxr_binding
virtual std::vector< XrSwapchainImageBaseHeader * > createSwapchainImages(uint32_t image_count)=0
virtual void submitToSwapchainImage(XrSwapchainImageBaseHeader &swapchain_image, const GHOST_XrDrawViewInfo &draw_info)=0
static GHOST_ContextD3D * createOffscreenContextD3D()
static GHOST_TSuccess disposeContextD3D(GHOST_ContextD3D *context)
~GHOST_XrGraphicsBindingOpenGL()
std::optional< int64_t > chooseSwapchainFormat(const std::vector< int64_t > &runtime_formats, GHOST_TXrSwapchainFormat &r_format, bool &r_is_srgb_format) const override
bool needsUpsideDownDrawing(GHOST_Context &ghost_ctx) const override
std::vector< XrSwapchainImageBaseHeader * > createSwapchainImages(uint32_t image_count) override
void initFromGhostContext(GHOST_Context &ghost_ctx) override
bool checkVersionRequirements(GHOST_Context &ghost_ctx, XrInstance instance, XrSystemId system_id, std::string *r_requirement_info) const override
void submitToSwapchainImage(XrSwapchainImageBaseHeader &swapchain_image, const GHOST_XrDrawViewInfo &draw_info) override
SyclQueue void void size_t num_bytes void
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3