The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDLU: RenderCacheState and RestoreCacheState on iOS
occular


Joined: 08 Dec 2016
Posts: 1
I'm using SDL2 and want to use SDLU's RenderCacheState and RestoreCacheState on iOS.

It's not working - I've altered the rectangles SDL example to add a call to RenderCacheState, then RestoreCacheState, as follows:

Code:
void
render(SDL_Renderer *renderer)
{
    Uint8 r, g, b;
    int renderW;
    int renderH;
   
    SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
   
    /*  Come up with a random rectangle */
    SDL_Rect rect;
    rect.w = randomInt(64, 128);
    rect.h = randomInt(64, 128);
    rect.x = randomInt(0, renderW);
    rect.y = randomInt(0, renderH);
   
    /* Come up with a random color */
    r = randomInt(50, 255);
    g = randomInt(50, 255);
    b = randomInt(50, 255);
   
    /*  Fill the rectangle in the color */
    SDL_SetRenderDrawColor(renderer, r, g, b, 255);
    SDL_RenderFillRect(renderer, &rect);
   
    SDLU_GL_RenderCacheState(renderer);   // <------------ trying out this functionality
    SDLU_GL_RenderRestoreState(renderer);   // <------------ trying out this functionality
   
    /* update screen */
    SDL_RenderPresent(renderer);
}


When I run this in simulator and on an actual device, I see only one rectangle painted, then no more.

Firstly, is my code above a legal way and place to call these two functions? This should work, right?

I found a comment in the SDLU headers saying that this RenderCacheState functionality has been tested as working on MacOS and Linux, but other platforms may vary. So it may just not work on iOS, but I want to be sure my example code isn't illegal in some way.

Thanks!
Shocked
Re: SDLU: RenderCacheState and RestoreCacheState on iOS
neoaggelos


Joined: 02 Jan 2013
Posts: 138
Hello and sorry for the terribly late reply,

First of all, does the code work properly on your desktop, or is just iOS? Secondly, RenderCacheState() and
RenderRestoreState() have always been roots for problems (colors not showing up properly etc, with varying
success on different platforms).

For a while, I've been thinking that these are kinda hit-or-miss, because of the vast number of ways you can
render things with OpenGL. As in, I think there is little value in playing guess as to how they will be used, and
therefore what they should do in the background. Instead, would anyone benefit from a function like
SDLU_GL_PushGeometry() where you push many vertices-colors-texture at once?

Also, would you mind running the testrender2 program on your desktop? (It won't run on iOS, it uses OpenGL)

Thanks (and Merry Christmas),
Aggelos

occular wrote:
I'm using SDL2 and want to use SDLU's RenderCacheState and RestoreCacheState on iOS.

It's not working - I've altered the rectangles SDL example to add a call to RenderCacheState, then RestoreCacheState, as follows:

Code:
void
render(SDL_Renderer *renderer)
{
    Uint8 r, g, b;
    int renderW;
    int renderH;
   
    SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
   
    /*  Come up with a random rectangle */
    SDL_Rect rect;
    rect.w = randomInt(64, 128);
    rect.h = randomInt(64, 128);
    rect.x = randomInt(0, renderW);
    rect.y = randomInt(0, renderH);
   
    /* Come up with a random color */
    r = randomInt(50, 255);
    g = randomInt(50, 255);
    b = randomInt(50, 255);
   
    /*  Fill the rectangle in the color */
    SDL_SetRenderDrawColor(renderer, r, g, b, 255);
    SDL_RenderFillRect(renderer, &rect);
   
    SDLU_GL_RenderCacheState(renderer);   // <------------ trying out this functionality
    SDLU_GL_RenderRestoreState(renderer);   // <------------ trying out this functionality
   
    /* update screen */
    SDL_RenderPresent(renderer);
}


When I run this in simulator and on an actual device, I see only one rectangle painted, then no more.

Firstly, is my code above a legal way and place to call these two functions? This should work, right?

I found a comment in the SDLU headers saying that this RenderCacheState functionality has been tested as working on MacOS and Linux, but other platforms may vary. So it may just not work on iOS, but I want to be sure my example code isn't illegal in some way.

Thanks!
Shocked
Re: SDLU: RenderCacheState and RestoreCacheState on iOS
neoaggelos


Joined: 02 Jan 2013
Posts: 138
Hello and sorry for the terribly late reply,

First of all, does the code work properly on your desktop, or is it just iOS? Secondly, RenderCacheState() and
RenderRestoreState() have always been roots for problems (colors not showing up properly etc, with varying
success on different platforms).

For a while, I've been thinking that these are kinda hit-or-miss, because of the vast number of ways you can
render things with OpenGL. As in, I think there is little value in playing guess as to how they will be used, and
therefore what they should do in the background. Instead, would anyone benefit from a function like
SDLU_GL_PushGeometry() where you push many vertices-colors-texture at once?

Also, would you mind running the testrender2 program on your desktop? (It won't run on iOS, it uses OpenGL)

Thanks (and Merry Christmas),
Aggelos

occular wrote:
I'm using SDL2 and want to use SDLU's RenderCacheState and RestoreCacheState on iOS.

It's not working - I've altered the rectangles SDL example to add a call to RenderCacheState, then RestoreCacheState, as follows:

Code:
void
render(SDL_Renderer *renderer)
{
    Uint8 r, g, b;
    int renderW;
    int renderH;
   
    SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
   
    /*  Come up with a random rectangle */
    SDL_Rect rect;
    rect.w = randomInt(64, 128);
    rect.h = randomInt(64, 128);
    rect.x = randomInt(0, renderW);
    rect.y = randomInt(0, renderH);
   
    /* Come up with a random color */
    r = randomInt(50, 255);
    g = randomInt(50, 255);
    b = randomInt(50, 255);
   
    /*  Fill the rectangle in the color */
    SDL_SetRenderDrawColor(renderer, r, g, b, 255);
    SDL_RenderFillRect(renderer, &rect);
   
    SDLU_GL_RenderCacheState(renderer);   // <------------ trying out this functionality
    SDLU_GL_RenderRestoreState(renderer);   // <------------ trying out this functionality
   
    /* update screen */
    SDL_RenderPresent(renderer);
}


When I run this in simulator and on an actual device, I see only one rectangle painted, then no more.

Firstly, is my code above a legal way and place to call these two functions? This should work, right?

I found a comment in the SDLU headers saying that this RenderCacheState functionality has been tested as working on MacOS and Linux, but other platforms may vary. So it may just not work on iOS, but I want to be sure my example code isn't illegal in some way.

Thanks!
Shocked