Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Commits
79ededf7
Commit
79ededf7
authored
3 years ago
by
Trevor Hollmann
Browse files
Options
Downloads
Patches
Plain Diff
[
#63
] Define and document material bitmask handling.
parent
9c61a205
No related branches found
No related tags found
1 merge request
!51
Resolve "Laden mehrer Meshes mit Materials und Textures"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/asset_loader/include/vkcv/asset/asset_loader.hpp
+24
-14
24 additions, 14 deletions
modules/asset_loader/include/vkcv/asset/asset_loader.hpp
modules/asset_loader/src/vkcv/asset/asset_loader.cpp
+7
-0
7 additions, 0 deletions
modules/asset_loader/src/vkcv/asset/asset_loader.cpp
with
31 additions
and
14 deletions
modules/asset_loader/include/vkcv/asset/asset_loader.hpp
+
24
−
14
View file @
79ededf7
...
...
@@ -55,20 +55,6 @@ enum class PrimitiveMode : uint8_t {
/* The indices in the index buffer can be of different bit width. */
enum
class
IndexType
:
uint8_t
{
UNDEFINED
=
0
,
UINT8
=
1
,
UINT16
=
2
,
UINT32
=
3
};
/* Flags for the bit-mask in the Material struct. Use the bitof() macro to
* translate the enums value when checking a flag of the mask:
* Material mat = ...;
* if (mat.textureMask & bitflag(PBRTextureTarget::baseColor)) {...} */
// TODO Maybe it's easier to replace the bitflag() macro with a "hasTexture()"
// macro that already combines the logical AND with the bitflag?
enum
class
PBRTextureTarget
{
baseColor
=
1
,
metalRough
=
2
,
normal
=
4
,
occlusion
=
8
,
emissive
=
16
};
/* This macro translates the index of an enum in the defined order to an
* integer with a single bit set in the corresponding place. */
#define bitflag(ENUM) (0x1u << (ENUM))
typedef
struct
{
// TODO define struct for samplers (low priority)
// NOTE: glTF defines samplers based on OpenGL, which can not be
...
...
@@ -101,6 +87,30 @@ typedef struct {
struct
{
float
r
,
g
,
b
;
}
emissiveFactor
;
}
Material
;
/* Flags for the bit-mask in the Material struct. To check if a material has a
* certain texture target, you can use the hasTexture() function below, passing
* the material struct and the enum. */
enum
class
PBRTextureTarget
{
baseColor
=
1
,
metalRough
=
2
,
normal
=
4
,
occlusion
=
8
,
emissive
=
16
};
/* This macro translates the index of an enum in the defined order to an
* integer with a single bit set in the corresponding place. It is used for
* working with the bitmask of texture targets ("textureMask") in the Material
* struct:
* Material mat = ...;
* if (mat.textureMask & bitflag(PBRTextureTarget::baseColor)) {...}
* However, this logic is also encapsulated in the convenience-function
* materialHasTexture() so users of the asset loader module can avoid direct
* contact with bit-level operations. */
#define bitflag(ENUM) (0x1u << ((unsigned)(ENUM)))
/* To signal that a certain texture target is active in a Material struct, its
* bit is set in the textureMask. You can use this function to check that:
* Material mat = ...;
* if (materialHasTexture(&mat, baseColor)) {...} */
bool
materialHasTexture
(
const
Material
*
const
m
,
const
PBRTextureTarget
t
);
/* This struct represents one (possibly the only) part of a mesh. There is
* always one vertexBuffer and zero or one indexBuffer (indexed rendering is
* common but not always used). If there is no index buffer, this is indicated
...
...
This diff is collapsed.
Click to expand it.
modules/asset_loader/src/vkcv/asset/asset_loader.cpp
+
7
−
0
View file @
79ededf7
...
...
@@ -241,6 +241,13 @@ int loadMesh(const std::string &path, Mesh &mesh) {
return
1
;
}
bool
materialHasTexture
(
const
Material
*
const
m
,
const
PBRTextureTarget
t
)
{
return
m
->
textureMask
&
bitflag
(
t
);
}
int
loadScene
(
const
std
::
string
&
path
,
Scene
&
scene
){
fx
::
gltf
::
Document
sceneObjects
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment