diff --git a/build.zig b/build.zig index 60356a215..77681e0e6 100644 --- a/build.zig +++ b/build.zig @@ -205,7 +205,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. raylib.root_module.addCMacro("PLATFORM_DRM", ""); raylib.root_module.addCMacro("EGL_NO_X11", ""); raylib.root_module.addCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", ""); - } else if (target.result.abi == .android) { + } else if (target.result.abi.isAndroid()) { //these are the only tag options per https://developer.android.com/ndk/guides/other_build_systems const hostTuple = switch (builtin.target.os.tag) { @@ -215,7 +215,14 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. else => @panic("unsupported host OS"), }; - const androidTriple = try target.result.linuxTriple(b.allocator); + const androidTriple = switch (target.result.cpu.arch) { + .x86 => "i686-linux-android", + .x86_64 => "x86_64-linux-android", + .arm => "arm-linux-androideabi", + .aarch64 => "aarch64-linux-android", + .riscv64 => "riscv64-linux-android", + else => error.InvalidAndroidTarget, + } catch @panic("invalid android target!"); const androidNdkPathString: []const u8 = options.android_ndk; if (androidNdkPathString.len < 1) @panic("no ndk path provided and ANDROID_NDK_HOME is not set"); const androidApiLevel: []const u8 = options.android_api_version; diff --git a/src/external/rprand.h b/src/external/rprand.h index ded6708e5..ba8368726 100644 --- a/src/external/rprand.h +++ b/src/external/rprand.h @@ -90,7 +90,7 @@ #define RPRAND_FREE(ptr) free(ptr) #endif -// Simple log system to avoid RPNG_LOG() calls if required +// Simple log system to avoid log calls if required // NOTE: Avoiding those calls, also avoids const strings memory usage #define RPRAND_SHOW_LOG_INFO #if defined(RPNG_SHOW_LOG_INFO) diff --git a/src/rcore.c b/src/rcore.c index 5b2679c95..fdc4b54be 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -2314,9 +2314,12 @@ FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool // WARNING: files.count is not reseted to 0 after unloading void UnloadDirectoryFiles(FilePathList files) { - for (unsigned int i = 0; i < files.capacity; i++) RL_FREE(files.paths[i]); + if (files.paths != NULL) + { + for (unsigned int i = 0; i < files.capacity; i++) RL_FREE(files.paths[i]); - RL_FREE(files.paths); + RL_FREE(files.paths); + } } // Create directories (including full path requested), returns 0 on success @@ -3738,7 +3741,7 @@ static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const // Scan all files and directories recursively from a base path static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *files, const char *filter) { - char path[MAX_FILEPATH_LENGTH] = { 0 }; + static char path[MAX_FILEPATH_LENGTH] = { 0 }; memset(path, 0, MAX_FILEPATH_LENGTH); struct dirent *dp = NULL; diff --git a/src/rlgl.h b/src/rlgl.h index 955051228..1a757d949 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -56,8 +56,8 @@ * * #define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack * #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported -* #define RL_CULL_DISTANCE_NEAR 0.001 // Default projection matrix near cull distance -* #define RL_CULL_DISTANCE_FAR 10000.0 // Default projection matrix far cull distance +* #define RL_CULL_DISTANCE_NEAR 0.05 // Default projection matrix near cull distance +* #define RL_CULL_DISTANCE_FAR 4000.0 // Default projection matrix far cull distance * * When loading a shader, the following vertex attributes and uniform * location names are tried to be set automatically: @@ -239,10 +239,10 @@ // Projection matrix culling #ifndef RL_CULL_DISTANCE_NEAR - #define RL_CULL_DISTANCE_NEAR 0.001 // Default near cull distance + #define RL_CULL_DISTANCE_NEAR 0.05 // Default near cull distance #endif #ifndef RL_CULL_DISTANCE_FAR - #define RL_CULL_DISTANCE_FAR 10000.0 // Default far cull distance + #define RL_CULL_DISTANCE_FAR 4000.0 // Default far cull distance #endif // Texture parameters (equivalent to OpenGL defines) diff --git a/src/rmodels.c b/src/rmodels.c index a7f48fd11..61ac9504d 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -496,12 +496,18 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color vertices[2] = (Vector3){ cosslice*vertices[2].x - sinslice*vertices[2].z, vertices[2].y, sinslice*vertices[2].x + cosslice*vertices[2].z }; // Rotation matrix around y axis vertices[3] = (Vector3){ cosslice*vertices[3].x - sinslice*vertices[3].z, vertices[3].y, sinslice*vertices[3].x + cosslice*vertices[3].z }; + rlNormal3f(vertices[0].x, vertices[0].y, vertices[0].z); rlVertex3f(vertices[0].x, vertices[0].y, vertices[0].z); + rlNormal3f(vertices[3].x, vertices[3].y, vertices[3].z); rlVertex3f(vertices[3].x, vertices[3].y, vertices[3].z); + rlNormal3f(vertices[1].x, vertices[1].y, vertices[1].z); rlVertex3f(vertices[1].x, vertices[1].y, vertices[1].z); + rlNormal3f(vertices[0].x, vertices[0].y, vertices[0].z); rlVertex3f(vertices[0].x, vertices[0].y, vertices[0].z); + rlNormal3f(vertices[2].x, vertices[2].y, vertices[2].z); rlVertex3f(vertices[2].x, vertices[2].y, vertices[2].z); + rlNormal3f(vertices[3].x, vertices[3].y, vertices[3].z); rlVertex3f(vertices[3].x, vertices[3].y, vertices[3].z); } @@ -1423,9 +1429,17 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform) rlEnableTexture(material.maps[MATERIAL_MAP_DIFFUSE].texture.id); - rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.vertices); + if (mesh.animVertices) + rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.animVertices); + else + rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.vertices); + rlEnableStatePointer(GL_TEXTURE_COORD_ARRAY, mesh.texcoords); - rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.normals); + if (mesh.normals) + rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.animNormalss); + else + rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.normals); + rlEnableStatePointer(GL_COLOR_ARRAY, mesh.colors); rlPushMatrix(); @@ -5815,15 +5829,17 @@ static Model LoadGLTF(const char *fileName) for (unsigned int p = 0; p < mesh->primitives_count; p++) { + bool hasJoints = false; + // NOTE: We only support primitives defined by triangles if (mesh->primitives[p].type != cgltf_primitive_type_triangles) continue; for (unsigned int j = 0; j < mesh->primitives[p].attributes_count; j++) { // NOTE: JOINTS_1 + WEIGHT_1 will be used for +4 joints influencing a vertex -> Not supported by raylib - if (mesh->primitives[p].attributes[j].type == cgltf_attribute_type_joints) // JOINTS_n (vec4: 4 bones max per vertex / u8, u16) { + hasJoints = true; cgltf_accessor *attribute = mesh->primitives[p].attributes[j].data; // NOTE: JOINTS_n can only be vec4 and u8/u16 @@ -5924,6 +5940,34 @@ static Model LoadGLTF(const char *fileName) } } + // check if we are animated, and the mesh was not given any bone assignments, but is the child of a bone node + // in this case we need to fully attach all the verts to the parent bone so it will animate with the bone. + if (data->skins_count > 0 && !hasJoints && node->parent != NULL && node->parent->mesh == NULL) + { + int parentBoneId = -1; + for (int joint = 0; joint < model.boneCount; joint++) + { + if (data->skins[0].joints[joint] == node->parent) + { + parentBoneId = joint; + break; + } + } + + if (parentBoneId >= 0) + { + model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount * 4, sizeof(unsigned char)); + model.meshes[meshIndex].boneWeights = RL_CALLOC(model.meshes[meshIndex].vertexCount * 4, sizeof(float)); + + for (int vertexIndex = 0; vertexIndex < model.meshes[meshIndex].vertexCount * 4; vertexIndex += 4) + { + model.meshes[meshIndex].boneIds[vertexIndex] = (unsigned char)parentBoneId; + model.meshes[meshIndex].boneWeights[vertexIndex] = 1.0f; + } + } + + } + // Animated vertex data model.meshes[meshIndex].animVertices = RL_CALLOC(model.meshes[meshIndex].vertexCount*3, sizeof(float)); memcpy(model.meshes[meshIndex].animVertices, model.meshes[meshIndex].vertices, model.meshes[meshIndex].vertexCount*3*sizeof(float)); diff --git a/src/rtext.c b/src/rtext.c index e7bc341f1..4ee9b34b6 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -161,6 +161,10 @@ extern void LoadFontDefault(void) { #define BIT_CHECK(a,b) ((a) & (1u << (b))) + // check to see if we have allready allocated the font for an image, and if we don't need to upload, then just return + if (defaultFont.glyphs != NULL && !isGpuReady) + return; + // NOTE: Using UTF-8 encoding table for Unicode U+0000..U+00FF Basic Latin + Latin-1 Supplement // Ref: http://www.utf8-chartable.de/unicode-utf8-table.pl @@ -256,8 +260,19 @@ extern void LoadFontDefault(void) counter++; } - - if (isGpuReady) defaultFont.texture = LoadTextureFromImage(imFont); + + if (isGpuReady) + { + defaultFont.texture = LoadTextureFromImage(imFont); + + // we have already loaded the font glyph data an image, and the GPU is ready, we are done + // if we don't do this, we will leak memory by reallocating the glyphs and rects + if (defaultFont.glyphs != NULL) + { + UnloadImage(imFont); + return; + } + } // Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, glyphCount //------------------------------------------------------------------------------ @@ -282,7 +297,7 @@ extern void LoadFontDefault(void) testPosX += (int)(defaultFont.recs[i].width + (float)charsDivisor); - if (testPosX >= defaultFont.texture.width) + if (testPosX >= imFont.width) { currentLine++; currentPosX = 2*charsDivisor + charsWidth[i];