mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-31 22:25:21 -04:00
render/gles: Simplify textures a bit
We don't need our own enum for types. Instead we just use
GL_TEXTURE_{2D,EXTERNAL_OES}, which already describes usage.
Also fixes a situation where we were using GL_TEXTURE_2D in a situation
we should not have. wl_drm buffers are always GL_TEXTURE_EXTERNAL_OES,
no matter if they're RGB or any other format.
This commit is contained in:
parent
f2d3b1000f
commit
85a2ee6d30
3 changed files with 38 additions and 60 deletions
|
|
@ -51,7 +51,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
struct wlr_gles2_texture *texture =
|
||||
get_gles2_texture_in_context(wlr_texture);
|
||||
|
||||
if (texture->type != WLR_GLES2_TEXTURE_GLTEX) {
|
||||
if (texture->target != GL_TEXTURE_2D) {
|
||||
wlr_log(WLR_ERROR, "Cannot write pixels to immutable texture");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
// TODO: what if the unpack subimage extension isn't supported?
|
||||
PUSH_GLES2_DEBUG;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->gl_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->tex);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (fmt->bpp / 8));
|
||||
glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, src_x);
|
||||
|
|
@ -85,7 +85,7 @@ static bool gles2_texture_to_dmabuf(struct wlr_texture *wlr_texture,
|
|||
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
||||
|
||||
if (!texture->image) {
|
||||
assert(texture->type == WLR_GLES2_TEXTURE_GLTEX);
|
||||
assert(texture->target == GL_TEXTURE_2D);
|
||||
|
||||
if (!eglCreateImageKHR) {
|
||||
return false;
|
||||
|
|
@ -93,7 +93,7 @@ static bool gles2_texture_to_dmabuf(struct wlr_texture *wlr_texture,
|
|||
|
||||
texture->image = eglCreateImageKHR(texture->egl->display,
|
||||
texture->egl->context, EGL_GL_TEXTURE_2D_KHR,
|
||||
(EGLClientBuffer)(uintptr_t)texture->gl_tex, NULL);
|
||||
(EGLClientBuffer)(uintptr_t)texture->tex, NULL);
|
||||
if (texture->image == EGL_NO_IMAGE_KHR) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -121,15 +121,9 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) {
|
|||
|
||||
PUSH_GLES2_DEBUG;
|
||||
|
||||
if (texture->image_tex) {
|
||||
glDeleteTextures(1, &texture->image_tex);
|
||||
}
|
||||
glDeleteTextures(1, &texture->tex);
|
||||
wlr_egl_destroy_image(texture->egl, texture->image);
|
||||
|
||||
if (texture->type == WLR_GLES2_TEXTURE_GLTEX) {
|
||||
glDeleteTextures(1, &texture->gl_tex);
|
||||
}
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
|
||||
free(texture);
|
||||
|
|
@ -166,14 +160,14 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
|
|||
texture->egl = egl;
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
texture->type = WLR_GLES2_TEXTURE_GLTEX;
|
||||
texture->target = GL_TEXTURE_2D;
|
||||
texture->has_alpha = fmt->has_alpha;
|
||||
texture->wl_format = fmt->wl_format;
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
|
||||
glGenTextures(1, &texture->gl_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->gl_tex);
|
||||
glGenTextures(1, &texture->tex);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->tex);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (fmt->bpp / 8));
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
|
||||
|
|
@ -202,7 +196,6 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
|||
}
|
||||
wlr_texture_init(&texture->wlr_texture, &texture_impl);
|
||||
texture->egl = egl;
|
||||
texture->wl_drm = data;
|
||||
|
||||
EGLint fmt;
|
||||
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
|
||||
|
|
@ -213,17 +206,12 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
GLenum target;
|
||||
switch (fmt) {
|
||||
case EGL_TEXTURE_RGB:
|
||||
case EGL_TEXTURE_RGBA:
|
||||
target = GL_TEXTURE_2D;
|
||||
texture->type = WLR_GLES2_TEXTURE_WL_DRM_GL;
|
||||
texture->has_alpha = fmt == EGL_TEXTURE_RGBA;
|
||||
texture->has_alpha = false;
|
||||
break;
|
||||
case EGL_TEXTURE_RGBA:
|
||||
case EGL_TEXTURE_EXTERNAL_WL:
|
||||
target = GL_TEXTURE_EXTERNAL_OES;
|
||||
texture->type = WLR_GLES2_TEXTURE_WL_DRM_EXT;
|
||||
texture->has_alpha = true;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -232,11 +220,13 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
texture->target = GL_TEXTURE_EXTERNAL_OES;
|
||||
|
||||
PUSH_GLES2_DEBUG;
|
||||
|
||||
glGenTextures(1, &texture->image_tex);
|
||||
glBindTexture(target, texture->image_tex);
|
||||
glEGLImageTargetTexture2DOES(target, texture->image);
|
||||
glGenTextures(1, &texture->tex);
|
||||
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->tex);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, texture->image);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
return &texture->wlr_texture;
|
||||
|
|
@ -280,7 +270,7 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
|||
texture->egl = egl;
|
||||
texture->width = attribs->width;
|
||||
texture->height = attribs->height;
|
||||
texture->type = WLR_GLES2_TEXTURE_DMABUF;
|
||||
texture->target = GL_TEXTURE_EXTERNAL_OES;
|
||||
texture->has_alpha = true;
|
||||
texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways
|
||||
texture->inverted_y =
|
||||
|
|
@ -294,8 +284,8 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
|
|||
|
||||
PUSH_GLES2_DEBUG;
|
||||
|
||||
glGenTextures(1, &texture->image_tex);
|
||||
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->image_tex);
|
||||
glGenTextures(1, &texture->tex);
|
||||
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->tex);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, texture->image);
|
||||
|
||||
POP_GLES2_DEBUG;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue