1
# ----------------------------------------------------------------------------
3
# Copyright (c) 2008 Daniel Moisset, Ricardo Quesada, Rayentray Tappa, Lucio Torre
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are met:
9
# * Redistributions of source code must retain the above copyright
10
# notice, this list of conditions and the following disclaimer.
11
# * Redistributions in binary form must reproduce the above copyright
12
# notice, this list of conditions and the following disclaimer in
13
# the documentation and/or other materials provided with the
15
# * Neither the name of cocos2d nor the names of its
16
# contributors may be used to endorse or promote products
17
# derived from this software without specific prior written
20
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
# POSSIBILITY OF SUCH DAMAGE.
32
# ----------------------------------------------------------------------------
33
"""A thin wrapper for OpenGL framebuffer objets. For implementation use only"""
35
__docformat__ = 'restructuredtext'
37
from pyglet.gl import *
39
class FramebufferObject (object):
41
Wrapper for framebuffer objects. See
43
http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt
45
API is not very OO, should be improved.
48
"""Create a new framebuffer object"""
50
glGenFramebuffersEXT (1, byref(id))
54
"""Set FBO as current rendering target"""
55
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, self._id)
58
"""Set default framebuffer as current rendering target"""
59
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0)
61
def texture2d (self, texture):
62
"""Map currently bound framebuffer (not necessarily self) to texture"""
63
glFramebufferTexture2DEXT (
65
GL_COLOR_ATTACHMENT0_EXT,
70
def check_status(self):
71
"""Check that currently set framebuffer is ready for rendering"""
72
status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT)
73
if status != GL_FRAMEBUFFER_COMPLETE_EXT:
74
raise Exception ("Frambuffer not complete: %d" % status)
77
'''Delete the framebuffer from the GPU memory'''
79
glDeleteFramebuffersEXT(1, byref(id))