@@ -89,6 +89,7 @@ def bind(self, stack=True):
8989 push_fbo (self )
9090 if len (self .color_buffers ) > 1 :
9191 GL .glDrawBuffers (len (self .color_buffers ), self .color_buffers_ids )
92+
9293 w , h = self .size
9394 GL .glViewport (0 , 0 , w , h )
9495
@@ -116,7 +117,7 @@ def clear(self):
116117
117118 @classmethod
118119 def create (cls , width , height , depth = False ,
119- internal_format = GL .GL_RGBA8 , format = GL .GL_RGBA , type = GL .GL_UNSIGNED_BYTE ):
120+ internal_format = GL .GL_RGBA8 , format = GL .GL_RGBA , type = GL .GL_UNSIGNED_BYTE , layers = 1 ):
120121 """
121122 Convenient shortcut for creating single color attachment FBOs
122123
@@ -130,14 +131,20 @@ def create(cls, width, height, depth=False,
130131 """
131132 fbo = FBO ()
132133 fbo .bind (stack = False )
133- c = Texture .create_2d (width = width , height = height , internal_format = internal_format , format = format , type = type ,
134- wrap_s = GL .GL_CLAMP_TO_EDGE , wrap_t = GL .GL_CLAMP_TO_EDGE , wrap_r = GL .GL_CLAMP_TO_EDGE )
135- fbo .add_color_attachment (c )
134+
135+ # Add N layers of color attachments
136+ for layer in range (layers ):
137+ c = Texture .create_2d (width = width , height = height , internal_format = internal_format , format = format , type = type ,
138+ wrap_s = GL .GL_CLAMP_TO_EDGE , wrap_t = GL .GL_CLAMP_TO_EDGE , wrap_r = GL .GL_CLAMP_TO_EDGE )
139+ fbo .add_color_attachment (c )
140+
141+ # Set depth attachment is specified
136142 if depth :
137143 d = Texture .create_2d (width = width , height = height ,
138144 internal_format = GL .GL_DEPTH24_STENCIL8 , format = GL .GL_DEPTH_COMPONENT ,
139145 wrap_s = GL .GL_CLAMP_TO_EDGE , wrap_t = GL .GL_CLAMP_TO_EDGE , wrap_r = GL .GL_CLAMP_TO_EDGE )
140146 fbo .set_depth_attachment (d )
147+
141148 fbo .check_status ()
142149 fbo .release (stack = False )
143150 return fbo
@@ -151,6 +158,7 @@ def add_color_attachment(self, texture):
151158 # Internal states
152159 self .color_buffers_ids .append (GL .GL_COLOR_ATTACHMENT0 + len (self .color_buffers ))
153160 self .color_buffers .append (texture )
161+
154162 # Attach to fbo
155163 GL .glFramebufferTexture2D (
156164 GL .GL_FRAMEBUFFER ,
0 commit comments