1

I'm getting out of memory errors when creating a large (2^13) framebuffer object in PyOpenGL/PyQt:

    width = 8192
    height = 8192

    self.textureFbo = QtOpenGL.QGLFramebufferObject(width,height)
    self.textureFbo.bind()

    texture = self.bindTexture(QtGui.QPixmap(self.textureFilePath)) # 2^13
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glClear (GL_COLOR_BUFFER_BIT);

    glLoadIdentity()
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity()
    glOrtho(0, +1, +1, 0, -0.1, 2.0);

    glBegin(GL_POLYGON);
    glTexCoord2d(1.0, 0.0)      
    glVertex3f (0.0, 0.0, 0.0)
    glTexCoord2d(1.0, 1.0)
    glVertex3f (1.0, 0.0, 0.0)
    glTexCoord2d(0.0, 1.0)
    glVertex3f (1.0, 1.0, 0.0)
    glTexCoord2d(0.0, 0.0)
    glVertex3f (0.0, 1.0, 0.0)
    glEnd();

    self.deleteTexture(texture)
    self.textureFbo.release()
    self.textureFboLoaded = True

gives:

OpenGL.error.GLError: GLError(
        err = 1285,
        description = 'out of memory',
        baseOperation = glClear,
        cArguments = (GL_COLOR_BUFFER_BIT,)
)
QGLFramebufferObject: Framebuffer incomplete attachment.
Traceback (most recent call last):
  File "main.py", line 286, in paintGL
    self.loadTextureFBO()
  File "main.py", line 357, in loadTextureFBO
    glEnable(GL_TEXTURE_2D)
  File "C:\Python27\lib\site-packages\OpenGL\error.py", line 208, in glCheckErro
r
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
        err = 1285,
        description = 'out of memory',
        baseOperation = glEnable,
        cArguments = (GL_TEXTURE_2D,)
)
QImage: out of memory, returning null image

However this works fine if I step down to either a 2^12 texture, or FBO.

It seems unreasonable to me that two images (FBO+texure) of around 132mb 268mb each (4 bytes*8192^2) should fill up my 1gb of video memory. What am I missing?

genpfault
  • 47,669
  • 9
  • 68
  • 119
leohutson
  • 85
  • 2
  • 9

1 Answers1

1

First, note that 4 x 8192^2 is 268M, not 132, so we're talking over half a GB, for these two objects. Presumably there are other demands on memory, too. I agree it sounds like you should not have a problem, but I don't know what else is going on.

Ernest Friedman-Hill
  • 77,245
  • 10
  • 138
  • 182
  • Thanks for the answer, I just found a video card profiler called GPU-Z, it does not show the memory usage of my second GPU, only my first. So I'm assuming my SLI setup is messed up, and I only have 1GB of vram. Anyway, the baseline video memory usage before I run my script is 26mb. I run my script at the maximum framebuffer size I can, which I figured out after trial and error is exactly 7287^2, and the vram usage peaks at 589mb, then I increase the image size to 7288^2, and get the out of memory error. Weird, perhaps there's an upper bound to framebuffer size other than the memory limit? – leohutson Apr 28 '11 at 02:42
  • 1
    In SLI, the textures need to get loaded to both cards (how else could texture units on both cards run efficiently), so you can't add the VRAM sizes together. – Ben Voigt Apr 28 '11 at 03:32
  • That makes a lot sense, still; the vram usage peaks at 589mb, so it seems weird that it runs out of memory for a very slightly larger framebuffer. – leohutson Apr 28 '11 at 04:02
  • 1
    @Leo: Remember that your program isn't the only thing using VRAM--probably your OS/Window system and any other programs that might be running are impacting it as well. The video memory might just be fragmented such that there is enough memory available, but not in one contiguous chunk. – Drew Hall May 06 '11 at 01:28
  • 1
    Ah, thanks; that was what it was, non-contiguous memory, I split the texture up into four separate framebuffers and the problem went away. – leohutson May 12 '11 at 04:19