@@ -29,21 +29,11 @@ module Graphics.Rendering.OpenGL.GL.Framebuffer (
29
29
ClearBuffer (.. ), clear ,
30
30
clearColor , clearIndex , clearDepth , clearDepthf , clearStencil , clearAccum ,
31
31
32
- -- clearBufferiv,
33
- -- clearBufferfv,
34
- -- clearBufferuiv,
35
- -- clearNamedFramebufferiv,
36
- -- clearNamedFramebufferfv,
37
- -- clearNamedFramebufferuiv,
38
-
39
- -- clearBufferfi,
40
- -- clearNamedFramebufferfi,
32
+ ClearBufferCommand (.. ), clearBuffer , clearNamedFramebuffer ,
41
33
42
34
-- * Invalidating Framebuffer Contents
43
- -- invalidateSubFramebuffer,
44
- -- invalidateNamedFramebufferSubData,
45
- -- invalidateFramebuffer,
46
- -- invalidateNamedFramebufferData,
35
+ invalidateSubFramebuffer , invalidateNamedFramebufferSubData ,
36
+ invalidateFramebuffer , invalidateNamedFramebufferData ,
47
37
48
38
-- * The Accumulation Buffer
49
39
AccumOp (.. ), accum ,
@@ -57,11 +47,15 @@ import Control.Monad
57
47
import Data.Maybe
58
48
import Data.StateVar
59
49
import Foreign.Marshal.Array
60
- import Foreign.Ptr -- REMOVE ME ----------------------------------------------------------------------------------------------------
50
+ import Foreign.Marshal.Utils
51
+ import Foreign.Ptr
61
52
import Graphics.Rendering.OpenGL.GL.BufferMode
62
53
import Graphics.Rendering.OpenGL.GL.Capability
54
+ import Graphics.Rendering.OpenGL.GL.CoordTrans
63
55
import Graphics.Rendering.OpenGL.GL.Face
64
56
import Graphics.Rendering.OpenGL.GL.FramebufferObjects.FramebufferObject
57
+ import Graphics.Rendering.OpenGL.GL.FramebufferObjects.FramebufferObjectAttachment
58
+ import Graphics.Rendering.OpenGL.GL.FramebufferObjects.FramebufferTarget
65
59
import Graphics.Rendering.OpenGL.GL.GLboolean
66
60
import Graphics.Rendering.OpenGL.GL.QueryUtils
67
61
import Graphics.Rendering.OpenGL.GL.VertexSpec
@@ -345,49 +339,94 @@ clearAccum =
345
339
makeStateVar (getFloat4 Color4 GetAccumClearValue )
346
340
(\ (Color4 r g b a) -> glClearAccum r g b a)
347
341
348
- -- buffer = COLOR => drawbuffer i (= DRAW_BUFFERi, DrawBufferIndex), pointer to 4 elems
349
- -- buffer = DEPTH => drawbuffer must be 0, only "f" version allowed, 1 elem
350
- -- buffer = STENCIL => drawbuffer must be 0, only "i" version allowed, 1 elem
351
-
352
- clearBufferiv :: GLenum -> GLint -> Ptr GLint -> IO ()
353
- clearBufferiv = glClearBufferiv
354
-
355
- clearBufferfv :: GLenum -> GLint -> Ptr GLfloat -> IO ()
356
- clearBufferfv = glClearBufferfv
357
-
358
- clearBufferuiv :: GLenum -> GLint -> Ptr GLuint -> IO ()
359
- clearBufferuiv = glClearBufferuiv
342
+ -- | Describes which buffer(s) to clear and the value to use.
343
+
344
+ data ClearBufferCommand
345
+ = ClearColorBufferInt DrawBufferIndex (Color4 GLint )
346
+ -- ^ Clear the signed integer color buffer(s) at the given index.
347
+ | ClearColorBufferFloat DrawBufferIndex (Color4 GLfloat )
348
+ -- ^ Clear the fixed- or floating-point color buffer(s) at the given index.
349
+ | ClearColorBufferUint DrawBufferIndex (Color4 GLuint )
350
+ -- ^ Clear the unsigned color buffer(s) at the given index.
351
+ | ClearDepthBuffer GLfloat
352
+ -- ^ Clear the depth buffer.
353
+ | ClearStencilBuffer GLint
354
+ -- ^ Clear the stencil buffer.
355
+ | ClearDepthAndStencilBuffers GLfloat GLint
356
+ -- ^ Clear the depth buffer and the stencil buffer.
357
+ deriving ( Eq , Ord , Show )
360
358
361
- clearNamedFramebufferiv :: GLuint -> GLenum -> GLint -> Ptr GLint -> IO ()
362
- clearNamedFramebufferiv = glClearNamedFramebufferiv
359
+ -- | Clear the given buffer(s).
360
+
361
+ clearBuffer :: ClearBufferCommand -> IO ()
362
+ clearBuffer cmd = case cmd of
363
+ ClearColorBufferInt i c ->
364
+ with c $ glClearBufferiv gl_COLOR (fromIntegral i) . castPtr
365
+ ClearColorBufferFloat i c ->
366
+ with c $ glClearBufferfv gl_COLOR (fromIntegral i) . castPtr
367
+ ClearColorBufferUint i c ->
368
+ with c $ glClearBufferuiv gl_COLOR (fromIntegral i) . castPtr
369
+ ClearDepthBuffer d ->
370
+ with d $ glClearBufferfv gl_DEPTH 0
371
+ ClearStencilBuffer s ->
372
+ with s $ glClearBufferiv gl_STENCIL 0
373
+ ClearDepthAndStencilBuffers d s ->
374
+ glClearBufferfi gl_DEPTH_STENCIL 0 d s
375
+
376
+ -- | The direct-state-access version of 'clearBuffer'.
377
+
378
+ clearNamedFramebuffer :: FramebufferObject -> ClearBufferCommand -> IO ()
379
+ clearNamedFramebuffer fbo cmd = case cmd of
380
+ ClearColorBufferInt i c ->
381
+ with c $ glClearNamedFramebufferiv f gl_COLOR (fromIntegral i) . castPtr
382
+ ClearColorBufferFloat i c ->
383
+ with c $ glClearNamedFramebufferfv f gl_COLOR (fromIntegral i) . castPtr
384
+ ClearColorBufferUint i c ->
385
+ with c $ glClearNamedFramebufferuiv f gl_COLOR (fromIntegral i) . castPtr
386
+ ClearDepthBuffer d ->
387
+ with d $ glClearNamedFramebufferfv f gl_DEPTH 0
388
+ ClearStencilBuffer s ->
389
+ with s $ glClearNamedFramebufferiv f gl_STENCIL 0
390
+ ClearDepthAndStencilBuffers d s ->
391
+ glClearNamedFramebufferfi f gl_DEPTH_STENCIL d s
392
+ where f = framebufferID fbo
363
393
364
- clearNamedFramebufferfv :: GLuint -> GLenum -> GLint -> Ptr GLfloat -> IO ()
365
- clearNamedFramebufferfv = glClearNamedFramebufferfv
394
+ --------------------------------------------------------------------------------
366
395
367
- clearNamedFramebufferuiv :: GLuint -> GLenum -> GLint -> Ptr GLuint -> IO ()
368
- clearNamedFramebufferuiv = glClearNamedFramebufferuiv
396
+ -- | Invalidate a region of the attachments bound to the given target.
369
397
370
- -- buffer must be DEPTH_STENCIL, drawbuffer must be 0, depth/stencil args
398
+ invalidateSubFramebuffer :: FramebufferTarget -> [FramebufferObjectAttachment ] -> (Position , Size ) -> IO ()
399
+ invalidateSubFramebuffer target attachments (Position x y, Size w h) =
400
+ withAttachments attachments $ \ numAttachments atts ->
401
+ glInvalidateSubFramebuffer (marshalFramebufferTarget target) numAttachments atts x y w h
371
402
372
- clearBufferfi :: GLenum -> GLint -> GLfloat -> GLint -> IO ()
373
- clearBufferfi = glClearBufferfi
403
+ -- | The direct-state-access version of 'invalidateSubFramebuffer'.
374
404
375
- clearNamedFramebufferfi :: GLuint -> GLenum -> GLfloat -> GLint -> IO ()
376
- clearNamedFramebufferfi = glClearNamedFramebufferfi
405
+ invalidateNamedFramebufferSubData :: FramebufferObject -> [FramebufferObjectAttachment ] -> (Position , Size ) -> IO ()
406
+ invalidateNamedFramebufferSubData fbo attachments (Position x y, Size w h) =
407
+ withAttachments attachments $ \ numAttachments atts ->
408
+ glInvalidateNamedFramebufferSubData (framebufferID fbo) numAttachments atts x y w h
377
409
378
- --------------------------------------------------------------------------------
410
+ -- | A version of 'invalidateSubFramebuffer' affecting the whole viewport.
379
411
380
- invalidateSubFramebuffer :: GLenum -> GLsizei -> Ptr GLenum -> GLint -> GLint -> GLsizei -> GLsizei -> IO ()
381
- invalidateSubFramebuffer = glInvalidateSubFramebuffer
412
+ invalidateFramebuffer :: FramebufferTarget -> [FramebufferObjectAttachment ] -> IO ()
413
+ invalidateFramebuffer target attachments =
414
+ withAttachments attachments $
415
+ glInvalidateFramebuffer (marshalFramebufferTarget target)
382
416
383
- invalidateNamedFramebufferSubData :: GLuint -> GLsizei -> Ptr GLenum -> GLint -> GLint -> GLsizei -> GLsizei -> IO ()
384
- invalidateNamedFramebufferSubData = glInvalidateNamedFramebufferSubData
417
+ -- | The direct-state-access version of 'invalidateFramebuffer'.
385
418
386
- invalidateFramebuffer :: GLenum -> GLsizei -> Ptr GLenum -> IO ()
387
- invalidateFramebuffer = glInvalidateFramebuffer
419
+ invalidateNamedFramebufferData :: FramebufferObject -> [FramebufferObjectAttachment ] -> IO ()
420
+ invalidateNamedFramebufferData fbo attachments =
421
+ withAttachments attachments $
422
+ glInvalidateNamedFramebufferData (framebufferID fbo)
388
423
389
- invalidateNamedFramebufferData :: GLuint -> GLsizei -> Ptr GLenum -> IO ()
390
- invalidateNamedFramebufferData = glInvalidateNamedFramebufferData
424
+ withAttachments :: [FramebufferObjectAttachment ] -> (GLsizei -> Ptr GLenum -> IO () ) -> IO ()
425
+ withAttachments attachments success
426
+ | all isJust atts = withArrayLen (catMaybes atts) $ \ len buf ->
427
+ success (fromIntegral len) buf
428
+ | otherwise = recordInvalidEnum
429
+ where atts = map marshalFramebufferObjectAttachment attachments
391
430
392
431
--------------------------------------------------------------------------------
393
432
0 commit comments