2020-05-30 15:56:33 +00:00
|
|
|
// Copyright 2019-2020, Collabora, Ltd.
|
2019-03-18 05:52:32 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief OpenGL client side glue to compositor implementation.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup comp_client
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2019-10-30 11:02:37 +00:00
|
|
|
#include <assert.h>
|
2019-03-18 05:52:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-03-21 20:19:52 +00:00
|
|
|
#include "util/u_misc.h"
|
|
|
|
|
2020-07-17 22:44:52 +00:00
|
|
|
#include <xrt/xrt_config_have.h>
|
|
|
|
#if defined(XRT_HAVE_EGL)
|
|
|
|
#include "ogl/egl_api.h"
|
|
|
|
#endif
|
|
|
|
#if defined(XRT_HAVE_OPENGL) || defined(XRT_HAVE_OPENGLES)
|
2019-10-09 15:39:38 +00:00
|
|
|
#include "ogl/ogl_api.h"
|
2020-07-16 22:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#include "client/comp_gl_client.h"
|
|
|
|
|
2020-04-29 22:47:32 +00:00
|
|
|
#include <inttypes.h>
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-03 21:26:34 +00:00
|
|
|
/*!
|
|
|
|
* Down-cast helper.
|
|
|
|
* @private @memberof client_gl_swapchain
|
|
|
|
*/
|
|
|
|
static inline struct client_gl_swapchain *
|
|
|
|
client_gl_swapchain(struct xrt_swapchain *xsc)
|
|
|
|
{
|
|
|
|
return (struct client_gl_swapchain *)xsc;
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Swapchain functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_gl_swapchain_destroy(struct xrt_swapchain *xsc)
|
|
|
|
{
|
|
|
|
struct client_gl_swapchain *sc = client_gl_swapchain(xsc);
|
|
|
|
|
|
|
|
uint32_t num_images = sc->base.base.num_images;
|
|
|
|
if (num_images > 0) {
|
|
|
|
glDeleteTextures(num_images, &sc->base.images[0]);
|
2019-06-18 19:04:19 +00:00
|
|
|
U_ZERO_ARRAY(sc->base.images);
|
2020-07-10 09:23:38 +00:00
|
|
|
glDeleteMemoryObjectsEXT(num_images, &sc->memory[0]);
|
2019-06-18 19:04:19 +00:00
|
|
|
U_ZERO_ARRAY(sc->base.images);
|
2019-03-18 05:52:32 +00:00
|
|
|
sc->base.base.num_images = 0;
|
|
|
|
}
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Destroy the native swapchain as well.
|
|
|
|
xrt_swapchain_destroy((struct xrt_swapchain **)&sc->xscn);
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
free(sc);
|
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2020-06-09 20:56:26 +00:00
|
|
|
client_gl_swapchain_acquire_image(struct xrt_swapchain *xsc,
|
|
|
|
uint32_t *out_index)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct client_gl_swapchain *sc = client_gl_swapchain(xsc);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native swapchain.
|
|
|
|
return xrt_swapchain_acquire_image(&sc->xscn->base, out_index);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2019-03-18 05:52:32 +00:00
|
|
|
client_gl_swapchain_wait_image(struct xrt_swapchain *xsc,
|
|
|
|
uint64_t timeout,
|
|
|
|
uint32_t index)
|
|
|
|
{
|
|
|
|
struct client_gl_swapchain *sc = client_gl_swapchain(xsc);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native swapchain.
|
|
|
|
return xrt_swapchain_wait_image(&sc->xscn->base, timeout, index);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2019-03-18 05:52:32 +00:00
|
|
|
client_gl_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index)
|
|
|
|
{
|
|
|
|
struct client_gl_swapchain *sc = client_gl_swapchain(xsc);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native swapchain.
|
|
|
|
return xrt_swapchain_release_image(&sc->xscn->base, index);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Compositor functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-06-17 06:36:38 +00:00
|
|
|
static xrt_result_t
|
|
|
|
client_gl_compositor_prepare_session(struct xrt_compositor *xc,
|
|
|
|
struct xrt_session_prepare_info *xspi)
|
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native compositor.
|
|
|
|
return xrt_comp_prepare_session(&c->xcn->base, xspi);
|
2020-06-17 06:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2019-03-18 05:52:32 +00:00
|
|
|
client_gl_compositor_begin_session(struct xrt_compositor *xc,
|
|
|
|
enum xrt_view_type type)
|
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
2020-06-25 11:58:01 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native compositor.
|
|
|
|
return xrt_comp_begin_session(&c->xcn->base, type);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2019-03-18 05:52:32 +00:00
|
|
|
client_gl_compositor_end_session(struct xrt_compositor *xc)
|
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
2020-06-25 11:58:01 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native compositor.
|
|
|
|
return xrt_comp_end_session(&c->xcn->base);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2019-03-18 05:52:32 +00:00
|
|
|
client_gl_compositor_wait_frame(struct xrt_compositor *xc,
|
2020-06-23 16:11:39 +00:00
|
|
|
int64_t *out_frame_id,
|
2020-03-02 19:34:43 +00:00
|
|
|
uint64_t *predicted_display_time,
|
|
|
|
uint64_t *predicted_display_period)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
2020-06-25 11:58:01 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native compositor.
|
|
|
|
return xrt_comp_wait_frame(&c->xcn->base, out_frame_id,
|
2020-06-23 16:11:39 +00:00
|
|
|
predicted_display_time,
|
2020-06-04 12:31:01 +00:00
|
|
|
predicted_display_period);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2020-06-23 16:11:39 +00:00
|
|
|
client_gl_compositor_begin_frame(struct xrt_compositor *xc, int64_t frame_id)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
2020-06-25 11:58:01 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native compositor.
|
|
|
|
return xrt_comp_begin_frame(&c->xcn->base, frame_id);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2020-06-23 16:11:39 +00:00
|
|
|
client_gl_compositor_discard_frame(struct xrt_compositor *xc, int64_t frame_id)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
2020-06-25 11:58:01 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native compositor.
|
|
|
|
return xrt_comp_discard_frame(&c->xcn->base, frame_id);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2020-04-22 12:59:40 +00:00
|
|
|
client_gl_compositor_layer_begin(struct xrt_compositor *xc,
|
2020-06-23 16:11:39 +00:00
|
|
|
int64_t frame_id,
|
2020-04-22 12:59:40 +00:00
|
|
|
enum xrt_blend_mode env_blend_mode)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
return xrt_comp_layer_begin(&c->xcn->base, frame_id, env_blend_mode);
|
2020-04-22 12:59:40 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2020-06-09 18:02:04 +00:00
|
|
|
client_gl_compositor_layer_stereo_projection(struct xrt_compositor *xc,
|
|
|
|
struct xrt_device *xdev,
|
2020-06-09 20:29:46 +00:00
|
|
|
struct xrt_swapchain *l_xsc,
|
|
|
|
struct xrt_swapchain *r_xsc,
|
2020-06-09 18:02:04 +00:00
|
|
|
struct xrt_layer_data *data)
|
2020-04-22 12:59:40 +00:00
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
2020-07-14 22:13:07 +00:00
|
|
|
struct xrt_swapchain *l_xscn, *r_xscn;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-09 18:02:04 +00:00
|
|
|
assert(data->type == XRT_LAYER_STEREO_PROJECTION);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
l_xscn = &client_gl_swapchain(l_xsc)->xscn->base;
|
|
|
|
r_xscn = &client_gl_swapchain(r_xsc)->xscn->base;
|
2020-06-09 18:02:04 +00:00
|
|
|
data->flip_y = true;
|
2020-04-22 12:59:40 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
return xrt_comp_layer_stereo_projection(&c->xcn->base, xdev, l_xscn,
|
|
|
|
r_xscn, data);
|
2020-04-22 12:59:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2020-04-22 12:59:40 +00:00
|
|
|
client_gl_compositor_layer_quad(struct xrt_compositor *xc,
|
|
|
|
struct xrt_device *xdev,
|
2020-06-09 20:29:46 +00:00
|
|
|
struct xrt_swapchain *xsc,
|
2020-06-09 18:02:04 +00:00
|
|
|
struct xrt_layer_data *data)
|
2020-04-22 12:59:40 +00:00
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
|
|
|
struct xrt_swapchain *xscfb;
|
|
|
|
|
2020-06-09 18:02:04 +00:00
|
|
|
assert(data->type == XRT_LAYER_QUAD);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
xscfb = &client_gl_swapchain(xsc)->xscn->base;
|
2020-06-09 18:02:04 +00:00
|
|
|
data->flip_y = true;
|
2020-04-22 12:59:40 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
return xrt_comp_layer_quad(&c->xcn->base, xdev, xscfb, data);
|
2020-04-22 12:59:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 12:31:01 +00:00
|
|
|
static xrt_result_t
|
2020-06-23 16:11:39 +00:00
|
|
|
client_gl_compositor_layer_commit(struct xrt_compositor *xc, int64_t frame_id)
|
2020-04-22 12:59:40 +00:00
|
|
|
{
|
2020-07-17 15:11:35 +00:00
|
|
|
//! @hack: The swapchain images should have been externally synchronized
|
|
|
|
glFlush();
|
|
|
|
|
2020-04-22 12:59:40 +00:00
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
return xrt_comp_layer_commit(&c->xcn->base, frame_id);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t
|
|
|
|
gl_format_to_vk(int64_t format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case GL_RGBA8: return 37 /*VK_FORMAT_R8G8B8A8_UNORM*/;
|
2019-05-04 20:25:24 +00:00
|
|
|
case GL_SRGB8_ALPHA8: return 43 /*VK_FORMAT_R8G8B8A8_SRGB*/;
|
2020-06-25 16:47:34 +00:00
|
|
|
case GL_RGB10_A2: return 64 /*VK_FORMAT_A2B10G10R10_UNORM_PACK32*/;
|
|
|
|
case GL_RGBA16F: return 97 /*VK_FORMAT_R16G16B16A16_SFLOAT*/;
|
2019-03-18 05:52:32 +00:00
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 10:21:35 +00:00
|
|
|
static int64_t
|
|
|
|
vk_format_to_gl(int64_t format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case 37 /*VK_FORMAT_R8G8B8A8_UNORM*/: return GL_RGBA8;
|
|
|
|
case 43 /*VK_FORMAT_R8G8B8A8_SRGB*/: return GL_SRGB8_ALPHA8;
|
|
|
|
case 44 /*VK_FORMAT_B8G8R8A8_UNORM*/: return 0;
|
|
|
|
case 50 /*VK_FORMAT_B8G8R8A8_SRGB*/: return 0;
|
2020-06-25 16:47:34 +00:00
|
|
|
case 64 /*VK_FORMAT_A2B10G10R10_UNORM_PACK32*/: return GL_RGB10_A2;
|
|
|
|
case 97 /*VK_FORMAT_R16G16B16A16_SFLOAT*/: return GL_RGBA16F;
|
2020-04-17 10:21:35 +00:00
|
|
|
default:
|
2020-04-29 22:47:32 +00:00
|
|
|
printf("Cannot convert VK format 0x%016" PRIx64
|
|
|
|
" to GL format!\n",
|
|
|
|
format);
|
2020-04-17 10:21:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 14:01:06 +00:00
|
|
|
static xrt_result_t
|
2019-03-18 05:52:32 +00:00
|
|
|
client_gl_swapchain_create(struct xrt_compositor *xc,
|
2020-07-16 14:01:06 +00:00
|
|
|
struct xrt_swapchain_create_info *info,
|
|
|
|
struct xrt_swapchain **out_xsc)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
2020-07-16 14:01:06 +00:00
|
|
|
xrt_result_t xret = XRT_SUCCESS;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-07-02 20:25:56 +00:00
|
|
|
if (info->array_size > 1) {
|
2019-11-15 16:30:57 +00:00
|
|
|
const char *version_str = (const char *)glGetString(GL_VERSION);
|
|
|
|
if (strstr(version_str, "OpenGL ES 2.") == version_str) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s - only one array layer is supported with "
|
|
|
|
"OpenGL ES 2\n",
|
|
|
|
__func__);
|
2020-07-16 14:01:06 +00:00
|
|
|
return XRT_ERROR_OPENGL;
|
2019-11-15 16:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 20:25:56 +00:00
|
|
|
int64_t vk_format = gl_format_to_vk(info->format);
|
2019-03-18 05:52:32 +00:00
|
|
|
if (vk_format == 0) {
|
|
|
|
fprintf(stderr, "%s - Invalid format!\n", __func__);
|
2020-07-16 14:01:06 +00:00
|
|
|
return XRT_ERROR_VULKAN;
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 14:01:06 +00:00
|
|
|
struct xrt_swapchain_create_info xinfo = *info;
|
|
|
|
xinfo.format = vk_format;
|
|
|
|
struct xrt_swapchain_native *xscn = NULL;
|
|
|
|
xret = xrt_comp_native_create_swapchain(c->xcn, &xinfo, &xscn);
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-03 17:04:06 +00:00
|
|
|
|
2020-07-16 14:01:06 +00:00
|
|
|
if (xret != XRT_SUCCESS) {
|
|
|
|
return xret;
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
2020-07-16 14:01:06 +00:00
|
|
|
assert(xscn != NULL);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
struct xrt_swapchain *xsc = &xscn->base;
|
2020-04-08 14:13:28 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
struct client_gl_swapchain *sc =
|
2019-03-21 20:19:52 +00:00
|
|
|
U_TYPED_CALLOC(struct client_gl_swapchain);
|
2019-03-18 05:52:32 +00:00
|
|
|
sc->base.base.destroy = client_gl_swapchain_destroy;
|
|
|
|
sc->base.base.acquire_image = client_gl_swapchain_acquire_image;
|
|
|
|
sc->base.base.wait_image = client_gl_swapchain_wait_image;
|
|
|
|
sc->base.base.release_image = client_gl_swapchain_release_image;
|
2020-07-14 22:13:07 +00:00
|
|
|
// Fetch the number of images from the native swapchain.
|
2020-04-08 14:13:28 +00:00
|
|
|
sc->base.base.num_images = xsc->num_images;
|
2020-07-14 22:13:07 +00:00
|
|
|
sc->xscn = xscn;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-10-30 14:30:50 +00:00
|
|
|
GLuint prev_texture = 0;
|
2020-07-02 20:25:56 +00:00
|
|
|
glGetIntegerv(info->array_size == 1 ? GL_TEXTURE_BINDING_2D
|
|
|
|
: GL_TEXTURE_BINDING_2D_ARRAY,
|
2019-10-30 14:30:50 +00:00
|
|
|
(GLint *)&prev_texture);
|
|
|
|
|
2020-04-08 14:13:28 +00:00
|
|
|
glGenTextures(xsc->num_images, sc->base.images);
|
|
|
|
for (uint32_t i = 0; i < xsc->num_images; i++) {
|
2020-07-02 20:25:56 +00:00
|
|
|
glBindTexture(info->array_size == 1 ? GL_TEXTURE_2D
|
|
|
|
: GL_TEXTURE_2D_ARRAY,
|
2019-10-30 14:30:50 +00:00
|
|
|
sc->base.images[i]);
|
|
|
|
}
|
2020-07-10 09:23:38 +00:00
|
|
|
glCreateMemoryObjectsEXT(xsc->num_images, &sc->memory[0]);
|
2020-04-08 14:13:28 +00:00
|
|
|
for (uint32_t i = 0; i < xsc->num_images; i++) {
|
2019-03-18 05:52:32 +00:00
|
|
|
GLint dedicated = GL_TRUE;
|
2020-07-10 09:23:38 +00:00
|
|
|
glMemoryObjectParameterivEXT(
|
|
|
|
sc->memory[i], GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
|
|
|
|
glImportMemoryFdEXT(sc->memory[i], xscn->images[i].size,
|
2020-06-03 17:04:06 +00:00
|
|
|
GL_HANDLE_TYPE_OPAQUE_FD_EXT,
|
2020-07-14 22:13:07 +00:00
|
|
|
xscn->images[i].fd);
|
2020-05-30 15:56:33 +00:00
|
|
|
|
|
|
|
// We have consumed this fd now, make sure it's not freed again.
|
2020-07-14 22:13:07 +00:00
|
|
|
xscn->images[i].fd = -1;
|
2020-05-30 15:56:33 +00:00
|
|
|
|
2020-07-02 20:25:56 +00:00
|
|
|
if (info->array_size == 1) {
|
|
|
|
glTextureStorageMem2DEXT(
|
|
|
|
sc->base.images[i], info->mip_count,
|
|
|
|
(GLuint)info->format, info->width, info->height,
|
2020-07-10 09:23:38 +00:00
|
|
|
sc->memory[i], 0);
|
2019-04-30 15:22:19 +00:00
|
|
|
} else {
|
|
|
|
glTextureStorageMem3DEXT(
|
2020-07-02 20:25:56 +00:00
|
|
|
sc->base.images[i], info->mip_count,
|
|
|
|
(GLuint)info->format, info->width, info->height,
|
2020-07-10 09:23:38 +00:00
|
|
|
info->array_size, sc->memory[i], 0);
|
2019-04-30 15:22:19 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-02 20:25:56 +00:00
|
|
|
glBindTexture(info->array_size == 1 ? GL_TEXTURE_2D
|
|
|
|
: GL_TEXTURE_2D_ARRAY,
|
2019-10-30 14:30:50 +00:00
|
|
|
prev_texture);
|
|
|
|
|
2020-07-16 14:01:06 +00:00
|
|
|
*out_xsc = &sc->base.base;
|
|
|
|
return XRT_SUCCESS;
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 06:36:38 +00:00
|
|
|
static xrt_result_t
|
|
|
|
client_gl_compositor_poll_events(struct xrt_compositor *xc,
|
|
|
|
union xrt_compositor_event *out_xce)
|
|
|
|
{
|
|
|
|
struct client_gl_compositor *c = client_gl_compositor(xc);
|
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Pipe down call into native compositor.
|
|
|
|
return xrt_comp_poll_events(&c->xcn->base, out_xce);
|
2020-06-17 06:36:38 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 11:02:37 +00:00
|
|
|
static void
|
|
|
|
client_gl_compositor_destroy(struct xrt_compositor *xc)
|
|
|
|
{
|
|
|
|
assert(!"Destroy should be implemented by the winsys code that uses the GL code.");
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
bool
|
|
|
|
client_gl_compositor_init(struct client_gl_compositor *c,
|
2020-07-14 22:13:07 +00:00
|
|
|
struct xrt_compositor_native *xcn,
|
2019-03-18 05:52:32 +00:00
|
|
|
client_gl_get_procaddr get_gl_procaddr)
|
|
|
|
{
|
|
|
|
c->base.base.create_swapchain = client_gl_swapchain_create;
|
2020-06-17 06:36:38 +00:00
|
|
|
c->base.base.prepare_session = client_gl_compositor_prepare_session;
|
2019-03-18 05:52:32 +00:00
|
|
|
c->base.base.begin_session = client_gl_compositor_begin_session;
|
|
|
|
c->base.base.end_session = client_gl_compositor_end_session;
|
|
|
|
c->base.base.wait_frame = client_gl_compositor_wait_frame;
|
|
|
|
c->base.base.begin_frame = client_gl_compositor_begin_frame;
|
|
|
|
c->base.base.discard_frame = client_gl_compositor_discard_frame;
|
2020-04-22 12:59:40 +00:00
|
|
|
c->base.base.layer_begin = client_gl_compositor_layer_begin;
|
|
|
|
c->base.base.layer_stereo_projection =
|
|
|
|
client_gl_compositor_layer_stereo_projection;
|
|
|
|
c->base.base.layer_quad = client_gl_compositor_layer_quad;
|
|
|
|
c->base.base.layer_commit = client_gl_compositor_layer_commit;
|
2019-10-30 11:02:37 +00:00
|
|
|
c->base.base.destroy = client_gl_compositor_destroy;
|
2020-06-17 06:36:38 +00:00
|
|
|
c->base.base.poll_events = client_gl_compositor_poll_events;
|
2020-07-14 22:13:07 +00:00
|
|
|
c->xcn = xcn;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-07-14 22:13:07 +00:00
|
|
|
// Passthrough our formats from the native compositor to the client.
|
2020-04-17 10:21:35 +00:00
|
|
|
size_t count = 0;
|
2020-07-14 22:13:07 +00:00
|
|
|
for (uint32_t i = 0; i < xcn->base.num_formats; i++) {
|
|
|
|
int64_t f = vk_format_to_gl(xcn->base.formats[i]);
|
2020-04-17 10:21:35 +00:00
|
|
|
if (f == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->base.base.formats[count++] = f;
|
|
|
|
}
|
|
|
|
c->base.base.num_formats = count;
|
|
|
|
|
2020-07-16 22:22:59 +00:00
|
|
|
#if defined(XRT_HAVE_OPENGL)
|
2019-03-18 05:52:32 +00:00
|
|
|
gladLoadGL(get_gl_procaddr);
|
2020-07-16 22:22:59 +00:00
|
|
|
#elif defined(XRT_HAVE_OPENGLES)
|
|
|
|
gladLoadGLES2(get_gl_procaddr);
|
|
|
|
#endif
|
2020-07-15 17:34:32 +00:00
|
|
|
// @todo log this to a proper logger.
|
|
|
|
#define CHECK_REQUIRED_EXTENSION(EXT) \
|
|
|
|
do { \
|
|
|
|
if (!GLAD_##EXT) { \
|
|
|
|
fprintf(stderr, \
|
|
|
|
"%s - Needed extension " #EXT \
|
|
|
|
" not supported\n", \
|
|
|
|
__func__); \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
CHECK_REQUIRED_EXTENSION(GL_EXT_memory_object);
|
|
|
|
#ifdef XRT_OS_LINUX
|
|
|
|
CHECK_REQUIRED_EXTENSION(GL_EXT_memory_object_fd);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef CHECK_REQUIRED_EXTENSION
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|