Issues

Issue #353 resolved

Check if image has already been bound before binding

Alex Szpakowski
created an issue

Currently Image::bind() (which gets called right before drawing an image, which means it gets called once for each particle in a particle system every draw call) looks like this

{{{ void Image::bind() const { if (texture != 0) glBindTexture(GL_TEXTURE_2D,texture); } }}}

This means OpenGL will re-bind the image even when that exact image is already bound. Changing Image::bind() to this {{{ void Image::bind() const { if (texture == 0) return;

GLuint boundTex;
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *)&boundTex);

// only bind if this texture is not already bound
if (boundTex != texture)
    glBindTexture(GL_TEXTURE_2D, texture);

} }}}

Gives significant performance benefits. I haven't tested particle systems specifically yet, but drawing 1850 32x32 images at 800x600 on my Intel HD 3000 went from 10.5ms per frame down to 6.45ms with this change.

Comments (6)

  1. Alex Szpakowski reporter

    This is apparently way slower on nvidia cards (but still way faster on the others)... I think it would probably be best to implement a pure love version that doesn't need to check OpenGL, as long as it's reliable. Another option would be to disable the checking on video cards from nvidia, but that's a little hack-ish.

  2. Log in to comment