Don’t use SDL_RenderLine for gradient backgrounds. Instead you should have a pre-filled gradient texture. If you want it dynamically a single color you can make it greyscale and use texture color mod to color it. If you want it multi-colored dynamically you could use a render target and render lines into that and then use that as your gradient. The texture doesn’t need to be very big, either.
Thanks a lot for the suggestions – it helps confirm what I had in mind for optimization once the time rolls around for it (I have the luxury of simply ignoring the issue for the time being). It is nice to know that I was thinking in the right direction
During the time that I discovered the performance issue (a few months ago), I experimented with one-time rendering the gradient fill to a rendering target and then rendering from that, and sure enough, the performance improved dramatically for me. At this time, the thought occurred to me that I could probably just
use a regular texture for this.
I hadn’t thought of using a greyscale texture – interesting idea, I might just have to give it a shot… texture color modulation works wonders for bitmap fonts…
This will save you a huge amount of performance. The SDL line and point API functions are not designed for massive numbers of calls, just some additional work to fill in gaps between textures or do a little background decoration.
Indeed, the API has been wonderful for my other needs! (mostly as a bits and pieces decorator).
Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/08/ 14, at 0:57, Sam Lantinga wrote:
On Wed, Aug 13, 2014 at 2:31 PM, Jeffrey Carpenter <@Jeffrey_Carpenter> wrote:
On Aug 8, 2014, at 11:21, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:
2014-08-08 13:09 GMT-03:00, Tero Lindeman :
One thing that might be quite easy to improve about the SDL_Renderer is the
SDL_RenderFillRects() routine because it seems all implementations are just
doing the same as RenderFillRect() many times over and missing the change
to
build a bigger VBO that contains all the rectangles. And it’s not hard to
guess I mentioned this because it would be a good base for a similar
function
that takes two more parameters: source rects and the texture. Then it
would
be up to the user to build the rectangle lists and keep track of state
changes.
Good point, though honestly I doubt it’s commonly used, it’s likely
most programs just call SDL_RenderFillRect several times. Same deal
with SDL_RenderDrawRect(s).
There’s also SDL_RenderDrawLines, where the same situation applies.
However, that one may be more worth looking into, because rendering
multiple lines together in a single batch is actually pretty useful
(e.g. if you’re rendering a wireframe or a grid or something like
that).
How bad is this, anyway? They barely cause a state change, in contrast
with SDL_RenderCopy, which has a rather heavy state change (changing
the texture has a much more severe penalty). You’ll still need a large
amount of blits to actually cause slow down, but even then.
If you use a function that uses SDL_RenderLine for dithered, linear gradient filled backgrounds, and then use it for three (roughly) 320x240 sized widgets (720ish +/- draw calls per frame if I remember right), you can easily start seeing performance issues. A (roughly) ~15…30fps+ diff can be seen.
This doesn’t matter much to me on my Macbook (Intel Graphics 3000 with plenty of fps to spare), but certainly matters a great deal on my older single core AMD64 windev box (Geforce 6200), where I’ve seen fps drop as low as 4fps, and unable to peak greater than 10fps.
I certainly have slight concern with the performance of the code under iOS, but unfortunately, that test won’t see the light of day for some time.
Admittedly, I haven’t tried very hard at optimizing the function, nor are any of these tests done on a release build, so you might have to take my comment with a grain of salt?
P.S. Sorry for my brevity, I’m emailing from my phone.
Cheers!
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org