SFML community forums

Bindings - other languages => DotNet => Topic started by: Xyro on May 09, 2011, 09:55:39 am

Title: SFML multiple shaders to RenderImage
Post by: Xyro on May 09, 2011, 09:55:39 am
I'm trying to implement multiple global shaders so I came up with this :

Code: [Select]

foreach (Shader shader in globalShaders)
{
     Program.renderImage.Draw(new Sprite(Program.renderImage.Image), shader);
}


But for some reason this gives me really strange artifacts and the only way I found to fix this is by copying the image over to another image(which is going to lag since its done every frame and multiple times as there is more then one shader) then clearing the renderImage and then drawing it.

Is there a workaround so I can make this work ?
Title: SFML multiple shaders to RenderImage
Post by: Laurent on May 09, 2011, 11:02:26 am
You can't read and write the same image at the same time, so yes you can't do it without at least two images.

But you don't need to copy the image every time, you can use a kind of double-buffering:

RenderImage image1 = new RenderImage(...);
RenderImage image2 = new RenderImage(...);

RenderImage front = image1;
RenderImage back = image2;

...

foreach (Shader shader in globalShaders)
{
    // draw "back" into "front"
    front.Clear();
    front.Draw(new Sprite(back.Image), shader);
    front.Display();

    // swap front and back buffers
    RenderImage temp = front;
    front = back;
    back = temp;
}

// the final result is in the variable "back"
Title: SFML multiple shaders to RenderImage
Post by: Xyro on May 09, 2011, 05:52:09 pm
Worked perfectly, thanks again laurent :)