SFML community forums

Help => Graphics => Topic started by: takercena on April 12, 2012, 04:15:15 am

Title: RenderTexture Updating Every Frame Rescale
Post by: takercena on April 12, 2012, 04:15:15 am
I am using rendertexture to stream pixels that are 30 fps. I am following this tutorial
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php#details

However, when I rescale it to higher view area from 640*480 to 1366 * 768, the video is very lag. How to solve this problem?

Second, how to perform anti aliasing on rendertexture?
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: Laurent on April 12, 2012, 08:05:23 am
Quote
However, when I rescale it to higher view area from 640*480 to 1366 * 768, the video is very lag. How to solve this problem?
Depends on what you do exactly, which we have no idea about.

Quote
Second, how to perform anti aliasing on rendertexture?
Anti-aliasing is not supported yet on render-textures, but you can smooth them.
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: takercena on April 12, 2012, 03:11:48 pm
Depends on what you do exactly, which we have no idea about.

The way I do it is first, in a loop, I am getting a RGBA feed from camera. Then, I am converting every pixels of one frame, update it to sf:texture(pixels) and finally draw it to window. Is this a correct way?

Is there any other method to perform anti aliasing that you can suggest?
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: Laurent on April 12, 2012, 03:32:37 pm
Quote
The way I do it is first, in a loop, I am getting a RGBA feed from camera. Then, I am converting every pixels of one frame, update it to sf:texture(pixels) and finally draw it to window. Is this a correct way?
This is correct.
But you should show us how you get and convert pixels, it's easy to write inefficient code for this kind of stuff.
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: takercena on April 12, 2012, 03:46:22 pm
Code: [Select]
      customTexture.create(640, 480);
    window.create(sf::VideoMode(1366, 768, 32), "Rendering Camera", sf::Style::Default, windowSetting);
window.setActive();
customTexture.setSmooth(true);
customSprite.setTexture(customTexture);
customSprite.scale(2.13f,1.6f);   
     while(window.isOpen())
{
while(window.pollEvent(evt))
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{ window.close(); exit(1);}
if(evt.type = sf::Event::Closed)
window.close();
}
newCam->Update();
for(long int i = 0; i < 640*480; i++)
{
wRGBA[i].r = (unsigned char)newCam->getRGBA(i, 'r');
wRGBA[i].g = (unsigned char)newCam->getRGBA(i, 'g');
wRGBA[i].b = (unsigned char)newCam->getRGBA(i, 'b');
wRGBA[i].a = 255;
}

pixels = (sf::Uint8*)(wRGBA);
customTexture.update(pixels);
window.draw(customSprite);
window.display();
}
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: Laurent on April 12, 2012, 04:56:51 pm
Quote
Code: [Select]
for(long int i = 0; i < 640*480; i++)
{
wRGBA[i].r = (unsigned char)newCam->getRGBA(i, 'r');
wRGBA[i].g = (unsigned char)newCam->getRGBA(i, 'g');
wRGBA[i].b = (unsigned char)newCam->getRGBA(i, 'b');
wRGBA[i].a = 255;
}
This code looks horribly slow: you're processing every component of every pixel individually, and the getRGBA function taking a pixel index and a char argument for the color component (!) is most likely slower than a direct access.

What API are these functions from?
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: takercena on April 12, 2012, 05:07:42 pm
The method is actually return XnRGB24Pixel (OpenNI). Since SFML won't accept RGB, I have to convert it to RGBA first before updating the texture.
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: Laurent on April 12, 2012, 05:33:49 pm
True. Unfortunately, SFML doesn't accept other pixel formats, and I'm still not sure if I'll extend this in the future.

But what is the type of the newCam instance? Is it a class of yours? If so, can you show the implementation of the Update and getRGBA functions (inconsistent naming convention, by the way)?
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: takercena on April 12, 2012, 05:51:10 pm
Update is just an update once each frame (new data) is available and ready to be processed. If there is new data available, the color is retrieved using getRGBA(). http://openni.org/docs2/Tutorial/conc_updating_data.html
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: Laurent on April 12, 2012, 06:12:55 pm
Where is getRGBA?
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: takercena on April 12, 2012, 06:32:14 pm
Where is getRGBA?

http://openni.org/docs2/Tutorial/struct_xn_r_g_b24_pixel.html. I just returning each color respectively.
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: Laurent on April 12, 2012, 07:16:31 pm
But why a slow function call, instead of a fast direct access?
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: takercena on April 13, 2012, 12:22:58 am
It just my naive implementation of OOP.
Title: Re: RenderTexture Updating Every Frame Rescale
Post by: Laurent on April 13, 2012, 08:04:49 am
Well, here you need maximum performances, bothering with intermediate layers of OO just wastes CPU cycles.

And I personnally would find pixels[j].r clearer than newCam->getRGBA(i, 'r').