Exemple #1
0
 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")
Exemple #3
0
 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")
Exemple #5
0
 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)
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #8
0
    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
Exemple #9
0
 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)]
Exemple #10
0
 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
Exemple #11
0
 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
Exemple #12
0
    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
Exemple #13
0
    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
Exemple #14
0
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)]
Exemple #15
0
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)]
Exemple #16
0
    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
Exemple #17
0
 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
Exemple #18
0
 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]
Exemple #19
0
 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]
Exemple #20
0
 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]
Exemple #21
0
 def max_lod(self, max_lod):
     _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_MAX_LOD, _gl.pointer(_gl.GLint(max_lod)))
Exemple #22
0
 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]
Exemple #23
0
 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))
Exemple #24
0
 def base_level(self, base_level):
     with self:
         _gl.glTexParameterIiv(self._target, _gl.GL_TEXTURE_BASE_LEVEL, _gl.pointer(_gl.GLint(base_level)))
Exemple #25
0
 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
Exemple #26
0
 def _iformat(self):
     _iformat = _gl.GLint()
     with self:
         _gl.glGetTexLevelParameteriv(self._target, 0, _gl.GL_TEXTURE_INTERNAL_FORMAT, _gl.pointer(_iformat))
     return _iformat.value
Exemple #27
0
 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
Exemple #28
0
 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]
Exemple #29
0
 def max_level(self, max_level):
     with self:
         _gl.glTexParameterIiv(self._target, _gl.GL_TEXTURE_MAX_LEVEL, _gl.pointer(_gl.GLint(max_level)))
Exemple #30
0
 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]
Exemple #31
0
 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))
Exemple #32
0
 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]
Exemple #33
0
 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))
Exemple #34
0
 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
Exemple #35
0
 def _current_query(self):
     _current_query = _gl.GLint()
     _gl.glGetQueryiv(self._target, _gl.GL_CURRENT_QUERY, _gl.pointer(_current_query))
     return _current_query.value
Exemple #36
0
 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]
Exemple #37
0
 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)
Exemple #38
0
 def min_lod(self, min_lod):
     _gl.glSamplerParameteriv(self._id, _gl.GL_TEXTURE_MIN_LOD, _gl.pointer(_gl.GLint(min_lod)))
Exemple #39
0
 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))
Exemple #40
0
 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
Exemple #41
0
 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))
Exemple #42
0
 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)
Exemple #43
0
 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))
Exemple #44
0
 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
Exemple #45
0
 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))
Exemple #46
0
 def lod_bias(self, lod_bias):
     with self:
         _gl.glTexParameterfv(self._target, _gl.GL_TEXTURE_LOD_BIAS, _gl.pointer(_gl.GLfloat(lod_bias)))
Exemple #47
0
 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))
Exemple #48
0
 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]
Exemple #49
0
 def lod_bias(self, lod_bias):
     _gl.glSamplerParameterfv(self._id, _gl.GL_TEXTURE_LOD_BIAS, _gl.pointer(_gl.GLfloat(lod_bias)))
Exemple #50
0
 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))
Exemple #51
0
 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))
Exemple #52
0
 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
Exemple #53
0
 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
Exemple #54
0
 def max_lod(self, max_lod):
     with self:
         _gl.glTexParameterIiv(self._target, _gl.GL_TEXTURE_MAX_LOD, _gl.pointer(_gl.GLint(max_lod)))