Commit Graph

58 Commits

Author SHA1 Message Date
Benjamin Otte
141769fb46 gl: Turn has_foo flags into GdkGLFeatures
The goal is to have it mirror GdkVulkanFeatures, and in particular
having an environment variable to turn individual flags off.
2024-03-16 13:44:02 +01:00
Benjamin Otte
4e2c7d5eb0 gl: Require GL/GLES flag when looking up memory formats
This code just adds the argument to the function and fixes all callers.

It's separate because it's just a bunch of boilerplate.
2024-01-16 20:35:20 +01:00
Matthias Clasen
59578c6d18 Fix typos throughout
These were pointed out by codespell.
2024-01-07 20:44:05 -05:00
Benjamin Otte
4dfc07ef57 memoryformat: Fix variable types
Use the same types that GL uses.
2023-12-12 01:49:41 +01:00
Benjamin Otte
0889037959 gltexture: Use the right format to download
When the format is set correctly, which it should be, we should just use
it.

So do that.
2023-12-12 01:49:40 +01:00
Benjamin Otte
3a1349e8ef gl: Make gdk_memory_format_gl_format() no longer check support
Now that we have gdk_gl_context_get_memory_flags() and code can use that
function, make the code do that.

Remove support checks from gdk_memory_format_gl_format().

This is an initial naive port that doesn't try to make use of the finer-grained
flags yet.
2023-12-11 07:33:26 +01:00
Matthias Clasen
b95d8ebdd3 memoryformat: Change some private API
Make gdk_memory_format_gl_format take the GdkGLContext,
instead of just a gles boolean. This will let us
check for extensions that may be needed for certain
formats.

Update all callers.
2023-10-19 16:44:18 -04:00
Benjamin Otte
8aaecc3416 gltexture: Restore previous GL context
Texture downloads can be initiated due to the weirdest reasons - and if
they cause a GL context to be changed, it'd be basically unpredictable
when the GL context changes.

An example is the Cairo renderer - if it needs to draw a GL texture, it
will download it.

Now that no longer changes the GL context.
2023-08-24 05:00:29 +02:00
Benjamin Otte
dd4b8a4c89 gl: Pass swizzle array directly
There's no need to pass pointers to arrays, as arrays are already
pointers.
2023-08-12 23:13:23 +02:00
Matthias Clasen
f29c7e76f5 gltexture: Use proper alignment for downloads 2023-05-30 22:35:45 -04:00
Matthias Clasen
1c72f46eed gltexture: Rewrite downloading code
For non-gles, make it handle unpremultiplied formats,
and everything else, by downloading the texture in its
preferred format and, in most cases, doing a
gdk_memory_convert afterwards.

For gles, keep using glReadPixels, but handle cases
where the gl read format doesn't match the texture
format by doing the necessary swizzling before calling
gdk_memory_convert.
2023-05-30 15:57:18 -04:00
Matthias Clasen
0f61c52593 gdk: Simplify gdk_memory_format_gl_format
Make the callers of this function check for
straight alpha themselves, and only do the
version compatibility check here. This makes
the function usable in contexts where straight
alpha is acceptable.
2023-05-30 14:49:45 -04:00
Sophie Herold
ef8c835762 gsk: Support swizzle for gray and alpha formats
Swizzling is needed to display one channel memory formats
as gray etc.
2023-05-30 14:41:01 -04:00
Benjamin Otte
6506a3bc9c texturebuilder: Add ::udpate-region and ::update-texture 2023-05-02 00:30:58 +02:00
Matthias Clasen
6efaa79e3c gltexture: Synchronize when downloading
If the GL texture has a sync object, wait
on it before downloading the data.
2023-04-27 06:57:02 +02:00
Matthias Clasen
92eb845482 gltexture: Optionally take a sync object
Add a new function to TextureBuilder that takes a GLsync that
requires internal code to wait on before using the texture.

Somewhat sneakily, we don't take the sync if syncs are not supported by
the current GL context.
As public API has no code to query the sync for the destroy notify, this
is fine and it means we don't have to do the check every time we want to
call gdk_texture_get_sync() internally.
2023-04-27 06:55:37 +02:00
Benjamin Otte
18a4b2475e gltexture: Deprecate gdk_gl_texture_new()
Use GdkGLTextureBuilder instead.
2023-04-27 06:40:47 +02:00
Benjamin Otte
e37fbaf13a texturebuilder: Add ::format and ::has-mipmap
We were trying to deduce that previously. Now we have explicit API
2023-04-27 06:40:47 +02:00
Benjamin Otte
3aefed39b1 glcontext: Use GdkGLVersion elsewhere
... and add a convenience API to generate GL versions from strings to
make the gdk_gl_context_check() API nicer.
2023-04-27 02:13:32 +02:00
Benjamin Otte
8965d6c7f8 gl: Only allow RGB(A)8 on GLES2
GLES2 has no idea what 16bit textures even are, let alone floating point.
2023-04-17 05:57:44 +02:00
Matthias Clasen
5c558c0091 Fix up criticals from GdkGLTexture
I broke this in 4291f27b56.
I overlooked that there may not be a current context.
2023-03-24 11:29:38 -04:00
Matthias Clasen
7cb7e0ab35 gl: Add a private way to query mipmap status
Make GdkGLTexture determine if the texture has
a mipmap, and provide private API to query this
information.

This check is done in gdkgltexture.c instead of
gskgldriver.c, since we're already binding the
texture here for other reasons, so it is easy
to query a few more things.
2023-03-23 23:16:54 -04:00
Matthias Clasen
4291f27b56 gltexture: Try harder to determine the format
We can query these things as long as the texture ID
is valid in the current context.
2023-03-23 22:56:06 -04:00
Bilal Elmoussaoui
23408f6dbf GLTexture: Add GL_RGB format support 2023-03-13 13:59:17 +00:00
Benjamin Otte
c9f54ca371 texture: Export gdk_texture_get_format()
The API docs outline why quite well.

This should make it possible to do saving of textures to image files
without any private API with the same featureset that GTK uses.

Also remove the gsktextureprivate.h include where
gdk_texture_get_format() was the only reason for it.
2023-02-15 00:39:18 +01:00
Matthias Clasen
12057c8a30 gltexture: Small refactoring
We do this in two places, so factor out
the dropping of GL resources into a helper.
2023-02-02 10:01:36 +01:00
Matthias Clasen
6655177a0b Cosmetics 2023-02-01 18:38:22 +01:00
Matthias Clasen
1cb621633c gltexture: Use the right context
When checking characteristics of the context
for downloading, we were using self->context,
even though we are using a possibly different
context for downloading.

Pass the right context along and use it.
2023-02-01 11:32:07 +01:00
Christian Hergert
e706e14fd9 gdk/gl: handle GL_RGBA/GL_UNSIGNED_NORMALIZED
WebKit's GTK 4 port can give us textures with an internal format of
GL_RGBA with GL_UNSIGNED_NORMALIZED and a bit-depth of 8. This fixes
warnings for every GdkGLTexture created/delivered to the GskGLRenderer.

The format is essentially the same as GL_RGBA8 since it is normalized
between 0.0..1.0 for 8-bit components.

Fixes #4783
2022-03-24 18:05:11 -07:00
Benjamin Otte
2c71825324 gltexture: Only use glGetFramebufferParameter() when available
Fixes #4678
2022-02-08 01:34:19 +01:00
Maximiliano Sandoval R
ef9dbf73cc
gir: Add type annotations for {GL,Memory}Texture 2022-01-06 19:30:29 +01:00
Benjamin Otte
5803dd765d gles: glGetTexLevelParameter() isn't supported 2021-12-25 15:07:44 +01:00
Benjamin Otte
c7e36bcf22 gltexture: Fix conditions for glGetTexImage() call
The conditions were inverted, plus we failed to limit this call to
non-GLES.
2021-10-17 22:28:44 +02:00
Benjamin Otte
52e88ed4c8 gltexture: Determine format in current thread
Close widget-factory and observe:

Thread 1:
 * acquire main loop
 * handle close button
 * close window
 * dispose video and media stream
 * stop GstPlayer
WAIT on pipeline stopping

Thread 2:
 * prepare next image in pipeline
 * hand image to GtkGstSink
 * create GdkTexture from image
 * gdk_gl_texture_new() determines format
WAIT on acquiring main loop

Sounds like a deadlock?

Indeed, so don't do that.
2021-10-13 14:33:44 +02:00
Benjamin Otte
31e9072906 gl: Fix downloading textures *again*
It turns out glReadPixels() cannot convert pixels and you are only
allowed to pass a single value into the function arguments. You need to
know which ones or things will explode.

GL is great.
2021-10-13 14:33:44 +02:00
Benjamin Otte
b65b64628d texture: Refactor downloading
Pass a format do GdkTextureClass::download(). That way we can download
data in any format.

Also replace gdk_texture_download_texture() with
gdk_memory_texture_from_texture() which again takes a format.

The old functionality is still there for code that wants it: Just pass
gdk_texture_get_format (texture) as the format argument.
2021-10-12 02:06:43 +02:00
Benjamin Otte
8950c0dc96 texture: Make format a property of GdkTexture
For MemoryTexture, this is a simple change.

For GLTexture, we need to query the format at texture creation. This
sounds like a bad idea and extra work until one realizes that we'd
need to do that anyway when using the texure the first time - either
when downloading, or when trying to use it in a rendernode, where we
will soon need that information to determine if the texture prefers high
depth.
2021-10-07 02:41:30 +02:00
Benjamin Otte
48781cf7f7 memorytexture: Split out GdkMemoryFormat handling
Also, now make gdk_memory_convert() the only conversion functions
and allow conversions between any 2 formats by going via a float[4].

This could be optimized via fast-paths, but so far it isn't.
2021-10-06 22:50:07 +02:00
Benjamin Otte
551f76ea69 gltexture: Fallback in download_float()
GLES only allows downloading float if the texture matches specific
criteria and I'm too lazy to determine them, so always fall back.

And the custom stride fallback code isn't necessary, because falling
back does exactly that step already.
2021-09-16 23:59:37 +02:00
Benjamin Otte
a4f3fbbda1 gltexture: Fix download() for GLES
GLES can't do glGetTexImage(), so implement a version that does
glReadPixels() on GLES.
2021-09-16 23:59:37 +02:00
Benjamin Otte
6785461c26 gltexture: Make sure downloading textures works in a different thread
This happens in the real world when using the inspector to look at a
node recording of a GStreamer video while the video is still playing.

GStreamer will use the GL context in a different thread while we are
busy trying to download it.

A test is included.
2021-09-13 01:40:03 +02:00
Benjamin Otte
719eafa60c gl: Implement uploading and downloading HDR formats
Also refactor the GL uploading so it does the fallback in a
GLES-compatible way, which means we only need one fallback.
2021-09-12 05:54:37 +02:00
Benjamin Otte
53275481a5 texture: Add gdk_texture_download_float() 2021-09-12 05:54:37 +02:00
Benjamin Otte
c349ed9562 gltexture: Implement download() via glGetTexImage()
1. The download via gdk_cairo_draw_from_gl() was broken sometimes

2. We get easy conversion on fallback by chaining up and using
   download_texture().

3. One more place where Cairo is no longer necessary.
2021-09-12 05:22:21 +02:00
Benjamin Otte
74ce69a8a1 gltexture: Make release() use download_texture()
1. It avoids Cairo, and in particular conversion to Cairo.

2. Keeping a texture allows easy chaining in the vfuncs.

3. Using a texture means releasing will work for HDR formats
   too, once we add them.
2021-09-12 05:22:21 +02:00
Benjamin Otte
4f17f3ac24 texture: Add gdk_texture_download_texture()
A private vfunc that downloads a texture as a GdkMemoryTexture in
whatever format the texture deems best.

There are multiple reasons for this:

 * GLES cannot download the Cairo format. But it can download some
   format and then just delegate to the GdkMemoryTexture implementation.

 * All the other download vfuncs (including the ones still coming) can
   be implemented via download_texture() and delegation, making the
   interface easier.

 * We want to implement image loading and saving support. By using
   download_texture(), we can save in the actual format of the texture.

 * A potential GdkCompressedTexture could be implemented by just
   providing this one vfunc as a compress() step.
2021-09-12 05:22:21 +02:00
Benjamin Otte
51d0d13a9e gltexture: release() to a texture, not a cairo_surface
This makes forwarding vfuncs a lot easier, because we can just call them
on the texture.
2021-09-12 05:22:21 +02:00
Benjamin Otte
0ee3b1c861 texture: Remove unused argument from vfunc 2021-09-12 05:22:21 +02:00
Matthias Clasen
9132f1831c docs: Rework the gdk docs
Convert links, make things more concise.
2021-03-11 16:37:31 +00:00
Matthias Clasen
2de7f760e5 gl texture: fix a typo 2019-01-23 22:33:44 -05:00