diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2018-09-20 22:39:02 +0300 |
---|---|---|
committer | Kosyrev Serge <_deepfire@feelingofgreen.ru> | 2018-09-20 23:03:28 +0300 |
commit | 83c56918279a1fa795cc4c8c53af1f6c8c147029 (patch) | |
tree | 8440e6c620c518dd3180164e30db7ea60a0c5695 /examples | |
parent | 5d0c09aeddd4856758480d48dc33f5eac2ac673e (diff) |
pickInt: glReadBuffer/glReadPixels framebuffer format specificity
Diffstat (limited to 'examples')
-rw-r--r-- | examples/pickInt.hs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/examples/pickInt.hs b/examples/pickInt.hs index 5a499d4..36bc36c 100644 --- a/examples/pickInt.hs +++ b/examples/pickInt.hs | |||
@@ -152,20 +152,24 @@ pickFrameBuffer | |||
152 | pickFrameBuffer fb (w, h) (x, y) = do | 152 | pickFrameBuffer fb (w, h) (x, y) = do |
153 | glFinish | 153 | glFinish |
154 | glBindFramebuffer GL_READ_FRAMEBUFFER $ fromIntegral fb | 154 | glBindFramebuffer GL_READ_FRAMEBUFFER $ fromIntegral fb |
155 | glReadBuffer GL_BACK_LEFT | 155 | let (fbmode, format) = |
156 | withFrameBuffer x (h - y - 1) 1 1 $ \p -> fromIntegral <$> F.peek (F.castPtr p :: F.Ptr F.Word32) | 156 | if fb == 0 |
157 | 157 | then (GL_BACK_LEFT, GL_RGBA) | |
158 | withFrameBuffer :: Int -> Int -> Int -> Int -> (F.Ptr F.Word8 -> IO a) -> IO a | 158 | else (GL_COLOR_ATTACHMENT0, GL_RGBA_INTEGER) |
159 | withFrameBuffer x y w h fn = F.allocaBytes (w*h*4) $ \p -> do | 159 | glReadBuffer fbmode |
160 | withFrameBuffer w format x (h - y - 1) 1 1 $ \p -> fromIntegral <$> F.peek (F.castPtr p :: F.Ptr F.Word32) | ||
161 | |||
162 | withFrameBuffer :: Int -> GLenum -> Int -> Int -> Int -> Int -> (F.Ptr F.Word8 -> IO a) -> IO a | ||
163 | withFrameBuffer rowLen format x y w h fn = F.allocaBytes (w*h*4) $ \p -> do | ||
160 | glPixelStorei GL_UNPACK_LSB_FIRST 0 | 164 | glPixelStorei GL_UNPACK_LSB_FIRST 0 |
161 | glPixelStorei GL_UNPACK_SWAP_BYTES 0 | 165 | glPixelStorei GL_UNPACK_SWAP_BYTES 0 |
162 | glPixelStorei GL_UNPACK_ROW_LENGTH $ fromIntegral w | 166 | glPixelStorei GL_UNPACK_ROW_LENGTH $ fromIntegral rowLen |
163 | glPixelStorei GL_UNPACK_IMAGE_HEIGHT 0 | 167 | glPixelStorei GL_UNPACK_IMAGE_HEIGHT 0 |
164 | glPixelStorei GL_UNPACK_SKIP_ROWS 0 | 168 | glPixelStorei GL_UNPACK_SKIP_ROWS 0 |
165 | glPixelStorei GL_UNPACK_SKIP_PIXELS 0 | 169 | glPixelStorei GL_UNPACK_SKIP_PIXELS 0 |
166 | glPixelStorei GL_UNPACK_SKIP_IMAGES 0 | 170 | glPixelStorei GL_UNPACK_SKIP_IMAGES 0 |
167 | glPixelStorei GL_UNPACK_ALIGNMENT 1 | 171 | glPixelStorei GL_UNPACK_ALIGNMENT 1 |
168 | glReadPixels (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) GL_RGBA GL_UNSIGNED_BYTE $ F.castPtr p | 172 | glReadPixels (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) format GL_UNSIGNED_BYTE $ F.castPtr p |
169 | glPixelStorei GL_UNPACK_ROW_LENGTH 0 | 173 | glPixelStorei GL_UNPACK_ROW_LENGTH 0 |
170 | fn p | 174 | fn p |
171 | 175 | ||