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

Pages: 1 [2] 3 4 ... 16
16
Feature requests / One context per RenderTexture?
« on: September 04, 2015, 01:08:31 am »
I've been doing some research into the sfml source and have found that RenderTextureImpl* and Window creates extra contexts. Due to the performance hit discussed over here http://en.sfml-dev.org/forums/index.php?topic=18585.0 I wonder if it would be better to use a single-context strategy in RenderTexture?

To be more specific: why does RenderTextureImplFBO create a new context, when it could just create an fbo on the shared context and bind it on setActive?

17
Graphics / Re: Optimizing Rendering
« on: September 03, 2015, 06:57:28 am »
Instead of starting my own thread I'm just going to chime in here and say that I'm experiencing the same issues. I have lots of Render Textures and the profiler reveals that wglMakeCurrent is taking a substantial amount of time.  Afaict SFML uses one GL context per render texture and then has to switch between them.  I was curious whether the setActive() call was the buffer being flushed as binary suggested, so I made two minimal examples.

(A) uses 20 manually created FBOs and (B) uses 20 sf::RenderTextures. The code for each is below. (A) runs at around 340 fps and (B) runs at 220 fps on my machine. MSVC's profiler shows (B) on the right and you can see wglMakeCurrent takes up a big chunk of the total run-time.

I talked about it a little on twitter and I think that having one context per render texture is not a great approach when rendertexture count is high. Also, a discussion here comments about a few strategies to optimise the use of many fbos. One strategy is to have a single FBO and then rebind different textures to them as you render. It's a very specific use case, but unfortunately seems a little tricky with the one context-per-render texture approach of sfml.



#include <GL/glew.h>
#include <SFML/Graphics.hpp>
// #include <SFML/OpenGL.hpp>
// #include "mm/common/profiler.h"
#include <array>
#include <iostream>
#include <Windows.h>

// as per: http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf
extern "C" {
        _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}

int main1();
int main2();
void drawThing();

int main(){    
        // return main1();
        return main2();
};


static const int W = 800;
static const int N = 20;

int main1()
{
        sf::RenderWindow window(sf::VideoMode(W, W), "test");
        window.setFramerateLimit(1000);

       
        std::array<sf::RenderTexture, N> rts;
        for (auto& rt: rts)     rt.create(W, W);
       
        sf::Clock clock;
        int frameCount = 0;
        while (window.isOpen())
        {
                // BROFILER_FRAME("App");

                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed) window.close();
                        if (event.type == sf::Event::KeyPressed){
                                if (event.key.code == sf::Keyboard::Escape){
                                        window.close();
                                }
                        }
                }

                // draw to texture
                for (auto& rt : rts){
                        rt.clear(sf::Color(255,0,0));
                        rt.setActive(true);
                        //rt.pushGLStates();
                        rt.setView(sf::View(sf::FloatRect(0,W,W,W)));

                        glViewport(0, 0, W, W);

                        glMatrixMode(GL_PROJECTION);
                        glPushMatrix();
                        glLoadIdentity();
                        glOrtho(0.0, W, 0.0, W, -1.0, 1.0);
                        glMatrixMode(GL_MODELVIEW);
                        glPushMatrix();
                        glLoadIdentity();
               
                        drawThing();

                        glPopMatrix();
                        glPopMatrix();

                        /*
                        sf::RectangleShape shape(sf::Vector2f(W / 2, W / 2));
                        shape.setOrigin(W / 4, W / 4);
                        shape.setPosition(W / 2, W / 2);
                        rt.draw(shape);
                        */



                        rt.display();

                        //rt.popGLStates();
                }
                window.setActive(true);
                window.pushGLStates();
                // draw textures to window
                window.clear();
                for (auto& rt : rts){
                        auto spr = sf::Sprite(rt.getTexture());
                        window.draw(spr);
                }
                window.display();
                window.popGLStates();

                frameCount++;
                if (frameCount > 100){
                        std::cout << 1./(clock.getElapsedTime().asSeconds() / 100) << std::endl;
                        frameCount = 0;
                        clock.restart();
                }
        }

        return EXIT_SUCCESS;
}

std::pair<int,int> makeFBO(int w, int h){
        GLuint tex, fb;

        glGenTextures(1, &tex);
        glBindTexture(GL_TEXTURE_2D, tex);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

        //NULL means reserve texture memory, but texels are undefined
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
        //-------------------------
        glGenFramebuffers(1, &fb);
        glBindFramebuffer(GL_FRAMEBUFFER, fb);

        //Attach 2D texture to this FBO
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
       
        //Does the GPU support current FBO configuration?
        GLenum status;
        status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        switch (status)
        {
        case GL_FRAMEBUFFER_COMPLETE:
                std::cout << "good";
                break;
        default:
                std::exit(EXIT_FAILURE);
        }

        return { fb, tex };
}

int main2()
{      
        sf::RenderWindow window(sf::VideoMode(W, W), "test");
        window.setFramerateLimit(1000);
        glewInit();
        std::array<std::pair<int,int>, N> fbos;
        for (int i = 0; i < N; i++){
                fbos[i] = makeFBO(W, W);
        }
       
        sf::Clock clock;
        int frameCount = 0;
        while (window.isOpen())
        {
                // BROFILER_FRAME("App");

                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed) window.close();
                        if (event.type == sf::Event::KeyPressed){
                                if (event.key.code == sf::Keyboard::Escape){
                                        window.close();
                                }
                        }
                }

                // draw to fbos
                for (auto& fbo: fbos){

                        window.pushGLStates();

                        glMatrixMode(GL_PROJECTION);
                        glPushMatrix();
                        glLoadIdentity();
                        glOrtho(0.0, W, 0.0, W, -1.0, 1.0);
                        glMatrixMode(GL_MODELVIEW);
                        glPushMatrix();
                        glLoadIdentity();

                        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.first);
                        glClearColor(1, 0, 0, 1);
                        glClear(GL_COLOR_BUFFER_BIT);

                        drawThing();

                        glPopMatrix();
                        glPopMatrix();

                        window.popGLStates();

                }
                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

                // draw textures to window
                window.clear();

                window.pushGLStates();
                glMatrixMode(GL_PROJECTION);
                glPushMatrix();
                glLoadIdentity();
                glOrtho(0.0, W, 0.0, W, -1.0, 1.0);
                glMatrixMode(GL_MODELVIEW);
                glPushMatrix();
                glLoadIdentity();
               
                for (auto& fb: fbos){
                        glColor3f(1, 1, 1);
                        glEnable(GL_TEXTURE_2D);
                        glBindTexture(GL_TEXTURE_2D, fb.second);

                        glBegin(GL_QUADS);
                        glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
                        glTexCoord2f(0, 1); glVertex3f(0, W, 0);
                        glTexCoord2f(1, 1); glVertex3f(W, W, 0);
                        glTexCoord2f(1, 0); glVertex3f(W, 0, 0);
                        glEnd();

                        // auto spr = sf::Sprite(rt.getTexture());
                        // window.draw(spr);                                           
                }

                glPopMatrix();
                glPopMatrix();

                window.popGLStates();
               
                window.display();

                frameCount++;
                if (frameCount > 100){
                        std::cout << 1. / (clock.getElapsedTime().asSeconds() / 100) << std::endl;
                        frameCount = 0;
                        clock.restart();
                }
        }

        return EXIT_SUCCESS;
}

void drawThing(){
        int W = 500;

        // do drawing  
        glBegin(GL_QUADS);
        glColor3f(1, 1, 1);
        glVertex2f(0, 0);
        glVertex2f(W, 0);
        glVertex2f(W, W/2);
        glVertex2f(0, W / 2);
        glColor3f(1, 0, 1);
        glVertex2f(0, 0);
        glVertex2f(W/2, 0);
        glVertex2f(W/2, W / 4);
        glVertex2f(0, W / 4);
        glEnd();


}

18
SFML website / Re: Showcase section on site?
« on: July 19, 2015, 06:38:52 am »
Just found out about this site:

http://dev.sfmlprojects.org/games

It looks pretty damn good and may be used to showcase SFML games pretty well.

Oh, that looks pretty neat. Would be good to just merge that games page into the main website and adapt the styling appropriately.

19
SFML website / Re: Showcase section on site?
« on: July 15, 2015, 02:23:02 am »
This all sounds great, glad you guys are up for it. We definitely want to show off different styles, I agree 100%.

On SDL: I refreshed the SDL page, I see they are from a pool, but the pool doesn't seem that big (maybe 20 games max?) They all seem like commercial games too, and the promotion image is not a screenshot. So I think in this sense it has a different agenda, it's saying "all these great games are made with SDL, you can trust that SDL is capable." Which is different than saying "here's some screenshots, you can make things like these."

So I guess there are two different angles this could be approached from. The good thing about the SDL way is it doesn't matter what style the game is, as they just show the promotion/cover image. It's the fact the game exists, and you can click the link and check it out, that is important there. So maybe we should approach this the same way?

Whatever you choose to do I think we all agree that it'll be nice to have a little section on the site to see some great things made with SFML.

20
SFML website / Re: Showcase section on site?
« on: July 14, 2015, 01:40:48 am »
Well I just feel having only 3 or 4 projects picked would be unfair for other projects. As you see with the Unity Showcase and many other similar sites, they usually go for nothing or everything. ;)

Oh I disagree. Here's some instances:

Unity: Probably millions of games made with unity but they feature about 100 on that main page.

Ogre3d show about 10 games or so, out of the many thousands of commercial games and otherwise: http://www.ogre3d.org/gallery

GLFW: Doesn't have a showcase section, but has a news feed which occasionally features games: http://www.glfw.org/The-Polynomial.html

SDL: Features projects on their front page https://www.libsdl.org/

The question of fairness is something I thought would come up, but this is about promoting SFML and its capabilities -- not promoting the games themselves. If someone gets annoyed because their game isn't shown in the showcase then they are missing the point.

I think the best way to do it would be for Laurent or whoever's mainly in charge these days to just select some from a pool.

21
SFML website / Re: Showcase section on site?
« on: July 13, 2015, 10:20:47 am »
I think you'd just want to pick a good representative sample of about 3 or 4. It's more about answering the question "why kind of games can i (realistically) make with sfml" than "what are all the projects made with sfml".

The unity showcase has good examples: a short snippet of text, a screenshot or two, and a link. https://unity3d.com/showcase/gallery

Maybe this thread could be for potential projects, which are then voted on? Otherwise, maybe the main devs could choose one each?

22
SFML website / Showcase section on site?
« on: July 12, 2015, 02:17:30 am »
I was asking around on Twitter about SFML-based games, and I think there are quite a few interesting-looking ones that would make a great little visual showcase for the website. Here's a few screenshots and links to the projects - the last one is from my own project, Moonman. (I also added them to the wiki/Projects.)

I think a good format would be the same layout as the front page, but instead have 3 games with images, a description of the game, and maybe a quote from the developer about SFML.

Thoughts?

http://www.pioneersgame.com/


http://vagantegame.com/


http://www.playcrea.com/


http://moonman.io



23
Graphics / Re: RenderTexture and GL_OUT_OF_MEMORY
« on: June 12, 2015, 02:31:23 am »
Eigenbom, just for clarification on your question, I think it would be wise to confirm that you're saying that RenderTexture returns false on failure but Texture returns true on failure. If that's not what you were stating, your question is extremely misleading.

Yep, that's what I'm saying. RenderTexture thinks that its internal Texture->create() succeeded, when actually OpenGL had already reported a GL_OUT_OF_MEMORY error. It would be nice if SFML was a bit more robust in this area .. sure you'll never have 100% valid error checking because memory errors can be weird or reported late etc, but you can start to check some of them after certain allocations. Checking for GL_OUT_OF_MEMORY after glTexImage2D seems like a reasonable candidate.

Unfortunately I've got to get back work now, the Moonman beckons.

24
Graphics / Re: RenderTexture and GL_OUT_OF_MEMORY
« on: June 11, 2015, 05:27:57 am »
Thanks for the info, but that's really beside the point of what my thread was about.

My only concern is just that Texture::create() returns true if it fails to create a texture, despite what the documentation says. You're saying that it's a problem with the caller, and that the caller should know if it will succeed or not.

25
Graphics / RenderTexture and GL_OUT_OF_MEMORY
« on: June 11, 2015, 02:08:29 am »
Hi! So I'm greedily creating RenderTextures at the maximum texture size, the calls are failing, and then the create(w,h) function returns false. That's all fine, however the error printed is:

"Impossible to create render texture (failed to link the target texture to the framebuffer)".

Running in DEBUG shows more precisely that the problem is actually a GL_OUT_OF_MEMORY error, caused when creating the internal Texture.

I think it'd be nice if the Texture::create function fails and returns false if it can't create the texture because of memory. This would then also let RenderTexture report the true error, that resides with the texture creation.

(In my case I just call RenderTexture::create() with halving sizes until it succeeds, so my system works fine.)

26
SFML projects / Re: Screenshot Thread
« on: April 21, 2015, 09:16:55 am »
Just been working away on Moonman as is my life :) Saw this thread from chatting to Hiura on twitter. Plenty more screens etc at the mm forum. Keep up the fun work everyone


27
SFML projects / Re: Moonman (my sfml game is on kickstarter!)
« on: February 09, 2015, 12:11:10 am »
Yep we made it! Thanks everyone for backing the project and showing enthusiasm for it! :D

28
SFML projects / Re: Moonman (my sfml game is on kickstarter!)
« on: February 08, 2015, 01:03:04 am »
Thanks Grimshaw :D

The Kickstarter is 97% funded and has 4 days left! Thanks for getting involved you guys, and if you're going to back to get alpha access and KS-only updates, then now is the time to do it. I'm going to be really busy the next few weeks so I might not be around, but please ping me at @eigenbom if you want to say hi or ask a question. :D

Go SFML! :D

29
SFML projects / Re: Moonman (my sfml game is on kickstarter!)
« on: February 06, 2015, 09:17:27 am »
Wow, this is so good, not my kind of game but it's really well done and the graphic style is incredible.
Also this kind of games it's usually popular on YT, have you thought about giving it for free to a few youtubers?
you could get a lot of attention in that way.

--
Also code related question, if I can ask, you said that you are for the most part using sf::sprites, for the terrain too? doesn't that cause issues? or the culling is enough to avoid problems?

Hey thanks :) yep I've had some big you tubers play it, with over 40000 views total I think.

I split the terrain up into 16x16 tile chunks and use a render texture to cache the rendering. So if the terrain doesn't change its only a few draw calls.

30
SFML projects / Re: Moonman (my sfml game is on kickstarter!)
« on: February 06, 2015, 12:20:03 am »
Well it's been an absolutely crazy few weeks. I'll tell you all about it one day, but it's really been a rollercoaster. Some days I wake up with 30 emails and other days I wake up with nothing. I've sent hundreds of emails to the press, done 5 or so interviews, and haven't had a break.

Moonman is 85% funded and has 6 days to go!

If you haven't yet backed it, now is the time! :D






Pages: 1 [2] 3 4 ... 16