Commits

Leonard Ritter committed 9016523

glDrawBuffers, glTexSubImage, glReadPixels

Comments (0)

Files changed (1)

     GL_DOUBLE: GLdouble,
 }
 
+GL_FORMAT_TO_COUNT = {
+    GL_RED : 1,
+    GL_RG : 2,
+    GL_RGB : 3,
+    GL_RGBA : 4
+}
+
 ################################################################################
 
 def _cstr(data):
     return _ffi.new('{0}[{1}]'.format(
             GL_TYPE_ID_TO_TYPE[typeid],count))
     
+def glDrawBuffers(bufs):
+    print(bufs)
+    _glDrawBuffers(len(bufs), _array('GLenum', bufs))
+    
 def glShaderSource(shader, sources):
     sources = [_cstr(source) for source in sources]
     _glShaderSource(shader, len(sources), sources, _ffi.NULL)
 def glGetShaderInfoLog(shader):
     maxLength = glGetShaderiv(shader, GL_INFO_LOG_LENGTH)
     length = _ffi.new('GLsizei *')    
-    infoLog = _ffi.new('char[{0}]'.format(maxLength))
+    infoLog = _ffi.new('char[]', maxLength)
     _glGetShaderInfoLog(shader, maxLength, length, infoLog)
     return _ffi.string(infoLog)
 
 def glGetShaderSource(shader):
     maxLength = glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH)
     length = _ffi.new('GLsizei *')    
-    source = _ffi.new('char[{0}]'.format(maxLength))
+    source = _ffi.new('char[]', maxLength)
     _glGetShaderSource(shader, maxLength, length, source)
     return _ffi.string(source)
 
 def glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data):
     ptr = _wrap_texture_data(type, data)
     _glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, ptr)
+
+def glTexSubImage1D(target, level, xoffset, width, format, type, data):
+    ptr = _wrap_texture_data(type, data)
+    _glTexSubImage1D(target, level, xoffset, width, format, type, ptr)
+
+def glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data):
+    ptr = _wrap_texture_data(type, data)
+    _glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, ptr)
+
+def glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data):
+    ptr = _wrap_texture_data(type, data)
+    _glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, ptr)
     
 def glReadPixels(x, y, width, height, format, type, data = None):
     if data is None:
-        data = _array(GL_TYPE_ID_TO_TYPE[type], (width*height))
+        data = _array(GL_TYPE_ID_TO_TYPE[type], (width*height*GL_FORMAT_TO_COUNT[format]))
     _glReadPixels(x,y,width,height,format,type,data)
     return data