initial work to split into dart_filament and flutter_filament
This commit is contained in:
36
dart_filament/ARCHITECTURE.md
Normal file
36
dart_filament/ARCHITECTURE.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Rendering/plugin architecture
|
||||
|
||||
This is an overview of how the rendering surface is constructed, and how the Flutter plugin communicates with the Filament renderer. If you are looking to extend the plugin or add (and hopefully contribute back upstream) additional features, start here.
|
||||
|
||||
## Rendering surface
|
||||
|
||||
|Platform|Type|
|
||||
|---|---|
|
||||
|Windows|HWND beneath transparency (OpenGL), glTexture render target + Flutter Texture widget (GLES/ANGLE), glTexture render target + Flutter Texture widget (GLES/ANGLE)|
|
||||
|Android|SurfaceTexture render target + Flutter Texture widget|
|
||||
|iOS|CVPixelBuffer surface (Metal) + Flutter Texture widget|
|
||||
|MacOS|CVMetalTexture render target (Metal) + Flutter Texture widget|
|
||||
|
||||
On most platforms, we create Filament with a headless swapchain, then render into a (hardware accelerated) texture that Flutter imports into its own widget hierarchy via a Texture widget. This allows the Filament viewport to be transformed/composed completely within the Flutter hierarchy (i.e. you could rotate/scale/translate the FilamentWidget in Flutter if you wanted, or insert other widgets above/below).
|
||||
|
||||
Due to performance issues on Windows, we choose a different default approach where Filament renders into its own window, which is then composed with the Flutter window via the system compositor. This only works on Windows 10.
|
||||
|
||||
Using this approach, you will not be able to add a Flutter widget behind the Filament viewport, or transform the viewport itself from within Flutter.
|
||||
|
||||
You can fall-back to the Texture/render target approach by setting `WGL_USE_BACKING_WINDOW` to `false` in `CMakeLists.txt` for Windows.
|
||||
|
||||
However, I don't currently have capacity to maintain this pathway so it will probably be broken on any given day.
|
||||
|
||||
If you want to try the fallback, you have two options for a rendering backend. With `USE_ANGLE` set to `true` in `CMakeLists.txt`, we will use the ANGLE backend (which translates GLES calls to D3D). This provides end-to-end GPU texture support, however there are some odd rendering artifacts with some of the Filament shaders (and in fact will crash with some dynamic lights).
|
||||
|
||||
`USE_ANGLE` set to `false` will use the OpenGL backend, but requires copying the contents of the texture from the GPU to CPU on every frame. This is not optimal for performance.
|
||||
|
||||
### Why not Platform Views?
|
||||
|
||||
Initially, performance of Platform Views was inferior to Texture widgets (and in any case, weren't supported on Windows/Linux). I suspect this is still the case (though that might be worth revisiting).
|
||||
|
||||
However, I am now thinking it would be better to lean towards the current Windows model (where the Flutter app is composited over a Filament viewport running in a separate window or view). I suspect that the overwhelming use case is a Flutter UI sitting on top of a Filament viewport, and that very few people will need to insert widgets beneath the viewport (or transform the viewport from within Flutter, excluding resizes or mobile orientation changes which can be handled independently). Deferring to the system compositor should deliver far better performance, at the cost of slightly more complexity in the setting up the app harness.
|
||||
|
||||
## Flutter <-> Platform <-> FFI
|
||||
|
||||
TODO
|
||||
22
dart_filament/CHANGELOG.md
Normal file
22
dart_filament/CHANGELOG.md
Normal file
@@ -0,0 +1,22 @@
|
||||
## 0.7.0
|
||||
* `removeAsset` & `clearAssets` have been renamed `removeEntity` and `clearEntities`
|
||||
* added support for parenting one entity to another
|
||||
* added basic collision detection + callbacks
|
||||
* added keyboard/mouse widgets + controls
|
||||
* `createViewer` now `awaits` the insertion of `FilamentWidget` so you no longer need to manually defer calling until after FilamentWidget has been rendered
|
||||
* `setCameraRotation` now accepts a quaternion instead of an axis/angle
|
||||
* instancing is now supported.
|
||||
* `setBoneTransform` has been removed. To set the transform for a bone, just `addBoneAnimation` with a single frame.
|
||||
* the Dart library has been restructured to expose a cleaner API surface. Import `package:flutter_filament/flutter_filament.dart`
|
||||
* created a separate `Scene` class to hold lights/entities. For now, this is simply a singleton that holds all `getScene`
|
||||
* `getChildEntities` now returns the actual entities. The previous method has been renamed to `getChildEntityNames`.
|
||||
|
||||
## 0.6.0
|
||||
|
||||
* `createViewer` is no longer called by `FilamentWidget` and must be called manually at least one frame after a FilamentWidget has been inserted into the widget hierarchy.
|
||||
|
||||
|
||||
## 0.5.0
|
||||
|
||||
* Replaced `isReadyForScene` Future in `FilamentController` with the `Stream<bool>` `hasViewer`.
|
||||
* Rendering is set to false when the app is hidden, inactive or paused; on resume, this will be set to the value it held prior to being hidden/inactive/paused.
|
||||
449
dart_filament/README.md
Normal file
449
dart_filament/README.md
Normal file
@@ -0,0 +1,449 @@
|
||||
# Flutter Filament
|
||||
|
||||
Cross-platform, 3D PBR rendering and animation for [Flutter](https://github.com/google/filament).
|
||||
|
||||
Wraps the [the Filament rendering library](https://github.com/google/filament).
|
||||
|
||||
Powers the [Polyvox](https://polyvox.app) and [odd-io](https://github.com/odd-io/) engines.
|
||||
|
||||
This is still in beta: bugs/missing features are to be expected.
|
||||
|
||||
https://github.com/nmfisher/flutter_filament/assets/7238578/abaed1c8-c97b-4999-97b2-39e85e0fa7dd
|
||||
|
||||
|
||||
|Feature|Supported|
|
||||
|---|---|
|
||||
|Platforms|✅ iOS (arm64)<br/>✅ MacOS (arm64)<br/>✅ Android (arm64) <br/>✅ Windows (x64) (>= 10)<br/>⚠️ Linux (x64 - broken)<br/>⚠️ Web (planned)|
|
||||
|Formats|✅ glb <br/>⚠️ glTF (partial - see Known Issues)|
|
||||
|Texture support|✅ PNG <br/>✅ JPEG <br/>✅ KTX <br/>⚠️ KTX2 (planned)|
|
||||
|Camera movement|✅ Desktop (mouse)<br/>✅ Mobile (swipe/pinch)|
|
||||
|Animation|✅ Embedded glTF skinning animations<br/>✅ Embedded glTF morph animations<br/> ✅ Runtime/dynamic morph animations<br/> ⚠️ Runtime/dynamic skinning animations <br/>
|
||||
|Entity manipulation|✅ Viewport selection<br/>⚠️ Entity/transform parenting (planned)<br/> ⚠️ Transform manipulation (mouse/gesture to rotate/translate/scale object) (partial)<br/>⚠️ Runtime material changes (planned)|
|
||||
|
||||
Special thanks to [odd-io](https://github.com/odd-io/) for sponsoring work on supporting Windows, raycasting, testing and documentation.
|
||||
|
||||
PRs are welcome but please create a placeholder PR to discuss before writing any code. This will help with feature planning, avoid clashes with existing work and keep the project structure consistent.
|
||||
|
||||
## Getting Started
|
||||
|
||||
This package requires Flutter >= `3.16.0-0.2.pre`, so you will need to first switch to the `beta` channel:
|
||||
|
||||
```
|
||||
flutter channel beta
|
||||
flutter upgrade
|
||||
```
|
||||
There are specific issues with earlier versions on Windows/MacOS (mobile should actually be fine, so if you want to experiment on your own you're free to remove the minimum version from `pubspec.yaml`).
|
||||
|
||||
Next, clone this repository and pull the latest binaries from Git LFS:
|
||||
|
||||
```
|
||||
cd $HOME
|
||||
git clone <repo> && cd flutter_filament
|
||||
git lfs pull
|
||||
```
|
||||
|
||||
(this step won't be needed after the plugin is published to pub.dev).
|
||||
|
||||
> You *do not need to build Filament yourself*. The repository is bundled with all necessary headers/static libraries (`windows/lib`, `ios/lib`, `macos/lib` and `linux/lib`) and the Flutter plugin has been configured to link at build time.
|
||||
|
||||
Run the example project to check:
|
||||
|
||||
```
|
||||
cd example && flutter run -d <macos/windows/Your iPhone/etc>
|
||||
```
|
||||
|
||||
To use the plugin in your own project, add the plugin to your pubspec.yaml:
|
||||
|
||||
```
|
||||
name: your_project
|
||||
description: Your project
|
||||
...
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_filament:
|
||||
path: <path where you cloned the repository>
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
See the `example` project for a complete sample that incorporates many of the below steps, and more.
|
||||
|
||||
### Creating the viewport widget and controller
|
||||
|
||||
Create an instance of `FilamentControllerFFI` somewhere in your app where it will not be garbage collected until you no longer need a rendering canvas:
|
||||
|
||||
```
|
||||
class MyApp extends StatelessWidget {
|
||||
|
||||
final _filamentController = FilamentControllerFFI();
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
This is a relatively lightweight object, however its constructor will load/bind symbols from the native library. This may momentarily block the UI, so you may wish to structure your app so that this is hidden behind a static widget until it is available.
|
||||
|
||||
Next, create an instance of `FilamentWidget` in the widget hierarchy where you want the rendering canvas to appear. This can be sized as large or as small as you want. On most platforms, Flutter widgets can be positioned above or below the `FilamentWidget`.
|
||||
|
||||
```
|
||||
class MyApp extends StatelessWidget {
|
||||
|
||||
final _filamentController = FilamentControllerFFI();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
color: Colors.white,
|
||||
home: Scaffold(backgroundColor: Colors.white, body: Stack(children:[
|
||||
Container(color:Colors.green, height:100, width:100),
|
||||
Positioned.fill(top:100, left:100child:FilamentWidget(controller:_filamentController)),
|
||||
Positioned(right:0, bottom:0, child:Container(color:Colors.purple, height:100, width:100))
|
||||
])));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When a `FilamentWidget` is added to the widget hierarchy:
|
||||
1) by default a Container will be rendered with solid red. If you want to change this, pass a widget as the `initial` paramer to the `FilamentWidget` constructor.
|
||||
2) on the second frame, `FilamentWidget` will pass its dimensions/pixel ratio to the `FilamentController`
|
||||
3) You can then call `createViewer` to create:
|
||||
* the rendering surface (on most platforms, a backing texture that will be registered with Flutter for use in a `Texture` widget)
|
||||
* a rendering thread
|
||||
* a `FilamentViewer` and an `SceneManager`, which will allow you to load assets/cameras/lighting/etc via the `FilamentController`
|
||||
4) after an indeterminate number of frames, `FilamentController` will notify `FilamentWidget` when a rendering surface is available the viewport
|
||||
5) `FilamentWidget` will replace the default `initial` Widget with the viewport (which will initially be solid black or white, depending on your platform).
|
||||
|
||||
IMPORTANT: there *will* be a delay between adding a `FilamentWidget`, calling `createViewer` and the actual rendering viewport becoming available. This is why we fill `FilamentWidget` with red - to make it abundantly clear that you need to handle this asynchronous delay appropriately. Once `createViewer` has completed, the viewport is available for rendering.
|
||||
|
||||
> Currently, the `initial` widget will also be displayed whenever the viewport is resized (including changing orientation on mobile and drag-to-resize on desktop). You probably want to change this from the default red.
|
||||
|
||||
Congratulations! You now have a scene. It's completely empty, so you probably want to add something visible.
|
||||
|
||||
### Load a background
|
||||
|
||||
You probably want to set a background for your scene. You can load a skybox:
|
||||
```
|
||||
await _filamentController.loadSkybox("assets/default_env/default_env_skybox.ktx)
|
||||
```
|
||||
|
||||
or a static background image:
|
||||
|
||||
```
|
||||
await _filamentController.setBackgroundImage("assets/background.ktx)
|
||||
```
|
||||
|
||||
or a solid background color:
|
||||
|
||||
```
|
||||
await _filamentController.setBackgroundColor(0.0, 1.0, 0.0, 1.0); // solid green
|
||||
```
|
||||
|
||||
At this point, you might not see any change in the viewport. This is because the FilamentController will only actually render into the viewport once `render` has been called.
|
||||
|
||||
By default, the FilamentController will only render into the viewport by manually calling `render()` on the FilamentController. This is to avoid needlessly running a render loop when there is nothing to display.
|
||||
|
||||
```
|
||||
await _filamentController.render()
|
||||
```
|
||||
|
||||
You should now see your background displayed in the scene. To automatically render at 60fps, call `setRendering`:
|
||||
```
|
||||
await _filamentController.setRendering(true);
|
||||
```
|
||||
|
||||
### Load an asset
|
||||
|
||||
To add a glTF asset to the scene, call `loadGlb()` on `FilamentController` with the Flutter asset path to your .glb file.
|
||||
|
||||
For example, if your `pubspec.yaml` looks like this:
|
||||
```
|
||||
flutter:
|
||||
assets:
|
||||
- assets/models/bob.glb
|
||||
```
|
||||
|
||||
Then you would call the following
|
||||
```
|
||||
var entity = await _filamentController.loadGlb("assets/models/bob.glb");
|
||||
```
|
||||
You can also pass a URI to indicate that the glTF file should be loaded from the filesystem:
|
||||
```
|
||||
var entity = await _filamentController.loadGlb("file:///tmp/bob.glb");
|
||||
```
|
||||
|
||||
The return type `FilamentEntity` is simply an integer handle that be used to manipulate the entity in the scene. For example, to remove the asset:
|
||||
```
|
||||
await _filamentController.removeEntity(entity);
|
||||
entity = null;
|
||||
```
|
||||
> Removing an entity from the scene will invalidate the corresponding `FilamentEntity` handle, so ensure you don't retain any references to it after calling `removeEntity` or `clearEntities`. Removing one `FilamentEntity` does not invalidate/change any other `FilamentEntity` handles; you can continue to safely manipulate these via the `FilamentController`.
|
||||
|
||||
### Lighting
|
||||
|
||||
You should now see your object in the viewport, but since we haven't added a light, this will be solid black.
|
||||
|
||||
Add an image-based light from a KTX file:
|
||||
|
||||
```
|
||||
await _filamentController.loadIbl("assets/default_env/default_env_ibl.ktx");
|
||||
```
|
||||
|
||||
You can also add dynamic lights:
|
||||
|
||||
```
|
||||
var sun = await _filamentController.addLight(
|
||||
```
|
||||
|
||||
### Manipulating entity transforms
|
||||
|
||||
To set the world space position of the asset:
|
||||
```
|
||||
_filamentController.setPositon(entity, 1.0, 1.0, 1.0);
|
||||
```
|
||||
|
||||
On desktop, you can also click any renderable object in the viewport to retrieve its associated FilamentEntity (see below).
|
||||
|
||||
### Camera movement
|
||||
|
||||
To enable mouse/swipe navigation through the scene, wrap the `FilamentWidget` inside a `FilamentGestureDetector`:
|
||||
|
||||
```
|
||||
class MyApp extends StatelessWidget {
|
||||
|
||||
final _filamentController = FilamentControllerFFI();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
color: Colors.white,
|
||||
home: Scaffold(backgroundColor: Colors.white, body: Stack(children:[
|
||||
Positioned.fill(child:FilamentGestureDetector(
|
||||
controller: _filamentController,
|
||||
child:FilamentWidget(
|
||||
controller:_filamentController
|
||||
))),
|
||||
Positioned(right:0, bottom:0, child:Container(color:Colors.purple, height:100, width:100))
|
||||
])));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
On desktop:
|
||||
1) hold the middle mouse button and move the mouse to rotate the camera
|
||||
2) hold the left mouse button and move the mouse to pan the camera
|
||||
3) scroll up/down with the scrollwheel to zoom in/out.
|
||||
|
||||
On mobile:
|
||||
1) swipe with your finger to pan the camera
|
||||
2) double tap the viewport, then swipe with your finger to rotate the camera (double-tap again to return to pan)
|
||||
3) pinch with two fingers in/out to zoom in/out.
|
||||
|
||||
### Changing the active camera
|
||||
|
||||
Every scene has a default camera. Whenever you rotate/pan/zoom the viewport, you are moving the default camera.
|
||||
|
||||
If you have added an entity to the scene that contains one or more camera nodes, you can change the active scene camera to one of those camera nodes.
|
||||
|
||||
```
|
||||
var asset = await _filamentController.loadGlb("assets/some_asset_with_camera.glb");
|
||||
await _filamentController.setCamera(asset, "Camera.002"); // pass the node name to load a specific camera under that entity node
|
||||
await _filamentController.setCamera(asset, null); // pass null to load the first camera found under that entity
|
||||
```
|
||||
|
||||
### Picking entities
|
||||
|
||||
On desktop, left-clicking an object in the viewport will retrieve the FilamentEntity for the top-most renderable instance at that cursor position (if any).
|
||||
|
||||
Note this is an asynchronous operation, so you will need to subscribe to the [pickResult] stream on your [FilamentController] to do something with the result.
|
||||
|
||||
```
|
||||
class MyApp extends StatefulWidget {
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
|
||||
final _filamentController = FilamentControllerFFI();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_filamentController.pickResult.listen((FilamentEntity filamentEntity) async {
|
||||
var entityName = _filamentController.getNameForEntity(filamentEntity);
|
||||
await showDialog(builder:(ctx) {
|
||||
return Container(child:Text("You clicked $entityName"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
color: Colors.white,
|
||||
home: Scaffold(backgroundColor: Colors.white, body: Stack(children:[
|
||||
Positioned.fill(child:FilamentGestureDetector(
|
||||
controller: _filamentController,
|
||||
child:FilamentWidget(
|
||||
controller:_filamentController
|
||||
))),
|
||||
])));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
If you want to work with custom materials, you will need some (basic knowledge of the underlying Filament library)[https://google.github.io/filament/Materials.html#compilingmaterials].
|
||||
|
||||
Things to keep in mind:
|
||||
- You must compile materials with the correct version of Filament (see the table above). Keep in mind that versions may not be identical across platforms so you may need multiple uberz files for multiple platforms.
|
||||
|
||||
e.g. the lit_opaque.uberz file has been created from a Filament build:
|
||||
|
||||
```
|
||||
cd out/cmake-android-release-aarch64/libs/gltfio
|
||||
uberz -TSHADINGMODEL=lit -TBLENDING=opaque -o lit_opaque_43.uberz lit_opaque
|
||||
```
|
||||
|
||||
(note that the number in the filename corresponds to the Material version, not the Filament version. Not every Filament version requires a new Material version).
|
||||
|
||||
## Footguns
|
||||
|
||||
### Stripping in release mode
|
||||
|
||||
If you build your app in release mode, you will need to ensure that "Dead Strip" is set to false.
|
||||
|
||||
This is because we only invoke the library at runtime via FFI, so at link time these symbols are otherwise treated as redundant.
|
||||
|
||||
### Animations when backgrounded
|
||||
|
||||
Don't call playAnimation when the app is in the background (i.e inactive/hidden). This will queue, but not start, an animation, and eventually this will overflow the command buffer when the app is foregrounded/resumed.
|
||||
|
||||
If you have some kind of looping animation in your app code, make sure it pauses while the app is backgrounded.
|
||||
|
||||
|
||||
|
||||
## Versioning
|
||||
|
||||
||Android|iOS|MacOS|Windows|Linux|WebGL|
|
||||
|---|---|---|---|---|---||
|
||||
|Filament|v1.43.1 (arm64/armeabi-v7a/x86/x86_64)|v1.43.1* (arm64)|v1.43.1 (arm64)|v1.32.4 (x86_64)|TODO**|TODO***|
|
||||
|Flutter||3.15.0-15.2.pre|3.15.0-15.2.pre|3.15.0-15.2.pre
|
||||
|
||||
* iOS release build has a skybox bug so the debug versions are currently shipped on iOS
|
||||
** (Waiting for https://github.com/google/filament/issues/7078 to be resolved before upgrading, not sure exactly when the bug was introduced but it was somewhere between v1.32.4 and v1.40.0)
|
||||
*** Texture widget not currently supported on web in Flutter.
|
||||
|
||||
|
||||
## Testing
|
||||
|
||||
We automate testing by running the example project on actual iOS/Android/MacOS/Windows devices and executing various operations.
|
||||
|
||||
Eventually we want to compare screenshots after each operation to a set of goldens for every platform.
|
||||
|
||||
Currently this is only possible on iOS (see https://github.com/flutter/flutter/issues/123063 and https://github.com/flutter/flutter/issues/127306).
|
||||
|
||||
To re-generate the golden screenshots for a given device:
|
||||
|
||||
```
|
||||
./regenerate_goldens.sh <your_device_id>
|
||||
```
|
||||
To run the tests and compare against those goldens:
|
||||
```
|
||||
./compare_goldens.sh <your_device_id>
|
||||
```
|
||||
|
||||
The results will depend on the actual device used to generate the golden, therefore if you are using a different device (which is likely), your results may not be the same. This is expected.
|
||||
|
||||
# Building Filament from source
|
||||
|
||||
```
|
||||
git clone git@github.com:nmfisher/filament.git && cd filament
|
||||
```
|
||||
|
||||
## Android/iOS/MacOS
|
||||
|
||||
```
|
||||
git checkout flutter-filament-ios-android-macos
|
||||
./build.sh -p <platform> release
|
||||
```
|
||||
|
||||
## Windows
|
||||
|
||||
To support embedding GPU textures in Flutter (rather than copying to a CPU pixel buffer on every frame), we need to build a slightly customized version of Filament that uses GLES on Windows (rather than the default, which uses OpenGL).
|
||||
|
||||
Separately, we also force the Filament gltfio library to load assets via in-memory buffers, rather than the filesystem. This is simply a convenience so we don't have to use different logic for gltf resource loading across platforms.
|
||||
|
||||
```
|
||||
git checkout flutter-filament-windows
|
||||
mkdir out && cd out
|
||||
"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build . --target gltf_viewer --config Debug
|
||||
```
|
||||
|
||||
Building notes:
|
||||
On Android/iOS, we remove -fno-exceptions from CMakeLists.txt
|
||||
|
||||
Project structure:
|
||||
- most shared code/headers under ios/src (because I still can't get podspec to build a target with symlinks or relative paths)
|
||||
- building on MacOS, we currently just delete the macos/include and macos/src directories and copy from iOS (for same reason),
|
||||
e.g.
|
||||
|
||||
```
|
||||
make sync-macos
|
||||
```
|
||||
|
||||
- Note also need to specifically build imageio/png/tinyexr
|
||||
- if release build, then need to comment out -fno-exceptions
|
||||
|
||||
# Linux specific
|
||||
|
||||
(Fedora 34)
|
||||
Building Filament:
|
||||
env LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/11/ CC=clang CXX=clang++ CXX_FLAGS="-v" LD_FLAGS="-v" FILAMENT_REQUIRES_CXXABI=true ./build.sh -c release
|
||||
|
||||
Running example project:
|
||||
export PKG_CONFIG_PATH=/usr/lib/pkgconfig/:/usr/lib64/pkgconfig/ CPLUS_INCLUDE_PATH=/usr/include/gtk-3.0/:/usr/include/pango-1.0/:/usr/include/harfbuzz:/usr/include/cairo/:/usr/include/gdk-pixbuf-2.0/:/usr/include/atk-1.0/
|
||||
|
||||
Web:
|
||||
|
||||
EMCC_CFLAGS="-Wno-missing-field-initializers -Wno-deprecated-literal-operator -fPIC" ./build.sh -c -p webgl -i debug
|
||||
|
||||
EMCC_CFLAGS="-I/Users/nickfisher/Documents/filament/libs/utils/include -I/Users/nickfisher/Documents/filament/libs/image/include -I/Users/nickfisher/Documents/filament/libs/math/include -I../../..//third_party/basisu/encoder/ -I../../..//third_party/libpng/ -I../../..//third_party/tinyexr/ -fPIC" emmake make
|
||||
|
||||
|
||||
## Materials
|
||||
|
||||
We use a single material (no lighting and no transparency) for background images:
|
||||
|
||||
```
|
||||
make generate-background-material
|
||||
```
|
||||
|
||||
# Known issues
|
||||
|
||||
## Windows
|
||||
|
||||
Loading a glTF (but NOT a glb) may crash due to a race condition between uploading resource data to GPU memory and being freed on the host side. This has been fixed in recent versions of Filament, but other bugs on Windows prevent upgrading. Only workaround is to load a .glb file.
|
||||
|
||||
## Android
|
||||
In release mode, you must add the following to your `app/build.gradle`:
|
||||
|
||||
```
|
||||
buildTypes {
|
||||
release {
|
||||
...
|
||||
shrinkResources false
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
...
|
||||
dependencies {
|
||||
....
|
||||
implementation 'net.java.dev.jna:jna:5.10.0@aar'
|
||||
}
|
||||
```
|
||||
|
||||
# Thanks
|
||||
|
||||
- https://github.com/alexmercerind/flutter-windows-ANGLE-OpenGL-ES
|
||||
3
dart_filament/example_cli/.gitignore
vendored
Normal file
3
dart_filament/example_cli/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# https://dart.dev/guides/libraries/private-files
|
||||
# Created by `dart pub`
|
||||
.dart_tool/
|
||||
3
dart_filament/example_cli/CHANGELOG.md
Normal file
3
dart_filament/example_cli/CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version.
|
||||
2
dart_filament/example_cli/README.md
Normal file
2
dart_filament/example_cli/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
A sample command-line application with an entrypoint in `bin/`, library code
|
||||
in `lib/`, and example unit test in `test/`.
|
||||
30
dart_filament/example_cli/analysis_options.yaml
Normal file
30
dart_filament/example_cli/analysis_options.yaml
Normal file
@@ -0,0 +1,30 @@
|
||||
# This file configures the static analysis results for your project (errors,
|
||||
# warnings, and lints).
|
||||
#
|
||||
# This enables the 'recommended' set of lints from `package:lints`.
|
||||
# This set helps identify many issues that may lead to problems when running
|
||||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
|
||||
# style and format.
|
||||
#
|
||||
# If you want a smaller set of lints you can change this to specify
|
||||
# 'package:lints/core.yaml'. These are just the most critical lints
|
||||
# (the recommended set includes the core lints).
|
||||
# The core lints are also what is used by pub.dev for scoring packages.
|
||||
|
||||
include: package:lints/recommended.yaml
|
||||
|
||||
# Uncomment the following section to specify additional rules.
|
||||
|
||||
# linter:
|
||||
# rules:
|
||||
# - camel_case_types
|
||||
|
||||
# analyzer:
|
||||
# exclude:
|
||||
# - path/to/excluded/files/**
|
||||
|
||||
# For more information about the core and recommended set of lints, see
|
||||
# https://dart.dev/go/core-lints
|
||||
|
||||
# For additional information about configuring this file, see
|
||||
# https://dart.dev/guides/language/analysis-options
|
||||
42
dart_filament/example_cli/bin/example_cli.dart
Normal file
42
dart_filament/example_cli/bin/example_cli.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:dart_filament/dart_filament/swift/swift_bindings.g.dart';
|
||||
import 'package:dart_filament/dart_filament/utils/dart_resources.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:dart_filament/dart_filament.dart';
|
||||
import 'package:dart_filament/dart_filament/dart_filament.g.dart';
|
||||
|
||||
void main() async {
|
||||
var testDir = File(Platform.script.toFilePath()).parent.path;
|
||||
final lib = DartFilamentTexture1(DynamicLibrary.open(
|
||||
'../native/lib/macos/swift/libdartfilamenttexture.dylib'));
|
||||
final object = DartFilamentTexture.new1(lib);
|
||||
object.initWithWidth_height_(500, 500);
|
||||
|
||||
final resourceLoader = calloc<ResourceLoaderWrapper>(1);
|
||||
var loadToOut = NativeCallable<
|
||||
Void Function(Pointer<Char>,
|
||||
Pointer<ResourceBuffer>)>.listener(DartResourceLoader.loadResource);
|
||||
|
||||
resourceLoader.ref.loadToOut = loadToOut.nativeFunction;
|
||||
var freeResource = NativeCallable<Void Function(ResourceBuffer)>.listener(
|
||||
DartResourceLoader.freeResource);
|
||||
resourceLoader.ref.freeResource = freeResource.nativeFunction;
|
||||
|
||||
var viewer = FilamentViewer(resourceLoader: resourceLoader);
|
||||
|
||||
await viewer.initialized;
|
||||
await viewer.createSwapChain(500, 500);
|
||||
await viewer.createRenderTarget(500, 500, object.metalTextureAddress);
|
||||
await viewer.updateViewportAndCameraProjection(500, 500);
|
||||
|
||||
var outDir = Directory("$testDir/skybox");
|
||||
outDir.createSync();
|
||||
await viewer.setRecordingOutputDirectory(outDir.path);
|
||||
await viewer.setRecording(true);
|
||||
await viewer.loadSkybox(
|
||||
"file:///$testDir/../../../flutter_filament/example/assets/default_env/default_env_skybox.ktx");
|
||||
await Future.delayed(Duration(milliseconds: 16));
|
||||
await viewer.render();
|
||||
await viewer.dispose();
|
||||
}
|
||||
BIN
dart_filament/example_cli/bin/output_000000.png
Normal file
BIN
dart_filament/example_cli/bin/output_000000.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
BIN
dart_filament/example_cli/bin/skybox/output_000008.png
Normal file
BIN
dart_filament/example_cli/bin/skybox/output_000008.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
484
dart_filament/example_cli/pubspec.lock
Normal file
484
dart_filament/example_cli/pubspec.lock
Normal file
@@ -0,0 +1,484 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
_fe_analyzer_shared:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: _fe_analyzer_shared
|
||||
sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "67.0.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.4.1"
|
||||
animation_tools_dart:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: animation_tools_dart
|
||||
sha256: c4bc4096d43227b573345a3ea3cb26c3af47a70af31cd7d7d3a5b7c99e33d615
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.0.2"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.11.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: boolean_selector
|
||||
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
cli_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: cli_config
|
||||
sha256: ac20a183a07002b700f0c25e61b7ee46b23c309d76ab7b7640a028f18e4d99ec
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
cli_util:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: cli_util
|
||||
sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.1"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.18.0"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: convert
|
||||
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
coverage:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: coverage
|
||||
sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.7.2"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: crypto
|
||||
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.3"
|
||||
dart_filament:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.5.0"
|
||||
ffi:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: ffi
|
||||
sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
ffigen:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: ffigen
|
||||
sha256: dead012f29db2be71ea152458f5eab600de98fbc244e01088ae6bf2616bceca7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "11.0.0"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: file
|
||||
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.0.0"
|
||||
frontend_server_client:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: frontend_server_client
|
||||
sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: glob
|
||||
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_multi_server
|
||||
sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.1"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.2"
|
||||
io:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: io
|
||||
sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.1"
|
||||
lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: lints
|
||||
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logging
|
||||
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.16+1"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "25dfcaf170a0190f47ca6355bdd4552cb8924b430512ff0cafb8db9bd41fe33b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.14.0"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: mime
|
||||
sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.5"
|
||||
native_assets_cli:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: native_assets_cli
|
||||
sha256: "9c1b67ccf85ec9282f34e5348ae78dcb7da2c7dc965c0265306477d977853a0d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.4"
|
||||
native_toolchain_c:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: native_toolchain_c
|
||||
sha256: "1b1b86f47570378d0003f0d949fbb03b637ec9d2dcbcf698a16f7cbffb3a945c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.1"
|
||||
node_preamble:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: node_preamble
|
||||
sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: package_config
|
||||
sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path
|
||||
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.0"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: plugin_platform_interface
|
||||
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.8"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pool
|
||||
sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.5.1"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pub_semver
|
||||
sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
quiver:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: quiver
|
||||
sha256: b1c1ac5ce6688d77f65f3375a9abb9319b3cb32486bdc7a1e0fdf004d7ba4e47
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.1"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf
|
||||
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
shelf_packages_handler:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_packages_handler
|
||||
sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
shelf_static:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_static
|
||||
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
shelf_web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_web_socket
|
||||
sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
source_map_stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_map_stack_trace
|
||||
sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
source_maps:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_maps
|
||||
sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.10.12"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.10.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.11.1"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: string_scanner
|
||||
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: term_glyph
|
||||
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
test:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: test
|
||||
sha256: d72b538180efcf8413cd2e4e6fcc7ae99c7712e0909eb9223f9da6e6d0ef715f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.25.4"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "2419f20b0c8677b2d67c8ac4d1ac7372d862dc6c460cdbb052b40155408cd794"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.1"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
sha256: "4d070a6bc36c1c4e89f20d353bfd71dc30cdf2bd0e14349090af360a029ab292"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.2"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: tuple
|
||||
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.2"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "14.2.1"
|
||||
watcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: watcher
|
||||
sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
web_socket_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web_socket_channel
|
||||
sha256: "58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.5"
|
||||
webkit_inspection_protocol:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: webkit_inspection_protocol
|
||||
sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: yaml
|
||||
sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
yaml_edit:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: yaml_edit
|
||||
sha256: c566f4f804215d84a7a2c377667f546c6033d5b34b4f9e60dfb09d17c4e97826
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
sdks:
|
||||
dart: ">=3.5.0-76.0.dev <4.0.0"
|
||||
20
dart_filament/example_cli/pubspec.yaml
Normal file
20
dart_filament/example_cli/pubspec.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
name: example_cli
|
||||
description: A sample command-line application.
|
||||
version: 1.0.0
|
||||
# repository: https://github.com/my_org/my_repo
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.0-76.0.dev
|
||||
|
||||
# Add regular dependencies here.
|
||||
dependencies:
|
||||
dart_filament:
|
||||
path: ../
|
||||
ffi:
|
||||
|
||||
dev_dependencies:
|
||||
ffigen: ^11.0.0
|
||||
lints: ^3.0.0
|
||||
test: ^1.24.0
|
||||
native_assets_cli: ^0.5.0
|
||||
native_toolchain_c: ^0.4.0
|
||||
8
dart_filament/example_cli/test/example_cli_test.dart
Normal file
8
dart_filament/example_cli/test/example_cli_test.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'package:example_cli/example_cli.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('calculate', () {
|
||||
expect(calculate(), 42);
|
||||
});
|
||||
}
|
||||
93
dart_filament/hook/build.dart
Normal file
93
dart_filament/hook/build.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
import 'package:native_toolchain_c/native_toolchain_c.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
await build(args, (config, output) async {
|
||||
var platform = config.targetOS.toString().toLowerCase();
|
||||
var libDir = "${config.packageRoot.toFilePath()}/native/lib/$platform/";
|
||||
|
||||
final packageName = config.packageName;
|
||||
|
||||
final sources = Directory("${config.packageRoot.toFilePath()}/native/src")
|
||||
.listSync(recursive: true)
|
||||
.whereType<File>()
|
||||
.map((f) => f.path)
|
||||
.toList();
|
||||
sources.addAll([
|
||||
"${config.packageRoot.toFilePath()}/native/include/material/gizmo.c",
|
||||
"${config.packageRoot.toFilePath()}/native/include/material/image.c",
|
||||
]);
|
||||
|
||||
final cbuilder = CBuilder.library(
|
||||
name: packageName,
|
||||
language: Language.cpp,
|
||||
assetName: 'dart_filament.dart',
|
||||
sources: sources,
|
||||
includes: ['native/include', 'native/include/filament'],
|
||||
flags: [
|
||||
'-mmacosx-version-min=13.0',
|
||||
'-std=c++17',
|
||||
'-framework',
|
||||
'Foundation',
|
||||
'-framework',
|
||||
'CoreVideo',
|
||||
'-framework',
|
||||
'Cocoa',
|
||||
'-framework',
|
||||
'Metal',
|
||||
"-lfilament",
|
||||
"-lbackend",
|
||||
"-lfilameshio",
|
||||
"-lviewer",
|
||||
"-lfilamat",
|
||||
"-lgeometry",
|
||||
"-lutils",
|
||||
"-lfilabridge",
|
||||
"-lgltfio_core",
|
||||
"-lfilament-iblprefilter",
|
||||
"-limage",
|
||||
"-limageio",
|
||||
"-ltinyexr",
|
||||
"-lgltfio_core",
|
||||
"-lfilaflat",
|
||||
"-ldracodec",
|
||||
"-libl",
|
||||
"-lktxreader",
|
||||
"-lpng",
|
||||
"-lz",
|
||||
"-lstb",
|
||||
"-luberzlib",
|
||||
"-lsmol-v",
|
||||
"-luberarchive",
|
||||
"-lzstd",
|
||||
"-lstdc++",
|
||||
"-lbluegl",
|
||||
"-lbluevk",
|
||||
"-lbasis_transcoder",
|
||||
"-L$libDir",
|
||||
"-force_load",
|
||||
"$libDir/libbackend.a",
|
||||
"-force_load",
|
||||
"$libDir/libktxreader.a",
|
||||
"-force_load",
|
||||
"$libDir/libvkshaders.a",
|
||||
],
|
||||
dartBuildFiles: ['hook/build.dart'],
|
||||
);
|
||||
|
||||
await cbuilder.run(
|
||||
buildConfig: config,
|
||||
buildOutput: output,
|
||||
logger: Logger('')
|
||||
..level = Level.ALL
|
||||
..onRecord.listen((record) => print(record.message)),
|
||||
);
|
||||
});
|
||||
}
|
||||
7
dart_filament/lib/dart_filament.dart
Normal file
7
dart_filament/lib/dart_filament.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
library filament_dart;
|
||||
|
||||
export 'dart_filament/abstract_filament_viewer.dart';
|
||||
export 'dart_filament/filament_viewer_impl.dart';
|
||||
export 'dart_filament/dart_filament.g.dart';
|
||||
|
||||
export 'dart_filament/entities/entity_transform_controller.dart';
|
||||
649
dart_filament/lib/dart_filament/abstract_filament_viewer.dart
Normal file
649
dart_filament/lib/dart_filament/abstract_filament_viewer.dart
Normal file
@@ -0,0 +1,649 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
|
||||
import 'package:dart_filament/dart_filament/entities/gizmo.dart';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
typedef RenderCallback = Pointer<NativeFunction<Void Function(Pointer<Void>)>>;
|
||||
|
||||
// "picking" means clicking/tapping on the viewport, and unprojecting the X/Y coordinate to determine whether any renderable entities were present at those coordinates.
|
||||
typedef FilamentPickResult = ({FilamentEntity entity, double x, double y});
|
||||
|
||||
// copied from filament/backened/DriverEnums.h
|
||||
enum PrimitiveType {
|
||||
// don't change the enums values (made to match GL)
|
||||
POINTS, //!< points
|
||||
LINES, //!< lines
|
||||
UNUSED1,
|
||||
LINE_STRIP, //!< line strip
|
||||
TRIANGLES, //!< triangles
|
||||
TRIANGLE_STRIP, //!< triangle strip
|
||||
}
|
||||
|
||||
enum ToneMapper { ACES, FILMIC, LINEAR }
|
||||
|
||||
// see filament Manipulator.h for more details
|
||||
enum ManipulatorMode { ORBIT, MAP, FREE_FLIGHT }
|
||||
|
||||
class TextureDetails {
|
||||
final int textureId;
|
||||
|
||||
// both width and height are in physical, not logical pixels
|
||||
final int width;
|
||||
final int height;
|
||||
|
||||
TextureDetails(
|
||||
{required this.textureId, required this.width, required this.height});
|
||||
}
|
||||
|
||||
abstract class AbstractFilamentViewer {
|
||||
///
|
||||
/// The result(s) of calling [pick] (see below).
|
||||
/// This may be a broadcast stream, so you should ensure you have subscribed to this stream before calling [pick].
|
||||
/// If [pick] is called without an active subscription to this stream, the results will be silently discarded.
|
||||
///
|
||||
Stream<FilamentPickResult> get pickResult;
|
||||
|
||||
///
|
||||
/// Whether the controller is currently rendering at [framerate].
|
||||
///
|
||||
bool get rendering;
|
||||
|
||||
///
|
||||
/// Set to true to continuously render the scene at the framerate specified by [setFrameRate] (60 fps by default).
|
||||
///
|
||||
Future setRendering(bool render);
|
||||
|
||||
///
|
||||
/// Render a single frame.
|
||||
///
|
||||
Future render();
|
||||
|
||||
///
|
||||
/// Sets the framerate for continuous rendering when [setRendering] is enabled.
|
||||
///
|
||||
Future setFrameRate(int framerate);
|
||||
|
||||
///
|
||||
/// Destroys/disposes the viewer (including the entire scene). You cannot use the viewer after calling this method.
|
||||
///
|
||||
Future dispose();
|
||||
|
||||
///
|
||||
/// Set the background image to [path] (which should have a file extension .png, .jpg, or .ktx).
|
||||
/// This will be rendered at the maximum depth (i.e. behind all other objects including the skybox).
|
||||
/// If [fillHeight] is false, the image will be rendered at its original size. Note this may cause issues with pixel density so be sure to specify the correct resolution
|
||||
/// If [fillHeight] is true, the image will be stretched/compressed to fit the height of the viewport.
|
||||
///
|
||||
Future setBackgroundImage(String path, {bool fillHeight = false});
|
||||
|
||||
///
|
||||
/// Moves the background image to the relative offset from the origin (bottom-left) specified by [x] and [y].
|
||||
/// If [clamp] is true, the image cannot be positioned outside the bounds of the viewport.
|
||||
///
|
||||
Future setBackgroundImagePosition(double x, double y, {bool clamp = false});
|
||||
|
||||
///
|
||||
/// Removes the background image.
|
||||
///
|
||||
Future clearBackgroundImage();
|
||||
|
||||
///
|
||||
/// Sets the color for the background plane (positioned at the maximum depth, i.e. behind all other objects including the skybox).
|
||||
///
|
||||
Future setBackgroundColor(double r, double g, double b, double alpha);
|
||||
|
||||
///
|
||||
/// Load a skybox from [skyboxPath] (which must be a .ktx file)
|
||||
///
|
||||
Future loadSkybox(String skyboxPath);
|
||||
|
||||
///
|
||||
/// Removes the skybox from the scene.
|
||||
///
|
||||
Future removeSkybox();
|
||||
|
||||
///
|
||||
/// Loads an image-based light from the specified path at the given intensity.
|
||||
/// Only one IBL can be active at any given time; if an IBL has already been loaded, it will be replaced.
|
||||
///
|
||||
Future loadIbl(String lightingPath, {double intensity = 30000});
|
||||
|
||||
///
|
||||
/// Rotates the IBL & skybox.
|
||||
///
|
||||
Future rotateIbl(Matrix3 rotation);
|
||||
|
||||
///
|
||||
/// Removes the image-based light from the scene.
|
||||
///
|
||||
Future removeIbl();
|
||||
|
||||
///
|
||||
/// Adds a dynamic light to the scene.
|
||||
/// copied from filament LightManager.h
|
||||
/// enum class Type : uint8_t {
|
||||
/// SUN, //!< Directional light that also draws a sun's disk in the sky.
|
||||
/// DIRECTIONAL, //!< Directional light, emits light in a given direction.
|
||||
/// POINT, //!< Point light, emits light from a position, in all directions.
|
||||
/// FOCUSED_SPOT, //!< Physically correct spot light.
|
||||
/// SPOT, //!< Spot light with coupling of outer cone and illumination disabled.
|
||||
/// };
|
||||
Future<FilamentEntity> addLight(
|
||||
int type,
|
||||
double colour,
|
||||
double intensity,
|
||||
double posX,
|
||||
double posY,
|
||||
double posZ,
|
||||
double dirX,
|
||||
double dirY,
|
||||
double dirZ,
|
||||
bool castShadows);
|
||||
|
||||
Future removeLight(FilamentEntity light);
|
||||
|
||||
///
|
||||
/// Remove all lights (excluding IBL) from the scene.
|
||||
///
|
||||
Future clearLights();
|
||||
|
||||
///
|
||||
/// Load the .glb asset at the given path and insert into the scene.
|
||||
///
|
||||
Future<FilamentEntity> loadGlb(String path, {int numInstances = 1});
|
||||
|
||||
///
|
||||
/// Create a new instance of [entity].
|
||||
///
|
||||
Future<FilamentEntity> createInstance(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Returns the number of instances of the asset associated with [entity].
|
||||
///
|
||||
Future<int> getInstanceCount(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Returns all instances of [entity].
|
||||
///
|
||||
Future<List<FilamentEntity>> getInstances(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Load the .gltf asset at the given path and insert into the scene.
|
||||
/// [relativeResourcePath] is the folder path where the glTF resources are stored;
|
||||
/// this is usually the parent directory of the .gltf file itself.
|
||||
///
|
||||
Future<FilamentEntity> loadGltf(String path, String relativeResourcePath,
|
||||
{bool force = false});
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future panStart(double x, double y);
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future panUpdate(double x, double y);
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future panEnd();
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future rotateStart(double x, double y);
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future rotateUpdate(double x, double y);
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future rotateEnd();
|
||||
|
||||
///
|
||||
/// Set the weights for all morph targets in [entity] to [weights].
|
||||
/// Note that [weights] must contain values for ALL morph targets, but no exception will be thrown if you don't do so (you'll just get incorrect results).
|
||||
/// If you only want to set one value, set all others to zero (check [getMorphTargetNames] if you need the get a list of all morph targets).
|
||||
/// IMPORTANT - this accepts the actual FilamentEntity with the relevant morph targets (unlike [getMorphTargetNames], which uses the parent entity and the child mesh name).
|
||||
/// Use [getChildEntityByName] if you are setting the weights for a child mesh.
|
||||
///
|
||||
Future setMorphTargetWeights(FilamentEntity entity, List<double> weights);
|
||||
|
||||
///
|
||||
/// Gets the names of all morph targets for the mesh [meshName] under [entity].
|
||||
///
|
||||
Future<List<String>> getMorphTargetNames(
|
||||
FilamentEntity entity, String meshName);
|
||||
|
||||
Future<List<String>> getAnimationNames(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Returns the length (in seconds) of the animation at the given index.
|
||||
///
|
||||
Future<double> getAnimationDuration(
|
||||
FilamentEntity entity, int animationIndex);
|
||||
|
||||
///
|
||||
/// Animate the morph targets in [entity]. See [MorphTargetAnimation] for an explanation as to how to construct the animation frame data.
|
||||
/// This method will check the morph target names specified in [animation] against the morph target names that actually exist exist under [meshName] in [entity],
|
||||
/// throwing an exception if any cannot be found.
|
||||
/// It is permissible for [animation] to omit any targets that do exist under [meshName]; these simply won't be animated.
|
||||
///
|
||||
Future setMorphAnimationData(
|
||||
FilamentEntity entity, MorphAnimationData animation,
|
||||
{List<String>? targetMeshNames});
|
||||
|
||||
///
|
||||
/// Resets all bones in the given entity to their rest pose.
|
||||
/// This should be done before every call to addBoneAnimation.
|
||||
///
|
||||
Future resetBones(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Transforms the bone(s)/joint(s) according [animation].
|
||||
/// To set the instantaneous transform, just use a single frame.
|
||||
///
|
||||
Future addBoneAnimation(FilamentEntity entity, BoneAnimationData animation);
|
||||
|
||||
///
|
||||
/// Removes/destroys the specified entity from the scene.
|
||||
/// [entity] will no longer be a valid handle after this method is called; ensure you immediately discard all references once this method is complete.
|
||||
///
|
||||
Future removeEntity(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Removes/destroys all renderable entities from the scene (including cameras).
|
||||
/// All [FilamentEntity] handles will no longer be valid after this method is called; ensure you immediately discard all references to all entities once this method is complete.
|
||||
///
|
||||
Future clearEntities();
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future zoomBegin();
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future zoomUpdate(double x, double y, double z);
|
||||
|
||||
///
|
||||
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
|
||||
///
|
||||
Future zoomEnd();
|
||||
|
||||
///
|
||||
/// Schedules the glTF animation at [index] in [entity] to start playing on the next frame.
|
||||
///
|
||||
Future playAnimation(FilamentEntity entity, int index,
|
||||
{bool loop = false,
|
||||
bool reverse = false,
|
||||
bool replaceActive = true,
|
||||
double crossfade = 0.0});
|
||||
|
||||
///
|
||||
/// Schedules the glTF animation at [index] in [entity] to start playing on the next frame.
|
||||
///
|
||||
Future playAnimationByName(FilamentEntity entity, String name,
|
||||
{bool loop = false,
|
||||
bool reverse = false,
|
||||
bool replaceActive = true,
|
||||
double crossfade = 0.0});
|
||||
|
||||
Future setAnimationFrame(
|
||||
FilamentEntity entity, int index, int animationFrame);
|
||||
|
||||
Future stopAnimation(FilamentEntity entity, int animationIndex);
|
||||
Future stopAnimationByName(FilamentEntity entity, String name);
|
||||
|
||||
///
|
||||
/// Sets the current scene camera to the glTF camera under [name] in [entity].
|
||||
///
|
||||
Future setCamera(FilamentEntity entity, String? name);
|
||||
|
||||
///
|
||||
/// Sets the current scene camera to the main camera (which is always available and added to every scene by default).
|
||||
///
|
||||
Future setMainCamera();
|
||||
|
||||
///
|
||||
/// Returns the entity associated with the main camera.
|
||||
///
|
||||
Future<FilamentEntity> getMainCamera();
|
||||
|
||||
///
|
||||
/// Sets the current scene camera to the glTF camera under [name] in [entity].
|
||||
///
|
||||
Future setCameraFov(double degrees, double width, double height);
|
||||
|
||||
///
|
||||
/// Sets the tone mapping (requires postprocessing).
|
||||
///
|
||||
Future setToneMapping(ToneMapper mapper);
|
||||
|
||||
///
|
||||
/// Sets the strength of the bloom.
|
||||
///
|
||||
Future setBloom(double bloom);
|
||||
|
||||
///
|
||||
/// Sets the focal length of the camera. Default value is 28.0.
|
||||
///
|
||||
Future setCameraFocalLength(double focalLength);
|
||||
|
||||
///
|
||||
/// Sets the distance (in world units) to the near/far planes for the active camera. Default values are 0.05/1000.0. See Camera.h for details.
|
||||
///
|
||||
Future setCameraCulling(double near, double far);
|
||||
|
||||
///
|
||||
/// Get the distance (in world units) to the near culling plane for the active camera.
|
||||
///
|
||||
Future<double> getCameraCullingNear();
|
||||
|
||||
///
|
||||
/// Get the distance (in world units) to the far culling plane for the active camera.
|
||||
///
|
||||
Future<double> getCameraCullingFar();
|
||||
|
||||
///
|
||||
/// Sets the focus distance for the camera.
|
||||
///
|
||||
Future setCameraFocusDistance(double focusDistance);
|
||||
|
||||
///
|
||||
/// Get the camera position in world space.
|
||||
///
|
||||
Future<Vector3> getCameraPosition();
|
||||
|
||||
///
|
||||
/// Get the camera's model matrix.
|
||||
///
|
||||
Future<Matrix4> getCameraModelMatrix();
|
||||
|
||||
///
|
||||
/// Get the camera's view matrix. See Camera.h for more details.
|
||||
///
|
||||
Future<Matrix4> getCameraViewMatrix();
|
||||
|
||||
///
|
||||
/// Get the camera's projection matrix. See Camera.h for more details.
|
||||
///
|
||||
Future<Matrix4> getCameraProjectionMatrix();
|
||||
|
||||
///
|
||||
/// Get the camera's culling projection matrix. See Camera.h for more details.
|
||||
///
|
||||
Future<Matrix4> getCameraCullingProjectionMatrix();
|
||||
|
||||
///
|
||||
/// Get the camera's culling frustum in world space. Returns a (vector_math) [Frustum] instance where plane0-plane6 define the left, right, bottom, top, far and near planes respectively.
|
||||
/// See Camera.h and (filament) Frustum.h for more details.
|
||||
///
|
||||
Future<Frustum> getCameraFrustum();
|
||||
|
||||
///
|
||||
/// Set the camera position in world space. Note this is not persistent - any viewport navigation will reset the camera transform.
|
||||
///
|
||||
Future setCameraPosition(double x, double y, double z);
|
||||
|
||||
///
|
||||
/// Get the camera rotation matrix.
|
||||
///
|
||||
Future<Matrix3> getCameraRotation();
|
||||
|
||||
///
|
||||
/// Repositions the camera to the last vertex of the bounding box of [entity], looking at the penultimate vertex.
|
||||
///
|
||||
Future moveCameraToAsset(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Enables/disables frustum culling. Currently we don't expose a method for manipulating the camera projection/culling matrices so this is your only option to deal with unwanted near/far clipping.
|
||||
///
|
||||
Future setViewFrustumCulling(bool enabled);
|
||||
|
||||
///
|
||||
/// Sets the camera exposure.
|
||||
///
|
||||
Future setCameraExposure(
|
||||
double aperture, double shutterSpeed, double sensitivity);
|
||||
|
||||
///
|
||||
/// Rotate the camera by [rads] around the given axis. Note this is not persistent - any viewport navigation will reset the camera transform.
|
||||
///
|
||||
Future setCameraRotation(Quaternion quaternion);
|
||||
|
||||
///
|
||||
/// Sets the camera model matrix.
|
||||
///
|
||||
Future setCameraModelMatrix(List<double> matrix);
|
||||
|
||||
///
|
||||
/// Sets the `baseColorFactor` property for the material at index [materialIndex] in [entity] under node [meshName] to [color].
|
||||
///
|
||||
Future setMaterialColor(FilamentEntity entity, String meshName,
|
||||
int materialIndex, double r, double g, double b, double a);
|
||||
|
||||
///
|
||||
/// Scale [entity] to fit within the unit cube.
|
||||
///
|
||||
Future transformToUnitCube(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Directly sets the world space position for [entity] to the given coordinates, skipping all collision detection.
|
||||
///
|
||||
Future setPosition(FilamentEntity entity, double x, double y, double z);
|
||||
|
||||
///
|
||||
/// Directly sets the scale for [entity], skipping all collision detection.
|
||||
///
|
||||
Future setScale(FilamentEntity entity, double scale);
|
||||
|
||||
///
|
||||
/// Directly sets the rotation for [entity] to [rads] around the axis {x,y,z}, skipping all collision detection.
|
||||
///
|
||||
Future setRotation(
|
||||
FilamentEntity entity, double rads, double x, double y, double z);
|
||||
|
||||
///
|
||||
/// Queues an update to the worldspace position for [entity] to {x,y,z}.
|
||||
/// The actual update will occur on the next frame, and will be subject to collision detection.
|
||||
///
|
||||
Future queuePositionUpdate(
|
||||
FilamentEntity entity, double x, double y, double z,
|
||||
{bool relative = false});
|
||||
|
||||
///
|
||||
/// Queues an update to the worldspace rotation for [entity].
|
||||
/// The actual update will occur on the next frame, and will be subject to collision detection.
|
||||
///
|
||||
Future queueRotationUpdate(
|
||||
FilamentEntity entity, double rads, double x, double y, double z,
|
||||
{bool relative = false});
|
||||
|
||||
///
|
||||
/// Same as [queueRotationUpdate].
|
||||
///
|
||||
Future queueRotationUpdateQuat(FilamentEntity entity, Quaternion quat,
|
||||
{bool relative = false});
|
||||
|
||||
///
|
||||
/// Enable/disable postprocessing.
|
||||
///
|
||||
Future setPostProcessing(bool enabled);
|
||||
|
||||
///
|
||||
/// Set antialiasing options.
|
||||
///
|
||||
Future setAntiAliasing(bool msaa, bool fxaa, bool taa);
|
||||
|
||||
///
|
||||
/// Sets the rotation for [entity] to the specified quaternion.
|
||||
///
|
||||
Future setRotationQuat(FilamentEntity entity, Quaternion rotation);
|
||||
|
||||
///
|
||||
/// Reveal the node [meshName] under [entity]. Only applicable if [hide] had previously been called; this is a no-op otherwise.
|
||||
///
|
||||
Future reveal(FilamentEntity entity, String? meshName);
|
||||
|
||||
///
|
||||
/// If [meshName] is provided, hide the node [meshName] under [entity], otherwise hide the root node for [entity].
|
||||
/// The entity still exists in memory, but is no longer being rendered into the scene. Call [reveal] to re-commence rendering.
|
||||
///
|
||||
Future hide(FilamentEntity entity, String? meshName);
|
||||
|
||||
///
|
||||
/// Used to select the entity in the scene at the given viewport coordinates.
|
||||
/// Called by `FilamentGestureDetector` on a mouse/finger down event. You probably don't want to call this yourself.
|
||||
/// This is asynchronous and will require 2-3 frames to complete - subscribe to the [pickResult] stream to receive the results of this method.
|
||||
/// [x] and [y] must be in local logical coordinates (i.e. where 0,0 is at top-left of the FilamentWidget).
|
||||
///
|
||||
void pick(int x, int y);
|
||||
|
||||
///
|
||||
/// Retrieves the name assigned to the given FilamentEntity (usually corresponds to the glTF mesh name).
|
||||
///
|
||||
String? getNameForEntity(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Sets the options for manipulating the camera via the viewport.
|
||||
/// ManipulatorMode.FREE_FLIGHT and ManipulatorMode.MAP are currently unsupported and will throw an exception.
|
||||
///
|
||||
Future setCameraManipulatorOptions(
|
||||
{ManipulatorMode mode = ManipulatorMode.ORBIT,
|
||||
double orbitSpeedX = 0.01,
|
||||
double orbitSpeedY = 0.01,
|
||||
double zoomSpeed = 0.01});
|
||||
|
||||
///
|
||||
/// Returns all child entities under [parent].
|
||||
///
|
||||
Future<List<FilamentEntity>> getChildEntities(
|
||||
FilamentEntity parent, bool renderableOnly);
|
||||
|
||||
///
|
||||
/// Finds the child entity named [childName] associated with the given parent.
|
||||
/// Usually, [parent] will be the return value from [loadGlb]/[loadGltf] and [childName] will be the name of a node/mesh.
|
||||
///
|
||||
Future<FilamentEntity> getChildEntity(
|
||||
FilamentEntity parent, String childName);
|
||||
|
||||
///
|
||||
/// List the name of all child entities under the given entity.
|
||||
///
|
||||
Future<List<String>> getChildEntityNames(FilamentEntity entity,
|
||||
{bool renderableOnly = true});
|
||||
|
||||
///
|
||||
/// If [recording] is set to true, each frame the framebuffer/texture will be written to /tmp/output_*.png.
|
||||
/// This will impact performance; handle with care.
|
||||
///
|
||||
Future setRecording(bool recording);
|
||||
|
||||
///
|
||||
/// Sets the output directory where recorded PNGs will be placed.
|
||||
///
|
||||
Future setRecordingOutputDirectory(String outputDirectory);
|
||||
|
||||
///
|
||||
/// An [entity] will only be animatable after an animation component is attached.
|
||||
/// Any calls to [playAnimation]/[setBoneAnimation]/[setMorphAnimation] will have no visual effect until [addAnimationComponent] has been called on the instance.
|
||||
///
|
||||
Future addAnimationComponent(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Makes [entity] collidable.
|
||||
/// This allows you to call [testCollisions] with any other entity ("entity B") to see if [entity] has collided with entity B. The callback will be invoked if so.
|
||||
/// Alternatively, if [affectsTransform] is true and this entity collides with another entity, any queued position updates to the latter entity will be ignored.
|
||||
///
|
||||
Future addCollisionComponent(FilamentEntity entity,
|
||||
{void Function(int entityId1, int entityId2)? callback,
|
||||
bool affectsTransform = false});
|
||||
|
||||
///
|
||||
/// Removes the collision component from [entity], meaning this will no longer be tested when [testCollisions] or [queuePositionUpdate] is called with another entity.
|
||||
///
|
||||
Future removeCollisionComponent(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Creates a (renderable) entity with the specified geometry and adds to the scene.
|
||||
///
|
||||
Future createGeometry(List<double> vertices, List<int> indices,
|
||||
{String? materialPath,
|
||||
PrimitiveType primitiveType = PrimitiveType.TRIANGLES});
|
||||
|
||||
///
|
||||
/// Sets the parent transform of [child] to the transform of [parent].
|
||||
///
|
||||
Future setParent(FilamentEntity child, FilamentEntity parent);
|
||||
|
||||
///
|
||||
/// Test all collidable entities against this entity to see if any have collided.
|
||||
/// This method returns void; the relevant callback passed to [addCollisionComponent] will be fired if a collision is detected.
|
||||
///
|
||||
Future testCollisions(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Sets the draw priority for the given entity. See RenderableManager.h for more details.
|
||||
///
|
||||
Future setPriority(FilamentEntity entityId, int priority);
|
||||
|
||||
///
|
||||
/// The Scene holds the transform gizmo and all loaded entities/lights.
|
||||
///
|
||||
Scene get scene;
|
||||
}
|
||||
|
||||
///
|
||||
/// For now, this class just holds the entities that have been loaded (though not necessarily visible in the Filament Scene).
|
||||
///
|
||||
abstract class Scene {
|
||||
///
|
||||
/// The last entity clicked/tapped in the viewport (internally, the result of calling pick);
|
||||
FilamentEntity? selected;
|
||||
|
||||
///
|
||||
/// A Stream updated whenever an entity is added/removed from the scene.
|
||||
///
|
||||
Stream<bool> get onUpdated;
|
||||
|
||||
///
|
||||
/// A Stream containing every FilamentEntity added to the scene (i.e. via [loadGlb], [loadGltf] or [addLight]).
|
||||
/// This is provided for convenience so you can set listeners in front-end widgets that can respond to entity loads without manually passing around the FilamentEntity returned from those methods.
|
||||
///
|
||||
Stream<FilamentEntity> get onLoad;
|
||||
|
||||
///
|
||||
/// A Stream containing every FilamentEntity removed from the scene (i.e. via [removeEntity], [clearEntities], [removeLight] or [clearLights]).
|
||||
|
||||
Stream<FilamentEntity> get onUnload;
|
||||
|
||||
///
|
||||
/// Lists all light entities currently loaded (not necessarily active in the scene). Does not account for instances.
|
||||
///
|
||||
Iterable<FilamentEntity> listLights();
|
||||
|
||||
///
|
||||
/// Lists all entities currently loaded (not necessarily active in the scene). Does not account for instances.
|
||||
///
|
||||
Iterable<FilamentEntity> listEntities();
|
||||
|
||||
///
|
||||
/// Attach the gizmo to the specified entity.
|
||||
///
|
||||
void select(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// The transform gizmo.
|
||||
///
|
||||
Future<Gizmo> get gizmo;
|
||||
}
|
||||
1705
dart_filament/lib/dart_filament/dart_filament.g.dart
Normal file
1705
dart_filament/lib/dart_filament/dart_filament.g.dart
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,182 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
|
||||
import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart';
|
||||
import 'package:dart_filament/dart_filament/filament_viewer_impl.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
|
||||
class EntityTransformController {
|
||||
final FilamentViewer controller;
|
||||
final FilamentEntity _entity;
|
||||
|
||||
late Timer _ticker;
|
||||
|
||||
double translationSpeed;
|
||||
double rotationRadsPerSecond;
|
||||
|
||||
bool _forward = false;
|
||||
bool _strafeLeft = false;
|
||||
bool _strafeRight = false;
|
||||
bool _back = false;
|
||||
bool _rotateLeft = false;
|
||||
bool _rotateRight = false;
|
||||
double _rotY = 0;
|
||||
|
||||
int? forwardAnimationIndex;
|
||||
int? backwardAnimationIndex;
|
||||
int? strafeLeftAnimationIndex;
|
||||
int? strafeRightAnimationIndex;
|
||||
|
||||
EntityTransformController(this.controller, this._entity,
|
||||
{this.translationSpeed = 1,
|
||||
this.rotationRadsPerSecond = pi / 2,
|
||||
this.forwardAnimationIndex,
|
||||
this.backwardAnimationIndex,
|
||||
this.strafeLeftAnimationIndex,
|
||||
this.strafeRightAnimationIndex}) {
|
||||
var translationSpeedPerTick = translationSpeed / (1000 / 16.667);
|
||||
var rotationRadsPerTick = rotationRadsPerSecond / (1000 / 16.667);
|
||||
_ticker = Timer.periodic(const Duration(milliseconds: 16), (timer) {
|
||||
_update(translationSpeedPerTick, rotationRadsPerTick);
|
||||
});
|
||||
}
|
||||
|
||||
bool _enabled = true;
|
||||
void enable() {
|
||||
_enabled = true;
|
||||
}
|
||||
|
||||
void disable() {
|
||||
_enabled = false;
|
||||
}
|
||||
|
||||
void _update(
|
||||
double translationSpeedPerTick, double rotationRadsPerTick) async {
|
||||
if (!_enabled) {
|
||||
return;
|
||||
}
|
||||
var _position = v.Vector3.zero();
|
||||
bool updateTranslation = false;
|
||||
if (_forward) {
|
||||
_position.add(v.Vector3(0, 0, -translationSpeedPerTick));
|
||||
updateTranslation = true;
|
||||
}
|
||||
if (_back) {
|
||||
_position.add(v.Vector3(0, 0, translationSpeedPerTick));
|
||||
updateTranslation = true;
|
||||
}
|
||||
if (_strafeLeft) {
|
||||
_position.add(v.Vector3(-translationSpeedPerTick, 0, 0));
|
||||
updateTranslation = true;
|
||||
}
|
||||
if (_strafeRight) {
|
||||
_position.add(v.Vector3(translationSpeedPerTick, 0, 0));
|
||||
updateTranslation = true;
|
||||
}
|
||||
|
||||
// TODO - use pitch/yaw/roll
|
||||
bool updateRotation = false;
|
||||
var _rotation = v.Quaternion.identity();
|
||||
|
||||
double rads = 0.0;
|
||||
if (_rotY != 0) {
|
||||
rads = _rotY * pi / 1000;
|
||||
var rotY = v.Quaternion.axisAngle(v.Vector3(0, 1, 0), rads).normalized();
|
||||
_rotation = rotY;
|
||||
updateRotation = true;
|
||||
_rotY = 0;
|
||||
}
|
||||
|
||||
if (updateTranslation) {
|
||||
await controller.queuePositionUpdate(
|
||||
_entity, _position.x, _position.y, _position.z,
|
||||
relative: true);
|
||||
}
|
||||
if (updateRotation) {
|
||||
await controller.queueRotationUpdateQuat(_entity, _rotation,
|
||||
relative: true);
|
||||
}
|
||||
}
|
||||
|
||||
void look(double deltaX) async {
|
||||
_rotY -= deltaX;
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_ticker.cancel();
|
||||
}
|
||||
|
||||
bool _playingForwardAnimation = false;
|
||||
bool _playingBackwardAnimation = false;
|
||||
|
||||
void forwardPressed() async {
|
||||
_forward = true;
|
||||
if (forwardAnimationIndex != null && !_playingForwardAnimation) {
|
||||
await controller.playAnimation(_entity, forwardAnimationIndex!,
|
||||
loop: true, replaceActive: false);
|
||||
_playingForwardAnimation = true;
|
||||
}
|
||||
}
|
||||
|
||||
void forwardReleased() async {
|
||||
_forward = false;
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
if (!_forward) {
|
||||
_playingForwardAnimation = false;
|
||||
if (forwardAnimationIndex != null) {
|
||||
await controller.stopAnimation(_entity, forwardAnimationIndex!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void backPressed() async {
|
||||
_back = true;
|
||||
if (forwardAnimationIndex != null) {
|
||||
if (!_playingBackwardAnimation) {
|
||||
await controller.playAnimation(_entity, forwardAnimationIndex!,
|
||||
loop: true, replaceActive: false, reverse: true);
|
||||
_playingBackwardAnimation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void backReleased() async {
|
||||
_back = false;
|
||||
if (forwardAnimationIndex != null) {
|
||||
await controller.stopAnimation(_entity, forwardAnimationIndex!);
|
||||
}
|
||||
_playingBackwardAnimation = false;
|
||||
}
|
||||
|
||||
void strafeLeftPressed() {
|
||||
_strafeLeft = true;
|
||||
}
|
||||
|
||||
void strafeLeftReleased() async {
|
||||
_strafeLeft = false;
|
||||
}
|
||||
|
||||
void strafeRightPressed() {
|
||||
_strafeRight = true;
|
||||
}
|
||||
|
||||
void strafeRightReleased() async {
|
||||
_strafeRight = false;
|
||||
}
|
||||
|
||||
void Function()? _mouse1DownCallback;
|
||||
void onMouse1Down(void Function() callback) {
|
||||
_mouse1DownCallback = callback;
|
||||
}
|
||||
|
||||
void mouse1Down() async {
|
||||
_mouse1DownCallback?.call();
|
||||
}
|
||||
|
||||
void mouse1Up() async {}
|
||||
|
||||
void mouse2Up() async {}
|
||||
|
||||
void mouse2Down() async {}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// a handle that can be safely passed back to the rendering layer to manipulate an Entity
|
||||
typedef FilamentEntity = int;
|
||||
74
dart_filament/lib/dart_filament/entities/gizmo.dart
Normal file
74
dart_filament/lib/dart_filament/entities/gizmo.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
|
||||
import 'package:dart_filament/dart_filament/filament_viewer_impl.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import '../abstract_filament_viewer.dart';
|
||||
|
||||
class Gizmo {
|
||||
final FilamentEntity x;
|
||||
Vector3 _x = Vector3(0.1, 0, 0);
|
||||
final FilamentEntity y;
|
||||
Vector3 _y = Vector3(0.0, 0.1, 0);
|
||||
final FilamentEntity z;
|
||||
Vector3 _z = Vector3(0.0, 0.0, 0.1);
|
||||
|
||||
final FilamentViewer controller;
|
||||
|
||||
FilamentEntity? _activeAxis;
|
||||
FilamentEntity? _activeEntity;
|
||||
bool get isActive => _activeAxis != null;
|
||||
|
||||
Gizmo(this.x, this.y, this.z, this.controller) {
|
||||
controller.pickResult.listen(_onPickResult);
|
||||
}
|
||||
|
||||
Future _reveal() async {
|
||||
await controller.reveal(x, null);
|
||||
await controller.reveal(y, null);
|
||||
await controller.reveal(z, null);
|
||||
}
|
||||
|
||||
void translate(double x, double y) async {
|
||||
late Vector3 vec;
|
||||
if (_activeAxis == x) {
|
||||
vec = _x;
|
||||
} else if (_activeAxis == y) {
|
||||
vec = _y;
|
||||
} else if (_activeAxis == z) {
|
||||
vec = _z;
|
||||
}
|
||||
await controller.queuePositionUpdate(
|
||||
_activeEntity!, x * vec.x, -y * vec.y, -x * vec.z,
|
||||
relative: true);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_activeAxis = null;
|
||||
}
|
||||
|
||||
void _onPickResult(FilamentPickResult result) async {
|
||||
if (result.entity == x || result.entity == y || result.entity == z) {
|
||||
_activeAxis = result.entity;
|
||||
} else {
|
||||
attach(result.entity);
|
||||
}
|
||||
}
|
||||
|
||||
void attach(FilamentEntity entity) async {
|
||||
_activeAxis = null;
|
||||
_activeEntity = entity;
|
||||
await _reveal();
|
||||
await controller.setParent(x, entity);
|
||||
await controller.setParent(y, entity);
|
||||
await controller.setParent(z, entity);
|
||||
}
|
||||
|
||||
void detach() async {
|
||||
await controller.setParent(x, 0);
|
||||
await controller.setParent(y, 0);
|
||||
await controller.setParent(z, 0);
|
||||
await controller.hide(x, null);
|
||||
await controller.hide(y, null);
|
||||
await controller.hide(z, null);
|
||||
}
|
||||
}
|
||||
1195
dart_filament/lib/dart_filament/filament_viewer_impl.dart
Normal file
1195
dart_filament/lib/dart_filament/filament_viewer_impl.dart
Normal file
File diff suppressed because it is too large
Load Diff
138
dart_filament/lib/dart_filament/scene.dart
Normal file
138
dart_filament/lib/dart_filament/scene.dart
Normal file
@@ -0,0 +1,138 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'package:dart_filament/dart_filament/dart_filament.g.dart';
|
||||
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
|
||||
import 'package:dart_filament/dart_filament/filament_viewer_impl.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
import 'entities/gizmo.dart';
|
||||
import 'abstract_filament_viewer.dart';
|
||||
|
||||
///
|
||||
/// For now, this class just holds the entities that have been loaded (though not necessarily visible in the Filament Scene).
|
||||
///
|
||||
class SceneImpl extends Scene {
|
||||
Gizmo? _gizmo;
|
||||
Future<Gizmo> get gizmo async {
|
||||
if (_gizmo == null) {
|
||||
final out = calloc<Int32>(3);
|
||||
get_gizmo(_sceneManager!, out);
|
||||
_gizmo = Gizmo(out[0], out[1], out[2], controller);
|
||||
calloc.free(out);
|
||||
}
|
||||
return _gizmo!;
|
||||
}
|
||||
|
||||
FilamentViewer controller;
|
||||
|
||||
final Pointer<Void> _sceneManager;
|
||||
|
||||
SceneImpl(this._gizmo, this.controller, this._sceneManager);
|
||||
|
||||
@override
|
||||
FilamentEntity? selected;
|
||||
|
||||
final _onUpdatedController = StreamController<bool>.broadcast();
|
||||
@override
|
||||
Stream<bool> get onUpdated => _onUpdatedController.stream;
|
||||
|
||||
final _onLoadController = StreamController<FilamentEntity>.broadcast();
|
||||
@override
|
||||
Stream<FilamentEntity> get onLoad => _onLoadController.stream;
|
||||
|
||||
final _onUnloadController = StreamController<FilamentEntity>.broadcast();
|
||||
@override
|
||||
Stream<FilamentEntity> get onUnload => _onUnloadController.stream;
|
||||
|
||||
final _lights = <FilamentEntity>{};
|
||||
final _entities = <FilamentEntity>{};
|
||||
|
||||
void registerLight(FilamentEntity entity) {
|
||||
_lights.add(entity);
|
||||
_onLoadController.sink.add(entity);
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
void unregisterLight(FilamentEntity entity) async {
|
||||
var children = await controller.getChildEntities(entity, true);
|
||||
if (selected == entity || children.contains(selected)) {
|
||||
selected = null;
|
||||
_gizmo?.detach();
|
||||
}
|
||||
_lights.remove(entity);
|
||||
_onUnloadController.add(entity);
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
void unregisterEntity(FilamentEntity entity) async {
|
||||
var children = await controller.getChildEntities(entity, true);
|
||||
if (selected == entity || children.contains(selected)) {
|
||||
selected = null;
|
||||
_gizmo?.detach();
|
||||
}
|
||||
_entities.remove(entity);
|
||||
_onUnloadController.add(entity);
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
void registerEntity(FilamentEntity entity) {
|
||||
_entities.add(entity);
|
||||
_entities.add(entity);
|
||||
_onLoadController.sink.add(entity);
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
void clearLights() {
|
||||
for (final light in _lights) {
|
||||
if (selected == light) {
|
||||
selected = null;
|
||||
_gizmo?.detach();
|
||||
}
|
||||
_onUnloadController.add(light);
|
||||
}
|
||||
|
||||
_lights.clear();
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
void clearEntities() {
|
||||
for (final entity in _entities) {
|
||||
if (selected == entity) {
|
||||
selected = null;
|
||||
_gizmo?.detach();
|
||||
}
|
||||
_onUnloadController.add(entity);
|
||||
}
|
||||
_entities.clear();
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
///
|
||||
/// Lists all entities currently loaded (not necessarily active in the scene).
|
||||
///
|
||||
Iterable<FilamentEntity> listLights() {
|
||||
return _lights;
|
||||
}
|
||||
|
||||
@override
|
||||
Iterable<FilamentEntity> listEntities() {
|
||||
return _entities;
|
||||
}
|
||||
|
||||
void registerSelected(FilamentEntity entity) {
|
||||
selected = entity;
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
void unregisterSelected() {
|
||||
selected = null;
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
|
||||
@override
|
||||
void select(FilamentEntity entity) {
|
||||
selected = entity;
|
||||
_gizmo?.attach(entity);
|
||||
_onUpdatedController.add(true);
|
||||
}
|
||||
}
|
||||
73832
dart_filament/lib/dart_filament/swift/swift_bindings.g.dart
Normal file
73832
dart_filament/lib/dart_filament/swift/swift_bindings.g.dart
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
|
||||
class CameraOrientation {
|
||||
v.Vector3 position = v.Vector3(0, 0, 0);
|
||||
|
||||
var rotationX = 0.0;
|
||||
var rotationY = 0.0;
|
||||
var rotationZ = 0.0;
|
||||
|
||||
v.Quaternion compose() {
|
||||
return v.Quaternion.axisAngle(v.Vector3(0, 0, 1), rotationZ) *
|
||||
v.Quaternion.axisAngle(v.Vector3(0, 1, 0), rotationY) *
|
||||
v.Quaternion.axisAngle(v.Vector3(1, 0, 0), rotationX);
|
||||
}
|
||||
}
|
||||
29
dart_filament/lib/dart_filament/utils/dart_resources.dart
Normal file
29
dart_filament/lib/dart_filament/utils/dart_resources.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart_filament/dart_filament/dart_filament.g.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
class DartResourceLoader {
|
||||
static final _assets = <int, Pointer>{};
|
||||
static void loadResource(Pointer<Char> uri, Pointer<ResourceBuffer> out) {
|
||||
try {
|
||||
var data = File(uri.cast<Utf8>().toDartString().replaceAll("file://", ""))
|
||||
.readAsBytesSync();
|
||||
var ptr = calloc<Uint8>(data.lengthInBytes);
|
||||
ptr.asTypedList(data.lengthInBytes).setRange(0, data.lengthInBytes, data);
|
||||
|
||||
out.ref.data = ptr.cast<Void>();
|
||||
out.ref.size = data.lengthInBytes;
|
||||
out.ref.id = _assets.length;
|
||||
_assets[out.ref.id] = ptr;
|
||||
} catch (err) {
|
||||
print(err);
|
||||
out.ref.size = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void freeResource(ResourceBuffer rb) {
|
||||
calloc.free(_assets[rb.id]!);
|
||||
}
|
||||
}
|
||||
29
dart_filament/lib/dart_filament/utils/light_options.dart
Normal file
29
dart_filament/lib/dart_filament/utils/light_options.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
|
||||
class LightOptions {
|
||||
String? iblPath;
|
||||
double iblIntensity;
|
||||
int directionalType;
|
||||
double directionalColor;
|
||||
double directionalIntensity;
|
||||
bool directionalCastShadows;
|
||||
late v.Vector3 directionalPosition;
|
||||
late v.Vector3 directionalDirection;
|
||||
|
||||
LightOptions(
|
||||
{required this.iblPath,
|
||||
required this.iblIntensity,
|
||||
required this.directionalType,
|
||||
required this.directionalColor,
|
||||
required this.directionalIntensity,
|
||||
required this.directionalCastShadows,
|
||||
v.Vector3? directionalDirection,
|
||||
v.Vector3? directionalPosition}) {
|
||||
this.directionalDirection = directionalDirection == null
|
||||
? v.Vector3(0, -1, 0)
|
||||
: directionalDirection;
|
||||
this.directionalPosition = directionalPosition == null
|
||||
? v.Vector3(0, 100, 0)
|
||||
: directionalPosition;
|
||||
}
|
||||
}
|
||||
10
dart_filament/lib/dart_filament/utils/using_pointer.dart
Normal file
10
dart_filament/lib/dart_filament/utils/using_pointer.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
final allocator = calloc;
|
||||
|
||||
void using(Pointer ptr, Future Function(Pointer ptr) function) async {
|
||||
await function.call(ptr);
|
||||
allocator.free(ptr);
|
||||
}
|
||||
207
dart_filament/native/include/DartFilamentApi.h
Normal file
207
dart_filament/native/include/DartFilamentApi.h
Normal file
@@ -0,0 +1,207 @@
|
||||
#ifndef _FLUTTER_FILAMENT_API_H
|
||||
#define _FLUTTER_FILAMENT_API_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef IS_DLL
|
||||
#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
|
||||
#else
|
||||
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
#else
|
||||
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
// we copy the LLVM <stdbool.h> here rather than including,
|
||||
// because on Windows it's difficult to pin the exact location which confuses dart ffigen
|
||||
|
||||
#ifndef __STDBOOL_H
|
||||
#define __STDBOOL_H
|
||||
|
||||
#define __bool_true_false_are_defined 1
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
|
||||
/* FIXME: We should be issuing a deprecation warning here, but cannot yet due
|
||||
* to system headers which include this header file unconditionally.
|
||||
*/
|
||||
#elif !defined(__cplusplus)
|
||||
#define bool _Bool
|
||||
#define true 1
|
||||
#define false 0
|
||||
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
/* Define _Bool as a GNU extension. */
|
||||
#define _Bool bool
|
||||
#if defined(__cplusplus) && __cplusplus < 201103L
|
||||
/* For C++98, define bool, false, true as a GNU extension. */
|
||||
#define bool bool
|
||||
#define false false
|
||||
#define true true
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __STDBOOL_H */
|
||||
|
||||
#if defined(__APPLE__) || defined(__EMSCRIPTEN__)
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
typedef int32_t EntityId;
|
||||
typedef int32_t _ManipulatorMode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT const void *create_filament_viewer(const void *const context, const ResourceLoaderWrapper *const loader, void *const platform, const char *uberArchivePath);
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void *get_scene_manager(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void create_render_target(const void *const viewer, intptr_t texture, uint32_t width, uint32_t height);
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image(const void *const viewer, const char *path, bool fillHeight);
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position(const void *const viewer, float x, float y, bool clamp);
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_color(const void *const viewer, const float r, const float g, const float b, const float a);
|
||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping(const void *const viewer, int toneMapping);
|
||||
FLUTTER_PLUGIN_EXPORT void set_bloom(const void *const viewer, float strength);
|
||||
FLUTTER_PLUGIN_EXPORT void load_skybox(const void *const viewer, const char *skyboxPath);
|
||||
FLUTTER_PLUGIN_EXPORT void load_ibl(const void *const viewer, const char *iblPath, float intensity);
|
||||
FLUTTER_PLUGIN_EXPORT void rotate_ibl(const void *const viewer, float *rotationMatrix);
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId add_light(const void *const viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
FLUTTER_PLUGIN_EXPORT void remove_light(const void *const viewer, EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void *sceneManager, const char *assetPath, int numInstances);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb_from_buffer(void *sceneManager, const void *const data, size_t length);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_gltf(void *sceneManager, const char *assetPath, const char *relativePath);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId create_instance(void *sceneManager, EntityId id);
|
||||
FLUTTER_PLUGIN_EXPORT int get_instance_count(void *sceneManager, EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT void get_instances(void *sceneManager, EntityId entityId, EntityId *out);
|
||||
FLUTTER_PLUGIN_EXPORT void set_main_camera(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId get_main_camera(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT bool set_camera(const void *const viewer, EntityId asset, const char *nodeName);
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void *const viewer, bool enabled);
|
||||
FLUTTER_PLUGIN_EXPORT void render(
|
||||
const void *const viewer,
|
||||
uint64_t frameTimeInNanos,
|
||||
void *pixelBuffer,
|
||||
void (*callback)(void *buf, size_t size, void *data),
|
||||
void *data);
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain(const void *const viewer, const void *const window, uint32_t width, uint32_t height);
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval(const void *const viewer, float interval);
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection(const void *const viewer, uint32_t width, uint32_t height, float scaleFactor);
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_begin(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_update(const void *const viewer, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_end(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void grab_begin(const void *const viewer, float x, float y, bool pan);
|
||||
FLUTTER_PLUGIN_EXPORT void grab_update(const void *const viewer, float x, float y);
|
||||
FLUTTER_PLUGIN_EXPORT void grab_end(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void apply_weights(
|
||||
void *sceneManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
float *const weights,
|
||||
int count);
|
||||
FLUTTER_PLUGIN_EXPORT bool set_morph_target_weights(
|
||||
void *sceneManager,
|
||||
EntityId asset,
|
||||
const float *const morphData,
|
||||
int numWeights);
|
||||
FLUTTER_PLUGIN_EXPORT bool set_morph_animation(
|
||||
void *sceneManager,
|
||||
EntityId asset,
|
||||
const float *const morphData,
|
||||
const int *const morphIndices,
|
||||
int numMorphTargets,
|
||||
int numFrames,
|
||||
float frameLengthInMs);
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose(
|
||||
void *sceneManager,
|
||||
EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void add_bone_animation(
|
||||
void *sceneManager,
|
||||
EntityId asset,
|
||||
const float *const frameData,
|
||||
int numFrames,
|
||||
const char *const boneName,
|
||||
const char **const meshNames,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs,
|
||||
bool isModelSpace);
|
||||
FLUTTER_PLUGIN_EXPORT bool set_bone_transform(
|
||||
void *sceneManager,
|
||||
EntityId asset,
|
||||
const char *entityName,
|
||||
const float *const transform,
|
||||
const char *boneName);
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation(void *sceneManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame(void *sceneManager, EntityId asset, int animationIndex, int animationFrame);
|
||||
FLUTTER_PLUGIN_EXPORT void stop_animation(void *sceneManager, EntityId asset, int index);
|
||||
FLUTTER_PLUGIN_EXPORT int get_animation_count(void *sceneManager, EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void get_animation_name(void *sceneManager, EntityId asset, char *const outPtr, int index);
|
||||
FLUTTER_PLUGIN_EXPORT float get_animation_duration(void *sceneManager, EntityId asset, int index);
|
||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void *sceneManager, EntityId asset, const char *meshName, char *const outPtr, int index);
|
||||
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void *sceneManager, EntityId asset, const char *meshName);
|
||||
FLUTTER_PLUGIN_EXPORT void remove_entity(const void *const viewer, EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void clear_entities(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT bool set_material_color(void *sceneManager, EntityId asset, const char *meshName, int materialIndex, const float r, const float g, const float b, const float a);
|
||||
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void *sceneManager, EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void queue_position_update(void *sceneManager, EntityId asset, float x, float y, float z, bool relative);
|
||||
FLUTTER_PLUGIN_EXPORT void queue_rotation_update(void *sceneManager, EntityId asset, float rads, float x, float y, float z, float w, bool relative);
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void *sceneManager, EntityId asset, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void *sceneManager, EntityId asset, float rads, float x, float y, float z, float w);
|
||||
FLUTTER_PLUGIN_EXPORT void set_scale(void *sceneManager, EntityId asset, float scale);
|
||||
|
||||
// Camera methods
|
||||
FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void *const viewer, EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void *const viewer, bool enabled);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_exposure(const void *const viewer, float aperture, float shutterSpeed, float sensitivity);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_position(const void *const viewer, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void get_camera_position(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(const void *const viewer, float w, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void *const viewer, const float *const matrix);
|
||||
FLUTTER_PLUGIN_EXPORT const double *const get_camera_model_matrix(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT const double *const get_camera_view_matrix(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT const double *const get_camera_projection_matrix(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_projection_matrix(const void *const viewer, const double *const matrix, double near, double far);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_culling(const void *const viewer, double near, double far);
|
||||
FLUTTER_PLUGIN_EXPORT double get_camera_culling_near(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT double get_camera_culling_far(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT const double *const get_camera_culling_projection_matrix(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT const double *const get_camera_frustum(const void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_fov(const void *const viewer, float fovInDegrees, float aspect);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void *const viewer, float focalLength);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void *const viewer, float focusDistance);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_manipulator_options(const void *const viewer, _ManipulatorMode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed);
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int hide_mesh(void *sceneManager, EntityId asset, const char *meshName);
|
||||
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void *sceneManager, EntityId asset, const char *meshName);
|
||||
FLUTTER_PLUGIN_EXPORT void set_post_processing(void *const viewer, bool enabled);
|
||||
FLUTTER_PLUGIN_EXPORT void set_antialiasing(void *const viewer, bool msaa, bool fxaa, bool taa);
|
||||
FLUTTER_PLUGIN_EXPORT void pick(void *const viewer, int x, int y, void (*callback)(EntityId entityId, int x, int y));
|
||||
FLUTTER_PLUGIN_EXPORT const char *get_name_for_entity(void *const sceneManager, const EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId find_child_entity_by_name(void *const sceneManager, const EntityId parent, const char *name);
|
||||
FLUTTER_PLUGIN_EXPORT int get_entity_count(void *const sceneManager, const EntityId target, bool renderableOnly);
|
||||
FLUTTER_PLUGIN_EXPORT void get_entities(void *const sceneManager, const EntityId target, bool renderableOnly, EntityId *out);
|
||||
FLUTTER_PLUGIN_EXPORT const char *get_entity_name_at(void *const sceneManager, const EntityId target, int index, bool renderableOnly);
|
||||
FLUTTER_PLUGIN_EXPORT void set_recording(void *const viewer, bool recording);
|
||||
FLUTTER_PLUGIN_EXPORT void set_recording_output_directory(void *const viewer, const char *outputDirectory);
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy();
|
||||
FLUTTER_PLUGIN_EXPORT void flutter_filament_free(void *ptr);
|
||||
FLUTTER_PLUGIN_EXPORT void add_collision_component(void *const sceneManager, EntityId entityId, void (*callback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform);
|
||||
FLUTTER_PLUGIN_EXPORT void remove_collision_component(void *const sceneManager, EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT bool add_animation_component(void *const sceneManager, EntityId entityId);
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT EntityId create_geometry(void *const viewer, float *vertices, int numVertices, uint16_t *indices, int numIndices, int primitiveType, const char *materialPath);
|
||||
FLUTTER_PLUGIN_EXPORT void set_parent(void *const sceneManager, EntityId child, EntityId parent);
|
||||
FLUTTER_PLUGIN_EXPORT void test_collisions(void *const sceneManager, EntityId entity);
|
||||
FLUTTER_PLUGIN_EXPORT void set_priority(void *const sceneManager, EntityId entityId, int priority);
|
||||
FLUTTER_PLUGIN_EXPORT void get_gizmo(void *const sceneManager, EntityId *out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
114
dart_filament/native/include/DartFilamentFFIApi.h
Normal file
114
dart_filament/native/include/DartFilamentFFIApi.h
Normal file
@@ -0,0 +1,114 @@
|
||||
#ifndef _FLUTTER_FILAMENT_FFI_API_H
|
||||
#define _FLUTTER_FILAMENT_FFI_API_H
|
||||
|
||||
#include "DartFilamentApi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
///
|
||||
/// This header replicates most of the methods in FlutterFilamentApi.h, and is only intended to be used to generate client FFI bindings.
|
||||
/// The intention is that calling one of these methods will call its respective method in FlutterFilamentApi.h, but wrapped in some kind of thread runner to ensure thread safety.
|
||||
///
|
||||
|
||||
typedef int32_t EntityId;
|
||||
typedef void (*FilamentRenderCallback)(void *const owner);
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_filament_viewer_ffi(
|
||||
void *const context,
|
||||
void *const platform,
|
||||
const char *uberArchivePath,
|
||||
const ResourceLoaderWrapper *const loader,
|
||||
void (*renderCallback)(void *const renderCallbackOwner),
|
||||
void *const renderCallbackOwner,
|
||||
void (*callback)(void *const viewer));
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void *const viewer, void *const surface, uint32_t width, uint32_t height, void (*onComplete)());
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain_ffi(void *const viewer, void (*onComplete)());
|
||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void *const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height, void (*onComplete)());
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer_ffi(void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT FilamentRenderCallback make_render_callback_fn_pointer(FilamentRenderCallback);
|
||||
FLUTTER_PLUGIN_EXPORT void set_rendering_ffi(void *const viewer, bool rendering);
|
||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval_ffi(float frameInterval);
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection_ffi(void *const viewer, const uint32_t width, const uint32_t height, const float scaleFactor, void (*onComplete)());
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_color_ffi(void *const viewer, const float r, const float g, const float b, const float a);
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image_ffi(void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_ffi(void *const viewer, const char *path, bool fillHeight, void (*onComplete)());
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position_ffi(void *const viewer, float x, float y, bool clamp);
|
||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping_ffi(void *const viewer, int toneMapping);
|
||||
FLUTTER_PLUGIN_EXPORT void set_bloom_ffi(void *const viewer, float strength);
|
||||
FLUTTER_PLUGIN_EXPORT void load_skybox_ffi(void *const viewer, const char *skyboxPath, void (*onComplete)());
|
||||
FLUTTER_PLUGIN_EXPORT void load_ibl_ffi(void *const viewer, const char *iblPath, float intensity);
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox_ffi(void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl_ffi(void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void add_light_ffi(
|
||||
void *const viewer,
|
||||
uint8_t type,
|
||||
float colour,
|
||||
float intensity,
|
||||
float posX,
|
||||
float posY,
|
||||
float posZ,
|
||||
float dirX,
|
||||
float dirY,
|
||||
float dirZ,
|
||||
bool shadows,
|
||||
void (*callback)(EntityId));
|
||||
FLUTTER_PLUGIN_EXPORT void remove_light_ffi(void *const viewer, EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights_ffi(void *const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void load_glb_ffi(void *const sceneManager, const char *assetPath, int numInstances, void (*callback)(EntityId));
|
||||
FLUTTER_PLUGIN_EXPORT void load_glb_from_buffer_ffi(void *const sceneManager, const void *const data, size_t length, int numInstances, void (*callback)(EntityId));
|
||||
FLUTTER_PLUGIN_EXPORT void load_gltf_ffi(void *const sceneManager, const char *assetPath, const char *relativePath, void (*callback)(EntityId));
|
||||
FLUTTER_PLUGIN_EXPORT void create_instance_ffi(void *const sceneManager, EntityId entityId, void (*callback)(EntityId));
|
||||
FLUTTER_PLUGIN_EXPORT void remove_entity_ffi(void *const viewer, EntityId asset, void (*callback)());
|
||||
FLUTTER_PLUGIN_EXPORT void clear_entities_ffi(void *const viewer, void (*callback)());
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_ffi(void *const viewer, EntityId asset, const char *nodeName, void (*callback)(bool));
|
||||
FLUTTER_PLUGIN_EXPORT void apply_weights_ffi(
|
||||
void *const sceneManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
float *const weights,
|
||||
int count);
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void *const sceneManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void *const sceneManager, EntityId asset, int animationIndex, int animationFrame);
|
||||
FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void *const sceneManager, EntityId asset, int index);
|
||||
FLUTTER_PLUGIN_EXPORT void get_animation_count_ffi(void *const sceneManager, EntityId asset, void (*callback)(int));
|
||||
FLUTTER_PLUGIN_EXPORT void get_animation_name_ffi(void *const sceneManager, EntityId asset, char *const outPtr, int index, void (*callback)());
|
||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name_ffi(void *const sceneManager, EntityId asset, const char *meshName, char *const outPtr, int index, void (*callback)());
|
||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name_count_ffi(void *const sceneManager, EntityId asset, const char *meshName, void (*callback)(int32_t));
|
||||
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights_ffi(void *const sceneManager,
|
||||
EntityId asset,
|
||||
const float *const morphData,
|
||||
int numWeights,
|
||||
void (*callback)(bool));
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_bone_transform_ffi(
|
||||
void *sceneManager,
|
||||
EntityId asset,
|
||||
const char *entityName,
|
||||
const float *const transform,
|
||||
const char *boneName,
|
||||
void (*callback)(bool));
|
||||
FLUTTER_PLUGIN_EXPORT void add_bone_animation_ffi(
|
||||
void *sceneManager,
|
||||
EntityId asset,
|
||||
const float *const frameData,
|
||||
int numFrames,
|
||||
const char *const boneName,
|
||||
const char **const meshNames,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs,
|
||||
bool isModelSpace);
|
||||
FLUTTER_PLUGIN_EXPORT void set_post_processing_ffi(void *const viewer, bool enabled);
|
||||
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose_ffi(void *const sceneManager, EntityId entityId);
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi();
|
||||
FLUTTER_PLUGIN_EXPORT void create_geometry_ffi(void *const viewer, float *vertices, int numVertices, uint16_t *indices, int numIndices, int primitiveType, const char *materialPath, void (*callback)(EntityId));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _FLUTTER_FILAMENT_FFI_API_H
|
||||
226
dart_filament/native/include/FilamentViewer.hpp
Normal file
226
dart_filament/native/include/FilamentViewer.hpp
Normal file
@@ -0,0 +1,226 @@
|
||||
#pragma once
|
||||
|
||||
#include <filament/Camera.h>
|
||||
#include <filament/Frustum.h>
|
||||
#include <filament/ColorGrading.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/IndexBuffer.h>
|
||||
#include <filament/RenderableManager.h>
|
||||
#include <filament/Renderer.h>
|
||||
#include <filament/Scene.h>
|
||||
#include <filament/Skybox.h>
|
||||
#include <filament/TransformManager.h>
|
||||
#include <filament/VertexBuffer.h>
|
||||
#include <filament/View.h>
|
||||
#include <filament/LightManager.h>
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <gltfio/ResourceLoader.h>
|
||||
|
||||
#include <camutils/Manipulator.h>
|
||||
|
||||
#include <utils/NameComponentManager.h>
|
||||
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include <math/mat3.h>
|
||||
#include <math/norm.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
#include "SceneManager.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
namespace flutter_filament
|
||||
{
|
||||
|
||||
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace filament;
|
||||
using namespace filament::math;
|
||||
using namespace gltfio;
|
||||
using namespace camutils;
|
||||
|
||||
enum ToneMapping
|
||||
{
|
||||
ACES,
|
||||
FILMIC,
|
||||
LINEAR
|
||||
};
|
||||
|
||||
class FilamentViewer
|
||||
{
|
||||
|
||||
typedef int32_t EntityId;
|
||||
|
||||
public:
|
||||
FilamentViewer(const void *context, const ResourceLoaderWrapperImpl *const resourceLoaderWrapper, void *const platform = nullptr, const char *uberArchivePath = nullptr);
|
||||
~FilamentViewer();
|
||||
|
||||
void setToneMapping(ToneMapping toneMapping);
|
||||
void setBloom(float strength);
|
||||
void loadSkybox(const char *const skyboxUri);
|
||||
void removeSkybox();
|
||||
|
||||
void loadIbl(const char *const iblUri, float intensity);
|
||||
void removeIbl();
|
||||
void rotateIbl(const math::mat3f &matrix);
|
||||
|
||||
void removeEntity(EntityId asset);
|
||||
void clearEntities();
|
||||
|
||||
void updateViewportAndCameraProjection(int height, int width, float scaleFactor);
|
||||
void render(
|
||||
uint64_t frameTimeInNanos,
|
||||
void *pixelBuffer,
|
||||
void (*callback)(void *buf, size_t size, void *data),
|
||||
void *data);
|
||||
void setFrameInterval(float interval);
|
||||
|
||||
bool setCamera(EntityId asset, const char *nodeName);
|
||||
void setMainCamera();
|
||||
EntityId getMainCamera();
|
||||
void setCameraFov(double fovDegrees, double aspect);
|
||||
|
||||
void createSwapChain(const void *surface, uint32_t width, uint32_t height);
|
||||
void destroySwapChain();
|
||||
|
||||
void createRenderTarget(intptr_t textureId, uint32_t width, uint32_t height);
|
||||
|
||||
Renderer *getRenderer();
|
||||
|
||||
void setBackgroundColor(const float r, const float g, const float b, const float a);
|
||||
void setBackgroundImage(const char *resourcePath, bool fillHeight);
|
||||
void clearBackgroundImage();
|
||||
void setBackgroundImagePosition(float x, float y, bool clamp);
|
||||
|
||||
// Camera methods
|
||||
void moveCameraToAsset(EntityId entityId);
|
||||
void setViewFrustumCulling(bool enabled);
|
||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||
void setCameraPosition(float x, float y, float z);
|
||||
void setCameraRotation(float w, float x, float y, float z);
|
||||
const math::mat4 getCameraModelMatrix();
|
||||
const math::mat4 getCameraViewMatrix();
|
||||
const math::mat4 getCameraProjectionMatrix();
|
||||
const math::mat4 getCameraCullingProjectionMatrix();
|
||||
const filament::Frustum getCameraFrustum();
|
||||
void setCameraModelMatrix(const float *const matrix);
|
||||
void setCameraProjectionMatrix(const double *const matrix, double near, double far);
|
||||
void setCameraFocalLength(float focalLength);
|
||||
void setCameraCulling(double near, double far);
|
||||
double getCameraCullingNear();
|
||||
double getCameraCullingFar();
|
||||
void setCameraFocusDistance(float focusDistance);
|
||||
void setCameraManipulatorOptions(filament::camutils::Mode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed);
|
||||
void grabBegin(float x, float y, bool pan);
|
||||
void grabUpdate(float x, float y);
|
||||
void grabEnd();
|
||||
void scrollBegin();
|
||||
void scrollUpdate(float x, float y, float delta);
|
||||
void scrollEnd();
|
||||
void pick(uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y));
|
||||
|
||||
EntityId addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
void removeLight(EntityId entityId);
|
||||
void clearLights();
|
||||
void setPostProcessing(bool enabled);
|
||||
|
||||
void setRecording(bool recording);
|
||||
void setRecordingOutputDirectory(const char *path);
|
||||
|
||||
void setAntiAliasing(bool msaaEnabled, bool fxaaEnabled, bool taaEnabled);
|
||||
void setDepthOfField();
|
||||
|
||||
EntityId createGeometry(float *vertices, uint32_t numVertices, uint16_t *indices, uint32_t numIndices, filament::RenderableManager::PrimitiveType primitiveType = RenderableManager::PrimitiveType::TRIANGLES, const char *materialPath = nullptr);
|
||||
|
||||
SceneManager *const getSceneManager()
|
||||
{
|
||||
return (SceneManager *const)_sceneManager;
|
||||
}
|
||||
|
||||
private:
|
||||
const ResourceLoaderWrapperImpl *const _resourceLoaderWrapper;
|
||||
|
||||
Scene *_scene = nullptr;
|
||||
View *_view = nullptr;
|
||||
Engine *_engine = nullptr;
|
||||
flutter_filament::ThreadPool *_tp = nullptr;
|
||||
Renderer *_renderer = nullptr;
|
||||
RenderTarget *_rt = nullptr;
|
||||
Texture *_rtColor = nullptr;
|
||||
Texture *_rtDepth = nullptr;
|
||||
|
||||
SwapChain *_swapChain = nullptr;
|
||||
|
||||
SceneManager *_sceneManager = nullptr;
|
||||
|
||||
std::mutex mtx; // mutex to ensure thread safety when removing assets
|
||||
|
||||
std::vector<utils::Entity> _lights;
|
||||
Texture *_skyboxTexture = nullptr;
|
||||
Skybox *_skybox = nullptr;
|
||||
Texture *_iblTexture = nullptr;
|
||||
IndirectLight *_indirectLight = nullptr;
|
||||
bool _recomputeAabb = false;
|
||||
bool _actualSize = false;
|
||||
|
||||
float _frameInterval = 1000.0 / 60.0;
|
||||
|
||||
// Camera properties
|
||||
Camera *_mainCamera = nullptr; // the default camera added to every scene. If you want the *active* camera, access via View.
|
||||
float _cameraFocalLength = 28.0f;
|
||||
float _cameraFocusDistance = 0.0f;
|
||||
Manipulator<double> *_manipulator = nullptr;
|
||||
filament::camutils::Mode _manipulatorMode = filament::camutils::Mode::ORBIT;
|
||||
double _orbitSpeedX = 0.01;
|
||||
double _orbitSpeedY = 0.01;
|
||||
double _zoomSpeed = 0.01;
|
||||
math::mat4f _cameraPosition;
|
||||
math::mat4f _cameraRotation;
|
||||
void _createManipulator();
|
||||
double _near = 0.05;
|
||||
double _far = 1000.0;
|
||||
|
||||
ColorGrading *colorGrading = nullptr;
|
||||
|
||||
// background image properties
|
||||
uint32_t _imageHeight = 0;
|
||||
uint32_t _imageWidth = 0;
|
||||
mat4f _imageScale;
|
||||
Texture *_imageTexture = nullptr;
|
||||
utils::Entity _imageEntity;
|
||||
VertexBuffer *_imageVb = nullptr;
|
||||
IndexBuffer *_imageIb = nullptr;
|
||||
Material *_imageMaterial = nullptr;
|
||||
TextureSampler _imageSampler;
|
||||
void loadKtx2Texture(std::string path, ResourceBuffer data);
|
||||
void loadKtxTexture(std::string path, ResourceBuffer data);
|
||||
void loadPngTexture(std::string path, ResourceBuffer data);
|
||||
void loadTextureFromPath(std::string path);
|
||||
void savePng(void *data, size_t size, int frameNumber);
|
||||
|
||||
time_point_t _recordingStartTime = std::chrono::high_resolution_clock::now();
|
||||
time_point_t _fpsCounterStartTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
bool _recording = false;
|
||||
std::string _recordingOutputDirectory = std::string("/tmp");
|
||||
std::mutex _recordingMutex;
|
||||
double _cumulativeAnimationUpdateTime = 0;
|
||||
int _frameCount = 0;
|
||||
int _skippedFrames = 0;
|
||||
};
|
||||
|
||||
struct FrameCallbackData
|
||||
{
|
||||
FilamentViewer *viewer;
|
||||
uint32_t frameNumber;
|
||||
};
|
||||
|
||||
}
|
||||
34
dart_filament/native/include/Log.hpp
Normal file
34
dart_filament/native/include/Log.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FLUTTER_FILAMENT_LOG_H
|
||||
#define FLUTTER_FILAMENT_LOG_H
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#elif defined __ANDROID__
|
||||
#include <android/log.h>
|
||||
#define LOGTAG "FlutterFilament"
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
static void Log(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
__android_log_vprint(ANDROID_LOG_DEBUG, LOGTAG, fmt, args);
|
||||
#elif defined __OBJC__
|
||||
NSString *format = [[NSString alloc] initWithUTF8String:fmt];
|
||||
NSLogv(format, args);
|
||||
#else
|
||||
vprintf(fmt, args);
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#endif
|
||||
110
dart_filament/native/include/ResourceBuffer.hpp
Normal file
110
dart_filament/native/include/ResourceBuffer.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef RESOURCE_BUFFER_H
|
||||
#define RESOURCE_BUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//
|
||||
// A ResourceBuffer is a unified interface for working with
|
||||
// binary assets across various platforms.
|
||||
// This is simply:
|
||||
// 1) a pointer to some data
|
||||
// 2) the length of the data
|
||||
// 3) an ID that can be passed back to the native platform to release the underlying asset when needed.
|
||||
//
|
||||
struct ResourceBuffer
|
||||
{
|
||||
const void *const data;
|
||||
const int32_t size;
|
||||
const int32_t id;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
ResourceBuffer(void *const data, int32_t size, int32_t id) : data(data), size(size), id(id) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct ResourceBuffer ResourceBuffer;
|
||||
typedef void (*LoadFilamentResourceIntoOutPointer)(const char *uri, ResourceBuffer *out);
|
||||
typedef ResourceBuffer (*LoadFilamentResource)(const char *uri);
|
||||
typedef ResourceBuffer (*LoadFilamentResourceFromOwner)(const char *const, void *const owner);
|
||||
typedef void (*FreeFilamentResource)(ResourceBuffer);
|
||||
typedef void (*FreeFilamentResourceFromOwner)(ResourceBuffer, void *const owner);
|
||||
|
||||
struct ResourceLoaderWrapper
|
||||
{
|
||||
LoadFilamentResource loadResource;
|
||||
FreeFilamentResource freeResource;
|
||||
LoadFilamentResourceFromOwner loadFromOwner;
|
||||
FreeFilamentResourceFromOwner freeFromOwner;
|
||||
void *owner;
|
||||
LoadFilamentResourceIntoOutPointer loadToOut;
|
||||
};
|
||||
typedef struct ResourceLoaderWrapper ResourceLoaderWrapper;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
#include <thread>
|
||||
using namespace std::chrono_literals;
|
||||
namespace flutter_filament
|
||||
{
|
||||
|
||||
struct ResourceLoaderWrapperImpl : public ResourceLoaderWrapper
|
||||
{
|
||||
|
||||
ResourceLoaderWrapperImpl(LoadFilamentResource loader, FreeFilamentResource freeResource)
|
||||
{
|
||||
loadFromOwner = nullptr;
|
||||
freeFromOwner = nullptr;
|
||||
loadResource = loader;
|
||||
freeResource = freeResource;
|
||||
owner = nullptr;
|
||||
}
|
||||
|
||||
ResourceLoaderWrapperImpl(LoadFilamentResourceFromOwner loader, FreeFilamentResourceFromOwner freeResource, void *owner)
|
||||
{
|
||||
loadResource = nullptr;
|
||||
freeResource = nullptr;
|
||||
loadFromOwner = loader;
|
||||
freeFromOwner = freeResource;
|
||||
owner = owner;
|
||||
}
|
||||
|
||||
ResourceBuffer load(const char *uri) const
|
||||
{
|
||||
if (loadToOut)
|
||||
{
|
||||
ResourceBuffer rb(nullptr, 0, -1);
|
||||
loadToOut(uri, &rb);
|
||||
while (rb.size == 0)
|
||||
{
|
||||
std::this_thread::sleep_for(100ms);
|
||||
}
|
||||
|
||||
return rb;
|
||||
}
|
||||
else if (loadFromOwner)
|
||||
{
|
||||
auto rb = loadFromOwner(uri, owner);
|
||||
return rb;
|
||||
}
|
||||
auto rb = loadResource(uri);
|
||||
return rb;
|
||||
}
|
||||
|
||||
void free(ResourceBuffer rb) const
|
||||
{
|
||||
if (freeFromOwner)
|
||||
{
|
||||
freeFromOwner(rb, owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
freeResource(rb);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
195
dart_filament/native/include/SceneManager.hpp
Normal file
195
dart_filament/native/include/SceneManager.hpp
Normal file
@@ -0,0 +1,195 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include <filament/Scene.h>
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <gltfio/FilamentInstance.h>
|
||||
#include <gltfio/ResourceLoader.h>
|
||||
|
||||
#include <filament/IndexBuffer.h>
|
||||
#include <filament/InstanceBuffer.h>
|
||||
|
||||
#include "material/gizmo.h"
|
||||
#include "utils/NameComponentManager.h"
|
||||
#include "ResourceBuffer.hpp"
|
||||
#include "components/CollisionComponentManager.hpp"
|
||||
#include "components/AnimationComponentManager.hpp"
|
||||
|
||||
#include "tsl/robin_map.h"
|
||||
|
||||
namespace flutter_filament
|
||||
{
|
||||
typedef int32_t EntityId;
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::gltfio;
|
||||
using namespace utils;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using std::vector;
|
||||
|
||||
class SceneManager
|
||||
{
|
||||
public:
|
||||
SceneManager(const ResourceLoaderWrapperImpl *const loader,
|
||||
Engine *engine,
|
||||
Scene *scene,
|
||||
const char *uberArchivePath);
|
||||
~SceneManager();
|
||||
|
||||
EntityId loadGltf(const char *uri, const char *relativeResourcePath);
|
||||
|
||||
////
|
||||
/// @brief Load the GLB from the specified path, optionally creating multiple instances.
|
||||
/// @param uri the path to the asset. Should be either asset:// (representing a Flutter asset), or file:// (representing a filesystem file).
|
||||
/// @param numInstances the number of instances to create.
|
||||
/// @return an Entity representing the FilamentAsset associated with the loaded FilamentAsset.
|
||||
///
|
||||
EntityId loadGlb(const char *uri, int numInstances);
|
||||
EntityId loadGlbFromBuffer(const uint8_t *data, size_t length, int numInstances = 1);
|
||||
EntityId createInstance(EntityId entityId);
|
||||
|
||||
void remove(EntityId entity);
|
||||
void destroyAll();
|
||||
unique_ptr<vector<string>> getAnimationNames(EntityId entity);
|
||||
float getAnimationDuration(EntityId entity, int animationIndex);
|
||||
|
||||
unique_ptr<vector<string>> getMorphTargetNames(EntityId entity, const char *name);
|
||||
void transformToUnitCube(EntityId e);
|
||||
inline void updateTransform(EntityId e);
|
||||
void setScale(EntityId e, float scale);
|
||||
void setPosition(EntityId e, float x, float y, float z);
|
||||
void setRotation(EntityId e, float rads, float x, float y, float z, float w);
|
||||
void queuePositionUpdate(EntityId e, float x, float y, float z, bool relative);
|
||||
void queueRotationUpdate(EntityId e, float rads, float x, float y, float z, float w, bool relative);
|
||||
const utils::Entity *getCameraEntities(EntityId e);
|
||||
size_t getCameraEntityCount(EntityId e);
|
||||
const utils::Entity *getLightEntities(EntityId e) noexcept;
|
||||
size_t getLightEntityCount(EntityId e) noexcept;
|
||||
void updateAnimations();
|
||||
void updateTransforms();
|
||||
void testCollisions(EntityId entity);
|
||||
bool setMaterialColor(EntityId e, const char *meshName, int materialInstance, const float r, const float g, const float b, const float a);
|
||||
|
||||
bool setMorphAnimationBuffer(
|
||||
EntityId entityId,
|
||||
const float *const morphData,
|
||||
const int *const morphIndices,
|
||||
int numMorphTargets,
|
||||
int numFrames,
|
||||
float frameLengthInMs);
|
||||
|
||||
bool setMorphTargetWeights(EntityId entityId, const float *const weights, int count);
|
||||
|
||||
/// @brief Set the local transform for the bone at boneIndex/skinIndex in the given entity.
|
||||
/// @param entityId the parent entity
|
||||
/// @param entityName the name of the mesh under entityId for which the bone will be set.
|
||||
/// @param skinIndex the index of the joint skin. Currently only 0 is supported.
|
||||
/// @param boneName the name of the bone
|
||||
/// @param transform the 4x4 matrix representing the local transform for the bone
|
||||
/// @return true if the transform was successfully set, false otherwise
|
||||
bool setBoneTransform(EntityId entityId, const char *entityName, int skinIndex, const char *boneName, math::mat4f transform);
|
||||
|
||||
/// @brief Set frame data to animate the given bones/entities.
|
||||
/// @param entity the parent entity
|
||||
/// @param frameData frame data as quaternions
|
||||
/// @param numFrames the number of frames
|
||||
/// @param boneName the name of the bone to animate
|
||||
/// @param meshName an array of mesh names under [entity] that should be animated
|
||||
/// @param numMeshTargets the number of meshes under [meshName]
|
||||
/// @param frameLengthInMs the length of each frame in ms
|
||||
/// @return true if the bone animation was successfully enqueued
|
||||
bool addBoneAnimation(
|
||||
EntityId entity,
|
||||
const float *const frameData,
|
||||
int numFrames,
|
||||
const char *const boneName,
|
||||
const char **const meshName,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs,
|
||||
bool isModelSpace);
|
||||
void resetBones(EntityId entityId);
|
||||
void playAnimation(EntityId e, int index, bool loop, bool reverse, bool replaceActive, float crossfade = 0.3f);
|
||||
void stopAnimation(EntityId e, int index);
|
||||
void setMorphTargetWeights(const char *const entityName, float *weights, int count);
|
||||
void loadTexture(EntityId entity, const char *resourcePath, int renderableIndex);
|
||||
void setAnimationFrame(EntityId entity, int animationIndex, int animationFrame);
|
||||
bool hide(EntityId entity, const char *meshName);
|
||||
bool reveal(EntityId entity, const char *meshName);
|
||||
const char *getNameForEntity(EntityId entityId);
|
||||
utils::Entity findChildEntityByName(
|
||||
EntityId entityId,
|
||||
const char *entityName);
|
||||
int getEntityCount(EntityId entity, bool renderableOnly);
|
||||
void getEntities(EntityId entity, bool renderableOnly, EntityId *out);
|
||||
const char *getEntityNameAt(EntityId entity, int index, bool renderableOnly);
|
||||
void addCollisionComponent(EntityId entity, void (*onCollisionCallback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform);
|
||||
void removeCollisionComponent(EntityId entityId);
|
||||
void setParent(EntityId child, EntityId parent);
|
||||
bool addAnimationComponent(EntityId entity);
|
||||
|
||||
/// @brief returns the number of instances of the FilamentAsset represented by the given entity.
|
||||
/// @param entityId
|
||||
/// @return the number of instances
|
||||
int getInstanceCount(EntityId entityId);
|
||||
|
||||
/// @brief returns an array containing all instances of the FilamentAsset represented by the given entity.
|
||||
/// @param entityId
|
||||
void getInstances(EntityId entityId, EntityId *out);
|
||||
|
||||
///
|
||||
/// Sets the draw priority for the given entity. See RenderableManager.h for more details.
|
||||
///
|
||||
void setPriority(EntityId entity, int priority);
|
||||
|
||||
/// @brief returns the gizmo entity, used to manipulate the global transform for entities
|
||||
/// @param out a pointer to an array of three EntityId {x, y, z}
|
||||
/// @return
|
||||
///
|
||||
void getGizmo(EntityId *out);
|
||||
|
||||
friend class FilamentViewer;
|
||||
|
||||
private:
|
||||
gltfio::AssetLoader *_assetLoader = nullptr;
|
||||
const ResourceLoaderWrapperImpl *const _resourceLoaderWrapper;
|
||||
Engine *_engine;
|
||||
Scene *_scene;
|
||||
gltfio::MaterialProvider *_ubershaderProvider = nullptr;
|
||||
gltfio::ResourceLoader *_gltfResourceLoader = nullptr;
|
||||
gltfio::TextureProvider *_stbDecoder = nullptr;
|
||||
gltfio::TextureProvider *_ktxDecoder = nullptr;
|
||||
std::mutex _mutex;
|
||||
Material *_gizmoMaterial;
|
||||
|
||||
utils::NameComponentManager *_ncm;
|
||||
|
||||
tsl::robin_map<
|
||||
EntityId,
|
||||
gltfio::FilamentInstance *>
|
||||
_instances;
|
||||
tsl::robin_map<EntityId, gltfio::FilamentAsset *> _assets;
|
||||
tsl::robin_map<EntityId, std::tuple<math::float3, bool, math::quatf, bool, float>> _transformUpdates;
|
||||
|
||||
AnimationComponentManager *_animationComponentManager = nullptr;
|
||||
CollisionComponentManager *_collisionComponentManager = nullptr;
|
||||
|
||||
gltfio::FilamentInstance *getInstanceByEntityId(EntityId entityId);
|
||||
gltfio::FilamentAsset *getAssetByEntityId(EntityId entityId);
|
||||
|
||||
utils::Entity findEntityByName(
|
||||
const gltfio::FilamentInstance *instance,
|
||||
const char *entityName);
|
||||
|
||||
EntityId addGizmo();
|
||||
utils::Entity _gizmoX;
|
||||
utils::Entity _gizmoY;
|
||||
utils::Entity _gizmoZ;
|
||||
};
|
||||
}
|
||||
34
dart_filament/native/include/StreamBufferAdapter.hpp
Normal file
34
dart_filament/native/include/StreamBufferAdapter.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <streambuf>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
namespace flutter_filament {
|
||||
|
||||
|
||||
//
|
||||
// A generic adapter to expose any contiguous section of memory as a std::streambuf.
|
||||
// Mostly for Android/iOS assets which may not be able to be directly loaded as streams.
|
||||
//
|
||||
class StreamBufferAdapter : public std::streambuf
|
||||
{
|
||||
public:
|
||||
StreamBufferAdapter(const char *begin, const char *end);
|
||||
~StreamBufferAdapter() {
|
||||
|
||||
}
|
||||
std::streamsize size();
|
||||
|
||||
private:
|
||||
int_type uflow() override;
|
||||
int_type underflow() override;
|
||||
int_type pbackfail(int_type ch) override;
|
||||
std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which) override;
|
||||
std::streampos seekpos(std::streampos sp, std::ios_base::openmode which) override;
|
||||
std::streamsize showmanyc() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
79
dart_filament/native/include/ThreadPool.hpp
Normal file
79
dart_filament/native/include/ThreadPool.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is licensed under the zlib/libpng license, included in this
|
||||
* distribution in the file COPYING.
|
||||
*/
|
||||
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#ifndef _THREADPOOL_HPP
|
||||
#define _THREADPOOL_HPP
|
||||
|
||||
namespace flutter_filament {
|
||||
|
||||
class ThreadPool {
|
||||
std::vector<std::thread> pool;
|
||||
bool stop;
|
||||
|
||||
std::mutex access;
|
||||
std::condition_variable cond;
|
||||
std::deque<std::function<void()>> tasks;
|
||||
|
||||
public:
|
||||
explicit ThreadPool(int nr = 1) : stop(false) {
|
||||
while(nr-->0) {
|
||||
add_worker();
|
||||
}
|
||||
}
|
||||
~ThreadPool() {
|
||||
stop = true;
|
||||
for(std::thread &t : pool) {
|
||||
t.join();
|
||||
}
|
||||
pool.clear();
|
||||
}
|
||||
|
||||
template<class Rt>
|
||||
auto add_task(std::packaged_task<Rt()>& pt) -> std::future<Rt> {
|
||||
std::unique_lock<std::mutex> lock(access);
|
||||
|
||||
auto ret = pt.get_future();
|
||||
tasks.push_back([pt=std::make_shared<std::packaged_task<Rt()>>(std::move(pt))]{ (*pt)();});
|
||||
|
||||
cond.notify_one();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
void add_worker() {
|
||||
std::thread t([this]() {
|
||||
while(!stop || tasks.size() > 0) {
|
||||
std::function<void()> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(access);
|
||||
if(tasks.empty()) {
|
||||
cond.wait_for(lock, std::chrono::duration<int, std::milli>(5));
|
||||
continue;
|
||||
}
|
||||
task = std::move(tasks.front());
|
||||
tasks.pop_front();
|
||||
}
|
||||
task();
|
||||
}
|
||||
});
|
||||
pool.push_back(std::move(t));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif//_THREADPOOL_HPP
|
||||
|
||||
// vim: syntax=cpp11
|
||||
32
dart_filament/native/include/TimeIt.hpp
Normal file
32
dart_filament/native/include/TimeIt.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef TIMEIT_H_
|
||||
#define TIMEIT_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus <= 199711L && !_WIN32
|
||||
#include <ctime>
|
||||
#else
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
|
||||
Timer() { reset(); }
|
||||
void reset();
|
||||
double elapsed();
|
||||
|
||||
private:
|
||||
|
||||
#if __cplusplus <= 199711L && !_WIN32
|
||||
timespec beg_, end_;
|
||||
#else
|
||||
typedef std::chrono::high_resolution_clock clock_;
|
||||
typedef std::chrono::duration<double, std::ratio<1> > second_;
|
||||
std::chrono::time_point<clock_> beg_;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMEIT_H_
|
||||
6552
dart_filament/native/include/cgltf.h
Normal file
6552
dart_filament/native/include/cgltf.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,280 @@
|
||||
#pragma once
|
||||
|
||||
#include "Log.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <variant>
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/RenderableManager.h>
|
||||
#include <filament/Renderer.h>
|
||||
#include <filament/Scene.h>
|
||||
#include <filament/Texture.h>
|
||||
#include <filament/TransformManager.h>
|
||||
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
#include <math/mat3.h>
|
||||
#include <math/norm.h>
|
||||
|
||||
#include <gltfio/Animator.h>
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/ResourceLoader.h>
|
||||
#include <utils/NameComponentManager.h>
|
||||
|
||||
template class std::vector<float>;
|
||||
namespace flutter_filament
|
||||
{
|
||||
using namespace filament;
|
||||
using namespace filament::gltfio;
|
||||
using namespace utils;
|
||||
using namespace std::chrono;
|
||||
|
||||
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
|
||||
|
||||
enum AnimationType
|
||||
{
|
||||
MORPH,
|
||||
BONE,
|
||||
GLTF
|
||||
};
|
||||
|
||||
struct AnimationStatus
|
||||
{
|
||||
time_point_t start = time_point_t::max();
|
||||
bool loop = false;
|
||||
bool reverse = false;
|
||||
float durationInSecs = 0;
|
||||
};
|
||||
|
||||
struct GltfAnimation : AnimationStatus
|
||||
{
|
||||
int index = -1;
|
||||
};
|
||||
|
||||
//
|
||||
// Use this to construct a dynamic (i.e. non-glTF embedded) morph target animation.
|
||||
//
|
||||
struct MorphAnimation : AnimationStatus
|
||||
{
|
||||
utils::Entity meshTarget;
|
||||
int numFrames = -1;
|
||||
float frameLengthInMs = 0;
|
||||
std::vector<float> frameData;
|
||||
std::vector<int> morphIndices;
|
||||
int lengthInFrames;
|
||||
};
|
||||
|
||||
//
|
||||
// Use this to construct a dynamic (i.e. non-glTF embedded) bone/joint animation.
|
||||
//
|
||||
struct BoneAnimation : AnimationStatus
|
||||
{
|
||||
size_t boneIndex;
|
||||
std::vector<utils::Entity> meshTargets;
|
||||
size_t skinIndex = 0;
|
||||
int lengthInFrames;
|
||||
float frameLengthInMs = 0;
|
||||
std::vector<math::mat4f> frameData;
|
||||
};
|
||||
|
||||
struct AnimationComponent
|
||||
{
|
||||
std::variant<FilamentInstance *, Entity> target;
|
||||
std::vector<math::mat4f> initialJointTransforms;
|
||||
std::vector<GltfAnimation> gltfAnimations;
|
||||
std::vector<MorphAnimation> morphAnimations;
|
||||
std::vector<BoneAnimation> boneAnimations;
|
||||
|
||||
// the index of the last active glTF animation,
|
||||
// used to cross-fade
|
||||
int fadeGltfAnimationIndex = -1;
|
||||
float fadeDuration = 0.0f;
|
||||
float fadeOutAnimationStart = 0.0f;
|
||||
};
|
||||
|
||||
class AnimationComponentManager : public utils::SingleInstanceComponentManager<AnimationComponent>
|
||||
{
|
||||
|
||||
filament::TransformManager &_transformManager;
|
||||
filament::RenderableManager &_renderableManager;
|
||||
|
||||
public:
|
||||
AnimationComponentManager(
|
||||
filament::TransformManager &transformManager,
|
||||
filament::RenderableManager &renderableManager) : _transformManager(transformManager),
|
||||
_renderableManager(renderableManager){};
|
||||
|
||||
void addAnimationComponent(std::variant<FilamentInstance *, Entity> target)
|
||||
{
|
||||
AnimationComponent animationComponent;
|
||||
animationComponent.target = target;
|
||||
EntityInstanceBase::Type componentInstance;
|
||||
if (std::holds_alternative<FilamentInstance *>(target))
|
||||
{
|
||||
auto instance = std::get<FilamentInstance *>(target);
|
||||
const auto joints = instance->getJointsAt(0);
|
||||
|
||||
for (int i = 0; i < instance->getJointCountAt(0); i++)
|
||||
{
|
||||
const auto joint = joints[i];
|
||||
const auto &jointTransformInstance = _transformManager.getInstance(joint);
|
||||
const auto &jointTransform = _transformManager.getTransform(jointTransformInstance);
|
||||
animationComponent.initialJointTransforms.push_back(jointTransform);
|
||||
}
|
||||
componentInstance = addComponent(instance->getRoot());
|
||||
}
|
||||
else
|
||||
{
|
||||
componentInstance = addComponent(std::get<Entity>(target));
|
||||
}
|
||||
|
||||
this->elementAt<0>(componentInstance) = animationComponent;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
auto now = high_resolution_clock::now();
|
||||
|
||||
for (auto it = begin(); it < end(); it++)
|
||||
{
|
||||
const auto &entity = getEntity(it);
|
||||
|
||||
auto componentInstance = getInstance(entity);
|
||||
auto &animationComponent = elementAt<0>(componentInstance);
|
||||
|
||||
auto &morphAnimations = animationComponent.morphAnimations;
|
||||
|
||||
if (std::holds_alternative<FilamentInstance *>(animationComponent.target))
|
||||
{
|
||||
auto target = std::get<FilamentInstance *>(animationComponent.target);
|
||||
auto animator = target->getAnimator();
|
||||
auto &gltfAnimations = animationComponent.gltfAnimations;
|
||||
auto &boneAnimations = animationComponent.boneAnimations;
|
||||
|
||||
for (int i = ((int)gltfAnimations.size()) - 1; i >= 0; i--)
|
||||
{
|
||||
|
||||
auto animationStatus = animationComponent.gltfAnimations[i];
|
||||
|
||||
auto elapsedInSecs = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - animationStatus.start).count()) / 1000.0f;
|
||||
|
||||
if (!animationStatus.loop && elapsedInSecs >= animationStatus.durationInSecs)
|
||||
{
|
||||
animator->applyAnimation(animationStatus.index, animationStatus.durationInSecs - 0.001);
|
||||
animator->updateBoneMatrices();
|
||||
gltfAnimations.erase(gltfAnimations.begin() + i);
|
||||
animationComponent.fadeGltfAnimationIndex = -1;
|
||||
continue;
|
||||
}
|
||||
animator->applyAnimation(animationStatus.index, elapsedInSecs);
|
||||
|
||||
if (animationComponent.fadeGltfAnimationIndex != -1 && elapsedInSecs < animationComponent.fadeDuration)
|
||||
{
|
||||
// cross-fade
|
||||
auto fadeFromTime = animationComponent.fadeOutAnimationStart + elapsedInSecs;
|
||||
auto alpha = elapsedInSecs / animationComponent.fadeDuration;
|
||||
animator->applyCrossFade(animationComponent.fadeGltfAnimationIndex, fadeFromTime, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
animator->updateBoneMatrices();
|
||||
|
||||
for (int i = (int)boneAnimations.size() - 1; i >= 0; i--)
|
||||
{
|
||||
auto animationStatus = boneAnimations[i];
|
||||
|
||||
auto elapsedInSecs = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - animationStatus.start).count()) / 1000.0f;
|
||||
|
||||
if (!animationStatus.loop && elapsedInSecs >= animationStatus.durationInSecs)
|
||||
{
|
||||
boneAnimations.erase(boneAnimations.begin() + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
float elapsedFrames = elapsedInSecs * 1000.0f / animationStatus.frameLengthInMs;
|
||||
|
||||
int currFrame = static_cast<int>(elapsedFrames) % animationStatus.lengthInFrames;
|
||||
float delta = elapsedFrames - currFrame;
|
||||
int nextFrame = currFrame;
|
||||
auto restLocalTransform = animationComponent.initialJointTransforms[animationStatus.boneIndex];
|
||||
|
||||
// offset from the end if reverse
|
||||
if (animationStatus.reverse)
|
||||
{
|
||||
currFrame = animationStatus.lengthInFrames - currFrame;
|
||||
if (currFrame > 0)
|
||||
{
|
||||
nextFrame = currFrame - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextFrame = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currFrame < animationStatus.lengthInFrames - 1)
|
||||
{
|
||||
nextFrame = currFrame + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextFrame = currFrame;
|
||||
}
|
||||
}
|
||||
|
||||
// simple linear interpolation
|
||||
math::mat4f curr = (1 - delta) * (restLocalTransform * animationStatus.frameData[currFrame]);
|
||||
math::mat4f next = delta * (restLocalTransform * animationStatus.frameData[nextFrame]);
|
||||
math::mat4f localTransform = curr + next;
|
||||
|
||||
const Entity joint = target->getJointsAt(animationStatus.skinIndex)[animationStatus.boneIndex];
|
||||
|
||||
auto jointTransform = _transformManager.getInstance(joint);
|
||||
|
||||
_transformManager.setTransform(jointTransform, localTransform);
|
||||
|
||||
animator->updateBoneMatrices();
|
||||
|
||||
if (animationStatus.loop && elapsedInSecs >= animationStatus.durationInSecs)
|
||||
{
|
||||
animationStatus.start = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = (int)morphAnimations.size() - 1; i >= 0; i--)
|
||||
{
|
||||
|
||||
auto animationStatus = morphAnimations[i];
|
||||
|
||||
auto elapsedInSecs = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - animationStatus.start).count()) / 1000.0f;
|
||||
|
||||
if (!animationStatus.loop && elapsedInSecs >= animationStatus.durationInSecs)
|
||||
{
|
||||
morphAnimations.erase(morphAnimations.begin() + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
int frameNumber = static_cast<int>(elapsedInSecs * 1000.0f / animationStatus.frameLengthInMs) % animationStatus.lengthInFrames;
|
||||
// offset from the end if reverse
|
||||
if (animationStatus.reverse)
|
||||
{
|
||||
frameNumber = animationStatus.lengthInFrames - frameNumber;
|
||||
}
|
||||
auto baseOffset = frameNumber * animationStatus.morphIndices.size();
|
||||
for (int i = 0; i < animationStatus.morphIndices.size(); i++)
|
||||
{
|
||||
auto morphIndex = animationStatus.morphIndices[i];
|
||||
// set the weights appropriately
|
||||
_renderableManager.setMorphWeights(
|
||||
_renderableManager.getInstance(animationStatus.meshTarget),
|
||||
animationStatus.frameData.data() + baseOffset + i,
|
||||
1,
|
||||
morphIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/Entity.h"
|
||||
#include "utils/EntityInstance.h"
|
||||
#include "utils/SingleInstanceComponentManager.h"
|
||||
#include "filament/TransformManager.h"
|
||||
#include "gltfio/FilamentAsset.h"
|
||||
#include "gltfio/FilamentInstance.h"
|
||||
#include "Log.hpp"
|
||||
|
||||
namespace flutter_filament
|
||||
{
|
||||
|
||||
typedef void(*CollisionCallback)(int32_t entityId1, int32_t entityId2) ;
|
||||
class CollisionComponentManager : public utils::SingleInstanceComponentManager<filament::Aabb, CollisionCallback, bool> {
|
||||
|
||||
const filament::TransformManager& _transformManager;
|
||||
public:
|
||||
CollisionComponentManager(const filament::TransformManager& transformManager) : _transformManager(transformManager) {}
|
||||
|
||||
std::vector<filament::math::float3> collides(utils::Entity transformingEntity, filament::Aabb sourceBox) {
|
||||
auto sourceCorners = sourceBox.getCorners();
|
||||
std::vector<filament::math::float3> collisionAxes;
|
||||
for(auto it = begin(); it < end(); it++) {
|
||||
auto entity = getEntity(it);
|
||||
|
||||
if(entity == transformingEntity) {
|
||||
continue;
|
||||
}
|
||||
auto targetXformInstance = _transformManager.getInstance(entity);
|
||||
auto targetXform = _transformManager.getWorldTransform(targetXformInstance);
|
||||
auto targetBox = elementAt<0>(it).transform(targetXform);
|
||||
auto targetCorners = targetBox.getCorners();
|
||||
|
||||
// Log("Checking collision for entity %d with aabb extent %f %f %f against source entity %d with aabb extent %f %f %f", entity, targetBox.extent().x, targetBox.extent().y, targetBox.extent().z, transformingEntityId, sourceBox.extent().x, sourceBox.extent().y, sourceBox.extent().z);
|
||||
|
||||
bool collided = false;
|
||||
|
||||
// iterate over every vertex in the source/target AABB
|
||||
for(int i = 0; i < 8; i++) {
|
||||
auto intersecting = sourceCorners.vertices[i];
|
||||
auto min = targetBox.min;
|
||||
auto max = targetBox.max;
|
||||
|
||||
// if the vertex has insersected with the target/source AABB
|
||||
if(targetBox.contains(sourceCorners.vertices[i]) <= 0) {
|
||||
collided = true;
|
||||
// Log("targetBox %f %f %f contains source vertex %f %f %f", targetBox.extent().x, targetBox.extent().y, targetBox.extent().z, sourceCorners.vertices[i].x, sourceCorners.vertices[i].y, sourceCorners.vertices[i].z);
|
||||
} else if(sourceBox.contains(targetCorners.vertices[i]) <= 0) {
|
||||
// Log("sourceBox %f %f %f contains target vertex %f %f %f", sourceBox.extent().x, sourceBox.extent().y, sourceBox.extent().z, targetCorners.vertices[i].x, targetCorners.vertices[i].y, targetCorners.vertices[i].z);
|
||||
collided = true;
|
||||
intersecting = targetCorners.vertices[i];
|
||||
min = sourceBox.min;
|
||||
max = sourceBox.max;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
auto affectsTransform = elementAt<2>(it);
|
||||
if(affectsTransform) {
|
||||
float xmin = min.x - intersecting.x;
|
||||
float ymin = min.y - intersecting.y;
|
||||
float zmin = min.z - intersecting.z;
|
||||
float xmax = intersecting.x - max.x;
|
||||
float ymax = intersecting.y - max.y;
|
||||
float zmax = intersecting.z - max.z;
|
||||
|
||||
auto maxD = std::max(xmin,std::max(ymin,std::max(zmin,std::max(xmax,std::max(ymax,zmax)))));
|
||||
filament::math::float3 axis;
|
||||
if(maxD == xmin) {
|
||||
axis = {-1.0f,0.0f, 0.0f};
|
||||
} else if(maxD == ymin) {
|
||||
axis = {0.0f,-1.0f, 0.0f};
|
||||
} else if(maxD == zmin) {
|
||||
axis = {0.0f,0.0f, -1.0f};
|
||||
} else if(maxD == xmax) {
|
||||
axis = {1.0f,0.0f, 0.0f};
|
||||
} else if(maxD == ymax) {
|
||||
axis = {0.0f,1.0f, 0.0f};
|
||||
} else {
|
||||
axis = { 0.0f, 0.0f, 1.0f};
|
||||
}
|
||||
collisionAxes.push_back(axis);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(collided) {
|
||||
auto callback = elementAt<1>(it);
|
||||
if(callback) {
|
||||
callback(utils::Entity::smuggle(entity), utils::Entity::smuggle(transformingEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return collisionAxes;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
3621
dart_filament/native/include/filament/GL/glcorearb.h
Normal file
3621
dart_filament/native/include/filament/GL/glcorearb.h
Normal file
File diff suppressed because it is too large
Load Diff
12050
dart_filament/native/include/filament/GL/glext.h
Normal file
12050
dart_filament/native/include/filament/GL/glext.h
Normal file
File diff suppressed because it is too large
Load Diff
850
dart_filament/native/include/filament/GL/wglext.h
Normal file
850
dart_filament/native/include/filament/GL/wglext.h
Normal file
@@ -0,0 +1,850 @@
|
||||
#ifndef __wglext_h_
|
||||
#define __wglext_h_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Copyright (c) 2013-2017 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
/*
|
||||
** This header is generated from the Khronos OpenGL / OpenGL ES XML
|
||||
** API Registry. The current version of the Registry, generator scripts
|
||||
** used to make the header, and the header can be found at
|
||||
** https://github.com/KhronosGroup/OpenGL-Registry
|
||||
*/
|
||||
|
||||
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define WGL_WGLEXT_VERSION 20171125
|
||||
|
||||
/* Generated C header for:
|
||||
* API: wgl
|
||||
* Versions considered: .*
|
||||
* Versions emitted: _nomatch_^
|
||||
* Default extensions included: wgl
|
||||
* Additional extensions included: _nomatch_^
|
||||
* Extensions removed: _nomatch_^
|
||||
*/
|
||||
|
||||
#ifndef WGL_ARB_buffer_region
|
||||
#define WGL_ARB_buffer_region 1
|
||||
#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
|
||||
#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002
|
||||
#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004
|
||||
#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008
|
||||
typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType);
|
||||
typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion);
|
||||
typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height);
|
||||
typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
HANDLE WINAPI wglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uType);
|
||||
VOID WINAPI wglDeleteBufferRegionARB (HANDLE hRegion);
|
||||
BOOL WINAPI wglSaveBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height);
|
||||
BOOL WINAPI wglRestoreBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
|
||||
#endif
|
||||
#endif /* WGL_ARB_buffer_region */
|
||||
|
||||
#ifndef WGL_ARB_context_flush_control
|
||||
#define WGL_ARB_context_flush_control 1
|
||||
#define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097
|
||||
#define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0
|
||||
#define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
|
||||
#endif /* WGL_ARB_context_flush_control */
|
||||
|
||||
#ifndef WGL_ARB_create_context
|
||||
#define WGL_ARB_create_context 1
|
||||
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001
|
||||
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
|
||||
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
|
||||
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
|
||||
#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
|
||||
#define WGL_CONTEXT_FLAGS_ARB 0x2094
|
||||
#define ERROR_INVALID_VERSION_ARB 0x2095
|
||||
typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
HGLRC WINAPI wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int *attribList);
|
||||
#endif
|
||||
#endif /* WGL_ARB_create_context */
|
||||
|
||||
#ifndef WGL_ARB_create_context_no_error
|
||||
#define WGL_ARB_create_context_no_error 1
|
||||
#define WGL_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
|
||||
#endif /* WGL_ARB_create_context_no_error */
|
||||
|
||||
#ifndef WGL_ARB_create_context_profile
|
||||
#define WGL_ARB_create_context_profile 1
|
||||
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
|
||||
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
|
||||
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
|
||||
#define ERROR_INVALID_PROFILE_ARB 0x2096
|
||||
#endif /* WGL_ARB_create_context_profile */
|
||||
|
||||
#ifndef WGL_ARB_create_context_robustness
|
||||
#define WGL_ARB_create_context_robustness 1
|
||||
#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
|
||||
#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
|
||||
#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
|
||||
#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
|
||||
#endif /* WGL_ARB_create_context_robustness */
|
||||
|
||||
#ifndef WGL_ARB_extensions_string
|
||||
#define WGL_ARB_extensions_string 1
|
||||
typedef const char *(WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
const char *WINAPI wglGetExtensionsStringARB (HDC hdc);
|
||||
#endif
|
||||
#endif /* WGL_ARB_extensions_string */
|
||||
|
||||
#ifndef WGL_ARB_framebuffer_sRGB
|
||||
#define WGL_ARB_framebuffer_sRGB 1
|
||||
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
|
||||
#endif /* WGL_ARB_framebuffer_sRGB */
|
||||
|
||||
#ifndef WGL_ARB_make_current_read
|
||||
#define WGL_ARB_make_current_read 1
|
||||
#define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043
|
||||
#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054
|
||||
typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
|
||||
typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (void);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
|
||||
HDC WINAPI wglGetCurrentReadDCARB (void);
|
||||
#endif
|
||||
#endif /* WGL_ARB_make_current_read */
|
||||
|
||||
#ifndef WGL_ARB_multisample
|
||||
#define WGL_ARB_multisample 1
|
||||
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
|
||||
#define WGL_SAMPLES_ARB 0x2042
|
||||
#endif /* WGL_ARB_multisample */
|
||||
|
||||
#ifndef WGL_ARB_pbuffer
|
||||
#define WGL_ARB_pbuffer 1
|
||||
DECLARE_HANDLE(HPBUFFERARB);
|
||||
#define WGL_DRAW_TO_PBUFFER_ARB 0x202D
|
||||
#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
|
||||
#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
|
||||
#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
|
||||
#define WGL_PBUFFER_LARGEST_ARB 0x2033
|
||||
#define WGL_PBUFFER_WIDTH_ARB 0x2034
|
||||
#define WGL_PBUFFER_HEIGHT_ARB 0x2035
|
||||
#define WGL_PBUFFER_LOST_ARB 0x2036
|
||||
typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
|
||||
typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer);
|
||||
typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC);
|
||||
typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
HPBUFFERARB WINAPI wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
|
||||
HDC WINAPI wglGetPbufferDCARB (HPBUFFERARB hPbuffer);
|
||||
int WINAPI wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC);
|
||||
BOOL WINAPI wglDestroyPbufferARB (HPBUFFERARB hPbuffer);
|
||||
BOOL WINAPI wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
|
||||
#endif
|
||||
#endif /* WGL_ARB_pbuffer */
|
||||
|
||||
#ifndef WGL_ARB_pixel_format
|
||||
#define WGL_ARB_pixel_format 1
|
||||
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
|
||||
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
|
||||
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
|
||||
#define WGL_ACCELERATION_ARB 0x2003
|
||||
#define WGL_NEED_PALETTE_ARB 0x2004
|
||||
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
|
||||
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
|
||||
#define WGL_SWAP_METHOD_ARB 0x2007
|
||||
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
|
||||
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
|
||||
#define WGL_TRANSPARENT_ARB 0x200A
|
||||
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
|
||||
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
|
||||
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
|
||||
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
|
||||
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
|
||||
#define WGL_SHARE_DEPTH_ARB 0x200C
|
||||
#define WGL_SHARE_STENCIL_ARB 0x200D
|
||||
#define WGL_SHARE_ACCUM_ARB 0x200E
|
||||
#define WGL_SUPPORT_GDI_ARB 0x200F
|
||||
#define WGL_SUPPORT_OPENGL_ARB 0x2010
|
||||
#define WGL_DOUBLE_BUFFER_ARB 0x2011
|
||||
#define WGL_STEREO_ARB 0x2012
|
||||
#define WGL_PIXEL_TYPE_ARB 0x2013
|
||||
#define WGL_COLOR_BITS_ARB 0x2014
|
||||
#define WGL_RED_BITS_ARB 0x2015
|
||||
#define WGL_RED_SHIFT_ARB 0x2016
|
||||
#define WGL_GREEN_BITS_ARB 0x2017
|
||||
#define WGL_GREEN_SHIFT_ARB 0x2018
|
||||
#define WGL_BLUE_BITS_ARB 0x2019
|
||||
#define WGL_BLUE_SHIFT_ARB 0x201A
|
||||
#define WGL_ALPHA_BITS_ARB 0x201B
|
||||
#define WGL_ALPHA_SHIFT_ARB 0x201C
|
||||
#define WGL_ACCUM_BITS_ARB 0x201D
|
||||
#define WGL_ACCUM_RED_BITS_ARB 0x201E
|
||||
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
|
||||
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
|
||||
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
|
||||
#define WGL_DEPTH_BITS_ARB 0x2022
|
||||
#define WGL_STENCIL_BITS_ARB 0x2023
|
||||
#define WGL_AUX_BUFFERS_ARB 0x2024
|
||||
#define WGL_NO_ACCELERATION_ARB 0x2025
|
||||
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
|
||||
#define WGL_FULL_ACCELERATION_ARB 0x2027
|
||||
#define WGL_SWAP_EXCHANGE_ARB 0x2028
|
||||
#define WGL_SWAP_COPY_ARB 0x2029
|
||||
#define WGL_SWAP_UNDEFINED_ARB 0x202A
|
||||
#define WGL_TYPE_RGBA_ARB 0x202B
|
||||
#define WGL_TYPE_COLORINDEX_ARB 0x202C
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
|
||||
typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
|
||||
BOOL WINAPI wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
|
||||
BOOL WINAPI wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
|
||||
#endif
|
||||
#endif /* WGL_ARB_pixel_format */
|
||||
|
||||
#ifndef WGL_ARB_pixel_format_float
|
||||
#define WGL_ARB_pixel_format_float 1
|
||||
#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
|
||||
#endif /* WGL_ARB_pixel_format_float */
|
||||
|
||||
#ifndef WGL_ARB_render_texture
|
||||
#define WGL_ARB_render_texture 1
|
||||
#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070
|
||||
#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071
|
||||
#define WGL_TEXTURE_FORMAT_ARB 0x2072
|
||||
#define WGL_TEXTURE_TARGET_ARB 0x2073
|
||||
#define WGL_MIPMAP_TEXTURE_ARB 0x2074
|
||||
#define WGL_TEXTURE_RGB_ARB 0x2075
|
||||
#define WGL_TEXTURE_RGBA_ARB 0x2076
|
||||
#define WGL_NO_TEXTURE_ARB 0x2077
|
||||
#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078
|
||||
#define WGL_TEXTURE_1D_ARB 0x2079
|
||||
#define WGL_TEXTURE_2D_ARB 0x207A
|
||||
#define WGL_MIPMAP_LEVEL_ARB 0x207B
|
||||
#define WGL_CUBE_MAP_FACE_ARB 0x207C
|
||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D
|
||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E
|
||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F
|
||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080
|
||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081
|
||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082
|
||||
#define WGL_FRONT_LEFT_ARB 0x2083
|
||||
#define WGL_FRONT_RIGHT_ARB 0x2084
|
||||
#define WGL_BACK_LEFT_ARB 0x2085
|
||||
#define WGL_BACK_RIGHT_ARB 0x2086
|
||||
#define WGL_AUX0_ARB 0x2087
|
||||
#define WGL_AUX1_ARB 0x2088
|
||||
#define WGL_AUX2_ARB 0x2089
|
||||
#define WGL_AUX3_ARB 0x208A
|
||||
#define WGL_AUX4_ARB 0x208B
|
||||
#define WGL_AUX5_ARB 0x208C
|
||||
#define WGL_AUX6_ARB 0x208D
|
||||
#define WGL_AUX7_ARB 0x208E
|
||||
#define WGL_AUX8_ARB 0x208F
|
||||
#define WGL_AUX9_ARB 0x2090
|
||||
typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
|
||||
BOOL WINAPI wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
|
||||
BOOL WINAPI wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList);
|
||||
#endif
|
||||
#endif /* WGL_ARB_render_texture */
|
||||
|
||||
#ifndef WGL_ARB_robustness_application_isolation
|
||||
#define WGL_ARB_robustness_application_isolation 1
|
||||
#define WGL_CONTEXT_RESET_ISOLATION_BIT_ARB 0x00000008
|
||||
#endif /* WGL_ARB_robustness_application_isolation */
|
||||
|
||||
#ifndef WGL_ARB_robustness_share_group_isolation
|
||||
#define WGL_ARB_robustness_share_group_isolation 1
|
||||
#endif /* WGL_ARB_robustness_share_group_isolation */
|
||||
|
||||
#ifndef WGL_3DFX_multisample
|
||||
#define WGL_3DFX_multisample 1
|
||||
#define WGL_SAMPLE_BUFFERS_3DFX 0x2060
|
||||
#define WGL_SAMPLES_3DFX 0x2061
|
||||
#endif /* WGL_3DFX_multisample */
|
||||
|
||||
#ifndef WGL_3DL_stereo_control
|
||||
#define WGL_3DL_stereo_control 1
|
||||
#define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055
|
||||
#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056
|
||||
#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057
|
||||
#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058
|
||||
typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglSetStereoEmitterState3DL (HDC hDC, UINT uState);
|
||||
#endif
|
||||
#endif /* WGL_3DL_stereo_control */
|
||||
|
||||
#ifndef WGL_AMD_gpu_association
|
||||
#define WGL_AMD_gpu_association 1
|
||||
#define WGL_GPU_VENDOR_AMD 0x1F00
|
||||
#define WGL_GPU_RENDERER_STRING_AMD 0x1F01
|
||||
#define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02
|
||||
#define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2
|
||||
#define WGL_GPU_RAM_AMD 0x21A3
|
||||
#define WGL_GPU_CLOCK_AMD 0x21A4
|
||||
#define WGL_GPU_NUM_PIPES_AMD 0x21A5
|
||||
#define WGL_GPU_NUM_SIMD_AMD 0x21A6
|
||||
#define WGL_GPU_NUM_RB_AMD 0x21A7
|
||||
#define WGL_GPU_NUM_SPI_AMD 0x21A8
|
||||
typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT *ids);
|
||||
typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, int property, GLenum dataType, UINT size, void *data);
|
||||
typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc);
|
||||
typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id);
|
||||
typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int *attribList);
|
||||
typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc);
|
||||
typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc);
|
||||
typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void);
|
||||
typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
UINT WINAPI wglGetGPUIDsAMD (UINT maxCount, UINT *ids);
|
||||
INT WINAPI wglGetGPUInfoAMD (UINT id, int property, GLenum dataType, UINT size, void *data);
|
||||
UINT WINAPI wglGetContextGPUIDAMD (HGLRC hglrc);
|
||||
HGLRC WINAPI wglCreateAssociatedContextAMD (UINT id);
|
||||
HGLRC WINAPI wglCreateAssociatedContextAttribsAMD (UINT id, HGLRC hShareContext, const int *attribList);
|
||||
BOOL WINAPI wglDeleteAssociatedContextAMD (HGLRC hglrc);
|
||||
BOOL WINAPI wglMakeAssociatedContextCurrentAMD (HGLRC hglrc);
|
||||
HGLRC WINAPI wglGetCurrentAssociatedContextAMD (void);
|
||||
VOID WINAPI wglBlitContextFramebufferAMD (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
|
||||
#endif
|
||||
#endif /* WGL_AMD_gpu_association */
|
||||
|
||||
#ifndef WGL_ATI_pixel_format_float
|
||||
#define WGL_ATI_pixel_format_float 1
|
||||
#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0
|
||||
#endif /* WGL_ATI_pixel_format_float */
|
||||
|
||||
#ifndef WGL_EXT_colorspace
|
||||
#define WGL_EXT_colorspace 1
|
||||
#define WGL_COLORSPACE_EXT 0x3087
|
||||
#define WGL_COLORSPACE_SRGB_EXT 0x3089
|
||||
#define WGL_COLORSPACE_LINEAR_EXT 0x308A
|
||||
#endif /* WGL_EXT_colorspace */
|
||||
|
||||
#ifndef WGL_EXT_create_context_es2_profile
|
||||
#define WGL_EXT_create_context_es2_profile 1
|
||||
#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
|
||||
#endif /* WGL_EXT_create_context_es2_profile */
|
||||
|
||||
#ifndef WGL_EXT_create_context_es_profile
|
||||
#define WGL_EXT_create_context_es_profile 1
|
||||
#define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004
|
||||
#endif /* WGL_EXT_create_context_es_profile */
|
||||
|
||||
#ifndef WGL_EXT_depth_float
|
||||
#define WGL_EXT_depth_float 1
|
||||
#define WGL_DEPTH_FLOAT_EXT 0x2040
|
||||
#endif /* WGL_EXT_depth_float */
|
||||
|
||||
#ifndef WGL_EXT_display_color_table
|
||||
#define WGL_EXT_display_color_table 1
|
||||
typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id);
|
||||
typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (const GLushort *table, GLuint length);
|
||||
typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id);
|
||||
typedef VOID (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
GLboolean WINAPI wglCreateDisplayColorTableEXT (GLushort id);
|
||||
GLboolean WINAPI wglLoadDisplayColorTableEXT (const GLushort *table, GLuint length);
|
||||
GLboolean WINAPI wglBindDisplayColorTableEXT (GLushort id);
|
||||
VOID WINAPI wglDestroyDisplayColorTableEXT (GLushort id);
|
||||
#endif
|
||||
#endif /* WGL_EXT_display_color_table */
|
||||
|
||||
#ifndef WGL_EXT_extensions_string
|
||||
#define WGL_EXT_extensions_string 1
|
||||
typedef const char *(WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
const char *WINAPI wglGetExtensionsStringEXT (void);
|
||||
#endif
|
||||
#endif /* WGL_EXT_extensions_string */
|
||||
|
||||
#ifndef WGL_EXT_framebuffer_sRGB
|
||||
#define WGL_EXT_framebuffer_sRGB 1
|
||||
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9
|
||||
#endif /* WGL_EXT_framebuffer_sRGB */
|
||||
|
||||
#ifndef WGL_EXT_make_current_read
|
||||
#define WGL_EXT_make_current_read 1
|
||||
#define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043
|
||||
typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
|
||||
typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (void);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
|
||||
HDC WINAPI wglGetCurrentReadDCEXT (void);
|
||||
#endif
|
||||
#endif /* WGL_EXT_make_current_read */
|
||||
|
||||
#ifndef WGL_EXT_multisample
|
||||
#define WGL_EXT_multisample 1
|
||||
#define WGL_SAMPLE_BUFFERS_EXT 0x2041
|
||||
#define WGL_SAMPLES_EXT 0x2042
|
||||
#endif /* WGL_EXT_multisample */
|
||||
|
||||
#ifndef WGL_EXT_pbuffer
|
||||
#define WGL_EXT_pbuffer 1
|
||||
DECLARE_HANDLE(HPBUFFEREXT);
|
||||
#define WGL_DRAW_TO_PBUFFER_EXT 0x202D
|
||||
#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E
|
||||
#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F
|
||||
#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030
|
||||
#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031
|
||||
#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032
|
||||
#define WGL_PBUFFER_LARGEST_EXT 0x2033
|
||||
#define WGL_PBUFFER_WIDTH_EXT 0x2034
|
||||
#define WGL_PBUFFER_HEIGHT_EXT 0x2035
|
||||
typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
|
||||
typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer);
|
||||
typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC);
|
||||
typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
HPBUFFEREXT WINAPI wglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
|
||||
HDC WINAPI wglGetPbufferDCEXT (HPBUFFEREXT hPbuffer);
|
||||
int WINAPI wglReleasePbufferDCEXT (HPBUFFEREXT hPbuffer, HDC hDC);
|
||||
BOOL WINAPI wglDestroyPbufferEXT (HPBUFFEREXT hPbuffer);
|
||||
BOOL WINAPI wglQueryPbufferEXT (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue);
|
||||
#endif
|
||||
#endif /* WGL_EXT_pbuffer */
|
||||
|
||||
#ifndef WGL_EXT_pixel_format
|
||||
#define WGL_EXT_pixel_format 1
|
||||
#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000
|
||||
#define WGL_DRAW_TO_WINDOW_EXT 0x2001
|
||||
#define WGL_DRAW_TO_BITMAP_EXT 0x2002
|
||||
#define WGL_ACCELERATION_EXT 0x2003
|
||||
#define WGL_NEED_PALETTE_EXT 0x2004
|
||||
#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005
|
||||
#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006
|
||||
#define WGL_SWAP_METHOD_EXT 0x2007
|
||||
#define WGL_NUMBER_OVERLAYS_EXT 0x2008
|
||||
#define WGL_NUMBER_UNDERLAYS_EXT 0x2009
|
||||
#define WGL_TRANSPARENT_EXT 0x200A
|
||||
#define WGL_TRANSPARENT_VALUE_EXT 0x200B
|
||||
#define WGL_SHARE_DEPTH_EXT 0x200C
|
||||
#define WGL_SHARE_STENCIL_EXT 0x200D
|
||||
#define WGL_SHARE_ACCUM_EXT 0x200E
|
||||
#define WGL_SUPPORT_GDI_EXT 0x200F
|
||||
#define WGL_SUPPORT_OPENGL_EXT 0x2010
|
||||
#define WGL_DOUBLE_BUFFER_EXT 0x2011
|
||||
#define WGL_STEREO_EXT 0x2012
|
||||
#define WGL_PIXEL_TYPE_EXT 0x2013
|
||||
#define WGL_COLOR_BITS_EXT 0x2014
|
||||
#define WGL_RED_BITS_EXT 0x2015
|
||||
#define WGL_RED_SHIFT_EXT 0x2016
|
||||
#define WGL_GREEN_BITS_EXT 0x2017
|
||||
#define WGL_GREEN_SHIFT_EXT 0x2018
|
||||
#define WGL_BLUE_BITS_EXT 0x2019
|
||||
#define WGL_BLUE_SHIFT_EXT 0x201A
|
||||
#define WGL_ALPHA_BITS_EXT 0x201B
|
||||
#define WGL_ALPHA_SHIFT_EXT 0x201C
|
||||
#define WGL_ACCUM_BITS_EXT 0x201D
|
||||
#define WGL_ACCUM_RED_BITS_EXT 0x201E
|
||||
#define WGL_ACCUM_GREEN_BITS_EXT 0x201F
|
||||
#define WGL_ACCUM_BLUE_BITS_EXT 0x2020
|
||||
#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021
|
||||
#define WGL_DEPTH_BITS_EXT 0x2022
|
||||
#define WGL_STENCIL_BITS_EXT 0x2023
|
||||
#define WGL_AUX_BUFFERS_EXT 0x2024
|
||||
#define WGL_NO_ACCELERATION_EXT 0x2025
|
||||
#define WGL_GENERIC_ACCELERATION_EXT 0x2026
|
||||
#define WGL_FULL_ACCELERATION_EXT 0x2027
|
||||
#define WGL_SWAP_EXCHANGE_EXT 0x2028
|
||||
#define WGL_SWAP_COPY_EXT 0x2029
|
||||
#define WGL_SWAP_UNDEFINED_EXT 0x202A
|
||||
#define WGL_TYPE_RGBA_EXT 0x202B
|
||||
#define WGL_TYPE_COLORINDEX_EXT 0x202C
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues);
|
||||
typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglGetPixelFormatAttribivEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
|
||||
BOOL WINAPI wglGetPixelFormatAttribfvEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues);
|
||||
BOOL WINAPI wglChoosePixelFormatEXT (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
|
||||
#endif
|
||||
#endif /* WGL_EXT_pixel_format */
|
||||
|
||||
#ifndef WGL_EXT_pixel_format_packed_float
|
||||
#define WGL_EXT_pixel_format_packed_float 1
|
||||
#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8
|
||||
#endif /* WGL_EXT_pixel_format_packed_float */
|
||||
|
||||
#ifndef WGL_EXT_swap_control
|
||||
#define WGL_EXT_swap_control 1
|
||||
typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
|
||||
typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglSwapIntervalEXT (int interval);
|
||||
int WINAPI wglGetSwapIntervalEXT (void);
|
||||
#endif
|
||||
#endif /* WGL_EXT_swap_control */
|
||||
|
||||
#ifndef WGL_EXT_swap_control_tear
|
||||
#define WGL_EXT_swap_control_tear 1
|
||||
#endif /* WGL_EXT_swap_control_tear */
|
||||
|
||||
#ifndef WGL_I3D_digital_video_control
|
||||
#define WGL_I3D_digital_video_control 1
|
||||
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050
|
||||
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051
|
||||
#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052
|
||||
#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053
|
||||
typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue);
|
||||
typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglGetDigitalVideoParametersI3D (HDC hDC, int iAttribute, int *piValue);
|
||||
BOOL WINAPI wglSetDigitalVideoParametersI3D (HDC hDC, int iAttribute, const int *piValue);
|
||||
#endif
|
||||
#endif /* WGL_I3D_digital_video_control */
|
||||
|
||||
#ifndef WGL_I3D_gamma
|
||||
#define WGL_I3D_gamma 1
|
||||
#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E
|
||||
#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F
|
||||
typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue);
|
||||
typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue);
|
||||
typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglGetGammaTableParametersI3D (HDC hDC, int iAttribute, int *piValue);
|
||||
BOOL WINAPI wglSetGammaTableParametersI3D (HDC hDC, int iAttribute, const int *piValue);
|
||||
BOOL WINAPI wglGetGammaTableI3D (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue);
|
||||
BOOL WINAPI wglSetGammaTableI3D (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue);
|
||||
#endif
|
||||
#endif /* WGL_I3D_gamma */
|
||||
|
||||
#ifndef WGL_I3D_genlock
|
||||
#define WGL_I3D_genlock 1
|
||||
#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044
|
||||
#define WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D 0x2045
|
||||
#define WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D 0x2046
|
||||
#define WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D 0x2047
|
||||
#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048
|
||||
#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049
|
||||
#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A
|
||||
#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B
|
||||
#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C
|
||||
typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC);
|
||||
typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC);
|
||||
typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL *pFlag);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT *uSource);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT *uEdge);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT *uRate);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT *uDelay);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglEnableGenlockI3D (HDC hDC);
|
||||
BOOL WINAPI wglDisableGenlockI3D (HDC hDC);
|
||||
BOOL WINAPI wglIsEnabledGenlockI3D (HDC hDC, BOOL *pFlag);
|
||||
BOOL WINAPI wglGenlockSourceI3D (HDC hDC, UINT uSource);
|
||||
BOOL WINAPI wglGetGenlockSourceI3D (HDC hDC, UINT *uSource);
|
||||
BOOL WINAPI wglGenlockSourceEdgeI3D (HDC hDC, UINT uEdge);
|
||||
BOOL WINAPI wglGetGenlockSourceEdgeI3D (HDC hDC, UINT *uEdge);
|
||||
BOOL WINAPI wglGenlockSampleRateI3D (HDC hDC, UINT uRate);
|
||||
BOOL WINAPI wglGetGenlockSampleRateI3D (HDC hDC, UINT *uRate);
|
||||
BOOL WINAPI wglGenlockSourceDelayI3D (HDC hDC, UINT uDelay);
|
||||
BOOL WINAPI wglGetGenlockSourceDelayI3D (HDC hDC, UINT *uDelay);
|
||||
BOOL WINAPI wglQueryGenlockMaxSourceDelayI3D (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay);
|
||||
#endif
|
||||
#endif /* WGL_I3D_genlock */
|
||||
|
||||
#ifndef WGL_I3D_image_buffer
|
||||
#define WGL_I3D_image_buffer 1
|
||||
#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001
|
||||
#define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002
|
||||
typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags);
|
||||
typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress);
|
||||
typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count);
|
||||
typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const LPVOID *pAddress, UINT count);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
LPVOID WINAPI wglCreateImageBufferI3D (HDC hDC, DWORD dwSize, UINT uFlags);
|
||||
BOOL WINAPI wglDestroyImageBufferI3D (HDC hDC, LPVOID pAddress);
|
||||
BOOL WINAPI wglAssociateImageBufferEventsI3D (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count);
|
||||
BOOL WINAPI wglReleaseImageBufferEventsI3D (HDC hDC, const LPVOID *pAddress, UINT count);
|
||||
#endif
|
||||
#endif /* WGL_I3D_image_buffer */
|
||||
|
||||
#ifndef WGL_I3D_swap_frame_lock
|
||||
#define WGL_I3D_swap_frame_lock 1
|
||||
typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (void);
|
||||
typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (void);
|
||||
typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL *pFlag);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL *pFlag);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglEnableFrameLockI3D (void);
|
||||
BOOL WINAPI wglDisableFrameLockI3D (void);
|
||||
BOOL WINAPI wglIsEnabledFrameLockI3D (BOOL *pFlag);
|
||||
BOOL WINAPI wglQueryFrameLockMasterI3D (BOOL *pFlag);
|
||||
#endif
|
||||
#endif /* WGL_I3D_swap_frame_lock */
|
||||
|
||||
#ifndef WGL_I3D_swap_frame_usage
|
||||
#define WGL_I3D_swap_frame_usage 1
|
||||
typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float *pUsage);
|
||||
typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void);
|
||||
typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglGetFrameUsageI3D (float *pUsage);
|
||||
BOOL WINAPI wglBeginFrameTrackingI3D (void);
|
||||
BOOL WINAPI wglEndFrameTrackingI3D (void);
|
||||
BOOL WINAPI wglQueryFrameTrackingI3D (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage);
|
||||
#endif
|
||||
#endif /* WGL_I3D_swap_frame_usage */
|
||||
|
||||
#ifndef WGL_NV_DX_interop
|
||||
#define WGL_NV_DX_interop 1
|
||||
#define WGL_ACCESS_READ_ONLY_NV 0x00000000
|
||||
#define WGL_ACCESS_READ_WRITE_NV 0x00000001
|
||||
#define WGL_ACCESS_WRITE_DISCARD_NV 0x00000002
|
||||
typedef BOOL (WINAPI * PFNWGLDXSETRESOURCESHAREHANDLENVPROC) (void *dxObject, HANDLE shareHandle);
|
||||
typedef HANDLE (WINAPI * PFNWGLDXOPENDEVICENVPROC) (void *dxDevice);
|
||||
typedef BOOL (WINAPI * PFNWGLDXCLOSEDEVICENVPROC) (HANDLE hDevice);
|
||||
typedef HANDLE (WINAPI * PFNWGLDXREGISTEROBJECTNVPROC) (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
|
||||
typedef BOOL (WINAPI * PFNWGLDXUNREGISTEROBJECTNVPROC) (HANDLE hDevice, HANDLE hObject);
|
||||
typedef BOOL (WINAPI * PFNWGLDXOBJECTACCESSNVPROC) (HANDLE hObject, GLenum access);
|
||||
typedef BOOL (WINAPI * PFNWGLDXLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects);
|
||||
typedef BOOL (WINAPI * PFNWGLDXUNLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglDXSetResourceShareHandleNV (void *dxObject, HANDLE shareHandle);
|
||||
HANDLE WINAPI wglDXOpenDeviceNV (void *dxDevice);
|
||||
BOOL WINAPI wglDXCloseDeviceNV (HANDLE hDevice);
|
||||
HANDLE WINAPI wglDXRegisterObjectNV (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
|
||||
BOOL WINAPI wglDXUnregisterObjectNV (HANDLE hDevice, HANDLE hObject);
|
||||
BOOL WINAPI wglDXObjectAccessNV (HANDLE hObject, GLenum access);
|
||||
BOOL WINAPI wglDXLockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects);
|
||||
BOOL WINAPI wglDXUnlockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects);
|
||||
#endif
|
||||
#endif /* WGL_NV_DX_interop */
|
||||
|
||||
#ifndef WGL_NV_DX_interop2
|
||||
#define WGL_NV_DX_interop2 1
|
||||
#endif /* WGL_NV_DX_interop2 */
|
||||
|
||||
#ifndef WGL_NV_copy_image
|
||||
#define WGL_NV_copy_image 1
|
||||
typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
|
||||
#endif
|
||||
#endif /* WGL_NV_copy_image */
|
||||
|
||||
#ifndef WGL_NV_delay_before_swap
|
||||
#define WGL_NV_delay_before_swap 1
|
||||
typedef BOOL (WINAPI * PFNWGLDELAYBEFORESWAPNVPROC) (HDC hDC, GLfloat seconds);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglDelayBeforeSwapNV (HDC hDC, GLfloat seconds);
|
||||
#endif
|
||||
#endif /* WGL_NV_delay_before_swap */
|
||||
|
||||
#ifndef WGL_NV_float_buffer
|
||||
#define WGL_NV_float_buffer 1
|
||||
#define WGL_FLOAT_COMPONENTS_NV 0x20B0
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4
|
||||
#define WGL_TEXTURE_FLOAT_R_NV 0x20B5
|
||||
#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6
|
||||
#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7
|
||||
#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8
|
||||
#endif /* WGL_NV_float_buffer */
|
||||
|
||||
#ifndef WGL_NV_gpu_affinity
|
||||
#define WGL_NV_gpu_affinity 1
|
||||
DECLARE_HANDLE(HGPUNV);
|
||||
struct _GPU_DEVICE {
|
||||
DWORD cb;
|
||||
CHAR DeviceName[32];
|
||||
CHAR DeviceString[128];
|
||||
DWORD Flags;
|
||||
RECT rcVirtualScreen;
|
||||
};
|
||||
typedef struct _GPU_DEVICE *PGPU_DEVICE;
|
||||
#define ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0
|
||||
#define ERROR_MISSING_AFFINITY_MASK_NV 0x20D1
|
||||
typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu);
|
||||
typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice);
|
||||
typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList);
|
||||
typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu);
|
||||
typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglEnumGpusNV (UINT iGpuIndex, HGPUNV *phGpu);
|
||||
BOOL WINAPI wglEnumGpuDevicesNV (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice);
|
||||
HDC WINAPI wglCreateAffinityDCNV (const HGPUNV *phGpuList);
|
||||
BOOL WINAPI wglEnumGpusFromAffinityDCNV (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu);
|
||||
BOOL WINAPI wglDeleteDCNV (HDC hdc);
|
||||
#endif
|
||||
#endif /* WGL_NV_gpu_affinity */
|
||||
|
||||
#ifndef WGL_NV_multisample_coverage
|
||||
#define WGL_NV_multisample_coverage 1
|
||||
#define WGL_COVERAGE_SAMPLES_NV 0x2042
|
||||
#define WGL_COLOR_SAMPLES_NV 0x20B9
|
||||
#endif /* WGL_NV_multisample_coverage */
|
||||
|
||||
#ifndef WGL_NV_present_video
|
||||
#define WGL_NV_present_video 1
|
||||
DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV);
|
||||
#define WGL_NUM_VIDEO_SLOTS_NV 0x20F0
|
||||
typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList);
|
||||
typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
int WINAPI wglEnumerateVideoDevicesNV (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList);
|
||||
BOOL WINAPI wglBindVideoDeviceNV (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList);
|
||||
BOOL WINAPI wglQueryCurrentContextNV (int iAttribute, int *piValue);
|
||||
#endif
|
||||
#endif /* WGL_NV_present_video */
|
||||
|
||||
#ifndef WGL_NV_render_depth_texture
|
||||
#define WGL_NV_render_depth_texture 1
|
||||
#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4
|
||||
#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5
|
||||
#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6
|
||||
#define WGL_DEPTH_COMPONENT_NV 0x20A7
|
||||
#endif /* WGL_NV_render_depth_texture */
|
||||
|
||||
#ifndef WGL_NV_render_texture_rectangle
|
||||
#define WGL_NV_render_texture_rectangle 1
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1
|
||||
#define WGL_TEXTURE_RECTANGLE_NV 0x20A2
|
||||
#endif /* WGL_NV_render_texture_rectangle */
|
||||
|
||||
#ifndef WGL_NV_swap_group
|
||||
#define WGL_NV_swap_group 1
|
||||
typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group);
|
||||
typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint *group, GLuint *barrier);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint *count);
|
||||
typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglJoinSwapGroupNV (HDC hDC, GLuint group);
|
||||
BOOL WINAPI wglBindSwapBarrierNV (GLuint group, GLuint barrier);
|
||||
BOOL WINAPI wglQuerySwapGroupNV (HDC hDC, GLuint *group, GLuint *barrier);
|
||||
BOOL WINAPI wglQueryMaxSwapGroupsNV (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers);
|
||||
BOOL WINAPI wglQueryFrameCountNV (HDC hDC, GLuint *count);
|
||||
BOOL WINAPI wglResetFrameCountNV (HDC hDC);
|
||||
#endif
|
||||
#endif /* WGL_NV_swap_group */
|
||||
|
||||
#ifndef WGL_NV_vertex_array_range
|
||||
#define WGL_NV_vertex_array_range 1
|
||||
typedef void *(WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
|
||||
typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
void *WINAPI wglAllocateMemoryNV (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
|
||||
void WINAPI wglFreeMemoryNV (void *pointer);
|
||||
#endif
|
||||
#endif /* WGL_NV_vertex_array_range */
|
||||
|
||||
#ifndef WGL_NV_video_capture
|
||||
#define WGL_NV_video_capture 1
|
||||
DECLARE_HANDLE(HVIDEOINPUTDEVICENV);
|
||||
#define WGL_UNIQUE_ID_NV 0x20CE
|
||||
#define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF
|
||||
typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice);
|
||||
typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList);
|
||||
typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue);
|
||||
typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice);
|
||||
UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList);
|
||||
BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
|
||||
BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue);
|
||||
BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
|
||||
#endif
|
||||
#endif /* WGL_NV_video_capture */
|
||||
|
||||
#ifndef WGL_NV_video_output
|
||||
#define WGL_NV_video_output 1
|
||||
DECLARE_HANDLE(HPVIDEODEV);
|
||||
#define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0
|
||||
#define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1
|
||||
#define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2
|
||||
#define WGL_VIDEO_OUT_COLOR_NV 0x20C3
|
||||
#define WGL_VIDEO_OUT_ALPHA_NV 0x20C4
|
||||
#define WGL_VIDEO_OUT_DEPTH_NV 0x20C5
|
||||
#define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6
|
||||
#define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7
|
||||
#define WGL_VIDEO_OUT_FRAME 0x20C8
|
||||
#define WGL_VIDEO_OUT_FIELD_1 0x20C9
|
||||
#define WGL_VIDEO_OUT_FIELD_2 0x20CA
|
||||
#define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB
|
||||
#define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC
|
||||
typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice);
|
||||
typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice);
|
||||
typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock);
|
||||
typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglGetVideoDeviceNV (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice);
|
||||
BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV hVideoDevice);
|
||||
BOOL WINAPI wglBindVideoImageNV (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer);
|
||||
BOOL WINAPI wglReleaseVideoImageNV (HPBUFFERARB hPbuffer, int iVideoBuffer);
|
||||
BOOL WINAPI wglSendPbufferToVideoNV (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock);
|
||||
BOOL WINAPI wglGetVideoInfoNV (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo);
|
||||
#endif
|
||||
#endif /* WGL_NV_video_output */
|
||||
|
||||
#ifndef WGL_OML_sync_control
|
||||
#define WGL_OML_sync_control 1
|
||||
typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc);
|
||||
typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32 *numerator, INT32 *denominator);
|
||||
typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder);
|
||||
typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder);
|
||||
typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc);
|
||||
typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc);
|
||||
#ifdef WGL_WGLEXT_PROTOTYPES
|
||||
BOOL WINAPI wglGetSyncValuesOML (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc);
|
||||
BOOL WINAPI wglGetMscRateOML (HDC hdc, INT32 *numerator, INT32 *denominator);
|
||||
INT64 WINAPI wglSwapBuffersMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder);
|
||||
INT64 WINAPI wglSwapLayerBuffersMscOML (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder);
|
||||
BOOL WINAPI wglWaitForMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc);
|
||||
BOOL WINAPI wglWaitForSbcOML (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc);
|
||||
#endif
|
||||
#endif /* WGL_OML_sync_control */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
2
dart_filament/native/include/filament/KHR/.clang-format
Normal file
2
dart_filament/native/include/filament/KHR/.clang-format
Normal file
@@ -0,0 +1,2 @@
|
||||
DisableFormat: true
|
||||
SortIncludes: false
|
||||
290
dart_filament/native/include/filament/KHR/khrplatform.h
Normal file
290
dart_filament/native/include/filament/KHR/khrplatform.h
Normal file
@@ -0,0 +1,290 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PRIVATE_ACQUIREDIMAGE_H
|
||||
#define TNT_FILAMENT_BACKEND_PRIVATE_ACQUIREDIMAGE_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class CallbackHandler;
|
||||
|
||||
// This lightweight POD allows us to bundle the state required to process an ACQUIRED stream.
|
||||
// Since these types of external images need to be moved around and queued up, an encapsulation is
|
||||
// very useful.
|
||||
|
||||
struct AcquiredImage {
|
||||
void* image = nullptr;
|
||||
backend::StreamCallback callback = nullptr;
|
||||
void* userData = nullptr;
|
||||
CallbackHandler* handler = nullptr;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PRIVATE_ACQUIREDIMAGE_H
|
||||
222
dart_filament/native/include/filament/backend/BufferDescriptor.h
Normal file
222
dart_filament/native/include/filament/backend/BufferDescriptor.h
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_BUFFERDESCRIPTOR_H
|
||||
#define TNT_FILAMENT_BACKEND_BUFFERDESCRIPTOR_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class CallbackHandler;
|
||||
|
||||
/**
|
||||
* A CPU memory-buffer descriptor, typically used to transfer data from the CPU to the GPU.
|
||||
*
|
||||
* A BufferDescriptor owns the memory buffer it references, therefore BufferDescriptor cannot
|
||||
* be copied, but can be moved.
|
||||
*
|
||||
* BufferDescriptor releases ownership of the memory-buffer when it's destroyed.
|
||||
*/
|
||||
class UTILS_PUBLIC BufferDescriptor {
|
||||
public:
|
||||
/**
|
||||
* Callback used to destroy the buffer data.
|
||||
* Guarantees:
|
||||
* Called on the main filament thread.
|
||||
*
|
||||
* Limitations:
|
||||
* Must be lightweight.
|
||||
* Must not call filament APIs.
|
||||
*/
|
||||
using Callback = void(*)(void* buffer, size_t size, void* user);
|
||||
|
||||
//! creates an empty descriptor
|
||||
BufferDescriptor() noexcept = default;
|
||||
|
||||
//! calls the callback to advertise BufferDescriptor no-longer owns the buffer
|
||||
~BufferDescriptor() noexcept {
|
||||
if (mCallback) {
|
||||
mCallback(buffer, size, mUser);
|
||||
}
|
||||
}
|
||||
|
||||
BufferDescriptor(const BufferDescriptor& rhs) = delete;
|
||||
BufferDescriptor& operator=(const BufferDescriptor& rhs) = delete;
|
||||
|
||||
BufferDescriptor(BufferDescriptor&& rhs) noexcept
|
||||
: buffer(rhs.buffer), size(rhs.size),
|
||||
mCallback(rhs.mCallback), mUser(rhs.mUser), mHandler(rhs.mHandler) {
|
||||
rhs.buffer = nullptr;
|
||||
rhs.mCallback = nullptr;
|
||||
}
|
||||
|
||||
BufferDescriptor& operator=(BufferDescriptor&& rhs) noexcept {
|
||||
if (this != &rhs) {
|
||||
buffer = rhs.buffer;
|
||||
size = rhs.size;
|
||||
mCallback = rhs.mCallback;
|
||||
mUser = rhs.mUser;
|
||||
mHandler = rhs.mHandler;
|
||||
rhs.buffer = nullptr;
|
||||
rhs.mCallback = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a BufferDescriptor that references a CPU memory-buffer
|
||||
* @param buffer Memory address of the CPU buffer to reference
|
||||
* @param size Size of the CPU buffer in bytes
|
||||
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
||||
* @param user An opaque user pointer passed to the callback function when it's called
|
||||
*/
|
||||
BufferDescriptor(void const* buffer, size_t size,
|
||||
Callback callback = nullptr, void* user = nullptr) noexcept
|
||||
: buffer(const_cast<void*>(buffer)), size(size), mCallback(callback), mUser(user) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a BufferDescriptor that references a CPU memory-buffer
|
||||
* @param buffer Memory address of the CPU buffer to reference
|
||||
* @param size Size of the CPU buffer in bytes
|
||||
* @param callback A callback used to release the CPU buffer from this BufferDescriptor
|
||||
* @param user An opaque user pointer passed to the callback function when it's called
|
||||
*/
|
||||
BufferDescriptor(void const* buffer, size_t size,
|
||||
CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept
|
||||
: buffer(const_cast<void*>(buffer)), size(size),
|
||||
mCallback(callback), mUser(user), mHandler(handler) {
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Helper to create a BufferDescriptor that uses a KNOWN method pointer w/ object passed
|
||||
* by pointer as the callback. e.g.:
|
||||
* auto bd = BufferDescriptor::make<Foo, &Foo::method>(buffer, size, foo);
|
||||
*
|
||||
* @param buffer Memory address of the CPU buffer to reference
|
||||
* @param size Size of the CPU buffer in bytes
|
||||
* @param handler Handler to use to dispatch the callback, or nullptr for the default handler
|
||||
* @return a new BufferDescriptor
|
||||
*/
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
static BufferDescriptor make(void const* buffer, size_t size, T* data,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return {
|
||||
buffer, size,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
(static_cast<T*>(u)->*method)(b, s);
|
||||
}, data
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create a BufferDescriptor that uses a functor as the callback.
|
||||
*
|
||||
* Caveats:
|
||||
* - DO NOT CALL setCallback() when using this helper.
|
||||
* - This make a heap allocation
|
||||
*
|
||||
* @param buffer Memory address of the CPU buffer to reference
|
||||
* @param size Size of the CPU buffer in bytes
|
||||
* @param functor functor of type f(void const* buffer, size_t size)
|
||||
* @param handler Handler to use to dispatch the callback, or nullptr for the default handler
|
||||
* @return a new BufferDescriptor
|
||||
*/
|
||||
template<typename T>
|
||||
static BufferDescriptor make(void const* buffer, size_t size, T&& functor,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return {
|
||||
buffer, size,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
},
|
||||
new T(std::forward<T>(functor))
|
||||
};
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set or replace the release callback function
|
||||
* @param callback The new callback function
|
||||
* @param user An opaque user pointer passed to the callbeck function when it's called
|
||||
*/
|
||||
void setCallback(Callback callback, void* user = nullptr) noexcept {
|
||||
this->mCallback = callback;
|
||||
this->mUser = user;
|
||||
this->mHandler = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or replace the release callback function
|
||||
* @param handler The Handler to use to dispatch the callback
|
||||
* @param callback The new callback function
|
||||
* @param user An opaque user pointer passed to the callbeck function when it's called
|
||||
*/
|
||||
void setCallback(CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept {
|
||||
mCallback = callback;
|
||||
mUser = user;
|
||||
mHandler = handler;
|
||||
}
|
||||
|
||||
//! Returns whether a release callback is set
|
||||
bool hasCallback() const noexcept { return mCallback != nullptr; }
|
||||
|
||||
//! Returns the currently set release callback function
|
||||
Callback getCallback() const noexcept {
|
||||
return mCallback;
|
||||
}
|
||||
|
||||
//! Returns the handler for this callback or nullptr if the default handler is to be used.
|
||||
CallbackHandler* getHandler() const noexcept {
|
||||
return mHandler;
|
||||
}
|
||||
|
||||
//! Returns the user opaque pointer associated to this BufferDescriptor
|
||||
void* getUser() const noexcept {
|
||||
return mUser;
|
||||
}
|
||||
|
||||
//! CPU memory-buffer virtual address
|
||||
void* buffer = nullptr;
|
||||
|
||||
//! CPU memory-buffer size in bytes
|
||||
size_t size = 0;
|
||||
|
||||
private:
|
||||
// callback when the buffer is consumed.
|
||||
Callback mCallback = nullptr;
|
||||
void* mUser = nullptr;
|
||||
CallbackHandler* mHandler = nullptr;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::BufferDescriptor& b);
|
||||
#endif
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_BUFFERDESCRIPTOR_H
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_CALLBACKHANDLER_H
|
||||
#define TNT_FILAMENT_BACKEND_CALLBACKHANDLER_H
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A generic interface to dispatch callbacks.
|
||||
*
|
||||
* All APIs that take a callback as argument also take a
|
||||
* CallbackHandler* which is used to dispatch the
|
||||
* callback: CallbackHandler::post() method is called from a service thread as soon
|
||||
* as possible (this will NEVER be the main thread), CallbackHandler::post()
|
||||
* is responsible for scheduling the callback onto the thread the
|
||||
* user desires.
|
||||
*
|
||||
* This is intended to make callbacks interoperate with
|
||||
* the platform/OS's own messaging system.
|
||||
*
|
||||
* CallbackHandler* can always be nullptr in which case the default handler is used. The
|
||||
* default handler always dispatches callbacks on filament's main thread opportunistically.
|
||||
*
|
||||
* Life time:
|
||||
* ---------
|
||||
*
|
||||
* Filament make no attempts to manage the life time of the CallbackHandler* and never takes
|
||||
* ownership.
|
||||
* In particular, this means that the CallbackHandler instance must stay valid until all
|
||||
* pending callbacks are been dispatched.
|
||||
*
|
||||
* Similarly, when shutting down filament, care must be taken to ensure that all pending callbacks
|
||||
* that might access filament's state have been dispatched. Filament can no longer ensure this
|
||||
* because callback execution is the responsibility of the CallbackHandler, which is external to
|
||||
* filament.
|
||||
* Typically, the concrete CallbackHandler would have a mechanism to drain and/or wait for all
|
||||
* callbacks to be processed.
|
||||
*
|
||||
*/
|
||||
class CallbackHandler {
|
||||
public:
|
||||
using Callback = void(*)(void* user);
|
||||
|
||||
/**
|
||||
* Schedules the callback to be called onto the appropriate thread.
|
||||
* Typically this will be the application's main thead.
|
||||
*
|
||||
* Must be thread-safe.
|
||||
*/
|
||||
virtual void post(void* user, Callback callback) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~CallbackHandler() = default;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_CALLBACKHANDLER_H
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PRIVATE_DRIVERAPIFORWARD_H
|
||||
#define TNT_FILAMENT_BACKEND_PRIVATE_DRIVERAPIFORWARD_H
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class CommandStream;
|
||||
|
||||
using DriverApi = CommandStream;
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PRIVATE_DRIVERAPIFORWARD_H
|
||||
1299
dart_filament/native/include/filament/backend/DriverEnums.h
Normal file
1299
dart_filament/native/include/filament/backend/DriverEnums.h
Normal file
File diff suppressed because it is too large
Load Diff
134
dart_filament/native/include/filament/backend/Handle.h
Normal file
134
dart_filament/native/include/filament/backend/Handle.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_HANDLE_H
|
||||
#define TNT_FILAMENT_BACKEND_HANDLE_H
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
#include <utils/ostream.h>
|
||||
#endif
|
||||
#include <utils/debug.h>
|
||||
|
||||
#include <type_traits> // FIXME: STL headers are not allowed in public headers
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
struct HwBufferObject;
|
||||
struct HwFence;
|
||||
struct HwIndexBuffer;
|
||||
struct HwProgram;
|
||||
struct HwRenderPrimitive;
|
||||
struct HwRenderTarget;
|
||||
struct HwSamplerGroup;
|
||||
struct HwStream;
|
||||
struct HwSwapChain;
|
||||
struct HwTexture;
|
||||
struct HwTimerQuery;
|
||||
struct HwVertexBufferInfo;
|
||||
struct HwVertexBuffer;
|
||||
|
||||
/*
|
||||
* A handle to a backend resource. HandleBase is for internal use only.
|
||||
* HandleBase *must* be a trivial for the purposes of calls, that is, it cannot have user-defined
|
||||
* copy or move constructors.
|
||||
*/
|
||||
|
||||
//! \privatesection
|
||||
|
||||
class HandleBase {
|
||||
public:
|
||||
using HandleId = uint32_t;
|
||||
static constexpr const HandleId nullid = HandleId{ UINT32_MAX };
|
||||
|
||||
constexpr HandleBase() noexcept: object(nullid) {}
|
||||
|
||||
// whether this Handle is initialized
|
||||
explicit operator bool() const noexcept { return object != nullid; }
|
||||
|
||||
// clear the handle, this doesn't free associated resources
|
||||
void clear() noexcept { object = nullid; }
|
||||
|
||||
// get this handle's handleId
|
||||
HandleId getId() const noexcept { return object; }
|
||||
|
||||
// initialize a handle, for internal use only.
|
||||
explicit HandleBase(HandleId id) noexcept : object(id) {
|
||||
assert_invariant(object != nullid); // usually means an uninitialized handle is used
|
||||
}
|
||||
|
||||
protected:
|
||||
HandleBase(HandleBase const& rhs) noexcept = default;
|
||||
HandleBase& operator=(HandleBase const& rhs) noexcept = default;
|
||||
|
||||
private:
|
||||
HandleId object;
|
||||
};
|
||||
|
||||
/**
|
||||
* Type-safe handle to backend resources
|
||||
* @tparam T Type of the resource
|
||||
*/
|
||||
template<typename T>
|
||||
struct Handle : public HandleBase {
|
||||
|
||||
Handle() noexcept = default;
|
||||
|
||||
Handle(Handle const& rhs) noexcept = default;
|
||||
|
||||
Handle& operator=(Handle const& rhs) noexcept = default;
|
||||
|
||||
explicit Handle(HandleId id) noexcept : HandleBase(id) { }
|
||||
|
||||
// compare handles of the same type
|
||||
bool operator==(const Handle& rhs) const noexcept { return getId() == rhs.getId(); }
|
||||
bool operator!=(const Handle& rhs) const noexcept { return getId() != rhs.getId(); }
|
||||
bool operator<(const Handle& rhs) const noexcept { return getId() < rhs.getId(); }
|
||||
bool operator<=(const Handle& rhs) const noexcept { return getId() <= rhs.getId(); }
|
||||
bool operator>(const Handle& rhs) const noexcept { return getId() > rhs.getId(); }
|
||||
bool operator>=(const Handle& rhs) const noexcept { return getId() >= rhs.getId(); }
|
||||
|
||||
// type-safe Handle cast
|
||||
template<typename B, typename = std::enable_if_t<std::is_base_of<T, B>::value> >
|
||||
Handle(Handle<B> const& base) noexcept : HandleBase(base) { } // NOLINT(hicpp-explicit-conversions,google-explicit-constructor)
|
||||
|
||||
private:
|
||||
#if !defined(NDEBUG)
|
||||
template <typename U>
|
||||
friend utils::io::ostream& operator<<(utils::io::ostream& out, const Handle<U>& h) noexcept;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Types used by the command stream
|
||||
// (we use this renaming because the macro-system doesn't deal well with "<" and ">")
|
||||
using BufferObjectHandle = Handle<HwBufferObject>;
|
||||
using FenceHandle = Handle<HwFence>;
|
||||
using IndexBufferHandle = Handle<HwIndexBuffer>;
|
||||
using ProgramHandle = Handle<HwProgram>;
|
||||
using RenderPrimitiveHandle = Handle<HwRenderPrimitive>;
|
||||
using RenderTargetHandle = Handle<HwRenderTarget>;
|
||||
using SamplerGroupHandle = Handle<HwSamplerGroup>;
|
||||
using StreamHandle = Handle<HwStream>;
|
||||
using SwapChainHandle = Handle<HwSwapChain>;
|
||||
using TextureHandle = Handle<HwTexture>;
|
||||
using TimerQueryHandle = Handle<HwTimerQuery>;
|
||||
using VertexBufferHandle = Handle<HwVertexBuffer>;
|
||||
using VertexBufferInfoHandle = Handle<HwVertexBufferInfo>;
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_HANDLE_H
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PIPELINESTATE_H
|
||||
#define TNT_FILAMENT_BACKEND_PIPELINESTATE_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Handle.h>
|
||||
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
//! \privatesection
|
||||
|
||||
struct PipelineState {
|
||||
Handle<HwProgram> program; // 4
|
||||
Handle<HwVertexBufferInfo> vertexBufferInfo; // 4
|
||||
RasterState rasterState; // 4
|
||||
StencilState stencilState; // 12
|
||||
PolygonOffset polygonOffset; // 8
|
||||
PrimitiveType primitiveType = PrimitiveType::TRIANGLES; // 1
|
||||
uint8_t padding[3] = {}; // 3
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::PipelineState& ps);
|
||||
#endif
|
||||
|
||||
#endif //TNT_FILAMENT_BACKEND_PIPELINESTATE_H
|
||||
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PIXELBUFFERDESCRIPTOR_H
|
||||
#define TNT_FILAMENT_BACKEND_PIXELBUFFERDESCRIPTOR_H
|
||||
|
||||
#include <backend/BufferDescriptor.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/debug.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A descriptor to an image in main memory, typically used to transfer image data from the CPU
|
||||
* to the GPU.
|
||||
*
|
||||
* A PixelBufferDescriptor owns the memory buffer it references, therefore PixelBufferDescriptor
|
||||
* cannot be copied, but can be moved.
|
||||
*
|
||||
* PixelBufferDescriptor releases ownership of the memory-buffer when it's destroyed.
|
||||
*/
|
||||
class UTILS_PUBLIC PixelBufferDescriptor : public BufferDescriptor {
|
||||
public:
|
||||
using PixelDataFormat = backend::PixelDataFormat;
|
||||
using PixelDataType = backend::PixelDataType;
|
||||
|
||||
PixelBufferDescriptor() = default;
|
||||
|
||||
/**
|
||||
* Creates a new PixelBufferDescriptor referencing an image in main memory
|
||||
*
|
||||
* @param buffer Virtual address of the buffer containing the image
|
||||
* @param size Size in bytes of the buffer containing the image
|
||||
* @param format Format of the image pixels
|
||||
* @param type Type of the image pixels
|
||||
* @param alignment Alignment in bytes of pixel rows
|
||||
* @param left Left coordinate in pixels
|
||||
* @param top Top coordinate in pixels
|
||||
* @param stride Stride of a row in pixels
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler
|
||||
* @param callback A callback used to release the CPU buffer
|
||||
* @param user An opaque user pointer passed to the callback function when it's called
|
||||
*/
|
||||
PixelBufferDescriptor(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type, uint8_t alignment,
|
||||
uint32_t left, uint32_t top, uint32_t stride,
|
||||
CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept
|
||||
: BufferDescriptor(buffer, size, handler, callback, user),
|
||||
left(left), top(top), stride(stride),
|
||||
format(format), type(type), alignment(alignment) {
|
||||
}
|
||||
|
||||
PixelBufferDescriptor(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type, uint8_t alignment = 1,
|
||||
uint32_t left = 0, uint32_t top = 0, uint32_t stride = 0,
|
||||
Callback callback = nullptr, void* user = nullptr) noexcept
|
||||
: BufferDescriptor(buffer, size, callback, user),
|
||||
left(left), top(top), stride(stride),
|
||||
format(format), type(type), alignment(alignment) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PixelBufferDescriptor referencing an image in main memory
|
||||
*
|
||||
* @param buffer Virtual address of the buffer containing the image
|
||||
* @param size Size in bytes of the buffer containing the image
|
||||
* @param format Format of the image pixels
|
||||
* @param type Type of the image pixels
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler
|
||||
* @param callback A callback used to release the CPU buffer
|
||||
* @param user An opaque user pointer passed to the callback function when it's called
|
||||
*/
|
||||
PixelBufferDescriptor(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type,
|
||||
CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept
|
||||
: BufferDescriptor(buffer, size, handler, callback, user),
|
||||
stride(0), format(format), type(type), alignment(1) {
|
||||
}
|
||||
|
||||
PixelBufferDescriptor(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type,
|
||||
Callback callback, void* user = nullptr) noexcept
|
||||
: BufferDescriptor(buffer, size, callback, user),
|
||||
stride(0), format(format), type(type), alignment(1) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new PixelBufferDescriptor referencing a compressed image in main memory
|
||||
*
|
||||
* @param buffer Virtual address of the buffer containing the image
|
||||
* @param size Size in bytes of the buffer containing the image
|
||||
* @param format Compressed format of the image
|
||||
* @param imageSize Compressed size of the image
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler
|
||||
* @param callback A callback used to release the CPU buffer
|
||||
* @param user An opaque user pointer passed to the callback function when it's called
|
||||
*/
|
||||
PixelBufferDescriptor(void const* buffer, size_t size,
|
||||
backend::CompressedPixelDataType format, uint32_t imageSize,
|
||||
CallbackHandler* handler, Callback callback, void* user = nullptr) noexcept
|
||||
: BufferDescriptor(buffer, size, handler, callback, user),
|
||||
imageSize(imageSize), compressedFormat(format), type(PixelDataType::COMPRESSED),
|
||||
alignment(1) {
|
||||
}
|
||||
|
||||
PixelBufferDescriptor(void const* buffer, size_t size,
|
||||
backend::CompressedPixelDataType format, uint32_t imageSize,
|
||||
Callback callback, void* user = nullptr) noexcept
|
||||
: BufferDescriptor(buffer, size, callback, user),
|
||||
imageSize(imageSize), compressedFormat(format), type(PixelDataType::COMPRESSED),
|
||||
alignment(1) {
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
static PixelBufferDescriptor make(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type, uint8_t alignment,
|
||||
uint32_t left, uint32_t top, uint32_t stride, T* data,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type, alignment, left, top, stride,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
(static_cast<T*>(u)->*method)(b, s); }, data };
|
||||
}
|
||||
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
static PixelBufferDescriptor make(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type, T* data,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type, handler, [](void* b, size_t s, void* u) {
|
||||
(static_cast<T*>(u)->*method)(b, s); }, data };
|
||||
}
|
||||
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
static PixelBufferDescriptor make(void const* buffer, size_t size,
|
||||
backend::CompressedPixelDataType format, uint32_t imageSize, T* data,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, imageSize, handler, [](void* b, size_t s, void* u) {
|
||||
(static_cast<T*>(u)->*method)(b, s); }, data
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static PixelBufferDescriptor make(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type, uint8_t alignment,
|
||||
uint32_t left, uint32_t top, uint32_t stride, T&& functor,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type, alignment, left, top, stride,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
}, new T(std::forward<T>(functor))
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static PixelBufferDescriptor make(void const* buffer, size_t size,
|
||||
PixelDataFormat format, PixelDataType type, T&& functor,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
}, new T(std::forward<T>(functor))
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static PixelBufferDescriptor make(void const* buffer, size_t size,
|
||||
backend::CompressedPixelDataType format, uint32_t imageSize, T&& functor,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, imageSize,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
}, new T(std::forward<T>(functor))
|
||||
};
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Computes the size in bytes needed to fit an image of given dimensions and format
|
||||
*
|
||||
* @param format Format of the image pixels
|
||||
* @param type Type of the image pixels
|
||||
* @param stride Stride of a row in pixels
|
||||
* @param height Height of the image in rows
|
||||
* @param alignment Alignment in bytes of pixel rows
|
||||
* @return The buffer size needed to fit this image in bytes
|
||||
*/
|
||||
static constexpr size_t computeDataSize(PixelDataFormat format, PixelDataType type,
|
||||
size_t stride, size_t height, size_t alignment) noexcept {
|
||||
assert_invariant(alignment);
|
||||
|
||||
if (type == PixelDataType::COMPRESSED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t n = 0;
|
||||
switch (format) {
|
||||
case PixelDataFormat::R:
|
||||
case PixelDataFormat::R_INTEGER:
|
||||
case PixelDataFormat::DEPTH_COMPONENT:
|
||||
case PixelDataFormat::ALPHA:
|
||||
n = 1;
|
||||
break;
|
||||
case PixelDataFormat::RG:
|
||||
case PixelDataFormat::RG_INTEGER:
|
||||
case PixelDataFormat::DEPTH_STENCIL:
|
||||
n = 2;
|
||||
break;
|
||||
case PixelDataFormat::RGB:
|
||||
case PixelDataFormat::RGB_INTEGER:
|
||||
n = 3;
|
||||
break;
|
||||
case PixelDataFormat::UNUSED: // shouldn't happen (used to be rgbm)
|
||||
case PixelDataFormat::RGBA:
|
||||
case PixelDataFormat::RGBA_INTEGER:
|
||||
n = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t bpp = n;
|
||||
switch (type) {
|
||||
case PixelDataType::COMPRESSED: // Impossible -- to squash the IDE warnings
|
||||
case PixelDataType::UBYTE:
|
||||
case PixelDataType::BYTE:
|
||||
// nothing to do
|
||||
break;
|
||||
case PixelDataType::USHORT:
|
||||
case PixelDataType::SHORT:
|
||||
case PixelDataType::HALF:
|
||||
bpp *= 2;
|
||||
break;
|
||||
case PixelDataType::UINT:
|
||||
case PixelDataType::INT:
|
||||
case PixelDataType::FLOAT:
|
||||
bpp *= 4;
|
||||
break;
|
||||
case PixelDataType::UINT_10F_11F_11F_REV:
|
||||
// Special case, format must be RGB and uses 4 bytes
|
||||
assert_invariant(format == PixelDataFormat::RGB);
|
||||
bpp = 4;
|
||||
break;
|
||||
case PixelDataType::UINT_2_10_10_10_REV:
|
||||
// Special case, format must be RGBA and uses 4 bytes
|
||||
assert_invariant(format == PixelDataFormat::RGBA);
|
||||
bpp = 4;
|
||||
break;
|
||||
case PixelDataType::USHORT_565:
|
||||
// Special case, format must be RGB and uses 2 bytes
|
||||
assert_invariant(format == PixelDataFormat::RGB);
|
||||
bpp = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t const bpr = bpp * stride;
|
||||
size_t const bprAligned = (bpr + (alignment - 1)) & (~alignment + 1);
|
||||
return bprAligned * height;
|
||||
}
|
||||
|
||||
//! left coordinate in pixels
|
||||
uint32_t left = 0;
|
||||
//! top coordinate in pixels
|
||||
uint32_t top = 0;
|
||||
union {
|
||||
struct {
|
||||
//! stride in pixels
|
||||
uint32_t stride;
|
||||
//! Pixel data format
|
||||
PixelDataFormat format;
|
||||
};
|
||||
struct {
|
||||
//! compressed image size
|
||||
uint32_t imageSize;
|
||||
//! compressed image format
|
||||
backend::CompressedPixelDataType compressedFormat;
|
||||
};
|
||||
};
|
||||
//! pixel data type
|
||||
PixelDataType type : 4;
|
||||
//! row alignment in bytes
|
||||
uint8_t alignment : 4;
|
||||
};
|
||||
|
||||
} // namespace backend::filament
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::PixelBufferDescriptor& b);
|
||||
#endif
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PIXELBUFFERDESCRIPTOR_H
|
||||
235
dart_filament/native/include/filament/backend/Platform.h
Normal file
235
dart_filament/native/include/filament/backend/Platform.h
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
#define TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class Driver;
|
||||
|
||||
/**
|
||||
* Platform is an interface that abstracts how the backend (also referred to as Driver) is
|
||||
* created. The backend provides several common Platform concrete implementations, which are
|
||||
* selected automatically. It is possible however to provide a custom Platform when creating
|
||||
* the filament Engine.
|
||||
*/
|
||||
class UTILS_PUBLIC Platform {
|
||||
public:
|
||||
struct SwapChain {};
|
||||
struct Fence {};
|
||||
struct Stream {};
|
||||
|
||||
struct DriverConfig {
|
||||
/**
|
||||
* Size of handle arena in bytes. Setting to 0 indicates default value is to be used.
|
||||
* Driver clamps to valid values.
|
||||
*/
|
||||
size_t handleArenaSize = 0;
|
||||
|
||||
/**
|
||||
* This number of most-recently destroyed textures will be tracked for use-after-free.
|
||||
* Throws an exception when a texture is freed but still bound to a SamplerGroup and used in
|
||||
* a draw call. 0 disables completely. Currently only respected by the Metal backend.
|
||||
*/
|
||||
size_t textureUseAfterFreePoolSize = 0;
|
||||
|
||||
/**
|
||||
* Set to `true` to forcibly disable parallel shader compilation in the backend.
|
||||
* Currently only honored by the GL and Metal backends.
|
||||
*/
|
||||
bool disableParallelShaderCompile = false;
|
||||
|
||||
/**
|
||||
* Disable backend handles use-after-free checks.
|
||||
*/
|
||||
bool disableHandleUseAfterFreeCheck = false;
|
||||
};
|
||||
|
||||
Platform() noexcept;
|
||||
|
||||
virtual ~Platform() noexcept;
|
||||
|
||||
/**
|
||||
* Queries the underlying OS version.
|
||||
* @return The OS version.
|
||||
*/
|
||||
virtual int getOSVersion() const noexcept = 0;
|
||||
|
||||
/**
|
||||
* Creates and initializes the low-level API (e.g. an OpenGL context or Vulkan instance),
|
||||
* then creates the concrete Driver.
|
||||
* The caller takes ownership of the returned Driver* and must destroy it with delete.
|
||||
*
|
||||
* @param sharedContext an optional shared context. This is not meaningful with all graphic
|
||||
* APIs and platforms.
|
||||
* For EGL platforms, this is an EGLContext.
|
||||
*
|
||||
* @param driverConfig specifies driver initialization parameters
|
||||
*
|
||||
* @return nullptr on failure, or a pointer to the newly created driver.
|
||||
*/
|
||||
virtual backend::Driver* UTILS_NULLABLE createDriver(void* UTILS_NULLABLE sharedContext,
|
||||
const DriverConfig& driverConfig) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Processes the platform's event queue when called from its primary event-handling thread.
|
||||
*
|
||||
* Internally, Filament might need to call this when waiting on a fence. It is only implemented
|
||||
* on platforms that need it, such as macOS + OpenGL. Returns false if this is not the main
|
||||
* thread, or if the platform does not need to perform any special processing.
|
||||
*/
|
||||
virtual bool pumpEvents() noexcept;
|
||||
|
||||
/**
|
||||
* InsertBlobFunc is an Invocable to an application-provided function that a
|
||||
* backend implementation may use to insert a key/value pair into the
|
||||
* cache.
|
||||
*/
|
||||
using InsertBlobFunc = utils::Invocable<
|
||||
void(const void* UTILS_NONNULL key, size_t keySize,
|
||||
const void* UTILS_NONNULL value, size_t valueSize)>;
|
||||
|
||||
/*
|
||||
* RetrieveBlobFunc is an Invocable to an application-provided function that a
|
||||
* backend implementation may use to retrieve a cached value from the
|
||||
* cache.
|
||||
*/
|
||||
using RetrieveBlobFunc = utils::Invocable<
|
||||
size_t(const void* UTILS_NONNULL key, size_t keySize,
|
||||
void* UTILS_NONNULL value, size_t valueSize)>;
|
||||
|
||||
/**
|
||||
* Sets the callback functions that the backend can use to interact with caching functionality
|
||||
* provided by the application.
|
||||
*
|
||||
* Cache functions may only be specified once during the lifetime of a
|
||||
* Platform. The <insert> and <retrieve> Invocables may be called at any time and
|
||||
* from any thread from the time at which setBlobFunc is called until the time that Platform
|
||||
* is destroyed. Concurrent calls to these functions from different threads is also allowed.
|
||||
* Either function can be null.
|
||||
*
|
||||
* @param insertBlob an Invocable that inserts a new value into the cache and associates
|
||||
* it with the given key
|
||||
* @param retrieveBlob an Invocable that retrieves from the cache the value associated with a
|
||||
* given key
|
||||
*/
|
||||
void setBlobFunc(InsertBlobFunc&& insertBlob, RetrieveBlobFunc&& retrieveBlob) noexcept;
|
||||
|
||||
/**
|
||||
* @return true if insertBlob is valid.
|
||||
*/
|
||||
bool hasInsertBlobFunc() const noexcept;
|
||||
|
||||
/**
|
||||
* @return true if retrieveBlob is valid.
|
||||
*/
|
||||
bool hasRetrieveBlobFunc() const noexcept;
|
||||
|
||||
/**
|
||||
* @return true if either of insertBlob or retrieveBlob are valid.
|
||||
*/
|
||||
bool hasBlobFunc() const noexcept {
|
||||
return hasInsertBlobFunc() || hasRetrieveBlobFunc();
|
||||
}
|
||||
|
||||
/**
|
||||
* To insert a new binary value into the cache and associate it with a given
|
||||
* key, the backend implementation can call the application-provided callback
|
||||
* function insertBlob.
|
||||
*
|
||||
* No guarantees are made as to whether a given key/value pair is present in
|
||||
* the cache after the set call. If a different value has been associated
|
||||
* with the given key in the past then it is undefined which value, if any, is
|
||||
* associated with the key after the set call. Note that while there are no
|
||||
* guarantees, the cache implementation should attempt to cache the most
|
||||
* recently set value for a given key.
|
||||
*
|
||||
* @param key pointer to the beginning of the key data that is to be inserted
|
||||
* @param keySize specifies the size in byte of the data pointed to by <key>
|
||||
* @param value pointer to the beginning of the value data that is to be inserted
|
||||
* @param valueSize specifies the size in byte of the data pointed to by <value>
|
||||
*/
|
||||
void insertBlob(const void* UTILS_NONNULL key, size_t keySize,
|
||||
const void* UTILS_NONNULL value, size_t valueSize);
|
||||
|
||||
/**
|
||||
* To retrieve the binary value associated with a given key from the cache, a
|
||||
* the backend implementation can call the application-provided callback
|
||||
* function retrieveBlob.
|
||||
*
|
||||
* If the cache contains a value for the given key and its size in bytes is
|
||||
* less than or equal to <valueSize> then the value is written to the memory
|
||||
* pointed to by <value>. Otherwise nothing is written to the memory pointed
|
||||
* to by <value>.
|
||||
*
|
||||
* @param key pointer to the beginning of the key
|
||||
* @param keySize specifies the size in bytes of the binary key pointed to by <key>
|
||||
* @param value pointer to a buffer to receive the cached binary data, if it exists
|
||||
* @param valueSize specifies the size in bytes of the memory pointed to by <value>
|
||||
* @return If the cache contains a value associated with the given key then the
|
||||
* size of that binary value in bytes is returned. Otherwise 0 is returned.
|
||||
*/
|
||||
size_t retrieveBlob(const void* UTILS_NONNULL key, size_t keySize,
|
||||
void* UTILS_NONNULL value, size_t valueSize);
|
||||
|
||||
using DebugUpdateStatFunc = utils::Invocable<void(const char* UTILS_NONNULL key, uint64_t value)>;
|
||||
|
||||
/**
|
||||
* Sets the callback function that the backend can use to update backend-specific statistics
|
||||
* to aid with debugging. This callback is guaranteed to be called on the Filament driver
|
||||
* thread.
|
||||
*
|
||||
* @param debugUpdateStat an Invocable that updates debug statistics
|
||||
*/
|
||||
void setDebugUpdateStatFunc(DebugUpdateStatFunc&& debugUpdateStat) noexcept;
|
||||
|
||||
/**
|
||||
* @return true if debugUpdateStat is valid.
|
||||
*/
|
||||
bool hasDebugUpdateStatFunc() const noexcept;
|
||||
|
||||
/**
|
||||
* To track backend-specific statistics, the backend implementation can call the
|
||||
* application-provided callback function debugUpdateStatFunc to associate or update a value
|
||||
* with a given key. It is possible for this function to be called multiple times with the
|
||||
* same key, in which case newer values should overwrite older values.
|
||||
*
|
||||
* This function is guaranteed to be called only on a single thread, the Filament driver
|
||||
* thread.
|
||||
*
|
||||
* @param key a null-terminated C-string with the key of the debug statistic
|
||||
* @param value the updated value of key
|
||||
*/
|
||||
void debugUpdateStat(const char* UTILS_NONNULL key, uint64_t value);
|
||||
|
||||
private:
|
||||
InsertBlobFunc mInsertBlob;
|
||||
RetrieveBlobFunc mRetrieveBlob;
|
||||
DebugUpdateStatFunc mDebugUpdateStat;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
102
dart_filament/native/include/filament/backend/PresentCallable.h
Normal file
102
dart_filament/native/include/filament/backend/PresentCallable.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PRESENTCALLABLE
|
||||
#define TNT_FILAMENT_BACKEND_PRESENTCALLABLE
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A PresentCallable is a callable object that, when called, schedules a frame for presentation on
|
||||
* a SwapChain.
|
||||
*
|
||||
* Typically, Filament's backend is responsible scheduling a frame's presentation. However, there
|
||||
* are certain cases where the application might want to control when a frame is scheduled for
|
||||
* presentation.
|
||||
*
|
||||
* For example, on iOS, UIKit elements can be synchronized to 3D content by scheduling a present
|
||||
* within a CATransation:
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* void myFrameScheduledCallback(PresentCallable presentCallable, void* user) {
|
||||
* [CATransaction begin];
|
||||
* // Update other UI elements...
|
||||
* presentCallable();
|
||||
* [CATransaction commit];
|
||||
* }
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* To obtain a PresentCallable, set a SwapChain::FrameScheduledCallback on a SwapChain with the
|
||||
* SwapChain::setFrameScheduledCallback method. The callback is called with a PresentCallable object
|
||||
* and optional user data:
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* swapChain->setFrameScheduledCallback(myFrameScheduledCallback, nullptr);
|
||||
* if (renderer->beginFrame(swapChain)) {
|
||||
* renderer->render(view);
|
||||
* renderer->endFrame();
|
||||
* }
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* @remark Only Filament's Metal backend supports PresentCallables and frame callbacks. Other
|
||||
* backends ignore the callback (which will never be called) and proceed normally.
|
||||
*
|
||||
* @remark The SwapChain::FrameScheduledCallback is called on an arbitrary thread.
|
||||
*
|
||||
* Applications *must* call each PresentCallable they receive. Each PresentCallable represents a
|
||||
* frame that is waiting to be presented. If an application fails to call a PresentCallable, a
|
||||
* memory leak could occur. To "cancel" the presentation of a frame, pass false to the
|
||||
* PresentCallable, which will cancel the presentation of the frame and release associated memory.
|
||||
*
|
||||
* @see Renderer, SwapChain::setFrameScheduledCallback
|
||||
*/
|
||||
class UTILS_PUBLIC PresentCallable {
|
||||
public:
|
||||
|
||||
using PresentFn = void(*)(bool presentFrame, void* user);
|
||||
|
||||
PresentCallable(PresentFn fn, void* user) noexcept;
|
||||
~PresentCallable() noexcept = default;
|
||||
PresentCallable(const PresentCallable& rhs) = default;
|
||||
PresentCallable& operator=(const PresentCallable& rhs) = default;
|
||||
|
||||
/**
|
||||
* Call this PresentCallable, scheduling the associated frame for presentation. Pass false for
|
||||
* presentFrame to effectively "cancel" the presentation of the frame.
|
||||
*
|
||||
* @param presentFrame if false, will not present the frame but releases associated memory
|
||||
*/
|
||||
void operator()(bool presentFrame = true) noexcept;
|
||||
|
||||
private:
|
||||
|
||||
PresentFn mPresentFn;
|
||||
void* mUser = nullptr;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated, FrameFinishedCallback has been renamed to SwapChain::FrameScheduledCallback.
|
||||
*/
|
||||
using FrameFinishedCallback UTILS_DEPRECATED = void(*)(PresentCallable callable, void* user);
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PRESENTCALLABLE
|
||||
174
dart_filament/native/include/filament/backend/Program.h
Normal file
174
dart_filament/native/include/filament/backend/Program.h
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PRIVATE_PROGRAM_H
|
||||
#define TNT_FILAMENT_BACKEND_PRIVATE_PROGRAM_H
|
||||
|
||||
#include <utils/CString.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/Invocable.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <array> // FIXME: STL headers are not allowed in public headers
|
||||
#include <utility> // FIXME: STL headers are not allowed in public headers
|
||||
#include <variant> // FIXME: STL headers are not allowed in public headers
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class Program {
|
||||
public:
|
||||
|
||||
static constexpr size_t SHADER_TYPE_COUNT = 3;
|
||||
static constexpr size_t UNIFORM_BINDING_COUNT = CONFIG_UNIFORM_BINDING_COUNT;
|
||||
static constexpr size_t SAMPLER_BINDING_COUNT = CONFIG_SAMPLER_BINDING_COUNT;
|
||||
|
||||
struct Sampler {
|
||||
utils::CString name = {}; // name of the sampler in the shader
|
||||
uint32_t binding = 0; // binding point of the sampler in the shader
|
||||
};
|
||||
|
||||
struct SamplerGroupData {
|
||||
utils::FixedCapacityVector<Sampler> samplers;
|
||||
ShaderStageFlags stageFlags = ShaderStageFlags::ALL_SHADER_STAGE_FLAGS;
|
||||
};
|
||||
|
||||
struct Uniform {
|
||||
utils::CString name; // full qualified name of the uniform field
|
||||
uint16_t offset; // offset in 'uint32_t' into the uniform buffer
|
||||
uint8_t size; // >1 for arrays
|
||||
UniformType type; // uniform type
|
||||
};
|
||||
|
||||
using UniformBlockInfo = std::array<utils::CString, UNIFORM_BINDING_COUNT>;
|
||||
using UniformInfo = utils::FixedCapacityVector<Uniform>;
|
||||
using SamplerGroupInfo = std::array<SamplerGroupData, SAMPLER_BINDING_COUNT>;
|
||||
using ShaderBlob = utils::FixedCapacityVector<uint8_t>;
|
||||
using ShaderSource = std::array<ShaderBlob, SHADER_TYPE_COUNT>;
|
||||
|
||||
Program() noexcept;
|
||||
|
||||
Program(const Program& rhs) = delete;
|
||||
Program& operator=(const Program& rhs) = delete;
|
||||
|
||||
Program(Program&& rhs) noexcept;
|
||||
Program& operator=(Program&& rhs) noexcept = delete;
|
||||
|
||||
~Program() noexcept;
|
||||
|
||||
Program& priorityQueue(CompilerPriorityQueue priorityQueue) noexcept;
|
||||
|
||||
// sets the material name and variant for diagnostic purposes only
|
||||
Program& diagnostics(utils::CString const& name,
|
||||
utils::Invocable<utils::io::ostream&(utils::io::ostream& out)>&& logger);
|
||||
|
||||
// sets one of the program's shader (e.g. vertex, fragment)
|
||||
// string-based shaders are null terminated, consequently the size parameter must include the
|
||||
// null terminating character.
|
||||
Program& shader(ShaderStage shader, void const* data, size_t size);
|
||||
|
||||
// Note: This is only needed for GLES3.0 backends, because the layout(binding=) syntax is
|
||||
// not permitted in glsl. The backend needs a way to associate a uniform block
|
||||
// to a binding point.
|
||||
Program& uniformBlockBindings(
|
||||
utils::FixedCapacityVector<std::pair<utils::CString, uint8_t>> const& uniformBlockBindings) noexcept;
|
||||
|
||||
// Note: This is only needed for GLES2.0, this is used to emulate UBO. This function tells
|
||||
// the program everything it needs to know about the uniforms at a given binding
|
||||
Program& uniforms(uint32_t index, UniformInfo const& uniforms) noexcept;
|
||||
|
||||
// Note: This is only needed for GLES2.0.
|
||||
Program& attributes(
|
||||
utils::FixedCapacityVector<std::pair<utils::CString, uint8_t>> attributes) noexcept;
|
||||
|
||||
// sets the 'bindingPoint' sampler group descriptor for this program.
|
||||
// 'samplers' can be destroyed after this call.
|
||||
// This effectively associates a set of (BindingPoints, index) to a texture unit in the shader.
|
||||
// Or more precisely, what layout(binding=) is set to in GLSL.
|
||||
Program& setSamplerGroup(size_t bindingPoint, ShaderStageFlags stageFlags,
|
||||
Sampler const* samplers, size_t count) noexcept;
|
||||
|
||||
struct SpecializationConstant {
|
||||
using Type = std::variant<int32_t, float, bool>;
|
||||
uint32_t id; // id set in glsl
|
||||
Type value; // value and type
|
||||
};
|
||||
|
||||
Program& specializationConstants(
|
||||
utils::FixedCapacityVector<SpecializationConstant> specConstants) noexcept;
|
||||
|
||||
Program& cacheId(uint64_t cacheId) noexcept;
|
||||
|
||||
Program& multiview(bool multiview) noexcept;
|
||||
|
||||
ShaderSource const& getShadersSource() const noexcept { return mShadersSource; }
|
||||
ShaderSource& getShadersSource() noexcept { return mShadersSource; }
|
||||
|
||||
UniformBlockInfo const& getUniformBlockBindings() const noexcept { return mUniformBlocks; }
|
||||
UniformBlockInfo& getUniformBlockBindings() noexcept { return mUniformBlocks; }
|
||||
|
||||
SamplerGroupInfo const& getSamplerGroupInfo() const { return mSamplerGroups; }
|
||||
SamplerGroupInfo& getSamplerGroupInfo() { return mSamplerGroups; }
|
||||
|
||||
auto const& getBindingUniformInfo() const { return mBindingUniformInfo; }
|
||||
auto& getBindingUniformInfo() { return mBindingUniformInfo; }
|
||||
|
||||
auto const& getAttributes() const { return mAttributes; }
|
||||
auto& getAttributes() { return mAttributes; }
|
||||
|
||||
utils::CString const& getName() const noexcept { return mName; }
|
||||
utils::CString& getName() noexcept { return mName; }
|
||||
|
||||
utils::FixedCapacityVector<SpecializationConstant> const& getSpecializationConstants() const noexcept {
|
||||
return mSpecializationConstants;
|
||||
}
|
||||
utils::FixedCapacityVector<SpecializationConstant>& getSpecializationConstants() noexcept {
|
||||
return mSpecializationConstants;
|
||||
}
|
||||
|
||||
uint64_t getCacheId() const noexcept { return mCacheId; }
|
||||
|
||||
bool isMultiview() const noexcept { return mMultiview; }
|
||||
|
||||
CompilerPriorityQueue getPriorityQueue() const noexcept { return mPriorityQueue; }
|
||||
|
||||
private:
|
||||
friend utils::io::ostream& operator<<(utils::io::ostream& out, const Program& builder);
|
||||
|
||||
UniformBlockInfo mUniformBlocks = {};
|
||||
SamplerGroupInfo mSamplerGroups = {};
|
||||
ShaderSource mShadersSource;
|
||||
utils::CString mName;
|
||||
uint64_t mCacheId{};
|
||||
utils::Invocable<utils::io::ostream&(utils::io::ostream& out)> mLogger;
|
||||
utils::FixedCapacityVector<SpecializationConstant> mSpecializationConstants;
|
||||
utils::FixedCapacityVector<std::pair<utils::CString, uint8_t>> mAttributes;
|
||||
std::array<UniformInfo, Program::UNIFORM_BINDING_COUNT> mBindingUniformInfo;
|
||||
CompilerPriorityQueue mPriorityQueue = CompilerPriorityQueue::HIGH;
|
||||
// Indicates the current engine was initialized with multiview stereo, and the variant for this
|
||||
// program contains STE flag. This will be referred later for the OpenGL shader compiler to
|
||||
// determine whether shader code replacement for the num_views should be performed.
|
||||
// This variable could be promoted as a more generic variable later if other similar needs occur.
|
||||
bool mMultiview = false;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PRIVATE_PROGRAM_H
|
||||
4
dart_filament/native/include/filament/backend/README.md
Normal file
4
dart_filament/native/include/filament/backend/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# include/backend Headers
|
||||
|
||||
Headers in `include/backend/` are fully public, in particular they can be included in filament's
|
||||
public headers.
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_SAMPLERDESCRIPTOR_H
|
||||
#define TNT_FILAMENT_BACKEND_SAMPLERDESCRIPTOR_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Handle.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
struct UTILS_PUBLIC SamplerDescriptor {
|
||||
Handle<HwTexture> t;
|
||||
SamplerParams s{};
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_SAMPLERDESCRIPTOR_H
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_TARGETBUFFERINFO_H
|
||||
#define TNT_FILAMENT_BACKEND_TARGETBUFFERINFO_H
|
||||
|
||||
#include <backend/Handle.h>
|
||||
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
//! \privatesection
|
||||
|
||||
struct TargetBufferInfo {
|
||||
// texture to be used as render target
|
||||
Handle<HwTexture> handle;
|
||||
|
||||
// starting layer index for multiview. This value is only used when the `layerCount` for the
|
||||
// render target is greater than 1.
|
||||
uint8_t baseViewIndex = 0;
|
||||
|
||||
// level to be used
|
||||
uint8_t level = 0;
|
||||
|
||||
// for cubemaps and 3D textures. See TextureCubemapFace for the face->layer mapping
|
||||
uint16_t layer = 0;
|
||||
};
|
||||
|
||||
class MRT {
|
||||
public:
|
||||
static constexpr uint8_t MIN_SUPPORTED_RENDER_TARGET_COUNT = 4u;
|
||||
|
||||
// When updating this, make sure to also take care of RenderTarget.java
|
||||
static constexpr uint8_t MAX_SUPPORTED_RENDER_TARGET_COUNT = 8u;
|
||||
|
||||
private:
|
||||
TargetBufferInfo mInfos[MAX_SUPPORTED_RENDER_TARGET_COUNT];
|
||||
|
||||
public:
|
||||
TargetBufferInfo const& operator[](size_t i) const noexcept {
|
||||
return mInfos[i];
|
||||
}
|
||||
|
||||
TargetBufferInfo& operator[](size_t i) noexcept {
|
||||
return mInfos[i];
|
||||
}
|
||||
|
||||
MRT() noexcept = default;
|
||||
|
||||
MRT(TargetBufferInfo const& color) noexcept // NOLINT(hicpp-explicit-conversions)
|
||||
: mInfos{ color } {
|
||||
}
|
||||
|
||||
MRT(TargetBufferInfo const& color0, TargetBufferInfo const& color1) noexcept
|
||||
: mInfos{ color0, color1 } {
|
||||
}
|
||||
|
||||
MRT(TargetBufferInfo const& color0, TargetBufferInfo const& color1,
|
||||
TargetBufferInfo const& color2) noexcept
|
||||
: mInfos{ color0, color1, color2 } {
|
||||
}
|
||||
|
||||
MRT(TargetBufferInfo const& color0, TargetBufferInfo const& color1,
|
||||
TargetBufferInfo const& color2, TargetBufferInfo const& color3) noexcept
|
||||
: mInfos{ color0, color1, color2, color3 } {
|
||||
}
|
||||
|
||||
// this is here for backward compatibility
|
||||
MRT(Handle<HwTexture> handle, uint8_t level, uint16_t layer) noexcept
|
||||
: mInfos{{ handle, 0, level, layer }} {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::TargetBufferInfo& tbi);
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::MRT& mrt);
|
||||
#endif
|
||||
|
||||
#endif //TNT_FILAMENT_BACKEND_TARGETBUFFERINFO_H
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PRIVATE_OPENGLPLATFORM_H
|
||||
#define TNT_FILAMENT_BACKEND_PRIVATE_OPENGLPLATFORM_H
|
||||
|
||||
#include <backend/AcquiredImage.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Platform.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class Driver;
|
||||
|
||||
/**
|
||||
* A Platform interface that creates an OpenGL backend.
|
||||
*
|
||||
* WARNING: None of the methods below are allowed to change the GL state and must restore it
|
||||
* upon return.
|
||||
*
|
||||
*/
|
||||
class OpenGLPlatform : public Platform {
|
||||
protected:
|
||||
|
||||
/*
|
||||
* Derived classes can use this to instantiate the default OpenGLDriver backend.
|
||||
* This is typically called from your implementation of createDriver()
|
||||
*/
|
||||
static Driver* UTILS_NULLABLE createDefaultDriver(OpenGLPlatform* UTILS_NONNULL platform,
|
||||
void* UTILS_NULLABLE sharedContext, const DriverConfig& driverConfig);
|
||||
|
||||
~OpenGLPlatform() noexcept override;
|
||||
|
||||
public:
|
||||
|
||||
struct ExternalTexture {
|
||||
unsigned int target; // GLenum target
|
||||
unsigned int id; // GLuint id
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by the driver to destroy the OpenGL context. This should clean up any windows
|
||||
* or buffers from initialization. This is for instance where `eglDestroyContext` would be
|
||||
* called.
|
||||
*/
|
||||
virtual void terminate() noexcept = 0;
|
||||
|
||||
/**
|
||||
* Return whether createSwapChain supports the SWAP_CHAIN_CONFIG_SRGB_COLORSPACE flag.
|
||||
* The default implementation returns false.
|
||||
*
|
||||
* @return true if SWAP_CHAIN_CONFIG_SRGB_COLORSPACE is supported, false otherwise.
|
||||
*/
|
||||
virtual bool isSRGBSwapChainSupported() const noexcept;
|
||||
|
||||
/**
|
||||
* Return whether protected contexts are supported by this backend.
|
||||
* If protected context are supported, the SWAP_CHAIN_CONFIG_PROTECTED_CONTENT flag can be
|
||||
* used when creating a SwapChain.
|
||||
* The default implementation returns false.
|
||||
*/
|
||||
virtual bool isProtectedContextSupported() const noexcept;
|
||||
|
||||
/**
|
||||
* Called by the driver to create a SwapChain for this driver.
|
||||
*
|
||||
* @param nativeWindow a token representing the native window. See concrete implementation
|
||||
* for details.
|
||||
* @param flags extra flags used by the implementation, see filament::SwapChain
|
||||
* @return The driver's SwapChain object.
|
||||
*
|
||||
*/
|
||||
virtual SwapChain* UTILS_NULLABLE createSwapChain(
|
||||
void* UTILS_NULLABLE nativeWindow, uint64_t flags) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Called by the driver create a headless SwapChain.
|
||||
*
|
||||
* @param width width of the buffer
|
||||
* @param height height of the buffer
|
||||
* @param flags extra flags used by the implementation, see filament::SwapChain
|
||||
* @return The driver's SwapChain object.
|
||||
*
|
||||
* TODO: we need a more generic way of passing construction parameters
|
||||
* A void* might be enough.
|
||||
*/
|
||||
virtual SwapChain* UTILS_NULLABLE createSwapChain(
|
||||
uint32_t width, uint32_t height, uint64_t flags) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Called by the driver to destroys the SwapChain
|
||||
* @param swapChain SwapChain to be destroyed.
|
||||
*/
|
||||
virtual void destroySwapChain(SwapChain* UTILS_NONNULL swapChain) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Returns the set of buffers that must be preserved up to the call to commit().
|
||||
* The default value is TargetBufferFlags::NONE.
|
||||
* The color buffer is always preserved, however ancillary buffers, such as the depth buffer
|
||||
* are generally discarded. The preserve flags can be used to make sure those ancillary
|
||||
* buffers are preserved until the call to commit.
|
||||
*
|
||||
* @param swapChain
|
||||
* @return buffer that must be preserved
|
||||
* @see commit()
|
||||
*/
|
||||
virtual TargetBufferFlags getPreservedFlags(SwapChain* UTILS_NONNULL swapChain) noexcept;
|
||||
|
||||
/**
|
||||
* Returns true if the swapchain is protected
|
||||
*/
|
||||
virtual bool isSwapChainProtected(Platform::SwapChain* UTILS_NONNULL swapChain) noexcept;
|
||||
|
||||
/**
|
||||
* Called by the driver to establish the default FBO. The default implementation returns 0.
|
||||
*
|
||||
* This method can be called either on the regular or protected OpenGL contexts and can return
|
||||
* a different or identical name, since these names exist in different namespaces.
|
||||
*
|
||||
* @return a GLuint casted to a uint32_t that is an OpenGL framebuffer object.
|
||||
*/
|
||||
virtual uint32_t getDefaultFramebufferObject() noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* Type of contexts available
|
||||
*/
|
||||
enum class ContextType {
|
||||
NONE, //!< No current context
|
||||
UNPROTECTED, //!< current context is unprotected
|
||||
PROTECTED //!< current context supports protected content
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the type of the context currently in use. This value is updated by makeCurrent()
|
||||
* and therefore can be cached between calls. ContextType::PROTECTED can only be returned
|
||||
* if isProtectedContextSupported() is true.
|
||||
* @return ContextType
|
||||
*/
|
||||
virtual ContextType getCurrentContextType() const noexcept;
|
||||
|
||||
/**
|
||||
* Binds the requested context to the current thread and drawSwapChain to the default FBO
|
||||
* returned by getDefaultFramebufferObject().
|
||||
*
|
||||
* @param type type of context to bind to the current thread.
|
||||
* @param drawSwapChain SwapChain to draw to. It must be bound to the default FBO.
|
||||
* @param readSwapChain SwapChain to read from (for operation like `glBlitFramebuffer`)
|
||||
* @return true on success, false on error.
|
||||
*/
|
||||
virtual bool makeCurrent(ContextType type,
|
||||
SwapChain* UTILS_NONNULL drawSwapChain,
|
||||
SwapChain* UTILS_NONNULL readSwapChain) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Called by the driver to make the OpenGL context active on the calling thread and bind
|
||||
* the drawSwapChain to the default FBO returned by getDefaultFramebufferObject().
|
||||
* The context used is either the default context or the protected context. When a context
|
||||
* change is necessary, the preContextChange and postContextChange callbacks are called,
|
||||
* before and after the context change respectively. postContextChange is given the index
|
||||
* of the new context (0 for default and 1 for protected).
|
||||
* The default implementation just calls makeCurrent(getCurrentContextType(), SwapChain*, SwapChain*).
|
||||
*
|
||||
* @param drawSwapChain SwapChain to draw to. It must be bound to the default FBO.
|
||||
* @param readSwapChain SwapChain to read from (for operation like `glBlitFramebuffer`)
|
||||
* @param preContextChange called before the context changes
|
||||
* @param postContextChange called after the context changes
|
||||
*/
|
||||
virtual void makeCurrent(
|
||||
SwapChain* UTILS_NONNULL drawSwapChain,
|
||||
SwapChain* UTILS_NONNULL readSwapChain,
|
||||
utils::Invocable<void()> preContextChange,
|
||||
utils::Invocable<void(size_t index)> postContextChange) noexcept;
|
||||
|
||||
/**
|
||||
* Called by the driver once the current frame finishes drawing. Typically, this should present
|
||||
* the drawSwapChain. This is for example where `eglMakeCurrent()` would be called.
|
||||
* @param swapChain the SwapChain to present.
|
||||
*/
|
||||
virtual void commit(SwapChain* UTILS_NONNULL swapChain) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Set the time the next committed buffer should be presented to the user at.
|
||||
*
|
||||
* @param presentationTimeInNanosecond time in the future in nanosecond. The clock used depends
|
||||
* on the concrete platform implementation.
|
||||
*/
|
||||
virtual void setPresentationTime(int64_t presentationTimeInNanosecond) noexcept;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Fence support
|
||||
|
||||
/**
|
||||
* Can this implementation create a Fence.
|
||||
* @return true if supported, false otherwise. The default implementation returns false.
|
||||
*/
|
||||
virtual bool canCreateFence() noexcept;
|
||||
|
||||
/**
|
||||
* Creates a Fence (e.g. eglCreateSyncKHR). This must be implemented if `canCreateFence`
|
||||
* returns true. Fences are used for frame pacing.
|
||||
*
|
||||
* @return A Fence object. The default implementation returns nullptr.
|
||||
*/
|
||||
virtual Fence* UTILS_NULLABLE createFence() noexcept;
|
||||
|
||||
/**
|
||||
* Destroys a Fence object. The default implementation does nothing.
|
||||
*
|
||||
* @param fence Fence to destroy.
|
||||
*/
|
||||
virtual void destroyFence(Fence* UTILS_NONNULL fence) noexcept;
|
||||
|
||||
/**
|
||||
* Waits on a Fence.
|
||||
*
|
||||
* @param fence Fence to wait on.
|
||||
* @param timeout Timeout.
|
||||
* @return Whether the fence signaled or timed out. See backend::FenceStatus.
|
||||
* The default implementation always return backend::FenceStatus::ERROR.
|
||||
*/
|
||||
virtual backend::FenceStatus waitFence(Fence* UTILS_NONNULL fence, uint64_t timeout) noexcept;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Streaming support
|
||||
|
||||
/**
|
||||
* Creates a Stream from a native Stream.
|
||||
*
|
||||
* WARNING: This is called synchronously from the application thread (NOT the Driver thread)
|
||||
*
|
||||
* @param nativeStream The native stream, this parameter depends on the concrete implementation.
|
||||
* @return A new Stream object.
|
||||
*/
|
||||
virtual Stream* UTILS_NULLABLE createStream(void* UTILS_NULLABLE nativeStream) noexcept;
|
||||
|
||||
/**
|
||||
* Destroys a Stream.
|
||||
* @param stream Stream to destroy.
|
||||
*/
|
||||
virtual void destroyStream(Stream* UTILS_NONNULL stream) noexcept;
|
||||
|
||||
/**
|
||||
* The specified stream takes ownership of the texture (tname) object
|
||||
* Once attached, the texture is automatically updated with the Stream's content, which
|
||||
* could be a video stream for instance.
|
||||
*
|
||||
* @param stream Stream to take ownership of the texture
|
||||
* @param tname GL texture id to "bind" to the Stream.
|
||||
*/
|
||||
virtual void attach(Stream* UTILS_NONNULL stream, intptr_t tname) noexcept;
|
||||
|
||||
/**
|
||||
* Destroys the texture associated to the stream
|
||||
* @param stream Stream to detach from its texture
|
||||
*/
|
||||
virtual void detach(Stream* UTILS_NONNULL stream) noexcept;
|
||||
|
||||
/**
|
||||
* Updates the content of the texture attached to the stream.
|
||||
* @param stream Stream to update
|
||||
* @param timestamp Output parameter: Timestamp of the image bound to the texture.
|
||||
*/
|
||||
virtual void updateTexImage(Stream* UTILS_NONNULL stream,
|
||||
int64_t* UTILS_NONNULL timestamp) noexcept;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// External Image support
|
||||
|
||||
/**
|
||||
* Creates an external texture handle. External textures don't have any parameters because
|
||||
* these are undefined until setExternalImage() is called.
|
||||
* @return a pointer to an ExternalTexture structure filled with valid token. However, the
|
||||
* implementation could just return { 0, GL_TEXTURE_2D } at this point. The actual
|
||||
* values can be delayed until setExternalImage.
|
||||
*/
|
||||
virtual ExternalTexture* UTILS_NULLABLE createExternalImageTexture() noexcept;
|
||||
|
||||
/**
|
||||
* Destroys an external texture handle and associated data.
|
||||
* @param texture a pointer to the handle to destroy.
|
||||
*/
|
||||
virtual void destroyExternalImage(ExternalTexture* UTILS_NONNULL texture) noexcept;
|
||||
|
||||
// called on the application thread to allow Filament to take ownership of the image
|
||||
|
||||
/**
|
||||
* Takes ownership of the externalImage. The externalImage parameter depends on the Platform's
|
||||
* concrete implementation. Ownership is released when destroyExternalImage() is called.
|
||||
*
|
||||
* WARNING: This is called synchronously from the application thread (NOT the Driver thread)
|
||||
*
|
||||
* @param externalImage A token representing the platform's external image.
|
||||
* @see destroyExternalImage
|
||||
*/
|
||||
virtual void retainExternalImage(void* UTILS_NONNULL externalImage) noexcept;
|
||||
|
||||
/**
|
||||
* Called to bind the platform-specific externalImage to an ExternalTexture.
|
||||
* ExternalTexture::id is guaranteed to be bound when this method is called and ExternalTexture
|
||||
* is updated with new values for id/target if necessary.
|
||||
*
|
||||
* WARNING: this method is not allowed to change the bound texture, or must restore the previous
|
||||
* binding upon return. This is to avoid problem with a backend doing state caching.
|
||||
*
|
||||
* @param externalImage The platform-specific external image.
|
||||
* @param texture an in/out pointer to ExternalTexture, id and target can be updated if necessary.
|
||||
* @return true on success, false on error.
|
||||
*/
|
||||
virtual bool setExternalImage(void* UTILS_NONNULL externalImage,
|
||||
ExternalTexture* UTILS_NONNULL texture) noexcept;
|
||||
|
||||
/**
|
||||
* The method allows platforms to convert a user-supplied external image object into a new type
|
||||
* (e.g. HardwareBuffer => EGLImage). The default implementation returns source.
|
||||
* @param source Image to transform.
|
||||
* @return Transformed image.
|
||||
*/
|
||||
virtual AcquiredImage transformAcquiredImage(AcquiredImage source) noexcept;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns true if additional OpenGL contexts can be created. Default: false.
|
||||
* @return true if additional OpenGL contexts can be created.
|
||||
* @see createContext
|
||||
*/
|
||||
virtual bool isExtraContextSupported() const noexcept;
|
||||
|
||||
/**
|
||||
* Creates an OpenGL context with the same configuration than the main context and makes it
|
||||
* current to the current thread. Must not be called from the main driver thread.
|
||||
* createContext() is only supported if isExtraContextSupported() returns true.
|
||||
* These additional contexts will be automatically terminated in terminate.
|
||||
*
|
||||
* @param shared whether the new context is shared with the main context.
|
||||
* @see isExtraContextSupported()
|
||||
* @see terminate()
|
||||
*/
|
||||
virtual void createContext(bool shared);
|
||||
|
||||
/**
|
||||
* Detach and destroy the current context if any and releases all resources associated to
|
||||
* this thread.
|
||||
*/
|
||||
virtual void releaseContext() noexcept;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PRIVATE_OPENGLPLATFORM_H
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_GL_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_GL_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
struct PlatformCocoaGLImpl;
|
||||
|
||||
/**
|
||||
* A concrete implementation of OpenGLPlatform that supports macOS's Cocoa.
|
||||
*/
|
||||
class PlatformCocoaGL : public OpenGLPlatform {
|
||||
public:
|
||||
PlatformCocoaGL();
|
||||
~PlatformCocoaGL() noexcept override;
|
||||
|
||||
protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
Driver* createDriver(void* sharedContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
// Currently returns 0
|
||||
int getOSVersion() const noexcept override;
|
||||
|
||||
bool pumpEvents() noexcept override;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain, SwapChain* readSwapChain) noexcept override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
OpenGLPlatform::ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImage(ExternalTexture* texture) noexcept override;
|
||||
void retainExternalImage(void* externalImage) noexcept override;
|
||||
bool setExternalImage(void* externalImage, ExternalTexture* texture) noexcept override;
|
||||
|
||||
private:
|
||||
PlatformCocoaGLImpl* pImpl = nullptr;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_GL_H
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_TOUCH_GL_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_TOUCH_GL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
struct PlatformCocoaTouchGLImpl;
|
||||
|
||||
class PlatformCocoaTouchGL : public OpenGLPlatform {
|
||||
public:
|
||||
PlatformCocoaTouchGL();
|
||||
~PlatformCocoaTouchGL() noexcept override;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
Driver* createDriver(void* sharedGLContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
int getOSVersion() const noexcept final { return 0; }
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
uint32_t getDefaultFramebufferObject() noexcept override;
|
||||
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain, SwapChain* readSwapChain) noexcept override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
|
||||
OpenGLPlatform::ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImage(ExternalTexture* texture) noexcept override;
|
||||
void retainExternalImage(void* externalImage) noexcept override;
|
||||
bool setExternalImage(void* externalImage, ExternalTexture* texture) noexcept override;
|
||||
|
||||
private:
|
||||
PlatformCocoaTouchGLImpl* pImpl = nullptr;
|
||||
};
|
||||
|
||||
using ContextManager = PlatformCocoaTouchGL;
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_COCOA_TOUCH_GL_H
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_EGL_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_EGL_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Platform.h>
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <EGL/eglplatform.h>
|
||||
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A concrete implementation of OpenGLPlatform that supports EGL.
|
||||
*/
|
||||
class PlatformEGL : public OpenGLPlatform {
|
||||
public:
|
||||
|
||||
PlatformEGL() noexcept;
|
||||
|
||||
// Return true if we're on an OpenGL platform (as opposed to OpenGL ES). false by default.
|
||||
virtual bool isOpenGL() const noexcept;
|
||||
|
||||
protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Helper for EGL configs and attributes parameters
|
||||
|
||||
class Config {
|
||||
public:
|
||||
Config();
|
||||
Config(std::initializer_list<std::pair<EGLint, EGLint>> list);
|
||||
EGLint& operator[](EGLint name);
|
||||
EGLint operator[](EGLint name) const;
|
||||
void erase(EGLint name) noexcept;
|
||||
EGLint const* data() const noexcept {
|
||||
return reinterpret_cast<EGLint const*>(mConfig.data());
|
||||
}
|
||||
size_t size() const noexcept {
|
||||
return mConfig.size();
|
||||
}
|
||||
private:
|
||||
std::vector<std::pair<EGLint, EGLint>> mConfig = {{ EGL_NONE, EGL_NONE }};
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
/**
|
||||
* Initializes EGL, creates the OpenGL context and returns a concrete Driver implementation
|
||||
* that supports OpenGL/OpenGL ES.
|
||||
*/
|
||||
Driver* createDriver(void* sharedContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
/**
|
||||
* This returns zero. This method can be overridden to return something more useful.
|
||||
* @return zero
|
||||
*/
|
||||
int getOSVersion() const noexcept override;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
void releaseContext() noexcept override;
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
bool isProtectedContextSupported() const noexcept override;
|
||||
|
||||
bool isSRGBSwapChainSupported() const noexcept override;
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
bool isSwapChainProtected(SwapChain* swapChain) noexcept override;
|
||||
|
||||
ContextType getCurrentContextType() const noexcept override;
|
||||
|
||||
bool makeCurrent(ContextType type,
|
||||
SwapChain* drawSwapChain,
|
||||
SwapChain* readSwapChain) noexcept override;
|
||||
|
||||
void makeCurrent(SwapChain* drawSwapChain, SwapChain* readSwapChain,
|
||||
utils::Invocable<void()> preContextChange,
|
||||
utils::Invocable<void(size_t index)> postContextChange) noexcept override;
|
||||
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
|
||||
bool canCreateFence() noexcept override;
|
||||
Fence* createFence() noexcept override;
|
||||
void destroyFence(Fence* fence) noexcept override;
|
||||
FenceStatus waitFence(Fence* fence, uint64_t timeout) noexcept override;
|
||||
|
||||
OpenGLPlatform::ExternalTexture* createExternalImageTexture() noexcept override;
|
||||
void destroyExternalImage(ExternalTexture* texture) noexcept override;
|
||||
bool setExternalImage(void* externalImage, ExternalTexture* texture) noexcept override;
|
||||
|
||||
/**
|
||||
* Logs glGetError() to slog.e
|
||||
* @param name a string giving some context on the error. Typically __func__.
|
||||
*/
|
||||
static void logEglError(const char* name) noexcept;
|
||||
static void logEglError(const char* name, EGLint error) noexcept;
|
||||
static const char* getEglErrorName(EGLint error) noexcept;
|
||||
|
||||
/**
|
||||
* Calls glGetError() to clear the current error flags. logs a warning to log.w if
|
||||
* an error was pending.
|
||||
*/
|
||||
static void clearGlError() noexcept;
|
||||
|
||||
/**
|
||||
* Always use this instead of eglMakeCurrent(), as it tracks some state.
|
||||
*/
|
||||
|
||||
EGLContext getContextForType(ContextType type) const noexcept;
|
||||
|
||||
// makes the draw and read surface current without changing the current context
|
||||
EGLBoolean makeCurrent(EGLSurface drawSurface, EGLSurface readSurface) noexcept {
|
||||
return egl.makeCurrent(drawSurface, readSurface);
|
||||
}
|
||||
|
||||
// makes context current and set draw and read surfaces to EGL_NO_SURFACE
|
||||
EGLBoolean makeCurrent(EGLContext context) noexcept {
|
||||
return egl.makeCurrent(context, mEGLDummySurface, mEGLDummySurface);
|
||||
}
|
||||
|
||||
// TODO: this should probably use getters instead.
|
||||
EGLDisplay mEGLDisplay = EGL_NO_DISPLAY;
|
||||
EGLContext mEGLContext = EGL_NO_CONTEXT;
|
||||
EGLContext mEGLContextProtected = EGL_NO_CONTEXT;
|
||||
EGLSurface mEGLDummySurface = EGL_NO_SURFACE;
|
||||
ContextType mCurrentContextType = ContextType::NONE;
|
||||
// mEGLConfig is valid only if ext.egl.KHR_no_config_context is false
|
||||
EGLConfig mEGLConfig = EGL_NO_CONFIG_KHR;
|
||||
Config mContextAttribs;
|
||||
std::vector<EGLContext> mAdditionalContexts;
|
||||
|
||||
// supported extensions detected at runtime
|
||||
struct {
|
||||
struct {
|
||||
bool OES_EGL_image_external_essl3 = false;
|
||||
} gl;
|
||||
struct {
|
||||
bool ANDROID_recordable = false;
|
||||
bool KHR_create_context = false;
|
||||
bool KHR_gl_colorspace = false;
|
||||
bool KHR_no_config_context = false;
|
||||
bool KHR_surfaceless_context = false;
|
||||
bool EXT_protected_content = false;
|
||||
} egl;
|
||||
} ext;
|
||||
|
||||
struct SwapChainEGL : public Platform::SwapChain {
|
||||
EGLSurface sur = EGL_NO_SURFACE;
|
||||
Config attribs{};
|
||||
EGLNativeWindowType nativeWindow{};
|
||||
EGLConfig config{};
|
||||
uint64_t flags{};
|
||||
};
|
||||
|
||||
void initializeGlExtensions() noexcept;
|
||||
|
||||
protected:
|
||||
EGLConfig findSwapChainConfig(uint64_t flags, bool window, bool pbuffer) const;
|
||||
|
||||
private:
|
||||
class EGL {
|
||||
EGLDisplay& mEGLDisplay;
|
||||
EGLSurface mCurrentDrawSurface = EGL_NO_SURFACE;
|
||||
EGLSurface mCurrentReadSurface = EGL_NO_SURFACE;
|
||||
EGLContext mCurrentContext = EGL_NO_CONTEXT;
|
||||
public:
|
||||
explicit EGL(EGLDisplay& dpy) : mEGLDisplay(dpy) {}
|
||||
EGLBoolean makeCurrent(EGLContext context,
|
||||
EGLSurface drawSurface, EGLSurface readSurface) noexcept;
|
||||
|
||||
EGLBoolean makeCurrent(EGLSurface drawSurface, EGLSurface readSurface) noexcept {
|
||||
return makeCurrent(mCurrentContext, drawSurface, readSurface);
|
||||
}
|
||||
} egl{ mEGLDisplay };
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_EGL_H
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_EGL_ANDROID_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_EGL_ANDROID_H
|
||||
|
||||
#include <backend/AcquiredImage.h>
|
||||
#include <backend/Platform.h>
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
#include <backend/platforms/PlatformEGL.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class ExternalStreamManagerAndroid;
|
||||
|
||||
/**
|
||||
* A concrete implementation of OpenGLPlatform and subclass of PlatformEGL that supports
|
||||
* EGL on Android. It adds Android streaming functionality to PlatformEGL.
|
||||
*/
|
||||
class PlatformEGLAndroid : public PlatformEGL {
|
||||
public:
|
||||
|
||||
PlatformEGLAndroid() noexcept;
|
||||
~PlatformEGLAndroid() noexcept override;
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
/**
|
||||
* Returns the Android SDK version.
|
||||
* @return Android SDK version.
|
||||
*/
|
||||
int getOSVersion() const noexcept override;
|
||||
|
||||
Driver* createDriver(void* sharedContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
/**
|
||||
* Set the presentation time using `eglPresentationTimeANDROID`
|
||||
* @param presentationTimeInNanosecond
|
||||
*/
|
||||
void setPresentationTime(int64_t presentationTimeInNanosecond) noexcept override;
|
||||
|
||||
|
||||
Stream* createStream(void* nativeStream) noexcept override;
|
||||
void destroyStream(Stream* stream) noexcept override;
|
||||
void attach(Stream* stream, intptr_t tname) noexcept override;
|
||||
void detach(Stream* stream) noexcept override;
|
||||
void updateTexImage(Stream* stream, int64_t* timestamp) noexcept override;
|
||||
|
||||
/**
|
||||
* Converts a AHardwareBuffer to EGLImage
|
||||
* @param source source.image is a AHardwareBuffer
|
||||
* @return source.image contains an EGLImage
|
||||
*/
|
||||
AcquiredImage transformAcquiredImage(AcquiredImage source) noexcept override;
|
||||
|
||||
private:
|
||||
int mOSVersion;
|
||||
ExternalStreamManagerAndroid& mExternalStreamManager;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_EGL_ANDROID_H
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_HEADLESS_H
|
||||
#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_HEADLESS_H
|
||||
|
||||
#include "PlatformEGL.h"
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A concrete implementation of OpenGLPlatform that supports EGL with only headless swapchains.
|
||||
*/
|
||||
class PlatformEGLHeadless : public PlatformEGL {
|
||||
public:
|
||||
PlatformEGLHeadless() noexcept;
|
||||
|
||||
Driver* createDriver(void* sharedContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
protected:
|
||||
bool isOpenGL() const noexcept override;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_HEADLESS_H
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_GLX_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_GLX_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bluegl/BlueGL.h"
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A concrete implementation of OpenGLPlatform that supports GLX.
|
||||
*/
|
||||
class PlatformGLX : public OpenGLPlatform {
|
||||
protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
Driver* createDriver(void* sharedGLContext,
|
||||
const DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
int getOSVersion() const noexcept final override { return 0; }
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain, SwapChain* readSwapChain) noexcept override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
|
||||
private:
|
||||
Display *mGLXDisplay;
|
||||
GLXContext mGLXContext;
|
||||
GLXFBConfig* mGLXConfig;
|
||||
GLXPbuffer mDummySurface;
|
||||
std::vector<GLXPbuffer> mPBuffers;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_GLX_H
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_WGL_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_WGL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include "utils/unwindows.h"
|
||||
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A concrete implementation of OpenGLPlatform that supports WGL.
|
||||
*/
|
||||
class PlatformWGL : public OpenGLPlatform {
|
||||
protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
Driver* createDriver(void* sharedGLContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
int getOSVersion() const noexcept final override { return 0; }
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain, SwapChain* readSwapChain) noexcept override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
|
||||
protected:
|
||||
HGLRC mContext = NULL;
|
||||
HWND mHWnd = NULL;
|
||||
HDC mWhdc = NULL;
|
||||
PIXELFORMATDESCRIPTOR mPfd = {};
|
||||
std::vector<HGLRC> mAdditionalContexts;
|
||||
std::vector<int> mAttribs;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_GLX_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_WEBGL_H
|
||||
#define TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_WEBGL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A concrete implementation of OpenGLPlatform that supports WebGL.
|
||||
*/
|
||||
class PlatformWebGL : public OpenGLPlatform {
|
||||
protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
Driver* createDriver(void* sharedGLContext,
|
||||
const Platform::DriverConfig& driverConfig) noexcept override;
|
||||
|
||||
int getOSVersion() const noexcept override;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
bool makeCurrent(ContextType type, SwapChain* drawSwapChain, SwapChain* readSwapChain) noexcept override;
|
||||
void commit(SwapChain* swapChain) noexcept override;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_OPENGL_OPENGL_PLATFORM_WEBGL_H
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
#define TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
|
||||
#include <backend/Platform.h>
|
||||
|
||||
#include <bluevk/BlueVK.h>
|
||||
|
||||
#include <utils/CString.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/PrivateImplementation.h>
|
||||
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
using SwapChain = Platform::SwapChain;
|
||||
|
||||
/**
|
||||
* Private implementation details for the provided vulkan platform.
|
||||
*/
|
||||
struct VulkanPlatformPrivate;
|
||||
|
||||
/**
|
||||
* A Platform interface that creates a Vulkan backend.
|
||||
*/
|
||||
class VulkanPlatform : public Platform, utils::PrivateImplementation<VulkanPlatformPrivate> {
|
||||
public:
|
||||
|
||||
/**
|
||||
* A collection of handles to objects and metadata that comprises a Vulkan context. The client
|
||||
* can instantiate this struct and pass to Engine::Builder::sharedContext if they wishes to
|
||||
* share their vulkan context. This is specifically necessary if the client wishes to override
|
||||
* the swapchain API.
|
||||
*/
|
||||
struct VulkanSharedContext {
|
||||
VkInstance instance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice logicalDevice = VK_NULL_HANDLE;
|
||||
uint32_t graphicsQueueFamilyIndex = 0xFFFFFFFF;
|
||||
// In the usual case, the client needs to allocate at least one more graphics queue
|
||||
// for Filament, and this index is the param to pass into vkGetDeviceQueue. In the case
|
||||
// where the gpu only has one graphics queue. Then the client needs to ensure that no
|
||||
// concurrent access can occur.
|
||||
uint32_t graphicsQueueIndex = 0xFFFFFFFF;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shorthand for the pointer to the Platform SwapChain struct, we use it also as a handle (i.e.
|
||||
* identifier for the swapchain).
|
||||
*/
|
||||
using SwapChainPtr = Platform::SwapChain*;
|
||||
|
||||
/**
|
||||
* Collection of images, formats, and extent (width/height) that defines the swapchain.
|
||||
*/
|
||||
struct SwapChainBundle {
|
||||
utils::FixedCapacityVector<VkImage> colors;
|
||||
VkImage depth = VK_NULL_HANDLE;
|
||||
VkFormat colorFormat = VK_FORMAT_UNDEFINED;
|
||||
VkFormat depthFormat = VK_FORMAT_UNDEFINED;
|
||||
VkExtent2D extent = {0, 0};
|
||||
};
|
||||
|
||||
VulkanPlatform();
|
||||
|
||||
~VulkanPlatform() override;
|
||||
|
||||
Driver* createDriver(void* sharedContext,
|
||||
Platform::DriverConfig const& driverConfig) noexcept override;
|
||||
|
||||
int getOSVersion() const noexcept override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// ---------- Platform Customization options ----------
|
||||
struct Customization {
|
||||
/**
|
||||
* The client can specify the GPU (i.e. VkDevice) for the platform. We allow the
|
||||
* following preferences:
|
||||
* 1) A substring to match against `VkPhysicalDeviceProperties.deviceName`. Empty string
|
||||
* by default.
|
||||
* 2) Index of the device in the list as returned by
|
||||
* `vkEnumeratePhysicalDevices`. -1 by default to indicate no preference.
|
||||
*/
|
||||
struct GPUPreference {
|
||||
utils::CString deviceName;
|
||||
int8_t index = -1;
|
||||
} gpu;
|
||||
|
||||
/**
|
||||
* Whether the platform supports sRGB swapchain. Default is true.
|
||||
*/
|
||||
bool isSRGBSwapChainSupported = true;
|
||||
|
||||
/**
|
||||
* When the platform window is resized, we will flush and wait on the command queues
|
||||
* before recreating the swapchain. Default is true.
|
||||
*/
|
||||
bool flushAndWaitOnWindowResize = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Client can override to indicate customized behavior or parameter for their platform.
|
||||
* @return `Customization` struct that indicates the client's platform
|
||||
* customizations.
|
||||
*/
|
||||
virtual Customization getCustomization() const noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
// -------- End platform customization options --------
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the images handles and format of the memory backing the swapchain. This should be called
|
||||
* after createSwapChain() or after recreateIfResized().
|
||||
* @param swapchain The handle returned by createSwapChain()
|
||||
* @return An array of VkImages
|
||||
*/
|
||||
virtual SwapChainBundle getSwapChainBundle(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Acquire the next image for rendering. The `index` will be written with an non-negative
|
||||
* integer that the backend can use to index into the `SwapChainBundle.colors` array. The
|
||||
* corresponding VkImage will be used as the output color attachment. The client should signal
|
||||
* the `clientSignal` semaphore when the image is ready to be used by the backend.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @param clientSignal The semaphore that the client will signal to indicate that the backend
|
||||
* may render into the image.
|
||||
* @param index Pointer to memory that will be filled with the index that corresponding
|
||||
* to an image in the `SwapChainBundle.colors` array.
|
||||
* @return Result of acquire
|
||||
*/
|
||||
virtual VkResult acquire(SwapChainPtr handle, VkSemaphore clientSignal, uint32_t* index);
|
||||
|
||||
/**
|
||||
* Present the image corresponding to `index` to the display. The client should wait on
|
||||
* `finishedDrawing` before presenting.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @param index Index that corresponding to an image in the
|
||||
* `SwapChainBundle.colors` array.
|
||||
* @param finishedDrawing Backend passes in a semaphore that the client will signal to
|
||||
* indicate that the client may render into the image.
|
||||
* @return Result of present
|
||||
*/
|
||||
virtual VkResult present(SwapChainPtr handle, uint32_t index, VkSemaphore finishedDrawing);
|
||||
|
||||
/**
|
||||
* Check if the surface size has changed.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @return Whether the swapchain has been resized
|
||||
*/
|
||||
virtual bool hasResized(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Carry out a recreation of the swapchain.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @return Result of the recreation
|
||||
*/
|
||||
virtual VkResult recreate(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Create a swapchain given a platform window, or if given a null `nativeWindow`, then we
|
||||
* try to create a headless swapchain with the given `extent`.
|
||||
* @param flags Optional parameters passed to the client as defined in
|
||||
* Filament::SwapChain.h.
|
||||
* @param extent Optional width and height that indicates the size of the headless swapchain.
|
||||
* @return Result of the operation
|
||||
*/
|
||||
virtual SwapChainPtr createSwapChain(void* nativeWindow, uint64_t flags = 0,
|
||||
VkExtent2D extent = {0, 0});
|
||||
|
||||
/**
|
||||
* Destroy the swapchain.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
*/
|
||||
virtual void destroy(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Clean up any resources owned by the Platform. For example, if the Vulkan instance handle was
|
||||
* generated by the platform, we need to clean it up in this method.
|
||||
*/
|
||||
virtual void terminate();
|
||||
|
||||
/**
|
||||
* @return The instance (VkInstance) for the Vulkan backend.
|
||||
*/
|
||||
VkInstance getInstance() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The logical device (VkDevice) that was selected as the backend device.
|
||||
*/
|
||||
VkDevice getDevice() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The physical device (i.e gpu) that was selected as the backend physical device.
|
||||
*/
|
||||
VkPhysicalDevice getPhysicalDevice() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The family index of the graphics queue selected for the Vulkan backend.
|
||||
*/
|
||||
uint32_t getGraphicsQueueFamilyIndex() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The index of the graphics queue (if there are multiple graphics queues)
|
||||
* selected for the Vulkan backend.
|
||||
*/
|
||||
uint32_t getGraphicsQueueIndex() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The queue that was selected for the Vulkan backend.
|
||||
*/
|
||||
VkQueue getGraphicsQueue() const noexcept;
|
||||
|
||||
private:
|
||||
// Platform dependent helper methods
|
||||
using ExtensionSet = std::unordered_set<std::string_view>;
|
||||
static ExtensionSet getRequiredInstanceExtensions();
|
||||
|
||||
using SurfaceBundle = std::tuple<VkSurfaceKHR, VkExtent2D>;
|
||||
static SurfaceBundle createVkSurfaceKHR(void* nativeWindow, VkInstance instance,
|
||||
uint64_t flags) noexcept;
|
||||
|
||||
friend struct VulkanPlatformPrivate;
|
||||
};
|
||||
|
||||
}// namespace filament::backend
|
||||
|
||||
#endif// TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
96
dart_filament/native/include/filament/bluegl/BlueGL.h
Normal file
96
dart_filament/native/include/filament/bluegl/BlueGL.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**********************************************************************************************
|
||||
* Generated by bluegl/bluegl-gen.py
|
||||
* DO NOT EDIT
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef TNT_FILAMENT_BLUEGL__H
|
||||
#define TNT_FILAMENT_BLUEGL__H
|
||||
|
||||
|
||||
// MSVC includes .../Windows Kits\10\Include\10.0.17763.0\um\GL/gl.h, with gl APIs conflicting with
|
||||
// bluegl\include\GL/glcorearb.h, causing errors for OpenGL APIs such as:
|
||||
// error C2375: 'glBindTexture': redefinition; different linkage
|
||||
#ifndef FILAMENT_PLATFORM_WGL
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#endif
|
||||
|
||||
|
||||
#include <GL/glcorearb.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
#ifdef far
|
||||
#undef far
|
||||
#endif
|
||||
|
||||
#ifdef near
|
||||
#undef near
|
||||
#endif
|
||||
|
||||
#ifdef ERROR
|
||||
#undef ERROR
|
||||
#endif
|
||||
|
||||
#ifdef OPAQUE
|
||||
#undef OPAQUE
|
||||
#endif
|
||||
|
||||
#ifdef TRANSPARENT
|
||||
#undef TRANSPARENT
|
||||
#endif
|
||||
|
||||
#ifdef PURE
|
||||
#undef PURE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
namespace bluegl {
|
||||
|
||||
/**
|
||||
* Looks up and binds all available OpenGL Core functions.
|
||||
* Every call to this function will increase an internal reference
|
||||
* counter that can be decreased by calling unbind().
|
||||
*
|
||||
* @return 0 on success or -1 if an error occurred.
|
||||
*/
|
||||
int bind();
|
||||
|
||||
/**
|
||||
* Unbinds all available OpenGL Core functions.
|
||||
* Every call to this function will decrease an internal reference
|
||||
* counter and unbind all OpenGL functions when the counter reaches 0.
|
||||
* As such you should assume that no OpenGL calls can be made after
|
||||
* calling this function.
|
||||
*/
|
||||
void unbind();
|
||||
|
||||
|
||||
} // namespace bluegl
|
||||
|
||||
#endif // TNT_FILAMENT_BLUEGL__H
|
||||
2600
dart_filament/native/include/filament/bluegl/BlueGLDefines.h
Normal file
2600
dart_filament/native/include/filament/bluegl/BlueGLDefines.h
Normal file
File diff suppressed because it is too large
Load Diff
85
dart_filament/native/include/filament/camutils/Bookmark.h
Normal file
85
dart_filament/native/include/filament/camutils/Bookmark.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CAMUTILS_BOOKMARK_H
|
||||
#define CAMUTILS_BOOKMARK_H
|
||||
|
||||
#include <camutils/compiler.h>
|
||||
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec3.h>
|
||||
|
||||
namespace filament {
|
||||
namespace camutils {
|
||||
|
||||
template <typename FLOAT> class FreeFlightManipulator;
|
||||
template <typename FLOAT> class OrbitManipulator;
|
||||
template <typename FLOAT> class MapManipulator;
|
||||
template <typename FLOAT> class Manipulator;
|
||||
|
||||
enum class Mode { ORBIT, MAP, FREE_FLIGHT };
|
||||
|
||||
/**
|
||||
* Opaque memento to a viewing position and orientation (e.g. the "home" camera position).
|
||||
*
|
||||
* This little struct is meant to be passed around by value and can be used to track camera
|
||||
* animation between waypoints. In map mode this implements Van Wijk interpolation.
|
||||
*
|
||||
* @see Manipulator::getCurrentBookmark, Manipulator::jumpToBookmark
|
||||
*/
|
||||
template <typename FLOAT>
|
||||
struct CAMUTILS_PUBLIC Bookmark {
|
||||
/**
|
||||
* Interpolates between two bookmarks. The t argument must be between 0 and 1 (inclusive), and
|
||||
* the two endpoints must have the same mode (ORBIT or MAP).
|
||||
*/
|
||||
static Bookmark<FLOAT> interpolate(Bookmark<FLOAT> a, Bookmark<FLOAT> b, double t);
|
||||
|
||||
/**
|
||||
* Recommends a duration for animation between two MAP endpoints. The return value is a unitless
|
||||
* multiplier.
|
||||
*/
|
||||
static double duration(Bookmark<FLOAT> a, Bookmark<FLOAT> b);
|
||||
|
||||
private:
|
||||
struct MapParams {
|
||||
FLOAT extent;
|
||||
filament::math::vec2<FLOAT> center;
|
||||
};
|
||||
struct OrbitParams {
|
||||
FLOAT phi;
|
||||
FLOAT theta;
|
||||
FLOAT distance;
|
||||
filament::math::vec3<FLOAT> pivot;
|
||||
};
|
||||
struct FlightParams {
|
||||
FLOAT pitch;
|
||||
FLOAT yaw;
|
||||
filament::math::vec3<FLOAT> position;
|
||||
};
|
||||
Mode mode;
|
||||
MapParams map;
|
||||
OrbitParams orbit;
|
||||
FlightParams flight;
|
||||
friend class FreeFlightManipulator<FLOAT>;
|
||||
friend class OrbitManipulator<FLOAT>;
|
||||
friend class MapManipulator<FLOAT>;
|
||||
};
|
||||
|
||||
} // namespace camutils
|
||||
} // namespace filament
|
||||
|
||||
#endif // CAMUTILS_BOOKMARK_H
|
||||
298
dart_filament/native/include/filament/camutils/Manipulator.h
Normal file
298
dart_filament/native/include/filament/camutils/Manipulator.h
Normal file
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CAMUTILS_MANIPULATOR_H
|
||||
#define CAMUTILS_MANIPULATOR_H
|
||||
|
||||
#include <camutils/Bookmark.h>
|
||||
#include <camutils/compiler.h>
|
||||
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace filament {
|
||||
namespace camutils {
|
||||
|
||||
enum class Fov { VERTICAL, HORIZONTAL };
|
||||
|
||||
/**
|
||||
* Helper that enables camera interaction similar to sketchfab or Google Maps.
|
||||
*
|
||||
* Clients notify the camera manipulator of various mouse or touch events, then periodically call
|
||||
* its getLookAt() method so that they can adjust their camera(s). Three modes are supported: ORBIT,
|
||||
* MAP, and FREE_FLIGHT. To construct a manipulator instance, the desired mode is passed into the
|
||||
* create method.
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* using CameraManipulator = camutils::Manipulator<float>;
|
||||
* CameraManipulator* manip;
|
||||
*
|
||||
* void init() {
|
||||
* manip = CameraManipulator::Builder()
|
||||
* .viewport(1024, 768)
|
||||
* .build(camutils::Mode::ORBIT);
|
||||
* }
|
||||
*
|
||||
* void onMouseDown(int x, int y) {
|
||||
* manip->grabBegin(x, y, false);
|
||||
* }
|
||||
*
|
||||
* void onMouseMove(int x, int y) {
|
||||
* manip->grabUpdate(x, y);
|
||||
* }
|
||||
*
|
||||
* void onMouseUp(int x, int y) {
|
||||
* manip->grabEnd();
|
||||
* }
|
||||
*
|
||||
* void gameLoop() {
|
||||
* while (true) {
|
||||
* filament::math::float3 eye, center, up;
|
||||
* manip->getLookAt(&eye, ¢er, &up);
|
||||
* camera->lookAt(eye, center, up);
|
||||
* render();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @see Bookmark
|
||||
*/
|
||||
template <typename FLOAT>
|
||||
class CAMUTILS_PUBLIC Manipulator {
|
||||
public:
|
||||
using vec2 = filament::math::vec2<FLOAT>;
|
||||
using vec3 = filament::math::vec3<FLOAT>;
|
||||
using vec4 = filament::math::vec4<FLOAT>;
|
||||
|
||||
/** Opaque handle to a viewing position and orientation to facilitate camera animation. */
|
||||
using Bookmark = filament::camutils::Bookmark<FLOAT>;
|
||||
|
||||
/** Optional raycasting function to enable perspective-correct panning. */
|
||||
typedef bool (*RayCallback)(const vec3& origin, const vec3& dir, FLOAT* t, void* userdata);
|
||||
|
||||
/** Builder state, direct access is allowed but Builder methods are preferred. **/
|
||||
struct Config {
|
||||
int viewport[2];
|
||||
vec3 targetPosition;
|
||||
vec3 upVector;
|
||||
FLOAT zoomSpeed;
|
||||
vec3 orbitHomePosition;
|
||||
vec2 orbitSpeed;
|
||||
Fov fovDirection;
|
||||
FLOAT fovDegrees;
|
||||
FLOAT farPlane;
|
||||
vec2 mapExtent;
|
||||
FLOAT mapMinDistance;
|
||||
vec3 flightStartPosition;
|
||||
FLOAT flightStartPitch;
|
||||
FLOAT flightStartYaw;
|
||||
FLOAT flightMaxSpeed;
|
||||
FLOAT flightSpeedSteps;
|
||||
vec2 flightPanSpeed;
|
||||
FLOAT flightMoveDamping;
|
||||
vec4 groundPlane;
|
||||
RayCallback raycastCallback;
|
||||
void* raycastUserdata;
|
||||
};
|
||||
|
||||
struct Builder {
|
||||
// Common properties
|
||||
Builder& viewport(int width, int height); //! Width and height of the viewing area
|
||||
Builder& targetPosition(FLOAT x, FLOAT y, FLOAT z); //! World-space position of interest, defaults to (0,0,0)
|
||||
Builder& upVector(FLOAT x, FLOAT y, FLOAT z); //! Orientation for the home position, defaults to (0,1,0)
|
||||
Builder& zoomSpeed(FLOAT val); //! Multiplied with scroll delta, defaults to 0.01
|
||||
|
||||
// Orbit mode properties
|
||||
Builder& orbitHomePosition(FLOAT x, FLOAT y, FLOAT z); //! Initial eye position in world space, defaults to (0,0,1)
|
||||
Builder& orbitSpeed(FLOAT x, FLOAT y); //! Multiplied with viewport delta, defaults to 0.01
|
||||
|
||||
// Map mode properties
|
||||
Builder& fovDirection(Fov fov); //! The axis that's held constant when viewport changes
|
||||
Builder& fovDegrees(FLOAT degrees); //! The full FOV (not the half-angle)
|
||||
Builder& farPlane(FLOAT distance); //! The distance to the far plane
|
||||
Builder& mapExtent(FLOAT worldWidth, FLOAT worldHeight); //! The ground size for computing home position
|
||||
Builder& mapMinDistance(FLOAT mindist); //! Constrains the zoom-in level
|
||||
|
||||
// Free flight properties
|
||||
Builder& flightStartPosition(FLOAT x, FLOAT y, FLOAT z); //! Initial eye position in world space, defaults to (0,0,0)
|
||||
Builder& flightStartOrientation(FLOAT pitch, FLOAT yaw); //! Initial orientation in pitch and yaw, defaults to (0,0)
|
||||
Builder& flightMaxMoveSpeed(FLOAT maxSpeed); //! The maximum camera speed in world units per second, defaults to 10
|
||||
Builder& flightSpeedSteps(int steps); //! The number of speed steps adjustable with scroll wheel, defaults to 80
|
||||
Builder& flightPanSpeed(FLOAT x, FLOAT y); //! Multiplied with viewport delta, defaults to 0.01,0.01
|
||||
Builder& flightMoveDamping(FLOAT damping); //! Applies a deceleration to camera movement, defaults to 0 (no damping)
|
||||
//! Lower values give slower damping times, a good default is 15
|
||||
//! Too high a value may lead to instability
|
||||
|
||||
// Raycast properties
|
||||
Builder& groundPlane(FLOAT a, FLOAT b, FLOAT c, FLOAT d); //! Plane equation used as a raycast fallback
|
||||
Builder& raycastCallback(RayCallback cb, void* userdata); //! Raycast function for accurate grab-and-pan
|
||||
|
||||
/**
|
||||
* Creates a new camera manipulator, either ORBIT, MAP, or FREE_FLIGHT.
|
||||
*
|
||||
* Clients can simply use "delete" to destroy the manipulator.
|
||||
*/
|
||||
Manipulator* build(Mode mode);
|
||||
|
||||
Config details = {};
|
||||
};
|
||||
|
||||
virtual ~Manipulator() = default;
|
||||
|
||||
/**
|
||||
* Gets the immutable mode of the manipulator.
|
||||
*/
|
||||
Mode getMode() const { return mMode; }
|
||||
|
||||
/**
|
||||
* Sets the viewport dimensions. The manipulator uses this to process grab events and raycasts.
|
||||
*/
|
||||
void setViewport(int width, int height);
|
||||
|
||||
/**
|
||||
* Gets the current orthonormal basis; this is usually called once per frame.
|
||||
*/
|
||||
void getLookAt(vec3* eyePosition, vec3* targetPosition, vec3* upward) const;
|
||||
|
||||
/**
|
||||
* Given a viewport coordinate, picks a point in the ground plane, or in the actual scene if the
|
||||
* raycast callback was provided.
|
||||
*/
|
||||
bool raycast(int x, int y, vec3* result) const;
|
||||
|
||||
/**
|
||||
* Given a viewport coordinate, computes a picking ray (origin + direction).
|
||||
*/
|
||||
void getRay(int x, int y, vec3* origin, vec3* dir) const;
|
||||
|
||||
/**
|
||||
* Starts a grabbing session (i.e. the user is dragging around in the viewport).
|
||||
*
|
||||
* In MAP mode, this starts a panning session.
|
||||
* In ORBIT mode, this starts either rotating or strafing.
|
||||
* In FREE_FLIGHT mode, this starts a nodal panning session.
|
||||
*
|
||||
* @param x X-coordinate for point of interest in viewport space
|
||||
* @param y Y-coordinate for point of interest in viewport space
|
||||
* @param strafe ORBIT mode only; if true, starts a translation rather than a rotation
|
||||
*/
|
||||
virtual void grabBegin(int x, int y, bool strafe) = 0;
|
||||
|
||||
/**
|
||||
* Updates a grabbing session.
|
||||
*
|
||||
* This must be called at least once between grabBegin / grabEnd to dirty the camera.
|
||||
*/
|
||||
virtual void grabUpdate(int x, int y) = 0;
|
||||
|
||||
/**
|
||||
* Ends a grabbing session.
|
||||
*/
|
||||
virtual void grabEnd() = 0;
|
||||
|
||||
/**
|
||||
* Keys used to translate the camera in FREE_FLIGHT mode.
|
||||
* FORWARD and BACKWARD dolly the camera forwards and backwards.
|
||||
* LEFT and RIGHT strafe the camera left and right.
|
||||
* UP and DOWN boom the camera upwards and downwards.
|
||||
*/
|
||||
enum class Key {
|
||||
FORWARD,
|
||||
LEFT,
|
||||
BACKWARD,
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN,
|
||||
|
||||
COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* Signals that a key is now in the down state.
|
||||
*
|
||||
* In FREE_FLIGHT mode, the camera is translated forward and backward and strafed left and right
|
||||
* depending on the depressed keys. This allows WASD-style movement.
|
||||
*/
|
||||
virtual void keyDown(Key key);
|
||||
|
||||
/**
|
||||
* Signals that a key is now in the up state.
|
||||
*
|
||||
* @see keyDown
|
||||
*/
|
||||
virtual void keyUp(Key key);
|
||||
|
||||
/**
|
||||
* In MAP and ORBIT modes, dollys the camera along the viewing direction.
|
||||
* In FREE_FLIGHT mode, adjusts the move speed of the camera.
|
||||
*
|
||||
* @param x X-coordinate for point of interest in viewport space, ignored in FREE_FLIGHT mode
|
||||
* @param y Y-coordinate for point of interest in viewport space, ignored in FREE_FLIGHT mode
|
||||
* @param scrolldelta In MAP and ORBIT modes, negative means "zoom in", positive means "zoom out"
|
||||
* In FREE_FLIGHT mode, negative means "slower", positive means "faster"
|
||||
*/
|
||||
virtual void scroll(int x, int y, FLOAT scrolldelta) = 0;
|
||||
|
||||
/**
|
||||
* Processes input and updates internal state.
|
||||
*
|
||||
* This must be called once every frame before getLookAt is valid.
|
||||
*
|
||||
* @param deltaTime The amount of time, in seconds, passed since the previous call to update.
|
||||
*/
|
||||
virtual void update(FLOAT deltaTime);
|
||||
|
||||
/**
|
||||
* Gets a handle that can be used to reset the manipulator back to its current position.
|
||||
*
|
||||
* @see jumpToBookmark
|
||||
*/
|
||||
virtual Bookmark getCurrentBookmark() const = 0;
|
||||
|
||||
/**
|
||||
* Gets a handle that can be used to reset the manipulator back to its home position.
|
||||
*
|
||||
* @see jumpToBookmark
|
||||
*/
|
||||
virtual Bookmark getHomeBookmark() const = 0;
|
||||
|
||||
/**
|
||||
* Sets the manipulator position and orientation back to a stashed state.
|
||||
*
|
||||
* @see getCurrentBookmark, getHomeBookmark
|
||||
*/
|
||||
virtual void jumpToBookmark(const Bookmark& bookmark) = 0;
|
||||
|
||||
protected:
|
||||
Manipulator(Mode mode, const Config& props);
|
||||
|
||||
virtual void setProperties(const Config& props);
|
||||
|
||||
vec3 raycastFarPlane(int x, int y) const;
|
||||
|
||||
const Mode mMode;
|
||||
Config mProps;
|
||||
vec3 mEye;
|
||||
vec3 mTarget;
|
||||
};
|
||||
|
||||
} // namespace camutils
|
||||
} // namespace filament
|
||||
|
||||
#endif /* CAMUTILS_MANIPULATOR_H */
|
||||
26
dart_filament/native/include/filament/camutils/compiler.h
Normal file
26
dart_filament/native/include/filament/camutils/compiler.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CAMUTILS_COMPILER_H
|
||||
#define CAMUTILS_COMPILER_H
|
||||
|
||||
#if __has_attribute(visibility)
|
||||
# define CAMUTILS_PUBLIC __attribute__((visibility("default")))
|
||||
#else
|
||||
# define CAMUTILS_PUBLIC
|
||||
#endif
|
||||
|
||||
#endif // CAMUTILS_COMPILER_H
|
||||
98
dart_filament/native/include/filament/filamat/Enums.h
Normal file
98
dart_filament/native/include/filament/filamat/Enums.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_ENUMMANAGER_H
|
||||
#define TNT_ENUMMANAGER_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <filamat/MaterialBuilder.h>
|
||||
|
||||
namespace filamat {
|
||||
|
||||
using Property = MaterialBuilder::Property;
|
||||
using UniformType = MaterialBuilder::UniformType;
|
||||
using SamplerType = MaterialBuilder::SamplerType;
|
||||
using SubpassType = MaterialBuilder::SubpassType;
|
||||
using SamplerFormat = MaterialBuilder::SamplerFormat;
|
||||
using ParameterPrecision = MaterialBuilder::ParameterPrecision;
|
||||
using OutputTarget = MaterialBuilder::OutputTarget;
|
||||
using OutputQualifier = MaterialBuilder::VariableQualifier;
|
||||
using OutputType = MaterialBuilder::OutputType;
|
||||
using ConstantType = MaterialBuilder::ConstantType;
|
||||
|
||||
// Convenience methods to convert std::string to Enum and also iterate over Enum values.
|
||||
class Enums {
|
||||
public:
|
||||
|
||||
// Returns true if string "s" is a valid string representation of an element of enum T.
|
||||
template<typename T>
|
||||
static bool isValid(const std::string& s) noexcept {
|
||||
std::unordered_map<std::string, T>& map = getMap<T>();
|
||||
return map.find(s) != map.end();
|
||||
}
|
||||
|
||||
// Return enum matching its string representation. Returns undefined if s is not a valid enum T
|
||||
// value. You should always call isValid() first to validate a string before calling toEnum().
|
||||
template<typename T>
|
||||
static T toEnum(const std::string& s) noexcept {
|
||||
std::unordered_map<std::string, T>& map = getMap<T>();
|
||||
return map.at(s);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static std::string toString(T t) noexcept;
|
||||
|
||||
// Return a map of all values in an enum with their string representation.
|
||||
template<typename T>
|
||||
static std::unordered_map<std::string, T>& map() noexcept {
|
||||
std::unordered_map<std::string, T>& map = getMap<T>();
|
||||
return map;
|
||||
};
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
static std::unordered_map<std::string, T>& getMap() noexcept;
|
||||
|
||||
static std::unordered_map<std::string, Property> mStringToProperty;
|
||||
static std::unordered_map<std::string, UniformType> mStringToUniformType;
|
||||
static std::unordered_map<std::string, SamplerType> mStringToSamplerType;
|
||||
static std::unordered_map<std::string, SubpassType> mStringToSubpassType;
|
||||
static std::unordered_map<std::string, SamplerFormat> mStringToSamplerFormat;
|
||||
static std::unordered_map<std::string, ParameterPrecision> mStringToSamplerPrecision;
|
||||
static std::unordered_map<std::string, OutputTarget> mStringToOutputTarget;
|
||||
static std::unordered_map<std::string, OutputQualifier> mStringToOutputQualifier;
|
||||
static std::unordered_map<std::string, OutputType> mStringToOutputType;
|
||||
static std::unordered_map<std::string, ConstantType> mStringToConstantType;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::string Enums::toString(T t) noexcept {
|
||||
std::unordered_map<std::string, T>& map = getMap<T>();
|
||||
auto result = std::find_if(map.begin(), map.end(), [t](auto& pair) {
|
||||
return pair.second == t;
|
||||
});
|
||||
if (result != map.end()) {
|
||||
return result->first;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace filamat
|
||||
|
||||
#endif //TNT_ENUMMANAGER_H
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMAT_INCLUDER_H
|
||||
#define TNT_FILAMAT_INCLUDER_H
|
||||
|
||||
#include <utils/CString.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace filamat {
|
||||
|
||||
struct IncludeResult {
|
||||
// The include name of the root file, as if it were being included.
|
||||
// I.e., 'foobar.h' in the case of #include "foobar.h"
|
||||
const utils::CString includeName;
|
||||
|
||||
// The following fields should be filled out by the IncludeCallback when processing an include,
|
||||
// or when calling resolveIncludes for the root file.
|
||||
|
||||
// The full contents of the include file. This may contain additional, recursive include
|
||||
// directives.
|
||||
utils::CString text;
|
||||
|
||||
// The line number for the first line of text (first line is 0).
|
||||
size_t lineNumberOffset = 0;
|
||||
|
||||
// The name of the include file. This gets passed as "includerName" for any includes inside of
|
||||
// source. This field isn't used by the include system; it's up to the callback to give meaning
|
||||
// to this value and interpret it accordingly. In the case of DirIncluder, this is an empty
|
||||
// string to represent the root include file, and a canonical path for subsequent included
|
||||
// files.
|
||||
utils::CString name;
|
||||
};
|
||||
|
||||
/**
|
||||
* A callback invoked by the include system when an #include "file.h" directive is found.
|
||||
*
|
||||
* For example, if a file main.h includes file.h on line 10, then IncludeCallback would be called
|
||||
* with the following:
|
||||
* includeCallback("main.h", {.includeName = "file.h" })
|
||||
* It's then up to the IncludeCallback to fill out the .text, .name, and (optionally)
|
||||
* lineNumberOffset fields.
|
||||
*
|
||||
* @param includedBy is the value that was given to IncludeResult.name for this source file, or
|
||||
* the empty string for the root source file.
|
||||
* @param result is the IncludeResult that the callback should fill out.
|
||||
* @return true, if the include was resolved successfully, false otherwise.
|
||||
*
|
||||
* For an example of implementing this callback, see tools/matc/src/matc/DirIncluder.h.
|
||||
*/
|
||||
using IncludeCallback = std::function<bool(
|
||||
const utils::CString& includedBy,
|
||||
IncludeResult& result)>;
|
||||
|
||||
} // namespace filamat
|
||||
|
||||
#endif
|
||||
898
dart_filament/native/include/filament/filamat/MaterialBuilder.h
Normal file
898
dart_filament/native/include/filament/filamat/MaterialBuilder.h
Normal file
@@ -0,0 +1,898 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMAT_MATERIAL_PACKAGE_BUILDER_H
|
||||
#define TNT_FILAMAT_MATERIAL_PACKAGE_BUILDER_H
|
||||
|
||||
#include <filament/MaterialEnums.h>
|
||||
|
||||
#include <filamat/IncludeCallback.h>
|
||||
#include <filamat/Package.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/TargetBufferInfo.h>
|
||||
|
||||
#include <utils/BitmaskEnum.h>
|
||||
#include <utils/bitset.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/CString.h>
|
||||
|
||||
#include <math/vec3.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace utils {
|
||||
class JobSystem;
|
||||
}
|
||||
|
||||
namespace filament {
|
||||
class BufferInterfaceBlock;
|
||||
}
|
||||
|
||||
namespace filamat {
|
||||
|
||||
struct MaterialInfo;
|
||||
struct Variant;
|
||||
class ChunkContainer;
|
||||
|
||||
class UTILS_PUBLIC MaterialBuilderBase {
|
||||
public:
|
||||
/**
|
||||
* High-level hint that works in concert with TargetApi to determine the shader models (used to
|
||||
* generate GLSL) and final output representations (spirv and/or text).
|
||||
* When generating the GLSL this is used to differentiate OpenGL from OpenGLES, it is also
|
||||
* used to make some performance adjustments.
|
||||
*/
|
||||
enum class Platform {
|
||||
DESKTOP,
|
||||
MOBILE,
|
||||
ALL
|
||||
};
|
||||
|
||||
/**
|
||||
* TargetApi defines which language after transpilation will be used, it is used to
|
||||
* account for some differences between these languages when generating the GLSL.
|
||||
*/
|
||||
enum class TargetApi : uint8_t {
|
||||
OPENGL = 0x01u,
|
||||
VULKAN = 0x02u,
|
||||
METAL = 0x04u,
|
||||
ALL = OPENGL | VULKAN | METAL
|
||||
};
|
||||
|
||||
/*
|
||||
* Generally we generate GLSL that will be converted to SPIRV, optimized and then
|
||||
* transpiled to the backend's language such as MSL, ESSL300, GLSL410 or SPIRV, in this
|
||||
* case the generated GLSL uses ESSL310 or GLSL450 and has Vulkan semantics and
|
||||
* TargetLanguage::SPIRV must be used.
|
||||
*
|
||||
* However, in some cases (e.g. when no optimization is asked) we generate the *final* GLSL
|
||||
* directly, this GLSL must be ESSL300 or GLSL410 and cannot use any Vulkan syntax, for this
|
||||
* situation we use TargetLanguage::GLSL. In this case TargetApi is guaranteed to be OPENGL.
|
||||
*
|
||||
* Note that TargetLanguage::GLSL is not the common case, as it is generally not used in
|
||||
* release builds.
|
||||
*
|
||||
* Also note that glslang performs semantics analysis on whichever GLSL ends up being generated.
|
||||
*/
|
||||
enum class TargetLanguage {
|
||||
GLSL, // GLSL with OpenGL 4.1 / OpenGL ES 3.0 semantics
|
||||
SPIRV // GLSL with Vulkan semantics
|
||||
};
|
||||
|
||||
enum class Optimization {
|
||||
NONE,
|
||||
PREPROCESSOR,
|
||||
SIZE,
|
||||
PERFORMANCE
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize MaterialBuilder.
|
||||
*
|
||||
* init must be called first before building any materials.
|
||||
*/
|
||||
static void init();
|
||||
|
||||
/**
|
||||
* Release internal MaterialBuilder resources.
|
||||
*
|
||||
* Call shutdown when finished building materials to release all internal resources. After
|
||||
* calling shutdown, another call to MaterialBuilder::init must precede another material build.
|
||||
*/
|
||||
static void shutdown();
|
||||
|
||||
protected:
|
||||
// Looks at platform and target API, then decides on shader models and output formats.
|
||||
void prepare(bool vulkanSemantics, filament::backend::FeatureLevel featureLevel);
|
||||
|
||||
using ShaderModel = filament::backend::ShaderModel;
|
||||
Platform mPlatform = Platform::DESKTOP;
|
||||
TargetApi mTargetApi = (TargetApi) 0;
|
||||
Optimization mOptimization = Optimization::PERFORMANCE;
|
||||
bool mPrintShaders = false;
|
||||
bool mGenerateDebugInfo = false;
|
||||
bool mIncludeEssl1 = true;
|
||||
utils::bitset32 mShaderModels;
|
||||
struct CodeGenParams {
|
||||
ShaderModel shaderModel;
|
||||
TargetApi targetApi;
|
||||
TargetLanguage targetLanguage;
|
||||
filament::backend::FeatureLevel featureLevel;
|
||||
};
|
||||
std::vector<CodeGenParams> mCodeGenPermutations;
|
||||
|
||||
// Keeps track of how many times MaterialBuilder::init() has been called without a call to
|
||||
// MaterialBuilder::shutdown(). Internally, glslang does something similar. We keep track for
|
||||
// ourselves, so we can inform the user if MaterialBuilder::init() hasn't been called before
|
||||
// attempting to build a material.
|
||||
static std::atomic<int> materialBuilderClients;
|
||||
};
|
||||
|
||||
// Utility function that looks at an Engine backend to determine TargetApi
|
||||
inline constexpr MaterialBuilderBase::TargetApi targetApiFromBackend(
|
||||
filament::backend::Backend backend) noexcept {
|
||||
using filament::backend::Backend;
|
||||
using TargetApi = MaterialBuilderBase::TargetApi;
|
||||
switch (backend) {
|
||||
case Backend::DEFAULT: return TargetApi::ALL;
|
||||
case Backend::OPENGL: return TargetApi::OPENGL;
|
||||
case Backend::VULKAN: return TargetApi::VULKAN;
|
||||
case Backend::METAL: return TargetApi::METAL;
|
||||
case Backend::NOOP: return TargetApi::OPENGL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MaterialBuilder builds Filament materials from shader code.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* #include <filamat/MaterialBuilder.h>
|
||||
* using namespace filamat;
|
||||
*
|
||||
* // Must be called before any materials can be built.
|
||||
* MaterialBuilder::init();
|
||||
|
||||
* MaterialBuilder builder;
|
||||
* builder
|
||||
* .name("My material")
|
||||
* .material("void material (inout MaterialInputs material) {"
|
||||
* " prepareMaterial(material);"
|
||||
* " material.baseColor.rgb = float3(1.0, 0.0, 0.0);"
|
||||
* "}")
|
||||
* .shading(MaterialBuilder::Shading::LIT)
|
||||
* .targetApi(MaterialBuilder::TargetApi::ALL)
|
||||
* .platform(MaterialBuilder::Platform::ALL);
|
||||
|
||||
* Package package = builder.build();
|
||||
* if (package.isValid()) {
|
||||
* // success!
|
||||
* }
|
||||
|
||||
* // Call when finished building all materials to release internal
|
||||
* // MaterialBuilder resources.
|
||||
* MaterialBuilder::shutdown();
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* @see filament::Material
|
||||
*/
|
||||
class UTILS_PUBLIC MaterialBuilder : public MaterialBuilderBase {
|
||||
public:
|
||||
MaterialBuilder();
|
||||
~MaterialBuilder();
|
||||
|
||||
MaterialBuilder(const MaterialBuilder& rhs) = delete;
|
||||
MaterialBuilder& operator=(const MaterialBuilder& rhs) = delete;
|
||||
|
||||
MaterialBuilder(MaterialBuilder&& rhs) noexcept = default;
|
||||
MaterialBuilder& operator=(MaterialBuilder&& rhs) noexcept = default;
|
||||
|
||||
static constexpr size_t MATERIAL_VARIABLES_COUNT = 4;
|
||||
enum class Variable : uint8_t {
|
||||
CUSTOM0,
|
||||
CUSTOM1,
|
||||
CUSTOM2,
|
||||
CUSTOM3
|
||||
// when adding more variables, make sure to update MATERIAL_VARIABLES_COUNT
|
||||
};
|
||||
|
||||
using MaterialDomain = filament::MaterialDomain;
|
||||
using RefractionMode = filament::RefractionMode;
|
||||
using RefractionType = filament::RefractionType;
|
||||
using ReflectionMode = filament::ReflectionMode;
|
||||
using VertexAttribute = filament::VertexAttribute;
|
||||
|
||||
using ShaderQuality = filament::ShaderQuality;
|
||||
using BlendingMode = filament::BlendingMode;
|
||||
using Shading = filament::Shading;
|
||||
using Interpolation = filament::Interpolation;
|
||||
using VertexDomain = filament::VertexDomain;
|
||||
using TransparencyMode = filament::TransparencyMode;
|
||||
using SpecularAmbientOcclusion = filament::SpecularAmbientOcclusion;
|
||||
|
||||
using AttributeType = filament::backend::UniformType;
|
||||
using UniformType = filament::backend::UniformType;
|
||||
using ConstantType = filament::backend::ConstantType;
|
||||
using SamplerType = filament::backend::SamplerType;
|
||||
using SubpassType = filament::backend::SubpassType;
|
||||
using SamplerFormat = filament::backend::SamplerFormat;
|
||||
using ParameterPrecision = filament::backend::Precision;
|
||||
using Precision = filament::backend::Precision;
|
||||
using CullingMode = filament::backend::CullingMode;
|
||||
using FeatureLevel = filament::backend::FeatureLevel;
|
||||
using StereoscopicType = filament::backend::StereoscopicType;
|
||||
|
||||
enum class VariableQualifier : uint8_t {
|
||||
OUT
|
||||
};
|
||||
|
||||
enum class OutputTarget : uint8_t {
|
||||
COLOR,
|
||||
DEPTH
|
||||
};
|
||||
|
||||
enum class OutputType : uint8_t {
|
||||
FLOAT,
|
||||
FLOAT2,
|
||||
FLOAT3,
|
||||
FLOAT4
|
||||
};
|
||||
|
||||
struct PreprocessorDefine {
|
||||
std::string name;
|
||||
std::string value;
|
||||
|
||||
PreprocessorDefine(std::string name, std::string value) :
|
||||
name(std::move(name)), value(std::move(value)) {}
|
||||
};
|
||||
using PreprocessorDefineList = std::vector<PreprocessorDefine>;
|
||||
|
||||
|
||||
MaterialBuilder& noSamplerValidation(bool enabled) noexcept;
|
||||
|
||||
//! Enable generation of ESSL 1.0 code in FL0 materials.
|
||||
MaterialBuilder& includeEssl1(bool enabled) noexcept;
|
||||
|
||||
//! Set the name of this material.
|
||||
MaterialBuilder& name(const char* name) noexcept;
|
||||
|
||||
//! Set the file name of this material file. Used in error reporting.
|
||||
MaterialBuilder& fileName(const char* name) noexcept;
|
||||
|
||||
//! Set the shading model.
|
||||
MaterialBuilder& shading(Shading shading) noexcept;
|
||||
|
||||
//! Set the interpolation mode.
|
||||
MaterialBuilder& interpolation(Interpolation interpolation) noexcept;
|
||||
|
||||
//! Add a parameter (i.e., a uniform) to this material.
|
||||
MaterialBuilder& parameter(const char* name, UniformType type,
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT) noexcept;
|
||||
|
||||
//! Add a parameter array to this material.
|
||||
MaterialBuilder& parameter(const char* name, size_t size, UniformType type,
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT) noexcept;
|
||||
|
||||
//! Add a constant parameter to this material.
|
||||
template<typename T>
|
||||
using is_supported_constant_parameter_t = typename std::enable_if<
|
||||
std::is_same<int32_t, T>::value ||
|
||||
std::is_same<float, T>::value ||
|
||||
std::is_same<bool, T>::value>::type;
|
||||
template<typename T, typename = is_supported_constant_parameter_t<T>>
|
||||
MaterialBuilder& constant(const char *name, ConstantType type, T defaultValue = 0);
|
||||
|
||||
/**
|
||||
* Add a sampler parameter to this material.
|
||||
*
|
||||
* When SamplerType::SAMPLER_EXTERNAL is specified, format and precision are ignored.
|
||||
*/
|
||||
MaterialBuilder& parameter(const char* name, SamplerType samplerType,
|
||||
SamplerFormat format = SamplerFormat::FLOAT,
|
||||
ParameterPrecision precision = ParameterPrecision::DEFAULT,
|
||||
bool multisample = false) noexcept;
|
||||
|
||||
MaterialBuilder& buffer(filament::BufferInterfaceBlock bib) noexcept;
|
||||
|
||||
//! Custom variables (all float4).
|
||||
MaterialBuilder& variable(Variable v, const char* name) noexcept;
|
||||
|
||||
/**
|
||||
* Require a specified attribute.
|
||||
*
|
||||
* position is always required and normal depends on the shading model.
|
||||
*/
|
||||
MaterialBuilder& require(VertexAttribute attribute) noexcept;
|
||||
|
||||
//! Specify the domain that this material will operate in.
|
||||
MaterialBuilder& materialDomain(MaterialBuilder::MaterialDomain materialDomain) noexcept;
|
||||
|
||||
/**
|
||||
* Set the code content of this material.
|
||||
*
|
||||
* Surface Domain
|
||||
* --------------
|
||||
*
|
||||
* Materials in the SURFACE domain must declare a function:
|
||||
* ~~~~~
|
||||
* void material(inout MaterialInputs material) {
|
||||
* prepareMaterial(material);
|
||||
* material.baseColor.rgb = float3(1.0, 0.0, 0.0);
|
||||
* }
|
||||
* ~~~~~
|
||||
* this function *must* call `prepareMaterial(material)` before it returns.
|
||||
*
|
||||
* Post-process Domain
|
||||
* -------------------
|
||||
*
|
||||
* Materials in the POST_PROCESS domain must declare a function:
|
||||
* ~~~~~
|
||||
* void postProcess(inout PostProcessInputs postProcess) {
|
||||
* postProcess.color = float4(1.0);
|
||||
* }
|
||||
* ~~~~~
|
||||
*
|
||||
* @param code The source code of the material.
|
||||
* @param line The line number offset of the material, where 0 is the first line. Used for error
|
||||
* reporting
|
||||
*/
|
||||
MaterialBuilder& material(const char* code, size_t line = 0) noexcept;
|
||||
|
||||
/**
|
||||
* Set the callback used for resolving include directives.
|
||||
* The default is no callback, which disallows all includes.
|
||||
*/
|
||||
MaterialBuilder& includeCallback(IncludeCallback callback) noexcept;
|
||||
|
||||
/**
|
||||
* Set the vertex code content of this material.
|
||||
*
|
||||
* Surface Domain
|
||||
* --------------
|
||||
*
|
||||
* Materials in the SURFACE domain must declare a function:
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* void materialVertex(inout MaterialVertexInputs material) {
|
||||
*
|
||||
* }
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* Post-process Domain
|
||||
* -------------------
|
||||
*
|
||||
* Materials in the POST_PROCESS domain must declare a function:
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* void postProcessVertex(inout PostProcessVertexInputs postProcess) {
|
||||
*
|
||||
* }
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* @param code The source code of the material.
|
||||
* @param line The line number offset of the material, where 0 is the first line. Used for error
|
||||
* reporting
|
||||
*/
|
||||
MaterialBuilder& materialVertex(const char* code, size_t line = 0) noexcept;
|
||||
|
||||
|
||||
MaterialBuilder& quality(ShaderQuality quality) noexcept;
|
||||
|
||||
MaterialBuilder& featureLevel(FeatureLevel featureLevel) noexcept;
|
||||
|
||||
/**
|
||||
* Set the blending mode for this material. When set to MASKED, alpha to coverage is turned on.
|
||||
* You can override this behavior using alphaToCoverage(false).
|
||||
*/
|
||||
MaterialBuilder& blending(BlendingMode blending) noexcept;
|
||||
|
||||
/**
|
||||
* Set the blending mode of the post-lighting color for this material.
|
||||
* Only OPAQUE, TRANSPARENT and ADD are supported, the default is TRANSPARENT.
|
||||
* This setting requires the material properties "postLightingColor" and
|
||||
* "postLightingMixFactor" to be set.
|
||||
*/
|
||||
MaterialBuilder& postLightingBlending(BlendingMode blending) noexcept;
|
||||
|
||||
//! Set the vertex domain for this material.
|
||||
MaterialBuilder& vertexDomain(VertexDomain domain) noexcept;
|
||||
|
||||
/**
|
||||
* How triangles are culled by default (doesn't affect points or lines, BACK by default).
|
||||
* Material instances can override this.
|
||||
*/
|
||||
MaterialBuilder& culling(CullingMode culling) noexcept;
|
||||
|
||||
//! Enable / disable color-buffer write (enabled by default, material instances can override).
|
||||
MaterialBuilder& colorWrite(bool enable) noexcept;
|
||||
|
||||
//! Enable / disable depth-buffer write (enabled by default for opaque, disabled for others, material instances can override).
|
||||
MaterialBuilder& depthWrite(bool enable) noexcept;
|
||||
|
||||
//! Enable / disable depth based culling (enabled by default, material instances can override).
|
||||
MaterialBuilder& depthCulling(bool enable) noexcept;
|
||||
|
||||
//! Enable / disable instanced primitives (disabled by default).
|
||||
MaterialBuilder& instanced(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Double-sided materials don't cull faces, equivalent to culling(CullingMode::NONE).
|
||||
* doubleSided() overrides culling() if called.
|
||||
* When called with "false", this enables the capability for a run-time toggle.
|
||||
*/
|
||||
MaterialBuilder& doubleSided(bool doubleSided) noexcept;
|
||||
|
||||
/**
|
||||
* Any fragment with an alpha below this threshold is clipped (MASKED blending mode only).
|
||||
* The mask threshold can also be controlled by using the float material parameter called
|
||||
* `_maskThreshold`, or by calling
|
||||
* @ref filament::MaterialInstance::setMaskThreshold "MaterialInstance::setMaskThreshold".
|
||||
*/
|
||||
MaterialBuilder& maskThreshold(float threshold) noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables alpha-to-coverage. When enabled, the coverage of a fragment is based
|
||||
* on its alpha value. This parameter is only useful when MSAA is in use. Alpha to coverage
|
||||
* is enabled automatically when the blend mode is set to MASKED; this behavior can be
|
||||
* overridden by calling alphaToCoverage(false).
|
||||
*/
|
||||
MaterialBuilder& alphaToCoverage(bool enable) noexcept;
|
||||
|
||||
//! The material output is multiplied by the shadowing factor (UNLIT model only).
|
||||
MaterialBuilder& shadowMultiplier(bool shadowMultiplier) noexcept;
|
||||
|
||||
//! This material casts transparent shadows. The blending mode must be TRANSPARENT or FADE.
|
||||
MaterialBuilder& transparentShadow(bool transparentShadow) noexcept;
|
||||
|
||||
/**
|
||||
* Reduces specular aliasing for materials that have low roughness. Turning this feature on also
|
||||
* helps preserve the shapes of specular highlights as an object moves away from the camera.
|
||||
* When turned on, two float material parameters are added to control the effect:
|
||||
* `_specularAAScreenSpaceVariance` and `_specularAAThreshold`. You can also use
|
||||
* @ref filament::MaterialInstance::setSpecularAntiAliasingVariance
|
||||
* "MaterialInstance::setSpecularAntiAliasingVariance" and
|
||||
* @ref filament::MaterialInstance::setSpecularAntiAliasingThreshold
|
||||
* "setSpecularAntiAliasingThreshold"
|
||||
*
|
||||
* Disabled by default.
|
||||
*/
|
||||
MaterialBuilder& specularAntiAliasing(bool specularAntiAliasing) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the screen-space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing. The default value is set to 0.15. The specified value should be between 0 and
|
||||
* 1 and will be clamped if necessary.
|
||||
*/
|
||||
MaterialBuilder& specularAntiAliasingVariance(float screenSpaceVariance) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing. The default value is set to 0.2. The specified value should be between 0 and 1
|
||||
* and will be clamped if necessary.
|
||||
*/
|
||||
MaterialBuilder& specularAntiAliasingThreshold(float threshold) noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables the index of refraction (IoR) change caused by the clear coat layer when
|
||||
* present. When the IoR changes, the base color is darkened. Disabling this feature preserves
|
||||
* the base color as initially specified.
|
||||
*
|
||||
* Enabled by default.
|
||||
*/
|
||||
MaterialBuilder& clearCoatIorChange(bool clearCoatIorChange) noexcept;
|
||||
|
||||
//! Enable / disable flipping of the Y coordinate of UV attributes, enabled by default.
|
||||
MaterialBuilder& flipUV(bool flipUV) noexcept;
|
||||
|
||||
//! Enable / disable multi-bounce ambient occlusion, disabled by default on mobile.
|
||||
MaterialBuilder& multiBounceAmbientOcclusion(bool multiBounceAO) noexcept;
|
||||
|
||||
//! Set the specular ambient occlusion technique. Disabled by default on mobile.
|
||||
MaterialBuilder& specularAmbientOcclusion(SpecularAmbientOcclusion specularAO) noexcept;
|
||||
|
||||
//! Specify the refraction
|
||||
MaterialBuilder& refractionMode(RefractionMode refraction) noexcept;
|
||||
|
||||
//! Specify the refraction type
|
||||
MaterialBuilder& refractionType(RefractionType refractionType) noexcept;
|
||||
|
||||
//! Specifies how reflections should be rendered (default is DEFAULT).
|
||||
MaterialBuilder& reflectionMode(ReflectionMode mode) noexcept;
|
||||
|
||||
//! Specifies how transparent objects should be rendered (default is DEFAULT).
|
||||
MaterialBuilder& transparencyMode(TransparencyMode mode) noexcept;
|
||||
|
||||
//! Specify the stereoscopic type (default is INSTANCED)
|
||||
MaterialBuilder& stereoscopicType(StereoscopicType stereoscopicType) noexcept;
|
||||
|
||||
//! Specify the number of eyes for stereoscopic rendering
|
||||
MaterialBuilder& stereoscopicEyeCount(uint8_t eyeCount) noexcept;
|
||||
|
||||
/**
|
||||
* Enable / disable custom surface shading. Custom surface shading requires the LIT
|
||||
* shading model. In addition, the following function must be defined in the fragment
|
||||
* block:
|
||||
*
|
||||
* ~~~~~
|
||||
* vec3 surfaceShading(const MaterialInputs materialInputs,
|
||||
* const ShadingData shadingData, const LightData lightData) {
|
||||
*
|
||||
* return vec3(1.0); // Compute surface shading with custom BRDF, etc.
|
||||
* }
|
||||
* ~~~~~
|
||||
*
|
||||
* This function is invoked once per light. Please refer to the materials documentation
|
||||
* for more information about the different parameters.
|
||||
*
|
||||
* @param customSurfaceShading Enables or disables custom surface shading
|
||||
*/
|
||||
MaterialBuilder& customSurfaceShading(bool customSurfaceShading) noexcept;
|
||||
|
||||
/**
|
||||
* Specifies desktop vs mobile; works in concert with TargetApi to determine the shader models
|
||||
* (used to generate code) and final output representations (spirv and/or text).
|
||||
*/
|
||||
MaterialBuilder& platform(Platform platform) noexcept;
|
||||
|
||||
/**
|
||||
* Specifies OpenGL, Vulkan, or Metal.
|
||||
* This can be called repeatedly to build for multiple APIs.
|
||||
* Works in concert with Platform to determine the shader models (used to generate code) and
|
||||
* final output representations (spirv and/or text).
|
||||
* If linking against filamat_lite, only `OPENGL` is allowed.
|
||||
*/
|
||||
MaterialBuilder& targetApi(TargetApi targetApi) noexcept;
|
||||
|
||||
/**
|
||||
* Specifies the level of optimization to apply to the shaders (default is PERFORMANCE).
|
||||
* If linking against filamat_lite, this _must_ be called with Optimization::NONE.
|
||||
*/
|
||||
MaterialBuilder& optimization(Optimization optimization) noexcept;
|
||||
|
||||
// TODO: this is present here for matc's "--print" flag, but ideally does not belong inside
|
||||
// MaterialBuilder.
|
||||
//! If true, will output the generated GLSL shader code to stdout.
|
||||
MaterialBuilder& printShaders(bool printShaders) noexcept;
|
||||
|
||||
//! If true, will include debugging information in generated SPIRV.
|
||||
MaterialBuilder& generateDebugInfo(bool generateDebugInfo) noexcept;
|
||||
|
||||
//! Specifies a list of variants that should be filtered out during code generation.
|
||||
MaterialBuilder& variantFilter(filament::UserVariantFilterMask variantFilter) noexcept;
|
||||
|
||||
//! Adds a new preprocessor macro definition to the shader code. Can be called repeatedly.
|
||||
MaterialBuilder& shaderDefine(const char* name, const char* value) noexcept;
|
||||
|
||||
//! Add a new fragment shader output variable. Only valid for materials in the POST_PROCESS domain.
|
||||
MaterialBuilder& output(VariableQualifier qualifier, OutputTarget target, Precision precision,
|
||||
OutputType type, const char* name, int location = -1) noexcept;
|
||||
|
||||
MaterialBuilder& enableFramebufferFetch() noexcept;
|
||||
|
||||
MaterialBuilder& vertexDomainDeviceJittered(bool enabled) noexcept;
|
||||
|
||||
/**
|
||||
* Legacy morphing uses the data in the VertexAttribute slots (\c MORPH_POSITION_0, etc) and is
|
||||
* limited to 4 morph targets. See filament::RenderableManager::Builder::morphing().
|
||||
*/
|
||||
MaterialBuilder& useLegacyMorphing() noexcept;
|
||||
|
||||
//! specify compute kernel group size
|
||||
MaterialBuilder& groupSize(filament::math::uint3 groupSize) noexcept;
|
||||
|
||||
/**
|
||||
* Build the material. If you are using the Filament engine with this library, you should use
|
||||
* the job system provided by Engine.
|
||||
*/
|
||||
Package build(utils::JobSystem& jobSystem) noexcept;
|
||||
|
||||
public:
|
||||
// The methods and types below are for internal use
|
||||
/// @cond never
|
||||
|
||||
/**
|
||||
* Add a subpass parameter to this material.
|
||||
*/
|
||||
MaterialBuilder& subpass(SubpassType subpassType,
|
||||
SamplerFormat format, ParameterPrecision precision, const char* name) noexcept;
|
||||
MaterialBuilder& subpass(SubpassType subpassType,
|
||||
SamplerFormat format, const char* name) noexcept;
|
||||
MaterialBuilder& subpass(SubpassType subpassType,
|
||||
ParameterPrecision precision, const char* name) noexcept;
|
||||
MaterialBuilder& subpass(SubpassType subpassType, const char* name) noexcept;
|
||||
|
||||
struct Parameter {
|
||||
Parameter() noexcept: parameterType(INVALID) {}
|
||||
|
||||
// Sampler
|
||||
Parameter(const char* paramName, SamplerType t, SamplerFormat f, ParameterPrecision p, bool ms)
|
||||
: name(paramName), size(1), precision(p), samplerType(t), format(f), parameterType(SAMPLER), multisample(ms) { }
|
||||
|
||||
// Uniform
|
||||
Parameter(const char* paramName, UniformType t, size_t typeSize, ParameterPrecision p)
|
||||
: name(paramName), size(typeSize), uniformType(t), precision(p), parameterType(UNIFORM) { }
|
||||
|
||||
// Subpass
|
||||
Parameter(const char* paramName, SubpassType t, SamplerFormat f, ParameterPrecision p)
|
||||
: name(paramName), size(1), precision(p), subpassType(t), format(f), parameterType(SUBPASS) { }
|
||||
|
||||
utils::CString name;
|
||||
size_t size;
|
||||
UniformType uniformType;
|
||||
ParameterPrecision precision;
|
||||
SamplerType samplerType;
|
||||
SubpassType subpassType;
|
||||
SamplerFormat format;
|
||||
bool multisample;
|
||||
enum {
|
||||
INVALID,
|
||||
UNIFORM,
|
||||
SAMPLER,
|
||||
SUBPASS
|
||||
} parameterType;
|
||||
|
||||
bool isSampler() const { return parameterType == SAMPLER; }
|
||||
bool isUniform() const { return parameterType == UNIFORM; }
|
||||
bool isSubpass() const { return parameterType == SUBPASS; }
|
||||
};
|
||||
|
||||
struct Output {
|
||||
Output() noexcept = default;
|
||||
Output(const char* outputName, VariableQualifier qualifier, OutputTarget target,
|
||||
Precision precision, OutputType type, int location) noexcept
|
||||
: name(outputName), qualifier(qualifier), target(target), precision(precision),
|
||||
type(type), location(location) { }
|
||||
|
||||
utils::CString name;
|
||||
VariableQualifier qualifier;
|
||||
OutputTarget target;
|
||||
Precision precision;
|
||||
OutputType type;
|
||||
int location;
|
||||
};
|
||||
|
||||
struct Constant {
|
||||
utils::CString name;
|
||||
ConstantType type;
|
||||
union {
|
||||
int32_t i;
|
||||
float f;
|
||||
bool b;
|
||||
} defaultValue;
|
||||
};
|
||||
|
||||
static constexpr size_t MATERIAL_PROPERTIES_COUNT = filament::MATERIAL_PROPERTIES_COUNT;
|
||||
using Property = filament::Property;
|
||||
|
||||
using PropertyList = bool[MATERIAL_PROPERTIES_COUNT];
|
||||
using VariableList = utils::CString[MATERIAL_VARIABLES_COUNT];
|
||||
using OutputList = std::vector<Output>;
|
||||
|
||||
static constexpr size_t MAX_COLOR_OUTPUT = filament::backend::MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT;
|
||||
static constexpr size_t MAX_DEPTH_OUTPUT = 1;
|
||||
static_assert(MAX_COLOR_OUTPUT == 8,
|
||||
"When updating MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT, manually update post_process_inputs.fs"
|
||||
" and post_process.fs");
|
||||
|
||||
// Preview the first shader generated by the given CodeGenParams.
|
||||
// This is used to run Static Code Analysis before generating a package.
|
||||
std::string peek(filament::backend::ShaderStage type,
|
||||
const CodeGenParams& params, const PropertyList& properties) noexcept;
|
||||
|
||||
// Returns true if any of the parameter samplers matches the specified type.
|
||||
bool hasSamplerType(SamplerType samplerType) const noexcept;
|
||||
|
||||
static constexpr size_t MAX_PARAMETERS_COUNT = 48;
|
||||
static constexpr size_t MAX_SUBPASS_COUNT = 1;
|
||||
static constexpr size_t MAX_BUFFERS_COUNT = 4;
|
||||
using ParameterList = Parameter[MAX_PARAMETERS_COUNT];
|
||||
using SubpassList = Parameter[MAX_SUBPASS_COUNT];
|
||||
using BufferList = std::vector<std::unique_ptr<filament::BufferInterfaceBlock>>;
|
||||
using ConstantList = std::vector<Constant>;
|
||||
|
||||
// returns the number of parameters declared in this material
|
||||
uint8_t getParameterCount() const noexcept { return mParameterCount; }
|
||||
|
||||
// returns a list of at least getParameterCount() parameters
|
||||
const ParameterList& getParameters() const noexcept { return mParameters; }
|
||||
|
||||
// returns the number of parameters declared in this material
|
||||
uint8_t getSubpassCount() const noexcept { return mSubpassCount; }
|
||||
|
||||
// returns a list of at least getParameterCount() parameters
|
||||
const SubpassList& getSubPasses() const noexcept { return mSubpasses; }
|
||||
|
||||
filament::UserVariantFilterMask getVariantFilter() const { return mVariantFilter; }
|
||||
|
||||
FeatureLevel getFeatureLevel() const noexcept { return mFeatureLevel; }
|
||||
/// @endcond
|
||||
|
||||
struct Attribute {
|
||||
std::string_view name;
|
||||
AttributeType type;
|
||||
MaterialBuilder::VertexAttribute location;
|
||||
std::string getAttributeName() const noexcept {
|
||||
return "mesh_" + std::string{ name };
|
||||
}
|
||||
std::string getDefineName() const noexcept {
|
||||
std::string uppercase{ name };
|
||||
transform(uppercase.cbegin(), uppercase.cend(), uppercase.begin(), ::toupper);
|
||||
return "HAS_ATTRIBUTE_" + uppercase;
|
||||
}
|
||||
};
|
||||
|
||||
using AttributeDatabase = std::array<Attribute, filament::backend::MAX_VERTEX_ATTRIBUTE_COUNT>;
|
||||
|
||||
static inline AttributeDatabase const& getAttributeDatabase() noexcept {
|
||||
return sAttributeDatabase;
|
||||
}
|
||||
|
||||
private:
|
||||
static const AttributeDatabase sAttributeDatabase;
|
||||
|
||||
void prepareToBuild(MaterialInfo& info) noexcept;
|
||||
|
||||
// Return true if the shader is syntactically and semantically valid.
|
||||
// This method finds all the properties defined in the fragment and
|
||||
// vertex shaders of the material.
|
||||
bool findAllProperties(CodeGenParams const& semanticCodeGenParams) noexcept;
|
||||
|
||||
// Multiple calls to findProperties accumulate the property sets across fragment
|
||||
// and vertex shaders in mProperties.
|
||||
bool findProperties(filament::backend::ShaderStage type,
|
||||
MaterialBuilder::PropertyList& allProperties,
|
||||
CodeGenParams const& semanticCodeGenParams) noexcept;
|
||||
|
||||
bool runSemanticAnalysis(MaterialInfo* inOutInfo,
|
||||
CodeGenParams const& semanticCodeGenParams) noexcept;
|
||||
|
||||
bool checkLiteRequirements() noexcept;
|
||||
|
||||
bool checkMaterialLevelFeatures(MaterialInfo const& info) const noexcept;
|
||||
|
||||
void writeCommonChunks(ChunkContainer& container, MaterialInfo& info) const noexcept;
|
||||
void writeSurfaceChunks(ChunkContainer& container) const noexcept;
|
||||
|
||||
bool generateShaders(
|
||||
utils::JobSystem& jobSystem,
|
||||
const std::vector<filamat::Variant>& variants, ChunkContainer& container,
|
||||
const MaterialInfo& info) const noexcept;
|
||||
|
||||
bool hasCustomVaryings() const noexcept;
|
||||
bool needsStandardDepthProgram() const noexcept;
|
||||
|
||||
bool isLit() const noexcept { return mShading != filament::Shading::UNLIT; }
|
||||
|
||||
utils::CString mMaterialName;
|
||||
utils::CString mFileName;
|
||||
|
||||
class ShaderCode {
|
||||
public:
|
||||
void setLineOffset(size_t offset) noexcept { mLineOffset = offset; }
|
||||
void setUnresolved(const utils::CString& code) noexcept {
|
||||
mIncludesResolved = false;
|
||||
mCode = code;
|
||||
}
|
||||
|
||||
// Resolve all the #include directives, returns true if successful.
|
||||
bool resolveIncludes(IncludeCallback callback, const utils::CString& fileName) noexcept;
|
||||
|
||||
const utils::CString& getResolved() const noexcept {
|
||||
assert(mIncludesResolved);
|
||||
return mCode;
|
||||
}
|
||||
|
||||
size_t getLineOffset() const noexcept { return mLineOffset; }
|
||||
|
||||
private:
|
||||
utils::CString mCode;
|
||||
size_t mLineOffset = 0;
|
||||
bool mIncludesResolved = false;
|
||||
};
|
||||
|
||||
ShaderCode mMaterialFragmentCode;
|
||||
ShaderCode mMaterialVertexCode;
|
||||
|
||||
IncludeCallback mIncludeCallback = nullptr;
|
||||
|
||||
PropertyList mProperties;
|
||||
ParameterList mParameters;
|
||||
ConstantList mConstants;
|
||||
SubpassList mSubpasses;
|
||||
VariableList mVariables;
|
||||
OutputList mOutputs;
|
||||
BufferList mBuffers;
|
||||
|
||||
ShaderQuality mShaderQuality = ShaderQuality::DEFAULT;
|
||||
FeatureLevel mFeatureLevel = FeatureLevel::FEATURE_LEVEL_1;
|
||||
BlendingMode mBlendingMode = BlendingMode::OPAQUE;
|
||||
BlendingMode mPostLightingBlendingMode = BlendingMode::TRANSPARENT;
|
||||
CullingMode mCullingMode = CullingMode::BACK;
|
||||
Shading mShading = Shading::LIT;
|
||||
MaterialDomain mMaterialDomain = MaterialDomain::SURFACE;
|
||||
RefractionMode mRefractionMode = RefractionMode::NONE;
|
||||
RefractionType mRefractionType = RefractionType::SOLID;
|
||||
ReflectionMode mReflectionMode = ReflectionMode::DEFAULT;
|
||||
Interpolation mInterpolation = Interpolation::SMOOTH;
|
||||
VertexDomain mVertexDomain = VertexDomain::OBJECT;
|
||||
TransparencyMode mTransparencyMode = TransparencyMode::DEFAULT;
|
||||
StereoscopicType mStereoscopicType = StereoscopicType::INSTANCED;
|
||||
uint8_t mStereoscopicEyeCount = 2;
|
||||
|
||||
filament::AttributeBitset mRequiredAttributes;
|
||||
|
||||
float mMaskThreshold = 0.4f;
|
||||
float mSpecularAntiAliasingVariance = 0.15f;
|
||||
float mSpecularAntiAliasingThreshold = 0.2f;
|
||||
|
||||
filament::math::uint3 mGroupSize = { 1, 1, 1 };
|
||||
|
||||
bool mShadowMultiplier = false;
|
||||
bool mTransparentShadow = false;
|
||||
|
||||
uint8_t mParameterCount = 0;
|
||||
uint8_t mSubpassCount = 0;
|
||||
|
||||
bool mDoubleSided = false;
|
||||
bool mDoubleSidedCapability = false;
|
||||
bool mColorWrite = true;
|
||||
bool mDepthTest = true;
|
||||
bool mInstanced = false;
|
||||
bool mDepthWrite = true;
|
||||
bool mDepthWriteSet = false;
|
||||
bool mAlphaToCoverage = false;
|
||||
bool mAlphaToCoverageSet = false;
|
||||
|
||||
bool mSpecularAntiAliasing = false;
|
||||
bool mClearCoatIorChange = true;
|
||||
|
||||
bool mFlipUV = true;
|
||||
|
||||
bool mMultiBounceAO = false;
|
||||
bool mMultiBounceAOSet = false;
|
||||
|
||||
SpecularAmbientOcclusion mSpecularAO = SpecularAmbientOcclusion::NONE;
|
||||
bool mSpecularAOSet = false;
|
||||
|
||||
bool mCustomSurfaceShading = false;
|
||||
|
||||
bool mEnableFramebufferFetch = false;
|
||||
|
||||
bool mVertexDomainDeviceJittered = false;
|
||||
|
||||
bool mUseLegacyMorphing = false;
|
||||
|
||||
PreprocessorDefineList mDefines;
|
||||
|
||||
filament::UserVariantFilterMask mVariantFilter = {};
|
||||
|
||||
bool mNoSamplerValidation = false;
|
||||
};
|
||||
|
||||
} // namespace filamat
|
||||
|
||||
template<> struct utils::EnableBitMaskOperators<filamat::MaterialBuilder::TargetApi>
|
||||
: public std::true_type {};
|
||||
|
||||
#endif
|
||||
103
dart_filament/native/include/filament/filamat/Package.h
Normal file
103
dart_filament/native/include/filament/filamat/Package.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMAT_PACKAGE_H
|
||||
#define TNT_FILAMAT_PACKAGE_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filamat {
|
||||
|
||||
class UTILS_PUBLIC Package {
|
||||
public:
|
||||
Package() = default;
|
||||
|
||||
// Regular constructor
|
||||
explicit Package(size_t size) : mSize(size) {
|
||||
mPayload = new uint8_t[size];
|
||||
}
|
||||
|
||||
Package(const void* src, size_t size) : Package(size) {
|
||||
memcpy(mPayload, src, size);
|
||||
}
|
||||
|
||||
// Move Constructor
|
||||
Package(Package&& other) noexcept : mPayload(other.mPayload), mSize(other.mSize),
|
||||
mValid(other.mValid) {
|
||||
other.mPayload = nullptr;
|
||||
other.mSize = 0;
|
||||
other.mValid = false;
|
||||
}
|
||||
|
||||
// Move assignment
|
||||
Package& operator=(Package&& other) noexcept {
|
||||
std::swap(mPayload, other.mPayload);
|
||||
std::swap(mSize, other.mSize);
|
||||
std::swap(mValid, other.mValid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Copy assignment operator disallowed.
|
||||
Package& operator=(const Package& other) = delete;
|
||||
|
||||
// Copy constructor disallowed.
|
||||
Package(const Package& other) = delete;
|
||||
|
||||
~Package() {
|
||||
delete[] mPayload;
|
||||
}
|
||||
|
||||
uint8_t* getData() const noexcept {
|
||||
return mPayload;
|
||||
}
|
||||
|
||||
size_t getSize() const noexcept {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
uint8_t* getEnd() const noexcept {
|
||||
return mPayload + mSize;
|
||||
}
|
||||
|
||||
void setValid(bool valid) noexcept {
|
||||
mValid = valid;
|
||||
}
|
||||
|
||||
bool isValid() const noexcept {
|
||||
return mValid;
|
||||
}
|
||||
|
||||
static Package invalidPackage() {
|
||||
Package package(0);
|
||||
package.setValid(false);
|
||||
return package;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t* mPayload = nullptr;
|
||||
size_t mSize = 0;
|
||||
bool mValid = true;
|
||||
};
|
||||
|
||||
} // namespace filamat
|
||||
#endif
|
||||
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_IBL_PREFILTER_IBLPREFILTER_H
|
||||
#define TNT_IBL_PREFILTER_IBLPREFILTER_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Entity.h>
|
||||
|
||||
#include <filament/Texture.h>
|
||||
|
||||
namespace filament {
|
||||
class Engine;
|
||||
class View;
|
||||
class Scene;
|
||||
class Renderer;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class VertexBuffer;
|
||||
class IndexBuffer;
|
||||
class Camera;
|
||||
class Texture;
|
||||
} // namespace filament
|
||||
|
||||
/**
|
||||
* IBLPrefilterContext creates and initializes GPU state common to all environment map filters
|
||||
* supported. Typically, only one instance per filament Engine of this object needs to exist.
|
||||
*
|
||||
* Usage Example:
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* #include <filament/Engine.h>
|
||||
* using namespace filament;
|
||||
*
|
||||
* Engine* engine = Engine::create();
|
||||
*
|
||||
* IBLPrefilterContext context(engine);
|
||||
* IBLPrefilterContext::SpecularFilter filter(context);
|
||||
* Texture* texture = filter(environment_cubemap);
|
||||
*
|
||||
* IndirectLight* indirectLight = IndirectLight::Builder()
|
||||
* .reflections(texture)
|
||||
* .build(engine);
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
class UTILS_PUBLIC IBLPrefilterContext {
|
||||
public:
|
||||
|
||||
enum class Kernel : uint8_t {
|
||||
D_GGX, // Trowbridge-reitz distribution
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an IBLPrefilter context.
|
||||
* @param engine filament engine to use
|
||||
*/
|
||||
explicit IBLPrefilterContext(filament::Engine& engine);
|
||||
|
||||
/**
|
||||
* Destroys all GPU resources created during initialization.
|
||||
*/
|
||||
~IBLPrefilterContext() noexcept;
|
||||
|
||||
// not copyable
|
||||
IBLPrefilterContext(IBLPrefilterContext const&) = delete;
|
||||
IBLPrefilterContext& operator=(IBLPrefilterContext const&) = delete;
|
||||
|
||||
// movable
|
||||
IBLPrefilterContext(IBLPrefilterContext&& rhs) noexcept;
|
||||
IBLPrefilterContext& operator=(IBLPrefilterContext&& rhs) noexcept;
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* EquirectangularToCubemap is use to convert an equirectangluar image to a cubemap.
|
||||
*/
|
||||
class EquirectangularToCubemap {
|
||||
public:
|
||||
|
||||
struct Config {
|
||||
bool mirror = true; //!< mirror the source horizontally
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a EquirectangularToCubemap processor using the default Config
|
||||
* @param context IBLPrefilterContext to use
|
||||
*/
|
||||
explicit EquirectangularToCubemap(IBLPrefilterContext& context);
|
||||
|
||||
/**
|
||||
* Creates a EquirectangularToCubemap processor using the provided Config
|
||||
* @param context IBLPrefilterContext to use
|
||||
*/
|
||||
EquirectangularToCubemap(IBLPrefilterContext& context, Config const& config);
|
||||
|
||||
/**
|
||||
* Destroys all GPU resources created during initialization.
|
||||
*/
|
||||
~EquirectangularToCubemap() noexcept;
|
||||
|
||||
EquirectangularToCubemap(EquirectangularToCubemap const&) = delete;
|
||||
EquirectangularToCubemap& operator=(EquirectangularToCubemap const&) = delete;
|
||||
EquirectangularToCubemap(EquirectangularToCubemap&& rhs) noexcept;
|
||||
EquirectangularToCubemap& operator=(EquirectangularToCubemap&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Converts an equirectangular image to a cubemap.
|
||||
* @param equirectangular Texture to convert to a cubemap.
|
||||
* - Can't be null.
|
||||
* - Must be a 2d texture
|
||||
* - Must have equirectangular geometry, that is width == 2*height.
|
||||
* - Must be allocated with all mip levels.
|
||||
* - Must be SAMPLEABLE
|
||||
* @param outCubemap Output cubemap. If null the texture is automatically created
|
||||
* with default parameters (size of 256 with 9 levels).
|
||||
* - Must be a cubemap
|
||||
* - Must have SAMPLEABLE and COLOR_ATTACHMENT usage bits
|
||||
* @return returns outCubemap
|
||||
*/
|
||||
filament::Texture* operator()(
|
||||
filament::Texture const* equirectangular,
|
||||
filament::Texture* outCubemap = nullptr);
|
||||
|
||||
private:
|
||||
IBLPrefilterContext& mContext;
|
||||
filament::Material* mEquirectMaterial = nullptr;
|
||||
Config mConfig{};
|
||||
};
|
||||
|
||||
/**
|
||||
* IrradianceFilter is a GPU based implementation of the diffuse probe pre-integration filter.
|
||||
* An instance of IrradianceFilter is needed per filter configuration. A filter configuration
|
||||
* contains the filter's kernel and sample count.
|
||||
*/
|
||||
class IrradianceFilter {
|
||||
public:
|
||||
using Kernel = Kernel;
|
||||
|
||||
/**
|
||||
* Filter configuration.
|
||||
*/
|
||||
struct Config {
|
||||
uint16_t sampleCount = 1024u; //!< filter sample count (max 2048)
|
||||
Kernel kernel = Kernel::D_GGX; //!< filter kernel
|
||||
};
|
||||
|
||||
/**
|
||||
* Filtering options for the current environment.
|
||||
*/
|
||||
struct Options {
|
||||
float hdrLinear = 1024.0f; //!< no HDR compression up to this value
|
||||
float hdrMax = 16384.0f; //!< HDR compression between hdrLinear and hdrMax
|
||||
float lodOffset = 2.0f; //!< Good values are 2.0 or 3.0. Higher values help with heavily HDR inputs.
|
||||
bool generateMipmap = true; //!< set to false if the input environment map already has mipmaps
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a IrradianceFilter processor.
|
||||
* @param context IBLPrefilterContext to use
|
||||
* @param config Configuration of the filter
|
||||
*/
|
||||
IrradianceFilter(IBLPrefilterContext& context, Config config);
|
||||
|
||||
/**
|
||||
* Creates a filter with the default configuration.
|
||||
* @param context IBLPrefilterContext to use
|
||||
*/
|
||||
explicit IrradianceFilter(IBLPrefilterContext& context);
|
||||
|
||||
/**
|
||||
* Destroys all GPU resources created during initialization.
|
||||
*/
|
||||
~IrradianceFilter() noexcept;
|
||||
|
||||
IrradianceFilter(IrradianceFilter const&) = delete;
|
||||
IrradianceFilter& operator=(IrradianceFilter const&) = delete;
|
||||
IrradianceFilter(IrradianceFilter&& rhs) noexcept;
|
||||
IrradianceFilter& operator=(IrradianceFilter&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Generates an irradiance cubemap. Mipmaps are not generated even if present.
|
||||
* @param options Options for this environment
|
||||
* @param environmentCubemap Environment cubemap (input). Can't be null.
|
||||
* This cubemap must be SAMPLEABLE and must have all its
|
||||
* levels allocated. If Options.generateMipmap is true,
|
||||
* the mipmap levels will be overwritten, otherwise
|
||||
* it is assumed that all levels are correctly initialized.
|
||||
* @param outIrradianceTexture Output irradiance texture or, if null, it is
|
||||
* automatically created with some default parameters.
|
||||
* outIrradianceTexture must be a cubemap, it must have
|
||||
* at least COLOR_ATTACHMENT and SAMPLEABLE usages.
|
||||
*
|
||||
* @return returns outIrradianceTexture
|
||||
*/
|
||||
filament::Texture* operator()(Options options,
|
||||
filament::Texture const* environmentCubemap,
|
||||
filament::Texture* outIrradianceTexture = nullptr);
|
||||
|
||||
/**
|
||||
* Generates a prefiltered cubemap.
|
||||
* @param environmentCubemap Environment cubemap (input). Can't be null.
|
||||
* This cubemap must be SAMPLEABLE and must have all its
|
||||
* levels allocated. If Options.generateMipmap is true,
|
||||
* the mipmap levels will be overwritten, otherwise
|
||||
* it is assumed that all levels are correctly initialized.
|
||||
* @param outIrradianceTexture Output irradiance texture or, if null, it is
|
||||
* automatically created with some default parameters.
|
||||
* outIrradianceTexture must be a cubemap, it must have
|
||||
* at least COLOR_ATTACHMENT and SAMPLEABLE usages.
|
||||
*
|
||||
* @return returns outReflectionsTexture
|
||||
*/
|
||||
filament::Texture* operator()(
|
||||
filament::Texture const* environmentCubemap,
|
||||
filament::Texture* outIrradianceTexture = nullptr);
|
||||
|
||||
private:
|
||||
filament::Texture* createIrradianceTexture();
|
||||
IBLPrefilterContext& mContext;
|
||||
filament::Material* mKernelMaterial = nullptr;
|
||||
filament::Texture* mKernelTexture = nullptr;
|
||||
uint32_t mSampleCount = 0u;
|
||||
};
|
||||
|
||||
/**
|
||||
* SpecularFilter is a GPU based implementation of the specular probe pre-integration filter.
|
||||
* An instance of SpecularFilter is needed per filter configuration. A filter configuration
|
||||
* contains the filter's kernel and sample count.
|
||||
*/
|
||||
class SpecularFilter {
|
||||
public:
|
||||
using Kernel = Kernel;
|
||||
|
||||
/**
|
||||
* Filter configuration.
|
||||
*/
|
||||
struct Config {
|
||||
uint16_t sampleCount = 1024u; //!< filter sample count (max 2048)
|
||||
uint8_t levelCount = 5u; //!< number of roughness levels
|
||||
Kernel kernel = Kernel::D_GGX; //!< filter kernel
|
||||
};
|
||||
|
||||
/**
|
||||
* Filtering options for the current environment.
|
||||
*/
|
||||
struct Options {
|
||||
float hdrLinear = 1024.0f; //!< no HDR compression up to this value
|
||||
float hdrMax = 16384.0f; //!< HDR compression between hdrLinear and hdrMax
|
||||
float lodOffset = 1.0f; //!< Good values are 1.0 or 2.0. Higher values help with heavily HDR inputs.
|
||||
bool generateMipmap = true; //!< set to false if the input environment map already has mipmaps
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a SpecularFilter processor.
|
||||
* @param context IBLPrefilterContext to use
|
||||
* @param config Configuration of the filter
|
||||
*/
|
||||
SpecularFilter(IBLPrefilterContext& context, Config config);
|
||||
|
||||
/**
|
||||
* Creates a filter with the default configuration.
|
||||
* @param context IBLPrefilterContext to use
|
||||
*/
|
||||
explicit SpecularFilter(IBLPrefilterContext& context);
|
||||
|
||||
/**
|
||||
* Destroys all GPU resources created during initialization.
|
||||
*/
|
||||
~SpecularFilter() noexcept;
|
||||
|
||||
SpecularFilter(SpecularFilter const&) = delete;
|
||||
SpecularFilter& operator=(SpecularFilter const&) = delete;
|
||||
SpecularFilter(SpecularFilter&& rhs) noexcept;
|
||||
SpecularFilter& operator=(SpecularFilter&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Generates a prefiltered cubemap.
|
||||
* @param options Options for this environment
|
||||
* @param environmentCubemap Environment cubemap (input). Can't be null.
|
||||
* This cubemap must be SAMPLEABLE and must have all its
|
||||
* levels allocated. If Options.generateMipmap is true,
|
||||
* the mipmap levels will be overwritten, otherwise
|
||||
* it is assumed that all levels are correctly initialized.
|
||||
* @param outReflectionsTexture Output prefiltered texture or, if null, it is
|
||||
* automatically created with some default parameters.
|
||||
* outReflectionsTexture must be a cubemap, it must have
|
||||
* at least COLOR_ATTACHMENT and SAMPLEABLE usages and at
|
||||
* least the same number of levels than requested by Config.
|
||||
* @return returns outReflectionsTexture
|
||||
*/
|
||||
filament::Texture* operator()(Options options,
|
||||
filament::Texture const* environmentCubemap,
|
||||
filament::Texture* outReflectionsTexture = nullptr);
|
||||
|
||||
/**
|
||||
* Generates a prefiltered cubemap.
|
||||
* @param environmentCubemap Environment cubemap (input). Can't be null.
|
||||
* This cubemap must be SAMPLEABLE and must have all its
|
||||
* levels allocated. All mipmap levels will be overwritten.
|
||||
* @param outReflectionsTexture Output prefiltered texture or, if null, it is
|
||||
* automatically created with some default parameters.
|
||||
* outReflectionsTexture must be a cubemap, it must have
|
||||
* at least COLOR_ATTACHMENT and SAMPLEABLE usages and at
|
||||
* least the same number of levels than requested by Config.
|
||||
* @return returns outReflectionsTexture
|
||||
*/
|
||||
filament::Texture* operator()(
|
||||
filament::Texture const* environmentCubemap,
|
||||
filament::Texture* outReflectionsTexture = nullptr);
|
||||
|
||||
// TODO: option for progressive filtering
|
||||
|
||||
// TODO: add a callback for when the processing is done?
|
||||
|
||||
private:
|
||||
filament::Texture* createReflectionsTexture();
|
||||
IBLPrefilterContext& mContext;
|
||||
filament::Material* mKernelMaterial = nullptr;
|
||||
filament::Texture* mKernelTexture = nullptr;
|
||||
uint32_t mSampleCount = 0u;
|
||||
uint8_t mLevelCount = 1u;
|
||||
};
|
||||
|
||||
private:
|
||||
friend class Filter;
|
||||
filament::Engine& mEngine;
|
||||
filament::Renderer* mRenderer{};
|
||||
filament::Scene* mScene{};
|
||||
filament::VertexBuffer* mVertexBuffer{};
|
||||
filament::IndexBuffer* mIndexBuffer{};
|
||||
filament::Camera* mCamera{};
|
||||
utils::Entity mFullScreenQuadEntity{};
|
||||
utils::Entity mCameraEntity{};
|
||||
filament::View* mView{};
|
||||
filament::Material* mIntegrationMaterial{};
|
||||
filament::Material* mIrradianceIntegrationMaterial{};
|
||||
};
|
||||
|
||||
#endif //TNT_IBL_PREFILTER_IBLPREFILTER_H
|
||||
248
dart_filament/native/include/filament/filament/Box.h
Normal file
248
dart_filament/native/include/filament/filament/Box.h
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BOX_H
|
||||
#define TNT_FILAMENT_BOX_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mat3.h>
|
||||
#include <math/mat4.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* An axis aligned 3D box represented by its center and half-extent.
|
||||
*/
|
||||
class UTILS_PUBLIC Box {
|
||||
public:
|
||||
/** Center of the 3D box */
|
||||
math::float3 center = {};
|
||||
|
||||
/** Half extent from the center on all 3 axis */
|
||||
math::float3 halfExtent = {};
|
||||
|
||||
/**
|
||||
* Whether the box is empty, i.e.: it's volume is null.
|
||||
* @return true if the volume of the box is null
|
||||
*/
|
||||
constexpr bool isEmpty() const noexcept {
|
||||
return length2(halfExtent) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the lowest coordinates corner of the box.
|
||||
* @return center - halfExtent
|
||||
*/
|
||||
constexpr math::float3 getMin() const noexcept {
|
||||
return center - halfExtent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the largest coordinates corner of the box.
|
||||
* @return center + halfExtent
|
||||
*/
|
||||
constexpr math::float3 getMax() const noexcept {
|
||||
return center + halfExtent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the 3D box from its min / max coordinates on each axis
|
||||
* @param min lowest coordinates corner of the box
|
||||
* @param max largest coordinates corner of the box
|
||||
* @return This bounding box
|
||||
*/
|
||||
Box& set(const math::float3& min, const math::float3& max) noexcept {
|
||||
// float3 ctor needed for Visual Studio
|
||||
center = (max + min) * math::float3(0.5f);
|
||||
halfExtent = (max - min) * math::float3(0.5f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the bounding box of the union of two boxes
|
||||
* @param box The box to be combined with
|
||||
* @return The bounding box of the union of *this and box
|
||||
*/
|
||||
Box& unionSelf(const Box& box) noexcept {
|
||||
set(min(getMin(), box.getMin()), max(getMax(), box.getMax()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the box *to* a given center position
|
||||
* @param tr position to translate the box to
|
||||
* @return A box centered in \p tr with the same extent than *this
|
||||
*/
|
||||
constexpr Box translateTo(const math::float3& tr) const noexcept {
|
||||
return Box{ tr, halfExtent };
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the smallest bounding sphere of the box.
|
||||
* @return The smallest sphere defined by its center (.xyz) and radius (.w) that contains *this
|
||||
*/
|
||||
math::float4 getBoundingSphere() const noexcept {
|
||||
return { center, length(halfExtent) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Box by a linear transform and a translation.
|
||||
*
|
||||
* @param m a 3x3 matrix, the linear transform
|
||||
* @param t a float3, the translation
|
||||
* @param box the box to transform
|
||||
* @return the bounding box of the transformed box
|
||||
*/
|
||||
static Box transform(const math::mat3f& m, math::float3 const& t, const Box& box) noexcept {
|
||||
return { m * box.center + t, abs(m) * box.halfExtent };
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use transform() instead
|
||||
* @see transform()
|
||||
*/
|
||||
friend Box rigidTransform(Box const& box, const math::mat4f& m) noexcept {
|
||||
return transform(m.upperLeft(), m[3].xyz, box);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* An axis aligned box represented by its min and max coordinates
|
||||
*/
|
||||
struct UTILS_PUBLIC Aabb {
|
||||
|
||||
/** min coordinates */
|
||||
math::float3 min = FLT_MAX;
|
||||
|
||||
/** max coordinates */
|
||||
math::float3 max = -FLT_MAX;
|
||||
|
||||
/**
|
||||
* Computes the center of the box.
|
||||
* @return (max + min)/2
|
||||
*/
|
||||
math::float3 center() const noexcept {
|
||||
// float3 ctor needed for Visual Studio
|
||||
return (max + min) * math::float3(0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the half-extent of the box.
|
||||
* @return (max - min)/2
|
||||
*/
|
||||
math::float3 extent() const noexcept {
|
||||
// float3 ctor needed for Visual Studio
|
||||
return (max - min) * math::float3(0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the box is empty, i.e.: it's volume is null or negative.
|
||||
* @return true if min >= max, i.e: the volume of the box is null or negative
|
||||
*/
|
||||
bool isEmpty() const noexcept {
|
||||
return any(greaterThanEqual(min, max));
|
||||
}
|
||||
|
||||
struct Corners {
|
||||
using value_type = math::float3;
|
||||
value_type const* begin() const { return vertices; }
|
||||
value_type const* end() const { return vertices + 8; }
|
||||
value_type * begin() { return vertices; }
|
||||
value_type * end() { return vertices + 8; }
|
||||
value_type const* data() const { return vertices; }
|
||||
value_type * data() { return vertices; }
|
||||
size_t size() const { return 8; }
|
||||
value_type const& operator[](size_t i) const noexcept { return vertices[i]; }
|
||||
value_type& operator[](size_t i) noexcept { return vertices[i]; }
|
||||
value_type vertices[8];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the 8 corner vertices of the AABB.
|
||||
*/
|
||||
Corners getCorners() const {
|
||||
return Aabb::Corners{ .vertices = {
|
||||
{ min.x, min.y, min.z },
|
||||
{ max.x, min.y, min.z },
|
||||
{ min.x, max.y, min.z },
|
||||
{ max.x, max.y, min.z },
|
||||
{ min.x, min.y, max.z },
|
||||
{ max.x, min.y, max.z },
|
||||
{ min.x, max.y, max.z },
|
||||
{ max.x, max.y, max.z },
|
||||
}};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the box contains a given point.
|
||||
*
|
||||
* @param p the point to test
|
||||
* @return the maximum signed distance to the box. Negative if p is in the box
|
||||
*/
|
||||
float contains(math::float3 p) const noexcept {
|
||||
// we don't use std::max to avoid a dependency on <algorithm>
|
||||
auto const maximum = [](auto a, auto b) { return a > b ? a : b; };
|
||||
float d = min.x - p.x;
|
||||
d = maximum(d, min.y - p.y);
|
||||
d = maximum(d, min.z - p.z);
|
||||
d = maximum(d, p.x - max.x);
|
||||
d = maximum(d, p.y - max.y);
|
||||
d = maximum(d, p.z - max.z);
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies an affine transformation to the AABB.
|
||||
*
|
||||
* @param m the 3x3 transformation to apply
|
||||
* @param t the translation
|
||||
* @return the transformed box
|
||||
*/
|
||||
static Aabb transform(const math::mat3f& m, math::float3 const& t, const Aabb& box) noexcept {
|
||||
// Fast AABB transformation per Jim Arvo in Graphics Gems (1990).
|
||||
Aabb result{ t, t };
|
||||
for (size_t col = 0; col < 3; ++col) {
|
||||
for (size_t row = 0; row < 3; ++row) {
|
||||
const float a = m[col][row] * box.min[col];
|
||||
const float b = m[col][row] * box.max[col];
|
||||
result.min[row] += a < b ? a : b;
|
||||
result.max[row] += a < b ? b : a;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use transform() instead
|
||||
* @see transform()
|
||||
*/
|
||||
Aabb transform(const math::mat4f& m) const noexcept {
|
||||
return transform(m.upperLeft(), m[3].xyz, *this);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_BOX_H
|
||||
122
dart_filament/native/include/filament/filament/BufferObject.h
Normal file
122
dart_filament/native/include/filament/filament/BufferObject.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BUFFEROBJECT_H
|
||||
#define TNT_FILAMENT_BUFFEROBJECT_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/BufferDescriptor.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class FBufferObject;
|
||||
|
||||
class Engine;
|
||||
|
||||
/**
|
||||
* A generic GPU buffer containing data.
|
||||
*
|
||||
* Usage of this BufferObject is optional. For simple use cases it is not necessary. It is useful
|
||||
* only when you need to share data between multiple VertexBuffer instances. It also allows you to
|
||||
* efficiently swap-out the buffers in VertexBuffer.
|
||||
*
|
||||
* NOTE: For now this is only used for vertex data, but in the future we may use it for other things
|
||||
* (e.g. compute).
|
||||
*
|
||||
* @see VertexBuffer
|
||||
*/
|
||||
class UTILS_PUBLIC BufferObject : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
using BufferDescriptor = backend::BufferDescriptor;
|
||||
using BindingType = backend::BufferObjectBinding;
|
||||
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Size of the buffer in bytes.
|
||||
* @param byteCount Maximum number of bytes the BufferObject can hold.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& size(uint32_t byteCount) noexcept;
|
||||
|
||||
/**
|
||||
* The binding type for this buffer object. (defaults to VERTEX)
|
||||
* @param BindingType Distinguishes between SSBO, VBO, etc. For now this must be VERTEX.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& bindingType(BindingType bindingType) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the BufferObject and returns a pointer to it. After creation, the buffer
|
||||
* object is uninitialized. Use BufferObject::setBuffer() to initialize it.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this BufferObject with.
|
||||
*
|
||||
* @return pointer to the newly created object
|
||||
*
|
||||
* @exception utils::PostConditionPanic if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
|
||||
*
|
||||
* @see IndexBuffer::setBuffer
|
||||
*/
|
||||
BufferObject* UTILS_NONNULL build(Engine& engine);
|
||||
private:
|
||||
friend class FBufferObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronously copy-initializes a region of this BufferObject from the data provided.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine associated with this BufferObject.
|
||||
* @param buffer A BufferDescriptor representing the data used to initialize the BufferObject.
|
||||
* @param byteOffset Offset in bytes into the BufferObject
|
||||
*/
|
||||
void setBuffer(Engine& engine, BufferDescriptor&& buffer, uint32_t byteOffset = 0);
|
||||
|
||||
/**
|
||||
* Returns the size of this BufferObject in elements.
|
||||
* @return The maximum capacity of the BufferObject.
|
||||
*/
|
||||
size_t getByteCount() const noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~BufferObject() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_BUFFEROBJECT_H
|
||||
584
dart_filament/native/include/filament/filament/Camera.h
Normal file
584
dart_filament/native/include/filament/filament/Camera.h
Normal file
@@ -0,0 +1,584 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_CAMERA_H
|
||||
#define TNT_FILAMENT_CAMERA_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec4.h>
|
||||
#include <math/mat4.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace utils {
|
||||
class Entity;
|
||||
} // namespace utils
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* Camera represents the eye(s) through which the scene is viewed.
|
||||
*
|
||||
* A Camera has a position and orientation and controls the projection and exposure parameters.
|
||||
*
|
||||
* For stereoscopic rendering, a Camera maintains two separate "eyes": Eye 0 and Eye 1. These are
|
||||
* arbitrary and don't necessarily need to correspond to "left" and "right".
|
||||
*
|
||||
* Creation and destruction
|
||||
* ========================
|
||||
*
|
||||
* In Filament, Camera is a component that must be associated with an entity. To do so,
|
||||
* use Engine::createCamera(Entity). A Camera component is destroyed using
|
||||
* Engine::destroyCameraComponent(Entity).
|
||||
*
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* filament::Engine* engine = filament::Engine::create();
|
||||
*
|
||||
* utils::Entity myCameraEntity = utils::EntityManager::get().create();
|
||||
* filament::Camera* myCamera = engine->createCamera(myCameraEntity);
|
||||
* myCamera->setProjection(45, 16.0/9.0, 0.1, 1.0);
|
||||
* myCamera->lookAt({0, 1.60, 1}, {0, 0, 0});
|
||||
* engine->destroyCameraComponent(myCamera);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
*
|
||||
* Coordinate system
|
||||
* =================
|
||||
*
|
||||
* The camera coordinate system defines the *view space*. The camera points towards its -z axis
|
||||
* and is oriented such that its top side is in the direction of +y, and its right side in the
|
||||
* direction of +x.
|
||||
*
|
||||
* @note
|
||||
* Since the *near* and *far* planes are defined by the distance from the camera,
|
||||
* their respective coordinates are -\p distance(near) and -\p distance(far).
|
||||
*
|
||||
* Clipping planes
|
||||
* ===============
|
||||
*
|
||||
* The camera defines six *clipping planes* which together create a *clipping volume*. The
|
||||
* geometry outside this volume is clipped.
|
||||
*
|
||||
* The clipping volume can either be a box or a frustum depending on which projection is used,
|
||||
* respectively Projection.ORTHO or Projection.PERSPECTIVE. The six planes are specified either
|
||||
* directly or indirectly using setProjection().
|
||||
*
|
||||
* The six planes are:
|
||||
* - left
|
||||
* - right
|
||||
* - bottom
|
||||
* - top
|
||||
* - near
|
||||
* - far
|
||||
*
|
||||
* @note
|
||||
* To increase the depth-buffer precision, the *far* clipping plane is always assumed to be at
|
||||
* infinity for rendering. That is, it is not used to clip geometry during rendering.
|
||||
* However, it is used during the culling phase (objects entirely behind the *far*
|
||||
* plane are culled).
|
||||
*
|
||||
*
|
||||
* Choosing the *near* plane distance
|
||||
* ==================================
|
||||
*
|
||||
* The *near* plane distance greatly affects the depth-buffer resolution.
|
||||
*
|
||||
* Example: Precision at 1m, 10m, 100m and 1Km for various near distances assuming a 32-bit float
|
||||
* depth-buffer:
|
||||
*
|
||||
* near (m) | 1 m | 10 m | 100 m | 1 Km
|
||||
* -----------:|:------:|:-------:|:--------:|:--------:
|
||||
* 0.001 | 7.2e-5 | 0.0043 | 0.4624 | 48.58
|
||||
* 0.01 | 6.9e-6 | 0.0001 | 0.0430 | 4.62
|
||||
* 0.1 | 3.6e-7 | 7.0e-5 | 0.0072 | 0.43
|
||||
* 1.0 | 0 | 3.8e-6 | 0.0007 | 0.07
|
||||
*
|
||||
* As can be seen in the table above, the depth-buffer precision drops rapidly with the
|
||||
* distance to the camera.
|
||||
*
|
||||
* Make sure to pick the highest *near* plane distance possible.
|
||||
*
|
||||
* On Vulkan and Metal platforms (or OpenGL platforms supporting either EXT_clip_control or
|
||||
* ARB_clip_control extensions), the depth-buffer precision is much less dependent on the *near*
|
||||
* plane value:
|
||||
*
|
||||
* near (m) | 1 m | 10 m | 100 m | 1 Km
|
||||
* -----------:|:------:|:-------:|:--------:|:--------:
|
||||
* 0.001 | 1.2e-7 | 9.5e-7 | 7.6e-6 | 6.1e-5
|
||||
* 0.01 | 1.2e-7 | 9.5e-7 | 7.6e-6 | 6.1e-5
|
||||
* 0.1 | 5.9e-8 | 9.5e-7 | 1.5e-5 | 1.2e-4
|
||||
* 1.0 | 0 | 9.5e-7 | 7.6e-6 | 1.8e-4
|
||||
*
|
||||
*
|
||||
* Choosing the *far* plane distance
|
||||
* =================================
|
||||
*
|
||||
* The far plane distance is always set internally to infinity for rendering, however it is used for
|
||||
* culling and shadowing calculations. It is important to keep a reasonable ratio between
|
||||
* the near and far plane distances. Typically a ratio in the range 1:100 to 1:100000 is
|
||||
* commanded. Larger values may causes rendering artifacts or trigger assertions in debug builds.
|
||||
*
|
||||
*
|
||||
* Exposure
|
||||
* ========
|
||||
*
|
||||
* The Camera is also used to set the scene's exposure, just like with a real camera. The lights
|
||||
* intensity and the Camera exposure interact to produce the final scene's brightness.
|
||||
*
|
||||
*
|
||||
* Stereoscopic rendering
|
||||
* ======================
|
||||
*
|
||||
* The Camera's transform (as set by setModelMatrix or via TransformManager) defines a "head" space,
|
||||
* which typically corresponds to the location of the viewer's head. Each eye's transform is set
|
||||
* relative to this head space by setEyeModelMatrix.
|
||||
*
|
||||
* Each eye also maintains its own projection matrix. These can be set with setCustomEyeProjection.
|
||||
* Care must be taken to correctly set the projectionForCulling matrix, as well as its corresponding
|
||||
* near and far values. The projectionForCulling matrix must define a frustum (in head space) that
|
||||
* bounds the frustums of both eyes. Alternatively, culling may be disabled with
|
||||
* View::setFrustumCullingEnabled.
|
||||
*
|
||||
* \see Frustum, View
|
||||
*/
|
||||
class UTILS_PUBLIC Camera : public FilamentAPI {
|
||||
public:
|
||||
//! Denotes the projection type used by this camera. \see setProjection
|
||||
enum class Projection : int {
|
||||
PERSPECTIVE, //!< perspective projection, objects get smaller as they are farther
|
||||
ORTHO //!< orthonormal projection, preserves distances
|
||||
};
|
||||
|
||||
//! Denotes a field-of-view direction. \see setProjection
|
||||
enum class Fov : int {
|
||||
VERTICAL, //!< the field-of-view angle is defined on the vertical axis
|
||||
HORIZONTAL //!< the field-of-view angle is defined on the horizontal axis
|
||||
};
|
||||
|
||||
/** Returns the projection matrix from the field-of-view.
|
||||
*
|
||||
* @param fovInDegrees full field-of-view in degrees. 0 < \p fov < 180.
|
||||
* @param aspect aspect ratio \f$ \frac{width}{height} \f$. \p aspect > 0.
|
||||
* @param near distance in world units from the camera to the near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the far plane. \p far > \p near.
|
||||
* @param direction direction of the \p fovInDegrees parameter.
|
||||
*
|
||||
* @see Fov.
|
||||
*/
|
||||
static math::mat4 projection(Fov direction, double fovInDegrees,
|
||||
double aspect, double near, double far = INFINITY);
|
||||
|
||||
/** Returns the projection matrix from the focal length.
|
||||
*
|
||||
* @param focalLengthInMillimeters lens's focal length in millimeters. \p focalLength > 0.
|
||||
* @param aspect aspect ratio \f$ \frac{width}{height} \f$. \p aspect > 0.
|
||||
* @param near distance in world units from the camera to the near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the far plane. \p far > \p near.
|
||||
*/
|
||||
static math::mat4 projection(double focalLengthInMillimeters,
|
||||
double aspect, double near, double far = INFINITY);
|
||||
|
||||
|
||||
/** Sets the projection matrix from a frustum defined by six planes.
|
||||
*
|
||||
* @param projection type of #Projection to use.
|
||||
*
|
||||
* @param left distance in world units from the camera to the left plane,
|
||||
* at the near plane.
|
||||
* Precondition: \p left != \p right.
|
||||
*
|
||||
* @param right distance in world units from the camera to the right plane,
|
||||
* at the near plane.
|
||||
* Precondition: \p left != \p right.
|
||||
*
|
||||
* @param bottom distance in world units from the camera to the bottom plane,
|
||||
* at the near plane.
|
||||
* Precondition: \p bottom != \p top.
|
||||
*
|
||||
* @param top distance in world units from the camera to the top plane,
|
||||
* at the near plane.
|
||||
* Precondition: \p left != \p right.
|
||||
*
|
||||
* @param near distance in world units from the camera to the near plane. The near plane's
|
||||
* position in view space is z = -\p near.
|
||||
* Precondition: \p near > 0 for PROJECTION::PERSPECTIVE or
|
||||
* \p near != far for PROJECTION::ORTHO
|
||||
*
|
||||
* @param far distance in world units from the camera to the far plane. The far plane's
|
||||
* position in view space is z = -\p far.
|
||||
* Precondition: \p far > near for PROJECTION::PERSPECTIVE or
|
||||
* \p far != near for PROJECTION::ORTHO
|
||||
*
|
||||
* @see Projection, Frustum
|
||||
*/
|
||||
void setProjection(Projection projection,
|
||||
double left, double right,
|
||||
double bottom, double top,
|
||||
double near, double far);
|
||||
|
||||
|
||||
/** Utility to set the projection matrix from the field-of-view.
|
||||
*
|
||||
* @param fovInDegrees full field-of-view in degrees. 0 < \p fov < 180.
|
||||
* @param aspect aspect ratio \f$ \frac{width}{height} \f$. \p aspect > 0.
|
||||
* @param near distance in world units from the camera to the near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the far plane. \p far > \p near.
|
||||
* @param direction direction of the \p fovInDegrees parameter.
|
||||
*
|
||||
* @see Fov.
|
||||
*/
|
||||
void setProjection(double fovInDegrees, double aspect, double near, double far,
|
||||
Fov direction = Fov::VERTICAL);
|
||||
|
||||
/** Utility to set the projection matrix from the focal length.
|
||||
*
|
||||
* @param focalLengthInMillimeters lens's focal length in millimeters. \p focalLength > 0.
|
||||
* @param aspect aspect ratio \f$ \frac{width}{height} \f$. \p aspect > 0.
|
||||
* @param near distance in world units from the camera to the near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the far plane. \p far > \p near.
|
||||
*/
|
||||
void setLensProjection(double focalLengthInMillimeters,
|
||||
double aspect, double near, double far);
|
||||
|
||||
|
||||
/** Sets a custom projection matrix.
|
||||
*
|
||||
* The projection matrix must define an NDC system that must match the OpenGL convention,
|
||||
* that is all 3 axis are mapped to [-1, 1].
|
||||
*
|
||||
* @param projection custom projection matrix used for rendering and culling
|
||||
* @param near distance in world units from the camera to the near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the far plane. \p far > \p near.
|
||||
*/
|
||||
void setCustomProjection(math::mat4 const& projection, double near, double far) noexcept;
|
||||
|
||||
/** Sets the projection matrix.
|
||||
*
|
||||
* The projection matrices must define an NDC system that must match the OpenGL convention,
|
||||
* that is all 3 axis are mapped to [-1, 1].
|
||||
*
|
||||
* @param projection custom projection matrix used for rendering
|
||||
* @param projectionForCulling custom projection matrix used for culling
|
||||
* @param near distance in world units from the camera to the near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the far plane. \p far > \p near.
|
||||
*/
|
||||
void setCustomProjection(math::mat4 const& projection, math::mat4 const& projectionForCulling,
|
||||
double near, double far) noexcept;
|
||||
|
||||
/** Sets a custom projection matrix for each eye.
|
||||
*
|
||||
* The projectionForCulling, near, and far parameters establish a "culling frustum" which must
|
||||
* encompass anything any eye can see. All projection matrices must be set simultaneously. The
|
||||
* number of stereoscopic eyes is controlled by the stereoscopicEyeCount setting inside of
|
||||
* Engine::Config.
|
||||
*
|
||||
* @param projection an array of projection matrices, only the first config.stereoscopicEyeCount
|
||||
* are read
|
||||
* @param count size of the projection matrix array to set, must be
|
||||
* >= config.stereoscopicEyeCount
|
||||
* @param projectionForCulling custom projection matrix for culling, must encompass both eyes
|
||||
* @param near distance in world units from the camera to the culling near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the culling far plane. \p far > \p
|
||||
* near.
|
||||
* @see setCustomProjection
|
||||
* @see Engine::Config::stereoscopicEyeCount
|
||||
*/
|
||||
void setCustomEyeProjection(math::mat4 const* UTILS_NONNULL projection, size_t count,
|
||||
math::mat4 const& projectionForCulling, double near, double far);
|
||||
|
||||
/** Sets an additional matrix that scales the projection matrix.
|
||||
*
|
||||
* This is useful to adjust the aspect ratio of the camera independent from its projection.
|
||||
* First, pass an aspect of 1.0 to setProjection. Then set the scaling with the desired aspect
|
||||
* ratio:
|
||||
*
|
||||
* const double aspect = width / height;
|
||||
*
|
||||
* // with Fov::HORIZONTAL passed to setProjection:
|
||||
* camera->setScaling(double4 {1.0, aspect});
|
||||
*
|
||||
* // with Fov::VERTICAL passed to setProjection:
|
||||
* camera->setScaling(double4 {1.0 / aspect, 1.0});
|
||||
*
|
||||
*
|
||||
* By default, this is an identity matrix.
|
||||
*
|
||||
* @param scaling diagonal of the 2x2 scaling matrix to be applied after the projection matrix.
|
||||
*
|
||||
* @see setProjection, setLensProjection, setCustomProjection
|
||||
*/
|
||||
void setScaling(math::double2 scaling) noexcept;
|
||||
|
||||
/**
|
||||
* Sets an additional matrix that shifts the projection matrix.
|
||||
* By default, this is an identity matrix.
|
||||
*
|
||||
* @param shift x and y translation added to the projection matrix, specified in NDC
|
||||
* coordinates, that is, if the translation must be specified in pixels,
|
||||
* shift must be scaled by 1.0 / { viewport.width, viewport.height }.
|
||||
*
|
||||
* @see setProjection, setLensProjection, setCustomProjection
|
||||
*/
|
||||
void setShift(math::double2 shift) noexcept;
|
||||
|
||||
/** Returns the scaling amount used to scale the projection matrix.
|
||||
*
|
||||
* @return the diagonal of the scaling matrix applied after the projection matrix.
|
||||
*
|
||||
* @see setScaling
|
||||
*/
|
||||
math::double4 getScaling() const noexcept;
|
||||
|
||||
/** Returns the shift amount used to translate the projection matrix.
|
||||
*
|
||||
* @return the 2D translation x and y offsets applied after the projection matrix.
|
||||
*
|
||||
* @see setShift
|
||||
*/
|
||||
math::double2 getShift() const noexcept;
|
||||
|
||||
/** Returns the projection matrix used for rendering.
|
||||
*
|
||||
* The projection matrix used for rendering always has its far plane set to infinity. This
|
||||
* is why it may differ from the matrix set through setProjection() or setLensProjection().
|
||||
*
|
||||
* @param eyeId the index of the eye to return the projection matrix for, must be
|
||||
* < config.stereoscopicEyeCount
|
||||
* @return The projection matrix used for rendering
|
||||
*
|
||||
* @see setProjection, setLensProjection, setCustomProjection, getCullingProjectionMatrix,
|
||||
* setCustomEyeProjection
|
||||
*/
|
||||
math::mat4 getProjectionMatrix(uint8_t eyeId = 0) const;
|
||||
|
||||
|
||||
/** Returns the projection matrix used for culling (far plane is finite).
|
||||
*
|
||||
* @return The projection matrix set by setProjection or setLensProjection.
|
||||
*
|
||||
* @see setProjection, setLensProjection, getProjectionMatrix
|
||||
*/
|
||||
math::mat4 getCullingProjectionMatrix() const noexcept;
|
||||
|
||||
|
||||
//! Returns the frustum's near plane
|
||||
double getNear() const noexcept;
|
||||
|
||||
//! Returns the frustum's far plane used for culling
|
||||
double getCullingFar() const noexcept;
|
||||
|
||||
/** Sets the camera's model matrix.
|
||||
*
|
||||
* Helper method to set the camera's entity transform component.
|
||||
* It has the same effect as calling:
|
||||
*
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* engine.getTransformManager().setTransform(
|
||||
* engine.getTransformManager().getInstance(camera->getEntity()), model);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* @param model The camera position and orientation provided as a rigid transform matrix.
|
||||
*
|
||||
* @note The Camera "looks" towards its -z axis
|
||||
*
|
||||
* @warning \p model must be a rigid transform
|
||||
*/
|
||||
void setModelMatrix(const math::mat4& model) noexcept;
|
||||
void setModelMatrix(const math::mat4f& model) noexcept; //!< @overload
|
||||
|
||||
/** Set the position of an eye relative to this Camera (head).
|
||||
*
|
||||
* By default, both eyes' model matrices are identity matrices.
|
||||
*
|
||||
* For example, to position Eye 0 3cm leftwards and Eye 1 3cm rightwards:
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* const mat4 leftEye = mat4::translation(double3{-0.03, 0.0, 0.0});
|
||||
* const mat4 rightEye = mat4::translation(double3{ 0.03, 0.0, 0.0});
|
||||
* camera.setEyeModelMatrix(0, leftEye);
|
||||
* camera.setEyeModelMatrix(1, rightEye);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* This method is not intended to be called every frame. Instead, to update the position of the
|
||||
* head, use Camera::setModelMatrix.
|
||||
*
|
||||
* @param eyeId the index of the eye to set, must be < config.stereoscopicEyeCount
|
||||
* @param model the model matrix for an individual eye
|
||||
*/
|
||||
void setEyeModelMatrix(uint8_t eyeId, math::mat4 const& model);
|
||||
|
||||
/** Sets the camera's model matrix
|
||||
*
|
||||
* @param eye The position of the camera in world space.
|
||||
* @param center The point in world space the camera is looking at.
|
||||
* @param up A unit vector denoting the camera's "up" direction.
|
||||
*/
|
||||
void lookAt(math::double3 const& eye,
|
||||
math::double3 const& center,
|
||||
math::double3 const& up = math::double3{0, 1, 0}) noexcept;
|
||||
|
||||
/** Returns the camera's model matrix
|
||||
*
|
||||
* Helper method to return the camera's entity transform component.
|
||||
* It has the same effect as calling:
|
||||
*
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* engine.getTransformManager().getWorldTransform(
|
||||
* engine.getTransformManager().getInstance(camera->getEntity()));
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* @return The camera's pose in world space as a rigid transform. Parent transforms, if any,
|
||||
* are taken into account.
|
||||
*/
|
||||
math::mat4 getModelMatrix() const noexcept;
|
||||
|
||||
//! Returns the camera's view matrix (inverse of the model matrix)
|
||||
math::mat4 getViewMatrix() const noexcept;
|
||||
|
||||
//! Returns the camera's position in world space
|
||||
math::double3 getPosition() const noexcept;
|
||||
|
||||
//! Returns the camera's normalized left vector
|
||||
math::float3 getLeftVector() const noexcept;
|
||||
|
||||
//! Returns the camera's normalized up vector
|
||||
math::float3 getUpVector() const noexcept;
|
||||
|
||||
//! Returns the camera's forward vector
|
||||
math::float3 getForwardVector() const noexcept;
|
||||
|
||||
//! Returns the camera's field of view in degrees
|
||||
float getFieldOfViewInDegrees(Fov direction) const noexcept;
|
||||
|
||||
//! Returns the camera's culling Frustum in world space
|
||||
class Frustum getFrustum() const noexcept;
|
||||
|
||||
//! Returns the entity representing this camera
|
||||
utils::Entity getEntity() const noexcept;
|
||||
|
||||
/** Sets this camera's exposure (default is f/16, 1/125s, 100 ISO)
|
||||
*
|
||||
* The exposure ultimately controls the scene's brightness, just like with a real camera.
|
||||
* The default values provide adequate exposure for a camera placed outdoors on a sunny day
|
||||
* with the sun at the zenith.
|
||||
*
|
||||
* @param aperture Aperture in f-stops, clamped between 0.5 and 64.
|
||||
* A lower \p aperture value *increases* the exposure, leading to
|
||||
* a brighter scene. Realistic values are between 0.95 and 32.
|
||||
*
|
||||
* @param shutterSpeed Shutter speed in seconds, clamped between 1/25,000 and 60.
|
||||
* A lower shutter speed increases the exposure. Realistic values are
|
||||
* between 1/8000 and 30.
|
||||
*
|
||||
* @param sensitivity Sensitivity in ISO, clamped between 10 and 204,800.
|
||||
* A higher \p sensitivity increases the exposure. Realistic values are
|
||||
* between 50 and 25600.
|
||||
*
|
||||
* @note
|
||||
* With the default parameters, the scene must contain at least one Light of intensity
|
||||
* similar to the sun (e.g.: a 100,000 lux directional light).
|
||||
*
|
||||
* @see LightManager, Exposure
|
||||
*/
|
||||
void setExposure(float aperture, float shutterSpeed, float sensitivity) noexcept;
|
||||
|
||||
/** Sets this camera's exposure directly. Calling this method will set the aperture
|
||||
* to 1.0, the shutter speed to 1.2 and the sensitivity will be computed to match
|
||||
* the requested exposure (for a desired exposure of 1.0, the sensitivity will be
|
||||
* set to 100 ISO).
|
||||
*
|
||||
* This method is useful when trying to match the lighting of other engines or tools.
|
||||
* Many engines/tools use unit-less light intensities, which can be matched by setting
|
||||
* the exposure manually. This can be typically achieved by setting the exposure to
|
||||
* 1.0.
|
||||
*/
|
||||
void setExposure(float exposure) noexcept {
|
||||
setExposure(1.0f, 1.2f, 100.0f * (1.0f / exposure));
|
||||
}
|
||||
|
||||
//! returns this camera's aperture in f-stops
|
||||
float getAperture() const noexcept;
|
||||
|
||||
//! returns this camera's shutter speed in seconds
|
||||
float getShutterSpeed() const noexcept;
|
||||
|
||||
//! returns this camera's sensitivity in ISO
|
||||
float getSensitivity() const noexcept;
|
||||
|
||||
/** Returns the focal length in meters [m] for a 35mm camera.
|
||||
* Eye 0's projection matrix is used to compute the focal length.
|
||||
*/
|
||||
double getFocalLength() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the camera focus distance. This is used by the Depth-of-field PostProcessing effect.
|
||||
* @param distance Distance from the camera to the plane of focus in world units.
|
||||
* Must be positive and larger than the near clipping plane.
|
||||
*/
|
||||
void setFocusDistance(float distance) noexcept;
|
||||
|
||||
//! Returns the focus distance in world units
|
||||
float getFocusDistance() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the inverse of a projection matrix.
|
||||
*
|
||||
* \param p the projection matrix to inverse
|
||||
* \returns the inverse of the projection matrix \p p
|
||||
*/
|
||||
static math::mat4 inverseProjection(const math::mat4& p) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the inverse of a projection matrix.
|
||||
* @see inverseProjection(const math::mat4&)
|
||||
*/
|
||||
static math::mat4f inverseProjection(const math::mat4f& p) noexcept;
|
||||
|
||||
/**
|
||||
* Helper to compute the effective focal length taking into account the focus distance
|
||||
*
|
||||
* @param focalLength focal length in any unit (e.g. [m] or [mm])
|
||||
* @param focusDistance focus distance in same unit as focalLength
|
||||
* @return the effective focal length in same unit as focalLength
|
||||
*/
|
||||
static double computeEffectiveFocalLength(double focalLength, double focusDistance) noexcept;
|
||||
|
||||
/**
|
||||
* Helper to compute the effective field-of-view taking into account the focus distance
|
||||
*
|
||||
* @param fovInDegrees full field of view in degrees
|
||||
* @param focusDistance focus distance in meters [m]
|
||||
* @return effective full field of view in degrees
|
||||
*/
|
||||
static double computeEffectiveFov(double fovInDegrees, double focusDistance) noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~Camera() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_CAMERA_H
|
||||
217
dart_filament/native/include/filament/filament/Color.h
Normal file
217
dart_filament/native/include/filament/filament/Color.h
Normal file
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_COLOR_H
|
||||
#define TNT_FILAMENT_COLOR_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
//! RGB color in linear space
|
||||
using LinearColor = math::float3;
|
||||
|
||||
//! RGB color in sRGB space
|
||||
using sRGBColor = math::float3;
|
||||
|
||||
//! RGBA color in linear space, with alpha
|
||||
using LinearColorA = math::float4;
|
||||
|
||||
//! RGBA color in sRGB space, with alpha
|
||||
using sRGBColorA = math::float4;
|
||||
|
||||
//! types of RGB colors
|
||||
enum class RgbType : uint8_t {
|
||||
sRGB, //!< the color is defined in Rec.709-sRGB-D65 (sRGB) space
|
||||
LINEAR, //!< the color is defined in Rec.709-Linear-D65 ("linear sRGB") space
|
||||
};
|
||||
|
||||
//! types of RGBA colors
|
||||
enum class RgbaType : uint8_t {
|
||||
/**
|
||||
* the color is defined in Rec.709-sRGB-D65 (sRGB) space and the RGB values
|
||||
* have not been pre-multiplied by the alpha (for instance, a 50%
|
||||
* transparent red is <1,0,0,0.5>)
|
||||
*/
|
||||
sRGB,
|
||||
/**
|
||||
* the color is defined in Rec.709-Linear-D65 ("linear sRGB") space and the
|
||||
* RGB values have not been pre-multiplied by the alpha (for instance, a 50%
|
||||
* transparent red is <1,0,0,0.5>)
|
||||
*/
|
||||
LINEAR,
|
||||
/**
|
||||
* the color is defined in Rec.709-sRGB-D65 (sRGB) space and the RGB values
|
||||
* have been pre-multiplied by the alpha (for instance, a 50%
|
||||
* transparent red is <0.5,0,0,0.5>)
|
||||
*/
|
||||
PREMULTIPLIED_sRGB,
|
||||
/**
|
||||
* the color is defined in Rec.709-Linear-D65 ("linear sRGB") space and the
|
||||
* RGB values have been pre-multiplied by the alpha (for instance, a 50%
|
||||
* transparent red is <0.5,0,0,0.5>)
|
||||
*/
|
||||
PREMULTIPLIED_LINEAR
|
||||
};
|
||||
|
||||
//! type of color conversion to use when converting to/from sRGB and linear spaces
|
||||
enum ColorConversion {
|
||||
ACCURATE, //!< accurate conversion using the sRGB standard
|
||||
FAST //!< fast conversion using a simple gamma 2.2 curve
|
||||
};
|
||||
|
||||
/**
|
||||
* Utilities to manipulate and convert colors
|
||||
*/
|
||||
class UTILS_PUBLIC Color {
|
||||
public:
|
||||
//! converts an RGB color to linear space, the conversion depends on the specified type
|
||||
static LinearColor toLinear(RgbType type, math::float3 color);
|
||||
|
||||
//! converts an RGBA color to linear space, the conversion depends on the specified type
|
||||
static LinearColorA toLinear(RgbaType type, math::float4 color);
|
||||
|
||||
//! converts an RGB color in sRGB space to an RGB color in linear space
|
||||
template<ColorConversion = ACCURATE>
|
||||
static LinearColor toLinear(sRGBColor const& color);
|
||||
|
||||
/**
|
||||
* Converts an RGB color in Rec.709-Linear-D65 ("linear sRGB") space to an
|
||||
* RGB color in Rec.709-sRGB-D65 (sRGB) space.
|
||||
*/
|
||||
template<ColorConversion = ACCURATE>
|
||||
static sRGBColor toSRGB(LinearColor const& color);
|
||||
|
||||
/**
|
||||
* Converts an RGBA color in Rec.709-sRGB-D65 (sRGB) space to an RGBA color in
|
||||
* Rec.709-Linear-D65 ("linear sRGB") space the alpha component is left unmodified.
|
||||
*/
|
||||
template<ColorConversion = ACCURATE>
|
||||
static LinearColorA toLinear(sRGBColorA const& color);
|
||||
|
||||
/**
|
||||
* Converts an RGBA color in Rec.709-Linear-D65 ("linear sRGB") space to
|
||||
* an RGBA color in Rec.709-sRGB-D65 (sRGB) space the alpha component is
|
||||
* left unmodified.
|
||||
*/
|
||||
template<ColorConversion = ACCURATE>
|
||||
static sRGBColorA toSRGB(LinearColorA const& color);
|
||||
|
||||
/**
|
||||
* Converts a correlated color temperature to a linear RGB color in sRGB
|
||||
* space the temperature must be expressed in kelvin and must be in the
|
||||
* range 1,000K to 15,000K.
|
||||
*/
|
||||
static LinearColor cct(float K);
|
||||
|
||||
/**
|
||||
* Converts a CIE standard illuminant series D to a linear RGB color in
|
||||
* sRGB space the temperature must be expressed in kelvin and must be in
|
||||
* the range 4,000K to 25,000K
|
||||
*/
|
||||
static LinearColor illuminantD(float K);
|
||||
|
||||
/**
|
||||
* Computes the Beer-Lambert absorption coefficients from the specified
|
||||
* transmittance color and distance. The computed absorption will guarantee
|
||||
* the white light will become the specified color at the specified distance.
|
||||
* The output of this function can be used as the absorption parameter of
|
||||
* materials that use refraction.
|
||||
*
|
||||
* @param color the desired linear RGB color in sRGB space
|
||||
* @param distance the distance at which white light should become the specified color
|
||||
*
|
||||
* @return absorption coefficients for the Beer-Lambert law
|
||||
*/
|
||||
static math::float3 absorptionAtDistance(LinearColor const& color, float distance);
|
||||
|
||||
private:
|
||||
static math::float3 sRGBToLinear(math::float3 color) noexcept;
|
||||
static math::float3 linearToSRGB(math::float3 color) noexcept;
|
||||
};
|
||||
|
||||
// Use the default implementation from the header
|
||||
template<>
|
||||
inline LinearColor Color::toLinear<FAST>(sRGBColor const& color) {
|
||||
return pow(color, 2.2f);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline LinearColorA Color::toLinear<FAST>(sRGBColorA const& color) {
|
||||
return LinearColorA{pow(color.rgb, 2.2f), color.a};
|
||||
}
|
||||
|
||||
template<>
|
||||
inline LinearColor Color::toLinear<ACCURATE>(sRGBColor const& color) {
|
||||
return sRGBToLinear(color);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline LinearColorA Color::toLinear<ACCURATE>(sRGBColorA const& color) {
|
||||
return LinearColorA{sRGBToLinear(color.rgb), color.a};
|
||||
}
|
||||
|
||||
// Use the default implementation from the header
|
||||
template<>
|
||||
inline sRGBColor Color::toSRGB<FAST>(LinearColor const& color) {
|
||||
return pow(color, 1.0f / 2.2f);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline sRGBColorA Color::toSRGB<FAST>(LinearColorA const& color) {
|
||||
return sRGBColorA{pow(color.rgb, 1.0f / 2.2f), color.a};
|
||||
}
|
||||
|
||||
template<>
|
||||
inline sRGBColor Color::toSRGB<ACCURATE>(LinearColor const& color) {
|
||||
return linearToSRGB(color);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline sRGBColorA Color::toSRGB<ACCURATE>(LinearColorA const& color) {
|
||||
return sRGBColorA{linearToSRGB(color.rgb), color.a};
|
||||
}
|
||||
|
||||
inline LinearColor Color::toLinear(RgbType type, math::float3 color) {
|
||||
return (type == RgbType::LINEAR) ? color : Color::toLinear<ACCURATE>(color);
|
||||
}
|
||||
|
||||
// converts an RGBA color to linear space
|
||||
// the conversion depends on the specified type
|
||||
inline LinearColorA Color::toLinear(RgbaType type, math::float4 color) {
|
||||
switch (type) {
|
||||
case RgbaType::sRGB:
|
||||
return Color::toLinear<ACCURATE>(color) * math::float4{color.a, color.a, color.a, 1.0f};
|
||||
case RgbaType::LINEAR:
|
||||
return color * math::float4{color.a, color.a, color.a, 1.0f};
|
||||
case RgbaType::PREMULTIPLIED_sRGB:
|
||||
return Color::toLinear<ACCURATE>(color);
|
||||
case RgbaType::PREMULTIPLIED_LINEAR:
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_COLOR_H
|
||||
491
dart_filament/native/include/filament/filament/ColorGrading.h
Normal file
491
dart_filament/native/include/filament/filament/ColorGrading.h
Normal file
@@ -0,0 +1,491 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_COLORGRADING_H
|
||||
#define TNT_FILAMENT_COLORGRADING_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
#include <filament/ToneMapper.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Engine;
|
||||
class FColorGrading;
|
||||
|
||||
namespace color {
|
||||
class ColorSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* ColorGrading is used to transform (either to modify or correct) the colors of the HDR buffer
|
||||
* rendered by Filament. Color grading transforms are applied after lighting, and after any lens
|
||||
* effects (bloom for instance), and include tone mapping.
|
||||
*
|
||||
* Creation, usage and destruction
|
||||
* ===============================
|
||||
*
|
||||
* A ColorGrading object is created using the ColorGrading::Builder and destroyed by calling
|
||||
* Engine::destroy(const ColorGrading*). A ColorGrading object is meant to be set on a View.
|
||||
*
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* filament::Engine* engine = filament::Engine::create();
|
||||
*
|
||||
* filament::ColorGrading* colorGrading = filament::ColorGrading::Builder()
|
||||
* .toneMapping(filament::ColorGrading::ToneMapping::ACES)
|
||||
* .build(*engine);
|
||||
*
|
||||
* myView->setColorGrading(colorGrading);
|
||||
*
|
||||
* engine->destroy(colorGrading);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* Performance
|
||||
* ===========
|
||||
*
|
||||
* Creating a new ColorGrading object may be more expensive than other Filament objects as a
|
||||
* 3D LUT may need to be generated. The generation of a 3D LUT, if necessary, may happen on
|
||||
* the CPU.
|
||||
*
|
||||
* Ordering
|
||||
* ========
|
||||
*
|
||||
* The various transforms held by ColorGrading are applied in the following order:
|
||||
* - Exposure
|
||||
* - Night adaptation
|
||||
* - White balance
|
||||
* - Channel mixer
|
||||
* - Shadows/mid-tones/highlights
|
||||
* - Slope/offset/power (CDL)
|
||||
* - Contrast
|
||||
* - Vibrance
|
||||
* - Saturation
|
||||
* - Curves
|
||||
* - Tone mapping
|
||||
* - Luminance scaling
|
||||
* - Gamut mapping
|
||||
*
|
||||
* Defaults
|
||||
* ========
|
||||
*
|
||||
* Here are the default color grading options:
|
||||
* - Exposure: 0.0
|
||||
* - Night adaptation: 0.0
|
||||
* - White balance: temperature 0, and tint 0
|
||||
* - Channel mixer: red {1,0,0}, green {0,1,0}, blue {0,0,1}
|
||||
* - Shadows/mid-tones/highlights: shadows {1,1,1,0}, mid-tones {1,1,1,0}, highlights {1,1,1,0},
|
||||
* ranges {0,0.333,0.550,1}
|
||||
* - Slope/offset/power: slope 1.0, offset 0.0, and power 1.0
|
||||
* - Contrast: 1.0
|
||||
* - Vibrance: 1.0
|
||||
* - Saturation: 1.0
|
||||
* - Curves: gamma {1,1,1}, midPoint {1,1,1}, and scale {1,1,1}
|
||||
* - Tone mapping: ACESLegacyToneMapper
|
||||
* - Luminance scaling: false
|
||||
* - Gamut mapping: false
|
||||
* - Output color space: Rec709-sRGB-D65
|
||||
*
|
||||
* @see View
|
||||
*/
|
||||
class UTILS_PUBLIC ColorGrading : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
public:
|
||||
|
||||
enum class QualityLevel : uint8_t {
|
||||
LOW,
|
||||
MEDIUM,
|
||||
HIGH,
|
||||
ULTRA
|
||||
};
|
||||
|
||||
enum class LutFormat : uint8_t {
|
||||
INTEGER, //!< 10 bits per component
|
||||
FLOAT, //!< 16 bits per component (10 bits mantissa precision)
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* List of available tone-mapping operators.
|
||||
*
|
||||
* @deprecated Use Builder::toneMapper(ToneMapper*) instead
|
||||
*/
|
||||
enum class UTILS_DEPRECATED ToneMapping : uint8_t {
|
||||
LINEAR = 0, //!< Linear tone mapping (i.e. no tone mapping)
|
||||
ACES_LEGACY = 1, //!< ACES tone mapping, with a brightness modifier to match Filament's legacy tone mapper
|
||||
ACES = 2, //!< ACES tone mapping
|
||||
FILMIC = 3, //!< Filmic tone mapping, modelled after ACES but applied in sRGB space
|
||||
DISPLAY_RANGE = 4, //!< Tone mapping used to validate/debug scene exposure
|
||||
};
|
||||
|
||||
//! Use Builder to construct a ColorGrading object instance
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the quality level of the color grading. When color grading is implemented using
|
||||
* a 3D LUT, the quality level may impact the resolution and bit depth of the backing
|
||||
* 3D texture. For instance, a low quality level will use a 16x16x16 10 bit LUT, a medium
|
||||
* quality level will use a 32x32x32 10 bit LUT, a high quality will use a 32x32x32 16 bit
|
||||
* LUT, and a ultra quality will use a 64x64x64 16 bit LUT.
|
||||
* This overrides the values set by format() and dimensions().
|
||||
*
|
||||
* The default quality is medium.
|
||||
*
|
||||
* @param qualityLevel The desired quality of the color grading process
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& quality(QualityLevel qualityLevel) noexcept;
|
||||
|
||||
/**
|
||||
* When color grading is implemented using a 3D LUT, this sets the texture format of
|
||||
* of the LUT. This overrides the value set by quality().
|
||||
*
|
||||
* The default is INTEGER
|
||||
*
|
||||
* @param format The desired format of the 3D LUT.
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& format(LutFormat format) noexcept;
|
||||
|
||||
/**
|
||||
* When color grading is implemented using a 3D LUT, this sets the dimension of the LUT.
|
||||
* This overrides the value set by quality().
|
||||
*
|
||||
* The default is 32
|
||||
*
|
||||
* @param dim The desired dimension of the LUT. Between 16 and 64.
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& dimensions(uint8_t dim) noexcept;
|
||||
|
||||
/**
|
||||
* Selects the tone mapping operator to apply to the HDR color buffer as the last
|
||||
* operation of the color grading post-processing step.
|
||||
*
|
||||
* The default tone mapping operator is ACESLegacyToneMapper.
|
||||
*
|
||||
* The specified tone mapper must have a lifecycle that exceeds the lifetime of
|
||||
* this builder. Since the build(Engine&) method is synchronous, it is safe to
|
||||
* delete the tone mapper object after that finishes executing.
|
||||
*
|
||||
* @param toneMapper The tone mapping operator to apply to the HDR color buffer
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& toneMapper(ToneMapper const* UTILS_NULLABLE toneMapper) noexcept;
|
||||
|
||||
/**
|
||||
* Selects the tone mapping operator to apply to the HDR color buffer as the last
|
||||
* operation of the color grading post-processing step.
|
||||
*
|
||||
* The default tone mapping operator is ACES_LEGACY.
|
||||
*
|
||||
* @param toneMapping The tone mapping operator to apply to the HDR color buffer
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*
|
||||
* @deprecated Use toneMapper(ToneMapper*) instead
|
||||
*/
|
||||
UTILS_DEPRECATED
|
||||
Builder& toneMapping(ToneMapping toneMapping) noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables the luminance scaling component (LICH) from the exposure value
|
||||
* invariant luminance system (EVILS). When this setting is enabled, pixels with high
|
||||
* chromatic values will roll-off to white to offer a more natural rendering. This step
|
||||
* also helps avoid undesirable hue skews caused by out of gamut colors clipped
|
||||
* to the destination color gamut.
|
||||
*
|
||||
* When luminance scaling is enabled, tone mapping is performed on the luminance of each
|
||||
* pixel instead of per-channel.
|
||||
*
|
||||
* @param luminanceScaling Enables or disables luminance scaling post-tone mapping
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& luminanceScaling(bool luminanceScaling) noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables gamut mapping to the destination color space's gamut. When gamut
|
||||
* mapping is turned off, out-of-gamut colors are clipped to the destination's gamut,
|
||||
* which may produce hue skews (blue skewing to purple, green to yellow, etc.). When
|
||||
* gamut mapping is enabled, out-of-gamut colors are brought back in gamut by trying to
|
||||
* preserve the perceived chroma and lightness of the original values.
|
||||
*
|
||||
* @param gamutMapping Enables or disables gamut mapping
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& gamutMapping(bool gamutMapping) noexcept;
|
||||
|
||||
/**
|
||||
* Adjusts the exposure of this image. The exposure is specified in stops:
|
||||
* each stop brightens (positive values) or darkens (negative values) the image by
|
||||
* a factor of 2. This means that an exposure of 3 will brighten the image 8 times
|
||||
* more than an exposure of 0 (2^3 = 8 and 2^0 = 1). Contrary to the camera's exposure,
|
||||
* this setting is applied after all post-processing (bloom, etc.) are applied.
|
||||
*
|
||||
* @param exposure Value in EV stops. Can be negative, 0, or positive.
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& exposure(float exposure) noexcept;
|
||||
|
||||
/**
|
||||
* Controls the amount of night adaptation to replicate a more natural representation of
|
||||
* low-light conditions as perceived by the human vision system. In low-light conditions,
|
||||
* peak luminance sensitivity of the eye shifts toward the blue end of the color spectrum:
|
||||
* darker tones appear brighter, reducing contrast, and colors are blue shifted (the darker
|
||||
* the more intense the effect).
|
||||
*
|
||||
* @param adaptation Amount of adaptation, between 0 (no adaptation) and 1 (full adaptation).
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& nightAdaptation(float adaptation) noexcept;
|
||||
|
||||
/**
|
||||
* Adjusts the while balance of the image. This can be used to remove color casts
|
||||
* and correct the appearance of the white point in the scene, or to alter the
|
||||
* overall chromaticity of the image for artistic reasons (to make the image appear
|
||||
* cooler or warmer for instance).
|
||||
*
|
||||
* The while balance adjustment is defined with two values:
|
||||
* - Temperature, to modify the color temperature. This value will modify the colors
|
||||
* on a blue/yellow axis. Lower values apply a cool color temperature, and higher
|
||||
* values apply a warm color temperature. The lowest value, -1.0f, is equivalent to
|
||||
* a temperature of 50,000K. The highest value, 1.0f, is equivalent to a temperature
|
||||
* of 2,000K.
|
||||
* - Tint, to modify the colors on a green/magenta axis. The lowest value, -1.0f, will
|
||||
* apply a strong green cast, and the highest value, 1.0f, will apply a strong magenta
|
||||
* cast.
|
||||
*
|
||||
* Both values are expected to be in the range [-1.0..+1.0]. Values outside of that
|
||||
* range will be clipped to that range.
|
||||
*
|
||||
* @param temperature Modification on the blue/yellow axis, as a value between -1.0 and +1.0.
|
||||
* @param tint Modification on the green/magenta axis, as a value between -1.0 and +1.0.
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& whiteBalance(float temperature, float tint) noexcept;
|
||||
|
||||
/**
|
||||
* The channel mixer adjustment modifies each output color channel using the specified
|
||||
* mix of the source color channels.
|
||||
*
|
||||
* By default each output color channel is set to use 100% of the corresponding source
|
||||
* channel and 0% of the other channels. For instance, the output red channel is set to
|
||||
* {1.0, 0.0, 1.0} or 100% red, 0% green and 0% blue.
|
||||
*
|
||||
* Each output channel can add or subtract data from the source channel by using values
|
||||
* in the range [-2.0..+2.0]. Values outside of that range will be clipped to that range.
|
||||
*
|
||||
* Using the channel mixer adjustment you can for instance create a monochrome output
|
||||
* by setting all 3 output channels to the same mix. For instance: {0.4, 0.4, 0.2} for
|
||||
* all 3 output channels(40% red, 40% green and 20% blue).
|
||||
*
|
||||
* More complex mixes can be used to create more complex effects. For instance, here is
|
||||
* a mix that creates a sepia tone effect:
|
||||
* - outRed = {0.255, 0.858, 0.087}
|
||||
* - outGreen = {0.213, 0.715, 0.072}
|
||||
* - outBlue = {0.170, 0.572, 0.058}
|
||||
*
|
||||
* @param outRed The mix of source RGB for the output red channel, between -2.0 and +2.0
|
||||
* @param outGreen The mix of source RGB for the output green channel, between -2.0 and +2.0
|
||||
* @param outBlue The mix of source RGB for the output blue channel, between -2.0 and +2.0
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& channelMixer(
|
||||
math::float3 outRed, math::float3 outGreen, math::float3 outBlue) noexcept;
|
||||
|
||||
/**
|
||||
* Adjusts the colors separately in 3 distinct tonal ranges or zones: shadows, mid-tones,
|
||||
* and highlights.
|
||||
*
|
||||
* The tonal zones are by the ranges parameter: the x and y components define the beginning
|
||||
* and end of the transition from shadows to mid-tones, and the z and w components define
|
||||
* the beginning and end of the transition from mid-tones to highlights.
|
||||
*
|
||||
* A smooth transition is applied between the zones which means for instance that the
|
||||
* correction color of the shadows range will partially apply to the mid-tones, and the
|
||||
* other way around. This ensure smooth visual transitions in the final image.
|
||||
*
|
||||
* Each correction color is defined as a linear RGB color and a weight. The weight is a
|
||||
* value (which may be positive or negative) that is added to the linear RGB color before
|
||||
* mixing. This can be used to darken or brighten the selected tonal range.
|
||||
*
|
||||
* Shadows/mid-tones/highlights adjustment are performed linear space.
|
||||
*
|
||||
* @param shadows Linear RGB color (.rgb) and weight (.w) to apply to the shadows
|
||||
* @param midtones Linear RGB color (.rgb) and weight (.w) to apply to the mid-tones
|
||||
* @param highlights Linear RGB color (.rgb) and weight (.w) to apply to the highlights
|
||||
* @param ranges Range of the shadows (x and y), and range of the highlights (z and w)
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& shadowsMidtonesHighlights(
|
||||
math::float4 shadows, math::float4 midtones, math::float4 highlights,
|
||||
math::float4 ranges) noexcept;
|
||||
|
||||
/**
|
||||
* Applies a slope, offset, and power, as defined by the ASC CDL (American Society of
|
||||
* Cinematographers Color Decision List) to the image. The CDL can be used to adjust the
|
||||
* colors of different tonal ranges in the image.
|
||||
*
|
||||
* The ASC CDL is similar to the lift/gamma/gain controls found in many color grading tools.
|
||||
* Lift is equivalent to a combination of offset and slope, gain is equivalent to slope,
|
||||
* and gamma is equivalent to power.
|
||||
*
|
||||
* The slope and power values must be strictly positive. Values less than or equal to 0 will
|
||||
* be clamped to a small positive value, offset can be any positive or negative value.
|
||||
*
|
||||
* Version 1.2 of the ASC CDL adds saturation control, which is here provided as a separate
|
||||
* API. See the saturation() method for more information.
|
||||
*
|
||||
* Slope/offset/power adjustments are performed in log space.
|
||||
*
|
||||
* @param slope Multiplier of the input color, must be a strictly positive number
|
||||
* @param offset Added to the input color, can be a negative or positive number, including 0
|
||||
* @param power Power exponent of the input color, must be a strictly positive number
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& slopeOffsetPower(math::float3 slope, math::float3 offset, math::float3 power) noexcept;
|
||||
|
||||
/**
|
||||
* Adjusts the contrast of the image. Lower values decrease the contrast of the image
|
||||
* (the tonal range is narrowed), and higher values increase the contrast of the image
|
||||
* (the tonal range is widened). A value of 1.0 has no effect.
|
||||
*
|
||||
* The contrast is defined as a value in the range [0.0...2.0]. Values outside of that
|
||||
* range will be clipped to that range.
|
||||
*
|
||||
* Contrast adjustment is performed in log space.
|
||||
*
|
||||
* @param contrast Contrast expansion, between 0.0 and 2.0. 1.0 leaves contrast unaffected
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& contrast(float contrast) noexcept;
|
||||
|
||||
/**
|
||||
* Adjusts the saturation of the image based on the input color's saturation level.
|
||||
* Colors with a high level of saturation are less affected than colors with low saturation
|
||||
* levels.
|
||||
*
|
||||
* Lower vibrance values decrease intensity of the colors present in the image, and
|
||||
* higher values increase the intensity of the colors in the image. A value of 1.0 has
|
||||
* no effect.
|
||||
*
|
||||
* The vibrance is defined as a value in the range [0.0...2.0]. Values outside of that
|
||||
* range will be clipped to that range.
|
||||
*
|
||||
* Vibrance adjustment is performed in linear space.
|
||||
*
|
||||
* @param vibrance Vibrance, between 0.0 and 2.0. 1.0 leaves vibrance unaffected
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& vibrance(float vibrance) noexcept;
|
||||
|
||||
/**
|
||||
* Adjusts the saturation of the image. Lower values decrease intensity of the colors
|
||||
* present in the image, and higher values increase the intensity of the colors in the
|
||||
* image. A value of 1.0 has no effect.
|
||||
*
|
||||
* The saturation is defined as a value in the range [0.0...2.0]. Values outside of that
|
||||
* range will be clipped to that range.
|
||||
*
|
||||
* Saturation adjustment is performed in linear space.
|
||||
*
|
||||
* @param saturation Saturation, between 0.0 and 2.0. 1.0 leaves saturation unaffected
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& saturation(float saturation) noexcept;
|
||||
|
||||
/**
|
||||
* Applies a curve to each RGB channel of the image. Each curve is defined by 3 values:
|
||||
* a gamma value applied to the shadows only, a mid-point indicating where shadows stop
|
||||
* and highlights start, and a scale factor for the highlights.
|
||||
*
|
||||
* The gamma and mid-point must be strictly positive values. If they are not, they will be
|
||||
* clamped to a small positive value. The scale can be any negative of positive value.
|
||||
*
|
||||
* Curves are applied in linear space.
|
||||
*
|
||||
* @param shadowGamma Power value to apply to the shadows, must be strictly positive
|
||||
* @param midPoint Mid-point defining where shadows stop and highlights start, must be strictly positive
|
||||
* @param highlightScale Scale factor for the highlights, can be any negative or positive value
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& curves(math::float3 shadowGamma, math::float3 midPoint, math::float3 highlightScale) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the output color space for this ColorGrading object. After all color grading steps
|
||||
* have been applied, the final color will be converted in the desired color space.
|
||||
*
|
||||
* NOTE: Currently the output color space must be one of Rec709-sRGB-D65 or
|
||||
* Rec709-Linear-D65. Only the transfer function is taken into account.
|
||||
*
|
||||
* @param colorSpace The output color space.
|
||||
*
|
||||
* @return This Builder, for chaining calls
|
||||
*/
|
||||
Builder& outputColorSpace(const color::ColorSpace& colorSpace) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the ColorGrading object and returns a pointer to it.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this ColorGrading with.
|
||||
*
|
||||
* @return pointer to the newly created object.
|
||||
*/
|
||||
ColorGrading* UTILS_NONNULL build(Engine& engine);
|
||||
|
||||
private:
|
||||
friend class FColorGrading;
|
||||
};
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~ColorGrading() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_COLORGRADING_H
|
||||
255
dart_filament/native/include/filament/filament/ColorSpace.h
Normal file
255
dart_filament/native/include/filament/filament/ColorSpace.h
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_COLOR_SPACE_H
|
||||
#define TNT_FILAMENT_COLOR_SPACE_H
|
||||
|
||||
#include <math/vec2.h>
|
||||
|
||||
namespace filament::color {
|
||||
|
||||
using namespace math;
|
||||
|
||||
/**
|
||||
* Holds the chromaticities of a color space's primaries as xy coordinates
|
||||
* in xyY (Y is assumed to be 1).
|
||||
*/
|
||||
struct Primaries {
|
||||
float2 r;
|
||||
float2 g;
|
||||
float2 b;
|
||||
|
||||
bool operator==(const Primaries& rhs) const noexcept {
|
||||
return r == rhs.r && b == rhs.b && g == rhs.g;
|
||||
}
|
||||
};
|
||||
|
||||
//! Reference white for a color space, defined as the xy coordinates in the xyY space.
|
||||
using WhitePoint = float2;
|
||||
|
||||
/**
|
||||
* <p>Defines the parameters for the ICC parametric curve type 4, as
|
||||
* defined in ICC.1:2004-10, section 10.15.</p>
|
||||
*
|
||||
* <p>The EOTF is of the form:</p>
|
||||
*
|
||||
* \(\begin{equation}
|
||||
* Y = \begin{cases}c X + f & X \lt d \\\
|
||||
* \left( a X + b \right) ^{g} + e & X \ge d \end{cases}
|
||||
* \end{equation}\)
|
||||
*
|
||||
* <p>The corresponding OETF is simply the inverse function.</p>
|
||||
*
|
||||
* <p>The parameters defined by this class form a valid transfer
|
||||
* function only if all the following conditions are met:</p>
|
||||
* <ul>
|
||||
* <li>No parameter is a NaN</li>
|
||||
* <li>\(d\) is in the range \([0..1]\)</li>
|
||||
* <li>The function is not constant</li>
|
||||
* <li>The function is positive and increasing</li>
|
||||
* </ul>
|
||||
*/
|
||||
struct TransferFunction {
|
||||
/**
|
||||
* <p>Defines the parameters for the ICC parametric curve type 3, as
|
||||
* defined in ICC.1:2004-10, section 10.15.</p>
|
||||
*
|
||||
* <p>The EOTF is of the form:</p>
|
||||
*
|
||||
* \(\begin{equation}
|
||||
* Y = \begin{cases}c X & X \lt d \\\
|
||||
* \left( a X + b \right) ^{g} & X \ge d \end{cases}
|
||||
* \end{equation}\)
|
||||
*
|
||||
* <p>This constructor is equivalent to setting \(e\) and \(f\) to 0.</p>
|
||||
*
|
||||
* @param a The value of \(a\) in the equation of the EOTF described above
|
||||
* @param b The value of \(b\) in the equation of the EOTF described above
|
||||
* @param c The value of \(c\) in the equation of the EOTF described above
|
||||
* @param d The value of \(d\) in the equation of the EOTF described above
|
||||
* @param g The value of \(g\) in the equation of the EOTF described above
|
||||
*/
|
||||
constexpr TransferFunction(
|
||||
double a,
|
||||
double b,
|
||||
double c,
|
||||
double d,
|
||||
double e,
|
||||
double f,
|
||||
double g
|
||||
) : a(a),
|
||||
b(b),
|
||||
c(c),
|
||||
d(d),
|
||||
e(e),
|
||||
f(f),
|
||||
g(g) {
|
||||
}
|
||||
|
||||
constexpr TransferFunction(
|
||||
double a,
|
||||
double b,
|
||||
double c,
|
||||
double d,
|
||||
double g
|
||||
) : TransferFunction(a, b, c, d, 0.0, 0.0, g) {
|
||||
}
|
||||
|
||||
bool operator==(const TransferFunction& rhs) const noexcept {
|
||||
return
|
||||
a == rhs.a &&
|
||||
b == rhs.b &&
|
||||
c == rhs.c &&
|
||||
d == rhs.d &&
|
||||
e == rhs.e &&
|
||||
f == rhs.f &&
|
||||
g == rhs.g;
|
||||
}
|
||||
|
||||
double a;
|
||||
double b;
|
||||
double c;
|
||||
double d;
|
||||
double e;
|
||||
double f;
|
||||
double g;
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>A color space in Filament is always an RGB color space. A specific RGB color space
|
||||
* is defined by the following properties:</p>
|
||||
* <ul>
|
||||
* <li>Three chromaticities of the red, green and blue primaries, which
|
||||
* define the gamut of the color space.</li>
|
||||
* <li>A white point chromaticity that defines the stimulus to which
|
||||
* color space values are normalized (also just called "white").</li>
|
||||
* <li>An opto-electronic transfer function, also called opto-electronic
|
||||
* conversion function or often, and approximately, gamma function.</li>
|
||||
* <li>An electro-optical transfer function, also called electo-optical
|
||||
* conversion function or often, and approximately, gamma function.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <h3>Primaries and white point chromaticities</h3>
|
||||
* <p>In this implementation, the chromaticity of the primaries and the white
|
||||
* point of an RGB color space is defined in the CIE xyY color space. This
|
||||
* color space separates the chromaticity of a color, the x and y components,
|
||||
* and its luminance, the Y component. Since the primaries and the white
|
||||
* point have full brightness, the Y component is assumed to be 1 and only
|
||||
* the x and y components are needed to encode them.</p>
|
||||
*
|
||||
* <h3>Transfer functions</h3>
|
||||
* <p>A transfer function is a color component conversion function, defined as
|
||||
* a single variable, monotonic mathematical function. It is applied to each
|
||||
* individual component of a color. They are used to perform the mapping
|
||||
* between linear tristimulus values and non-linear electronic signal value.</p>
|
||||
* <p>The <em>opto-electronic transfer function</em> (OETF or OECF) encodes
|
||||
* tristimulus values in a scene to a non-linear electronic signal value.</p>
|
||||
*/
|
||||
class ColorSpace {
|
||||
public:
|
||||
constexpr ColorSpace(
|
||||
const Primaries primaries,
|
||||
const TransferFunction transferFunction,
|
||||
const WhitePoint whitePoint
|
||||
) : mPrimaries(primaries),
|
||||
mTransferFunction(transferFunction),
|
||||
mWhitePoint(whitePoint) {
|
||||
}
|
||||
|
||||
bool operator==(const ColorSpace& rhs) const noexcept {
|
||||
return mPrimaries == rhs.mPrimaries &&
|
||||
mTransferFunction == rhs.mTransferFunction &&
|
||||
mWhitePoint == rhs.mWhitePoint;
|
||||
}
|
||||
|
||||
constexpr const Primaries& getPrimaries() const { return mPrimaries; }
|
||||
constexpr const TransferFunction& getTransferFunction() const { return mTransferFunction; }
|
||||
constexpr const WhitePoint& getWhitePoint() const { return mWhitePoint; }
|
||||
|
||||
private:
|
||||
Primaries mPrimaries;
|
||||
TransferFunction mTransferFunction;
|
||||
WhitePoint mWhitePoint;
|
||||
};
|
||||
|
||||
/**
|
||||
* Intermediate class used when building a color space using the "-" syntax:
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* // Declares a "linear sRGB" color space.
|
||||
* ColorSpace myColorSpace = Rec709-Linear-D65;
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
class PartialColorSpace {
|
||||
public:
|
||||
constexpr ColorSpace operator-(const WhitePoint& whitePoint) const {
|
||||
return { mPrimaries, mTransferFunction, whitePoint };
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr PartialColorSpace(
|
||||
const Primaries primaries,
|
||||
const TransferFunction transferFunction
|
||||
) : mPrimaries(primaries),
|
||||
mTransferFunction(transferFunction) {
|
||||
}
|
||||
|
||||
Primaries mPrimaries;
|
||||
TransferFunction mTransferFunction;
|
||||
|
||||
friend class Gamut;
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines the chromaticities of the primaries for a color space. The chromaticities
|
||||
* are expressed as three pairs of xy coordinates (in xyY) for the red, green, and blue
|
||||
* chromaticities.
|
||||
*/
|
||||
class Gamut {
|
||||
public:
|
||||
constexpr explicit Gamut(const Primaries primaries) : mPrimaries(primaries) {
|
||||
}
|
||||
|
||||
constexpr Gamut(float2 r, float2 g, float2 b) : Gamut(Primaries{ r, g, b }) {
|
||||
}
|
||||
|
||||
constexpr PartialColorSpace operator-(const TransferFunction& transferFunction) const {
|
||||
return { mPrimaries, transferFunction };
|
||||
}
|
||||
|
||||
constexpr const Primaries& getPrimaries() const { return mPrimaries; }
|
||||
|
||||
private:
|
||||
Primaries mPrimaries;
|
||||
};
|
||||
|
||||
//! Rec.709 color gamut, used in the sRGB and DisplayP3 color spaces.
|
||||
constexpr Gamut Rec709 = {{ 0.640f, 0.330f },
|
||||
{ 0.300f, 0.600f },
|
||||
{ 0.150f, 0.060f }};
|
||||
|
||||
//! Linear transfer function.
|
||||
constexpr TransferFunction Linear = { 1.0, 0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
//! sRGB transfer function.
|
||||
constexpr TransferFunction sRGB = { 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045, 2.4 };
|
||||
|
||||
//! Standard CIE 1931 2° illuminant D65. This illuminant has a color temperature of 6504K.
|
||||
constexpr WhitePoint D65 = { 0.31271f, 0.32902f };
|
||||
|
||||
} // namespace filament::color
|
||||
|
||||
#endif // TNT_FILAMENT_COLOR_SPACE_H
|
||||
141
dart_filament/native/include/filament/filament/DebugRegistry.h
Normal file
141
dart_filament/native/include/filament/filament/DebugRegistry.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_DEBUGREGISTRY_H
|
||||
#define TNT_FILAMENT_DEBUGREGISTRY_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* A registry of runtime properties used exclusively for debugging
|
||||
*
|
||||
* Filament exposes a few properties that can be queried and set, which control certain debugging
|
||||
* features of the engine. These properties can be set at runtime at anytime.
|
||||
*
|
||||
*/
|
||||
class UTILS_PUBLIC DebugRegistry : public FilamentAPI {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Queries whether a property exists
|
||||
* @param name The name of the property to query
|
||||
* @return true if the property exists, false otherwise
|
||||
*/
|
||||
bool hasProperty(const char* UTILS_NONNULL name) const noexcept;
|
||||
|
||||
/**
|
||||
* Queries the address of a property's data from its name
|
||||
* @param name Name of the property we want the data address of
|
||||
* @return Address of the data of the \p name property
|
||||
* @{
|
||||
*/
|
||||
void* UTILS_NULLABLE getPropertyAddress(const char* UTILS_NONNULL name);
|
||||
|
||||
void const* UTILS_NULLABLE getPropertyAddress(const char* UTILS_NONNULL name) const noexcept;
|
||||
|
||||
template<typename T>
|
||||
inline T* UTILS_NULLABLE getPropertyAddress(const char* UTILS_NONNULL name) {
|
||||
return static_cast<T*>(getPropertyAddress(name));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T const* UTILS_NULLABLE getPropertyAddress(const char* UTILS_NONNULL name) const noexcept {
|
||||
return static_cast<T*>(getPropertyAddress(name));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool getPropertyAddress(const char* UTILS_NONNULL name,
|
||||
T* UTILS_NULLABLE* UTILS_NONNULL p) {
|
||||
*p = getPropertyAddress<T>(name);
|
||||
return *p != nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool getPropertyAddress(const char* UTILS_NONNULL name,
|
||||
T* const UTILS_NULLABLE* UTILS_NONNULL p) const noexcept {
|
||||
*p = getPropertyAddress<T>(name);
|
||||
return *p != nullptr;
|
||||
}
|
||||
/** @}*/
|
||||
|
||||
/**
|
||||
* Set the value of a property
|
||||
* @param name Name of the property to set the value of
|
||||
* @param v Value to set
|
||||
* @return true if the operation was successful, false otherwise.
|
||||
* @{
|
||||
*/
|
||||
bool setProperty(const char* UTILS_NONNULL name, bool v) noexcept;
|
||||
bool setProperty(const char* UTILS_NONNULL name, int v) noexcept;
|
||||
bool setProperty(const char* UTILS_NONNULL name, float v) noexcept;
|
||||
bool setProperty(const char* UTILS_NONNULL name, math::float2 v) noexcept;
|
||||
bool setProperty(const char* UTILS_NONNULL name, math::float3 v) noexcept;
|
||||
bool setProperty(const char* UTILS_NONNULL name, math::float4 v) noexcept;
|
||||
/** @}*/
|
||||
|
||||
/**
|
||||
* Get the value of a property
|
||||
* @param name Name of the property to get the value of
|
||||
* @param v A pointer to a variable which will hold the result
|
||||
* @return true if the call was successful and \p v was updated
|
||||
* @{
|
||||
*/
|
||||
bool getProperty(const char* UTILS_NONNULL name, bool* UTILS_NONNULL v) const noexcept;
|
||||
bool getProperty(const char* UTILS_NONNULL name, int* UTILS_NONNULL v) const noexcept;
|
||||
bool getProperty(const char* UTILS_NONNULL name, float* UTILS_NONNULL v) const noexcept;
|
||||
bool getProperty(const char* UTILS_NONNULL name, math::float2* UTILS_NONNULL v) const noexcept;
|
||||
bool getProperty(const char* UTILS_NONNULL name, math::float3* UTILS_NONNULL v) const noexcept;
|
||||
bool getProperty(const char* UTILS_NONNULL name, math::float4* UTILS_NONNULL v) const noexcept;
|
||||
/** @}*/
|
||||
|
||||
struct DataSource {
|
||||
void const* UTILS_NULLABLE data;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
DataSource getDataSource(const char* UTILS_NONNULL name) const noexcept;
|
||||
|
||||
struct FrameHistory {
|
||||
using duration_ms = float;
|
||||
duration_ms target{};
|
||||
duration_ms targetWithHeadroom{};
|
||||
duration_ms frameTime{};
|
||||
duration_ms frameTimeDenoised{};
|
||||
float scale = 1.0f;
|
||||
float pid_e = 0.0f;
|
||||
float pid_i = 0.0f;
|
||||
float pid_d = 0.0f;
|
||||
};
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~DebugRegistry() = default;
|
||||
};
|
||||
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif /* TNT_FILAMENT_DEBUGREGISTRY_H */
|
||||
968
dart_filament/native/include/filament/filament/Engine.h
Normal file
968
dart_filament/native/include/filament/filament/Engine.h
Normal file
@@ -0,0 +1,968 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_ENGINE_H
|
||||
#define TNT_FILAMENT_ENGINE_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Platform.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace utils {
|
||||
class Entity;
|
||||
class EntityManager;
|
||||
class JobSystem;
|
||||
} // namespace utils
|
||||
|
||||
namespace filament {
|
||||
|
||||
class BufferObject;
|
||||
class Camera;
|
||||
class ColorGrading;
|
||||
class DebugRegistry;
|
||||
class Fence;
|
||||
class IndexBuffer;
|
||||
class SkinningBuffer;
|
||||
class IndirectLight;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class MorphTargetBuffer;
|
||||
class Renderer;
|
||||
class RenderTarget;
|
||||
class Scene;
|
||||
class Skybox;
|
||||
class Stream;
|
||||
class SwapChain;
|
||||
class Texture;
|
||||
class VertexBuffer;
|
||||
class View;
|
||||
class InstanceBuffer;
|
||||
|
||||
class LightManager;
|
||||
class RenderableManager;
|
||||
class TransformManager;
|
||||
|
||||
#ifndef FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB
|
||||
# define FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB 3
|
||||
#endif
|
||||
|
||||
#ifndef FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB
|
||||
# define FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB 2
|
||||
#endif
|
||||
|
||||
#ifndef FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB
|
||||
# define FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB 1
|
||||
#endif
|
||||
|
||||
#ifndef FILAMENT_COMMAND_BUFFER_SIZE_IN_MB
|
||||
# define FILAMENT_COMMAND_BUFFER_SIZE_IN_MB (FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB * 3)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Engine is filament's main entry-point.
|
||||
*
|
||||
* An Engine instance main function is to keep track of all resources created by the user and
|
||||
* manage the rendering thread as well as the hardware renderer.
|
||||
*
|
||||
* To use filament, an Engine instance must be created first:
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* #include <filament/Engine.h>
|
||||
* using namespace filament;
|
||||
*
|
||||
* Engine* engine = Engine::create();
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* Engine essentially represents (or is associated to) a hardware context
|
||||
* (e.g. an OpenGL ES context).
|
||||
*
|
||||
* Rendering typically happens in an operating system's window (which can be full screen), such
|
||||
* window is managed by a filament.Renderer.
|
||||
*
|
||||
* A typical filament render loop looks like this:
|
||||
*
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* #include <filament/Engine.h>
|
||||
* #include <filament/Renderer.h>
|
||||
* #include <filament/Scene.h>
|
||||
* #include <filament/View.h>
|
||||
* using namespace filament;
|
||||
*
|
||||
* Engine* engine = Engine::create();
|
||||
* SwapChain* swapChain = engine->createSwapChain(nativeWindow);
|
||||
* Renderer* renderer = engine->createRenderer();
|
||||
* Scene* scene = engine->createScene();
|
||||
* View* view = engine->createView();
|
||||
*
|
||||
* view->setScene(scene);
|
||||
*
|
||||
* do {
|
||||
* // typically we wait for VSYNC and user input events
|
||||
* if (renderer->beginFrame(swapChain)) {
|
||||
* renderer->render(view);
|
||||
* renderer->endFrame();
|
||||
* }
|
||||
* } while (!quit);
|
||||
*
|
||||
* engine->destroy(view);
|
||||
* engine->destroy(scene);
|
||||
* engine->destroy(renderer);
|
||||
* engine->destroy(swapChain);
|
||||
* Engine::destroy(&engine); // clears engine*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* Resource Tracking
|
||||
* =================
|
||||
*
|
||||
* Each Engine instance keeps track of all objects created by the user, such as vertex and index
|
||||
* buffers, lights, cameras, etc...
|
||||
* The user is expected to free those resources, however, leaked resources are freed when the
|
||||
* engine instance is destroyed and a warning is emitted in the console.
|
||||
*
|
||||
* Thread safety
|
||||
* =============
|
||||
*
|
||||
* An Engine instance is not thread-safe. The implementation makes no attempt to synchronize
|
||||
* calls to an Engine instance methods.
|
||||
* If multi-threading is needed, synchronization must be external.
|
||||
*
|
||||
* Multi-threading
|
||||
* ===============
|
||||
*
|
||||
* When created, the Engine instance starts a render thread as well as multiple worker threads,
|
||||
* these threads have an elevated priority appropriate for rendering, based on the platform's
|
||||
* best practices. The number of worker threads depends on the platform and is automatically
|
||||
* chosen for best performance.
|
||||
*
|
||||
* On platforms with asymmetric cores (e.g. ARM's Big.Little), Engine makes some educated guesses
|
||||
* as to which cores to use for the render thread and worker threads. For example, it'll try to
|
||||
* keep an OpenGL ES thread on a Big core.
|
||||
*
|
||||
* Swap Chains
|
||||
* ===========
|
||||
*
|
||||
* A swap chain represents an Operating System's *native* renderable surface. Typically it's a window
|
||||
* or a view. Because a SwapChain is initialized from a native object, it is given to filament
|
||||
* as a `void*`, which must be of the proper type for each platform filament is running on.
|
||||
*
|
||||
* @see SwapChain
|
||||
*
|
||||
*
|
||||
* @see Renderer
|
||||
*/
|
||||
class UTILS_PUBLIC Engine {
|
||||
struct BuilderDetails;
|
||||
public:
|
||||
using Platform = backend::Platform;
|
||||
using Backend = backend::Backend;
|
||||
using DriverConfig = backend::Platform::DriverConfig;
|
||||
using FeatureLevel = backend::FeatureLevel;
|
||||
using StereoscopicType = backend::StereoscopicType;
|
||||
|
||||
/**
|
||||
* Config is used to define the memory footprint used by the engine, such as the
|
||||
* command buffer size. Config can be used to customize engine requirements based
|
||||
* on the applications needs.
|
||||
*
|
||||
* .perRenderPassArenaSizeMB (default: 3 MiB)
|
||||
* +--------------------------+
|
||||
* | |
|
||||
* | .perFrameCommandsSizeMB |
|
||||
* | (default 2 MiB) |
|
||||
* | |
|
||||
* +--------------------------+
|
||||
* | (froxel, etc...) |
|
||||
* +--------------------------+
|
||||
*
|
||||
*
|
||||
* .commandBufferSizeMB (default 3MiB)
|
||||
* +--------------------------+
|
||||
* | .minCommandBufferSizeMB |
|
||||
* +--------------------------+
|
||||
* | .minCommandBufferSizeMB |
|
||||
* +--------------------------+
|
||||
* | .minCommandBufferSizeMB |
|
||||
* +--------------------------+
|
||||
* : :
|
||||
* : :
|
||||
*
|
||||
*/
|
||||
struct Config {
|
||||
/**
|
||||
* Size in MiB of the low-level command buffer arena.
|
||||
*
|
||||
* Each new command buffer is allocated from here. If this buffer is too small the program
|
||||
* might terminate or rendering errors might occur.
|
||||
*
|
||||
* This is typically set to minCommandBufferSizeMB * 3, so that up to 3 frames can be
|
||||
* batched-up at once.
|
||||
*
|
||||
* This value affects the application's memory usage.
|
||||
*/
|
||||
uint32_t commandBufferSizeMB = FILAMENT_COMMAND_BUFFER_SIZE_IN_MB;
|
||||
|
||||
|
||||
/**
|
||||
* Size in MiB of the per-frame data arena.
|
||||
*
|
||||
* This is the main arena used for allocations when preparing a frame.
|
||||
* e.g.: Froxel data and high-level commands are allocated from this arena.
|
||||
*
|
||||
* If this size is too small, the program will abort on debug builds and have undefined
|
||||
* behavior otherwise.
|
||||
*
|
||||
* This value affects the application's memory usage.
|
||||
*/
|
||||
uint32_t perRenderPassArenaSizeMB = FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB;
|
||||
|
||||
|
||||
/**
|
||||
* Size in MiB of the backend's handle arena.
|
||||
*
|
||||
* Backends will fallback to slower heap-based allocations when running out of space and
|
||||
* log this condition.
|
||||
*
|
||||
* If 0, then the default value for the given platform is used
|
||||
*
|
||||
* This value affects the application's memory usage.
|
||||
*/
|
||||
uint32_t driverHandleArenaSizeMB = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Minimum size in MiB of a low-level command buffer.
|
||||
*
|
||||
* This is how much space is guaranteed to be available for low-level commands when a new
|
||||
* buffer is allocated. If this is too small, the engine might have to stall to wait for
|
||||
* more space to become available, this situation is logged.
|
||||
*
|
||||
* This value does not affect the application's memory usage.
|
||||
*/
|
||||
uint32_t minCommandBufferSizeMB = FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB;
|
||||
|
||||
|
||||
/**
|
||||
* Size in MiB of the per-frame high level command buffer.
|
||||
*
|
||||
* This buffer is related to the number of draw calls achievable within a frame, if it is
|
||||
* too small, the program will abort on debug builds and have undefined behavior otherwise.
|
||||
*
|
||||
* It is allocated from the 'per-render-pass arena' above. Make sure that at least 1 MiB is
|
||||
* left in the per-render-pass arena when deciding the size of this buffer.
|
||||
*
|
||||
* This value does not affect the application's memory usage.
|
||||
*/
|
||||
uint32_t perFrameCommandsSizeMB = FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB;
|
||||
|
||||
/**
|
||||
* Number of threads to use in Engine's JobSystem.
|
||||
*
|
||||
* Engine uses a utils::JobSystem to carry out paralleization of Engine workloads. This
|
||||
* value sets the number of threads allocated for JobSystem. Configuring this value can be
|
||||
* helpful in CPU-constrained environments where too many threads can cause contention of
|
||||
* CPU and reduce performance.
|
||||
*
|
||||
* The default value is 0, which implies that the Engine will use a heuristic to determine
|
||||
* the number of threads to use.
|
||||
*/
|
||||
uint32_t jobSystemThreadCount = 0;
|
||||
|
||||
/*
|
||||
* Number of most-recently destroyed textures to track for use-after-free.
|
||||
*
|
||||
* This will cause the backend to throw an exception when a texture is freed but still bound
|
||||
* to a SamplerGroup and used in a draw call. 0 disables completely.
|
||||
*
|
||||
* Currently only respected by the Metal backend.
|
||||
*/
|
||||
size_t textureUseAfterFreePoolSize = 0;
|
||||
|
||||
/**
|
||||
* Set to `true` to forcibly disable parallel shader compilation in the backend.
|
||||
* Currently only honored by the GL and Metal backends.
|
||||
*/
|
||||
bool disableParallelShaderCompile = false;
|
||||
|
||||
/*
|
||||
* The type of technique for stereoscopic rendering.
|
||||
*
|
||||
* This setting determines the algorithm used when stereoscopic rendering is enabled. This
|
||||
* decision applies to the entire Engine for the lifetime of the Engine. E.g., multiple
|
||||
* Views created from the Engine must use the same stereoscopic type.
|
||||
*
|
||||
* Each view can enable stereoscopic rendering via the StereoscopicOptions::enable flag.
|
||||
*
|
||||
* @see View::setStereoscopicOptions
|
||||
*/
|
||||
StereoscopicType stereoscopicType = StereoscopicType::INSTANCED;
|
||||
|
||||
/*
|
||||
* The number of eyes to render when stereoscopic rendering is enabled. Supported values are
|
||||
* between 1 and Engine::getMaxStereoscopicEyes() (inclusive).
|
||||
*
|
||||
* @see View::setStereoscopicOptions
|
||||
* @see Engine::getMaxStereoscopicEyes
|
||||
*/
|
||||
uint8_t stereoscopicEyeCount = 2;
|
||||
|
||||
/*
|
||||
* @deprecated This value is no longer used.
|
||||
*/
|
||||
uint32_t resourceAllocatorCacheSizeMB = 64;
|
||||
|
||||
/*
|
||||
* This value determines for how many frames are texture entries kept in the cache.
|
||||
*/
|
||||
uint32_t resourceAllocatorCacheMaxAge = 2;
|
||||
|
||||
/*
|
||||
* Disable backend handles use-after-free checks.
|
||||
*/
|
||||
bool disableHandleUseAfterFreeCheck = false;
|
||||
};
|
||||
|
||||
|
||||
#if UTILS_HAS_THREADING
|
||||
using CreateCallback = void(void* UTILS_NULLABLE user, void* UTILS_NONNULL token);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Engine::Builder is used to create a new filament Engine.
|
||||
*/
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
friend class FEngine;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* @param backend Which driver backend to use
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& backend(Backend backend) noexcept;
|
||||
|
||||
/**
|
||||
* @param platform A pointer to an object that implements Platform. If this is
|
||||
* provided, then this object is used to create the hardware context
|
||||
* and expose platform features to it.
|
||||
*
|
||||
* If not provided (or nullptr is used), an appropriate Platform
|
||||
* is created automatically.
|
||||
*
|
||||
* All methods of this interface are called from filament's
|
||||
* render thread, which is different from the main thread.
|
||||
*
|
||||
* The lifetime of \p platform must exceed the lifetime of
|
||||
* the Engine object.
|
||||
*
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& platform(Platform* UTILS_NULLABLE platform) noexcept;
|
||||
|
||||
/**
|
||||
* @param config A pointer to optional parameters to specify memory size
|
||||
* configuration options. If nullptr, then defaults used.
|
||||
*
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& config(const Config* UTILS_NULLABLE config) noexcept;
|
||||
|
||||
/**
|
||||
* @param sharedContext A platform-dependant context used as a shared context
|
||||
* when creating filament's internal context.
|
||||
*
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& sharedContext(void* UTILS_NULLABLE sharedContext) noexcept;
|
||||
|
||||
/**
|
||||
* @param featureLevel The feature level at which initialize Filament.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& featureLevel(FeatureLevel featureLevel) noexcept;
|
||||
|
||||
/**
|
||||
* Warning: This is an experimental API. See Engine::setPaused(bool) for caveats.
|
||||
*
|
||||
* @param paused Whether to start the rendering thread paused.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& paused(bool paused) noexcept;
|
||||
|
||||
#if UTILS_HAS_THREADING
|
||||
/**
|
||||
* Creates the filament Engine asynchronously.
|
||||
*
|
||||
* @param callback Callback called once the engine is initialized and it is safe to
|
||||
* call Engine::getEngine().
|
||||
*/
|
||||
void build(utils::Invocable<void(void* UTILS_NONNULL token)>&& callback) const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates an instance of Engine.
|
||||
*
|
||||
* @return A pointer to the newly created Engine, or nullptr if the Engine couldn't be
|
||||
* created.
|
||||
* nullptr if the GPU driver couldn't be initialized, for instance if it doesn't
|
||||
* support the right version of OpenGL or OpenGL ES.
|
||||
*
|
||||
* @exception utils::PostConditionPanic can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer. If exceptions are disabled, this condition if
|
||||
* fatal and this function will abort.
|
||||
*/
|
||||
Engine* UTILS_NULLABLE build() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Backward compatibility helper to create an Engine.
|
||||
* @see Builder
|
||||
*/
|
||||
static inline Engine* UTILS_NULLABLE create(Backend backend = Backend::DEFAULT,
|
||||
Platform* UTILS_NULLABLE platform = nullptr,
|
||||
void* UTILS_NULLABLE sharedContext = nullptr,
|
||||
const Config* UTILS_NULLABLE config = nullptr) {
|
||||
return Engine::Builder()
|
||||
.backend(backend)
|
||||
.platform(platform)
|
||||
.sharedContext(sharedContext)
|
||||
.config(config)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
#if UTILS_HAS_THREADING
|
||||
/**
|
||||
* Backward compatibility helper to create an Engine asynchronously.
|
||||
* @see Builder
|
||||
*/
|
||||
static inline void createAsync(CreateCallback callback,
|
||||
void* UTILS_NULLABLE user,
|
||||
Backend backend = Backend::DEFAULT,
|
||||
Platform* UTILS_NULLABLE platform = nullptr,
|
||||
void* UTILS_NULLABLE sharedContext = nullptr,
|
||||
const Config* UTILS_NULLABLE config = nullptr) {
|
||||
Engine::Builder()
|
||||
.backend(backend)
|
||||
.platform(platform)
|
||||
.sharedContext(sharedContext)
|
||||
.config(config)
|
||||
.build([callback, user](void* UTILS_NONNULL token) {
|
||||
callback(user, token);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an Engine* from createAsync(). This must be called from the same thread than
|
||||
* Engine::createAsync() was called from.
|
||||
*
|
||||
* @param token An opaque token given in the createAsync() callback function.
|
||||
*
|
||||
* @return A pointer to the newly created Engine, or nullptr if the Engine couldn't be created.
|
||||
*
|
||||
* @exception utils::PostConditionPanic can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer. If exceptions are disabled, this condition if fatal and
|
||||
* this function will abort.
|
||||
*/
|
||||
static Engine* UTILS_NULLABLE getEngine(void* UTILS_NONNULL token);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Destroy the Engine instance and all associated resources.
|
||||
*
|
||||
* Engine.destroy() should be called last and after all other resources have been destroyed,
|
||||
* it ensures all filament resources are freed.
|
||||
*
|
||||
* Destroy performs the following tasks:
|
||||
* 1. Destroy all internal software and hardware resources.
|
||||
* 2. Free all user allocated resources that are not already destroyed and logs a warning.
|
||||
* This indicates a "leak" in the user's code.
|
||||
* 3. Terminate the rendering engine's thread.
|
||||
*
|
||||
* @param engine A pointer to the filament.Engine* to be destroyed.
|
||||
* \p engine is cleared upon return.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* #include <filament/Engine.h>
|
||||
* using namespace filament;
|
||||
*
|
||||
* Engine* engine = Engine::create();
|
||||
* Engine::destroy(&engine); // clears engine*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* \remark
|
||||
* This method is thread-safe.
|
||||
*/
|
||||
static void destroy(Engine* UTILS_NULLABLE* UTILS_NULLABLE engine);
|
||||
|
||||
/**
|
||||
* Destroy the Engine instance and all associated resources.
|
||||
*
|
||||
* Engine.destroy() should be called last and after all other resources have been destroyed,
|
||||
* it ensures all filament resources are freed.
|
||||
*
|
||||
* Destroy performs the following tasks:
|
||||
* 1. Destroy all internal software and hardware resources.
|
||||
* 2. Free all user allocated resources that are not already destroyed and logs a warning.
|
||||
* This indicates a "leak" in the user's code.
|
||||
* 3. Terminate the rendering engine's thread.
|
||||
*
|
||||
* @param engine A pointer to the filament.Engine to be destroyed.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* #include <filament/Engine.h>
|
||||
* using namespace filament;
|
||||
*
|
||||
* Engine* engine = Engine::create();
|
||||
* Engine::destroy(engine);
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* \remark
|
||||
* This method is thread-safe.
|
||||
*/
|
||||
static void destroy(Engine* UTILS_NULLABLE engine);
|
||||
|
||||
/**
|
||||
* Query the feature level supported by the selected backend.
|
||||
*
|
||||
* A specific feature level needs to be set before the corresponding features can be used.
|
||||
*
|
||||
* @return FeatureLevel supported the selected backend.
|
||||
* @see setActiveFeatureLevel
|
||||
*/
|
||||
FeatureLevel getSupportedFeatureLevel() const noexcept;
|
||||
|
||||
/**
|
||||
* Activate all features of a given feature level. If an explicit feature level is not specified
|
||||
* at Engine initialization time via Builder::featureLevel, the default feature level is
|
||||
* FeatureLevel::FEATURE_LEVEL_0 on devices not compatible with GLES 3.0; otherwise, the default
|
||||
* is FeatureLevel::FEATURE_LEVEL_1. The selected feature level must not be higher than the
|
||||
* value returned by getActiveFeatureLevel() and it's not possible lower the active feature
|
||||
* level. Additionally, it is not possible to modify the feature level at all if the Engine was
|
||||
* initialized at FeatureLevel::FEATURE_LEVEL_0.
|
||||
*
|
||||
* @param featureLevel the feature level to activate. If featureLevel is lower than
|
||||
* getActiveFeatureLevel(), the current (higher) feature level is kept. If
|
||||
* featureLevel is higher than getSupportedFeatureLevel(), or if the engine
|
||||
* was initialized at feature level 0, an exception is thrown, or the
|
||||
* program is terminated if exceptions are disabled.
|
||||
*
|
||||
* @return the active feature level.
|
||||
*
|
||||
* @see Builder::featureLevel
|
||||
* @see getSupportedFeatureLevel
|
||||
* @see getActiveFeatureLevel
|
||||
*/
|
||||
FeatureLevel setActiveFeatureLevel(FeatureLevel featureLevel);
|
||||
|
||||
/**
|
||||
* Returns the currently active feature level.
|
||||
* @return currently active feature level
|
||||
* @see getSupportedFeatureLevel
|
||||
* @see setActiveFeatureLevel
|
||||
*/
|
||||
FeatureLevel getActiveFeatureLevel() const noexcept;
|
||||
|
||||
/**
|
||||
* Queries the maximum number of GPU instances that Filament creates when automatic instancing
|
||||
* is enabled. This value is also the limit for the number of transforms that can be stored in
|
||||
* an InstanceBuffer. This value may depend on the device and platform, but will remain constant
|
||||
* during the lifetime of this Engine.
|
||||
*
|
||||
* This value does not apply when using the instances(size_t) method on
|
||||
* RenderableManager::Builder.
|
||||
*
|
||||
* @return the number of max automatic instances
|
||||
* @see setAutomaticInstancingEnabled
|
||||
* @see RenderableManager::Builder::instances(size_t)
|
||||
* @see RenderableManager::Builder::instances(size_t, InstanceBuffer*)
|
||||
*/
|
||||
size_t getMaxAutomaticInstances() const noexcept;
|
||||
|
||||
/**
|
||||
* Queries the device and platform for support of the given stereoscopic type.
|
||||
*
|
||||
* @return true if the given stereo rendering is supported, false otherwise
|
||||
* @see View::setStereoscopicOptions
|
||||
*/
|
||||
bool isStereoSupported(StereoscopicType stereoscopicType) const noexcept;
|
||||
|
||||
/**
|
||||
* Retrieves the configuration settings of this Engine.
|
||||
*
|
||||
* This method returns the configuration object that was supplied to the Engine's
|
||||
* Builder::config method during the creation of this Engine. If the Builder::config method was
|
||||
* not explicitly called (or called with nullptr), this method returns the default configuration
|
||||
* settings.
|
||||
*
|
||||
* @return a Config object with this Engine's configuration
|
||||
* @see Builder::config
|
||||
*/
|
||||
const Config& getConfig() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the maximum number of stereoscopic eyes supported by Filament. The actual number of
|
||||
* eyes rendered is set at Engine creation time with the Engine::Config::stereoscopicEyeCount
|
||||
* setting.
|
||||
*
|
||||
* @return the max number of stereoscopic eyes supported
|
||||
* @see Engine::Config::stereoscopicEyeCount
|
||||
*/
|
||||
static size_t getMaxStereoscopicEyes() noexcept;
|
||||
|
||||
/**
|
||||
* @return EntityManager used by filament
|
||||
*/
|
||||
utils::EntityManager& getEntityManager() noexcept;
|
||||
|
||||
/**
|
||||
* @return RenderableManager reference
|
||||
*/
|
||||
RenderableManager& getRenderableManager() noexcept;
|
||||
|
||||
/**
|
||||
* @return LightManager reference
|
||||
*/
|
||||
LightManager& getLightManager() noexcept;
|
||||
|
||||
/**
|
||||
* @return TransformManager reference
|
||||
*/
|
||||
TransformManager& getTransformManager() noexcept;
|
||||
|
||||
/**
|
||||
* Helper to enable accurate translations.
|
||||
* If you need this Engine to handle a very large world space, one way to achieve this
|
||||
* automatically is to enable accurate translations in the TransformManager. This helper
|
||||
* provides a convenient way of doing that.
|
||||
* This is typically called once just after creating the Engine.
|
||||
*/
|
||||
void enableAccurateTranslations() noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables automatic instancing of render primitives. Instancing of render
|
||||
* primitives can greatly reduce CPU overhead but requires the instanced primitives to be
|
||||
* identical (i.e. use the same geometry) and use the same MaterialInstance. If it is known
|
||||
* that the scene doesn't contain any identical primitives, automatic instancing can have some
|
||||
* overhead and it is then best to disable it.
|
||||
*
|
||||
* Disabled by default.
|
||||
*
|
||||
* @param enable true to enable, false to disable automatic instancing.
|
||||
*
|
||||
* @see RenderableManager
|
||||
* @see MaterialInstance
|
||||
*/
|
||||
void setAutomaticInstancingEnabled(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* @return true if automatic instancing is enabled, false otherwise.
|
||||
* @see setAutomaticInstancingEnabled
|
||||
*/
|
||||
bool isAutomaticInstancingEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Creates a SwapChain from the given Operating System's native window handle.
|
||||
*
|
||||
* @param nativeWindow An opaque native window handle. e.g.: on Android this is an
|
||||
* `ANativeWindow*`.
|
||||
* @param flags One or more configuration flags as defined in `SwapChain`.
|
||||
*
|
||||
* @return A pointer to the newly created SwapChain.
|
||||
*
|
||||
* @see Renderer.beginFrame()
|
||||
*/
|
||||
SwapChain* UTILS_NONNULL createSwapChain(void* UTILS_NULLABLE nativeWindow, uint64_t flags = 0) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a headless SwapChain.
|
||||
*
|
||||
* @param width Width of the drawing buffer in pixels.
|
||||
* @param height Height of the drawing buffer in pixels.
|
||||
* @param flags One or more configuration flags as defined in `SwapChain`.
|
||||
*
|
||||
* @return A pointer to the newly created SwapChain.
|
||||
*
|
||||
* @see Renderer.beginFrame()
|
||||
*/
|
||||
SwapChain* UTILS_NONNULL createSwapChain(uint32_t width, uint32_t height, uint64_t flags = 0) noexcept;
|
||||
|
||||
/**
|
||||
* Creates a renderer associated to this engine.
|
||||
*
|
||||
* A Renderer is intended to map to a *window* on screen.
|
||||
*
|
||||
* @return A pointer to the newly created Renderer.
|
||||
*/
|
||||
Renderer* UTILS_NONNULL createRenderer() noexcept;
|
||||
|
||||
/**
|
||||
* Creates a View.
|
||||
*
|
||||
* @return A pointer to the newly created View.
|
||||
*/
|
||||
View* UTILS_NONNULL createView() noexcept;
|
||||
|
||||
/**
|
||||
* Creates a Scene.
|
||||
*
|
||||
* @return A pointer to the newly created Scene.
|
||||
*/
|
||||
Scene* UTILS_NONNULL createScene() noexcept;
|
||||
|
||||
/**
|
||||
* Creates a Camera component.
|
||||
*
|
||||
* @param entity Entity to add the camera component to.
|
||||
* @return A pointer to the newly created Camera.
|
||||
*/
|
||||
Camera* UTILS_NONNULL createCamera(utils::Entity entity) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the Camera component of the given entity.
|
||||
*
|
||||
* @param entity An entity.
|
||||
* @return A pointer to the Camera component for this entity or nullptr if the entity didn't
|
||||
* have a Camera component. The pointer is valid until destroyCameraComponent()
|
||||
* is called or the entity itself is destroyed.
|
||||
*/
|
||||
Camera* UTILS_NULLABLE getCameraComponent(utils::Entity entity) noexcept;
|
||||
|
||||
/**
|
||||
* Destroys the Camera component associated with the given entity.
|
||||
*
|
||||
* @param entity An entity.
|
||||
*/
|
||||
void destroyCameraComponent(utils::Entity entity) noexcept;
|
||||
|
||||
/**
|
||||
* Creates a Fence.
|
||||
*
|
||||
* @return A pointer to the newly created Fence.
|
||||
*/
|
||||
Fence* UTILS_NONNULL createFence() noexcept;
|
||||
|
||||
bool destroy(const BufferObject* UTILS_NULLABLE p); //!< Destroys a BufferObject object.
|
||||
bool destroy(const VertexBuffer* UTILS_NULLABLE p); //!< Destroys an VertexBuffer object.
|
||||
bool destroy(const Fence* UTILS_NULLABLE p); //!< Destroys a Fence object.
|
||||
bool destroy(const IndexBuffer* UTILS_NULLABLE p); //!< Destroys an IndexBuffer object.
|
||||
bool destroy(const SkinningBuffer* UTILS_NULLABLE p); //!< Destroys a SkinningBuffer object.
|
||||
bool destroy(const MorphTargetBuffer* UTILS_NULLABLE p); //!< Destroys a MorphTargetBuffer object.
|
||||
bool destroy(const IndirectLight* UTILS_NULLABLE p); //!< Destroys an IndirectLight object.
|
||||
|
||||
/**
|
||||
* Destroys a Material object
|
||||
* @param p the material object to destroy
|
||||
* @attention All MaterialInstance of the specified material must be destroyed before
|
||||
* destroying it.
|
||||
* @exception utils::PreConditionPanic is thrown if some MaterialInstances remain.
|
||||
* no-op if exceptions are disabled and some MaterialInstances remain.
|
||||
*/
|
||||
bool destroy(const Material* UTILS_NULLABLE p);
|
||||
bool destroy(const MaterialInstance* UTILS_NULLABLE p); //!< Destroys a MaterialInstance object.
|
||||
bool destroy(const Renderer* UTILS_NULLABLE p); //!< Destroys a Renderer object.
|
||||
bool destroy(const Scene* UTILS_NULLABLE p); //!< Destroys a Scene object.
|
||||
bool destroy(const Skybox* UTILS_NULLABLE p); //!< Destroys a SkyBox object.
|
||||
bool destroy(const ColorGrading* UTILS_NULLABLE p); //!< Destroys a ColorGrading object.
|
||||
bool destroy(const SwapChain* UTILS_NULLABLE p); //!< Destroys a SwapChain object.
|
||||
bool destroy(const Stream* UTILS_NULLABLE p); //!< Destroys a Stream object.
|
||||
bool destroy(const Texture* UTILS_NULLABLE p); //!< Destroys a Texture object.
|
||||
bool destroy(const RenderTarget* UTILS_NULLABLE p); //!< Destroys a RenderTarget object.
|
||||
bool destroy(const View* UTILS_NULLABLE p); //!< Destroys a View object.
|
||||
bool destroy(const InstanceBuffer* UTILS_NULLABLE p); //!< Destroys an InstanceBuffer object.
|
||||
void destroy(utils::Entity e); //!< Destroys all filament-known components from this entity
|
||||
|
||||
bool isValid(const BufferObject* UTILS_NULLABLE p); //!< Tells whether a BufferObject object is valid
|
||||
bool isValid(const VertexBuffer* UTILS_NULLABLE p); //!< Tells whether an VertexBuffer object is valid
|
||||
bool isValid(const Fence* UTILS_NULLABLE p); //!< Tells whether a Fence object is valid
|
||||
bool isValid(const IndexBuffer* UTILS_NULLABLE p); //!< Tells whether an IndexBuffer object is valid
|
||||
bool isValid(const SkinningBuffer* UTILS_NULLABLE p); //!< Tells whether a SkinningBuffer object is valid
|
||||
bool isValid(const MorphTargetBuffer* UTILS_NULLABLE p); //!< Tells whether a MorphTargetBuffer object is valid
|
||||
bool isValid(const IndirectLight* UTILS_NULLABLE p); //!< Tells whether an IndirectLight object is valid
|
||||
bool isValid(const Material* UTILS_NULLABLE p); //!< Tells whether an IndirectLight object is valid
|
||||
bool isValid(const Renderer* UTILS_NULLABLE p); //!< Tells whether a Renderer object is valid
|
||||
bool isValid(const Scene* UTILS_NULLABLE p); //!< Tells whether a Scene object is valid
|
||||
bool isValid(const Skybox* UTILS_NULLABLE p); //!< Tells whether a SkyBox object is valid
|
||||
bool isValid(const ColorGrading* UTILS_NULLABLE p); //!< Tells whether a ColorGrading object is valid
|
||||
bool isValid(const SwapChain* UTILS_NULLABLE p); //!< Tells whether a SwapChain object is valid
|
||||
bool isValid(const Stream* UTILS_NULLABLE p); //!< Tells whether a Stream object is valid
|
||||
bool isValid(const Texture* UTILS_NULLABLE p); //!< Tells whether a Texture object is valid
|
||||
bool isValid(const RenderTarget* UTILS_NULLABLE p); //!< Tells whether a RenderTarget object is valid
|
||||
bool isValid(const View* UTILS_NULLABLE p); //!< Tells whether a View object is valid
|
||||
bool isValid(const InstanceBuffer* UTILS_NULLABLE p); //!< Tells whether an InstanceBuffer object is valid
|
||||
|
||||
/**
|
||||
* Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) and blocks until
|
||||
* all commands to this point are executed. Note that does guarantee that the
|
||||
* hardware is actually finished.
|
||||
*
|
||||
* <p>This is typically used right after destroying the <code>SwapChain</code>,
|
||||
* in cases where a guarantee about the <code>SwapChain</code> destruction is needed in a
|
||||
* timely fashion, such as when responding to Android's
|
||||
* <code>android.view.SurfaceHolder.Callback.surfaceDestroyed</code></p>
|
||||
*/
|
||||
void flushAndWait();
|
||||
|
||||
/**
|
||||
* Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) but does not wait
|
||||
* for commands to be either executed or the hardware finished.
|
||||
*
|
||||
* <p>This is typically used after creating a lot of objects to start draining the command
|
||||
* queue which has a limited size.</p>
|
||||
*/
|
||||
void flush();
|
||||
|
||||
/**
|
||||
* Pause or resume rendering thread.
|
||||
*
|
||||
* <p>Warning: This is an experimental API. In particular, note the following caveats.
|
||||
*
|
||||
* <ul><li>
|
||||
* Buffer callbacks will never be called as long as the rendering thread is paused.
|
||||
* Do not rely on a buffer callback to unpause the thread.
|
||||
* </li><li>
|
||||
* While the rendering thread is paused, rendering commands will continue to be queued until the
|
||||
* buffer limit is reached. When the limit is reached, the program will abort.
|
||||
* </li></ul>
|
||||
*/
|
||||
void setPaused(bool paused);
|
||||
|
||||
/**
|
||||
* Drains the user callback message queue and immediately execute all pending callbacks.
|
||||
*
|
||||
* <p> Typically this should be called once per frame right after the application's vsync tick,
|
||||
* and typically just before computing parameters (e.g. object positions) for the next frame.
|
||||
* This is useful because otherwise callbacks will be executed by filament at a later time,
|
||||
* which may increase latency in certain applications.</p>
|
||||
*/
|
||||
void pumpMessageQueues();
|
||||
|
||||
/**
|
||||
* Returns the default Material.
|
||||
*
|
||||
* The default material is 80% white and uses the Material.Shading.LIT shading.
|
||||
*
|
||||
* @return A pointer to the default Material instance (a singleton).
|
||||
*/
|
||||
Material const* UTILS_NONNULL getDefaultMaterial() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the resolved backend.
|
||||
*/
|
||||
Backend getBackend() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the Platform object that belongs to this Engine.
|
||||
*
|
||||
* When Engine::create is called with no platform argument, Filament creates an appropriate
|
||||
* Platform subclass automatically. The specific subclass created depends on the backend and
|
||||
* OS. For example, when the OpenGL backend is used, the Platform object will be a descendant of
|
||||
* OpenGLPlatform.
|
||||
*
|
||||
* dynamic_cast should be used to cast the returned Platform object into a specific subclass.
|
||||
* Note that RTTI must be available to use dynamic_cast.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Platform* platform = engine->getPlatform();
|
||||
* // static_cast also works, but more dangerous.
|
||||
* SpecificPlatform* specificPlatform = dynamic_cast<SpecificPlatform*>(platform);
|
||||
* specificPlatform->platformSpecificMethod();
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* When a custom Platform is passed to Engine::create, Filament will use it instead, and this
|
||||
* method will return it.
|
||||
*
|
||||
* @return A pointer to the Platform object that was provided to Engine::create, or the
|
||||
* Filament-created one.
|
||||
*/
|
||||
Platform* UTILS_NULLABLE getPlatform() const noexcept;
|
||||
|
||||
/**
|
||||
* Allocate a small amount of memory directly in the command stream. The allocated memory is
|
||||
* guaranteed to be preserved until the current command buffer is executed
|
||||
*
|
||||
* @param size size to allocate in bytes. This should be small (e.g. < 1 KB)
|
||||
* @param alignment alignment requested
|
||||
* @return a pointer to the allocated buffer or nullptr if no memory was available.
|
||||
*
|
||||
* @note there is no need to destroy this buffer, it will be freed automatically when
|
||||
* the current command buffer is executed.
|
||||
*/
|
||||
void* UTILS_NULLABLE streamAlloc(size_t size, size_t alignment = alignof(double)) noexcept;
|
||||
|
||||
/**
|
||||
* Invokes one iteration of the render loop, used only on single-threaded platforms.
|
||||
*
|
||||
* This should be called every time the windowing system needs to paint (e.g. at 60 Hz).
|
||||
*/
|
||||
void execute();
|
||||
|
||||
/**
|
||||
* Retrieves the job system that the Engine has ownership over.
|
||||
*
|
||||
* @return JobSystem used by filament
|
||||
*/
|
||||
utils::JobSystem& getJobSystem() noexcept;
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
/**
|
||||
* WebGL only: Tells the driver to reset any internal state tracking if necessary.
|
||||
*
|
||||
* This is only useful when integrating an external renderer into Filament on platforms
|
||||
* like WebGL, where share contexts do not exist. Filament keeps track of the GL
|
||||
* state it has set (like which texture is bound), and does not re-set that state if
|
||||
* it does not think it needs to. However, if an external renderer has set different
|
||||
* state in the mean time, Filament will use that new state unknowingly.
|
||||
*
|
||||
* If you are in this situation, call this function - ideally only once per frame,
|
||||
* immediately after calling Engine::execute().
|
||||
*/
|
||||
void resetBackendState() noexcept;
|
||||
#endif
|
||||
|
||||
DebugRegistry& getDebugRegistry() noexcept;
|
||||
|
||||
protected:
|
||||
//! \privatesection
|
||||
Engine() noexcept = default;
|
||||
~Engine() = default;
|
||||
|
||||
public:
|
||||
//! \privatesection
|
||||
Engine(Engine const&) = delete;
|
||||
Engine(Engine&&) = delete;
|
||||
Engine& operator=(Engine const&) = delete;
|
||||
Engine& operator=(Engine&&) = delete;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_ENGINE_H
|
||||
129
dart_filament/native/include/filament/filament/Exposure.h
Normal file
129
dart_filament/native/include/filament/filament/Exposure.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_EXPOSURE_H
|
||||
#define TNT_FILAMENT_EXPOSURE_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Camera;
|
||||
|
||||
/**
|
||||
* A series of utilities to compute exposure, exposure value at ISO 100 (EV100),
|
||||
* luminance and illuminance using a physically-based camera model.
|
||||
*/
|
||||
namespace Exposure {
|
||||
|
||||
/**
|
||||
* Returns the exposure value (EV at ISO 100) of the specified camera.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float ev100(const Camera& camera) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the exposure value (EV at ISO 100) of the specified exposure parameters.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float ev100(float aperture, float shutterSpeed, float sensitivity) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the exposure value (EV at ISO 100) for the given average luminance (in @f$ \frac{cd}{m^2} @f$).
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float ev100FromLuminance(float luminance) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the exposure value (EV at ISO 100) for the given illuminance (in lux).
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float ev100FromIlluminance(float illuminance) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the photometric exposure for the specified camera.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float exposure(const Camera& camera) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the photometric exposure for the specified exposure parameters.
|
||||
* This function is equivalent to calling `exposure(ev100(aperture, shutterSpeed, sensitivity))`
|
||||
* but is slightly faster and offers higher precision.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float exposure(float aperture, float shutterSpeed, float sensitivity) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the photometric exposure for the given EV100.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float exposure(float ev100) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the incident luminance in @f$ \frac{cd}{m^2} @f$ for the specified camera acting as a spot meter.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float luminance(const Camera& camera) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the incident luminance in @f$ \frac{cd}{m^2} @f$ for the specified exposure parameters of
|
||||
* a camera acting as a spot meter.
|
||||
* This function is equivalent to calling `luminance(ev100(aperture, shutterSpeed, sensitivity))`
|
||||
* but is slightly faster and offers higher precision.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float luminance(float aperture, float shutterSpeed, float sensitivity) noexcept;
|
||||
|
||||
/**
|
||||
* Converts the specified EV100 to luminance in @f$ \frac{cd}{m^2} @f$.
|
||||
* EV100 is not a measure of luminance, but an EV100 can be used to denote a
|
||||
* luminance for which a camera would use said EV100 to obtain the nominally
|
||||
* correct exposure
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float luminance(float ev100) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the illuminance in lux for the specified camera acting as an incident light meter.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float illuminance(const Camera& camera) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the illuminance in lux for the specified exposure parameters of
|
||||
* a camera acting as an incident light meter.
|
||||
* This function is equivalent to calling `illuminance(ev100(aperture, shutterSpeed, sensitivity))`
|
||||
* but is slightly faster and offers higher precision.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float illuminance(float aperture, float shutterSpeed, float sensitivity) noexcept;
|
||||
|
||||
/**
|
||||
* Converts the specified EV100 to illuminance in lux.
|
||||
* EV100 is not a measure of illuminance, but an EV100 can be used to denote an
|
||||
* illuminance for which a camera would use said EV100 to obtain the nominally
|
||||
* correct exposure.
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
float illuminance(float ev100) noexcept;
|
||||
|
||||
} // namespace exposure
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_EXPOSURE_H
|
||||
88
dart_filament/native/include/filament/filament/Fence.h
Normal file
88
dart_filament/native/include/filament/filament/Fence.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_FENCE_H
|
||||
#define TNT_FILAMENT_FENCE_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* Fence is used to synchronize the application main thread with filament's rendering thread.
|
||||
*/
|
||||
class UTILS_PUBLIC Fence : public FilamentAPI {
|
||||
public:
|
||||
//! Special \p timeout value to disable wait()'s timeout.
|
||||
static constexpr uint64_t FENCE_WAIT_FOR_EVER = backend::FENCE_WAIT_FOR_EVER;
|
||||
|
||||
//! Error codes for Fence::wait()
|
||||
using FenceStatus = backend::FenceStatus;
|
||||
|
||||
/** Mode controls the behavior of the command stream when calling wait()
|
||||
*
|
||||
* @attention
|
||||
* It would be unwise to call `wait(..., Mode::DONT_FLUSH)` from the same thread
|
||||
* the Fence was created, as it would most certainly create a dead-lock.
|
||||
*/
|
||||
enum class Mode : uint8_t {
|
||||
FLUSH, //!< The command stream is flushed
|
||||
DONT_FLUSH //!< The command stream is not flushed
|
||||
};
|
||||
|
||||
/**
|
||||
* Client-side wait on the Fence.
|
||||
*
|
||||
* Blocks the current thread until the Fence signals.
|
||||
*
|
||||
* @param mode Whether the command stream is flushed before waiting or not.
|
||||
* @param timeout Wait time out. Using a \p timeout of 0 is a way to query the state of the fence.
|
||||
* A \p timeout value of FENCE_WAIT_FOR_EVER is used to disable the timeout.
|
||||
* @return FenceStatus::CONDITION_SATISFIED on success,
|
||||
* FenceStatus::TIMEOUT_EXPIRED if the time out expired or
|
||||
* FenceStatus::ERROR in other cases.
|
||||
* @see #Mode
|
||||
*/
|
||||
FenceStatus wait(Mode mode = Mode::FLUSH, uint64_t timeout = FENCE_WAIT_FOR_EVER);
|
||||
|
||||
/**
|
||||
* Client-side wait on a Fence and destroy the Fence.
|
||||
*
|
||||
* @param fence Fence object to wait on.
|
||||
*
|
||||
* @param mode Whether the command stream is flushed before waiting or not.
|
||||
*
|
||||
* @return FenceStatus::CONDITION_SATISFIED on success,
|
||||
* FenceStatus::ERROR otherwise.
|
||||
*/
|
||||
static FenceStatus waitAndDestroy(Fence* UTILS_NONNULL fence, Mode mode = Mode::FLUSH);
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~Fence() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_FENCE_H
|
||||
59
dart_filament/native/include/filament/filament/FilamentAPI.h
Normal file
59
dart_filament/native/include/filament/filament/FilamentAPI.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_FILAMENTAPI_H
|
||||
#define TNT_FILAMENT_FILAMENTAPI_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/PrivateImplementation.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* \privatesection
|
||||
* FilamentAPI is used to define an API in filament.
|
||||
* It ensures the class defining the API can't be created, destroyed
|
||||
* or copied by the caller.
|
||||
*/
|
||||
class UTILS_PUBLIC FilamentAPI {
|
||||
protected:
|
||||
// disallow creation on the stack
|
||||
FilamentAPI() noexcept = default;
|
||||
~FilamentAPI() = default;
|
||||
|
||||
public:
|
||||
// disallow copy and assignment
|
||||
FilamentAPI(FilamentAPI const&) = delete;
|
||||
FilamentAPI(FilamentAPI&&) = delete;
|
||||
FilamentAPI& operator=(FilamentAPI const&) = delete;
|
||||
FilamentAPI& operator=(FilamentAPI&&) = delete;
|
||||
|
||||
// allow placement-new allocation, don't use "noexcept", to avoid compiler null check
|
||||
static void *operator new (size_t, void* p) { return p; }
|
||||
|
||||
// prevent heap allocation
|
||||
static void *operator new (size_t) = delete;
|
||||
static void *operator new[] (size_t) = delete;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using BuilderBase = utils::PrivateImplementation<T>;
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_FILAMENTAPI_H
|
||||
130
dart_filament/native/include/filament/filament/Frustum.h
Normal file
130
dart_filament/native/include/filament/filament/Frustum.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_FRUSTUM_H
|
||||
#define TNT_FILAMENT_FRUSTUM_H
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mat4.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include <utils/unwindows.h> // Because we define NEAR and FAR in the Plane enum.
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Box;
|
||||
class Culler;
|
||||
|
||||
/**
|
||||
* A frustum defined by six planes
|
||||
*/
|
||||
class UTILS_PUBLIC Frustum {
|
||||
public:
|
||||
enum class Plane : uint8_t {
|
||||
LEFT,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
TOP,
|
||||
FAR,
|
||||
NEAR
|
||||
};
|
||||
|
||||
Frustum() = default;
|
||||
Frustum(const Frustum& rhs) = default;
|
||||
Frustum(Frustum&& rhs) noexcept = default;
|
||||
Frustum& operator=(const Frustum& rhs) = default;
|
||||
Frustum& operator=(Frustum&& rhs) noexcept = default;
|
||||
|
||||
/**
|
||||
* Creates a frustum from a projection matrix in GL convention
|
||||
* (usually the projection * view matrix)
|
||||
* @param pv a 4x4 projection matrix in GL convention
|
||||
*/
|
||||
explicit Frustum(const math::mat4f& pv);
|
||||
|
||||
/**
|
||||
* Sets the frustum from the given projection matrix
|
||||
* @param pv a 4x4 projection matrix
|
||||
*/
|
||||
void setProjection(const math::mat4f& pv);
|
||||
|
||||
/**
|
||||
* Returns the plane equation parameters with normalized normals
|
||||
* @param plane Identifier of the plane to retrieve the equation of
|
||||
* @return A plane equation encoded a float4 R such as R.x*x + R.y*y + R.z*z + R.w = 0
|
||||
*/
|
||||
math::float4 getNormalizedPlane(Plane plane) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns a copy of all six frustum planes in left, right, bottom, top, far, near order
|
||||
* @param planes six plane equations encoded as in getNormalizedPlane() in
|
||||
* left, right, bottom, top, far, near order
|
||||
*/
|
||||
void getNormalizedPlanes(math::float4 planes[UTILS_NONNULL 6]) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns all six frustum planes in left, right, bottom, top, far, near order
|
||||
* @return six plane equations encoded as in getNormalizedPlane() in
|
||||
* left, right, bottom, top, far, near order
|
||||
*/
|
||||
math::float4 const* UTILS_NONNULL getNormalizedPlanes() const noexcept { return mPlanes; }
|
||||
|
||||
/**
|
||||
* Returns whether a box intersects the frustum (i.e. is visible)
|
||||
* @param box The box to test against the frustum
|
||||
* @return true if the box may intersects the frustum, false otherwise. In some situations
|
||||
* a box that doesn't intersect the frustum might be reported as though it does. However,
|
||||
* a box that does intersect the frustum is always reported correctly (true).
|
||||
*/
|
||||
bool intersects(const Box& box) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether a sphere intersects the frustum (i.e. is visible)
|
||||
* @param sphere A sphere encoded as a center + radius.
|
||||
* @return true if the sphere may intersects the frustum, false otherwise. In some situations
|
||||
* a sphere that doesn't intersect the frustum might be reported as though it does. However,
|
||||
* a sphere that does intersect the frustum is always reported correctly (true).
|
||||
*/
|
||||
bool intersects(const math::float4& sphere) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether the frustum contains a given point.
|
||||
* @param p the point to test
|
||||
* @return the maximum signed distance to the frustum. Negative if p is inside.
|
||||
*/
|
||||
float contains(math::float3 p) const noexcept;
|
||||
|
||||
private:
|
||||
friend class Culler;
|
||||
math::float4 mPlanes[6];
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
namespace utils::io {
|
||||
class ostream;
|
||||
} // namespace utils::io
|
||||
utils::io::ostream& operator<<(utils::io::ostream& out, filament::Frustum const& frustum);
|
||||
#endif
|
||||
|
||||
#endif // TNT_FILAMENT_FRUSTUM_H
|
||||
129
dart_filament/native/include/filament/filament/IndexBuffer.h
Normal file
129
dart_filament/native/include/filament/filament/IndexBuffer.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_INDEXBUFFER_H
|
||||
#define TNT_FILAMENT_INDEXBUFFER_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <backend/BufferDescriptor.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class FIndexBuffer;
|
||||
|
||||
class Engine;
|
||||
|
||||
/**
|
||||
* A buffer containing vertex indices into a VertexBuffer. Indices can be 16 or 32 bit.
|
||||
* The buffer itself is a GPU resource, therefore mutating the data can be relatively slow.
|
||||
* Typically these buffers are constant.
|
||||
*
|
||||
* It is possible, and even encouraged, to use a single index buffer for several Renderables.
|
||||
*
|
||||
* @see VertexBuffer, RenderableManager
|
||||
*/
|
||||
class UTILS_PUBLIC IndexBuffer : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
using BufferDescriptor = backend::BufferDescriptor;
|
||||
|
||||
/**
|
||||
* Type of the index buffer
|
||||
*/
|
||||
enum class IndexType : uint8_t {
|
||||
USHORT = uint8_t(backend::ElementType::USHORT), //!< 16-bit indices
|
||||
UINT = uint8_t(backend::ElementType::UINT), //!< 32-bit indices
|
||||
};
|
||||
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Size of the index buffer in elements.
|
||||
* @param indexCount Number of indices the IndexBuffer can hold.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& indexCount(uint32_t indexCount) noexcept;
|
||||
|
||||
/**
|
||||
* Type of the index buffer, 16-bit or 32-bit.
|
||||
* @param indexType Type of indices stored in the IndexBuffer.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& bufferType(IndexType indexType) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the IndexBuffer object and returns a pointer to it. After creation, the index
|
||||
* buffer is uninitialized. Use IndexBuffer::setBuffer() to initialize the IndexBuffer.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this IndexBuffer with.
|
||||
*
|
||||
* @return pointer to the newly created object.
|
||||
*
|
||||
* @exception utils::PostConditionPanic if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
|
||||
*
|
||||
* @see IndexBuffer::setBuffer
|
||||
*/
|
||||
IndexBuffer* UTILS_NONNULL build(Engine& engine);
|
||||
private:
|
||||
friend class FIndexBuffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronously copy-initializes a region of this IndexBuffer from the data provided.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this IndexBuffer with.
|
||||
* @param buffer A BufferDescriptor representing the data used to initialize the IndexBuffer.
|
||||
* BufferDescriptor points to raw, untyped data that will be interpreted as
|
||||
* either 16-bit or 32-bits indices based on the Type of this IndexBuffer.
|
||||
* @param byteOffset Offset in *bytes* into the IndexBuffer
|
||||
*/
|
||||
void setBuffer(Engine& engine, BufferDescriptor&& buffer, uint32_t byteOffset = 0);
|
||||
|
||||
/**
|
||||
* Returns the size of this IndexBuffer in elements.
|
||||
* @return The number of indices the IndexBuffer holds.
|
||||
*/
|
||||
size_t getIndexCount() const noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~IndexBuffer() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_INDEXBUFFER_H
|
||||
356
dart_filament/native/include/filament/filament/IndirectLight.h
Normal file
356
dart_filament/native/include/filament/filament/IndirectLight.h
Normal file
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_INDIRECTLIGHT_H
|
||||
#define TNT_FILAMENT_INDIRECTLIGHT_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Engine;
|
||||
class Texture;
|
||||
|
||||
class FIndirectLight;
|
||||
|
||||
/**
|
||||
* IndirectLight is used to simulate environment lighting, a form of global illumination.
|
||||
*
|
||||
* Environment lighting has a two components:
|
||||
* 1. irradiance
|
||||
* 2. reflections (specular component)
|
||||
*
|
||||
* Environments are usually captured as high-resolution HDR equirectangular images and processed
|
||||
* by the **cmgen** tool to generate the data needed by IndirectLight.
|
||||
*
|
||||
* @note
|
||||
* Currently IndirectLight is intended to be used for "distant probes", that is, to represent
|
||||
* global illumination from a distant (i.e. at infinity) environment, such as the sky or distant
|
||||
* mountains. Only a single IndirectLight can be used in a Scene. This limitation will be lifted
|
||||
* in the future.
|
||||
*
|
||||
* Creation and destruction
|
||||
* ========================
|
||||
*
|
||||
* An IndirectLight object is created using the IndirectLight::Builder and destroyed by calling
|
||||
* Engine::destroy(const IndirectLight*).
|
||||
*
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* filament::Engine* engine = filament::Engine::create();
|
||||
*
|
||||
* filament::IndirectLight* environment = filament::IndirectLight::Builder()
|
||||
* .reflections(cubemap)
|
||||
* .build(*engine);
|
||||
*
|
||||
* engine->destroy(environment);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
*
|
||||
* Irradiance
|
||||
* ==========
|
||||
*
|
||||
* The irradiance represents the light that comes from the environment and shines an
|
||||
* object's surface.
|
||||
*
|
||||
* The irradiance is calculated automatically from the Reflections (see below), and generally
|
||||
* doesn't need to be provided explicitly. However, it can be provided separately from the
|
||||
* Reflections as
|
||||
* [spherical harmonics](https://en.wikipedia.org/wiki/Spherical_harmonics) (SH) of 1, 2 or
|
||||
* 3 bands, respectively 1, 4 or 9 coefficients.
|
||||
*
|
||||
* @note
|
||||
* Use the **cmgen** tool to generate the `SH` for a given environment.
|
||||
*
|
||||
* Reflections
|
||||
* ===========
|
||||
*
|
||||
* The reflections on object surfaces (specular component) is calculated from a specially
|
||||
* filtered cubemap pyramid generated by the **cmgen** tool.
|
||||
*
|
||||
*
|
||||
* @see Scene, Light, Texture, Skybox
|
||||
*/
|
||||
class UTILS_PUBLIC IndirectLight : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
|
||||
//! Use Builder to construct an IndirectLight object instance
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Set the reflections cubemap mipmap chain.
|
||||
*
|
||||
* @param cubemap A mip-mapped cubemap generated by **cmgen**. Each cubemap level
|
||||
* encodes a the irradiance for a roughness level.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
*/
|
||||
Builder& reflections(Texture const* UTILS_NULLABLE cubemap) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the irradiance as Spherical Harmonics.
|
||||
*
|
||||
* The irradiance must be pre-convolved by \f$ \langle n \cdot l \rangle \f$ and
|
||||
* pre-multiplied by the Lambertian diffuse BRDF \f$ \frac{1}{\pi} \f$ and
|
||||
* specified as Spherical Harmonics coefficients.
|
||||
*
|
||||
* Additionally, these Spherical Harmonics coefficients must be pre-scaled by the
|
||||
* reconstruction factors \f$ A_{l}^{m} \f$ below.
|
||||
*
|
||||
* The final coefficients can be generated using the `cmgen` tool.
|
||||
*
|
||||
* The index in the \p sh array is given by:
|
||||
*
|
||||
* `index(l, m) = l * (l + 1) + m`
|
||||
*
|
||||
* \f$ sh[index(l,m)] = L_{l}^{m} \frac{1}{\pi} A_{l}^{m} \hat{C_{l}} \f$
|
||||
*
|
||||
* index | l | m | \f$ A_{l}^{m} \f$ | \f$ \hat{C_{l}} \f$ | \f$ \frac{1}{\pi} A_{l}^{m}\hat{C_{l}} \f$ |
|
||||
* :-----:|:---:|:---:|:------------------:|:---------------------:|:--------------------------------------------:
|
||||
* 0 | 0 | 0 | 0.282095 | 3.1415926 | 0.282095
|
||||
* 1 | 1 | -1 | -0.488602 | 2.0943951 | -0.325735
|
||||
* 2 | ^ | 0 | 0.488602 | ^ | 0.325735
|
||||
* 3 | ^ | 1 | -0.488602 | ^ | -0.325735
|
||||
* 4 | 2 | -2 | 1.092548 | 0.785398 | 0.273137
|
||||
* 5 | ^ | -1 | -1.092548 | ^ | -0.273137
|
||||
* 6 | ^ | 0 | 0.315392 | ^ | 0.078848
|
||||
* 7 | ^ | 1 | -1.092548 | ^ | -0.273137
|
||||
* 8 | ^ | 2 | 0.546274 | ^ | 0.136569
|
||||
*
|
||||
*
|
||||
* Only 1, 2 or 3 bands are allowed.
|
||||
*
|
||||
* @param bands Number of spherical harmonics bands. Must be 1, 2 or 3.
|
||||
* @param sh Array containing the spherical harmonics coefficients.
|
||||
* The size of the array must be \f$ bands^{2} \f$.
|
||||
* (i.e. 1, 4 or 9 coefficients respectively).
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* Because the coefficients are pre-scaled, `sh[0]` is the environment's
|
||||
* average irradiance.
|
||||
*/
|
||||
Builder& irradiance(uint8_t bands, math::float3 const* UTILS_NONNULL sh) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the irradiance from the radiance expressed as Spherical Harmonics.
|
||||
*
|
||||
* The radiance must be specified as Spherical Harmonics coefficients \f$ L_{l}^{m} \f$
|
||||
*
|
||||
* The index in the \p sh array is given by:
|
||||
*
|
||||
* `index(l, m) = l * (l + 1) + m`
|
||||
*
|
||||
* \f$ sh[index(l,m)] = L_{l}^{m} \f$
|
||||
*
|
||||
* index | l | m
|
||||
* :-----:|:---:|:---:
|
||||
* 0 | 0 | 0
|
||||
* 1 | 1 | -1
|
||||
* 2 | ^ | 0
|
||||
* 3 | ^ | 1
|
||||
* 4 | 2 | -2
|
||||
* 5 | ^ | -1
|
||||
* 6 | ^ | 0
|
||||
* 7 | ^ | 1
|
||||
* 8 | ^ | 2
|
||||
*
|
||||
* @param bands Number of spherical harmonics bands. Must be 1, 2 or 3.
|
||||
* @param sh Array containing the spherical harmonics coefficients.
|
||||
* The size of the array must be \f$ bands^{2} \f$.
|
||||
* (i.e. 1, 4 or 9 coefficients respectively).
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& radiance(uint8_t bands, math::float3 const* UTILS_NONNULL sh) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the irradiance as a cubemap.
|
||||
*
|
||||
* The irradiance can alternatively be specified as a cubemap instead of Spherical
|
||||
* Harmonics coefficients. It may or may not be more efficient, depending on your
|
||||
* hardware (essentially, it's trading ALU for bandwidth).
|
||||
*
|
||||
* @param cubemap Cubemap representing the Irradiance pre-convolved by
|
||||
* \f$ \langle n \cdot l \rangle \f$.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* This irradiance cubemap can be generated with the **cmgen** tool.
|
||||
*
|
||||
* @see irradiance(uint8_t bands, math::float3 const* sh)
|
||||
*/
|
||||
Builder& irradiance(Texture const* UTILS_NULLABLE cubemap) noexcept;
|
||||
|
||||
/**
|
||||
* (optional) Environment intensity.
|
||||
*
|
||||
* Because the environment is encoded usually relative to some reference, the
|
||||
* range can be adjusted with this method.
|
||||
*
|
||||
* @param envIntensity Scale factor applied to the environment and irradiance such that
|
||||
* the result is in lux, or lumen/m^2 (default = 30000)
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& intensity(float envIntensity) noexcept;
|
||||
|
||||
/**
|
||||
* Specifies the rigid-body transformation to apply to the IBL.
|
||||
*
|
||||
* @param rotation 3x3 rotation matrix. Must be a rigid-body transform.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& rotation(math::mat3f const& rotation) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the IndirectLight object and returns a pointer to it.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this IndirectLight with.
|
||||
*
|
||||
* @return pointer to the newly created object or nullptr if exceptions are disabled and
|
||||
* an error occurred.
|
||||
*
|
||||
* @exception utils::PostConditionPanic if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
|
||||
*/
|
||||
IndirectLight* UTILS_NONNULL build(Engine& engine);
|
||||
|
||||
private:
|
||||
friend class FIndirectLight;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the environment's intensity.
|
||||
*
|
||||
* Because the environment is encoded usually relative to some reference, the
|
||||
* range can be adjusted with this method.
|
||||
*
|
||||
* @param intensity Scale factor applied to the environment and irradiance such that
|
||||
* the result is in lux, or <i>lumen/m^2</i> (default = 30000)
|
||||
*/
|
||||
void setIntensity(float intensity) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the environment's intensity in <i>lux</i>, or <i>lumen/m^2</i>.
|
||||
*/
|
||||
float getIntensity() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the rigid-body transformation to apply to the IBL.
|
||||
*
|
||||
* @param rotation 3x3 rotation matrix. Must be a rigid-body transform.
|
||||
*/
|
||||
void setRotation(math::mat3f const& rotation) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the rigid-body transformation applied to the IBL.
|
||||
*/
|
||||
const math::mat3f& getRotation() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the associated reflection map, or null if it does not exist.
|
||||
*/
|
||||
Texture const* UTILS_NULLABLE getReflectionsTexture() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the associated irradiance map, or null if it does not exist.
|
||||
*/
|
||||
Texture const* UTILS_NULLABLE getIrradianceTexture() const noexcept;
|
||||
|
||||
/**
|
||||
* Helper to estimate the direction of the dominant light in the environment represented by
|
||||
* spherical harmonics.
|
||||
*
|
||||
* This assumes that there is only a single dominant light (such as the sun in outdoors
|
||||
* environments), if it's not the case the direction returned will be an average of the
|
||||
* various lights based on their intensity.
|
||||
*
|
||||
* If there are no clear dominant light, as is often the case with low dynamic range (LDR)
|
||||
* environments, this method may return a wrong or unexpected direction.
|
||||
*
|
||||
* The dominant light direction can be used to set a directional light's direction,
|
||||
* for instance to produce shadows that match the environment.
|
||||
*
|
||||
* @param sh 3-band spherical harmonics
|
||||
*
|
||||
* @return A unit vector representing the direction of the dominant light
|
||||
*
|
||||
* @see LightManager::Builder::direction()
|
||||
* @see getColorEstimate()
|
||||
*/
|
||||
static math::float3 getDirectionEstimate(const math::float3 sh[UTILS_NONNULL 9]) noexcept;
|
||||
|
||||
/**
|
||||
* Helper to estimate the color and relative intensity of the environment represented by
|
||||
* spherical harmonics in a given direction.
|
||||
*
|
||||
* This can be used to set the color and intensity of a directional light. In this case
|
||||
* make sure to multiply this relative intensity by the the intensity of this indirect light.
|
||||
*
|
||||
* @param sh 3-band spherical harmonics
|
||||
* @param direction a unit vector representing the direction of the light to estimate the
|
||||
* color of. Typically this the value returned by getDirectionEstimate().
|
||||
*
|
||||
* @return A vector of 4 floats where the first 3 components represent the linear color and
|
||||
* the 4th component represents the intensity of the dominant light
|
||||
*
|
||||
* @see LightManager::Builder::color()
|
||||
* @see LightManager::Builder::intensity()
|
||||
* @see getDirectionEstimate, getIntensity, setIntensity
|
||||
*/
|
||||
static math::float4 getColorEstimate(const math::float3 sh[UTILS_NONNULL 9],
|
||||
math::float3 direction) noexcept;
|
||||
|
||||
|
||||
/** @deprecated use static versions instead */
|
||||
UTILS_DEPRECATED
|
||||
math::float3 getDirectionEstimate() const noexcept;
|
||||
|
||||
/** @deprecated use static versions instead */
|
||||
UTILS_DEPRECATED
|
||||
math::float4 getColorEstimate(math::float3 direction) const noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~IndirectLight() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_INDIRECTLIGHT_H
|
||||
106
dart_filament/native/include/filament/filament/InstanceBuffer.h
Normal file
106
dart_filament/native/include/filament/filament/InstanceBuffer.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_INSTANCEBUFFER_H
|
||||
#define TNT_FILAMENT_INSTANCEBUFFER_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
#include <filament/Engine.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* InstanceBuffer holds draw (GPU) instance transforms. These can be provided to a renderable to
|
||||
* "offset" each draw instance.
|
||||
*
|
||||
* @see RenderableManager::Builder::instances(size_t, InstanceBuffer*)
|
||||
*/
|
||||
class UTILS_PUBLIC InstanceBuffer : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @param instanceCount the number of instances this InstanceBuffer will support, must be
|
||||
* >= 1 and <= \c Engine::getMaxAutomaticInstances()
|
||||
* @see Engine::getMaxAutomaticInstances
|
||||
*/
|
||||
explicit Builder(size_t instanceCount) noexcept;
|
||||
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Provide an initial local transform for each instance. Each local transform is relative to
|
||||
* the transform of the associated renderable. This forms a parent-child relationship
|
||||
* between the renderable and its instances, so adjusting the renderable's transform will
|
||||
- * affect all instances.
|
||||
*
|
||||
* The array of math::mat4f must have length instanceCount, provided when constructing this
|
||||
* Builder.
|
||||
*
|
||||
* @param localTransforms an array of math::mat4f with length instanceCount, must remain
|
||||
* valid until after build() is called
|
||||
*/
|
||||
Builder& localTransforms(math::mat4f const* UTILS_NULLABLE localTransforms) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the InstanceBuffer object and returns a pointer to it.
|
||||
*/
|
||||
InstanceBuffer* UTILS_NONNULL build(Engine& engine);
|
||||
|
||||
private:
|
||||
friend class FInstanceBuffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the instance count specified when building this InstanceBuffer.
|
||||
*/
|
||||
size_t getInstanceCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the local transform for each instance. Each local transform is relative to the transform
|
||||
* of the associated renderable. This forms a parent-child relationship between the renderable
|
||||
* and its instances, so adjusting the renderable's transform will affect all instances.
|
||||
*
|
||||
* @param localTransforms an array of math::mat4f with length count, need not outlive this call
|
||||
* @param count the number of local transforms
|
||||
* @param offset index of the first instance to set local transforms
|
||||
*/
|
||||
void setLocalTransforms(math::mat4f const* UTILS_NONNULL localTransforms,
|
||||
size_t count, size_t offset = 0);
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~InstanceBuffer() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif //TNT_FILAMENT_INSTANCEBUFFER_H
|
||||
977
dart_filament/native/include/filament/filament/LightManager.h
Normal file
977
dart_filament/native/include/filament/filament/LightManager.h
Normal file
@@ -0,0 +1,977 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_LIGHTMANAGER_H
|
||||
#define TNT_FILAMENT_LIGHTMANAGER_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
#include <filament/Color.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Entity.h>
|
||||
#include <utils/EntityInstance.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
#include <math/quat.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace utils {
|
||||
class Entity;
|
||||
} // namespace utils
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Engine;
|
||||
class FEngine;
|
||||
class FLightManager;
|
||||
|
||||
/**
|
||||
* LightManager allows to create a light source in the scene, such as a sun or street lights.
|
||||
*
|
||||
* At least one light must be added to a scene in order to see anything
|
||||
* (unless the Material.Shading.UNLIT is used).
|
||||
*
|
||||
*
|
||||
* Creation and destruction
|
||||
* ========================
|
||||
*
|
||||
* A Light component is created using the LightManager::Builder and destroyed by calling
|
||||
* LightManager::destroy(utils::Entity).
|
||||
*
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* filament::Engine* engine = filament::Engine::create();
|
||||
* utils::Entity sun = utils::EntityManager.get().create();
|
||||
*
|
||||
* filament::LightManager::Builder(Type::SUN)
|
||||
* .castShadows(true)
|
||||
* .build(*engine, sun);
|
||||
*
|
||||
* engine->getLightManager().destroy(sun);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
*
|
||||
* Light types
|
||||
* ===========
|
||||
*
|
||||
* Lights come in three flavors:
|
||||
* - directional lights
|
||||
* - point lights
|
||||
* - spot lights
|
||||
*
|
||||
*
|
||||
* Directional lights
|
||||
* ------------------
|
||||
*
|
||||
* Directional lights have a direction, but don't have a position. All light rays are
|
||||
* parallel and come from infinitely far away and from everywhere. Typically a directional light
|
||||
* is used to simulate the sun.
|
||||
*
|
||||
* Directional lights and spot lights are able to cast shadows.
|
||||
*
|
||||
* To create a directional light use Type.DIRECTIONAL or Type.SUN, both are similar, but the later
|
||||
* also draws a sun's disk in the sky and its reflection on glossy objects.
|
||||
*
|
||||
* @warning Currently, only a single directional light is supported. If several directional lights
|
||||
* are added to the scene, the dominant one will be used.
|
||||
*
|
||||
* @see Builder.direction(), Builder.sunAngularRadius()
|
||||
*
|
||||
* Point lights
|
||||
* ------------
|
||||
*
|
||||
* Unlike directional lights, point lights have a position but emit light in all directions.
|
||||
* The intensity of the light diminishes with the inverse square of the distance to the light.
|
||||
* Builder.falloff() controls distance beyond which the light has no more influence.
|
||||
*
|
||||
* A scene can have multiple point lights.
|
||||
*
|
||||
* @see Builder.position(), Builder.falloff()
|
||||
*
|
||||
* Spot lights
|
||||
* -----------
|
||||
*
|
||||
* Spot lights are similar to point lights but the light it emits is limited to a cone defined by
|
||||
* Builder.spotLightCone() and the light's direction.
|
||||
*
|
||||
* A spot light is therefore defined by a position, a direction and inner and outer cones. The
|
||||
* spot light's influence is limited to inside the outer cone. The inner cone defines the light's
|
||||
* falloff attenuation.
|
||||
*
|
||||
* A physically correct spot light is a little difficult to use because changing the outer angle
|
||||
* of the cone changes the illumination levels, as the same amount of light is spread over a
|
||||
* changing volume. The coupling of illumination and the outer cone means that an artist cannot
|
||||
* tweak the influence cone of a spot light without also changing the perceived illumination.
|
||||
* It therefore makes sense to provide artists with a parameter to disable this coupling. This
|
||||
* is the difference between Type.FOCUSED_SPOT and Type.SPOT.
|
||||
*
|
||||
* @see Builder.position(), Builder.direction(), Builder.falloff(), Builder.spotLightCone()
|
||||
*
|
||||
* Performance considerations
|
||||
* ==========================
|
||||
*
|
||||
* Generally, adding lights to the scene hurts performance, however filament is designed to be
|
||||
* able to handle hundreds of lights in a scene under certain conditions. Here are some tips
|
||||
* to keep performances high.
|
||||
*
|
||||
* 1. Prefer spot lights to point lights and use the smallest outer cone angle possible.
|
||||
*
|
||||
* 2. Use the smallest possible falloff distance for point and spot lights.
|
||||
* Performance is very sensitive to overlapping lights. The falloff distance essentially
|
||||
* defines a sphere of influence for the light, so try to position point and spot lights
|
||||
* such that they don't overlap too much.
|
||||
*
|
||||
* On the other hand, a scene can contain hundreds of non overlapping lights without
|
||||
* incurring a significant overhead.
|
||||
*
|
||||
*/
|
||||
class UTILS_PUBLIC LightManager : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
using Instance = utils::EntityInstance<LightManager>;
|
||||
|
||||
/**
|
||||
* Returns the number of component in the LightManager, note that component are not
|
||||
* guaranteed to be active. Use the EntityManager::isAlive() before use if needed.
|
||||
*
|
||||
* @return number of component in the LightManager
|
||||
*/
|
||||
size_t getComponentCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether a particular Entity is associated with a component of this LightManager
|
||||
* @param e An Entity.
|
||||
* @return true if this Entity has a component associated with this manager.
|
||||
*/
|
||||
bool hasComponent(utils::Entity e) const noexcept;
|
||||
|
||||
/**
|
||||
* @return true if the this manager has no components
|
||||
*/
|
||||
bool empty() const noexcept;
|
||||
|
||||
/**
|
||||
* Retrieve the `Entity` of the component from its `Instance`.
|
||||
* @param i Instance of the component obtained from getInstance()
|
||||
* @return
|
||||
*/
|
||||
utils::Entity getEntity(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Retrieve the Entities of all the components of this manager.
|
||||
* @return A list, in no particular order, of all the entities managed by this manager.
|
||||
*/
|
||||
utils::Entity const* UTILS_NONNULL getEntities() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets an Instance representing the Light component associated with the given Entity.
|
||||
* @param e An Entity.
|
||||
* @return An Instance object, which represents the Light component associated with the Entity e.
|
||||
* @note Use Instance::isValid() to make sure the component exists.
|
||||
* @see hasComponent()
|
||||
*/
|
||||
Instance getInstance(utils::Entity e) const noexcept;
|
||||
|
||||
// destroys this component from the given entity
|
||||
void destroy(utils::Entity e) noexcept;
|
||||
|
||||
|
||||
//! Denotes the type of the light being created.
|
||||
enum class Type : uint8_t {
|
||||
SUN, //!< Directional light that also draws a sun's disk in the sky.
|
||||
DIRECTIONAL, //!< Directional light, emits light in a given direction.
|
||||
POINT, //!< Point light, emits light from a position, in all directions.
|
||||
FOCUSED_SPOT, //!< Physically correct spot light.
|
||||
SPOT, //!< Spot light with coupling of outer cone and illumination disabled.
|
||||
};
|
||||
|
||||
/**
|
||||
* Control the quality / performance of the shadow map associated to this light
|
||||
*/
|
||||
struct ShadowOptions {
|
||||
/** Size of the shadow map in texels. Must be a power-of-two and larger or equal to 8. */
|
||||
uint32_t mapSize = 1024;
|
||||
|
||||
/**
|
||||
* Number of shadow cascades to use for this light. Must be between 1 and 4 (inclusive).
|
||||
* A value greater than 1 turns on cascaded shadow mapping (CSM).
|
||||
* Only applicable to Type.SUN or Type.DIRECTIONAL lights.
|
||||
*
|
||||
* When using shadow cascades, cascadeSplitPositions must also be set.
|
||||
*
|
||||
* @see ShadowOptions::cascadeSplitPositions
|
||||
*/
|
||||
uint8_t shadowCascades = 1;
|
||||
|
||||
/**
|
||||
* The split positions for shadow cascades.
|
||||
*
|
||||
* Cascaded shadow mapping (CSM) partitions the camera frustum into cascades. These values
|
||||
* determine the planes along the camera's Z axis to split the frustum. The camera near
|
||||
* plane is represented by 0.0f and the far plane represented by 1.0f.
|
||||
*
|
||||
* For example, if using 4 cascades, these values would set a uniform split scheme:
|
||||
* { 0.25f, 0.50f, 0.75f }
|
||||
*
|
||||
* For N cascades, N - 1 split positions will be read from this array.
|
||||
*
|
||||
* Filament provides utility methods inside LightManager::ShadowCascades to help set these
|
||||
* values. For example, to use a uniform split scheme:
|
||||
*
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* LightManager::ShadowCascades::computeUniformSplits(options.splitPositions, 4);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* @see ShadowCascades::computeUniformSplits
|
||||
* @see ShadowCascades::computeLogSplits
|
||||
* @see ShadowCascades::computePracticalSplits
|
||||
*/
|
||||
float cascadeSplitPositions[3] = { 0.125f, 0.25f, 0.50f };
|
||||
|
||||
/** Constant bias in world units (e.g. meters) by which shadows are moved away from the
|
||||
* light. 1mm by default.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
float constantBias = 0.001f;
|
||||
|
||||
/** Amount by which the maximum sampling error is scaled. The resulting value is used
|
||||
* to move the shadow away from the fragment normal. Should be 1.0.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
float normalBias = 1.0f;
|
||||
|
||||
/** Distance from the camera after which shadows are clipped. This is used to clip
|
||||
* shadows that are too far and wouldn't contribute to the scene much, improving
|
||||
* performance and quality. This value is always positive.
|
||||
* Use 0.0f to use the camera far distance.
|
||||
* This only affect directional lights.
|
||||
*/
|
||||
float shadowFar = 0.0f;
|
||||
|
||||
/** Optimize the quality of shadows from this distance from the camera. Shadows will
|
||||
* be rendered in front of this distance, but the quality may not be optimal.
|
||||
* This value is always positive. Use 0.0f to use the camera near distance.
|
||||
* The default of 1m works well with many scenes. The quality of shadows may drop
|
||||
* rapidly when this value decreases.
|
||||
*/
|
||||
float shadowNearHint = 1.0f;
|
||||
|
||||
/** Optimize the quality of shadows in front of this distance from the camera. Shadows
|
||||
* will be rendered behind this distance, but the quality may not be optimal.
|
||||
* This value is always positive. Use std::numerical_limits<float>::infinity() to
|
||||
* use the camera far distance.
|
||||
*/
|
||||
float shadowFarHint = 100.0f;
|
||||
|
||||
/**
|
||||
* Controls whether the shadow map should be optimized for resolution or stability.
|
||||
* When set to true, all resolution enhancing features that can affect stability are
|
||||
* disabling, resulting in significantly lower resolution shadows, albeit stable ones.
|
||||
*
|
||||
* Setting this flag to true always disables LiSPSM (see below).
|
||||
*
|
||||
* @see lispsm
|
||||
*/
|
||||
bool stable = false;
|
||||
|
||||
/**
|
||||
* LiSPSM, or light-space perspective shadow-mapping is a technique allowing to better
|
||||
* optimize the use of the shadow-map texture. When enabled the effective resolution of
|
||||
* shadows is greatly improved and yields result similar to using cascades without the
|
||||
* extra cost. LiSPSM comes with some drawbacks however, in particular it is incompatible
|
||||
* with blurring because it effectively affects the blur kernel size.
|
||||
*
|
||||
* Blurring is only an issue when using ShadowType::VSM with a large blur or with
|
||||
* ShadowType::PCSS however.
|
||||
*
|
||||
* If these blurring artifacts become problematic, this flag can be used to disable LiSPSM.
|
||||
*
|
||||
* @see stable
|
||||
*/
|
||||
bool lispsm = true;
|
||||
|
||||
/**
|
||||
* Constant bias in depth-resolution units by which shadows are moved away from the
|
||||
* light. The default value of 0.5 is used to round depth values up.
|
||||
* Generally this value shouldn't be changed or at least be small and positive.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
float polygonOffsetConstant = 0.5f;
|
||||
|
||||
/**
|
||||
* Bias based on the change in depth in depth-resolution units by which shadows are moved
|
||||
* away from the light. The default value of 2.0 works well with SHADOW_SAMPLING_PCF_LOW.
|
||||
* Generally this value is between 0.5 and the size in texel of the PCF filter.
|
||||
* Setting this value correctly is essential for LISPSM shadow-maps.
|
||||
* This is ignored when the View's ShadowType is set to VSM.
|
||||
*/
|
||||
float polygonOffsetSlope = 2.0f;
|
||||
|
||||
/**
|
||||
* Whether screen-space contact shadows are used. This applies regardless of whether a
|
||||
* Renderable is a shadow caster.
|
||||
* Screen-space contact shadows are typically useful in large scenes.
|
||||
* (off by default)
|
||||
*/
|
||||
bool screenSpaceContactShadows = false;
|
||||
|
||||
/**
|
||||
* Number of ray-marching steps for screen-space contact shadows (8 by default).
|
||||
*
|
||||
* CAUTION: this parameter is ignored for all lights except the directional/sun light,
|
||||
* all other lights use the same value set for the directional/sun light.
|
||||
*
|
||||
*/
|
||||
uint8_t stepCount = 8;
|
||||
|
||||
/**
|
||||
* Maximum shadow-occluder distance for screen-space contact shadows (world units).
|
||||
* (30 cm by default)
|
||||
*
|
||||
* CAUTION: this parameter is ignored for all lights except the directional/sun light,
|
||||
* all other lights use the same value set for the directional/sun light.
|
||||
*
|
||||
*/
|
||||
float maxShadowDistance = 0.3f;
|
||||
|
||||
/**
|
||||
* Options available when the View's ShadowType is set to VSM.
|
||||
*
|
||||
* @warning This API is still experimental and subject to change.
|
||||
* @see View::setShadowType
|
||||
*/
|
||||
struct Vsm {
|
||||
/**
|
||||
* When elvsm is set to true, "Exponential Layered VSM without Layers" are used. It is
|
||||
* an improvement to the default EVSM which suffers important light leaks. Enabling
|
||||
* ELVSM for a single shadowmap doubles the memory usage of all shadow maps.
|
||||
* ELVSM is mostly useful when large blurs are used.
|
||||
*/
|
||||
bool elvsm = false;
|
||||
|
||||
/**
|
||||
* Blur width for the VSM blur. Zero do disable.
|
||||
* The maximum value is 125.
|
||||
*/
|
||||
float blurWidth = 0.0f;
|
||||
} vsm;
|
||||
|
||||
/**
|
||||
* Light bulb radius used for soft shadows. Currently this is only used when DPCF or PCSS is
|
||||
* enabled. (2cm by default).
|
||||
*/
|
||||
float shadowBulbRadius = 0.02f;
|
||||
|
||||
/**
|
||||
* Transforms the shadow direction. Must be a unit quaternion.
|
||||
* The default is identity.
|
||||
* Ignored if the light type isn't directional. For artistic use. Use with caution.
|
||||
*/
|
||||
math::quatf transform{ 1.0f };
|
||||
};
|
||||
|
||||
struct ShadowCascades {
|
||||
/**
|
||||
* Utility method to compute ShadowOptions::cascadeSplitPositions according to a uniform
|
||||
* split scheme.
|
||||
*
|
||||
* @param splitPositions a float array of at least size (cascades - 1) to write the split
|
||||
* positions into
|
||||
* @param cascades the number of shadow cascades, at most 4
|
||||
*/
|
||||
static void computeUniformSplits(float* UTILS_NONNULL splitPositions, uint8_t cascades);
|
||||
|
||||
/**
|
||||
* Utility method to compute ShadowOptions::cascadeSplitPositions according to a logarithmic
|
||||
* split scheme.
|
||||
*
|
||||
* @param splitPositions a float array of at least size (cascades - 1) to write the split
|
||||
* positions into
|
||||
* @param cascades the number of shadow cascades, at most 4
|
||||
* @param near the camera near plane
|
||||
* @param far the camera far plane
|
||||
*/
|
||||
static void computeLogSplits(float* UTILS_NONNULL splitPositions, uint8_t cascades,
|
||||
float near, float far);
|
||||
|
||||
/**
|
||||
* Utility method to compute ShadowOptions::cascadeSplitPositions according to a practical
|
||||
* split scheme.
|
||||
*
|
||||
* The practical split scheme uses uses a lambda value to interpolate between the logarithmic
|
||||
* and uniform split schemes. Start with a lambda value of 0.5f and adjust for your scene.
|
||||
*
|
||||
* See: Zhang et al 2006, "Parallel-split shadow maps for large-scale virtual environments"
|
||||
*
|
||||
* @param splitPositions a float array of at least size (cascades - 1) to write the split
|
||||
* positions into
|
||||
* @param cascades the number of shadow cascades, at most 4
|
||||
* @param near the camera near plane
|
||||
* @param far the camera far plane
|
||||
* @param lambda a float in the range [0, 1] that interpolates between log and
|
||||
* uniform split schemes
|
||||
*/
|
||||
static void computePracticalSplits(float* UTILS_NONNULL splitPositions, uint8_t cascades,
|
||||
float near, float far, float lambda);
|
||||
};
|
||||
|
||||
//! Use Builder to construct a Light object instance
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
public:
|
||||
/**
|
||||
* Creates a light builder and set the light's #Type.
|
||||
*
|
||||
* @param type #Type of Light object to create.
|
||||
*/
|
||||
explicit Builder(Type type) noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables a light channel. Light channel 0 is enabled by default.
|
||||
*
|
||||
* @param channel Light channel to enable or disable, between 0 and 7.
|
||||
* @param enable Whether to enable or disable the light channel.
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& lightChannel(unsigned int channel, bool enable = true) noexcept;
|
||||
|
||||
/**
|
||||
* Whether this Light casts shadows (disabled by default)
|
||||
*
|
||||
* @param enable Enables or disables casting shadows from this Light.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& castShadows(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the shadow-map options for this light.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& shadowOptions(const ShadowOptions& options) noexcept;
|
||||
|
||||
/**
|
||||
* Whether this light casts light (enabled by default)
|
||||
*
|
||||
* @param enable Enables or disables lighting from this Light.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* In some situations it can be useful to have a light in the scene that doesn't
|
||||
* actually emit light, but does cast shadows.
|
||||
*/
|
||||
Builder& castLight(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the initial position of the light in world space.
|
||||
*
|
||||
* @param position Light's position in world space. The default is at the origin.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* The Light's position is ignored for directional lights (Type.DIRECTIONAL or Type.SUN)
|
||||
*/
|
||||
Builder& position(const math::float3& position) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the initial direction of a light in world space.
|
||||
*
|
||||
* @param direction Light's direction in world space. Should be a unit vector.
|
||||
* The default is {0,-1,0}.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* The Light's direction is ignored for Type.POINT lights.
|
||||
*/
|
||||
Builder& direction(const math::float3& direction) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the initial color of a light.
|
||||
*
|
||||
* @param color Color of the light specified in the linear sRGB color-space.
|
||||
* The default is white {1,1,1}.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& color(const LinearColor& color) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the initial intensity of a light.
|
||||
* @param intensity This parameter depends on the Light.Type:
|
||||
* - For directional lights, it specifies the illuminance in *lux*
|
||||
* (or *lumen/m^2*).
|
||||
* - For point lights and spot lights, it specifies the luminous power
|
||||
* in *lumen*.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* For example, the sun's illuminance is about 100,000 lux.
|
||||
*
|
||||
* This method overrides any prior calls to intensity or intensityCandela.
|
||||
*
|
||||
*/
|
||||
Builder& intensity(float intensity) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the initial intensity of a spot or point light in candela.
|
||||
*
|
||||
* @param intensity Luminous intensity in *candela*.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* This method is equivalent to calling intensity(float intensity) for directional lights
|
||||
* (Type.DIRECTIONAL or Type.SUN).
|
||||
*
|
||||
* This method overrides any prior calls to intensity or intensityCandela.
|
||||
*/
|
||||
Builder& intensityCandela(float intensity) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the initial intensity of a light in watts.
|
||||
*
|
||||
* @param watts Energy consumed by a lightbulb. It is related to the energy produced
|
||||
* and ultimately the brightness by the \p efficiency parameter.
|
||||
* This value is often available on the packaging of commercial
|
||||
* lightbulbs.
|
||||
*
|
||||
* @param efficiency Efficiency in percent. This depends on the type of lightbulb used.
|
||||
*
|
||||
* Lightbulb type | Efficiency
|
||||
* ----------------:|-----------:
|
||||
* Incandescent | 2.2%
|
||||
* Halogen | 7.0%
|
||||
* LED | 8.7%
|
||||
* Fluorescent | 10.7%
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
*
|
||||
* @note
|
||||
* This call is equivalent to `Builder::intensity(efficiency * 683 * watts);`
|
||||
*
|
||||
* This method overrides any prior calls to intensity or intensityCandela.
|
||||
*/
|
||||
Builder& intensity(float watts, float efficiency) noexcept;
|
||||
|
||||
/**
|
||||
* Set the falloff distance for point lights and spot lights.
|
||||
*
|
||||
* At the falloff distance, the light has no more effect on objects.
|
||||
*
|
||||
* The falloff distance essentially defines a *sphere of influence* around the light, and
|
||||
* therefore has an impact on performance. Larger falloffs might reduce performance
|
||||
* significantly, especially when many lights are used.
|
||||
*
|
||||
* Try to avoid having a large number of light's spheres of influence overlap.
|
||||
*
|
||||
* @param radius Falloff distance in world units. Default is 1 meter.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* The Light's falloff is ignored for directional lights (Type.DIRECTIONAL or Type.SUN)
|
||||
*/
|
||||
Builder& falloff(float radius) noexcept;
|
||||
|
||||
/**
|
||||
* Defines a spot light'st angular falloff attenuation.
|
||||
*
|
||||
* A spot light is defined by a position, a direction and two cones, \p inner and \p outer.
|
||||
* These two cones are used to define the angular falloff attenuation of the spot light
|
||||
* and are defined by the angle from the center axis to where the falloff begins (i.e.
|
||||
* cones are defined by their half-angle).
|
||||
*
|
||||
* Both inner and outer are silently clamped to a minimum value of 0.5 degrees
|
||||
* (~0.00873 radians) to avoid floating-point precision issues during rendering.
|
||||
*
|
||||
* @param inner inner cone angle in *radians* between 0.00873 and \p outer
|
||||
* @param outer outer cone angle in *radians* between 0.00873 inner and @f$ \pi/2 @f$
|
||||
* @return This Builder, for chaining calls.
|
||||
*
|
||||
* @note
|
||||
* The spot light cone is ignored for directional and point lights.
|
||||
*
|
||||
* @see Type.SPOT, Type.FOCUSED_SPOT
|
||||
*/
|
||||
Builder& spotLightCone(float inner, float outer) noexcept;
|
||||
|
||||
/**
|
||||
* Defines the angular radius of the sun, in degrees, between 0.25° and 20.0°
|
||||
*
|
||||
* The Sun as seen from Earth has an angular size of 0.526° to 0.545°
|
||||
*
|
||||
* @param angularRadius sun's radius in degree. Default is 0.545°.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& sunAngularRadius(float angularRadius) noexcept;
|
||||
|
||||
/**
|
||||
* Defines the halo radius of the sun. The radius of the halo is defined as a
|
||||
* multiplier of the sun angular radius.
|
||||
*
|
||||
* @param haloSize radius multiplier. Default is 10.0.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& sunHaloSize(float haloSize) noexcept;
|
||||
|
||||
/**
|
||||
* Defines the halo falloff of the sun. The falloff is a dimensionless number
|
||||
* used as an exponent.
|
||||
*
|
||||
* @param haloFalloff halo falloff. Default is 80.0.
|
||||
*
|
||||
* @return This Builder, for chaining calls.
|
||||
*/
|
||||
Builder& sunHaloFalloff(float haloFalloff) noexcept;
|
||||
|
||||
enum Result { Error = -1, Success = 0 };
|
||||
|
||||
/**
|
||||
* Adds the Light component to an entity.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this light with.
|
||||
* @param entity Entity to add the light component to.
|
||||
* @return Success if the component was created successfully, Error otherwise.
|
||||
*
|
||||
* If exceptions are disabled and an error occurs, this function is a no-op.
|
||||
* Success can be checked by looking at the return value.
|
||||
*
|
||||
* If this component already exists on the given entity, it is first destroyed as if
|
||||
* destroy(utils::Entity e) was called.
|
||||
*
|
||||
* @warning
|
||||
* Currently, only 2048 lights can be created on a given Engine.
|
||||
*
|
||||
* @exception utils::PostConditionPanic if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
|
||||
*/
|
||||
Result build(Engine& engine, utils::Entity entity);
|
||||
|
||||
private:
|
||||
friend class FEngine;
|
||||
friend class FLightManager;
|
||||
};
|
||||
|
||||
static constexpr float EFFICIENCY_INCANDESCENT = 0.0220f; //!< Typical efficiency of an incandescent light bulb (2.2%)
|
||||
static constexpr float EFFICIENCY_HALOGEN = 0.0707f; //!< Typical efficiency of an halogen light bulb (7.0%)
|
||||
static constexpr float EFFICIENCY_FLUORESCENT = 0.0878f; //!< Typical efficiency of a fluorescent light bulb (8.7%)
|
||||
static constexpr float EFFICIENCY_LED = 0.1171f; //!< Typical efficiency of a LED light bulb (11.7%)
|
||||
|
||||
Type getType(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Helper function that returns if a light is a directional light
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return true is this light is a type of directional light
|
||||
*/
|
||||
inline bool isDirectional(Instance i) const noexcept {
|
||||
Type const type = getType(i);
|
||||
return type == Type::DIRECTIONAL || type == Type::SUN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that returns if a light is a point light
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return true is this light is a type of point light
|
||||
*/
|
||||
inline bool isPointLight(Instance i) const noexcept {
|
||||
return getType(i) == Type::POINT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that returns if a light is a spot light
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return true is this light is a type of spot light
|
||||
*/
|
||||
inline bool isSpotLight(Instance i) const noexcept {
|
||||
Type const type = getType(i);
|
||||
return type == Type::SPOT || type == Type::FOCUSED_SPOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables a light channel. Light channel 0 is enabled by default.
|
||||
* @param channel light channel to enable or disable, between 0 and 7.
|
||||
* @param enable whether to enable (true) or disable (false) the specified light channel.
|
||||
*/
|
||||
void setLightChannel(Instance i, unsigned int channel, bool enable = true) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether a light channel is enabled on a specified light.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param channel Light channel to query
|
||||
* @return true if the light channel is enabled, false otherwise
|
||||
*/
|
||||
bool getLightChannel(Instance i, unsigned int channel) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the light's position.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param position Light's position in world space. The default is at the origin.
|
||||
*
|
||||
* @see Builder.position()
|
||||
*/
|
||||
void setPosition(Instance i, const math::float3& position) noexcept;
|
||||
|
||||
//! returns the light's position in world space
|
||||
const math::float3& getPosition(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the light's direction
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param direction Light's direction in world space. Should be a unit vector.
|
||||
* The default is {0,-1,0}.
|
||||
*
|
||||
* @see Builder.direction()
|
||||
*/
|
||||
void setDirection(Instance i, const math::float3& direction) noexcept;
|
||||
|
||||
//! returns the light's direction in world space
|
||||
const math::float3& getDirection(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the light's hue as linear sRGB
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param color Color of the light specified in the linear sRGB color-space.
|
||||
* The default is white {1,1,1}.
|
||||
*
|
||||
* @see Builder.color(), getInstance()
|
||||
*/
|
||||
void setColor(Instance i, const LinearColor& color) noexcept;
|
||||
|
||||
/**
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return the light's color in linear sRGB
|
||||
*/
|
||||
const math::float3& getColor(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the light's intensity. The intensity can be negative.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param intensity This parameter depends on the Light.Type:
|
||||
* - For directional lights, it specifies the illuminance in *lux*
|
||||
* (or *lumen/m^2*).
|
||||
* - For point lights and spot lights, it specifies the luminous power
|
||||
* in *lumen*.
|
||||
*
|
||||
* @see Builder.intensity()
|
||||
*/
|
||||
void setIntensity(Instance i, float intensity) noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the light's intensity. The intensity can be negative.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param watts Energy consumed by a lightbulb. It is related to the energy produced
|
||||
* and ultimately the brightness by the \p efficiency parameter.
|
||||
* This value is often available on the packaging of commercial
|
||||
* lightbulbs.
|
||||
* @param efficiency Efficiency in percent. This depends on the type of lightbulb used.
|
||||
*
|
||||
* Lightbulb type | Efficiency
|
||||
* ----------------:|-----------:
|
||||
* Incandescent | 2.2%
|
||||
* Halogen | 7.0%
|
||||
* LED | 8.7%
|
||||
* Fluorescent | 10.7%
|
||||
*
|
||||
* @see Builder.intensity(float watts, float efficiency)
|
||||
*/
|
||||
void setIntensity(Instance i, float watts, float efficiency) noexcept {
|
||||
setIntensity(i, watts * 683.0f * efficiency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically updates the light's intensity in candela. The intensity can be negative.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param intensity Luminous intensity in *candela*.
|
||||
*
|
||||
* @note
|
||||
* This method is equivalent to calling setIntensity(float intensity) for directional lights
|
||||
* (Type.DIRECTIONAL or Type.SUN).
|
||||
*
|
||||
* @see Builder.intensityCandela(float intensity)
|
||||
*/
|
||||
void setIntensityCandela(Instance i, float intensity) noexcept;
|
||||
|
||||
/**
|
||||
* returns the light's luminous intensity in candela.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
*
|
||||
* @note for Type.FOCUSED_SPOT lights, the returned value depends on the \p outer cone angle.
|
||||
*
|
||||
* @return luminous intensity in candela.
|
||||
*/
|
||||
float getIntensity(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Set the falloff distance for point lights and spot lights.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param radius falloff distance in world units. Default is 1 meter.
|
||||
*
|
||||
* @see Builder.falloff()
|
||||
*/
|
||||
void setFalloff(Instance i, float radius) noexcept;
|
||||
|
||||
/**
|
||||
* returns the falloff distance of this light.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return the falloff distance of this light.
|
||||
*/
|
||||
float getFalloff(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates a spot light's cone as angles
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param inner inner cone angle in *radians* between 0.00873 and outer
|
||||
* @param outer outer cone angle in *radians* between 0.00873 and pi/2
|
||||
*
|
||||
* @see Builder.spotLightCone()
|
||||
*/
|
||||
void setSpotLightCone(Instance i, float inner, float outer) noexcept;
|
||||
|
||||
/**
|
||||
* returns the outer cone angle in *radians* between inner and pi/2.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return the outer cone angle of this light.
|
||||
*/
|
||||
float getSpotLightOuterCone(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* returns the inner cone angle in *radians* between 0 and pi/2.
|
||||
*
|
||||
* The value is recomputed from the initial values, thus is not precisely
|
||||
* the same as the one passed to setSpotLightCone() or Builder.spotLightCone().
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return the inner cone angle of this light.
|
||||
*/
|
||||
float getSpotLightInnerCone(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the angular radius of a Type.SUN light
|
||||
*
|
||||
* The Sun as seen from Earth has an angular size of 0.526° to 0.545°
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param angularRadius sun's radius in degrees. Default is 0.545°.
|
||||
*/
|
||||
void setSunAngularRadius(Instance i, float angularRadius) noexcept;
|
||||
|
||||
/**
|
||||
* returns the angular radius if the sun in degrees.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return the angular radius if the sun in degrees.
|
||||
*/
|
||||
float getSunAngularRadius(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the halo radius of a Type.SUN light. The radius
|
||||
* of the halo is defined as a multiplier of the sun angular radius.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param haloSize radius multiplier. Default is 10.0.
|
||||
*/
|
||||
void setSunHaloSize(Instance i, float haloSize) noexcept;
|
||||
|
||||
/**
|
||||
* returns the halo size of a Type.SUN light as a multiplier of the
|
||||
* sun angular radius.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return the halo size
|
||||
*/
|
||||
float getSunHaloSize(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* Dynamically updates the halo falloff of a Type.SUN light. The falloff
|
||||
* is a dimensionless number used as an exponent.
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param haloFalloff halo falloff. Default is 80.0.
|
||||
*/
|
||||
void setSunHaloFalloff(Instance i, float haloFalloff) noexcept;
|
||||
|
||||
/**
|
||||
* returns the halo falloff of a Type.SUN light as a dimensionless value.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return the halo falloff
|
||||
*/
|
||||
float getSunHaloFalloff(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* returns the shadow-map options for a given light
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @return A ShadowOption structure
|
||||
*/
|
||||
ShadowOptions const& getShadowOptions(Instance i) const noexcept;
|
||||
|
||||
/**
|
||||
* sets the shadow-map options for a given light
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param options A ShadowOption structure
|
||||
*/
|
||||
void setShadowOptions(Instance i, ShadowOptions const& options) noexcept;
|
||||
|
||||
/**
|
||||
* Whether this Light casts shadows (disabled by default)
|
||||
*
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
* @param shadowCaster Enables or disables casting shadows from this Light.
|
||||
*
|
||||
* @warning
|
||||
* - Only a Type.DIRECTIONAL, Type.SUN, Type.SPOT, or Type.FOCUSED_SPOT light can cast shadows
|
||||
*/
|
||||
void setShadowCaster(Instance i, bool shadowCaster) noexcept;
|
||||
|
||||
/**
|
||||
* returns whether this light casts shadows.
|
||||
* @param i Instance of the component obtained from getInstance().
|
||||
*/
|
||||
bool isShadowCaster(Instance i) const noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~LightManager() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_LIGHTMANAGER_H
|
||||
394
dart_filament/native/include/filament/filament/Material.h
Normal file
394
dart_filament/native/include/filament/filament/Material.h
Normal file
@@ -0,0 +1,394 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_MATERIAL_H
|
||||
#define TNT_FILAMENT_MATERIAL_H
|
||||
|
||||
#include <filament/Color.h>
|
||||
#include <filament/FilamentAPI.h>
|
||||
#include <filament/MaterialEnums.h>
|
||||
#include <filament/MaterialInstance.h>
|
||||
|
||||
#include <backend/CallbackHandler.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace utils {
|
||||
class CString;
|
||||
} // namespace utils
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Texture;
|
||||
class TextureSampler;
|
||||
|
||||
class FEngine;
|
||||
class FMaterial;
|
||||
|
||||
class Engine;
|
||||
|
||||
class UTILS_PUBLIC Material : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
using BlendingMode = filament::BlendingMode;
|
||||
using Shading = filament::Shading;
|
||||
using Interpolation = filament::Interpolation;
|
||||
using VertexDomain = filament::VertexDomain;
|
||||
using TransparencyMode = filament::TransparencyMode;
|
||||
|
||||
using ParameterType = backend::UniformType;
|
||||
using Precision = backend::Precision;
|
||||
using SamplerType = backend::SamplerType;
|
||||
using SamplerFormat = backend::SamplerFormat;
|
||||
using CullingMode = backend::CullingMode;
|
||||
using ShaderModel = backend::ShaderModel;
|
||||
using SubpassType = backend::SubpassType;
|
||||
|
||||
/**
|
||||
* Holds information about a material parameter.
|
||||
*/
|
||||
struct ParameterInfo {
|
||||
//! Name of the parameter.
|
||||
const char* UTILS_NONNULL name;
|
||||
//! Whether the parameter is a sampler (texture).
|
||||
bool isSampler;
|
||||
//! Whether the parameter is a subpass type.
|
||||
bool isSubpass;
|
||||
union {
|
||||
//! Type of the parameter if the parameter is not a sampler.
|
||||
ParameterType type;
|
||||
//! Type of the parameter if the parameter is a sampler.
|
||||
SamplerType samplerType;
|
||||
//! Type of the parameter if the parameter is a subpass.
|
||||
SubpassType subpassType;
|
||||
};
|
||||
//! Size of the parameter when the parameter is an array.
|
||||
uint32_t count;
|
||||
//! Requested precision of the parameter.
|
||||
Precision precision;
|
||||
};
|
||||
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Specifies the material data. The material data is a binary blob produced by
|
||||
* libfilamat or by matc.
|
||||
*
|
||||
* @param payload Pointer to the material data, must stay valid until build() is called.
|
||||
* @param size Size of the material data pointed to by "payload" in bytes.
|
||||
*/
|
||||
Builder& package(const void* UTILS_NONNULL payload, size_t size);
|
||||
|
||||
template<typename T>
|
||||
using is_supported_constant_parameter_t = typename std::enable_if<
|
||||
std::is_same<int32_t, T>::value ||
|
||||
std::is_same<float, T>::value ||
|
||||
std::is_same<bool, T>::value>::type;
|
||||
|
||||
/**
|
||||
* Specialize a constant parameter specified in the material definition with a concrete
|
||||
* value for this material. Once build() is called, this constant cannot be changed.
|
||||
* Will throw an exception if the name does not match a constant specified in the
|
||||
* material definition or if the type provided does not match.
|
||||
*
|
||||
* @tparam T The type of constant parameter, either int32_t, float, or bool.
|
||||
* @param name The name of the constant parameter specified in the material definition, such
|
||||
* as "myConstant".
|
||||
* @param nameLength Length in `char` of the name parameter.
|
||||
* @param value The value to use for the constant parameter, must match the type specified
|
||||
* in the material definition.
|
||||
*/
|
||||
template<typename T, typename = is_supported_constant_parameter_t<T>>
|
||||
Builder& constant(const char* UTILS_NONNULL name, size_t nameLength, T value);
|
||||
|
||||
/** inline helper to provide the constant name as a null-terminated C string */
|
||||
template<typename T, typename = is_supported_constant_parameter_t<T>>
|
||||
inline Builder& constant(const char* UTILS_NONNULL name, T value) {
|
||||
return constant(name, strlen(name), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Material object and returns a pointer to it.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this Material with.
|
||||
*
|
||||
* @return pointer to the newly created object or nullptr if exceptions are disabled and
|
||||
* an error occurred.
|
||||
*
|
||||
* @exception utils::PostConditionPanic if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
|
||||
*/
|
||||
Material* UTILS_NULLABLE build(Engine& engine);
|
||||
private:
|
||||
friend class FMaterial;
|
||||
};
|
||||
|
||||
using CompilerPriorityQueue = backend:: CompilerPriorityQueue;
|
||||
|
||||
/**
|
||||
* Asynchronously ensures that a subset of this Material's variants are compiled. After issuing
|
||||
* several Material::compile() calls in a row, it is recommended to call Engine::flush()
|
||||
* such that the backend can start the compilation work as soon as possible.
|
||||
* The provided callback is guaranteed to be called on the main thread after all specified
|
||||
* variants of the material are compiled. This can take hundreds of milliseconds.
|
||||
*
|
||||
* If all the material's variants are already compiled, the callback will be scheduled as
|
||||
* soon as possible, but this might take a few dozen millisecond, corresponding to how
|
||||
* many previous frames are enqueued in the backend. This also varies by backend. Therefore,
|
||||
* it is recommended to only call this method once per material shortly after creation.
|
||||
*
|
||||
* If the same variant is scheduled for compilation multiple times, the first scheduling
|
||||
* takes precedence; later scheduling are ignored.
|
||||
*
|
||||
* caveat: A consequence is that if a variant is scheduled on the low priority queue and later
|
||||
* scheduled again on the high priority queue, the later scheduling is ignored.
|
||||
* Therefore, the second callback could be called before the variant is compiled.
|
||||
* However, the first callback, if specified, will trigger as expected.
|
||||
*
|
||||
* The callback is guaranteed to be called. If the engine is destroyed while some material
|
||||
* variants are still compiling or in the queue, these will be discarded and the corresponding
|
||||
* callback will be called. In that case however the Material pointer passed to the callback
|
||||
* is guaranteed to be invalid (either because it's been destroyed by the user already, or,
|
||||
* because it's been cleaned-up by the Engine).
|
||||
*
|
||||
* UserVariantFilterMask::ALL should be used with caution. Only variants that an application
|
||||
* needs should be included in the variants argument. For example, the STE variant is only used
|
||||
* for stereoscopic rendering. If an application is not planning to render in stereo, this bit
|
||||
* should be turned off to avoid unnecessary material compilations.
|
||||
*
|
||||
* @param priority Which priority queue to use, LOW or HIGH.
|
||||
* @param variants Variants to include to the compile command.
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler
|
||||
* @param callback callback called on the main thread when the compilation is done on
|
||||
* by backend.
|
||||
*/
|
||||
void compile(CompilerPriorityQueue priority,
|
||||
UserVariantFilterMask variants,
|
||||
backend::CallbackHandler* UTILS_NULLABLE handler = nullptr,
|
||||
utils::Invocable<void(Material* UTILS_NONNULL)>&& callback = {}) noexcept;
|
||||
|
||||
inline void compile(CompilerPriorityQueue priority,
|
||||
UserVariantFilterBit variants,
|
||||
backend::CallbackHandler* UTILS_NULLABLE handler = nullptr,
|
||||
utils::Invocable<void(Material* UTILS_NONNULL)>&& callback = {}) noexcept {
|
||||
compile(priority, UserVariantFilterMask(variants), handler,
|
||||
std::forward<utils::Invocable<void(Material* UTILS_NONNULL)>>(callback));
|
||||
}
|
||||
|
||||
inline void compile(CompilerPriorityQueue priority,
|
||||
backend::CallbackHandler* UTILS_NULLABLE handler = nullptr,
|
||||
utils::Invocable<void(Material* UTILS_NONNULL)>&& callback = {}) noexcept {
|
||||
compile(priority, UserVariantFilterBit::ALL, handler,
|
||||
std::forward<utils::Invocable<void(Material* UTILS_NONNULL)>>(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of this material. Material instances should be freed using
|
||||
* Engine::destroy(const MaterialInstance*).
|
||||
*
|
||||
* @param name Optional name to associate with the given material instance. If this is null,
|
||||
* then the instance inherits the material's name.
|
||||
*
|
||||
* @return A pointer to the new instance.
|
||||
*/
|
||||
MaterialInstance* UTILS_NONNULL createInstance(const char* UTILS_NULLABLE name = nullptr) const noexcept;
|
||||
|
||||
//! Returns the name of this material as a null-terminated string.
|
||||
const char* UTILS_NONNULL getName() const noexcept;
|
||||
|
||||
//! Returns the shading model of this material.
|
||||
Shading getShading() const noexcept;
|
||||
|
||||
//! Returns the interpolation mode of this material. This affects how variables are interpolated.
|
||||
Interpolation getInterpolation() const noexcept;
|
||||
|
||||
//! Returns the blending mode of this material.
|
||||
BlendingMode getBlendingMode() const noexcept;
|
||||
|
||||
//! Returns the vertex domain of this material.
|
||||
VertexDomain getVertexDomain() const noexcept;
|
||||
|
||||
//! Returns the material's supported variants
|
||||
UserVariantFilterMask getSupportedVariants() const noexcept;
|
||||
|
||||
//! Returns the material domain of this material.
|
||||
//! The material domain determines how the material is used.
|
||||
MaterialDomain getMaterialDomain() const noexcept;
|
||||
|
||||
//! Returns the default culling mode of this material.
|
||||
CullingMode getCullingMode() const noexcept;
|
||||
|
||||
//! Returns the transparency mode of this material.
|
||||
//! This value only makes sense when the blending mode is transparent or fade.
|
||||
TransparencyMode getTransparencyMode() const noexcept;
|
||||
|
||||
//! Indicates whether instances of this material will, by default, write to the color buffer.
|
||||
bool isColorWriteEnabled() const noexcept;
|
||||
|
||||
//! Indicates whether instances of this material will, by default, write to the depth buffer.
|
||||
bool isDepthWriteEnabled() const noexcept;
|
||||
|
||||
//! Indicates whether instances of this material will, by default, use depth testing.
|
||||
bool isDepthCullingEnabled() const noexcept;
|
||||
|
||||
//! Indicates whether this material is double-sided.
|
||||
bool isDoubleSided() const noexcept;
|
||||
|
||||
//! Indicates whether this material uses alpha to coverage.
|
||||
bool isAlphaToCoverageEnabled() const noexcept;
|
||||
|
||||
//! Returns the alpha mask threshold used when the blending mode is set to masked.
|
||||
float getMaskThreshold() const noexcept;
|
||||
|
||||
//! Indicates whether this material uses the shadowing factor as a color multiplier.
|
||||
//! This values only makes sense when the shading mode is unlit.
|
||||
bool hasShadowMultiplier() const noexcept;
|
||||
|
||||
//! Indicates whether this material has specular anti-aliasing enabled
|
||||
bool hasSpecularAntiAliasing() const noexcept;
|
||||
|
||||
//! Returns the screen-space variance for specular-antialiasing, this value is between 0 and 1.
|
||||
float getSpecularAntiAliasingVariance() const noexcept;
|
||||
|
||||
//! Returns the clamping threshold for specular-antialiasing, this value is between 0 and 1.
|
||||
float getSpecularAntiAliasingThreshold() const noexcept;
|
||||
|
||||
//! Returns the list of vertex attributes required by this material.
|
||||
AttributeBitset getRequiredAttributes() const noexcept;
|
||||
|
||||
//! Returns the refraction mode used by this material.
|
||||
RefractionMode getRefractionMode() const noexcept;
|
||||
|
||||
//! Return the refraction type used by this material.
|
||||
RefractionType getRefractionType() const noexcept;
|
||||
|
||||
//! Returns the reflection mode used by this material.
|
||||
ReflectionMode getReflectionMode() const noexcept;
|
||||
|
||||
//! Returns the minimum required feature level for this material.
|
||||
backend::FeatureLevel getFeatureLevel() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of parameters declared by this material.
|
||||
* The returned value can be 0.
|
||||
*/
|
||||
size_t getParameterCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets information about this material's parameters.
|
||||
*
|
||||
* @param parameters A pointer to a list of ParameterInfo.
|
||||
* The list must be at least "count" large
|
||||
* @param count The number of parameters to retrieve. Must be >= 0 and can be > count.
|
||||
*
|
||||
* @return The number of parameters written to the parameters pointer.
|
||||
*/
|
||||
size_t getParameters(ParameterInfo* UTILS_NONNULL parameters, size_t count) const noexcept;
|
||||
|
||||
//! Indicates whether a parameter of the given name exists on this material.
|
||||
bool hasParameter(const char* UTILS_NONNULL name) const noexcept;
|
||||
|
||||
//! Indicates whether an existing parameter is a sampler or not.
|
||||
bool isSampler(const char* UTILS_NONNULL name) const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the value of the given parameter on this material's default instance.
|
||||
*
|
||||
* @param name The name of the material parameter
|
||||
* @param value The value of the material parameter
|
||||
*
|
||||
* @see getDefaultInstance()
|
||||
*/
|
||||
template <typename T>
|
||||
void setDefaultParameter(const char* UTILS_NONNULL name, T value) noexcept {
|
||||
getDefaultInstance()->setParameter(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a texture and sampler parameters on this material's default instance.
|
||||
*
|
||||
* @param name The name of the material texture parameter
|
||||
* @param texture The texture to set as parameter
|
||||
* @param sampler The sampler to be used with this texture
|
||||
*
|
||||
* @see getDefaultInstance()
|
||||
*/
|
||||
void setDefaultParameter(const char* UTILS_NONNULL name,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) noexcept {
|
||||
getDefaultInstance()->setParameter(name, texture, sampler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the given parameter on this material's default instance.
|
||||
*
|
||||
* @param name The name of the material color parameter
|
||||
* @param type Whether the color is specified in the linear or sRGB space
|
||||
* @param color The color as a floating point red, green, blue tuple
|
||||
*
|
||||
* @see getDefaultInstance()
|
||||
*/
|
||||
void setDefaultParameter(const char* UTILS_NONNULL name, RgbType type, math::float3 color) noexcept {
|
||||
getDefaultInstance()->setParameter(name, type, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the given parameter on this material's default instance.
|
||||
*
|
||||
* @param name The name of the material color parameter
|
||||
* @param type Whether the color is specified in the linear or sRGB space
|
||||
* @param color The color as a floating point red, green, blue, alpha tuple
|
||||
*
|
||||
* @see getDefaultInstance()
|
||||
*/
|
||||
void setDefaultParameter(const char* UTILS_NONNULL name, RgbaType type, math::float4 color) noexcept {
|
||||
getDefaultInstance()->setParameter(name, type, color);
|
||||
}
|
||||
|
||||
//! Returns this material's default instance.
|
||||
MaterialInstance* UTILS_NONNULL getDefaultInstance() noexcept;
|
||||
|
||||
//! Returns this material's default instance.
|
||||
MaterialInstance const* UTILS_NONNULL getDefaultInstance() const noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~Material() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_MATERIAL_H
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMAT_MATERIAL_CHUNK_TYPES_H
|
||||
#define TNT_FILAMAT_MATERIAL_CHUNK_TYPES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filamat {
|
||||
|
||||
// Pack an eight character string into a 64 bit integer.
|
||||
constexpr inline uint64_t charTo64bitNum(const char str[9]) noexcept {
|
||||
return
|
||||
( (static_cast<uint64_t >(str[0]) << 56))
|
||||
| ((static_cast<uint64_t >(str[1]) << 48) & 0x00FF000000000000U)
|
||||
| ((static_cast<uint64_t >(str[2]) << 40) & 0x0000FF0000000000U)
|
||||
| ((static_cast<uint64_t >(str[3]) << 32) & 0x000000FF00000000U)
|
||||
| ((static_cast<uint64_t >(str[4]) << 24) & 0x00000000FF000000U)
|
||||
| ((static_cast<uint64_t >(str[5]) << 16) & 0x0000000000FF0000U)
|
||||
| ((static_cast<uint64_t >(str[6]) << 8) & 0x000000000000FF00U)
|
||||
| ( static_cast<uint64_t >(str[7]) & 0x00000000000000FFU);
|
||||
}
|
||||
|
||||
enum UTILS_PUBLIC ChunkType : uint64_t {
|
||||
Unknown = charTo64bitNum("UNKNOWN "),
|
||||
MaterialUib = charTo64bitNum("MAT_UIB "),
|
||||
MaterialSib = charTo64bitNum("MAT_SIB "),
|
||||
MaterialSubpass = charTo64bitNum("MAT_SUB "),
|
||||
MaterialGlsl = charTo64bitNum("MAT_GLSL"),
|
||||
MaterialEssl1 = charTo64bitNum("MAT_ESS1"),
|
||||
MaterialSpirv = charTo64bitNum("MAT_SPIR"),
|
||||
MaterialMetal = charTo64bitNum("MAT_METL"),
|
||||
MaterialShaderModels = charTo64bitNum("MAT_SMDL"),
|
||||
MaterialSamplerBindings = charTo64bitNum("MAT_SAMP"),
|
||||
MaterialUniformBindings = charTo64bitNum("MAT_UNIF"),
|
||||
MaterialBindingUniformInfo = charTo64bitNum("MAT_UFRM"),
|
||||
MaterialAttributeInfo = charTo64bitNum("MAT_ATTR"),
|
||||
MaterialProperties = charTo64bitNum("MAT_PROP"),
|
||||
MaterialConstants = charTo64bitNum("MAT_CONS"),
|
||||
|
||||
MaterialName = charTo64bitNum("MAT_NAME"),
|
||||
MaterialVersion = charTo64bitNum("MAT_VERS"),
|
||||
MaterialCacheId = charTo64bitNum("MAT_UUID"),
|
||||
MaterialFeatureLevel = charTo64bitNum("MAT_FEAT"),
|
||||
MaterialShading = charTo64bitNum("MAT_SHAD"),
|
||||
MaterialBlendingMode = charTo64bitNum("MAT_BLEN"),
|
||||
MaterialTransparencyMode = charTo64bitNum("MAT_TRMD"),
|
||||
MaterialMaskThreshold = charTo64bitNum("MAT_THRS"),
|
||||
MaterialShadowMultiplier = charTo64bitNum("MAT_SHML"),
|
||||
MaterialSpecularAntiAliasing = charTo64bitNum("MAT_SPAA"),
|
||||
MaterialSpecularAntiAliasingVariance = charTo64bitNum("MAT_SVAR"),
|
||||
MaterialSpecularAntiAliasingThreshold = charTo64bitNum("MAT_STHR"),
|
||||
MaterialClearCoatIorChange = charTo64bitNum("MAT_CIOR"),
|
||||
MaterialDomain = charTo64bitNum("MAT_DOMN"),
|
||||
MaterialVariantFilterMask = charTo64bitNum("MAT_VFLT"),
|
||||
MaterialRefraction = charTo64bitNum("MAT_REFM"),
|
||||
MaterialRefractionType = charTo64bitNum("MAT_REFT"),
|
||||
MaterialReflectionMode = charTo64bitNum("MAT_REFL"),
|
||||
|
||||
MaterialRequiredAttributes = charTo64bitNum("MAT_REQA"),
|
||||
MaterialDoubleSidedSet = charTo64bitNum("MAT_DOSS"),
|
||||
MaterialDoubleSided = charTo64bitNum("MAT_DOSI"),
|
||||
|
||||
MaterialColorWrite = charTo64bitNum("MAT_CWRIT"),
|
||||
MaterialDepthWriteSet = charTo64bitNum("MAT_DEWS"),
|
||||
MaterialDepthWrite = charTo64bitNum("MAT_DWRIT"),
|
||||
MaterialDepthTest = charTo64bitNum("MAT_DTEST"),
|
||||
MaterialInstanced = charTo64bitNum("MAT_INSTA"),
|
||||
MaterialCullingMode = charTo64bitNum("MAT_CUMO"),
|
||||
MaterialAlphaToCoverageSet = charTo64bitNum("MAT_A2CS"),
|
||||
MaterialAlphaToCoverage = charTo64bitNum("MAT_A2CO"),
|
||||
|
||||
MaterialHasCustomDepthShader =charTo64bitNum("MAT_CSDP"),
|
||||
|
||||
MaterialVertexDomain = charTo64bitNum("MAT_VEDO"),
|
||||
MaterialInterpolation = charTo64bitNum("MAT_INTR"),
|
||||
|
||||
DictionaryText = charTo64bitNum("DIC_TEXT"),
|
||||
DictionarySpirv = charTo64bitNum("DIC_SPIR"),
|
||||
};
|
||||
|
||||
} // namespace filamat
|
||||
|
||||
#endif // TNT_FILAMAT_MATERIAL_CHUNK_TYPES_H
|
||||
256
dart_filament/native/include/filament/filament/MaterialEnums.h
Normal file
256
dart_filament/native/include/filament/filament/MaterialEnums.h
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_MATERIAL_ENUM_H
|
||||
#define TNT_FILAMENT_MATERIAL_ENUM_H
|
||||
|
||||
#include <utils/bitset.h>
|
||||
#include <utils/BitmaskEnum.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
// update this when a new version of filament wouldn't work with older materials
|
||||
static constexpr size_t MATERIAL_VERSION = 51;
|
||||
|
||||
/**
|
||||
* Supported shading models
|
||||
*/
|
||||
enum class Shading : uint8_t {
|
||||
UNLIT, //!< no lighting applied, emissive possible
|
||||
LIT, //!< default, standard lighting
|
||||
SUBSURFACE, //!< subsurface lighting model
|
||||
CLOTH, //!< cloth lighting model
|
||||
SPECULAR_GLOSSINESS, //!< legacy lighting model
|
||||
};
|
||||
|
||||
/**
|
||||
* Attribute interpolation types in the fragment shader
|
||||
*/
|
||||
enum class Interpolation : uint8_t {
|
||||
SMOOTH, //!< default, smooth interpolation
|
||||
FLAT //!< flat interpolation
|
||||
};
|
||||
|
||||
/**
|
||||
* Shader quality, affect some global quality parameters
|
||||
*/
|
||||
enum class ShaderQuality : int8_t {
|
||||
DEFAULT = -1, // LOW on mobile, HIGH on desktop
|
||||
LOW = 0, // enable optimizations that can slightly affect correctness
|
||||
NORMAL = 1, // normal quality, correctness honored
|
||||
HIGH = 2 // higher quality (e.g. better upscaling, etc...)
|
||||
};
|
||||
|
||||
/**
|
||||
* Supported blending modes
|
||||
*/
|
||||
enum class BlendingMode : uint8_t {
|
||||
//! material is opaque
|
||||
OPAQUE,
|
||||
//! material is transparent and color is alpha-pre-multiplied, affects diffuse lighting only
|
||||
TRANSPARENT,
|
||||
//! material is additive (e.g.: hologram)
|
||||
ADD,
|
||||
//! material is masked (i.e. alpha tested)
|
||||
MASKED,
|
||||
/**
|
||||
* material is transparent and color is alpha-pre-multiplied, affects specular lighting
|
||||
* when adding more entries, change the size of FRenderer::CommandKey::blending
|
||||
*/
|
||||
FADE,
|
||||
//! material darkens what's behind it
|
||||
MULTIPLY,
|
||||
//! material brightens what's behind it
|
||||
SCREEN,
|
||||
};
|
||||
|
||||
/**
|
||||
* How transparent objects are handled
|
||||
*/
|
||||
enum class TransparencyMode : uint8_t {
|
||||
//! the transparent object is drawn honoring the raster state
|
||||
DEFAULT,
|
||||
/**
|
||||
* the transparent object is first drawn in the depth buffer,
|
||||
* then in the color buffer, honoring the culling mode, but ignoring the depth test function
|
||||
*/
|
||||
TWO_PASSES_ONE_SIDE,
|
||||
|
||||
/**
|
||||
* the transparent object is drawn twice in the color buffer,
|
||||
* first with back faces only, then with front faces; the culling
|
||||
* mode is ignored. Can be combined with two-sided lighting
|
||||
*/
|
||||
TWO_PASSES_TWO_SIDES
|
||||
};
|
||||
|
||||
/**
|
||||
* Supported types of vertex domains.
|
||||
*/
|
||||
enum class VertexDomain : uint8_t {
|
||||
OBJECT, //!< vertices are in object space, default
|
||||
WORLD, //!< vertices are in world space
|
||||
VIEW, //!< vertices are in view space
|
||||
DEVICE //!< vertices are in normalized device space
|
||||
// when adding more entries, make sure to update VERTEX_DOMAIN_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* Vertex attribute types
|
||||
*/
|
||||
enum VertexAttribute : uint8_t {
|
||||
// Update hasIntegerTarget() in VertexBuffer when adding an attribute that will
|
||||
// be read as integers in the shaders
|
||||
|
||||
POSITION = 0, //!< XYZ position (float3)
|
||||
TANGENTS = 1, //!< tangent, bitangent and normal, encoded as a quaternion (float4)
|
||||
COLOR = 2, //!< vertex color (float4)
|
||||
UV0 = 3, //!< texture coordinates (float2)
|
||||
UV1 = 4, //!< texture coordinates (float2)
|
||||
BONE_INDICES = 5, //!< indices of 4 bones, as unsigned integers (uvec4)
|
||||
BONE_WEIGHTS = 6, //!< weights of the 4 bones (normalized float4)
|
||||
// -- we have 1 unused slot here --
|
||||
CUSTOM0 = 8,
|
||||
CUSTOM1 = 9,
|
||||
CUSTOM2 = 10,
|
||||
CUSTOM3 = 11,
|
||||
CUSTOM4 = 12,
|
||||
CUSTOM5 = 13,
|
||||
CUSTOM6 = 14,
|
||||
CUSTOM7 = 15,
|
||||
|
||||
// Aliases for legacy vertex morphing.
|
||||
// See RenderableManager::Builder::morphing().
|
||||
MORPH_POSITION_0 = CUSTOM0,
|
||||
MORPH_POSITION_1 = CUSTOM1,
|
||||
MORPH_POSITION_2 = CUSTOM2,
|
||||
MORPH_POSITION_3 = CUSTOM3,
|
||||
MORPH_TANGENTS_0 = CUSTOM4,
|
||||
MORPH_TANGENTS_1 = CUSTOM5,
|
||||
MORPH_TANGENTS_2 = CUSTOM6,
|
||||
MORPH_TANGENTS_3 = CUSTOM7,
|
||||
|
||||
// this is limited by driver::MAX_VERTEX_ATTRIBUTE_COUNT
|
||||
};
|
||||
|
||||
static constexpr size_t MAX_LEGACY_MORPH_TARGETS = 4;
|
||||
static constexpr size_t MAX_MORPH_TARGETS = 256; // this is limited by filament::CONFIG_MAX_MORPH_TARGET_COUNT
|
||||
static constexpr size_t MAX_CUSTOM_ATTRIBUTES = 8;
|
||||
|
||||
/**
|
||||
* Material domains
|
||||
*/
|
||||
enum class MaterialDomain : uint8_t {
|
||||
SURFACE = 0, //!< shaders applied to renderables
|
||||
POST_PROCESS = 1, //!< shaders applied to rendered buffers
|
||||
COMPUTE = 2, //!< compute shader
|
||||
};
|
||||
|
||||
/**
|
||||
* Specular occlusion
|
||||
*/
|
||||
enum class SpecularAmbientOcclusion : uint8_t {
|
||||
NONE = 0, //!< no specular occlusion
|
||||
SIMPLE = 1, //!< simple specular occlusion
|
||||
BENT_NORMALS = 2, //!< more accurate specular occlusion, requires bent normals
|
||||
};
|
||||
|
||||
/**
|
||||
* Refraction
|
||||
*/
|
||||
enum class RefractionMode : uint8_t {
|
||||
NONE = 0, //!< no refraction
|
||||
CUBEMAP = 1, //!< refracted rays go to the ibl cubemap
|
||||
SCREEN_SPACE = 2, //!< refracted rays go to screen space
|
||||
};
|
||||
|
||||
/**
|
||||
* Refraction type
|
||||
*/
|
||||
enum class RefractionType : uint8_t {
|
||||
SOLID = 0, //!< refraction through solid objects (e.g. a sphere)
|
||||
THIN = 1, //!< refraction through thin objects (e.g. window)
|
||||
};
|
||||
|
||||
/**
|
||||
* Reflection mode
|
||||
*/
|
||||
enum class ReflectionMode : uint8_t {
|
||||
DEFAULT = 0, //! reflections sample from the scene's IBL only
|
||||
SCREEN_SPACE = 1, //! reflections sample from screen space, and fallback to the scene's IBL
|
||||
};
|
||||
|
||||
// can't really use std::underlying_type<AttributeIndex>::type because the driver takes a uint32_t
|
||||
using AttributeBitset = utils::bitset32;
|
||||
|
||||
static constexpr size_t MATERIAL_PROPERTIES_COUNT = 27;
|
||||
enum class Property : uint8_t {
|
||||
BASE_COLOR, //!< float4, all shading models
|
||||
ROUGHNESS, //!< float, lit shading models only
|
||||
METALLIC, //!< float, all shading models, except unlit and cloth
|
||||
REFLECTANCE, //!< float, all shading models, except unlit and cloth
|
||||
AMBIENT_OCCLUSION, //!< float, lit shading models only, except subsurface and cloth
|
||||
CLEAR_COAT, //!< float, lit shading models only, except subsurface and cloth
|
||||
CLEAR_COAT_ROUGHNESS, //!< float, lit shading models only, except subsurface and cloth
|
||||
CLEAR_COAT_NORMAL, //!< float, lit shading models only, except subsurface and cloth
|
||||
ANISOTROPY, //!< float, lit shading models only, except subsurface and cloth
|
||||
ANISOTROPY_DIRECTION, //!< float3, lit shading models only, except subsurface and cloth
|
||||
THICKNESS, //!< float, subsurface shading model only
|
||||
SUBSURFACE_POWER, //!< float, subsurface shading model only
|
||||
SUBSURFACE_COLOR, //!< float3, subsurface and cloth shading models only
|
||||
SHEEN_COLOR, //!< float3, lit shading models only, except subsurface
|
||||
SHEEN_ROUGHNESS, //!< float3, lit shading models only, except subsurface and cloth
|
||||
SPECULAR_COLOR, //!< float3, specular-glossiness shading model only
|
||||
GLOSSINESS, //!< float, specular-glossiness shading model only
|
||||
EMISSIVE, //!< float4, all shading models
|
||||
NORMAL, //!< float3, all shading models only, except unlit
|
||||
POST_LIGHTING_COLOR, //!< float4, all shading models
|
||||
POST_LIGHTING_MIX_FACTOR,//!< float, all shading models
|
||||
CLIP_SPACE_TRANSFORM, //!< mat4, vertex shader only
|
||||
ABSORPTION, //!< float3, how much light is absorbed by the material
|
||||
TRANSMISSION, //!< float, how much light is refracted through the material
|
||||
IOR, //!< float, material's index of refraction
|
||||
MICRO_THICKNESS, //!< float, thickness of the thin layer
|
||||
BENT_NORMAL, //!< float3, all shading models only, except unlit
|
||||
|
||||
// when adding new Properties, make sure to update MATERIAL_PROPERTIES_COUNT
|
||||
};
|
||||
|
||||
using UserVariantFilterMask = uint32_t;
|
||||
|
||||
enum class UserVariantFilterBit : UserVariantFilterMask {
|
||||
DIRECTIONAL_LIGHTING = 0x01, //!< Directional lighting
|
||||
DYNAMIC_LIGHTING = 0x02, //!< Dynamic lighting
|
||||
SHADOW_RECEIVER = 0x04, //!< Shadow receiver
|
||||
SKINNING = 0x08, //!< Skinning
|
||||
FOG = 0x10, //!< Fog
|
||||
VSM = 0x20, //!< Variance shadow maps
|
||||
SSR = 0x40, //!< Screen-space reflections
|
||||
STE = 0x80, //!< Instanced stereo rendering
|
||||
ALL = 0xFF,
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
template<> struct utils::EnableBitMaskOperators<filament::UserVariantFilterBit>
|
||||
: public std::true_type {};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,501 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_MATERIALINSTANCE_H
|
||||
#define TNT_FILAMENT_MATERIALINSTANCE_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
#include <filament/Color.h>
|
||||
|
||||
#include <filament/MaterialEnums.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Material;
|
||||
class Texture;
|
||||
class TextureSampler;
|
||||
class UniformBuffer;
|
||||
class BufferInterfaceBlock;
|
||||
|
||||
class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
|
||||
template<size_t N>
|
||||
using StringLiteralHelper = const char[N];
|
||||
|
||||
struct StringLiteral {
|
||||
const char* UTILS_NONNULL data;
|
||||
size_t size;
|
||||
template<size_t N>
|
||||
StringLiteral(StringLiteralHelper<N> const& s) noexcept // NOLINT(google-explicit-constructor)
|
||||
: data(s), size(N - 1) {
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
using CullingMode = filament::backend::CullingMode;
|
||||
using TransparencyMode = filament::TransparencyMode;
|
||||
using DepthFunc = filament::backend::SamplerCompareFunc;
|
||||
using StencilCompareFunc = filament::backend::SamplerCompareFunc;
|
||||
using StencilOperation = filament::backend::StencilOperation;
|
||||
using StencilFace = filament::backend::StencilFace;
|
||||
|
||||
template<typename T>
|
||||
using is_supported_parameter_t = typename std::enable_if<
|
||||
std::is_same<float, T>::value ||
|
||||
std::is_same<int32_t, T>::value ||
|
||||
std::is_same<uint32_t, T>::value ||
|
||||
std::is_same<math::int2, T>::value ||
|
||||
std::is_same<math::int3, T>::value ||
|
||||
std::is_same<math::int4, T>::value ||
|
||||
std::is_same<math::uint2, T>::value ||
|
||||
std::is_same<math::uint3, T>::value ||
|
||||
std::is_same<math::uint4, T>::value ||
|
||||
std::is_same<math::float2, T>::value ||
|
||||
std::is_same<math::float3, T>::value ||
|
||||
std::is_same<math::float4, T>::value ||
|
||||
std::is_same<math::mat4f, T>::value ||
|
||||
// these types are slower as they need a layout conversion
|
||||
std::is_same<bool, T>::value ||
|
||||
std::is_same<math::bool2, T>::value ||
|
||||
std::is_same<math::bool3, T>::value ||
|
||||
std::is_same<math::bool4, T>::value ||
|
||||
std::is_same<math::mat3f, T>::value
|
||||
>::type;
|
||||
|
||||
/**
|
||||
* Creates a new MaterialInstance using another MaterialInstance as a template for initialization.
|
||||
* The new MaterialInstance is an instance of the same Material of the template instance and
|
||||
* must be destroyed just like any other MaterialInstance.
|
||||
*
|
||||
* @param other A MaterialInstance to use as a template for initializing a new instance
|
||||
* @param name A name for the new MaterialInstance or nullptr to use the template's name
|
||||
* @return A new MaterialInstance
|
||||
*/
|
||||
static MaterialInstance* UTILS_NONNULL duplicate(MaterialInstance const* UTILS_NONNULL other,
|
||||
const char* UTILS_NULLABLE name = nullptr) noexcept;
|
||||
|
||||
/**
|
||||
* @return the Material associated with this instance
|
||||
*/
|
||||
Material const* UTILS_NONNULL getMaterial() const noexcept;
|
||||
|
||||
/**
|
||||
* @return the name associated with this instance
|
||||
*/
|
||||
const char* UTILS_NONNULL getName() const noexcept;
|
||||
|
||||
/**
|
||||
* Set a uniform by name
|
||||
*
|
||||
* @param name Name of the parameter as defined by Material. Cannot be nullptr.
|
||||
* @param nameLength Length in `char` of the name parameter.
|
||||
* @param value Value of the parameter to set.
|
||||
* @throws utils::PreConditionPanic if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
void setParameter(const char* UTILS_NONNULL name, size_t nameLength, T const& value);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(StringLiteral name, T const& value) {
|
||||
setParameter<T>(name.data, name.size, value);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(const char* UTILS_NONNULL name, T const& value) {
|
||||
setParameter<T>(name, strlen(name), value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a uniform array by name
|
||||
*
|
||||
* @param name Name of the parameter array as defined by Material. Cannot be nullptr.
|
||||
* @param nameLength Length in `char` of the name parameter.
|
||||
* @param values Array of values to set to the named parameter array.
|
||||
* @param count Size of the array to set.
|
||||
* @throws utils::PreConditionPanic if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
void setParameter(const char* UTILS_NONNULL name, size_t nameLength,
|
||||
const T* UTILS_NONNULL values, size_t count);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(StringLiteral name, const T* UTILS_NONNULL values, size_t count) {
|
||||
setParameter<T>(name.data, name.size, values, count);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
template<typename T, typename = is_supported_parameter_t<T>>
|
||||
inline void setParameter(const char* UTILS_NONNULL name,
|
||||
const T* UTILS_NONNULL values, size_t count) {
|
||||
setParameter<T>(name, strlen(name), values, count);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a texture as the named parameter
|
||||
*
|
||||
* Note: Depth textures can't be sampled with a linear filter unless the comparison mode is set
|
||||
* to COMPARE_TO_TEXTURE.
|
||||
*
|
||||
* @param name Name of the parameter as defined by Material. Cannot be nullptr.
|
||||
* @param nameLength Length in `char` of the name parameter.
|
||||
* @param texture Non nullptr Texture object pointer.
|
||||
* @param sampler Sampler parameters.
|
||||
* @throws utils::PreConditionPanic if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
void setParameter(const char* UTILS_NONNULL name, size_t nameLength,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
inline void setParameter(StringLiteral name,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
|
||||
setParameter(name.data, name.size, texture, sampler);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
inline void setParameter(const char* UTILS_NONNULL name,
|
||||
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
|
||||
setParameter(name, strlen(name), texture, sampler);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an RGB color as the named parameter.
|
||||
* A conversion might occur depending on the specified type
|
||||
*
|
||||
* @param name Name of the parameter as defined by Material. Cannot be nullptr.
|
||||
* @param nameLength Length in `char` of the name parameter.
|
||||
* @param type Whether the color value is encoded as Linear or sRGB.
|
||||
* @param color Array of read, green, blue channels values.
|
||||
* @throws utils::PreConditionPanic if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
void setParameter(const char* UTILS_NONNULL name, size_t nameLength,
|
||||
RgbType type, math::float3 color);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
inline void setParameter(StringLiteral name, RgbType type, math::float3 color) {
|
||||
setParameter(name.data, name.size, type, color);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
inline void setParameter(const char* UTILS_NONNULL name, RgbType type, math::float3 color) {
|
||||
setParameter(name, strlen(name), type, color);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an RGBA color as the named parameter.
|
||||
* A conversion might occur depending on the specified type
|
||||
*
|
||||
* @param name Name of the parameter as defined by Material. Cannot be nullptr.
|
||||
* @param nameLength Length in `char` of the name parameter.
|
||||
* @param type Whether the color value is encoded as Linear or sRGB/A.
|
||||
* @param color Array of read, green, blue and alpha channels values.
|
||||
* @throws utils::PreConditionPanic if name doesn't exist or no-op if exceptions are disabled.
|
||||
*/
|
||||
void setParameter(const char* UTILS_NONNULL name, size_t nameLength,
|
||||
RgbaType type, math::float4 color);
|
||||
|
||||
/** inline helper to provide the name as a null-terminated string literal */
|
||||
inline void setParameter(StringLiteral name, RgbaType type, math::float4 color) {
|
||||
setParameter(name.data, name.size, type, color);
|
||||
}
|
||||
|
||||
/** inline helper to provide the name as a null-terminated C string */
|
||||
inline void setParameter(const char* UTILS_NONNULL name, RgbaType type, math::float4 color) {
|
||||
setParameter(name, strlen(name), type, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set-up a custom scissor rectangle; by default it is disabled.
|
||||
*
|
||||
* The scissor rectangle gets clipped by the View's viewport, in other words, the scissor
|
||||
* cannot affect fragments outside of the View's Viewport.
|
||||
*
|
||||
* Currently the scissor is not compatible with dynamic resolution and should always be
|
||||
* disabled when dynamic resolution is used.
|
||||
*
|
||||
* @param left left coordinate of the scissor box relative to the viewport
|
||||
* @param bottom bottom coordinate of the scissor box relative to the viewport
|
||||
* @param width width of the scissor box
|
||||
* @param height height of the scissor box
|
||||
*
|
||||
* @see unsetScissor
|
||||
* @see View::setViewport
|
||||
* @see View::setDynamicResolutionOptions
|
||||
*/
|
||||
void setScissor(uint32_t left, uint32_t bottom, uint32_t width, uint32_t height) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the scissor rectangle to its default disabled setting.
|
||||
*
|
||||
* Currently the scissor is not compatible with dynamic resolution and should always be
|
||||
* disabled when dynamic resolution is used.
|
||||
*
|
||||
* @see View::setDynamicResolutionOptions
|
||||
*/
|
||||
void unsetScissor() noexcept;
|
||||
|
||||
/**
|
||||
* Sets a polygon offset that will be applied to all renderables drawn with this material
|
||||
* instance.
|
||||
*
|
||||
* The value of the offset is scale * dz + r * constant, where dz is the change in depth
|
||||
* relative to the screen area of the triangle, and r is the smallest value that is guaranteed
|
||||
* to produce a resolvable offset for a given implementation. This offset is added before the
|
||||
* depth test.
|
||||
*
|
||||
* @warning using a polygon offset other than zero has a significant negative performance
|
||||
* impact, as most implementations have to disable early depth culling. DO NOT USE unless
|
||||
* absolutely necessary.
|
||||
*
|
||||
* @param scale scale factor used to create a variable depth offset for each triangle
|
||||
* @param constant scale factor used to create a constant depth offset for each triangle
|
||||
*/
|
||||
void setPolygonOffset(float scale, float constant) noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the minimum alpha value a fragment must have to not be discarded when the blend
|
||||
* mode is MASKED. Defaults to 0.4 if it has not been set in the parent Material. The specified
|
||||
* value should be between 0 and 1 and will be clamped if necessary.
|
||||
*/
|
||||
void setMaskThreshold(float threshold) noexcept;
|
||||
|
||||
/**
|
||||
* Gets the minimum alpha value a fragment must have to not be discarded when the blend
|
||||
* mode is MASKED
|
||||
*/
|
||||
float getMaskThreshold() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the screen space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing. The default value is set to 0.15. The specified value should be between
|
||||
* 0 and 1 and will be clamped if necessary.
|
||||
*/
|
||||
void setSpecularAntiAliasingVariance(float variance) noexcept;
|
||||
|
||||
/**
|
||||
* Gets the screen space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing.
|
||||
*/
|
||||
float getSpecularAntiAliasingVariance() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing. The default value is set to 0.2. The specified value should be between 0
|
||||
* and 1 and will be clamped if necessary.
|
||||
*/
|
||||
void setSpecularAntiAliasingThreshold(float threshold) noexcept;
|
||||
|
||||
/**
|
||||
* Gets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing.
|
||||
*/
|
||||
float getSpecularAntiAliasingThreshold() const noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables double-sided lighting if the parent Material has double-sided capability,
|
||||
* otherwise prints a warning. If double-sided lighting is enabled, backface culling is
|
||||
* automatically disabled.
|
||||
*/
|
||||
void setDoubleSided(bool doubleSided) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether double-sided lighting is enabled when the parent Material has double-sided
|
||||
* capability.
|
||||
*/
|
||||
bool isDoubleSided() const noexcept;
|
||||
|
||||
/**
|
||||
* Specifies how transparent objects should be rendered (default is DEFAULT).
|
||||
*/
|
||||
void setTransparencyMode(TransparencyMode mode) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the transparency mode.
|
||||
*/
|
||||
TransparencyMode getTransparencyMode() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default triangle culling state that was set on the material.
|
||||
*/
|
||||
void setCullingMode(CullingMode culling) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the face culling mode.
|
||||
*/
|
||||
CullingMode getCullingMode() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default color-buffer write state that was set on the material.
|
||||
*/
|
||||
void setColorWrite(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether color write is enabled.
|
||||
*/
|
||||
bool isColorWriteEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default depth-buffer write state that was set on the material.
|
||||
*/
|
||||
void setDepthWrite(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether depth write is enabled.
|
||||
*/
|
||||
bool isDepthWriteEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default depth testing state that was set on the material.
|
||||
*/
|
||||
void setDepthCulling(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default depth function state that was set on the material.
|
||||
*/
|
||||
void setDepthFunc(DepthFunc depthFunc) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the depth function state.
|
||||
*/
|
||||
DepthFunc getDepthFunc() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether depth culling is enabled.
|
||||
*/
|
||||
bool isDepthCullingEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default stencil-buffer write state that was set on the material.
|
||||
*/
|
||||
void setStencilWrite(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether stencil write is enabled.
|
||||
*/
|
||||
bool isStencilWriteEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the stencil comparison function (default is StencilCompareFunc::A).
|
||||
*
|
||||
* It's possible to set separate stencil comparison functions; one for front-facing polygons,
|
||||
* and one for back-facing polygons. The face parameter determines the comparison function(s)
|
||||
* updated by this call.
|
||||
*/
|
||||
void setStencilCompareFunction(StencilCompareFunc func,
|
||||
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the stencil fail operation (default is StencilOperation::KEEP).
|
||||
*
|
||||
* The stencil fail operation is performed to update values in the stencil buffer when the
|
||||
* stencil test fails.
|
||||
*
|
||||
* It's possible to set separate stencil fail operations; one for front-facing polygons, and one
|
||||
* for back-facing polygons. The face parameter determines the stencil fail operation(s) updated
|
||||
* by this call.
|
||||
*/
|
||||
void setStencilOpStencilFail(StencilOperation op,
|
||||
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the depth fail operation (default is StencilOperation::KEEP).
|
||||
*
|
||||
* The depth fail operation is performed to update values in the stencil buffer when the depth
|
||||
* test fails.
|
||||
*
|
||||
* It's possible to set separate depth fail operations; one for front-facing polygons, and one
|
||||
* for back-facing polygons. The face parameter determines the depth fail operation(s) updated
|
||||
* by this call.
|
||||
*/
|
||||
void setStencilOpDepthFail(StencilOperation op,
|
||||
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the depth-stencil pass operation (default is StencilOperation::KEEP).
|
||||
*
|
||||
* The depth-stencil pass operation is performed to update values in the stencil buffer when
|
||||
* both the stencil test and depth test pass.
|
||||
*
|
||||
* It's possible to set separate depth-stencil pass operations; one for front-facing polygons,
|
||||
* and one for back-facing polygons. The face parameter determines the depth-stencil pass
|
||||
* operation(s) updated by this call.
|
||||
*/
|
||||
void setStencilOpDepthStencilPass(StencilOperation op,
|
||||
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the stencil reference value (default is 0).
|
||||
*
|
||||
* The stencil reference value is the left-hand side for stencil comparison tests. It's also
|
||||
* used as the replacement stencil value when StencilOperation is REPLACE.
|
||||
*
|
||||
* It's possible to set separate stencil reference values; one for front-facing polygons, and
|
||||
* one for back-facing polygons. The face parameter determines the reference value(s) updated by
|
||||
* this call.
|
||||
*/
|
||||
void setStencilReferenceValue(uint8_t value,
|
||||
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the stencil read mask (default is 0xFF).
|
||||
*
|
||||
* The stencil read mask masks the bits of the values participating in the stencil comparison
|
||||
* test- both the value read from the stencil buffer and the reference value.
|
||||
*
|
||||
* It's possible to set separate stencil read masks; one for front-facing polygons, and one for
|
||||
* back-facing polygons. The face parameter determines the stencil read mask(s) updated by this
|
||||
* call.
|
||||
*/
|
||||
void setStencilReadMask(uint8_t readMask,
|
||||
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;
|
||||
|
||||
/**
|
||||
* Sets the stencil write mask (default is 0xFF).
|
||||
*
|
||||
* The stencil write mask masks the bits in the stencil buffer updated by stencil operations.
|
||||
*
|
||||
* It's possible to set separate stencil write masks; one for front-facing polygons, and one for
|
||||
* back-facing polygons. The face parameter determines the stencil write mask(s) updated by this
|
||||
* call.
|
||||
*/
|
||||
void setStencilWriteMask(uint8_t writeMask,
|
||||
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~MaterialInstance() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_MATERIALINSTANCE_H
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_MORPHTARGETBUFFER_H
|
||||
#define TNT_FILAMENT_MORPHTARGETBUFFER_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <filament/Engine.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* MorphTargetBuffer is used to hold morphing data (positions and tangents).
|
||||
*
|
||||
* Both positions and tangents are required.
|
||||
*
|
||||
*/
|
||||
class UTILS_PUBLIC MorphTargetBuffer : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Size of the morph targets in vertex counts.
|
||||
* @param vertexCount Number of vertex counts the morph targets can hold.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& vertexCount(size_t vertexCount) noexcept;
|
||||
|
||||
/**
|
||||
* Size of the morph targets in targets.
|
||||
* @param count Number of targets the morph targets can hold.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& count(size_t count) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the MorphTargetBuffer object and returns a pointer to it.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine to associate this MorphTargetBuffer with.
|
||||
*
|
||||
* @return pointer to the newly created object.
|
||||
*
|
||||
* @exception utils::PostConditionPanic if a runtime error occurred, such as running out of
|
||||
* memory or other resources.
|
||||
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
|
||||
*/
|
||||
MorphTargetBuffer* UTILS_NONNULL build(Engine& engine);
|
||||
private:
|
||||
friend class FMorphTargetBuffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates positions for the given morph target.
|
||||
*
|
||||
* This is equivalent to the float4 method, but uses 1.0 for the 4th component.
|
||||
*
|
||||
* Both positions and tangents must be provided.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine associated with this MorphTargetBuffer.
|
||||
* @param targetIndex the index of morph target to be updated.
|
||||
* @param positions pointer to at least "count" positions
|
||||
* @param count number of float3 vectors in positions
|
||||
* @param offset offset into the target buffer, expressed as a number of float4 vectors
|
||||
* @see setTangentsAt
|
||||
*/
|
||||
void setPositionsAt(Engine& engine, size_t targetIndex,
|
||||
math::float3 const* UTILS_NONNULL positions, size_t count, size_t offset = 0);
|
||||
|
||||
/**
|
||||
* Updates positions for the given morph target.
|
||||
*
|
||||
* Both positions and tangents must be provided.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine associated with this MorphTargetBuffer.
|
||||
* @param targetIndex the index of morph target to be updated.
|
||||
* @param positions pointer to at least "count" positions
|
||||
* @param count number of float4 vectors in positions
|
||||
* @param offset offset into the target buffer, expressed as a number of float4 vectors
|
||||
* @see setTangentsAt
|
||||
*/
|
||||
void setPositionsAt(Engine& engine, size_t targetIndex,
|
||||
math::float4 const* UTILS_NONNULL positions, size_t count, size_t offset = 0);
|
||||
|
||||
/**
|
||||
* Updates tangents for the given morph target.
|
||||
*
|
||||
* These quaternions must be represented as signed shorts, where real numbers in the [-1,+1]
|
||||
* range multiplied by 32767.
|
||||
*
|
||||
* @param engine Reference to the filament::Engine associated with this MorphTargetBuffer.
|
||||
* @param targetIndex the index of morph target to be updated.
|
||||
* @param tangents pointer to at least "count" tangents
|
||||
* @param count number of short4 quaternions in tangents
|
||||
* @param offset offset into the target buffer, expressed as a number of short4 vectors
|
||||
* @see setPositionsAt
|
||||
*/
|
||||
void setTangentsAt(Engine& engine, size_t targetIndex,
|
||||
math::short4 const* UTILS_NONNULL tangents, size_t count, size_t offset = 0);
|
||||
|
||||
/**
|
||||
* Returns the vertex count of this MorphTargetBuffer.
|
||||
* @return The number of vertices the MorphTargetBuffer holds.
|
||||
*/
|
||||
size_t getVertexCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the target count of this MorphTargetBuffer.
|
||||
* @return The number of targets the MorphTargetBuffer holds.
|
||||
*/
|
||||
size_t getCount() const noexcept;
|
||||
|
||||
protected:
|
||||
// prevent heap allocation
|
||||
~MorphTargetBuffer() = default;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif //TNT_FILAMENT_MORPHTARGETBUFFER_H
|
||||
607
dart_filament/native/include/filament/filament/Options.h
Normal file
607
dart_filament/native/include/filament/filament/Options.h
Normal file
@@ -0,0 +1,607 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_OPTIONS_H
|
||||
#define TNT_FILAMENT_OPTIONS_H
|
||||
|
||||
#include <filament/Color.h>
|
||||
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec3.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Texture;
|
||||
|
||||
/**
|
||||
* Generic quality level.
|
||||
*/
|
||||
enum class QualityLevel : uint8_t {
|
||||
LOW,
|
||||
MEDIUM,
|
||||
HIGH,
|
||||
ULTRA
|
||||
};
|
||||
|
||||
enum class BlendMode : uint8_t {
|
||||
OPAQUE,
|
||||
TRANSLUCENT
|
||||
};
|
||||
|
||||
/**
|
||||
* Dynamic resolution can be used to either reach a desired target frame rate
|
||||
* by lowering the resolution of a View, or to increase the quality when the
|
||||
* rendering is faster than the target frame rate.
|
||||
*
|
||||
* This structure can be used to specify the minimum scale factor used when
|
||||
* lowering the resolution of a View, and the maximum scale factor used when
|
||||
* increasing the resolution for higher quality rendering. The scale factors
|
||||
* can be controlled on each X and Y axis independently. By default, all scale
|
||||
* factors are set to 1.0.
|
||||
*
|
||||
* enabled: enable or disables dynamic resolution on a View
|
||||
*
|
||||
* homogeneousScaling: by default the system scales the major axis first. Set this to true
|
||||
* to force homogeneous scaling.
|
||||
*
|
||||
* minScale: the minimum scale in X and Y this View should use
|
||||
*
|
||||
* maxScale: the maximum scale in X and Y this View should use
|
||||
*
|
||||
* quality: upscaling quality.
|
||||
* LOW: 1 bilinear tap, Medium: 4 bilinear taps, High: 9 bilinear taps (tent)
|
||||
*
|
||||
* \note
|
||||
* Dynamic resolution is only supported on platforms where the time to render
|
||||
* a frame can be measured accurately. Dynamic resolution is currently only
|
||||
* supported on Android.
|
||||
*
|
||||
* @see Renderer::FrameRateOptions
|
||||
*
|
||||
*/
|
||||
struct DynamicResolutionOptions {
|
||||
math::float2 minScale = {0.5f, 0.5f}; //!< minimum scale factors in x and y %codegen_java_float%
|
||||
math::float2 maxScale = {1.0f, 1.0f}; //!< maximum scale factors in x and y %codegen_java_float%
|
||||
float sharpness = 0.9f; //!< sharpness when QualityLevel::MEDIUM or higher is used [0 (disabled), 1 (sharpest)]
|
||||
bool enabled = false; //!< enable or disable dynamic resolution
|
||||
bool homogeneousScaling = false; //!< set to true to force homogeneous scaling
|
||||
|
||||
/**
|
||||
* Upscaling quality
|
||||
* LOW: bilinear filtered blit. Fastest, poor quality
|
||||
* MEDIUM: AMD FidelityFX FSR1 w/ mobile optimizations
|
||||
* HIGH: AMD FidelityFX FSR1 w/ mobile optimizations
|
||||
* ULTRA: AMD FidelityFX FSR1
|
||||
* FSR1 require a well anti-aliased (MSAA or TAA), noise free scene.
|
||||
*
|
||||
* The default upscaling quality is set to LOW.
|
||||
*/
|
||||
QualityLevel quality = QualityLevel::LOW;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options to control the bloom effect
|
||||
*
|
||||
* enabled: Enable or disable the bloom post-processing effect. Disabled by default.
|
||||
*
|
||||
* levels: Number of successive blurs to achieve the blur effect, the minimum is 3 and the
|
||||
* maximum is 12. This value together with resolution influences the spread of the
|
||||
* blur effect. This value can be silently reduced to accommodate the original
|
||||
* image size.
|
||||
*
|
||||
* resolution: Resolution of bloom's minor axis. The minimum value is 2^levels and the
|
||||
* the maximum is lower of the original resolution and 4096. This parameter is
|
||||
* silently clamped to the minimum and maximum.
|
||||
* It is highly recommended that this value be smaller than the target resolution
|
||||
* after dynamic resolution is applied (horizontally and vertically).
|
||||
*
|
||||
* strength: how much of the bloom is added to the original image. Between 0 and 1.
|
||||
*
|
||||
* blendMode: Whether the bloom effect is purely additive (false) or mixed with the original
|
||||
* image (true).
|
||||
*
|
||||
* threshold: When enabled, a threshold at 1.0 is applied on the source image, this is
|
||||
* useful for artistic reasons and is usually needed when a dirt texture is used.
|
||||
*
|
||||
* dirt: A dirt/scratch/smudges texture (that can be RGB), which gets added to the
|
||||
* bloom effect. Smudges are visible where bloom occurs. Threshold must be
|
||||
* enabled for the dirt effect to work properly.
|
||||
*
|
||||
* dirtStrength: Strength of the dirt texture.
|
||||
*/
|
||||
struct BloomOptions {
|
||||
enum class BlendMode : uint8_t {
|
||||
ADD, //!< Bloom is modulated by the strength parameter and added to the scene
|
||||
INTERPOLATE //!< Bloom is interpolated with the scene using the strength parameter
|
||||
};
|
||||
Texture* dirt = nullptr; //!< user provided dirt texture %codegen_skip_json% %codegen_skip_javascript%
|
||||
float dirtStrength = 0.2f; //!< strength of the dirt texture %codegen_skip_json% %codegen_skip_javascript%
|
||||
float strength = 0.10f; //!< bloom's strength between 0.0 and 1.0
|
||||
uint32_t resolution = 384; //!< resolution of vertical axis (2^levels to 2048)
|
||||
uint8_t levels = 6; //!< number of blur levels (1 to 11)
|
||||
BlendMode blendMode = BlendMode::ADD; //!< how the bloom effect is applied
|
||||
bool threshold = true; //!< whether to threshold the source
|
||||
bool enabled = false; //!< enable or disable bloom
|
||||
float highlight = 1000.0f; //!< limit highlights to this value before bloom [10, +inf]
|
||||
|
||||
/**
|
||||
* Bloom quality level.
|
||||
* LOW (default): use a more optimized down-sampling filter, however there can be artifacts
|
||||
* with dynamic resolution, this can be alleviated by using the homogenous mode.
|
||||
* MEDIUM: Good balance between quality and performance.
|
||||
* HIGH: In this mode the bloom resolution is automatically increased to avoid artifacts.
|
||||
* This mode can be significantly slower on mobile, especially at high resolution.
|
||||
* This mode greatly improves the anamorphic bloom.
|
||||
*/
|
||||
QualityLevel quality = QualityLevel::LOW;
|
||||
|
||||
bool lensFlare = false; //!< enable screen-space lens flare
|
||||
bool starburst = true; //!< enable starburst effect on lens flare
|
||||
float chromaticAberration = 0.005f; //!< amount of chromatic aberration
|
||||
uint8_t ghostCount = 4; //!< number of flare "ghosts"
|
||||
float ghostSpacing = 0.6f; //!< spacing of the ghost in screen units [0, 1[
|
||||
float ghostThreshold = 10.0f; //!< hdr threshold for the ghosts
|
||||
float haloThickness = 0.1f; //!< thickness of halo in vertical screen units, 0 to disable
|
||||
float haloRadius = 0.4f; //!< radius of halo in vertical screen units [0, 0.5]
|
||||
float haloThreshold = 10.0f; //!< hdr threshold for the halo
|
||||
};
|
||||
|
||||
/**
|
||||
* Options to control large-scale fog in the scene
|
||||
*/
|
||||
struct FogOptions {
|
||||
/**
|
||||
* Distance in world units [m] from the camera to where the fog starts ( >= 0.0 )
|
||||
*/
|
||||
float distance = 0.0f;
|
||||
|
||||
/**
|
||||
* Distance in world units [m] after which the fog calculation is disabled.
|
||||
* This can be used to exclude the skybox, which is desirable if it already contains clouds or
|
||||
* fog. The default value is +infinity which applies the fog to everything.
|
||||
*
|
||||
* Note: The SkyBox is typically at a distance of 1e19 in world space (depending on the near
|
||||
* plane distance and projection used though).
|
||||
*/
|
||||
float cutOffDistance = INFINITY;
|
||||
|
||||
/**
|
||||
* fog's maximum opacity between 0 and 1
|
||||
*/
|
||||
float maximumOpacity = 1.0f;
|
||||
|
||||
/**
|
||||
* Fog's floor in world units [m]. This sets the "sea level".
|
||||
*/
|
||||
float height = 0.0f;
|
||||
|
||||
/**
|
||||
* How fast the fog dissipates with altitude. heightFalloff has a unit of [1/m].
|
||||
* It can be expressed as 1/H, where H is the altitude change in world units [m] that causes a
|
||||
* factor 2.78 (e) change in fog density.
|
||||
*
|
||||
* A falloff of 0 means the fog density is constant everywhere and may result is slightly
|
||||
* faster computations.
|
||||
*/
|
||||
float heightFalloff = 1.0f;
|
||||
|
||||
/**
|
||||
* Fog's color is used for ambient light in-scattering, a good value is
|
||||
* to use the average of the ambient light, possibly tinted towards blue
|
||||
* for outdoors environments. Color component's values should be between 0 and 1, values
|
||||
* above one are allowed but could create a non energy-conservative fog (this is dependant
|
||||
* on the IBL's intensity as well).
|
||||
*
|
||||
* We assume that our fog has no absorption and therefore all the light it scatters out
|
||||
* becomes ambient light in-scattering and has lost all directionality, i.e.: scattering is
|
||||
* isotropic. This somewhat simulates Rayleigh scattering.
|
||||
*
|
||||
* This value is used as a tint instead, when fogColorFromIbl is enabled.
|
||||
*
|
||||
* @see fogColorFromIbl
|
||||
*/
|
||||
LinearColor color = { 1.0f, 1.0f, 1.0f };
|
||||
|
||||
/**
|
||||
* Extinction factor in [1/m] at altitude 'height'. The extinction factor controls how much
|
||||
* light is absorbed and out-scattered per unit of distance. Each unit of extinction reduces
|
||||
* the incoming light to 37% of its original value.
|
||||
*
|
||||
* Note: The extinction factor is related to the fog density, it's usually some constant K times
|
||||
* the density at sea level (more specifically at fog height). The constant K depends on
|
||||
* the composition of the fog/atmosphere.
|
||||
*
|
||||
* For historical reason this parameter is called `density`.
|
||||
*/
|
||||
float density = 0.1f;
|
||||
|
||||
/**
|
||||
* Distance in world units [m] from the camera where the Sun in-scattering starts.
|
||||
*/
|
||||
float inScatteringStart = 0.0f;
|
||||
|
||||
/**
|
||||
* Very inaccurately simulates the Sun's in-scattering. That is, the light from the sun that
|
||||
* is scattered (by the fog) towards the camera.
|
||||
* Size of the Sun in-scattering (>0 to activate). Good values are >> 1 (e.g. ~10 - 100).
|
||||
* Smaller values result is a larger scattering size.
|
||||
*/
|
||||
float inScatteringSize = -1.0f;
|
||||
|
||||
/**
|
||||
* The fog color will be sampled from the IBL in the view direction and tinted by `color`.
|
||||
* Depending on the scene this can produce very convincing results.
|
||||
*
|
||||
* This simulates a more anisotropic phase-function.
|
||||
*
|
||||
* `fogColorFromIbl` is ignored when skyTexture is specified.
|
||||
*
|
||||
* @see skyColor
|
||||
*/
|
||||
bool fogColorFromIbl = false;
|
||||
|
||||
/**
|
||||
* skyTexture must be a mipmapped cubemap. When provided, the fog color will be sampled from
|
||||
* this texture, higher resolution mip levels will be used for objects at the far clip plane,
|
||||
* and lower resolution mip levels for objects closer to the camera. The skyTexture should
|
||||
* typically be heavily blurred; a typical way to produce this texture is to blur the base
|
||||
* level with a strong gaussian filter or even an irradiance filter and then generate mip
|
||||
* levels as usual. How blurred the base level is somewhat of an artistic decision.
|
||||
*
|
||||
* This simulates a more anisotropic phase-function.
|
||||
*
|
||||
* `fogColorFromIbl` is ignored when skyTexture is specified.
|
||||
*
|
||||
* @see Texture
|
||||
* @see fogColorFromIbl
|
||||
*/
|
||||
Texture* skyColor = nullptr; //!< %codegen_skip_json% %codegen_skip_javascript%
|
||||
|
||||
/**
|
||||
* Enable or disable large-scale fog
|
||||
*/
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options to control Depth of Field (DoF) effect in the scene.
|
||||
*
|
||||
* cocScale can be used to set the depth of field blur independently from the camera
|
||||
* aperture, e.g. for artistic reasons. This can be achieved by setting:
|
||||
* cocScale = cameraAperture / desiredDoFAperture
|
||||
*
|
||||
* @see Camera
|
||||
*/
|
||||
struct DepthOfFieldOptions {
|
||||
enum class Filter : uint8_t {
|
||||
NONE,
|
||||
UNUSED,
|
||||
MEDIAN
|
||||
};
|
||||
float cocScale = 1.0f; //!< circle of confusion scale factor (amount of blur)
|
||||
float cocAspectRatio = 1.0f; //!< width/height aspect ratio of the circle of confusion (simulate anamorphic lenses)
|
||||
float maxApertureDiameter = 0.01f; //!< maximum aperture diameter in meters (zero to disable rotation)
|
||||
bool enabled = false; //!< enable or disable depth of field effect
|
||||
Filter filter = Filter::MEDIAN; //!< filter to use for filling gaps in the kernel
|
||||
bool nativeResolution = false; //!< perform DoF processing at native resolution
|
||||
/**
|
||||
* Number of of rings used by the gather kernels. The number of rings affects quality
|
||||
* and performance. The actual number of sample per pixel is defined
|
||||
* as (ringCount * 2 - 1)^2. Here are a few commonly used values:
|
||||
* 3 rings : 25 ( 5x 5 grid)
|
||||
* 4 rings : 49 ( 7x 7 grid)
|
||||
* 5 rings : 81 ( 9x 9 grid)
|
||||
* 17 rings : 1089 (33x33 grid)
|
||||
*
|
||||
* With a maximum circle-of-confusion of 32, it is never necessary to use more than 17 rings.
|
||||
*
|
||||
* Usually all three settings below are set to the same value, however, it is often
|
||||
* acceptable to use a lower ring count for the "fast tiles", which improves performance.
|
||||
* Fast tiles are regions of the screen where every pixels have a similar
|
||||
* circle-of-confusion radius.
|
||||
*
|
||||
* A value of 0 means default, which is 5 on desktop and 3 on mobile.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
uint8_t foregroundRingCount = 0; //!< number of kernel rings for foreground tiles
|
||||
uint8_t backgroundRingCount = 0; //!< number of kernel rings for background tiles
|
||||
uint8_t fastGatherRingCount = 0; //!< number of kernel rings for fast tiles
|
||||
/** @}*/
|
||||
|
||||
/**
|
||||
* maximum circle-of-confusion in pixels for the foreground, must be in [0, 32] range.
|
||||
* A value of 0 means default, which is 32 on desktop and 24 on mobile.
|
||||
*/
|
||||
uint16_t maxForegroundCOC = 0;
|
||||
|
||||
/**
|
||||
* maximum circle-of-confusion in pixels for the background, must be in [0, 32] range.
|
||||
* A value of 0 means default, which is 32 on desktop and 24 on mobile.
|
||||
*/
|
||||
uint16_t maxBackgroundCOC = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options to control the vignetting effect.
|
||||
*/
|
||||
struct VignetteOptions {
|
||||
float midPoint = 0.5f; //!< high values restrict the vignette closer to the corners, between 0 and 1
|
||||
float roundness = 0.5f; //!< controls the shape of the vignette, from a rounded rectangle (0.0), to an oval (0.5), to a circle (1.0)
|
||||
float feather = 0.5f; //!< softening amount of the vignette effect, between 0 and 1
|
||||
LinearColorA color = {0.0f, 0.0f, 0.0f, 1.0f}; //!< color of the vignette effect, alpha is currently ignored
|
||||
bool enabled = false; //!< enables or disables the vignette effect
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure used to set the precision of the color buffer and related quality settings.
|
||||
*
|
||||
* @see setRenderQuality, getRenderQuality
|
||||
*/
|
||||
struct RenderQuality {
|
||||
/**
|
||||
* Sets the quality of the HDR color buffer.
|
||||
*
|
||||
* A quality of HIGH or ULTRA means using an RGB16F or RGBA16F color buffer. This means
|
||||
* colors in the LDR range (0..1) have a 10 bit precision. A quality of LOW or MEDIUM means
|
||||
* using an R11G11B10F opaque color buffer or an RGBA16F transparent color buffer. With
|
||||
* R11G11B10F colors in the LDR range have a precision of either 6 bits (red and green
|
||||
* channels) or 5 bits (blue channel).
|
||||
*/
|
||||
QualityLevel hdrColorBuffer = QualityLevel::HIGH;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for screen space Ambient Occlusion (SSAO) and Screen Space Cone Tracing (SSCT)
|
||||
* @see setAmbientOcclusionOptions()
|
||||
*/
|
||||
struct AmbientOcclusionOptions {
|
||||
float radius = 0.3f; //!< Ambient Occlusion radius in meters, between 0 and ~10.
|
||||
float power = 1.0f; //!< Controls ambient occlusion's contrast. Must be positive.
|
||||
float bias = 0.0005f; //!< Self-occlusion bias in meters. Use to avoid self-occlusion. Between 0 and a few mm.
|
||||
float resolution = 0.5f;//!< How each dimension of the AO buffer is scaled. Must be either 0.5 or 1.0.
|
||||
float intensity = 1.0f; //!< Strength of the Ambient Occlusion effect.
|
||||
float bilateralThreshold = 0.05f; //!< depth distance that constitute an edge for filtering
|
||||
QualityLevel quality = QualityLevel::LOW; //!< affects # of samples used for AO.
|
||||
QualityLevel lowPassFilter = QualityLevel::MEDIUM; //!< affects AO smoothness
|
||||
QualityLevel upsampling = QualityLevel::LOW; //!< affects AO buffer upsampling quality
|
||||
bool enabled = false; //!< enables or disables screen-space ambient occlusion
|
||||
bool bentNormals = false; //!< enables bent normals computation from AO, and specular AO
|
||||
float minHorizonAngleRad = 0.0f; //!< min angle in radian to consider
|
||||
/**
|
||||
* Screen Space Cone Tracing (SSCT) options
|
||||
* Ambient shadows from dominant light
|
||||
*/
|
||||
struct Ssct {
|
||||
float lightConeRad = 1.0f; //!< full cone angle in radian, between 0 and pi/2
|
||||
float shadowDistance = 0.3f; //!< how far shadows can be cast
|
||||
float contactDistanceMax = 1.0f; //!< max distance for contact
|
||||
float intensity = 0.8f; //!< intensity
|
||||
math::float3 lightDirection = { 0, -1, 0 }; //!< light direction
|
||||
float depthBias = 0.01f; //!< depth bias in world units (mitigate self shadowing)
|
||||
float depthSlopeBias = 0.01f; //!< depth slope bias (mitigate self shadowing)
|
||||
uint8_t sampleCount = 4; //!< tracing sample count, between 1 and 255
|
||||
uint8_t rayCount = 1; //!< # of rays to trace, between 1 and 255
|
||||
bool enabled = false; //!< enables or disables SSCT
|
||||
};
|
||||
Ssct ssct; // %codegen_skip_javascript% %codegen_java_flatten%
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for Multi-Sample Anti-aliasing (MSAA)
|
||||
* @see setMultiSampleAntiAliasingOptions()
|
||||
*/
|
||||
struct MultiSampleAntiAliasingOptions {
|
||||
bool enabled = false; //!< enables or disables msaa
|
||||
|
||||
/**
|
||||
* sampleCount number of samples to use for multi-sampled anti-aliasing.\n
|
||||
* 0: treated as 1
|
||||
* 1: no anti-aliasing
|
||||
* n: sample count. Effective sample could be different depending on the
|
||||
* GPU capabilities.
|
||||
*/
|
||||
uint8_t sampleCount = 4;
|
||||
|
||||
/**
|
||||
* custom resolve improves quality for HDR scenes, but may impact performance.
|
||||
*/
|
||||
bool customResolve = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for Temporal Anti-aliasing (TAA)
|
||||
* Most TAA parameters are extremely costly to change, as they will trigger the TAA post-process
|
||||
* shaders to be recompiled. These options should be changed or set during initialization.
|
||||
* `filterWidth`, `feedback` and `jitterPattern`, however, can be changed at any time.
|
||||
*
|
||||
* `feedback` of 0.1 effectively accumulates a maximum of 19 samples in steady state.
|
||||
* see "A Survey of Temporal Antialiasing Techniques" by Lei Yang and all for more information.
|
||||
*
|
||||
* @see setTemporalAntiAliasingOptions()
|
||||
*/
|
||||
struct TemporalAntiAliasingOptions {
|
||||
float filterWidth = 1.0f; //!< reconstruction filter width typically between 0.2 (sharper, aliased) and 1.5 (smoother)
|
||||
float feedback = 0.12f; //!< history feedback, between 0 (maximum temporal AA) and 1 (no temporal AA).
|
||||
float lodBias = -1.0f; //!< texturing lod bias (typically -1 or -2)
|
||||
float sharpness = 0.0f; //!< post-TAA sharpen, especially useful when upscaling is true.
|
||||
bool enabled = false; //!< enables or disables temporal anti-aliasing
|
||||
bool upscaling = false; //!< 4x TAA upscaling. Disables Dynamic Resolution. [BETA]
|
||||
|
||||
enum class BoxType : uint8_t {
|
||||
AABB, //!< use an AABB neighborhood
|
||||
VARIANCE, //!< use the variance of the neighborhood (not recommended)
|
||||
AABB_VARIANCE //!< use both AABB and variance
|
||||
};
|
||||
|
||||
enum class BoxClipping : uint8_t {
|
||||
ACCURATE, //!< Accurate box clipping
|
||||
CLAMP, //!< clamping
|
||||
NONE //!< no rejections (use for debugging)
|
||||
};
|
||||
|
||||
enum class JitterPattern : uint8_t {
|
||||
RGSS_X4, //! 4-samples, rotated grid sampling
|
||||
UNIFORM_HELIX_X4, //! 4-samples, uniform grid in helix sequence
|
||||
HALTON_23_X8, //! 8-samples of halton 2,3
|
||||
HALTON_23_X16, //! 16-samples of halton 2,3
|
||||
HALTON_23_X32 //! 32-samples of halton 2,3
|
||||
};
|
||||
|
||||
bool filterHistory = true; //!< whether to filter the history buffer
|
||||
bool filterInput = true; //!< whether to apply the reconstruction filter to the input
|
||||
bool useYCoCg = false; //!< whether to use the YcoCg color-space for history rejection
|
||||
BoxType boxType = BoxType::AABB; //!< type of color gamut box
|
||||
BoxClipping boxClipping = BoxClipping::ACCURATE; //!< clipping algorithm
|
||||
JitterPattern jitterPattern = JitterPattern::HALTON_23_X16; //! Jitter Pattern
|
||||
float varianceGamma = 1.0f; //! High values increases ghosting artefact, lower values increases jittering, range [0.75, 1.25]
|
||||
|
||||
bool preventFlickering = false; //!< adjust the feedback dynamically to reduce flickering
|
||||
bool historyReprojection = true; //!< whether to apply history reprojection (debug option)
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for Screen-space Reflections.
|
||||
* @see setScreenSpaceReflectionsOptions()
|
||||
*/
|
||||
struct ScreenSpaceReflectionsOptions {
|
||||
float thickness = 0.1f; //!< ray thickness, in world units
|
||||
float bias = 0.01f; //!< bias, in world units, to prevent self-intersections
|
||||
float maxDistance = 3.0f; //!< maximum distance, in world units, to raycast
|
||||
float stride = 2.0f; //!< stride, in texels, for samples along the ray.
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for the screen-space guard band.
|
||||
* A guard band can be enabled to avoid some artifacts towards the edge of the screen when
|
||||
* using screen-space effects such as SSAO. Enabling the guard band reduces performance slightly.
|
||||
* Currently the guard band can only be enabled or disabled.
|
||||
*/
|
||||
struct GuardBandOptions {
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* List of available post-processing anti-aliasing techniques.
|
||||
* @see setAntiAliasing, getAntiAliasing, setSampleCount
|
||||
*/
|
||||
enum class AntiAliasing : uint8_t {
|
||||
NONE, //!< no anti aliasing performed as part of post-processing
|
||||
FXAA //!< FXAA is a low-quality but very efficient type of anti-aliasing. (default).
|
||||
};
|
||||
|
||||
/**
|
||||
* List of available post-processing dithering techniques.
|
||||
*/
|
||||
enum class Dithering : uint8_t {
|
||||
NONE, //!< No dithering
|
||||
TEMPORAL //!< Temporal dithering (default)
|
||||
};
|
||||
|
||||
/**
|
||||
* List of available shadow mapping techniques.
|
||||
* @see setShadowType
|
||||
*/
|
||||
enum class ShadowType : uint8_t {
|
||||
PCF, //!< percentage-closer filtered shadows (default)
|
||||
VSM, //!< variance shadows
|
||||
DPCF, //!< PCF with contact hardening simulation
|
||||
PCSS, //!< PCF with soft shadows and contact hardening
|
||||
PCFd, // for debugging only, don't use.
|
||||
};
|
||||
|
||||
/**
|
||||
* View-level options for VSM Shadowing.
|
||||
* @see setVsmShadowOptions()
|
||||
* @warning This API is still experimental and subject to change.
|
||||
*/
|
||||
struct VsmShadowOptions {
|
||||
/**
|
||||
* Sets the number of anisotropic samples to use when sampling a VSM shadow map. If greater
|
||||
* than 0, mipmaps will automatically be generated each frame for all lights.
|
||||
*
|
||||
* The number of anisotropic samples = 2 ^ vsmAnisotropy.
|
||||
*/
|
||||
uint8_t anisotropy = 0;
|
||||
|
||||
/**
|
||||
* Whether to generate mipmaps for all VSM shadow maps.
|
||||
*/
|
||||
bool mipmapping = false;
|
||||
|
||||
/**
|
||||
* The number of MSAA samples to use when rendering VSM shadow maps.
|
||||
* Must be a power-of-two and greater than or equal to 1. A value of 1 effectively turns
|
||||
* off MSAA.
|
||||
* Higher values may not be available depending on the underlying hardware.
|
||||
*/
|
||||
uint8_t msaaSamples = 1;
|
||||
|
||||
/**
|
||||
* Whether to use a 32-bits or 16-bits texture format for VSM shadow maps. 32-bits
|
||||
* precision is rarely needed, but it does reduces light leaks as well as "fading"
|
||||
* of the shadows in some situations. Setting highPrecision to true for a single
|
||||
* shadow map will double the memory usage of all shadow maps.
|
||||
*/
|
||||
bool highPrecision = false;
|
||||
|
||||
/**
|
||||
* VSM minimum variance scale, must be positive.
|
||||
*/
|
||||
float minVarianceScale = 0.5f;
|
||||
|
||||
/**
|
||||
* VSM light bleeding reduction amount, between 0 and 1.
|
||||
*/
|
||||
float lightBleedReduction = 0.15f;
|
||||
};
|
||||
|
||||
/**
|
||||
* View-level options for DPCF and PCSS Shadowing.
|
||||
* @see setSoftShadowOptions()
|
||||
* @warning This API is still experimental and subject to change.
|
||||
*/
|
||||
struct SoftShadowOptions {
|
||||
/**
|
||||
* Globally scales the penumbra of all DPCF and PCSS shadows
|
||||
* Acceptable values are greater than 0
|
||||
*/
|
||||
float penumbraScale = 1.0f;
|
||||
|
||||
/**
|
||||
* Globally scales the computed penumbra ratio of all DPCF and PCSS shadows.
|
||||
* This effectively controls the strength of contact hardening effect and is useful for
|
||||
* artistic purposes. Higher values make the shadows become softer faster.
|
||||
* Acceptable values are equal to or greater than 1.
|
||||
*/
|
||||
float penumbraRatioScale = 1.0f;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for stereoscopic (multi-eye) rendering.
|
||||
*/
|
||||
struct StereoscopicOptions {
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif //TNT_FILAMENT_OPTIONS_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user