2019-03-18 05:52:32 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Holds OpenGL swapchain related functions.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup oxr_main
|
|
|
|
* @ingroup comp_client
|
|
|
|
*/
|
|
|
|
|
2019-10-30 14:31:54 +00:00
|
|
|
#include <assert.h>
|
2019-03-18 05:52:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "xrt/xrt_gfx_xlib.h"
|
|
|
|
#include "util/u_debug.h"
|
|
|
|
|
|
|
|
#include "oxr_objects.h"
|
|
|
|
#include "oxr_logger.h"
|
|
|
|
|
|
|
|
|
2019-12-03 19:08:10 +00:00
|
|
|
#ifdef XR_USE_GRAPHICS_API_OPENGL
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
static XrResult
|
|
|
|
oxr_swapchain_gl_destroy(struct oxr_logger *log, struct oxr_swapchain *sc)
|
|
|
|
{
|
2020-05-30 16:01:00 +00:00
|
|
|
// Release any waited image.
|
|
|
|
if (sc->waited.yes) {
|
|
|
|
sc->release_image(log, sc, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release any acquired images.
|
|
|
|
XrSwapchainImageWaitInfo waitInfo = {0};
|
|
|
|
while (!u_index_fifo_is_empty(&sc->acquired.fifo)) {
|
|
|
|
sc->wait_image(log, sc, &waitInfo);
|
2019-03-18 05:52:32 +00:00
|
|
|
sc->release_image(log, sc, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->swapchain != NULL) {
|
|
|
|
sc->swapchain->destroy(sc->swapchain);
|
|
|
|
sc->swapchain = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static XrResult
|
|
|
|
oxr_swapchain_gl_enumerate_images(struct oxr_logger *log,
|
|
|
|
struct oxr_swapchain *sc,
|
|
|
|
uint32_t count,
|
|
|
|
XrSwapchainImageBaseHeader *images)
|
|
|
|
{
|
|
|
|
struct xrt_swapchain_gl *xsc = (struct xrt_swapchain_gl *)sc->swapchain;
|
2019-10-30 14:31:54 +00:00
|
|
|
|
2019-10-30 14:43:01 +00:00
|
|
|
XrSwapchainImageOpenGLKHR *gl_imgs = NULL;
|
|
|
|
XrSwapchainImageOpenGLESKHR *gles_imgs = NULL;
|
2019-10-30 14:31:54 +00:00
|
|
|
assert(count > 0);
|
2019-10-30 14:43:01 +00:00
|
|
|
switch (images[0].type) {
|
|
|
|
case XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR:
|
|
|
|
gl_imgs = (XrSwapchainImageOpenGLKHR *)images;
|
|
|
|
break;
|
|
|
|
case XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR:
|
|
|
|
gles_imgs = (XrSwapchainImageOpenGLESKHR *)images;
|
|
|
|
break;
|
|
|
|
default:
|
2019-10-30 14:31:54 +00:00
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"unsupported XrSwapchainImageBaseHeader type");
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2019-10-30 14:43:01 +00:00
|
|
|
if ((gl_imgs != NULL && gl_imgs[i].type != images[0].type) ||
|
|
|
|
(gles_imgs != NULL &&
|
|
|
|
gles_imgs[i].type != images[0].type)) {
|
2019-10-30 14:31:54 +00:00
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"images array contains mixed types");
|
|
|
|
}
|
2019-10-30 14:43:01 +00:00
|
|
|
if (gl_imgs != NULL) {
|
|
|
|
gl_imgs[i].image = xsc->images[i];
|
|
|
|
}
|
|
|
|
if (gles_imgs != NULL) {
|
|
|
|
gles_imgs[i].image = xsc->images[i];
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sc->sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XrResult
|
|
|
|
oxr_swapchain_gl_create(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
const XrSwapchainCreateInfo *createInfo,
|
|
|
|
struct oxr_swapchain **out_swapchain)
|
|
|
|
{
|
|
|
|
struct oxr_swapchain *sc;
|
|
|
|
XrResult ret;
|
|
|
|
|
|
|
|
ret = oxr_create_swapchain(log, sess, createInfo, &sc);
|
|
|
|
if (ret != XR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->destroy = oxr_swapchain_gl_destroy;
|
|
|
|
sc->enumerate_images = oxr_swapchain_gl_enumerate_images;
|
|
|
|
|
|
|
|
*out_swapchain = sc;
|
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
2019-12-03 19:08:10 +00:00
|
|
|
|
|
|
|
#endif // XR_USE_GRAPHICS_API_OPENGL
|