pyopengl
pyopengl copied to clipboard
GL_HALF_FLOAT support with glTexImage[2|3]D
Trying to use GL_HALF_FLOAT as type for glTexImage[2|3]D leads to the following error (tested on macos with python3.7 and pyopengl 3.1.5 without accelerate):
Traceback (most recent call last):
File "lib/python3.7/site-packages/OpenGL/latebind.py", line 43, in __call__
return self._finalCall( *args, **named )
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 232, in 'calling callback function'
File "test_half_float.py", line 62, in display
self.prepare_texture()
File "test_half_float.py", line 43, in prepare_texture
image)
File "lib/python3.7/site-packages/OpenGL/latebind.py", line 47, in __call__
return self._finalCall( *args, **named )
File "lib/python3.7/site-packages/OpenGL/wrapper.py", line 879, in wrapperCall
pyArgs = tuple( calculate_pyArgs( args ))
File "lib/python3.7/site-packages/OpenGL/wrapper.py", line 450, in calculate_pyArgs
yield converter(args[index], self, args)
File "lib/python3.7/site-packages/OpenGL/GL/images.py", line 455, in __call__
arrayType = arrays.GL_CONSTANT_TO_ARRAY_TYPE[ images.TYPE_TO_ARRAYTYPE[ type ] ]
KeyError: (GL_HALF_FLOAT_ARB, <OpenGL.GL.images.ImageInputConverter object at 0x10c57ac18>)
Traceback (most recent call last):
File "lib/python3.7/site-packages/OpenGL/latebind.py", line 43, in __call__
return self._finalCall( *args, **named )
Code to reproduce:
import OpenGL
OpenGL.FULL_LOGGING = True
import OpenGL.GL as gl
import OpenGL.GLUT as glut
import numpy
class TestWindow:
def __init__(self):
self.texid = None
glut.glutInit()
glut.glutInitDisplayMode(glut.GLUT_RGBA)
glut.glutInitWindowPosition(0, 0)
glut.glutInitWindowSize(600, 480)
self.window = glut.glutCreateWindow(b"Half float")
glut.glutDisplayFunc(self.display)
def prepare_texture(self):
shape = 128, 128, 128
image = numpy.random.random(numpy.prod(shape)).reshape(shape).astype(numpy.float16)
if self.texid is None:
gl.glEnable(gl.GL_TEXTURE_3D)
self.texid = gl.glGenTextures(1)
gl.glBindTexture(gl.GL_TEXTURE_3D, self.texid)
gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
gl.glTexImage3D(
gl.GL_TEXTURE_3D,
0,
gl.GL_R16F,
image.shape[2],
image.shape[1],
image.shape[0],
0,
gl.GL_RED,
gl.GL_HALF_FLOAT,
image)
else:
gl.glTexSubImage3D(
gl.GL_TEXTURE_3D,
0,
0,
0,
0,
image.shape[1],
image.shape[1],
image.shape[0],
gl.GL_RED,
gl.GL_HALF_FLOAT,
image)
def display(self):
gl.glClearColor(1., 0., 0., 1.)
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
self.prepare_texture()
gl.glBegin(gl.GL_QUADS)
gl.glTexCoord3f(0., 0., 1.)
gl.glVertex2f(-1., -1.)
gl.glTexCoord3f(1., 0., 1.)
gl.glVertex2f(1., -1.)
gl.glTexCoord3f(1., 1., 0.)
gl.glVertex2f(1., 1.)
gl.glTexCoord3f(0., 1., 0.)
gl.glVertex2f(-1., 1.)
gl.glEnd()
glut.glutSwapBuffers()
test = TestWindow()
glut.glutMainLoop()