Commit graph

128 commits

Author SHA1 Message Date
Simon Hausmann
ad98ae65ae Avoid unnecessary path building 2020-07-10 10:24:36 +02:00
Simon Hausmann
f45ff6ce79 Add support for stroking paths
This will make it easier to visualize the path for layouts.
2020-07-09 09:36:16 +02:00
Simon Hausmann
dfe95a2f6d Allow rendering primitives to break down into multiple GL primitives
This is in preparation for path stroking and filling.
2020-07-09 09:10:55 +02:00
Simon Hausmann
afa23faa94 Move the path building function into corelib
We're going to need it not only in the GL renderer but also in the layout code.
2020-07-08 20:36:40 +02:00
Simon Hausmann
c6c0f1f589 Make path arc rendering more robust
Some arcs may not result in any content, for example if the radius is too small
or start and end pointer overlap. Let Lyon do the
checking for us and handle it accordingly.

Newer versions of Lyon will allow the re-use of the SvgArc created temporarily.
2020-07-08 08:42:01 +02:00
Simon Hausmann
f646809ff4 Added ArcTo element for paths 2020-07-07 16:02:46 +02:00
Simon Hausmann
1ab71b8ca3 Prepare the path element setup in the run-time for extensibility
Make the anonymous struct for the LineTo variant in the PathElement enum
as separate structure, which can be introspected using rtto::FieldInfo.
2020-07-07 14:14:17 +02:00
Simon Hausmann
9cf2d618d2 Use Lyon's path builder
Instead of trying to convert the individual (future) elements, let's use a builder.
This way the markup remains simple and due to
future support for bindings we can't really
pre-compute the path events anyway.
2020-07-07 14:14:17 +02:00
Simon Hausmann
4e22c2839e Add the rendering primitives for rendering a path
Right now the path is limited to polygons (only LineTo elements) and only the fill color can be specified.
2020-07-01 14:58:09 +02:00
Simon Hausmann
8f613685ba Expose a ComponentWindow in C++
This paves a way for a more modular API.
2020-06-17 19:15:18 +02:00
Simon Hausmann
9df888578f Expose a ComponentWindow type in Rust
This comes with a factory function that re-directs to the backend and a
run member function to replace
sixtyfps_runtime_run_component_with_gl_renderer. For now it's all still
hidden in the generated run() method.
2020-06-17 19:15:18 +02:00
Simon Hausmann
85bf8a195a Improve EventLoop encapsulation
Hide the winit loop and extract it only in the GL renderer
2020-06-17 15:16:46 +02:00
Simon Hausmann
271f52b9c9 Fix rectangle rendering with alpha
Lyon generates triangles, not a triangle strip. For a triangle strip
we'd end up drawing too many triangles, messing
up the alpha on overdraw.
2020-06-16 13:46:25 +02:00
Olivier Goffart
89968e0722 Add a Slice type which can be used in FFI 2020-06-10 14:23:57 +02:00
Simon Hausmann
1404cb73ae Add support for embedding resources in the rust generator
This is relatively straight-forward via a pass in the compiler to
collect the resources to embed and then use include_bytes! (once per
resource).

What's really annoying is that the rust resource enum can't store a
&'static [u8] because cbindgen doesn't represent that, probably because
the slice representation isn't guaranteed to stay as it is. So instead
this, for now, uses raw pointers.
2020-06-09 22:54:29 +02:00
Simon Hausmann
5bae6e01a5 Prepare for the ability to embed image data
The Image's source property used to be a string. Now it is a Resource
enum, which can either be None or an absolute file path to the image on
disk. This also replaces the internal Image type.

The compiler internally resolves the img bang expression to a resource
reference, which shall remain just an absolute path. For now the target
generator passes that through, but in the future the target generator
may choose a target specific way of embedding the data and thus
generating a different Resource type in the final code (through
compile_expression in the cpp and rust generator).

The C++ binding is a bit messy as cbindgen doesn't really support
exporting enums that can be constructed on the C++ side. So instead we
use cbindgen to merely export the type internally and only use the tag
from it then. The public API is then a custom Resource type that is
meant to be binary compatible.
2020-06-09 22:54:29 +02:00
Simon Hausmann
aa61a9d2b2 Reduce the #[cfg] usage a little in the GL renderer
Collect configuration specific fields in one PlatformData structure.
2020-06-09 14:04:39 +02:00
Simon Hausmann
fb2b12c28a Implement basic text rendering on the wasm port
Based on Olivier's suggestion, the text rendering primitive is created
by painting the text onto a temporary HTML canvas
element and binding that to a texture.
2020-06-08 17:00:59 +02:00
Olivier Goffart
7b8df5ca9d Use interior mutability for the cache
So we do not need a mutable reference to the Component
2020-06-04 14:03:30 +02:00
Olivier Goffart
e4366efb67 Do not require the component to be static to show a window 2020-06-04 13:44:40 +02:00
Simon Hausmann
bcc6c6a60a Move Color and RenderingPrimitive into abi::datastructures
This paves the way to replace RenderingInfo.
2020-05-22 16:07:06 +02:00
Simon Hausmann
cd80a4038f Clean up HasRenderingPrimitive trait API after transition
The extraction does not have to be optional anymore. That will make
future code using this simpler.
2020-05-22 16:07:06 +02:00
Simon Hausmann
21842bdd75 Remove the individual primitive factory functions from RenderingPrimitivesBuilder
Only use the new one that takes the new enum.
2020-05-22 16:07:06 +02:00
Simon Hausmann
9459578265 Add API to the RenderingPrimitivesBuilder to build the new style primitive 2020-05-22 16:07:06 +02:00
Simon Hausmann
5c8163d7a7 Introduce a new rendering primitive enum in the graphics module
This shall become the successor to RenderingInfo. For now it's just a
place holder, but the idea is that backend creates the opaque primitive
that holds this public rendering primitive, exposed via the
HasRenderingPrimitive trait.
2020-05-22 16:07:06 +02:00
Simon Hausmann
e7fd69bad1 Rename internal types
Rename the backend specific RenderingPrimitive to LowLevelRenderingPrimitive,
in order to make room for a high-level RenderingPrimitive enum that's public.
2020-05-22 16:07:06 +02:00
Simon Hausmann
f2662f0884 Simplify image primitives graphics API
Don't require a dest rect for now. Rendering is always at (0, 0) but
with the transformation applied. And the size shall for now not be a
parameter.
2020-05-22 16:07:06 +02:00
Simon Hausmann
4d26fe6674 Implement support for selecting the font family and pixel size in the GL renderer
The public API in the properties is still missing.
2020-05-21 20:55:34 +02:00
Simon Hausmann
86eaf027d4 Implement glyph runs grouped by texture
In order to support multiple font sizes, etc. we have to deal with the
fact that the glyphs for a string may not end up all in the same atlas
texture. Therefore splitting of glyph runs by texture is necessary.

This works but could be improved further by sharing the vertex arrays
and just re-binding to a different texture and drawing the run's
triangles by index.
2020-05-21 15:51:09 +02:00
Simon Hausmann
66c91ef658 Prepare for supporting multiple glyph runs
A glyphs primitive may end up requiring multiple draw commands in the future,
so prepare for that.
2020-05-21 15:51:09 +02:00
Simon Hausmann
de923131ee Remove dummy test code
It's not testing anything :-)
2020-05-20 13:27:07 +02:00
Simon Hausmann
994d47a529 Shader module cleanup
Move the specific shaders into the shaders module and then hide the Shader
type. It's not necessary to export it anymore.
2020-05-20 13:27:07 +02:00
Simon Hausmann
f7dfb030a0 Improve shader setup code
Determine the locations of the uniforms and attributes once instead of on every use.
This makes the code easier to read and faster.
2020-05-20 13:27:07 +02:00
Simon Hausmann
b7fd9658d3 More shader code cleanup
Move the uniform and attribute binding into the shader encapsulating types.
2020-05-20 13:27:07 +02:00
Simon Hausmann
036c1aae38 Begin shader code cleanup
Start by a bit of encapsulation of the specific shaders we use.
2020-05-20 13:27:07 +02:00
Simon Hausmann
5acb8e7bdd Minor glyph handling cleanup
When laying out glyphs, don't require a slice, just an iterator.
2020-05-20 11:02:48 +02:00
Simon Hausmann
9b9a29e03d Clean up glyph handling
Avoid calling glyph_for_char twice for each character.
Instead do the conversion once explicitly. That needs to be done anyway for shaping.
2020-05-20 10:50:49 +02:00
Simon Hausmann
e0cc9aef2a Cleanup text rendering code a bit
Move the text related code into a separate file.
2020-05-20 10:50:49 +02:00
Simon Hausmann
f29aa0a302 GL buffer handling cleanup
Move the buffer handling code into a separate file.
2020-05-20 10:50:49 +02:00
Simon Hausmann
4834de04f9 Shader code cleanup
Move the shader code into a separate file
2020-05-20 10:50:49 +02:00
Simon Hausmann
f27a715b30 GL texture handling cleanup
Move the gl texture handling code into a separate file/module.
2020-05-20 08:52:20 +02:00
Simon Hausmann
527525f733 Another issue created for tracking 2020-05-19 22:16:08 +02:00
Simon Hausmann
d7b742d082 Created issue for comment 2020-05-19 22:14:27 +02:00
Simon Hausmann
3f813808f1 Small comment fix 2020-05-19 22:13:11 +02:00
Simon Hausmann
81b5f70718 Implement colored text rendering 2020-05-19 21:58:01 +02:00
Simon Hausmann
ddf137221a Implement glyph rendering using atlas texturing
This means duplicate glyphs are rendered only once and we store glyphs
in the atlas texture globally instead of a texture per text primitive.
2020-05-19 21:47:47 +02:00
Simon Hausmann
3c2ad7b275 Add support for atlas textures in the GL renderer
... and place images in there by default. This improves locality.

The atlasing is also needed for individual glyph rendering, which is
coming soon.
2020-05-19 20:38:28 +02:00
Simon Hausmann
cbd28bf745 Simplify image primitives API
Removed the source rectangle as that can also be done on the source image side,
if necessary.
2020-05-19 20:37:36 +02:00
Simon Hausmann
23d3964a0d Add boilerplate for text items
Forward the text and color properties to the rendering backend, where
right now we just rendering all the glyphs into a dedicated texture.

Next steps are a glyph atlas texture, blending the specified color with
the alpha of the glyphs, configurable size and family, shaping with
Harfbuzz and may more things.
2020-05-18 19:04:12 +02:00
Olivier Goffart
686f4c9591 More work on the vtable macro to adapt the Component
This does not work yet
2020-05-18 11:04:54 +02:00