From b570b32337cd08ca3cf6eece683d2e23171bcbd5 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 28 Feb 2019 16:28:49 +0100 Subject: [PATCH 1/8] Added some comments on #594 --- src/rlgl.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index 52165150a..717801e39 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -728,6 +728,8 @@ typedef struct DrawCall { //unsigned int vaoId; // Vertex Array id to be used on the draw //unsigned int shaderId; // Shader id to be used on the draw unsigned int textureId; // Texture id to be used on the draw + // TODO: Support additional texture units? + //Matrix projection; // Projection matrix for this draw //Matrix modelview; // Modelview matrix for this draw } DrawCall; @@ -4132,9 +4134,13 @@ static void DrawBuffersDefault(void) glUniformMatrix4fv(currentShader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP)); glUniform4f(currentShader.locs[LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f); - glUniform1i(currentShader.locs[LOC_MAP_DIFFUSE], 0); + glUniform1i(currentShader.locs[LOC_MAP_DIFFUSE], 0); // Provided value refers to the texture unit (active) + + // TODO: Support additional texture units on custom shader + //if (currentShader->locs[LOC_MAP_SPECULAR] > 0) glUniform1i(currentShader.locs[LOC_MAP_SPECULAR], 1); + //if (currentShader->locs[LOC_MAP_NORMAL] > 0) glUniform1i(currentShader.locs[LOC_MAP_NORMAL], 2); - // NOTE: Additional map textures not considered for default buffers drawing + // NOTE: Right now additional map textures not considered for default buffers drawing int vertexOffset = 0; @@ -4164,6 +4170,10 @@ static void DrawBuffersDefault(void) for (int i = 0; i < drawsCounter; i++) { glBindTexture(GL_TEXTURE_2D, draws[i].textureId); + + // TODO: Find some way to bind additional textures --> Use global texture IDs? Register them on draw[i]? + //if (currentShader->locs[LOC_MAP_SPECULAR] > 0) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textureUnit1_id); } + //if (currentShader->locs[LOC_MAP_SPECULAR] > 0) { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textureUnit2_id); } if ((draws[i].mode == RL_LINES) || (draws[i].mode == RL_TRIANGLES)) glDrawArrays(draws[i].mode, vertexOffset, draws[i].vertexCount); else From a90c9c5ade55684cfd46b18f91edeb9208d1f7d7 Mon Sep 17 00:00:00 2001 From: Skabunkel <> Date: Thu, 28 Feb 2019 17:50:47 +0100 Subject: [PATCH 2/8] Removed unnecessary --- src/text.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/text.c b/src/text.c index 24f51f97a..f228a4df4 100644 --- a/src/text.c +++ b/src/text.c @@ -688,8 +688,7 @@ void UnloadFont(Font font) { for (int i = 0; i < font.charsCount; i++) { - if(font.chars[i].data != NULL) - free(font.chars[i].data); + free(font.chars[i].data); } UnloadTexture(font.texture); free(font.chars); From d679a97e926dce81ed64dc40612b6ac8f78ea264 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 28 Feb 2019 18:39:58 +0100 Subject: [PATCH 3/8] Removed some NULL pointer checks --- src/rlgl.h | 22 +++++++++++----------- src/textures.c | 7 ++----- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index 717801e39..a89878397 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -2727,18 +2727,18 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform) // Unload mesh data from CPU and GPU void rlUnloadMesh(Mesh *mesh) { - if (mesh->vertices != NULL) free(mesh->vertices); - if (mesh->texcoords != NULL) free(mesh->texcoords); - if (mesh->normals != NULL) free(mesh->normals); - if (mesh->colors != NULL) free(mesh->colors); - if (mesh->tangents != NULL) free(mesh->tangents); - if (mesh->texcoords2 != NULL) free(mesh->texcoords2); - if (mesh->indices != NULL) free(mesh->indices); + free(mesh->vertices); + free(mesh->texcoords); + free(mesh->normals); + free(mesh->colors); + free(mesh->tangents); + free(mesh->texcoords2); + free(mesh->indices); - if (mesh->baseVertices != NULL) free(mesh->baseVertices); - if (mesh->baseNormals != NULL) free(mesh->baseNormals); - if (mesh->weightBias != NULL) free(mesh->weightBias); - if (mesh->weightId != NULL) free(mesh->weightId); + free(mesh->baseVertices); + free(mesh->baseNormals); + free(mesh->weightBias); + free(mesh->weightId); rlDeleteBuffers(mesh->vboId[0]); // vertex rlDeleteBuffers(mesh->vboId[1]); // texcoords diff --git a/src/textures.c b/src/textures.c index d79cb3cb0..01c9b2f5d 100644 --- a/src/textures.c +++ b/src/textures.c @@ -353,7 +353,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int { TraceLog(LOG_WARNING, "[%s] RAW image data can not be read, wrong requested format or size", fileName); - if (image.data != NULL) free(image.data); + free(image.data); } else { @@ -414,10 +414,7 @@ RenderTexture2D LoadRenderTexture(int width, int height) // Unload image from CPU memory (RAM) void UnloadImage(Image image) { - if (image.data != NULL) free(image.data); - - // NOTE: It becomes anoying every time a texture is loaded - //TraceLog(LOG_INFO, "Unloaded image data"); + free(image.data); } // Unload texture from GPU memory (VRAM) From 50da9f623e1c2c70530653399a9acf1092e30a1d Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 28 Feb 2019 22:25:27 +0100 Subject: [PATCH 4/8] Return value in GetClipboardText() --- src/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core.c b/src/core.c index bff926009..dc60eee46 100644 --- a/src/core.c +++ b/src/core.c @@ -990,6 +990,8 @@ const char *GetClipboardText(void) { #if defined(PLATFORM_DESKTOP) return glfwGetClipboardString(window); +#else + return NULL; #endif } From 36fa0207f29a4f3e2ed1a8e4d541bcd14e09ff2b Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 28 Feb 2019 23:06:37 +0100 Subject: [PATCH 5/8] Some spacing review --- src/core.c | 2 +- src/rlgl.h | 6 +++--- src/shapes.c | 2 +- src/text.c | 2 -- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core.c b/src/core.c index dc60eee46..4e195ec7b 100644 --- a/src/core.c +++ b/src/core.c @@ -4321,7 +4321,7 @@ static void *EventThread(void *arg) // Button parsing if (event.type == EV_KEY) { - if((event.code == BTN_TOUCH) || (event.code == BTN_LEFT)) + if ((event.code == BTN_TOUCH) || (event.code == BTN_LEFT)) { currentMouseStateEvdev[MOUSE_LEFT_BUTTON] = event.value; if (event.value > 0) gestureEvent.touchAction = TOUCH_DOWN; diff --git a/src/rlgl.h b/src/rlgl.h index a89878397..b8895a085 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1624,7 +1624,7 @@ void rlglInit(int width, int height) if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) texMirrorClampSupported = true; // Debug marker support - if(strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true; + if (strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true; } #if defined(_WIN32) && defined(_MSC_VER) @@ -1804,7 +1804,7 @@ void rlLoadExtensions(void *loader) #if defined(GRAPHICS_API_OPENGL_21) if (GLAD_GL_VERSION_2_1) TraceLog(LOG_INFO, "OpenGL 2.1 profile supported"); #elif defined(GRAPHICS_API_OPENGL_33) - if(GLAD_GL_VERSION_3_3) TraceLog(LOG_INFO, "OpenGL 3.3 Core profile supported"); + if (GLAD_GL_VERSION_3_3) TraceLog(LOG_INFO, "OpenGL 3.3 Core profile supported"); else TraceLog(LOG_ERROR, "OpenGL 3.3 Core profile not supported"); #endif #endif @@ -4095,7 +4095,7 @@ static void UpdateBuffersDefault(void) // Another option: map the buffer object into client's memory // Probably this code could be moved somewhere else... // vertexData[currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - // if(vertexData[currentBuffer].vertices) + // if (vertexData[currentBuffer].vertices) // { // Update vertex data // } diff --git a/src/shapes.c b/src/shapes.c index 837e4e9c4..fd28f3a3b 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -400,7 +400,7 @@ void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color) { if (lineThick > rec.width || lineThick > rec.height) { - if(rec.width > rec.height) lineThick = (int)rec.height/2; + if (rec.width > rec.height) lineThick = (int)rec.height/2; else if (rec.width < rec.height) lineThick = (int)rec.width/2; } diff --git a/src/text.c b/src/text.c index f228a4df4..d44cdd11a 100644 --- a/src/text.c +++ b/src/text.c @@ -1326,13 +1326,11 @@ int TextToInteger(const char *text) return result; } - //---------------------------------------------------------------------------------- //---------------------------------------------------------------------------------- // Module specific Functions Definition //---------------------------------------------------------------------------------- - #if defined(SUPPORT_FILEFORMAT_FNT) // Load a BMFont file (AngelCode font file) static Font LoadBMFont(const char *fileName) From d7fd6e0f1a4106690af7901173f421ea2fb1ea40 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 2 Mar 2019 14:29:04 +0100 Subject: [PATCH 6/8] Corrected issue with possible 0 division Reported on rfxgen tool, it crashes on some parameters --- src/raudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index 5f42222e5..d24cc8e67 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -367,7 +367,7 @@ static mal_uint32 OnAudioBufferDSPRead(mal_dsp *pDSP, mal_uint32 frameCount, voi { AudioBuffer *audioBuffer = (AudioBuffer *)pUserData; - mal_uint32 subBufferSizeInFrames = audioBuffer->bufferSizeInFrames/2; + mal_uint32 subBufferSizeInFrames = (audioBuffer->bufferSizeInFrames > 1)? audioBuffer->bufferSizeInFrames/2 : audioBuffer->bufferSizeInFrames; mal_uint32 currentSubBufferIndex = audioBuffer->frameCursorPos/subBufferSizeInFrames; if (currentSubBufferIndex > 1) From 2e99c6cefbaacf03d71ad10c03a60fbb49c46aa1 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 4 Mar 2019 22:58:20 +0100 Subject: [PATCH 7/8] ADDED: IsWindowResized() --- src/core.c | 15 +++++++++++++++ src/raylib.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/core.c b/src/core.c index 4e195ec7b..e6852eef7 100644 --- a/src/core.c +++ b/src/core.c @@ -273,6 +273,7 @@ static GLFWwindow *window; // Native window (graphic device #endif static bool windowReady = false; // Check if window has been initialized successfully static bool windowMinimized = false; // Check if window has been minimized +static bool windowResized = false; // Check if window has been resized static const char *windowTitle = NULL; // Window text title... static unsigned int displayWidth, displayHeight;// Display width and height (monitor, device-screen, LCD, ...) @@ -742,6 +743,16 @@ bool IsWindowMinimized(void) #endif } +// Check if window has been resized +bool IsWindowResized(void) +{ +#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP) + return windowResized; +#else + return false; +#endif +} + // Check if window is currently hidden bool IsWindowHidden(void) { @@ -3137,6 +3148,8 @@ static void PollInputEvents(void) gamepadAxisCount = axisCount; } } + + windowResized = false; #if defined(SUPPORT_EVENTS_WAITING) glfwWaitEvents(); @@ -3414,6 +3427,8 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height) currentHeight = height; // NOTE: Postprocessing texture is not scaled to new size + + windowResized = true; } // GLFW3 WindowIconify Callback, runs when window is minimized/restored diff --git a/src/raylib.h b/src/raylib.h index 17a6efc6a..9fdcf2d8c 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -865,6 +865,7 @@ RLAPI bool WindowShouldClose(void); // Check if KE RLAPI void CloseWindow(void); // Close window and unload OpenGL context RLAPI bool IsWindowReady(void); // Check if window has been initialized successfully RLAPI bool IsWindowMinimized(void); // Check if window has been minimized (or lost focus) +RLAPI bool IsWindowResized(void); // Check if window has been resized RLAPI bool IsWindowHidden(void); // Check if window is currently hidden RLAPI void ToggleFullscreen(void); // Toggle fullscreen mode (only PLATFORM_DESKTOP) RLAPI void UnhideWindow(void); // Show the window From 2f97a3f83531867511f65f2b2ed894706cfb2e06 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 5 Mar 2019 16:46:48 +0100 Subject: [PATCH 8/8] Proposed Model struct review --- src/raylib.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/raylib.h b/src/raylib.h index 9fdcf2d8c..cc4612041 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -342,6 +342,15 @@ typedef struct Model { Mesh mesh; // Vertex data buffers (RAM and VRAM) Matrix transform; // Local transform matrix Material material; // Shader and textures data + /* + Mesh *meshes; // Vertex data buffers (RAM and VRAM) + int meshCount; + + Material *materials; // Shader and textures data + int materialCount; + + int *meshMaterial; // Material assigned to every mesh + */ } Model; // Ray type (useful for raycast) @@ -1180,7 +1189,7 @@ RLAPI const char *TextSubtext(const char *text, int position, int length); RLAPI const char *TextReplace(char *text, const char *replace, const char *by); // Replace text string (memory should be freed!) RLAPI const char *TextInsert(const char *text, const char *insert, int position); // Insert text in a position (memory should be freed!) RLAPI const char *TextJoin(const char **textList, int count, const char *delimiter); // Join text strings with delimiter -RLAPI const char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings +RLAPI const char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor! RLAPI int TextFindIndex(const char *text, const char *find); // Find first text occurrence within a string RLAPI const char *TextToUpper(const char *text); // Get upper case version of provided string