def canUseFloatTextures(nvals=1): """Returns ``True`` if this GL environment supports floating point textures, ``False`` otherwise. The test is based on the availability of the ``ARB_texture_float`` extension. :arg nvals: Number of values per voxel :returns: A tuple containing: - ``True`` if floating point textures are supported, ``False`` otherwise - The base texture format to use (``None`` if floating point textures are not supported) - The internal texture format to use (``None`` if floating point textures are not supported) """ # We need the texture_float extension. The # texture_rg extension just provides some # nicer/more modern data types, but is not # necessary. floatSupported = glexts.hasExtension('GL_ARB_texture_float') rgSupported = glexts.hasExtension('GL_ARB_texture_rg') if not floatSupported: return False, None, None if rgSupported: if nvals == 1: baseFmt = gl.GL_RED elif nvals == 3: baseFmt = gl.GL_RGB elif nvals == 4: baseFmt = gl.GL_RGBA if nvals == 1: intFmt = gl.GL_R32F elif nvals == 3: intFmt = gl.GL_RGB32F elif nvals == 4: intFmt = gl.GL_RGBA32F return True, baseFmt, intFmt else: if nvals == 1: baseFmt = gl.GL_LUMINANCE elif nvals == 3: baseFmt = gl.GL_RGB elif nvals == 4: baseFmt = gl.GL_RGBA if nvals == 1: intFmt = arbtf.GL_LUMINANCE32F_ARB elif nvals == 3: intFmt = gl.GL_RGB32F elif nvals == 4: intFmt = gl.GL_RGBA32F return True, baseFmt, intFmt
def oneChannelFormat(dtype): """Determines suitable one-channel base and internal texture formats to use for the given ``numpy`` data type. :return: A tuple containing: - the base texture format to use - the internal texture format to use .. note:: This is used by the :func:`getTextureType` function. The returned formats may be ignored for floating point data types, depending on whether floating point textures are supported - see :func:`canUseFloatTextures`. """ # Make sure we have a numpy dtype # *instance*, and not a class. dtype = _makeInstance(dtype) floatSupported = glexts.hasExtension('GL_ARB_texture_float') rgSupported = glexts.hasExtension('GL_ARB_texture_rg') nbits = dtype.itemsize * 8 if rgSupported: if nbits == 8: return gl.GL_RED, gl.GL_R8 else: return gl.GL_RED, gl.GL_R16 # GL_RED does not exist in old OpenGLs - # we have to use luminance instead. else: if nbits == 8: return gl.GL_LUMINANCE, gl.GL_LUMINANCE8 # But GL_LUMINANCE is deprecated in GL 3.x, # and some more recent GL drivers seem to # have trouble displaying GL_LUMINANCE16 # textures - displayting them at what seems # to be a down-sampled (e.g. using a 4 bit # storage format) version of the data. So we # store the data as floating point if we can. elif floatSupported: return gl.GL_LUMINANCE, arbtf.GL_LUMINANCE16F_ARB # Hopefully float textures are supported # on recent GL drivers which don't support # LUMINANCE_16 else: return gl.GL_LUMINANCE, gl.GL_LUMINANCE16
def queryExtensions(*args): from OpenGL import extensions class Extensions(object): pass result = Extensions() _logger.info("Extensions:") for name in args: value = extensions.hasExtension(name) setattr(result, name, value) _logger.info("%s: %s", name, value) return result