google-code-export / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

pyglet.image.Texture assumes Tex2d #605

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
pyglet.Image.create_for_size accepts a 'target' parameter.
The default would be GL_TEXTURE_2D.
I am trying to create a 1D texture for a GLSL shader.
Passing GL_TEXTURE_1D or other values creates an error.

Looking at the code, it becomes obvious that Texture is assumed to be 2D only.

The documentation should be updated to make it clearer what 'target' means and 
what values are available (this page contains a list 
http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml )

It would be _fantastic_ if Texture could be abstracted to provide 1D / 3D 
support too.
I think this is unlikely however.

What steps will reproduce the problem?
1. import pyglet
2. texture = pyglet.image.Texture.create_for_size(
            GL_TEXTURE_1D,
            60,
            1,
            GL_RGB
            )

Paste in the traceback or error message:
  File "/Users/adamgriffiths/Workspace/VirtualEnvs/razorback/lib/python2.7/site-packages/pyglet/image/__init__.py", line 1569, in create_for_size
    blank)
  File "/Users/adamgriffiths/Workspace/VirtualEnvs/razorback/lib/python2.7/site-packages/pyglet/gl/lib.py", line 105, in errcheck
    raise GLException(msg)
pyglet.gl.lib.GLException: invalid enumerant

pyglet 1.2 alpha (HEAD from repo) with Python 2.7.3 on OS-X 10.8

Original issue reported on code.google.com by adam.lw....@gmail.com on 9 Sep 2012 at 8:52

GoogleCodeExporter commented 9 years ago
It seems GL_TEXTURE_3D has been split off into it's own Texture3D class, so it 
makes sense for any changes to be for a new Texture1D class.
The image blit_to_texture methods would also have to be updated to handle 
glTexImage1D instead of glTexImage2d/3d as it is now.

Original comment by adam.lw....@gmail.com on 9 Sep 2012 at 9:29

GoogleCodeExporter commented 9 years ago
I've modified pyglet.image.Texture in a fork on Github.
https://github.com/adamlwgriffiths/Pyglet/commit/f00fed3bb8f7a4fc8be57e6307feef8
58da8ed34

It may not be the best way to do it.

Original comment by adam.lw....@gmail.com on 13 Sep 2012 at 2:53

GoogleCodeExporter commented 9 years ago
I'm not sure if there are more 1D 'target' types apart from GL_TEXTURE_1D.
I have to take into account that there are many 2D types, not just 
GL_TEXTURE_2D.

Hence, most code is:
if target != GL_TEXTURE_2D:
  do 1D stuff

Honestly, the image module needs a bit of refactoring. But it's working at the 
moment so it's obviously a low priority =)

Original comment by adam.lw....@gmail.com on 13 Sep 2012 at 2:55

GoogleCodeExporter commented 9 years ago

Original comment by useboxnet on 21 Sep 2013 at 10:52