From 621965cb8cbb743820dd66bdde61fc3c79b156a8 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 6 May 2019 16:38:58 +0200 Subject: [PATCH] Move bunnymark example to another module --- examples/others/resources/wabbit_alpha.png | Bin 449 -> 0 bytes examples/textures/resources/wabbit_alpha.png | Bin 0 -> 561 bytes .../textures_bunnymark.c} | 59 +++++++++++------- 3 files changed, 37 insertions(+), 22 deletions(-) delete mode 100644 examples/others/resources/wabbit_alpha.png create mode 100644 examples/textures/resources/wabbit_alpha.png rename examples/{others/bunnymark.c => textures/textures_bunnymark.c} (50%) diff --git a/examples/others/resources/wabbit_alpha.png b/examples/others/resources/wabbit_alpha.png deleted file mode 100644 index 79c31675083b7ffc272a6370bc189360bde484d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 449 zcmeAS@N?(olHy`uVBq!ia0y~yV31;9U{K{?V_;y2N&C5tfq_A?#5JNMI6tkVJh3R1 z!7(L2DOJHUH!(dmC^a#qvhZZ84FdyXvZsqe1NMU zf!pr@=MFfy&0{anLP4>r9R+pSN*u}1}x^V55-3)98*YHU^xz^8E z{zuQa>cFxR*JXb50$9_krz@2PJ_tGT@|otPPX9J(#jVv02Yb)2dc~k}lOwtI%A1lm z@5C4n#_mwM%C*8qK_m9+8Mdm)2ao=cbu@@KbeVQft*a-d%z=?NKPaqI14-?iy0WWg+Z8+Vb&Z8 zkcwoFAYTTCDpdxChGqtapZ^&c8eTFmlo~KFyh>nTu$sZZAf7)d{-_%R1LJm27srr_ zTP;)1mOeJ%X|aE@aayQi_1SF;nUtn0{+hStVa(;@QJQJr6greNiVlCzxv5|%^M@zp zQA9k)WAiYdO@AY!-*GtW~AKAHQt<+wy(uN zd70CXgs-tvw@Wjf$@_8P%rX6hqENY0cLdBgWnMW|`bX@}!>wOjSI;PUYrwr%Zfm7) zL09a8fRF#WvONA)E?Bs_cguoj&(!;0-B7>ns>sW{`_9+5!G-Oc8Fz>HGq;w^+lO%$>Jw{mft%6)o#OoX@;7nExIvnR{9JK O3=E#GelF{r5}E*d+xiXw literal 0 HcmV?d00001 diff --git a/examples/others/bunnymark.c b/examples/textures/textures_bunnymark.c similarity index 50% rename from examples/others/bunnymark.c rename to examples/textures/textures_bunnymark.c index 8b524b011..76078838d 100644 --- a/examples/others/bunnymark.c +++ b/examples/textures/textures_bunnymark.c @@ -1,18 +1,23 @@ /******************************************************************************************* * -* raylib example - Bunnymark +* raylib [textures] example - Bunnymark * * This example has been created using raylib 1.6 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ #include "raylib.h" -#include // Required for: malloc(), free() -#define MAX_BUNNIES 100000 // 100K bunnies +#include // Required for: malloc(), free() + +#define MAX_BUNNIES 100000 // 100K bunnies limit + +// This is the maximum amount of elements (quads) per batch +// NOTE: This value is defined in [rlgl] module and can be changed there +#define MAX_BATCH_ELEMENTS 8192 typedef struct Bunny { Vector2 position; @@ -24,10 +29,10 @@ int main() { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 1280; - int screenHeight = 960; + const int screenWidth = 800; + const int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark"); + InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark"); Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); @@ -49,8 +54,11 @@ int main() for (int i = 0; i < 100; i++) { bunnies[bunniesCount].position = GetMousePosition(); - bunnies[bunniesCount].speed.x = (float)GetRandomValue(250, 500)/60.0f; - bunnies[bunniesCount].speed.y = (float)(GetRandomValue(250, 500) - 500)/60.0f; + bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), + GetRandomValue(80, 240), + GetRandomValue(100, 240), 255 }; bunniesCount++; } } @@ -61,8 +69,10 @@ int main() bunnies[i].position.x += bunnies[i].speed.x; bunnies[i].position.y += bunnies[i].speed.y; - if ((bunnies[i].position.x > GetScreenWidth()) || (bunnies[i].position.x < 0)) bunnies[i].speed.x *= -1; - if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1; + if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) || + ((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1; + if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) || + ((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1; } //---------------------------------------------------------------------------------- @@ -74,17 +84,20 @@ int main() for (int i = 0; i < bunniesCount; i++) { - // NOTE: When internal QUADS batch limit is reached, a draw call is launched and - // batching buffer starts being filled again; before launching the draw call, - // updated vertex data from internal buffer is send to GPU... it seems it generates - // a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps - DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, RAYWHITE); + // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), + // a draw call is launched and buffer starts being filled again; + // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... + // Process of sending data is costly and it could happen that GPU data has not been completely + // processed for drawing while new data is tried to be sent (updating current in-use buffers) + // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies + DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, bunnies[i].color); } - DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY); - DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY); - DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED); - DrawFPS(260, 10); + DrawRectangle(0, 0, screenWidth, 40, BLACK); + DrawText(FormatText("bunnies: %i", bunniesCount), 120, 10, 20, GREEN); + DrawText(FormatText("batched draw calls: %i", 1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); + + DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- @@ -92,9 +105,11 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - free(bunnies); + free(bunnies); // Unload bunnies data array + + UnloadTexture(texBunny); // Unload bunny texture - CloseWindow(); // Close window and OpenGL context + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0;