Commit Graph

205 Commits

Author SHA1 Message Date
Kamil Jarosz 7dd4d2006e render: Add primitives for drawing lines
This patch adds draw_line and draw_line_rect methods to CommandHandler,
providing empty impls to be overridden by corresponding backends.

The ability to draw lines is described using a new bitflags struct
RenderBackendFeatures, which contains a set of features
supported by the given render backend.
Currently, it contains a DRAW_LINES flag, which informs whether
the backend supports drawing lines as primitives.
2024-07-02 23:40:50 +02:00
Kamil Jarosz cff1b14409 render: Emulate drawing lines using quads 2024-07-02 23:40:50 +02:00
Kamil Jarosz 23f01e0dd9 render: Add Matrix::create_box_with_rotation
This patch splits the current method of create_box into
1. create_box -- without rotation, and
2. create_box_with_rotation -- with rotation.

The reason for that refactor is that create_box was often used without
rotation, and always passing 0.0 as rotation and having
a dedicated condition for 0.0 was superfluous.
2024-07-02 23:40:50 +02:00
Nathan Adams 7eef31046b render: Make serde optional 2024-06-13 00:22:33 +02:00
TÖRÖK Attila f9f4c3bb82 render/wgpu: Drop `naga_oil` in favor of manual string manipulation 2024-05-16 20:24:49 +02:00
sleepycatcoding be8cbd64d6 core/render/web: Make FromStr exclusively for snake_case 2024-05-16 01:14:42 +03:00
Kamil Jarosz b99bdadb8f render: Improve performance of round_to_i32
This patch improves performance of matrix::round_to_i32()
by using f32::round_ties_even(), which has been stable
since 1.77.0, instead of a custom algorithm.
2024-05-08 22:16:40 +02:00
Kamil Jarosz 6ad4bc4999 render: Add tests for round_to_i32 2024-05-08 22:16:40 +02:00
Adrian Wielgosik 08157a056e build: Fix redundant import warnings 2024-03-23 19:23:18 +01:00
Aaron Hill 900a8407d6 core: Implement lazy decoding of bitmaps
We hit a pathological case in House
(https://github.com/ruffle-rs/ruffle/issues/15154),
where eagerly decoding bitmaps during preloading results in
over 10GB of ram being used.

With this PR, we store the compressed bitmap, and only decode it
each time we instantiate it. In order to support bitmap fills,
we store the decoded width/height and a lazily-initialized GPU handle
in `Character::Bitmap`
2024-02-27 21:18:18 -05:00
Aaron Hill 86e471835e Fix clippy beta lint 2024-02-04 21:14:05 +01:00
Nathan Adams 70fbb4a7ac render: Move away from SyncHandle.retrieve_offscreen_texture to RenderBackend::resolve_sync_handle 2024-02-02 00:59:45 +01:00
Nathan Adams fcb74d8fbc wgpu: Deduplicate common gradients from a single Mesh 2024-01-27 21:37:22 +01:00
Nathan Adams e479d12af0 render: Make Mesh a struct, not just an alias for Vec<Draw> 2024-01-27 21:37:22 +01:00
Aaron Hill 820e7e828a wgpu: Allow Stage3D texture upload where source is smaller than dest
Fancy Pants World 4 relies on this behavior.
2024-01-25 00:30:10 +01:00
Aaron Hill 1cb24b41b0 render: Support PixelBender ByteArray/Vector.<Number> input/output
When ActionScript uses a ByteArray/Vector.<Number> as a shader input
or target, we create a temporary Rgba32Float texture, and copy the
input float32 bytes to/from the texture.

Unfortunately, wgpu doesn't seem to support an Rgb32Float (3-channel)
texture. When the shader uses 3 channels, we use a Rgba32Float
(4-channel) texture, and manually insert/remove padding for the
alpha channels. This isn't very efficient, but it's the simplest
solution.

The temporary textures themselves aren't cached anywhere - if this
becomes a performance issue, we could look into using some of our
existing wgpu texture/buffer pooling code.
2024-01-24 08:31:52 -05:00
Aaron Hill 57f6963133
render: Implement PixelBender Operation::Select (renamed from Loop) (#14503) 2024-01-11 01:04:50 +00:00
Aaron Hill 47db84473a avm2: Improve handling of Stage3D profile
We now validate the passed in profile, and return the selected profile
from 'Context3D.profile'. We don't yet alter the available
registers/textures based on the profile.
2024-01-07 22:34:33 +01:00
Nathan Adams f2b02acf44 chore: Appease clippy-beta 2023-11-13 20:26:50 +01:00
Nathan Adams f03b6307a8 core: Don't invalidate when setting filters to the same value 2023-11-10 22:24:45 +01:00
Aaron Hill 7110be920c Suport uploading ATFTextureData::CompressedRawAlpha
Fortunately, this is very simple - we can just take
the DXT5 data and upload it directly to the wgpu texture.
2023-11-10 02:00:40 +01:00
Lord-McSweeney 249454885b render: In `ShapeTessellator`, set `mask_index_count` to `None` in `flush_draw` before aborting 2023-11-09 20:22:25 +01:00
Aaron Hill b5097445e6 render: Add support for Context3DTextureFormat.COMPRESSED_ALPHA
This is our first non-rgba texture format (it uses Bc3RgbaUnorm).
ATF files store these textures in a very convoluted way - fortunately,
the 'dds2atf' tool is open-source, which allowed me to figure out
how to decode the texture back to a DXT5/DXT1 texture.
2023-10-23 11:18:27 -04:00
Aaron Hill d76306d5ae render: Fix incorrectly reading U24 in ATF parsing
We should be reading a big-endian U24.
2023-09-30 20:29:49 -04:00
Aaron Hill ec7a8ac645
avm2: Add support for Stage3D bytearray/compressed textures (#13180) 2023-09-28 03:03:30 +00:00
Aaron Hill ccf42c3614 naga-pixelbender: Stub out Opcode::Loop
Some experimentation with Pixel Bender Studio shows
that Opcode::Loop has a 23-byte payload. I haven't tried to
figure out how to interpet the payload yet, but we can now
skip over the opcode instead of bailing out entirely.
2023-08-30 17:36:31 -04:00
Nathan Adams 19ad492eaa avm2: Implement Graphics.cubicCurveTo and CUBIC_CURVE_TO 2023-08-27 20:17:43 +02:00
Nathan Adams eb2afb19c4 render: Add DrawCommand::CubicCurveTo 2023-08-27 20:17:43 +02:00
Nathan Adams 076977cc75 render: Rename DrawCommand::CurveTo to DrawCommand::QuadraticCurveTo 2023-08-27 20:17:43 +02:00
Nathan Adams 1a4a808c23 render: Make Filter::calculate_dest_rect work in Twips 2023-08-12 13:00:27 +02:00
Nathan Adams da090f0bd7 render: Move filter size calculation from wgpu to render/swf 2023-08-12 13:00:27 +02:00
SuchAFuriousDeath 11a472d40b
render: fix jpeg cmyk to rgb (#12592)
Co-authored-by: tompro <tomas.prochazka@apertia.cz>
2023-08-06 20:47:07 +03:00
Nathan Adams ab27c8b4ee render: Calculate correct bounds for shapes containing curves 2023-08-02 18:43:33 +02:00
Aaron Hill 583caa3389
avm2: Implement DisplayObject.blendShader (#12238) 2023-07-26 23:25:26 +00:00
relrelb 5f6d8d72ea render: Skip unreasonably large bitmaps
Some SWFs report unreasonable bitmap dimensions, and trying to reserve
enough capacity for them always fails. To avoid panics, skip those bitmaps.

Fixes #1191
Fixes #2759
Fixes #10701
2023-07-24 09:37:37 +03:00
Nathan Adams 4410d666ed avm2: Implement Bitmap.pixelSnapping 2023-07-22 00:34:17 +02:00
Nathan Adams 289f73c85f core: Add pixel snapping (default auto) to Bitmaps, and force it for cacheAsBitmap 2023-07-22 00:34:17 +02:00
Nathan Adams b201e19cc7 wgpu: Don't create an extra fresh texture for applying filters to a CAB 2023-07-20 23:19:20 +02:00
Nathan Adams 400ff32723 wgpu: Implement a naive DisplacementMap filter 2023-07-20 12:41:30 +02:00
Aaron Hill 715abd8985 avm2: Use invisible mask descendants for mouse picking and rendering
The 'DisplayObject.visible' flag seems to be ignored for mask objects
(and their descendants) - mouse picking still takes them into account,
and they get rendered as part of the mask.

This commit changes display object rendering and AVM2 mouse picking
to ignore DisplayObject.visibility when dealing with mask objects/
descendants.
2023-07-19 23:18:28 +02:00
Moulins 3ea67668c0 render: make Context3D renderers fully GC-agnostic
The 'gc_arena' dependency was only used to manipulate the `GcCell`s
containing the vertex and fragment shaders; replacing these by a
reference to a plain old `Cell` means tha  the Context3D traits and
types do not need to interact with GC'd object anymore.

As a knock-on effect, we can also remove the `Activation` parameter
from most of the `Context3DObject` methods.
2023-07-14 16:06:36 -06:00
Nathan Adams 30e7a1eac6 core: Account for filter size changes when drawing cacheAsBitmaps 2023-07-12 18:51:11 +02:00
moulins f5b4fbce77
Upgrade to new `gc-arena` API (#11182)
* core: add temporary, ruffle-internal copy of `gc-arena` crate

This will allow bumping the upstream `gc-arena` version while
reexporting our own version of the old `GcCell` API, so that
Ruffle's code can be gradually migrated.

Once the migration is done, this crate should be removed.

* core: bump `gc-arena` to kyren/gc-arena#56

Add back the removed `GcCell` to our internal facade crate

* core: bump `gc-arena` to current master

This bump renames `Gc::allocate` to `Gc::new`

* core: rename `GcCell::allocate` to `GcCell::new`, to match `Gc`

* core: bump gc-arena to (slighly after) v0.3.1

Add typedefs for old `*Context` names in the gc-arena facade crate

* core: replace uses of `CollectionContext<'_>` by `&Collection`

* core: Add `gc()` convenience method for `*Context` and `Activation` types

This allows shortening most instances of `[activation.]context.gc_context`
to `activation.gc()` or `context.gc()` (but not all instances, because of
borrowck) Note that this doesn't actually do these shortenings to avoid
major code churn.
2023-07-09 17:04:25 -04:00
Aaron Hill 9d3e96e3a4
render: Implement more Pixelbender opcodes, and fix matrices (#11896) 2023-07-09 16:54:26 +00:00
Aaron Hill b6fae8e214 wgpu: Cache Program3D bind group layout
The bind group layout only depends on the texture registers
(and 2D/cubemap type) accessed by the fragment shader, not on
the runtime texture bound with Context3D. This means that we can
build and cache it when we compile the AGAL program to a Naga
module.

Since the bind group layout is used for the overall pipeline, I've
refactored the shader caching code into `ShaderPairAgal`, which
holds both the vertex and fragment shader bytecode, and compiles
both in the `compile` function.
2023-07-09 12:39:10 -04:00
Aaron Hill f22bef99b4 core: Fix some Clippy lints on the latest nightly 2023-07-04 20:50:46 +02:00
Nathan Adams 146d565c02 render: Add Filter::scale() and use it to scale filter values (currently just blur_) 2023-07-03 20:13:40 +02:00
Aaron Hill 26101ae979 render: Add 'renderdoc' feature/module for manual frame capture
This feature is disabled by default. When enabled, you can use
`ruffle_render::renderdoc::begin_frame_capture` and
`ruffle_render::renderdoc::end_frame_capture` to manually trigger
a RenderDoc frame capture (if Ruffle wasn't launched by RenderDoc,
this logs an error).

This is very useful when debugging Stage3D/PixelBender bugs, as you
can produce a capture containing only the relevant graphics calls.
2023-07-02 13:59:19 -04:00
Aaron Hill 6e1f00edf2
render: Implement more PixelBender features (#11800) 2023-07-01 13:50:43 -04:00
Nathan Adams a5915a9bdb swf: Make Color Copy 2023-06-29 20:32:36 +02:00