Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MODELS] Disable GPU skinning for MacOS platform #4348

Merged
merged 24 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c35e253
Update raylib_api.* by CI
github-actions[bot] Mar 17, 2024
49a7a64
Merge branch 'master' of github.com:JeffM2501/raylib
JeffM2501 May 2, 2024
a126ff8
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 May 11, 2024
841e03d
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 May 12, 2024
ee3f5ec
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 May 16, 2024
661004a
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 May 19, 2024
02da1bb
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Jun 9, 2024
81d145f
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Jun 23, 2024
6060519
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Jun 25, 2024
8235c10
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Jun 28, 2024
ce7f191
Merge branch 'master' of github.com:JeffM2501/raylib
JeffM2501 Jun 28, 2024
5a8acfa
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Jun 28, 2024
95d0826
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Jul 1, 2024
7229666
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Jul 28, 2024
c8d907e
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Aug 8, 2024
cc6a9bd
Merge branch 'master' of github.com:JeffM2501/raylib
JeffM2501 Aug 8, 2024
f59f208
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Aug 21, 2024
d0a2f9a
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Aug 24, 2024
167401e
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Aug 24, 2024
3f1052d
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Sep 22, 2024
d924980
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Sep 27, 2024
8648e6e
Merge branch 'master' of github.com:raysan5/raylib
JeffM2501 Sep 29, 2024
d3767a3
Disable GPU skinning on MacOS
JeffM2501 Sep 29, 2024
44157b8
Update raylib_api.* by CI
github-actions[bot] Sep 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/models/models_gpu_skinning.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2024 Daniel Holden (@orangeduck)
*
* Note: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
*
********************************************************************************************/

Expand Down
2 changes: 1 addition & 1 deletion parser/output/raylib_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -11104,7 +11104,7 @@
},
{
"name": "UpdateModelAnimationBoneMatrices",
"description": "Update model animation mesh bone matrices",
"description": "Update model animation mesh bone matrices (Note GPU skinning does not work on Mac)",
"returnType": "void",
"params": [
{
Expand Down
2 changes: 1 addition & 1 deletion parser/output/raylib_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7621,7 +7621,7 @@ return {
},
{
name = "UpdateModelAnimationBoneMatrices",
description = "Update model animation mesh bone matrices",
description = "Update model animation mesh bone matrices (Note GPU skinning does not work on Mac)",
returnType = "void",
params = {
{type = "Model", name = "model"},
Expand Down
2 changes: 1 addition & 1 deletion parser/output/raylib_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4230,7 +4230,7 @@ Function 503: IsModelAnimationValid() (2 input parameters)
Function 504: UpdateModelAnimationBoneMatrices() (3 input parameters)
Name: UpdateModelAnimationBoneMatrices
Return type: void
Description: Update model animation mesh bone matrices
Description: Update model animation mesh bone matrices (Note GPU skinning does not work on Mac)
Param[1]: model (type: Model)
Param[2]: anim (type: ModelAnimation)
Param[3]: frame (type: int)
Expand Down
2 changes: 1 addition & 1 deletion parser/output/raylib_api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,7 @@
<Param type="Model" name="model" desc="" />
<Param type="ModelAnimation" name="anim" desc="" />
</Function>
<Function name="UpdateModelAnimationBoneMatrices" retType="void" paramCount="3" desc="Update model animation mesh bone matrices">
<Function name="UpdateModelAnimationBoneMatrices" retType="void" paramCount="3" desc="Update model animation mesh bone matrices (Note GPU skinning does not work on Mac)">
<Param type="Model" name="model" desc="" />
<Param type="ModelAnimation" name="anim" desc="" />
<Param type="int" name="frame" desc="" />
Expand Down
387 changes: 387 additions & 0 deletions projects/VS2022/examples/models_gpu_skinning.vcxproj

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions projects/VS2022/raylib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shapes_splines_drawing", "e
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shapes_top_down_lights", "examples\shapes_top_down_lights.vcxproj", "{703BE7BA-5B99-4F70-806D-3A259F6A991E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "models_gpu_skinning", "examples\models_gpu_skinning.vcxproj", "{8245DAD9-D402-4D5C-8F45-32229CD3B263}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug.DLL|x64 = Debug.DLL|x64
Expand Down Expand Up @@ -2531,6 +2533,22 @@ Global
{703BE7BA-5B99-4F70-806D-3A259F6A991E}.Release|x64.Build.0 = Release|x64
{703BE7BA-5B99-4F70-806D-3A259F6A991E}.Release|x86.ActiveCfg = Release|Win32
{703BE7BA-5B99-4F70-806D-3A259F6A991E}.Release|x86.Build.0 = Release|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug.DLL|x64.Build.0 = Debug.DLL|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug|x64.ActiveCfg = Debug|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug|x64.Build.0 = Debug|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug|x86.ActiveCfg = Debug|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Debug|x86.Build.0 = Debug|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release.DLL|x64.ActiveCfg = Release.DLL|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release.DLL|x64.Build.0 = Release.DLL|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release.DLL|x86.Build.0 = Release.DLL|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release|x64.ActiveCfg = Release|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release|x64.Build.0 = Release|x64
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release|x86.ActiveCfg = Release|Win32
{8245DAD9-D402-4D5C-8F45-32229CD3B263}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2682,6 +2700,7 @@ Global
{D8026C60-CCBC-45DF-9085-BF21569EB414} = {DA049009-21FF-4AC0-84E4-830DD1BCD0CE}
{DF25E545-00FF-4E64-844C-7DF98991F901} = {278D8859-20B1-428F-8448-064F46E1F021}
{703BE7BA-5B99-4F70-806D-3A259F6A991E} = {278D8859-20B1-428F-8448-064F46E1F021}
{8245DAD9-D402-4D5C-8F45-32229CD3B263} = {AF5BEC5C-1F2B-4DA8-B12D-D09FE569237C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E926C768-6307-4423-A1EC-57E95B1FAB29}
Expand Down
15 changes: 12 additions & 3 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,18 @@
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR 3
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT 4
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 6
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 7
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 8
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 6

// The mac OpenGL drivers do not support more than 8 VBOs, so we can't support GPU animations
#ifndef __APPLE__
#define RL_SUPPORT_MESH_ANIMATION_VBO
#endif

#ifdef RL_SUPPORT_MESH_ANIMATION_VBO
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 7
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
#endif


// Default shader vertex attribute names to set location points
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
Expand Down
2 changes: 1 addition & 1 deletion src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame);
RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data
RLAPI void UnloadModelAnimations(ModelAnimation *animations, int animCount); // Unload animation array data
RLAPI bool IsModelAnimationValid(Model model, ModelAnimation anim); // Check model animation skeleton match
RLAPI void UpdateModelAnimationBoneMatrices(Model model, ModelAnimation anim, int frame); // Update model animation mesh bone matrices
RLAPI void UpdateModelAnimationBoneMatrices(Model model, ModelAnimation anim, int frame); // Update model animation mesh bone matrices (Note GPU skinning does not work on Mac)

// Collision detection functions
RLAPI bool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2); // Check collision between two spheres
Expand Down
14 changes: 9 additions & 5 deletions src/rlgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,17 @@
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5
#endif
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 6
#endif
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 6
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 7
#endif
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 7
#endif
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 8
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
#endif


//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -4170,8 +4171,11 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);

#ifdef RL_SUPPORT_MESH_ANIMATION_VBO
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS);
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS);
#endif

// NOTE: If some attrib name is no found on the shader, it locations becomes -1

Expand Down
18 changes: 13 additions & 5 deletions src/rmodels.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,10 @@ void UploadMesh(Mesh *mesh, bool dynamic)
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR] = 0; // Vertex buffer: colors
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT] = 0; // Vertex buffer: tangents
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2] = 0; // Vertex buffer: texcoords2
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES] = 0; // Vertex buffer: indices
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS] = 0; // Vertex buffer: boneIds
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS] = 0; // Vertex buffer: boneWeights
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES] = 0; // Vertex buffer: indices


#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
mesh->vaoId = rlLoadVertexArray();
Expand Down Expand Up @@ -1340,7 +1341,8 @@ void UploadMesh(Mesh *mesh, bool dynamic)
rlSetVertexAttributeDefault(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, value, SHADER_ATTRIB_VEC2, 2);
rlDisableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2);
}


#ifdef RL_SUPPORT_MESH_ANIMATION_VBO
if (mesh->boneIds != NULL)
{
// Enable vertex attribute: boneIds (shader-location = 6)
Expand Down Expand Up @@ -1372,6 +1374,7 @@ void UploadMesh(Mesh *mesh, bool dynamic)
rlSetVertexAttributeDefault(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS, value, SHADER_ATTRIB_VEC4, 2);
rlDisableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS);
}
#endif

if (mesh->indices != NULL)
{
Expand Down Expand Up @@ -1485,13 +1488,14 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)

// Upload model normal matrix (if locations available)
if (material.shader.locs[SHADER_LOC_MATRIX_NORMAL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_NORMAL], MatrixTranspose(MatrixInvert(matModel)));


#ifdef RL_SUPPORT_MESH_ANIMATION_VBO
// Upload Bone Transforms
if (material.shader.locs[SHADER_LOC_BONE_MATRICES] != -1 && mesh.boneMatrices)
{
rlSetUniformMatrices(material.shader.locs[SHADER_LOC_BONE_MATRICES], mesh.boneMatrices, mesh.boneCount);
}

#endif
//-----------------------------------------------------

// Bind active texture maps (if available)
Expand Down Expand Up @@ -1570,7 +1574,8 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02], 2, RL_FLOAT, 0, 0, 0);
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02]);
}


#ifdef RL_SUPPORT_MESH_ANIMATION_VBO
// Bind mesh VBO data: vertex bone ids (shader-location = 6, if available)
if (material.shader.locs[SHADER_LOC_VERTEX_BONEIDS] != -1)
{
Expand All @@ -1586,6 +1591,7 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS], 4, RL_FLOAT, 0, 0, 0);
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS]);
}
#endif

if (mesh.indices != NULL) rlEnableVertexBufferElement(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES]);
}
Expand Down Expand Up @@ -1729,11 +1735,13 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
// Upload model normal matrix (if locations available)
if (material.shader.locs[SHADER_LOC_MATRIX_NORMAL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_NORMAL], MatrixTranspose(MatrixInvert(matModel)));

#ifdef RL_SUPPORT_MESH_ANIMATION_VBO
// Upload Bone Transforms
if (material.shader.locs[SHADER_LOC_BONE_MATRICES] != -1 && mesh.boneMatrices)
{
rlSetUniformMatrices(material.shader.locs[SHADER_LOC_BONE_MATRICES], mesh.boneMatrices, mesh.boneCount);
}
#endif

//-----------------------------------------------------

Expand Down
Loading