[SDL2]-Is "Dirty Rectangle" Optimization Possible?

[SDL2]-Is “Dirty Rectangle” Optimization Possible?

Hi,

I am trying to optimize my SDL2 2-D video game engine now.

TTF text drawing with SDL2_TTF is ridiculously slow
so I am trying to not draw TTF text as much as possible.

My question is the following:
Is "Dirty Rectangle"optimization possible with SDL2?
(I did "Dirty Rectangle"optimization in my SDL1 2-D video game engine with good results)

I would like to update only parts of the screen and not the entire screen each frame.
Let me know if the above is possible or not when using SDL2.
(it must be 100% cross-platform: Windows/Mac OS X/Linux)

Also another question: Is it possible to copy the screen to an SDL Texture?

Thanks!------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

2014-11-14 5:13 GMT+01:00 JeZ-l-Lee :

[SDL2]-Is “Dirty Rectangle” Optimization Possible?

Hi,

I am trying to optimize my SDL2 2-D video game engine now.

TTF text drawing with SDL2_TTF is ridiculously slow
so I am trying to not draw TTF text as much as possible.

My question is the following:
Is "Dirty Rectangle"optimization possible with SDL2?
(I did "Dirty Rectangle"optimization in my SDL1 2-D video game engine with
good results)

I would like to update only parts of the screen and not the entire screen
each frame.
Let me know if the above is possible or not when using SDL2.
(it must be 100% cross-platform: Windows/Mac OS X/Linux)

Also another question: Is it possible to copy the screen to an SDL Texture?

Thanks!


JeZ+Lee
JessePalser Gmail com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

If you’re doing accelerated rendering, either directly via OpenGL, or
indirectly via SDL_Render,
the backbuffer’s contents become undefined once swapped. This is so things
like
double buffering work reliably.

However, nobody is stopping you from keeping your own backbuffer (eg. a
render target
SDL_Texture) that you blit to the screen every frame, and onto which you
can apply any
optimizations you’d like, such as keeping track of the dirty region.

Have you tried caching the textures TTF generates? I never had any problems
with performance that way

2014-11-14 5:33 GMT+01:00 Jonas Kulla :> 2014-11-14 5:13 GMT+01:00 JeZ-l-Lee :

[SDL2]-Is “Dirty Rectangle” Optimization Possible?

Hi,

I am trying to optimize my SDL2 2-D video game engine now.

TTF text drawing with SDL2_TTF is ridiculously slow
so I am trying to not draw TTF text as much as possible.

My question is the following:
Is "Dirty Rectangle"optimization possible with SDL2?
(I did "Dirty Rectangle"optimization in my SDL1 2-D video game engine
with good results)

I would like to update only parts of the screen and not the entire screen
each frame.
Let me know if the above is possible or not when using SDL2.
(it must be 100% cross-platform: Windows/Mac OS X/Linux)

Also another question: Is it possible to copy the screen to an SDL
Texture?

Thanks!


JeZ+Lee
JessePalser Gmail com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

If you’re doing accelerated rendering, either directly via OpenGL, or
indirectly via SDL_Render,
the backbuffer’s contents become undefined once swapped. This is so things
like
double buffering work reliably.

However, nobody is stopping you from keeping your own backbuffer (eg. a
render target
SDL_Texture) that you blit to the screen every frame, and onto which you
can apply any
optimizations you’d like, such as keeping track of the dirty region.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

TTF text drawing with SDL2_TTF is ridiculously slow
so I am trying to not draw TTF text as much as possible.

My question is the following:
Is "Dirty Rectangle"optimization possible with SDL2?

Sort of. The framebuffer is invalid after you present, so you can’t
count on it having a stable image left over from previous drawings. You
can manage your own software surface and upload it to a texture as
dirty rectangles, but I wouldn’t recommend it. Overall, this is usually
slower and uglier code.

What you should do is one of two things:

  • Don’t call SDL_ttf more than necessary. If it’s the same string every
    frame, generate the texture once with SDL_ttf and use it multiple times.
  • Build a texture atlas with SDL_ttf (or whatever) and have a single
    texture with all the glyphs on it (or several textures with several
    glyphs on each, if you have a lot of glyphs), and then draw your strings
    on the fly, picking out the glyphs you need.

The beauty of having a GPU is that you don’t have to manage dirty
rectangles anymore…it’s crazy fast to just redraw the whole screen
every time, but a few rules change: uploading to the GPU is slow, so get
everything to the GPU once and use it over and over, and it’ll be fast,
fast, fast.

–ryan.

Hi,

Thanks for the information.
I got a new optimized TTF text drawing system operation at the below URL link:
http://forums.libsdl.org/viewtopic.php?t=10833

Thanks!------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com