Update bunnymark, issue #480
This commit is contained in:
parent
3327fcaf9f
commit
5d704708c4
1 changed files with 24 additions and 19 deletions
|
@ -3,9 +3,13 @@ package main
|
|||
import (
|
||||
"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
|
||||
type Bunny struct {
|
||||
Position rl.Vector2
|
||||
|
@ -14,15 +18,14 @@ type Bunny struct {
|
|||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(1280)
|
||||
screenHeight := int32(960)
|
||||
screenWidth := int32(800)
|
||||
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")
|
||||
|
||||
bunnies := make([]*Bunny, 0)
|
||||
bunniesCount := 0
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
|
@ -33,11 +36,11 @@ func main() {
|
|||
for i := 0; i < 100; i++ {
|
||||
b := &Bunny{}
|
||||
b.Position = rl.GetMousePosition()
|
||||
b.Speed.X = float32(rl.GetRandomValue(250, 500)) / 60.0
|
||||
b.Speed.Y = float32(rl.GetRandomValue(250, 500)-500) / 60.0
|
||||
b.Speed.X = float32(rl.GetRandomValue(-250, 250)) / 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)
|
||||
bunniesCount++
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,11 +49,11 @@ func main() {
|
|||
b.Position.X += b.Speed.X
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -60,18 +63,20 @@ func main() {
|
|||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
for _, b := range bunnies {
|
||||
// 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
|
||||
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), rl.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
|
||||
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), b.Color)
|
||||
}
|
||||
|
||||
rl.DrawRectangle(0, 0, screenWidth, 40, rl.LightGray)
|
||||
rl.DrawText("raylib bunnymark", 10, 10, 20, rl.DarkGray)
|
||||
rl.DrawText(fmt.Sprintf("bunnies: %d", bunniesCount), 400, 10, 20, rl.Red)
|
||||
rl.DrawRectangle(0, 0, screenWidth, 40, rl.Black)
|
||||
rl.DrawText(fmt.Sprintf("bunnies: %d", len(bunnies)), 120, 10, 20, rl.Green)
|
||||
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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue