Commit Graph

54 Commits

Author SHA1 Message Date
Egon Elbre 7c1a21ce56 add f32color.RGBA
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-03-12 13:21:34 +01:00
Elias Naur 7024a0e691 gpu: fix depth buffer on direct3d and headless opengl
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-11 17:45:16 +01:00
Elias Naur 61529c2cb6 gpu: fix clip intersection with the D3D backend
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-11 16:23:35 +01:00
Elias Naur 8405bf0e47 gpu/shaders: be more robust against floating point inaccuracies
We're forced by compatibility to encode an integer state into a
floating point. Make the implicit conversion from floating point to
integer more robust against GPUs with low precision floats.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 14:27:50 +00:00
Elias Naur b194a0ce58 internal/cmd/convertshaders: target 9.1 compatibility shader model
Direct3D 11 supports Direct3D 9.1 level hardware, but only if the shaders are
compiled for target 4_0_level_9_1.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-28 15:22:58 +01:00
Elias Naur bfb50cef5d all: remove unused fields, functions and add missing error handling
Credit to staticcheck.io.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 22:26:54 +01:00
Elias Naur e03b3cd808 app/internal/d3d11: add Direct3D backend
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:41:35 +01:00
Elias Naur d65bfdc275 internal/cmd/convertshaders: use gofmt to format output
In particular, the simplifying "-s" flag to gofmt ensures that the automatic
test for unformatted Go source files won't complain.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:41:31 +01:00
Elias Naur 591c89ab0a gpu: drop use of integer shader inputs
They're a pain to support. Encode the single integer value we have
as a float instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur 3043c4243a gpu/backend: add support for GLSL 1.50
Apple's OpenGL 3.2 Core implementation doesn't accept 1.30.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur dd6a247326 gpu/backend: add support for desktop OpenGL 3
In particular, add the GLSL 1.30 shader variant. Sigh.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur a0c4688d0c app/headless,gpu/gl: make ReadPixels y-flipping backend specific
The Direct3D backend doesn't need y-flipping, so don't do it unconditionally in
package app/headless.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur 8dce81d8fd gpu/shaders: introduce toClipSpace to map to GPU native clip space
OpenGL use the [-1; 1] range for clip depths, Direct3D [0; 1].
Use toClipSpace to encapsulate the difference.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur c34c350a52 gpu: pack 2D transforms in vec4 values
Instead of separate 2d scale and transform, pack them into a single
4d value.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur c20c1ab96f gpu/shaders: compensate for GPU Framebuffer => texture transformation
Add fboTextureTransform shader function for cancelling the
implied transformation from fragments output by the fragment
shader and the (u, v) coordinates used to sample from it in a
later pass.

For OpenGL the transformation is the identity.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur 29d36e11ee gpu/shaders: use correct type for integer vector
OpenGL supports casting from int to float during vertex array
reading. Direct3D doesn't. Since we're transpiling from GLSL, we can't
directly use the Direct3D builtin "asint". So that leaves using
"ivec2" instead of vec2.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur 0d266c413d gpu,gpu/backend: implement GLSL 300 es shader variants
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:58 +01:00
Elias Naur 23757b1022 gpu: avoid internal uniform buffer pointers
Uniform buffers are byte slice backed by Go structs. However, if a uniform
buffer value is embedded in a larger structure with pointers, the Cgo
pointer checker will complain. Avoid the error by moving the uniform
values into separate structures.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:23 +01:00
Elias Naur b9d131409e gpu/gl: tolerate programs with no attributes
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 0be4dd9af0 app/internal/cmd/convertshaders: use backend types directly
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur fd61c226d4 internal/cmd/convertshaders: move shader converter to separate package
To use the converter from other packages, make the converter a
runnable command.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
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