Commit Graph

19 Commits

Author SHA1 Message Date
Emmanuele Bassi
24230ca783 gl: Store the legacy bit in the GL program data
We need to know if we're using a legacy GL context in various places.

https://bugzilla.gnome.org/show_bug.cgi?id=756142
2015-10-07 16:21:57 +01:00
Emmanuele Bassi
2dfca143bb gdk: Allow querying if a GL context is in legacy mode
We want to have the ability to fall back to legacy GL contexts when
creating them. In order to do so, we need to store the legacy bit on the
GdkGLContext, as well as being able to query it.

Setting the legacy bit from outside GDK is not possible; we cannot
create GL contexts in 3.2 core profile *and* compatibility modes at the
same time, and if we allowed users to select the legacy mode themselves,
it would break the creation of the GdkWindow's paint GL context.

What we do allow is falling back to legacy GL context if the platform
does not support 3.2 core profiles — for instance, on older GPUs or
inside virtualized environments.

We are also going to use the legacy bit internally, to choose which GL
API we can use when drawing GL content.

https://bugzilla.gnome.org/show_bug.cgi?id=756142
2015-10-07 16:21:57 +01:00
Emmanuele Bassi
843475bd2e gl: Drop GdkGLContextClass.upload_texture()
It's unnecessary to allow per-backend overrides.
2015-02-09 19:10:31 +00:00
Emmanuele Bassi
6aaa6c337b gl: Move getters for context options to the public API
They can be useful for third party code as well.

https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-02-09 19:10:30 +00:00
Emmanuele Bassi
fa90052299 gl: Add context options
Users of the GdkGLContext API should be allowed to set properties on the
shim GdkGLContext instance prior to realization, so that the
backend-specific implementation can use the value of those properties
when creating the windowing system specific resources.

The main three options are:

 • a major/minor version tuple, to request a specific GL version
 • a debug bit, to request a "debug context", which provides additional
   validation and run time checking
 • a forward compatibility bit, to request a context that does not
   have deprecated functionality

See also:
 - https://www.opengl.org/registry/specs/ARB/glx_create_context.txt

https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-02-09 19:10:05 +00:00
Emmanuele Bassi
22e6f37c9c GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.

We have a couple of requirements in terms of API:

 • avoid, if at all possible, the "C arrays of integers with
   attribute, value pairs", which are hard to write and hard
   to bind in non-C languages.
 • allow failing in a recoverable way.
 • do not make the GL context creation API a mess of arguments.

Looking at prior art, it seems that a common pattern is to split the
construction phase in two:

 • a first phase that creates a GL context wrapper object and
   does preliminary checks on the environment.
 • a second phase that creates the backend-specific GL object.

We adopted a similar pattern:

 • gdk_window_create_gl_context() creates a GdkGLContext
 • gdk_gl_context_realize() creates the underlying resources

Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.

https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-02-09 19:10:04 +00:00
Chun-wei Fan
9fd9f61b00 gdkgl: Use vfunc For Uploading Textures
As the alignments, strides and image formats may be different across
platforms, make the texture upload a vfunc to allow backends to override
the GL commands for uploading textures for the software implementation for
gdk_gl_texture_from_surface(), if necessary.

Suggested by Alex to avoid copying non-trivial portions of code which would
then add maintainenace burden.

https://bugzilla.gnome.org/show_bug.cgi?id=740795
2014-12-17 16:06:25 +08:00
Jasper St. Pierre
6ffba866a6 gdkgl: Use one VBO for both position and uv attributes 2014-11-22 10:17:43 -08:00
Jasper St. Pierre
28846536cb gdkgl: Clean up program-manipulating code
Abstract the program ID and locations into a "program struct" which
we then use.
2014-11-22 09:29:27 -08:00
Alexander Larsson
cf94da2ca1 GdkGLContext: Remove unused update vfunc
The update virtual function for GdkGLContext is unused and is a
leftover from a previous GL approach. Just remove it.

https://bugzilla.gnome.org/show_bug.cgi?id=739750
2014-11-20 12:38:04 +01:00
Alexander Larsson
1f3f933edf GdkX11GLContext: Use bitblit for swap if no buffer age support
If buffer age is undefined and the updated area is not the whole
window then we use bit-blits instead of swap-buffers to end the
frame.

This allows us to not repaint the entire window unnecessarily if
buffer_age is not supported, like e.g. with DRI2.
2014-11-06 12:24:43 +01:00
Alexander Larsson
21189b9f7e Add gdk_gl_context_has_framebuffer_blit()
This checks if the context supports GL_EXT_framebuffer_blit
2014-11-06 12:24:43 +01:00
Alexander Larsson
5f9e6ec2dc GdkGL: Fix up GL_ARB_texture_rectangle support
This broke when gdk_gl_texture_quad moved to shaders. We need
a specialized shader for the rectangle case.
2014-11-06 12:24:43 +01:00
Alexander Larsson
e417b18373 gdk_gl_texture_quad: Use shaders to texture things
This is the modern way OpenGL works, and using it will let us
switch to a core context for the paint context, and work on
OpenGL ES 2.0.
2014-11-06 12:24:43 +01:00
Alexander Larsson
3c34ca3405 gdkgl: Don't constantly re-create the tmp framebuffer 2014-11-06 12:24:43 +01:00
Alexander Larsson
fb50015519 GdkGLContext: Change the way we track the current context
To properly support multithreaded use we use a global GPrivate
to track the current context. Since we also don't need to track
the current context on the display we move gdk_display_destroy_gl_context
to GdkGLContext::discard.
2014-10-30 12:43:03 +01:00
Alexander Larsson
72a6459d73 gdkglcontext: Track whether to use GL_TEXTURE_2D or GL_TEXTURE_RECTANGL_ARB 2014-10-27 21:17:08 +01:00
Alexander Larsson
3013997e23 Rename gdk_gl_context_flush_buffer to gdk_gl_context_end_frame
This makes a lot more sense.
2014-10-27 16:33:37 +01:00
Alexander Larsson
038aac6275 gdk: Add support for OpenGL
This adds the new type GdkGLContext that wraps an OpenGL context for a
particular native window. It also adds support for the gdk paint
machinery to use OpenGL to draw everything. As soon as anyone creates
a GL context for a native window we create a "paint context" for that
GdkWindow and switch to using GL for painting it.

This commit contains only an implementation for X11 (using GLX).

The way painting works is that all client gl contexts draw into
offscreen buffers rather than directly to the back buffer, and the
way something gets onto the window is by using gdk_cairo_draw_from_gl()
to draw part of that buffer onto the draw cairo context.

As a fallback (if we're doing redirected drawing or some effect like a
cairo_push_group()) we read back the gl buffer into memory and composite
using cairo. This means that GL rendering works in all cases, including
rendering to a PDF. However, this is not particularly fast.

In the *typical* case, where we're drawing directly to the window in
the regular paint loop we hit the fast path. The fast path uses opengl
to draw the buffer to the window back buffer, either by blitting or
texturing. Then we track the region that was drawn, and when the draw
ends we paint the normal cairo surface to the window (using
texture-from-pixmap in the X11 case, or texture from cairo image
otherwise) in the regions where there is no gl painted.

There are some complexities wrt layering of gl and cairo areas though:
* We track via gdk_window_mark_paint_from_clip() whenever gtk is
  painting over a region we previously rendered with opengl
  (flushed_region). This area (needs_blend_region) is blended
  rather than copied at the end of the frame.
* If we're drawing a gl texture with alpha we first copy the current
  cairo_surface inside the target region to the back buffer before
  we blend over it.

These two operations allow us full stacking of transparent gl and cairo
regions.
2014-10-13 10:43:31 -04:00