def result(self): if self._counter_bits <= 32: _result = _gl.GLuint() _gl.glGetQueryObjectuiv(self._id, _gl.GL_QUERY_RESULT_AVAILABLE, _gl.pointer(_result)) else: _result = _gl.GLuint64() _gl.glGetQueryObjectui64v(self._id, _gl.GL_QUERY_RESULT_AVAILABLE, _gl.pointer(_result)) return _result.value
def _get_active_X(self, getter, location_getter, max_length, index): _size = _gl.GLint() _type = _gl.GLenum() _name = _gl.create_string_buffer(max_length) with self._context: getter(self._id, index, max_length, None, _gl.pointer(_size), _gl.pointer(_type), _name) location = location_getter(self._id, _name) return location, _size.value, ShaderDatatype._from_gl(_type.value), _name.value.decode("ascii")
def _get_active_X(self, getter, location_getter, max_length, index): _size = _gl.GLint() _type = _gl.GLenum() _name = _gl.create_string_buffer(max_length) with self._context: getter(self._id, index, max_length, None, _gl.pointer(_size), _gl.pointer(_type), _name) location = location_getter(self._id, _name) return location, _size.value, ShaderDatatype._from_gl( _type.value), _name.value.decode("ascii")
def get_shape(self, level=0): """Returns the current texture data size at given mipmap level.""" with self: colors = gl_iformat_to_dtype[self._iformat][1] _width = _gl.GLint() _gl.glGetTexLevelParameteriv(self._target, level, _gl.GL_TEXTURE_WIDTH, _gl.pointer(_width)) if self._ndim == 2: return (_width.value, colors) _height = _gl.GLint() _gl.glGetTexLevelParameteriv(self._target, level, _gl.GL_TEXTURE_HEIGHT, _gl.pointer(_height)) if self._ndim == 3: return (_height.value, _width.value, colors) _depth = _gl.GLint() _gl.glGetTexLevelParameteriv(self._target, level, _gl.GL_TEXTURE_DEPTH, _gl.pointer(_depth)) if self._ndim == 4: return (_depth.value, _height.value, _width.value, colors)
def _log(self): with self._context: _info_log_length = _gl.GLint() _gl.glGetShaderiv(self._id, _gl.GL_INFO_LOG_LENGTH, _gl.pointer(_info_log_length)) _info_log = _gl.create_string_buffer(_info_log_length.value) _gl.glGetShaderInfoLog(self._id, _info_log_length, _gl.POINTER(_gl.GLint)(), _info_log) return _info_log.value
def source(self): with self._context: _shader_source_length = _gl.GLint() _gl.glGetShaderiv(self._id, _gl.GL_SHADER_SOURCE_LENGTH, _gl.pointer(_shader_source_length)) _source = _gl.create_string_buffer(_shader_source_length.value) _gl.glGetShaderSource(self._id, _shader_source_length, _gl.POINTER(_gl.GLint)(), _source) return _source.value
def __init__(self, context=None): """Create a new C{ManagedObject} using L{_generate_id}. @param context: The parent context. @type context: L{Context} """ if any(x is NotImplemented for x in (self._generate_id, self._delete_id)): raise TypeError("%s is abstract" % self.__class__.__name__) super(ManagedObject, self).__init__(context) with self._context: if hasattr(self._generate_id, "argtypes") and len( self._generate_id.argtypes) == 1: self._id = self._generate_id(self._type) elif hasattr(self._generate_id, "argtypes") and len( self._generate_id.argtypes) == 2: _id = _gl.GLuint() self._generate_id(1, _gl.pointer(_id)) self._id = _id.value else: self._id = self._generate_id() if self._id == 0: raise RuntimeError("could not create %s" % self.__class__.__name__) if self._db is not NotImplemented: getattr(self._context, self._db)._objects[self._id] = self
def __get__(self, obj, cls=None): if self._count_attr is None: with obj: return _gl.string_at(_gl.glGetString(self._arg)) else: with obj: _n = _gl.GLint() _gl.glGetIntegerv(self._count_attr, _gl.pointer(_n)) return [_gl.string_at(_gl.glGetStringi(self._arg, i)) for i in range(_n.value)]
def compile(self): with self._context: _gl.glCompileShader(self._id) _compile_status = _gl.GLint() _gl.glGetShaderiv(self._id, _gl.GL_COMPILE_STATUS, _gl.pointer(_compile_status)) if _compile_status.value != _gl.GL_TRUE: raise ShaderCompileError(self._log) return self._log or None
def initialize(argv=None): """Initialize GLUT. Called automatically on import.""" if argv is None: import sys argv = sys.argv _argc = _gl.c_int(len(argv)) _argv = (_gl.c_char_p * _argc.value)() if argv is not None: for i, a in enumerate(argv): _argv[i] = a.encode("ascii") if isinstance(a, str) else a _gl.glutInit(_gl.pointer(_argc), _argv) argv[:] = [_argv[i] for i in range(_argc.value)]
def __del__(self): """Delete the OpenGL object using L{_delete_id}. Any errors will be ignored because the OpenGL module may already have been garbage collected when the interpreter exits. """ try: if self._id is not None: with self._context: if hasattr(self._delete_id, "argtypes") and len( self._delete_id.argtypes) == 2: self._delete_id(1, _gl.pointer(_gl.GLuint(self._id))) else: self._delete_id(self._id) self._id = None except: pass
def _counter_bits(self): _counter_bits = _gl.GLint() _gl.glGetQueryiv(self._target, _gl.GL_QUERY_COUNTER_BITS, _gl.pointer(_counter_bits)) return _counter_bits.value
def swizzle_a(self): _swizzle_a = _gl.GLenum() with self: _gl.glGetTexParameterIuiv(self._target, _gl.GL_TEXTURE_SWIZZLE_A, _gl.pointer(_swizzle_a)) return self.swizzles[_swizzle_a.value]
def wrap_r(self): _wrap_r = _gl.GLenum() with self: _gl.glGetTexParameterIuiv(self._target, _gl.GL_TEXTURE_WRAP_R, _gl.pointer(_wrap_r)) return self.wrapmodes[_wrap_r.value]
def compare_mode(self): _compare_mode = _gl.GLenum() with self: _gl.glGetTexParameterIuiv(self._target, _gl.GL_TEXTURE_COMPARE_MODE, _gl.pointer(_compare_mode)) return self.compare_modes[_compare_mode.value]
def max_lod(self, max_lod): _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_MAX_LOD, _gl.pointer(_gl.GLint(max_lod)))
def compare_func(self): _compare_func = _gl.GLenum() with self: _gl.glGetTexParameterIuiv(self._target, _gl.GL_TEXTURE_COMPARE_FUNC, _gl.pointer(_compare_func)) return self.compare_funcs[_compare_func.value]
def compare_func(self, compare_func): _compare_func = _gl.GLenum(self.compare_funcs(compare_func)._value) with self: _gl.glTexParameterIuiv(self._target, _gl.GL_TEXTURE_COMPARE_FUNC, _gl.pointer(_compare_func))
def base_level(self, base_level): with self: _gl.glTexParameterIiv(self._target, _gl.GL_TEXTURE_BASE_LEVEL, _gl.pointer(_gl.GLint(base_level)))
def base_level(self): _base_level = _gl.GLint() with self: _gl.glGetTexParameterIiv(self._target, _gl.GL_TEXTURE_BASE_LEVEL, _gl.pointer(_base_level)) return _base_level.value
def _iformat(self): _iformat = _gl.GLint() with self: _gl.glGetTexLevelParameteriv(self._target, 0, _gl.GL_TEXTURE_INTERNAL_FORMAT, _gl.pointer(_iformat)) return _iformat.value
def max_level(self): _max_level = _gl.GLint() with self: _gl.glGetTexParameterIiv(self._target, _gl.GL_TEXTURE_MAX_LEVEL, _gl.pointer(_max_level)) return _max_level.value
def wrap_r(self): _wrap_r = _gl.GLint() _gl.glGetSamplerParameteriv(self._id, _gl.GL_TEXTURE_WRAP_R, _gl.pointer(_wrap_r)) return self.wrapmodes[_wrap_r.value]
def max_level(self, max_level): with self: _gl.glTexParameterIiv(self._target, _gl.GL_TEXTURE_MAX_LEVEL, _gl.pointer(_gl.GLint(max_level)))
def compare_func(self): _compare_func = _gl.GLint() _gl.glGetSamplerParameteriv(self._id, _gl.GL_TEXTURE_COMPARE_FUNC, _gl.pointer(_compare_func)) return self.compare_funcs[_compare_func.value]
def swizzle_a(self, swizzle_a): _swizzle_a = _gl.GLenum(self.swizzles(swizzle_a)._value) with self: _gl.glTexParameterIuiv(self._target, _gl.GL_TEXTURE_SWIZZLE_A, _gl.pointer(_swizzle_a))
def compare_mode(self): _compare_mode = _gl.GLint() _gl.glGetSamplerParameteriv(self._id, _gl.GL_TEXTURE_COMPARE_MODE, _gl.pointer(_compare_mode)) return self.compare_modes[_compare_mode.value]
def wrap_r(self, wrap_r): _wrap_r = _gl.GLenum(self.wrapmodes(wrap_r)._value) with self: _gl.glTexParameterIuiv(self._target, _gl.GL_TEXTURE_WRAP_R, _gl.pointer(_wrap_r))
def lod_bias(self): _lod_bias = _gl.GLfloat() _gl.glGetSamplerParameterfv(self._id, _gl.GL_TEXTURE_LOD_BIAS, _gl.pointer(_lod_bias)) return _lod_bias.value
def _current_query(self): _current_query = _gl.GLint() _gl.glGetQueryiv(self._target, _gl.GL_CURRENT_QUERY, _gl.pointer(_current_query)) return _current_query.value
def mag_filter(self): _mag_filter = _gl.GLint() _gl.glGetSamplerParameteriv(self._id, _gl.GL_TEXTURE_MAG_FILTER, _gl.pointer(_mag_filter)) return self.mag_filters[_mag_filter.value]
def result_available(self): _result_available = _gl.GLint() _gl.glGetQueryObjectiv(self._id, _gl.GL_QUERY_RESULT_AVAILABLE, _gl.pointer(_result_available)) return bool(_result_available.value)
def min_lod(self, min_lod): _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_MIN_LOD, _gl.pointer(_gl.GLint(min_lod)))
def compare_mode(self, compare_mode): _compare_mode = _gl.GLenum(self.compare_modes(compare_mode)._value) with self: _gl.glTexParameterIuiv(self._target, _gl.GL_TEXTURE_COMPARE_MODE, _gl.pointer(_compare_mode))
def min_lod(self): _min_lod = _gl.GLint() _gl.glGetSamplerParameteriv(self._id, _gl.GL_TEXTURE_MIN_LOD, _gl.pointer(_min_lod)) return _min_lod.value
def wrap_s(self, wrap_s): _wrap_s = _gl.GLint(self.wrapmodes(wrap_s)._value) _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_WRAP_S, _gl.pointer(_wrap_s))
def immutable_format(self): # Textures become immutable if their storage is specified with glTexStorage1D, glTexStorage2D or glTexStorage3D _immutable_format = _gl.GLenum() with self: _gl.glGetTexParameterIuiv(self._target, _gl.GL_TEXTURE_COMPARE_MODE, _gl.pointer(_immutable_format)) return bool(_immutable_format.value)
def wrap_r(self, wrap_r): _wrap_r = _gl.GLint(self.wrapmodes(wrap_r)._value) _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_WRAP_R, _gl.pointer(_wrap_r))
def lod_bias(self): _lod_bias = _gl.GLfloat() with self: _gl.glGetTexParameterfv(self._target, _gl.GL_TEXTURE_LOD_BIAS, _gl.pointer(_lod_bias)) return _lod_bias.value
def compare_func(self, compare_func): _compare_func = _gl.GLint(self.compare_funcs(compare_func)._value) _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_COMPARE_FUNC, _gl.pointer(_compare_func))
def lod_bias(self, lod_bias): with self: _gl.glTexParameterfv(self._target, _gl.GL_TEXTURE_LOD_BIAS, _gl.pointer(_gl.GLfloat(lod_bias)))
def compare_mode(self, compare_mode): _compare_mode = _gl.GLint(self.compare_modes(compare_mode)._value) _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_COMPARE_MODE, _gl.pointer(_compare_mode))
def mag_filter(self): _mag_filter = _gl.GLenum() with self: _gl.glGetTexParameterIuiv(self._target, _gl.GL_TEXTURE_MAG_FILTER, _gl.pointer(_mag_filter)) return self.mag_filters[_mag_filter.value]
def lod_bias(self, lod_bias): _gl.glSamplerParameterfv(self._id, _gl.GL_TEXTURE_LOD_BIAS, _gl.pointer(_gl.GLfloat(lod_bias)))
def mag_filter(self, mag_filter): _mag_filter = _gl.GLenum(self.mag_filters(mag_filter)._value) with self: _gl.glTexParameterIuiv(self._target, _gl.GL_TEXTURE_MAG_FILTER, _gl.pointer(_mag_filter))
def mag_filter(self, mag_filter): _mag_filter = _gl.GLint(self.mag_filters(mag_filter)._value) _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_MAG_FILTER, _gl.pointer(_mag_filter))
def max_lod(self): _max_lod = _gl.GLint() with self: _gl.glGetTexParameterIiv(self._target, _gl.GL_TEXTURE_MAX_LOD, _gl.pointer(_max_lod)) return _max_lod.value
def max_lod(self): _max_lod = _gl.GLint() _gl.glGetSamplerParameteriv(self._id, _gl.GL_TEXTURE_MAX_LOD, _gl.pointer(_max_lod)) return _max_lod.value
def max_lod(self, max_lod): with self: _gl.glTexParameterIiv(self._target, _gl.GL_TEXTURE_MAX_LOD, _gl.pointer(_gl.GLint(max_lod)))