Update bunnymark, issue #480

This commit is contained in:
Milan Nikolic 2025-06-09 19:36:06 +02:00
parent 3327fcaf9f
commit 5d704708c4
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75

View file

@ -3,9 +3,13 @@ package main
import ( import (
"fmt" "fmt"
"github.com/gen2brain/raylib-go/raylib" rl "github.com/gen2brain/raylib-go/raylib"
) )
// This is the maximum amount of elements (quads) per batch
// NOTE: This value is defined in [rlgl] module and can be changed there
const maxBatchElements = 8192
// Bunny type // Bunny type
type Bunny struct { type Bunny struct {
Position rl.Vector2 Position rl.Vector2
@ -14,15 +18,14 @@ type Bunny struct {
} }
func main() { func main() {
screenWidth := int32(1280) screenWidth := int32(800)
screenHeight := int32(960) screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Bunnymark") rl.InitWindow(screenWidth, screenHeight, "raylib [others] example - bunnymark")
texture := rl.LoadTexture("wabbit_alpha.png") texture := rl.LoadTexture("wabbit_alpha.png")
bunnies := make([]*Bunny, 0) bunnies := make([]*Bunny, 0)
bunniesCount := 0
rl.SetTargetFPS(60) rl.SetTargetFPS(60)
@ -33,11 +36,11 @@ func main() {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
b := &Bunny{} b := &Bunny{}
b.Position = rl.GetMousePosition() b.Position = rl.GetMousePosition()
b.Speed.X = float32(rl.GetRandomValue(250, 500)) / 60.0 b.Speed.X = float32(rl.GetRandomValue(-250, 250)) / 60.0
b.Speed.Y = float32(rl.GetRandomValue(250, 500)-500) / 60.0 b.Speed.Y = float32(rl.GetRandomValue(-250, 250)) / 60.0
b.Color = rl.NewColor(uint8(rl.GetRandomValue(50, 240)), uint8(rl.GetRandomValue(80, 240)), uint8(rl.GetRandomValue(100, 240)), 255)
bunnies = append(bunnies, b) bunnies = append(bunnies, b)
bunniesCount++
} }
} }
@ -46,11 +49,11 @@ func main() {
b.Position.X += b.Speed.X b.Position.X += b.Speed.X
b.Position.Y += b.Speed.Y b.Position.Y += b.Speed.Y
if (b.Position.X > float32(screenWidth)) || (b.Position.X < 0) { if ((b.Position.X + float32(texture.Width/2)) > float32(screenWidth)) || ((b.Position.X + float32(texture.Width/2)) < 0) {
b.Speed.X *= -1 b.Speed.X *= -1
} }
if (b.Position.Y > float32(screenHeight)) || (b.Position.Y < 0) { if ((b.Position.Y + float32(texture.Height/2)) > float32(screenHeight)) || ((b.Position.Y + float32(texture.Height/2-40)) < 0) {
b.Speed.Y *= -1 b.Speed.Y *= -1
} }
} }
@ -60,18 +63,20 @@ func main() {
rl.ClearBackground(rl.RayWhite) rl.ClearBackground(rl.RayWhite)
for _, b := range bunnies { for _, b := range bunnies {
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
// batching buffer starts being filled again; before launching the draw call, // a draw call is launched and buffer starts being filled again;
// updated vertex data from internal buffer is send to GPU... it seems it generates // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps // Process of sending data is costly and it could happen that GPU data has not been completely
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), rl.RayWhite) // 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
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), b.Color)
} }
rl.DrawRectangle(0, 0, screenWidth, 40, rl.LightGray) rl.DrawRectangle(0, 0, screenWidth, 40, rl.Black)
rl.DrawText("raylib bunnymark", 10, 10, 20, rl.DarkGray) rl.DrawText(fmt.Sprintf("bunnies: %d", len(bunnies)), 120, 10, 20, rl.Green)
rl.DrawText(fmt.Sprintf("bunnies: %d", bunniesCount), 400, 10, 20, rl.Red) rl.DrawText(fmt.Sprintf("batched draw calls: %d", 1+len(bunnies)/maxBatchElements), 320, 10, 20, rl.Maroon)
rl.DrawFPS(260, 10) rl.DrawFPS(10, 10)
rl.EndDrawing() rl.EndDrawing()
} }