Safari's WebGL1 implementation (rightly) complains that first-class
array types are not supported as function result types. Define and
use a struct type instead.
While we're here, use const variables instead of functions.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The macOS backend doesn't re-create contexts, holding on to the first
created instead. Make sure the GPU leaves the default framebuffer bound,
in case the context is re-used.
Signed-off-by: Elias Naur <mail@eliasnaur.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>
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>
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>
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>
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>
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>
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>
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>
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>
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>