Merge branch 'master' of github.com:tito/kivy into stylefixes

This commit is contained in:
Christopher Denter 2011-01-13 13:44:15 +01:00
commit 3fd96a6850
5 changed files with 31 additions and 9 deletions

View File

@ -4,6 +4,7 @@ cdef class BindTexture
from transformation cimport Matrix
from instructions cimport ContextInstruction
from texture cimport Texture
cdef class LineWidth(ContextInstruction):
cdef apply(self)
@ -13,7 +14,7 @@ cdef class Color(ContextInstruction):
cdef class BindTexture(ContextInstruction):
cdef str _source
cdef object _texture
cdef Texture _texture
cdef apply(self)

View File

@ -113,12 +113,12 @@ cdef class BindTexture(ContextInstruction):
'texture property')
self.source = kwargs.get('source', None)
if self.source == None:
if self.source is None:
self.texture = kwargs.get('texture', None)
cdef apply(self):
glActiveTexture(GL_TEXTURE0)
glBindTexture(self._texture.target, self._texture.id)
glBindTexture(self._texture.target, self._texture._id)
property texture:
def __get__(self):

View File

@ -15,9 +15,9 @@ cdef class Fbo(RenderContext):
cdef int _is_bound
cpdef clear_buffer(self)
cpdef bind(self)
cpdef release(self)
cdef bind(self)
cdef release(self)
cdef create_fbo(self)
cdef delete_fbo(self)
cdef apply(self)

View File

@ -140,10 +140,12 @@ cdef class Fbo(RenderContext):
cdef create_fbo(self):
cdef GLuint f_id
cdef int status
cdef int do_clear = 0
# create texture
if self._texture is None:
self._texture = Texture.create(size=(self._width, self._height))
do_clear = 1
# create framebuffer
glGenFramebuffers(1, &f_id)
@ -171,7 +173,8 @@ cdef class Fbo(RenderContext):
raise FboException('FBO Initialization failed', status)
# clear the fbo
self.clear_buffer()
if do_clear:
self.clear_buffer()
# unbind the framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0)
@ -180,7 +183,7 @@ cdef class Fbo(RenderContext):
projection_mat.view_clip(0.0, self._width, 0.0, self._height, -1.0, 1.0, 0)
self.set_state('projection_mat', projection_mat)
cdef bind(self):
cpdef bind(self):
if self._is_bound:
raise FboException('FBO is already binded.')
else:
@ -195,7 +198,7 @@ cdef class Fbo(RenderContext):
glGetIntegerv(GL_VIEWPORT, <GLint *>&self._viewport)
glViewport(0, 0, self._width, self._height)
cdef release(self):
cpdef release(self):
if self._is_bound == 0:
raise FboException('Cannot release a FBO not binded.')
else:

View File

@ -94,6 +94,23 @@ cdef inline int _buffer_type_to_gl_format(str x):
except KeyError:
raise Exception('Unknown <%s> format' % x)
cdef dict _gl_buffer_size = {
'ubyte': sizeof(GLubyte),
'ushort': sizeof(GLushort),
'uint': sizeof(GLuint),
'byte': sizeof(GLbyte),
'short': sizeof(GLshort),
'int': sizeof(GLint),
'float': sizeof(GLfloat)
}
cdef inline int _buffer_type_to_gl_size(str x):
x = x.lower()
try:
return _gl_buffer_size[x]
except KeyError:
raise Exception('Unknown <%s> format' % x)
cdef inline int _gl_format_size(GLuint x):
if x in (GL_RGB, GL_BGR):
return 3
@ -220,7 +237,8 @@ cdef _texture_create(int width, int height, str fmt, str buffertype, int
# ok, allocate memory for initial texture
cdef int glfmt = _fmt_to_gl_format(fmt)
cdef int datasize = sizeof(GLubyte) * texture_width * texture_height * _gl_format_size(glfmt)
cdef int datasize = texture_width * texture_height * \
_gl_format_size(glfmt) * _buffer_type_to_gl_size(buffertype)
cdef void *data = NULL
cdef int dataerr = 0