Skip to content
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

Skip glTexCoordPointer() call if not needed (performance optimization) #1015

Closed
wants to merge 1 commit into from

Conversation

hobby8
Copy link
Contributor

@hobby8 hobby8 commented Dec 4, 2015

Aimed at saving memory bandwidth for drawing operations not involving textures nor shaders.
More details in this forum thread.

@binary1248 binary1248 added this to the 2.5 milestone Mar 27, 2017
@eXpl0it3r eXpl0it3r added this to Ready in SFML 2.5.0 Mar 27, 2017
@eXpl0it3r
Copy link
Member

Merged in 973ac8d on master

@eXpl0it3r eXpl0it3r closed this Apr 4, 2017
@eXpl0it3r eXpl0it3r moved this from Ready to Merged in SFML 2.5.0 Apr 4, 2017
@naezith
Copy link

naezith commented May 14, 2017

This update broke one of my shaders, it was working beautifully before. It's broken because my quad does not have a texture so gl_TexCoord[0].xy is (0,0) everywhere in the quad.

Is there an alternative variable I can use for that? I am drawing these bars and I need to know which pixel I am at.

void JumpPad::renderBar() {
        sf::VertexArray quad(sf::Quads, 4);
        sf::FloatRect new_rect = jp_rect.getGlobalBounds();
        quad[0].position = sf::Vector2f(new_rect.left, new_rect.top);
        quad[1].position = sf::Vector2f(new_rect.left + new_rect.width, new_rect.top);
        quad[2].position = sf::Vector2f(new_rect.left + new_rect.width, new_rect.top + new_rect.height);
        quad[3].position = sf::Vector2f(new_rect.left, new_rect.top + new_rect.height);

        quad[0].texCoords = sf::Vector2f(0, 0);
        quad[1].texCoords = sf::Vector2f(1, 0);
        quad[2].texCoords = sf::Vector2f(1, 1);
        quad[3].texCoords = sf::Vector2f(0, 1);

        Game::i().rt.draw(quad);
}



// Rendering all jump pads
    sf::Shader::bind(&shader_jump_pad);
    sf::Texture::bind(nullptr);
    for(auto& jp : jumppads) jp.renderBar();
    sf::Shader::bind(nullptr);

Edit: I had to take that variable out. Passed in camera position and more, then used gl_FragCoord.

@LaurentGomila
Copy link
Member

LaurentGomila commented May 15, 2017

Shader::bind and Texture::bind are meant for use with OpenGL drawing. Why are you using them together with regular RenderTarget::draw calls?

The "right" way to do it would be:

Game::i().rt.draw(quad, &shader_jump_pad);

If you do it this way, your shader should work as before.

@naezith
Copy link

naezith commented May 15, 2017

I was doing what you wrote but binding once was faster as I remember, coded it long time ago. They work nicely now without gl_TexCoord

@SFML SFML deleted a comment from eXpl0it3r Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.5.0
  
Merged / Superseded
Development

Successfully merging this pull request may close these issues.

None yet

5 participants