Skip to content

feat(flame_3d)!: Introduce RenderContext to make GraphicsDevice focused#3872

Open
wolfenrain wants to merge 11 commits intomainfrom
feat(flame_3d)/introduce-render-context
Open

feat(flame_3d)!: Introduce RenderContext to make GraphicsDevice focused#3872
wolfenrain wants to merge 11 commits intomainfrom
feat(flame_3d)/introduce-render-context

Conversation

@wolfenrain
Copy link
Copy Markdown
Contributor

Description

Introducing a RenderContext3D that abstracts away actual rendering from the GraphicsDevice. This simplifies both binding, rendering and applying shaders in a way that is more sensible for game developers.

We hide away the complexity of the GraphicsDevice while still allowing complexity for those who need it.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

@wolfenrain wolfenrain marked this pull request as ready for review March 26, 2026 08:52
@wolfenrain wolfenrain marked this pull request as draft March 26, 2026 12:47
@wolfenrain wolfenrain marked this pull request as ready for review March 26, 2026 20:35
@wolfenrain wolfenrain force-pushed the feat(flame_3d)/introduce-render-context branch from 8b014e2 to fd3d22c Compare March 26, 2026 22:44
/// render directly to a [GraphicsDevice] instead of the regular rendering.
/// {@endtemplate}
class World3D extends flame.World with flame.HasGameReference {
class World3D extends flame.World with flame.HasGameReference<FlameGame3D> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense for it to declare T extends FlameGame3D, HasGameReference<T>, in case a user wants to extend World3D and also have a ref to their own game class?

@@ -1,21 +1,37 @@
// ignore_for_file: avoid_redundant_argument_values
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to disable it? can we just fix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I decided to disable it be quiet explicit how our render config is setup

If flutter_gpu ever changes the values we wouldn't know on time until rendering goes weird

j--;
}
_drawPool[j + 1] = entry;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt there any built-in sort-in-place-by algo on dart?

Comment on lines +54 to +60
if (_drawCount >= _drawPool.length) {
_drawPool.add(_DrawEntry());
}
_drawPool[_drawCount]
..distance = dx * dx + dy * dy + dz * dz
..object = object;
_drawCount++;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could encasulate a generic Pool class that handles minimal allocation while you can just do set/get

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also we never de-allocate after increasing the size. a pool class could also handle that through some heuristic

// values.
final dx = _cameraPosition.x - worldTransform.storage[12];
final dy = _cameraPosition.y - worldTransform.storage[13];
final dz = _cameraPosition.z - worldTransform.storage[14];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there no rows/col accessors that return a pre-allocated view over storage? 12-13-14 feel a bit arbitrary but if that is what we need to avoid vector3 allocation then it is what it is

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, we do have .mNN getters I believe, didn't think about that!

(-viewport.virtualSize / 2).toOffset() &
Size(viewport.virtualSize.x, viewport.virtualSize.y),
Offset.zero & renderSize,
Offset(-size.x / 2, -size.y / 2) & Size(size.x, size.y),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could just be (-size / 2) & size right? (assuming size is Vector2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but it would compute another vector so we wouldn't gain much

However we should just do a Rect.fromLTWH here honestly, that's the cheapest

Copy link
Copy Markdown
Member

@luanpotter luanpotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. left some considerations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants