| 1 |
/* |
| 2 |
* Copyright (C) 2021 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <cgltf.h> |
| 18 |
|
| 19 |
#include <math/vec4.h> |
| 20 |
|
| 21 |
namespace filament { class VertexBuffer; } |
| 22 |
|
| 23 |
namespace gltfio { |
| 24 |
|
| 25 |
/** |
| 26 |
* Internal helper that examines a cgltf primitive and generates data suitable for Filament's |
| 27 |
* TANGENTS attribute. This has been designed to be run as a JobSystem job, but clients are not |
| 28 |
* required to do so. |
| 29 |
*/ |
| 30 |
struct TangentsJob { |
| 31 |
static constexpr int kMorphTargetUnused = -1; |
| 32 |
|
| 33 |
// The inputs to the procedure. The prim is owned by the client, which should ensure that it |
| 34 |
// stays alive for the duration of the procedure. |
| 35 |
struct InputParams { |
| 36 |
const cgltf_primitive* prim; |
| 37 |
const int morphTargetIndex = kMorphTargetUnused; |
| 38 |
}; |
| 39 |
|
| 40 |
// The context of the procedure. These fields are not used by the procedure but are provided as |
| 41 |
// a convenience to clients. You can think of this as a scratch space for clients. |
| 42 |
struct Context { |
| 43 |
filament::VertexBuffer* const vb; |
| 44 |
const uint8_t slot; |
| 45 |
}; |
| 46 |
|
| 47 |
// The outputs of the procedure. The results array gets malloc'd by the procedure, so clients |
| 48 |
// should remember to free it. |
| 49 |
struct OutputParams { |
| 50 |
cgltf_size vertexCount; |
| 51 |
filament::math::short4* results; |
| 52 |
}; |
| 53 |
|
| 54 |
// Clients might want to track the jobs in an array, so the arguments are bundled into a struct. |
| 55 |
struct Params { |
| 56 |
InputParams in; |
| 57 |
Context context; |
| 58 |
OutputParams out; |
| 59 |
}; |
| 60 |
|
| 61 |
// Performs tangents generation synchronously. This can be invoked from inside a job if desired. |
| 62 |
// The parameters structure is owned by the client. |
| 63 |
static void run(Params* params); |
| 64 |
}; |
| 65 |
|
| 66 |
} // namespace gltfio |