New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader::isAvailable() breaks Texture when no GlResource has been created so far #211

Closed
mrwonko opened this Issue Apr 18, 2012 · 4 comments

Comments

Projects
None yet
5 participants
@mrwonko

mrwonko commented Apr 18, 2012

When Shader::isAvailable() is called before any sf::GlResource has been created, sf::Texture won't work. (It's completely white.) Fragment Shaders break, too.

This may be because priv::GlContext::globalInit() has not been called.

Code to reproduce:

#include <SFML/Graphics.hpp>

int main()
{
    sf::Shader::isAvailable(); //move this anywhere else and it works
    sf::Texture tex;
    if(!tex.loadFromFile("texture.jpg"))
    {
        return 0;
    }
    sf::Sprite sprite(tex);
    sf::RenderWindow wnd(sf::VideoMode(800, 600), "Shader::isAvailable() Texture bug");
    while(wnd.isOpen())
    {
        sf::Event ev;
        while(wnd.pollEvent(ev))
        {
            if(ev.type == sf::Event::Closed)
            {
                wnd.close();
            }
        }
        wnd.clear();
        wnd.draw(sprite);
        wnd.display();
    }
    return 0;
}

@ghost ghost assigned LaurentGomila Apr 19, 2012

@LaurentGomila

This comment has been minimized.

Show comment
Hide comment
@LaurentGomila

LaurentGomila Jun 19, 2013

Member

This is annoying...

The automatic context system relies on reference counting, which implies that only objects will make OpenGL calls. But there is this function, which doesn't require any object because it is static, and yet makes an OpenGL call.

I don't see any simple solution to this problem. So for now, one should never call sf::Shader::isAvailable() before creating any window, context or graphical resource.

Member

LaurentGomila commented Jun 19, 2013

This is annoying...

The automatic context system relies on reference counting, which implies that only objects will make OpenGL calls. But there is this function, which doesn't require any object because it is static, and yet makes an OpenGL call.

I don't see any simple solution to this problem. So for now, one should never call sf::Shader::isAvailable() before creating any window, context or graphical resource.

@Oberon00

This comment has been minimized.

Show comment
Hide comment
@Oberon00

Oberon00 Jun 24, 2013

Contributor

What's the problem with calling (protected by a mutex) globalInit() in ensureContext() if sharedContext == NULL? This would also simplify the GlResource constructor. Or are there cases where a thread context is required, but no shared one?

Contributor

Oberon00 commented Jun 24, 2013

What's the problem with calling (protected by a mutex) globalInit() in ensureContext() if sharedContext == NULL? This would also simplify the GlResource constructor. Or are there cases where a thread context is required, but no shared one?

@LaurentGomila

This comment has been minimized.

Show comment
Hide comment
@LaurentGomila

LaurentGomila Jun 24, 2013

Member

The global init/cleanup is driven by reference counting. If I call one of these functions directly I'll invalidate the reference counter.

Member

LaurentGomila commented Jun 24, 2013

The global init/cleanup is driven by reference counting. If I call one of these functions directly I'll invalidate the reference counter.

binary1248 added a commit that referenced this issue May 19, 2014

Fix the case where not having created a GlResource prior to calling S…
…hader::isAvailable() would break context management. (#211)

binary1248 added a commit that referenced this issue May 22, 2014

Fix the case where not having created a GlResource prior to calling S…
…hader::isAvailable() would break context management. (#211)
@eXpl0it3r

This comment has been minimized.

Show comment
Hide comment
@eXpl0it3r

eXpl0it3r May 22, 2014

Member

Merged in 1fe22e2

Member

eXpl0it3r commented May 22, 2014

Merged in 1fe22e2

@eXpl0it3r eXpl0it3r closed this May 22, 2014

@eXpl0it3r eXpl0it3r added resolved and removed confirmed labels May 22, 2014

@eXpl0it3r eXpl0it3r modified the milestones: 2.2, 2.x May 22, 2014

jcowgill added a commit to jcowgill/SFML that referenced this issue Sep 22, 2014

Fix the case where not having created a GlResource prior to calling S…
…hader::isAvailable() would break context management. (SFML#211)

(cherry picked from commit 1fe22e2)

James Cowgill: use old ensureGlewInit function

Conflicts:
	src/SFML/Graphics/Shader.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment