This is a first step towards supporting affine drawing transforms.
The rendering algorithm relies on quadratic curves that do not cross
x = 0 more than once, thus curves must be split after any rotation/shear
transforms. Move this logic and the generation of vertices to package gpu.
Also close all curves and draw zero-width edges as preparation for
transform since the will no longer implicitly be vertical with no
effect.
This commit will severely affect performance since vertexes are now
transformed also for cached items, using cpu resources.
Signed-off-by: Viktor <viktor.ogeman@gmail.com>
Specifying the clear color and depth at the time of clearing is
less error prone and a better for modern GPU APIs. As a bonus, we
can get rid of the BufferAttachment type.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
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>
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>
"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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>