Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: RenderTexture Updating Every Frame Rescale  (Read 3452 times)

0 Members and 1 Guest are viewing this topic.

takercena

  • Newbie
  • *
  • Posts: 10
    • View Profile
RenderTexture Updating Every Frame Rescale
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Updating Every Frame Rescale
« Reply #1 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.
Laurent Gomila - SFML developer

takercena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: RenderTexture Updating Every Frame Rescale
« Reply #2 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?
« Last Edit: April 12, 2012, 03:17:46 pm by takercena »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Updating Every Frame Rescale
« Reply #3 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.
Laurent Gomila - SFML developer

takercena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: RenderTexture Updating Every Frame Rescale
« Reply #4 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();
}
« Last Edit: April 12, 2012, 03:48:20 pm by takercena »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Updating Every Frame Rescale
« Reply #5 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?
Laurent Gomila - SFML developer

takercena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: RenderTexture Updating Every Frame Rescale
« Reply #6 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Updating Every Frame Rescale
« Reply #7 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)?
Laurent Gomila - SFML developer

takercena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: RenderTexture Updating Every Frame Rescale
« Reply #8 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
« Last Edit: April 12, 2012, 05:52:52 pm by takercena »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Updating Every Frame Rescale
« Reply #9 on: April 12, 2012, 06:12:55 pm »
Where is getRGBA?
Laurent Gomila - SFML developer

takercena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: RenderTexture Updating Every Frame Rescale
« Reply #10 on: April 12, 2012, 06:32:14 pm »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Updating Every Frame Rescale
« Reply #11 on: April 12, 2012, 07:16:31 pm »
But why a slow function call, instead of a fast direct access?
Laurent Gomila - SFML developer

takercena

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: RenderTexture Updating Every Frame Rescale
« Reply #12 on: April 13, 2012, 12:22:58 am »
It just my naive implementation of OOP.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture Updating Every Frame Rescale
« Reply #13 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').
« Last Edit: April 13, 2012, 08:06:34 am by Laurent »
Laurent Gomila - SFML developer

 

anything