Reuse dynamically created figures |
mr_tawan
|
I think you could use render target to create the texture.
|
|||||||||||
|
mr_tawan
|
I think you could use render target to create a texture, and resue it until you have to recreate a new one.
|
|||||||||||
|
SDL_SetRenderTarget |
slash
|
Thanx mr_tawan, So the suggestion is
1.) Create a new texture. 2.) Use SDL_SetRenderTarget to set the target to the new texture 3.) Draw my object as before 4.) Copy the texture to the window Am I right? Cheers, slash |
|||||||||||
|
mr_tawan
|
Yes. That should work.
The point is you have to clear the texture and redraw a new object into that texture only when it needs to (eg. size changed). Otherwise it will be the same as draw it to the screen directly, even worse render target can cause performance drop. |
|||||||||||
|
slash
|
That's exactly my use case. The figures are normally created exactly once. They are only created dynamically to handle different screen sizes.
Thanx again, I'll try this. Cheers, slash |
|||||||||||
|
slash
|
Hi mr_tawn,
thanx, I got it working. Still it got not expected results. I thought drawing a triangle every frame would be slower than to create it once in a texture and to copy it at the appropriate position all the time. Maybe I was misled here, a graphics processor may be faster in drawing directly to the window than copying the containing SDL_Rect to the window. Anyway, your proposal did work, although not with the expected performance gain. Thanx again Wolfgang |
|||||||||||
|
mr_tawan
|
Well if the object is not too complex, there're won't be much performance gain (or it may even have penalty instead).
|
|||||||||||
|