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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ifinox

Pages: [1]
1
Graphics / Re: sf::RenderTexture.clear() HUGE fps drop
« on: June 02, 2017, 04:05:50 pm »
Yea... But...
With this code:
int main()
{
        sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!");
        const int size = 50;
        sf::RenderTexture render[size];
        for (int i = 0; i < size; i++)
                render[i].create(i + 1, i + 1);

        sf::Clock framerateClock;
        while (window.isOpen())
        {
                std::cout << getFramerate(framerateClock) << "fps\n";
                window.clear();
                for (int i = 0; i < size; i++)
                        render[i].clear();

                window.display();
        }

        return 0;
}

On windows10 i have 20fps but on linux i have 400fps.
Just test it yourself.
And at windows first calling clear() with RenderTexture (next calling .clear() much less but still noticeable) always take around ~50% fps.

2
Graphics / Re: sf::RenderTexture.clear() HUGE fps drop
« on: June 02, 2017, 01:41:52 pm »
The issue with your code is the recreation of the render texture. It's an expensive operation and doing so 5 times every frame will kill your performance. I don't really lose any FPS when just calling clear.

Render texture is not a cheap "resource", as such its use should be limited and at best you should create it once and then reuse it as much as possible.

Also don't forget that FPS is not linear, if you get a jump from a couple of hundred FPS down to a few hundred less, then that's not as surprising.

sf::RenderTexture render1;
sf::RenderTexture render2;
sf::RenderTexture render3;
sf::RenderTexture render4;
sf::RenderTexture render5;

render1.create(5, 5);
render2.create(6, 6);
render3.create(7, 7);
render4.create(8, 8);
render5.create(9, 9);

sf::Clock framerateClock;
while (window.isOpen())
{
        std::cout << getFramerate(framerateClock) << "fps\n";
        window.clear(); // 1700FPS

        // if we add even more clears...
        render1.clear();
        render2.clear();
        render3.clear();
        render4.clear();
        render5.clear();
        // FPS around 300 - ~82% framerate less
        window.display();
}
But that simply code without recreating also have huge fps drop.
More confusing is that on linux with same code I am having 1500fps

3
Graphics / Re: sf::RenderTexture.clear() HUGE fps drop
« on: June 02, 2017, 12:24:59 pm »
Try upgrading to SFML 2.4.2 and make sure to test run your application in release mode and not debug mode.
Nothing changed. If you build this minimal code and you run it you have normal fps rate? (like ~1000)

4
Graphics / Re: sf::RenderTexture.clear() HUGE fps drop
« on: June 01, 2017, 11:38:57 pm »
Check out the following points of the forum rules. ;)

Version: SFML 2.4.0 Windows 10
Graphics : Intel HD520

Minimal Code:
#include <iostream>
#include <SFML/Graphics.hpp>

int getFramerate(sf::Clock & clock)
{
        static float lastFrameRate = 0;
        static float frameRate = 0;
        if (clock.getElapsedTime().asMilliseconds() < 1000)
        {
                frameRate++;
        }
        else
        {
                lastFrameRate = frameRate;
                frameRate = 0;
                clock.restart();
        }
        return (int)lastFrameRate;
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!");
        sf::RenderTexture render;
        render.create(5, 5);
        sf::Clock framerateClock;
        while (window.isOpen())
        {
               
                sf::Event event;
                while (window.pollEvent(event))
                        if (event.type == sf::Event::Closed)
                                window.close();


                std::cout << getFramerate(framerateClock) << "fps\n";
                window.clear(); // 1300FPS
                render.clear(); // ADDING ONE CLEAR -> 500FPS

                // if we add even more clears...
                render.create(6, 6);
                render.clear();
                render.create(5, 5);
                render.clear();
                render.create(6, 6);
                render.clear();
                render.create(5, 5);
                render.clear();
                render.create(6, 6);
                render.clear();
                // :-) -> 17FPS

                window.display();
        }

        return 0;
}

5
Graphics / sf::RenderTexture.clear() HUGE fps drop
« on: June 01, 2017, 10:33:41 pm »
Hello. I am coding simply roguelike and I have problem with sf::RenderTexture.
Normally I have around 600-700fps, but when I add rendertexture.clear() fps drops to 200-300fps!!
This happend despite the rendertexture size - even if i set rendertexture size to 5x5 ( create(5,5) ) or 1000x1000 there would be still 200-300fps.

Any idea how to solve that?

//edit

ThatCode:
visionMaskTexture.create(6, 6);
visionMaskTexture.clear();
visionMaskTexture.create(7, 6);
visionMaskTexture.clear();
visionMaskTexture.create(8, 6);
visionMaskTexture.clear();
make game unplayable(~10fps).
Why I have such fps drop with rendertexture?

6
Graphics / [Solved] Problem with changing size RenderTexture
« on: February 18, 2017, 10:23:41 am »
This is the code that reproduce the problem:
#include <vector>
#include <SFML/Graphics.hpp>

class UI : public sf::Drawable
{
        virtual void draw(sf::RenderTarget & target, sf::RenderStates states) const
        {
                target.draw(sprite);
        }
        sf::RenderTexture view;
        sf::Sprite sprite;
public:
        UI()
        {
        }
        void draw(const sf::Drawable & drawable)
        {
                view.draw(drawable);
        }
        void setSize(int x, int y)
        {
                view.create(x, y);
                view.clear();
        }
        void update(const std::vector<sf::RectangleShape>& squares)
        {
                for (int i = 0; i < squares.size(); i++)
                        view.draw(squares[i]);
                view.display();
                sprite.setTexture(view.getTexture());
        }
};
int main()
{
       
        sf::RectangleShape shape;
        shape.setSize(sf::Vector2f(20, 20));
        shape.setFillColor(sf::Color::White);

        int actualPosition = 0;
        std::vector <sf::RectangleShape> shapes;

        UI ui;
       
        for (int i = 0; i < 10; i++)
        {
                shape.setPosition(actualPosition, 0);
                shapes.push_back(shape);
                actualPosition += 21;
        }
        ui.setSize(21 * shapes.size(), 20);
        ui.update(shapes);

        sf::RenderWindow window(sf::VideoMode(21*shapes.size(), 20), "test");
        window.setFramerateLimit(20);
       
        while (window.isOpen())
        {
               
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if (event.type == sf::Event::KeyReleased)
                        {
                                if (event.key.code == sf::Keyboard::Space)
                                {
                                        shape.setPosition(actualPosition, 0);
                                        shapes.push_back(shape);
                                        actualPosition += 21;
                                        ui.setSize(21 * shapes.size(), 20);
                                        ui.update(shapes);
                                       
                                }
                                if (event.key.code == sf::Keyboard::B)
                                {
                                        shapes.pop_back();
                                        actualPosition -= 21;
                                        ui.setSize(21 * shapes.size(), 20);
                                        ui.update(shapes);
                                }
                                window.create(sf::VideoMode(21 * shapes.size(), 20), "test");
                                window.setFramerateLimit(20);
                        }
                }

                window.clear();
                window.draw(ui);
                window.display();
        }

        return 0;
}
 


When we remove square from std::vector everything is good.
When we add square to std::vector everthing is good.
When we add another square that will be more than starting 10 (or any number defined before main program loop) squares, window will resize but RenderTarget will don't draw squares that is more than 10.


What am I doing wrong?

7
Window / Re: How to check if both mouse button is pressed
« on: February 17, 2017, 04:34:50 pm »
Thank you!  :)
So if anyone will have similar problem here's the code:
if (event.type == sf::Event::MouseButtonPressed)
{
        bool left, right;
        left = right = false;
        if (mouse.isButtonPressed(sf::Mouse::Left))
                left = true;
                                       
        if (mouse.isButtonPressed(sf::Mouse::Right))
                right = true;

        if (left && right)
                std::cout << "LMB+RMB\n";
        else if (left)
                std::cout << "LMB\n";
        else if (right)
                std::cout << "RMB\n";
}
 

8
Window / How to check if both mouse button is pressed
« on: February 17, 2017, 12:58:15 pm »
Hello. I need to check if both lmb and rmb is pressed. How can i do that?

if (event.type == sf::Event::MouseButtonPressed)
{
        if (event.mouseButton.button == sf::Mouse::Left && event.mouseButton.button == sf::Mouse::Right)
                std::cout << "LMB+RMB\n";
        else if (event.mouseButton.button == sf::Mouse::Left)
                std::cout << "LMB\n";
        else if (event.mouseButton.button == sf::Mouse::Right)
                std::cout << "RMB\n";
}
 

That code I have now and it is obvious that not work, but how to do that properly?

9
Graphics / Weird behavior of shaders with variable index
« on: December 03, 2016, 06:20:45 pm »
Hello.
I am learning GLSL shaders and i wrote very simply light system.
When I want add all lights by using variable like this:
int var = 10;
gl_FragColor = light[0];
for(int i = 1; i<var; i++)
   gl_FragColor *= light[i]
I see graphics artifacts:


But when I  write indexes manually (i use vars because i want add lights in loop, not manually) like this:
gl_FragColor = light[0] * light[1];
Everything works fine:


Why I have artifacts?

Pages: [1]