Is there a function to disable object rendering?

edited July 2012 in Help request
I found awhile ago by experimentation there is a cost from offscreen Orx objects on iOS (it decreases FPS).

Based on this, I have an object that I want to keep offscreen, but in existence. It "slides up" onto the visible screen via FX, but it needs to already be in existence when the FX is applied. Otherwise, there's a delay while the object is created.

I don't want a mostly offscreen object to affect game performance, though. I was thinking I could capture the object's render start event and simply return false if the object is offscreen. Am I correct in thinking this should prevent the performance hit?

If so, is there an easier way to do this than processing the event manually. i.e. with the Orx API?

The object in question is a 269kb .png with round corners, so transparency is required. I could try to optimize the size of the texture so it loads faster, if that proves easier than what I'm trying to do in code.

Comments

  • edited July 2012
    acksys wrote:
    I don't want a mostly offscreen object to affect game performance, though. I was thinking I could capture the object's render start event and simply return false if the object is offscreen. Am I correct in thinking this should prevent the performance hit?

    Well, it all depends where the performance hit was. If it was the actual rendering itself, yes, it would cut it. It it was the fact that the object existed and was parsed by the renderer, then no.
    If so, is there an easier way to do this than processing the event manually. i.e. with the Orx API?

    Unfortunately no, you have to return orxFALSE for the orxRENDER_EVENT_OBJECT_START to bypass its rendering.
    The object in question is a 269kb .png with round corners, so transparency is required. I could try to optimize the size of the texture so it loads faster, if that proves easier than what I'm trying to do in code.

    If the transparency is only used for the round corners you have two options:
    - cut the objects so that only the corners are alpha blended and the other parts, all rectangular, are not blended
    - use a shader that will discard the corner pixels (ie. the transparent ones) and writes the other ones (2 lines shader).

    Not sure which one will have the less performance impact but they're worth a try, especially the shader one.


    I wouldn't try to have the texture loaded lazily when you need it, but you can unlink/relink the orxGRAPHIC of your object at will if need be (this way the texture stays in memory but the object won't get rendered as it doesn't have a graphic).
  • edited July 2012
    Good info, thanks. I believe I will be able to solve it with this.

    What are the differences between canceling the object's rendering event and unlinking its orxGRAPHIC?
  • edited July 2012
    They're about the same.

    Removing the orxGRAPHIC should be slightly more efficient, if any, but is a bit more of a constraint as you need to keep a reference to it in order to put link it again with your object whereas the event listener is maybe slightly less code.
  • edited July 2012
    If the creation of the object is slow because of loading of the png (i've experienced the same for my game), you can preload the orxGRAPHIC (orxGraphic_CreateFromConfig()) so that when you create the orxOBJECT it doesnt need to load the texture as it's already loaded.

    of course you'll need to delete the orxGRAPHIC at some point.

    if rendering is the issue, you can try to compress the texture with PVRTC, and/or split the opaque areas and transparent areas and use blending only for transparents areas.
  • edited July 2012
    Pre-loading the texture is another great option. Thank you.

    Thanks for the info about PVRTC, too. I'll look into that.
Sign In or Register to comment.