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 zcmV;y0Y3hTP)SOJFMz`0@qn1GK$9W|wOohG3Lai}FkWLtiT<2<{JbM8>W7|R$! zUuNqg#gmKmsTnILy&K;zJjd^_40xy)%EA1>FWWk~LFpr>Et|!Hv(V>Hs9!2xEQJ>~!qz76HLsxFXdG zs5~GjUDeD6dXvG$_#HtoUok|M-X@BSTy{VK4P?TJZcz}O&FVzD0fZu8Yajr@?2aYL r_Q@_>J=ju&>AqoA-=wzwF98MsNX4kdg00009a7bBm000XU z000XU0RWnu7ytkOAY({UO#lFTB>(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZ-w@E}nRCwBimCbeIFbsr0Ms* z*&s0-{0wB`SYHU^H&#rt{aIV?2tzDxNmR=K)5-)0!;}pcJC+TpXLyC0iMR{*LicWTj)OOb9QrbV+V^)FLnr6O)Fe9cy z_+a&2mA4xL%x?J5%*HQZa#bG6+z>aiY1GPf{1)8dwe&@+m~`zh3%wq-c};MNU7%3$ z{)%cy{du6FtBtgv=H@4l>ewgSMIj9XyWI8dQ*np00lQRB1BG;%yUCgL!%8u}DBfo! zuc_DvQ(4Wog1fO*D%E(Xo+D&wsLuRlYFKuXcwjHy+Gox`H1qu5NK<%q^kI9IcTtXe1fzsT!uO?00000NkvXXu0mjfdfWOA 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;