Reputation: 27
I'm programming a flood_fill() func for triangles. To do this i have to recover the pixel color at a certain position. I use a SDL_Texture in SDL_ACCESSTARGET to blit on and used for the final rendering (it's the main texture, with window size). The problem is that the texture is write-only. I found the function SDL_RenderReadPixels() but it is a slow operation and it is not suitable for this algorithm. I could maybe use a SDL_Surface instead of a SDL_Texture, but if i'm right, SDL_Surface isn't handled by the GPU and therefore would slow down rendering.
I tried to lock() and unlock() texture but it is also a slow way to proceed.
Here's the expected code :
Can someone tell me what would be the best way to handle this problem?
Upvotes: 0
Views: 91
Reputation: 27
For those who have the same problem :
Like I said, I would perform a flood_fill on a triangle by using texture but it is too slow. With SDL2, textures are stored in the VRAM, and accessing them is significantly slower than one stored in the RAM. So the solution is to use surface (pixel array stored in RAM), perform flood_fill on it and then converts it in a texture and copies it on the global texture. But it's also slower than a simple scanline algorithm. Another solution would be to not use textures at all, that's what I would do then, but while searching in the SDL2 source code, I found that even when you use SDL_UpdateWindowSurface() it converts it into a texture and render it.
Well, still no satisfactory solution.
Edit:
After noticing that SDL_UpdateWindowSurface() was too slow for what I wanted to do, I decided to try with OpenGL. With SDL it is possible to use an OpenGL context for rendering and it turns out that glDrawPixels() works perfectly to fastly draw pixel array.
Upvotes: -1