Author Topic: Surface downsides?  (Read 5697 times)

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Surface downsides?
« on: March 02, 2015, 03:53:47 PM »
Is there any downsides (performance issues, etc?) in adding objects to surfaces vs adding objects "directly"? I'm guessing fe.add_XXXX draws to it's own surface?

I ask because I put together a Layers module which basically draws the surfaces first, then you only draw to the surfaces. This gives you more flexibility and control with a "layered" effect, meaning you can add objects at a later time and have it drawn to the background or foreground layer.

I was initially including this as part of ExtendedObjects but I'm looking to put it out as a standalone module.

Code: [Select]
layers <- {
    version = 1.4,
    build = 100,
    function add( name )
    {
        this[name] <- fe.add_surface( fe.layout.width, fe.layout.height );
    },
    function init( layers = null )
    {
        //default layers to be used
        if ( layers == null ) layers = [ "Background", "Primary", "Foreground" ];
        //add layers
        foreach ( layer in layers ) { add( layer ); }
    }
}

//now we can draw to the layers instead, in any order we want
layers.init();
layers.Foreground.add_text("I'm on top of title", 0, 0, 400, 30);
layers.Background.add_text("[Title]", 0, 0, 400, 30);


This also means you could manipulate an entire surface (and group of objects) at once. In fact, I thought about using the surface as a holder for a more complex object might be an option. So the surface could be your "object", which includes multiple text or image objects.
« Last Edit: March 02, 2015, 03:59:40 PM by liquid8d »

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: Surface downsides?
« Reply #1 on: March 02, 2015, 11:41:09 PM »
Hi liquid8d,

The surfaces map directly to an SFML "RenderTexture", so the documentation on that might help you understand more what is going on with surfaces: http://www.sfml-dev.org/documentation/2.2/classsf_1_1RenderTexture.php

I'm pretty sure SFML in turn implements them as an OpenGL Framebuffer Object: https://www.opengl.org/wiki/Framebuffer_Object

So allocating a surface does use up additional video memory and adds another rendering step to the display process.  It shouldn't be an issue on newer hardware though unless you are allocating a whole wack of 'em

cheers

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Surface downsides?
« Reply #2 on: March 03, 2015, 02:31:39 PM »
so just don't go crazy :) sounds good, thanks!