1 ! Copyright (C) 2008 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: opengl opengl.gl combinators continuations kernel
5 IN: opengl.framebuffers
7 : gen-framebuffer ( -- id )
8 [ glGenFramebuffersEXT ] (gen-gl-object) ;
9 : gen-renderbuffer ( -- id )
10 [ glGenRenderbuffersEXT ] (gen-gl-object) ;
12 : delete-framebuffer ( id -- )
13 [ glDeleteFramebuffersEXT ] (delete-gl-object) ;
14 : delete-renderbuffer ( id -- )
15 [ glDeleteRenderbuffersEXT ] (delete-gl-object) ;
17 : framebuffer-incomplete? ( -- status/f )
18 GL_FRAMEBUFFER_EXT glCheckFramebufferStatusEXT
19 dup GL_FRAMEBUFFER_COMPLETE_EXT = f rot ? ;
21 : framebuffer-error ( status -- * )
23 { GL_FRAMEBUFFER_COMPLETE_EXT [ "framebuffer complete" ] }
24 { GL_FRAMEBUFFER_UNSUPPORTED_EXT [ "framebuffer configuration unsupported" ] }
25 { GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT [ "framebuffer incomplete (incomplete attachment)" ] }
26 { GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT [ "framebuffer incomplete (missing attachment)" ] }
27 { GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT [ "framebuffer incomplete (dimension mismatch)" ] }
28 { GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT [ "framebuffer incomplete (format mismatch)" ] }
29 { GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT [ "framebuffer incomplete (draw buffer(s) have no attachment)" ] }
30 { GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT [ "framebuffer incomplete (read buffer has no attachment)" ] }
31 [ drop gl-error "unknown framebuffer error" ]
34 : check-framebuffer ( -- )
35 framebuffer-incomplete? [ framebuffer-error ] when* ;
37 : with-framebuffer ( id quot -- )
38 GL_FRAMEBUFFER_EXT rot glBindFramebufferEXT
39 [ GL_FRAMEBUFFER_EXT 0 glBindFramebufferEXT ] [ ] cleanup ; inline
41 : framebuffer-attachment ( attachment -- id )
42 GL_FRAMEBUFFER_EXT swap GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
43 0 <uint> [ glGetFramebufferAttachmentParameterivEXT ] keep *uint ;