-1

I am wondering about performance in Raylib, especially using the DrawTexture and NewImageFromImage functions. I have the code below, it's written in Go so I am using the go-bindings found here : https://github.com/gen2brain/raylib-go

When I run the code below (full code : https://github.com/Hultan/fractal), I get approx. the following result for each frame:

Calculating done in 30.925822 ms! Drawing done in 135.477039 ms! 

So it calculates (and generates an image.Image) in 30 ms, and it takes four times as long to draw that image.

Am I using Raylib correct here? I have not tried to generate Mandelbrot fractals in decades, so those numbers might very well be reasonable today. I was expecting the computational part to be much slower than the drawing though, not the reverse...

And I do have a 5 year old graphics card, so maybe that's why...

const ( width, height = 800, 600 ) func main() { rl.InitWindow(width, height, "fractal") defer rl.CloseWindow() img := image.NewRGBA(image.Rect(0, 0, width, height)) for !rl.WindowShouldClose() { ... rl.BeginDrawing() t := time.Now() ... // Generating Mandelbrot fractal image into img ... fmt.Printf("Calculating done in %v!\n", time.Since(t)) t = time.Now() tex := rl.LoadTextureFromImage(rl.NewImageFromImage(img)) rl.DrawTexture(tex, 0, 0, rl.White) fmt.Printf("Drawing done in %v!\n", time.Since(t)) rl.EndDrawing() rl.UnloadTexture(tex) } } 

Edit : Added information about the fractal size, see comment.

2
  • How big is this image? Uploading textures is generally an expensive operation, you want to do as little of that as possible. In any case I would expect logic like this to be doing the generation of images in a separate goroutine so a different core can be busying itself with that. When you see test results that look strange, usually the test itself is not optimal. Commented Feb 22, 2024 at 12:21
  • I am sorry, I cut that part of the code out. The image is 800x600... The image is generated in a bunch of gouroutines, so that is not the problem (30ms). The problem, in my opinion, is that it takes 130ms to draw an image in Raylib. I would have guessed that it would be much faster. Commented Feb 22, 2024 at 12:30

1 Answer 1

1

In every iteration in the window loop your code allocates new texture with the supplied image so try loading the texture outside of the window loop.

Also if you have to draw something on the image try UpdateTexture() function within the loop to load the new image data instead of creating new texture. that will speed up things.

Finally you may want to set a target fps to avoid inconsistent frame updates and glitches.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.