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 - ison

Pages: [1]
1
Graphics / Re: Max blend mode/rendering optimization
« on: November 16, 2012, 10:09:32 pm »
Even if performance increase is low I decided to rewrite whole project using VAs ;) However I encountered an annoying problem. It seems that texture smoothing doesn't like texture atlases - because sometimes when drawing tile map, black lines appear between tiles. I have 2 pix space between textures in texture atlas, I tried to fill this space with sf::Color::Transparent but smoothing still blends border colors with black color. Is there any solution for this?

//edit
ok, problem solved
I had to fill space between textures in texture atlas with the nearest color to avoid texture bleeding

2
Graphics / Re: Max blend mode/rendering optimization
« on: November 15, 2012, 01:27:33 pm »
I don't know if my graphics card drivers are up to date but I think that automatic windows update handles this. I'll check.

while(1) {
            sf::Time time = _clock.getElapsedTime();
            printf("rand time: %.2lf ms\n", (time.asMicroseconds()-prevTime.asMicroseconds())/1000.0);
            prevTime = time;

            for(int i=0; i<QUANTITY; ++i) {
                int x = rand()%1024;
                int y = rand()%768;
                if(x == 0 && y == 0) {
                      putchar('.');
                }
            }
        }
 
The x == 0 thing prevents compiler from optimizing it and not calling rand().

3
Graphics / Re: Max blend mode/rendering optimization
« on: November 15, 2012, 12:33:59 pm »
1. Didn't help even if I put everything related to filling VA outside loop. I guess that GPU is bottleneck here so filling VA on CPU doesn't really matter.
2. Every test calls equal amount of rand().
rand() calls take 3 ms per frame.

4
Graphics / Re: Max blend mode/rendering optimization
« on: November 15, 2012, 12:10:35 pm »
Here's the code:

#include <SFML/Graphics.hpp>
#include <cstdio>

#define QUANTITY (100000)

int main()
{
    sf::RenderWindow window;
    window.create(sf::VideoMode(1024, 768, 32), "test", sf::Style::Default);

    int type;
    printf("0 - normal\n");
    printf("1 - atlas\n");
    printf("2 - VA\n");
    scanf("%d", &type);

    sf::Clock _clock;

    if(type == 0) {
        sf::Texture tex[3];
        sf::Sprite spr[3];

        tex[0].loadFromFile("test1.png");
        tex[1].loadFromFile("test2.png");
        tex[2].loadFromFile("test3.png");

        spr[0].setTexture(tex[0]);
        spr[1].setTexture(tex[1]);
        spr[2].setTexture(tex[2]);

        sf::Time prevTime;
        while(1) {
            sf::Time time = _clock.getElapsedTime();
            printf("normal time: %.2lf ms\n", (time.asMicroseconds()-prevTime.asMicroseconds())/1000.0);
            prevTime = time;

            for(int i=0; i<QUANTITY; ++i) {
                int x = rand()%1024;
                int y = rand()%768;
                spr[i%3].setPosition(x, y);
                window.draw(spr[i%3]);
            }

            window.display();
            window.clear();
        }
    }
    else if(type == 1) {
        sf::Texture tex;
        sf::Sprite spr[3];

        tex.loadFromFile("atlas.png");

        spr[0].setTexture(tex);
        spr[0].setTextureRect(sf::IntRect(0, 0, 100, 100));
        spr[1].setTexture(tex);
        spr[1].setTextureRect(sf::IntRect(100, 0, 100, 100));
        spr[2].setTexture(tex);
        spr[2].setTextureRect(sf::IntRect(200, 0, 100, 100));

        sf::Time prevTime;
        while(1) {
            sf::Time time = _clock.getElapsedTime();
            printf("atlas time: %.2lf ms\n", (time.asMicroseconds()-prevTime.asMicroseconds())/1000.0);
            prevTime = time;

            for(int i=0; i<QUANTITY; ++i) {
                int x = rand()%1024;
                int y = rand()%768;
                spr[i%3].setPosition(x, y);
                window.draw(spr[i%3]);
            }

            window.display();
            window.clear();
        }
    }
    else {
        sf::Texture tex;
        sf::Sprite spr[3];

        tex.loadFromFile("atlas.png");

        spr[0].setTexture(tex);
        spr[1].setTexture(tex);
        spr[2].setTexture(tex);

        sf::Time prevTime;
        while(1) {
            sf::Time time = _clock.getElapsedTime();
            printf("VA time: %.2lf ms\n", (time.asMicroseconds()-prevTime.asMicroseconds())/1000.0);
            prevTime = time;

            sf::VertexArray VA(sf::Quads, QUANTITY*4);
            for(int i=0; i<QUANTITY; ++i) {
                int x = rand()%1024;
                int y = rand()%768;
                int w = 100;
                int h = 100;

                VA[i*4].position = sf::Vector2f(x, y);
                VA[i*4+1].position = sf::Vector2f(x+w, y);
                VA[i*4+2].position = sf::Vector2f(x+w, y+h);
                VA[i*4+3].position = sf::Vector2f(x, y+h);

                VA[i*4].texCoords = sf::Vector2f((i%3)*w, 0);
                VA[i*4+1].texCoords = sf::Vector2f((i%3)*w+w, 0);
                VA[i*4+2].texCoords = sf::Vector2f((i%3)*w+w, h);
                VA[i*4+3].texCoords = sf::Vector2f((i%3)*w, h);
            }
            window.draw(VA, &tex);

            window.display();
            window.clear();
        }
    }
}
 
(yep, textures dimensions are hardcoded)

and textures used:
test1.png
test2.png
test3.png
atlas.png

with these textures i have ~725 ms for normal rendering and ~710 ms for VA
nvidia geforce 9600M GT, windows 7 32 bit

5
Graphics / Re: Max blend mode/rendering optimization
« on: November 14, 2012, 10:13:07 pm »
666 frames? 1 frame renders 1.5 sec, which means I have 0.666 frame/second

6
Graphics / Re: Max blend mode/rendering optimization
« on: November 14, 2012, 09:56:29 pm »
Thanks for answers.

Performance increase isn't as big as I expected.
100000 sprites per frame. 3 different textures.
Normal rendering: ~1500 ms / frame
Texture atlas: ~1485 ms / frame
VertexArray with texture atlas: ~1470 ms / frame

so actually it's not worth an effort.

7
Graphics / Max blend mode/rendering optimization
« on: November 13, 2012, 07:08:11 pm »
Hello :) I have a few questions.

Is it possible to achieve blend mode that outputs maximum of 2 colors for each color channel?
I've found this topic: http://stackoverflow.com/questions/2143690/is-it-possible-to-achieve-maxas-ad-opengl-blending however this solution doesn't seem to work.

The second question is: is it worth it to use texture atlas? If so, wouldn't it be a nice idea to implement such feature in SFML itself? I mean, when you load a texture you could have possibility to put it in 1 global texture atlas so there wouldn't be unnecessary calls for openGL to change current texture when you draw different sprites.

And the final question: is drawing a tile map using VertexArray more benefitial than drawing every sprite using draw calls individually? If so, then putting everything which has to be rendered to VertexArray and then using 1 draw call is the best solution right? Why do people use draw calls on each sprite rather than make 1 huge VertexArray?

Are there any other useful tricks to optimize rendering? I've noticed that changing current target buffer is very expensive. For example it's better to render all textures to the first FBO and then the others to the second FBO rather than mix these calls.

Thanks in advance

8
System / Re: Multithreaded loading screen
« on: September 24, 2012, 11:10:23 pm »
The one given in previous post is minimal bug-reproducing code, at least for me. When I change thread.launch() to just func() everything works fine - bitmap is displayed on a screen, if I use thread.launch() nothing is shown.

However, I found more interesting bug which I was debugging for ~2 hours. I found that you can't draw text using a default font in 1 thread while in second one work on text with the same font. What I was doing was displaying loading screen in main thread while in second load resources. When I used something like getLocalBounds() on a text (not the same text variable, just the same font - default one) in a second thread then font became damaged - some characters like 'I' were missing whenever I wanted to draw text with default font.
UB bugs are really hard to debug, it seems like index-out-of-bounds write so some character sprites are damaged(?) I don't know anything else that could do such thing. Maybe later I'll try to get minimal bug-reproducing code for this bug.

9
System / Re: Multithreaded loading screen
« on: September 24, 2012, 09:06:53 pm »
Oh, it seems you are right :)
I put loading resources in another thread and textures weren't displaying so I thought the problem was with textures loading, however I just noticed that it was because of FBO creation. They can't be created in another thread. FBOs creation is no big deal for me and can be done before resources loading thread, I guess they just need to be created with setActive(true) in current thread.
sf::Texture tex;
sf::RenderTexture fbo;

void func()
{
    tex.loadFromFile("test.png");
    fbo.create(100, 100);
}

int main(int argc, char **argv)
{
    sf::RenderWindow window(sf::VideoMode(1024, 768), "test", sf::Style::Default);
    sf::Thread thread(func);
    thread.launch();
    thread.wait();
    fbo.clear(sf::Color::White);
    fbo.draw(sf::Sprite(tex));
    fbo.display();
    window.draw(sf::Sprite(fbo.getTexture()));
    window.display();
    sf::sleep(sf::milliseconds(3000));
    return 0;
}
 

10
System / Multithreaded loading screen
« on: September 24, 2012, 08:33:21 pm »
Hello,
is it possible to load textures in another thread without using setActive?
I want to render and load resources simultaneously but it seems that textures can't be loaded from another thread.

11
General / Problem with getLocalBounds() for sf::Text
« on: August 28, 2012, 12:32:48 pm »
Hello,
I think there's a bug with getLocalBounds() method for sf::Text when there are spaces on the beginning or end of the string. I don't know, maybe it's a feature, but I need to get actual text size no matter if there are any spaces at the end, is it possible?
sf::Text text;
text.setCharacterSize(11);
text.setString("             ");
printf("%d\n", (int)text.getLocalBounds().width);
 
output is 0

I found a solution for this but it's not really nice way of getting actual text size I think ;)
Just add any letter on start and end of the string, get local bounds and then subtract length of these 2 letters.

12
General / Re: [SFML 2] Closing application via console
« on: August 25, 2012, 07:52:22 pm »
What happen without the loop ?
It doesn't matter what application is doing at the moment, I just did it to easily reproduce it so you have time to press console exit button.
If program exits normally SIGSEGV isn't raised.

13
General / [SFML 2] Closing application via console
« on: August 25, 2012, 06:33:24 pm »
Hello,
I've recently noticed that when I close my application via console close button, SIGSEGV is raised. Minimal program which reproduces this bug would be
int main()
{
    window.create(sf::VideoMode(1024, 768), "window", sf::Style::Default);
    sf::Text test;
    test.setCharacterSize(11);
    test.setString(" ");
    while(1);
}
 
When program reaches while(1) try to close it with console close button.
Problem occures only with sf::Text afaik. If you comment this line test.setString(" "); it doesn't happen.
Is it suppoused to be like this? I know that closing application via console close button isn't completely normal way to terminate application but it still shouldn't happen I think.

Pages: [1]