Commit Graph

33 Commits

Author SHA1 Message Date
Elias Naur 5cd5d49108 gpu/backend: move backend interface types to a separate package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur dfc1503c00 gpu: replace Backend.DefaultFramebuffer by Backend.CurrentFramebuffer
DefaultFramebuffer was set up at Backend creation time, which is
difficult to predict. Instead, let GPU query and cache the current
FBO when created.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur b4c163e437 gpu: Move Bind methods to Backend
Having Backend.Bind* methods better matches both opengl and d3d.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur e4a927982d gpu: add Framebuffer.ReadPixels
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 6fd545a4d8 gpu: add depthBits parameter to NewFramebuffer
Along with ReadPixels in the next change, a Framebuffer with depth is enough to
implement screenshot functionality on top of any Backend.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 10484d26f3 gpu: return and handle errors from Backend.New... methods
"handling" means panicing, but at least the panicing is moved up
a layer, leaving future changes to do it properly in GPU.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 9c984e03b8 gpu: drop Framebuffer.IsComplete in favour of an error from NewFramebuffer
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur eb7e11ee8e gpu: specify target Texture Backend.NewFramebuffer
OpenGL doesn't care if the texture to a framebuffer changes, but
Direct3D does. Change Backend to better match both APIs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur cae97a9861 gpu: add binding flags to Backend.NewTexture
Direct3D needs to know the texture bind usage up front, in particular
whether the texture is going to be used as a render target.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 411f566e3f gpu: rename BufferType to BufferBinding and make it a set
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 744a962beb gpu: remove Backend.NilTexture
It serves no purpose other than paranoia. Perhaps buggy drivers exists that
require unused texture slots cleared before drawing to a texture, but if so the
workaround belongs in the GL backend.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur a4ee72ed28 gpu: remove Backend.Resize and fully specify format in Backend.NewTexture
Re-create textures instead to better match direct3d.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 4e3bfd5b1b gpu: setup OpenGL ES texture uniforms automatically from shader metadata
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 5c359bbf89 gpu/shaders: delete unused uniform
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 5ba7854656 gpu/gl: fix offset calculation in DrawElements
The offset argument to DrawElements is in 16-bit shorts, while the
underlying DrawElements use byte offsets.

No users of DrawElements use a non-zero offset, so nothing changed.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 646a767665 gpu,gpu/gl: implement shader uniform buffers
Emulate them for the OpenGL ES backend because 2.0 doesn't support uniform
buffers. The future d3d backend only supports uniform (constant) buffers.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur ef3e94e7a7 gpu: add NewBuffer and Buffer.Upload for creating mutable buffers
We're going to need them for shader uniform buffer storage.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur fbb7fffd46 gpu: rename NewBuffer to NewImmutableBuffer
Prepare for adding NewBuffer for mutable buffers.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur f5905b3ca8 gpu: rename BufferTypeData to less vague BufferTypeVertices
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 826ab9e65b gpu,gpu/gl: specialize Buffer.Bind to Buffer.BindIndex
Direct3D can't support a generic Bind, and we don't need it now
BindVertex was added.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 9cdc8e6182 gpu,gpu/gl: introduce InputLayout and use shader reflection data
InputLayout is the abstraction for the mapping between vertex data and
shader inputs. The mapping is implicit in OpenGL but explicit in
Direct3D.

Infer the attribute name location index using shader reflection data,
and get rid of a parameter to NewProgram.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur ac7029fa24 gpu/internal/shaders: generate shader variants
We're about to add Direct3D support, where shaders are written in
HLSL. Rather than write shaders twice (or more), convert them to
a GLSL variant understood by the glslcc cross-compiler and generate
the OpenGL ES 2.0 and HLSL variants. The HLSL is used by a future
change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur f62725ea77 gpu: make Buffers immutable
The GPU implementation only uses immutable buffers so far, so let's
make it easy and performant for the backends.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:21 +01:00
Elias Naur 49365dbcc5 gpu: allocate path draw index buffer once
Before this change, the index buffer would start empty and grow up to the
maximum size (128kb). It would never shrink. We're about to tighten the GPU
buffer API to be immutable for performance and to better match Direct3D, so
allocate the index buffer once at startup, and limit it to a reasonable size.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:21 +01:00
Elias Naur 69dfd2e3a5 op/paint: add support for efficient ImageOp subimages
The new field ImageOp.Rect is initialized to cover the entire source
image, but can be modified to draw only a section of it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-13 13:15:32 +01:00
Elias Naur 6945a9062b gpu/gl: add detail to the float FBO error message
Updates gio#49

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-11 15:38:19 +01:00
Elias Naur ef9459c7fd gpu/gl: remove unused methods from Functions interface
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-10 18:22:58 +01:00
Elias Naur 8b5e9af5f8 gpu/gl: remove unused methods and unexport internal
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-10 18:22:58 +01:00
Elias Naur adb950cbf3 app/internal/srgb: move sRGB emulation to new internal package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-10 18:22:58 +01:00
Elias Naur 3ae5a37c24 gpu,gpu/gl: introduce Backend
A recent change made the OpenGL functions an interface of the functions
required for the implementation of GPU, a renderer for Gio operations.
That allowed for running Gio on external systems where OpenGL is
available.

However, to allow for non-OpenGL flavored backends such as Vulkan,
Metal and Direct3D, this change introduces Backend for the high-level
operations required by GPU. This change also adds a concrete backend
to package gl.

Type Backend is a first cut heavily based on OpenGL. Future changes will add
more backends, where the Backend interface quite possibly will need refinement.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-10 18:22:57 +01:00
Elias Naur 9602337b45 gpu/gl: remove redundant glClear from sRGB emulation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-10 15:58:36 +01:00
Elias Naur d2d495416a gpu: rename method GPU.Frame to BeginFrame and drop redundant argument
The viewport size was already specified in the call to Collect.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 21:35:19 +01:00
Elias Naur 3b6646933d gpu: expose the rendering implementation
The rendering implementation is needed for using Gio UI with external
window libraries such as GLFW. Expose it in the new package gpu.

Updates #26

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 21:21:38 +01:00