0

On Ubuntu 14.04, I'm testing an open source project which uses pyglet. I'm running /usr/bin/Xorg directly and separately, using the Nvidia driver with a Nvidia GPU.

The project has this part:

buffer = pyglet.image.get_buffer_manager().get_color_buffer()
image_data = buffer.get_image_data()

And pyglet.gl.lib.GLException: invalid operation occurs when it executes the second line.

Therefore I debugged using PYGLET_DEBUG_GL_* environment variables, and figured out that the error happens while calling glReadPixels(0, 0, 600, 400, 6407, 5121, <pyglet.image.c_ubyt).

The pyglet part of the stack trace is here: 1, 2

ColorBufferImage class originally uses GL_RGBA, and I tried changing it to use GL_RGB, by modifying the 2 lines here.

I didn't anticipate it, but GL_RGB made the glReadPixels() call work without the error, though I cannot use it since the open source project assumes it would be GL_RGBA.

I really want to know how to make GL_RGBA work...

Could someone please help me?

Update: I've just tried an another option, and I think changing the data type from GL_UNSIGNED_BYTE to GL_UNSIGNED_SHORT works (I also changed the buffer's primitive type from GLubyte to GLushort). If this is right, is this a bug of pyglet?

noname
  • 343
  • 4
  • 14
  • So does your buffer have alpha values? – stark Oct 09 '16 at 16:52
  • @stark Thanks for commenting, yes the buffer is `(GLubyte * (len(self.format) * self.width * self.height))()` and `len(self.format)` is 4. – noname Oct 09 '16 at 16:58
  • @noname; That does not answer the question. `self.format` is still ambiguous. What is `self.format`? Is the buffer you read into large enough? Does the type match the format? – thokra Oct 10 '16 at 11:23
  • @thokra It's just 'RGBA', and its length is 4. This representation is used inside pyglet. – noname Oct 10 '16 at 11:46
  • @thokra ADD: I accidentally pressed Enter, so I'm adding. I think the buffer size is OK. The original combination which doesn't work: `GL_RGBA`, `GL_UNSIGNED_BYTE`, `GLubyte` The new combination that works: `GL_RGBA`, `GL_UNSIGNED_SHORT`, `GLushort` So what I'm wondering is, I had to modify pyglet's source code, does that mean it's a bug? – noname Oct 10 '16 at 11:52
  • Would this solve the problem? `buffer.get_image_data().get_data("RGBA", 4)` or `"RGB", 3`? Does it make a difference? If not is there another option than to use `get_buffer_manager` and it's subfunction? – Torxed Oct 10 '16 at 12:24
  • Or fiddle around with the [Context Config](https://pyglet.readthedocs.io/en/latest/programming_guide/context.html) parameter that controls the `alpha_size` for instance. – Torxed Oct 10 '16 at 12:26

0 Answers0