comp/client: Use new texture target utility for OpenGL

This commit is contained in:
Ryan Pavlik 2020-08-18 15:32:33 -05:00
parent e48f68deb6
commit 3250617dcb
4 changed files with 47 additions and 39 deletions

View file

@ -22,6 +22,8 @@
#include "ogl/ogl_api.h" #include "ogl/ogl_api.h"
#endif #endif
#include "ogl/ogl_helpers.h"
#include "client/comp_gl_client.h" #include "client/comp_gl_client.h"
#include <inttypes.h> #include <inttypes.h>
@ -317,16 +319,13 @@ client_gl_swapchain_create(struct xrt_compositor *xc,
assert(xscn != NULL); assert(xscn != NULL);
// Save texture binding // Save texture binding
GLuint prev_texture = 0; GLint prev_texture = 0;
#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER) GLuint binding_enum = 0;
const GLuint binding_enum = GL_TEXTURE_BINDING_EXTERNAL_OES; GLuint tex_target = 0;
#else ogl_texture_target_for_swapchain_info(&xinfo, &tex_target,
const GLuint binding_enum = info->array_size == 1 &binding_enum);
? GL_TEXTURE_BINDING_2D
: GL_TEXTURE_BINDING_2D_ARRAY;
#endif
glGetIntegerv(binding_enum, (GLint *)&prev_texture); glGetIntegerv(binding_enum, &prev_texture);
struct xrt_swapchain *xsc = &xscn->base; struct xrt_swapchain *xsc = &xscn->base;
@ -348,13 +347,7 @@ client_gl_swapchain_create(struct xrt_compositor *xc,
sc->base.base.num_images = xsc->num_images; sc->base.base.num_images = xsc->num_images;
sc->xscn = xscn; sc->xscn = xscn;
#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER) glBindTexture(tex_target, prev_texture);
const GLuint binding_target_enum = GL_TEXTURE_EXTERNAL_OES;
#else
const GLuint binding_target_enum =
info->array_size == 1 ? GL_TEXTURE_2D : GL_TEXTURE_2D_ARRAY;
#endif
glBindTexture(binding_target_enum, prev_texture);
*out_xsc = &sc->base.base; *out_xsc = &sc->base.base;
return XRT_SUCCESS; return XRT_SUCCESS;

View file

@ -36,6 +36,9 @@ struct client_gl_swapchain
struct xrt_swapchain_gl base; struct xrt_swapchain_gl base;
struct xrt_swapchain_native *xscn; struct xrt_swapchain_native *xscn;
//! The texture target of images in this swapchain.
uint32_t tex_target;
}; };
/*! /*!

View file

@ -24,6 +24,7 @@
#include "ogl/egl_api.h" #include "ogl/egl_api.h"
#include "ogl/ogl_api.h" #include "ogl/ogl_api.h"
#include "ogl/ogl_helpers.h"
#include "client/comp_gl_client.h" #include "client/comp_gl_client.h"
#include "client/comp_gl_eglimage_swapchain.h" #include "client/comp_gl_eglimage_swapchain.h"
@ -199,15 +200,15 @@ client_gl_eglimage_swapchain_create(
glGenTextures(native_xsc->num_images, xscgl->images); glGenTextures(native_xsc->num_images, xscgl->images);
GLuint binding_enum = 0;
GLuint tex_target = 0;
ogl_texture_target_for_swapchain_info(info, &tex_target, &binding_enum);
sc->base.tex_target = tex_target;
for (uint32_t i = 0; i < native_xsc->num_images; i++) { for (uint32_t i = 0; i < native_xsc->num_images; i++) {
#ifdef XRT_OS_ANDROID
glBindTexture(GL_TEXTURE_EXTERNAL_OES, xscgl->images[i]); // Bind new texture name to the target.
#else glBindTexture(tex_target, xscgl->images[i]);
glBindTexture(info->array_size == 1 ? GL_TEXTURE_2D
: GL_TEXTURE_2D_ARRAY,
xscgl->images[i]);
#endif
EGLClientBuffer native_buffer = NULL; EGLClientBuffer native_buffer = NULL;
@ -224,7 +225,7 @@ client_gl_eglimage_swapchain_create(
return NULL; return NULL;
} }
EGLint attrs[] = {EGL_NONE}; EGLint attrs[] = {EGL_NONE};
EGLenum target = EGL_NATIVE_BUFFER_ANDROID; EGLenum source = EGL_NATIVE_BUFFER_ANDROID;
#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD) #elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
EGLint attrs[] = {EGL_WIDTH, EGLint attrs[] = {EGL_WIDTH,
info->width, info->width,
@ -239,27 +240,34 @@ client_gl_eglimage_swapchain_create(
EGL_DMA_BUF_PLANE0_PITCH_EXT, EGL_DMA_BUF_PLANE0_PITCH_EXT,
row_pitch, row_pitch,
EGL_NONE}; EGL_NONE};
EGLenum target = EGL_LINUX_DMA_BUF_EXT; EGLenum source = EGL_LINUX_DMA_BUF_EXT;
#else #else
#error "need port" #error "need port"
#endif #endif
sc->egl_images[i] = eglCreateImageKHR( sc->egl_images[i] = eglCreateImageKHR(
sc->display, EGL_NO_CONTEXT, target, native_buffer, attrs); sc->display, EGL_NO_CONTEXT, source, native_buffer, attrs);
if (NULL == sc->egl_images[i]) { if (EGL_NO_IMAGE_KHR == sc->egl_images[i]) {
EGL_SC_ERROR("eglCreateImageKHR failed"); EGL_SC_ERROR("eglCreateImageKHR failed");
client_gl_eglimage_swapchain_teardown_storage(sc); client_gl_eglimage_swapchain_teardown_storage(sc);
free(sc); free(sc);
return NULL; return NULL;
} }
#if defined(XRT_OS_ANDROID) /*!
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, * @todo this matches the behavior of the Google test, but is
sc->egl_images[i]); * not itself tested or fully rationalized.
#else *
//! @todo this should be glTexImage2D I think. * Also, glEGLImageTargetTexStorageEXT was added in Android
glEGLImageTargetTexture2DOES( * platform 28, so fairly recently.
info->array_size == 1 ? GL_TEXTURE_2D : GL_TEXTURE_2D_ARRAY, */
sc->egl_images[i]); if (GLAD_GL_EXT_EGL_image_storage &&
#endif glEGLImageTargetTexStorageEXT) {
glEGLImageTargetTexStorageEXT(tex_target,
sc->egl_images[i], NULL);
} else if (GLAD_GL_OES_EGL_image_external ||
GLAD_GL_OES_EGL_image_external_essl3) {
glEGLImageTargetTexture2DOES(tex_target,
sc->egl_images[i]);
}
} }
return &sc->base.base.base; return &sc->base.base.base;

View file

@ -18,6 +18,7 @@
#include "util/u_misc.h" #include "util/u_misc.h"
#include "ogl/ogl_api.h" #include "ogl/ogl_api.h"
#include "ogl/ogl_helpers.h"
#include "client/comp_gl_client.h" #include "client/comp_gl_client.h"
#include "client/comp_gl_memobj_swapchain.h" #include "client/comp_gl_memobj_swapchain.h"
@ -72,6 +73,10 @@ client_gl_memobj_swapchain_create(struct xrt_compositor *xc,
if (xscn == NULL) { if (xscn == NULL) {
return NULL; return NULL;
} }
GLuint binding_enum = 0;
GLuint tex_target = 0;
ogl_texture_target_for_swapchain_info(info, &tex_target, &binding_enum);
struct xrt_swapchain *native_xsc = &xscn->base; struct xrt_swapchain *native_xsc = &xscn->base;
struct client_gl_memobj_swapchain *sc = struct client_gl_memobj_swapchain *sc =
@ -82,12 +87,11 @@ client_gl_memobj_swapchain_create(struct xrt_compositor *xc,
// Fetch the number of images from the native swapchain. // Fetch the number of images from the native swapchain.
client_xsc->num_images = native_xsc->num_images; client_xsc->num_images = native_xsc->num_images;
sc->base.xscn = xscn; sc->base.xscn = xscn;
sc->base.tex_target = tex_target;
glGenTextures(native_xsc->num_images, xscgl->images); glGenTextures(native_xsc->num_images, xscgl->images);
for (uint32_t i = 0; i < native_xsc->num_images; i++) { for (uint32_t i = 0; i < native_xsc->num_images; i++) {
glBindTexture(info->array_size == 1 ? GL_TEXTURE_2D glBindTexture(tex_target, xscgl->images[i]);
: GL_TEXTURE_2D_ARRAY,
xscgl->images[i]);
} }
glCreateMemoryObjectsEXT(native_xsc->num_images, &sc->memory[0]); glCreateMemoryObjectsEXT(native_xsc->num_images, &sc->memory[0]);