Skip to content

Commit bdfaacd

Browse files
committed
Fixed indexed targets.
1 parent be9ffd2 commit bdfaacd

File tree

3 files changed

+72
-37
lines changed

3 files changed

+72
-37
lines changed

Graphics/Rendering/OpenGL/GL/BufferObjects.hs

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ mapBufferRange ::
361361
mapBufferRange t o l b =
362362
fmap (maybeNullPtr Nothing Just) $ mapBufferRange_ t o l b
363363

364-
flushMappedBufferRange :: BufferTarget -> Offset -> Length -> IO()
364+
flushMappedBufferRange :: BufferTarget -> Offset -> Length -> IO ()
365365
flushMappedBufferRange t = glFlushMappedBufferRange (marshalBufferTarget t)
366366

367367
--------------------------------------------------------------------------------
@@ -373,62 +373,71 @@ type RangeSize = GLsizeiptr
373373
type BufferRange = (BufferObject, RangeStartIndex, RangeSize)
374374

375375
data IndexedBufferTarget =
376-
IndexedTransformFeedbackBuffer
377-
--marshaling
376+
IndexedAtomicCounterBuffer
377+
| IndexedShaderStorageBuffer
378+
| IndexedTransformFeedbackBuffer
379+
| IndexedUniformBuffer
380+
deriving ( Eq, Ord, Show )
381+
378382
marshalIndexedBufferTarget :: IndexedBufferTarget -> IPName1I
379383
marshalIndexedBufferTarget x = case x of
384+
IndexedAtomicCounterBuffer -> GetAtomicCounterBuffer
385+
IndexedShaderStorageBuffer -> GetShaderStorageBuffer
380386
IndexedTransformFeedbackBuffer -> GetTransformFeedbackBuffer
387+
IndexedUniformBuffer -> GetUniformBuffer
381388

382-
marshalIndexedBufferStart :: IndexedBufferTarget -> IPName1I
383-
marshalIndexedBufferStart x = case x of
384-
IndexedTransformFeedbackBuffer -> GetTransformFeedbackBufferStart
385-
386-
marshalIndexedBufferSize :: IndexedBufferTarget -> IPName1I
387-
marshalIndexedBufferSize x = case x of
388-
IndexedTransformFeedbackBuffer -> GetTransformFeedbackBufferSize
389-
390-
getIndexed :: Num a => IPName1I -> BufferIndex -> GettableStateVar a
391-
getIndexed e i = makeGettableStateVar $ getInteger1i fromIntegral e i
392-
393-
--buffer
394389
bindBufferBase :: IndexedBufferTarget -> BufferIndex -> StateVar (Maybe BufferObject)
395390
bindBufferBase t i = makeStateVar (getIndexedBufferBinding t i) (setIndexedBufferBase t i)
396391

397-
setIndexedBufferBase :: IndexedBufferTarget -> BufferIndex -> Maybe BufferObject -> IO ()
398-
setIndexedBufferBase t i buf=
399-
case marshalGetPName . marshalIndexedBufferTarget $ t of
400-
Nothing -> recordInvalidEnum
401-
Just t' ->
402-
glBindBufferBase t' i . bufferID . fromMaybe noBufferObject $ buf
403-
404392
getIndexedBufferBinding :: IndexedBufferTarget -> BufferIndex -> IO (Maybe BufferObject)
405393
getIndexedBufferBinding t i = do
406394
buf <- getInteger1i (BufferObject . fromIntegral) (marshalIndexedBufferTarget t) i
407395
return $ if buf == noBufferObject then Nothing else Just buf
408396

397+
setIndexedBufferBase :: IndexedBufferTarget -> BufferIndex -> Maybe BufferObject -> IO ()
398+
setIndexedBufferBase t i buf =
399+
case marshalGetPName . marshalIndexedBufferTarget $ t of
400+
Nothing -> recordInvalidEnum
401+
Just t' -> glBindBufferBase t' i . bufferID . fromMaybe noBufferObject $ buf
402+
409403
bindBufferRange :: IndexedBufferTarget -> BufferIndex -> StateVar (Maybe BufferRange)
410404
bindBufferRange t i = makeStateVar (getIndexedBufferRange t i) (setIndexedBufferRange t i)
411405

406+
getIndexedBufferRange :: IndexedBufferTarget -> BufferIndex -> IO (Maybe BufferRange)
407+
getIndexedBufferRange t i = do
408+
buf <- getInteger1i (BufferObject . fromIntegral) (marshalIndexedBufferTarget t) i
409+
if buf == noBufferObject
410+
then return Nothing
411+
else do start <- get $ indexedBufferStart t i
412+
size <- get $ indexedBufferSize t i
413+
return $ Just (buf, start, size)
414+
412415
setIndexedBufferRange :: IndexedBufferTarget -> BufferIndex -> Maybe BufferRange -> IO ()
413-
setIndexedBufferRange t i (Just (buf, start, range)) =
416+
setIndexedBufferRange t i br =
414417
case marshalGetPName . marshalIndexedBufferTarget $ t of
415418
Nothing -> recordInvalidEnum
416419
Just t' -> glBindBufferRange t' i (bufferID buf) start range
417-
setIndexedBufferRange t i Nothing = setIndexedBufferBase t i Nothing
420+
where (buf, start, range) = fromMaybe (noBufferObject, 0, 0) br
418421

419-
getIndexedBufferRange :: IndexedBufferTarget -> BufferIndex -> IO(Maybe BufferRange)
420-
getIndexedBufferRange t i = do
421-
buf <- getInteger1i (BufferObject . fromIntegral) (marshalIndexedBufferTarget t) i
422-
if buf == noBufferObject
423-
then return Nothing
424-
else do
425-
start <- get $ indexedBufferStart t i
426-
size <- get $ indexedBufferSize t i
427-
return $ Just (buf, start, size)
422+
getIndexed :: Num a => IPName1I -> BufferIndex -> GettableStateVar a
423+
getIndexed e i = makeGettableStateVar $ getInteger641i fromIntegral e i
428424

425+
marshalIndexedBufferStart :: IndexedBufferTarget -> IPName1I
426+
marshalIndexedBufferStart x = case x of
427+
IndexedAtomicCounterBuffer -> GetAtomicCounterBufferStart
428+
IndexedShaderStorageBuffer -> GetShaderStorageBufferStart
429+
IndexedTransformFeedbackBuffer -> GetTransformFeedbackBufferStart
430+
IndexedUniformBuffer -> GetUniformBufferStart
429431

430432
indexedBufferStart :: IndexedBufferTarget -> BufferIndex -> GettableStateVar RangeStartIndex
431433
indexedBufferStart = getIndexed . marshalIndexedBufferStart
432434

435+
marshalIndexedBufferSize :: IndexedBufferTarget -> IPName1I
436+
marshalIndexedBufferSize x = case x of
437+
IndexedAtomicCounterBuffer -> GetAtomicCounterBufferSize
438+
IndexedShaderStorageBuffer -> GetShaderStorageBufferSize
439+
IndexedTransformFeedbackBuffer -> GetTransformFeedbackBufferSize
440+
IndexedUniformBuffer -> GetUniformBufferSize
441+
433442
indexedBufferSize :: IndexedBufferTarget -> BufferIndex -> GettableStateVar RangeSize
434443
indexedBufferSize = getIndexed . marshalIndexedBufferSize

Graphics/Rendering/OpenGL/GL/QueryUtils/PName.hs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ getBooleaniv p i = makeGetter (\e -> glGetBooleani_v e i) p
6969
getIntegeriv :: GetPName p => p -> GLuint -> Ptr GLint -> IO ()
7070
getIntegeriv p i = makeGetter (\e -> glGetIntegeri_v e i) p
7171

72+
getInteger64iv :: GetPName p => p -> GLuint -> Ptr GLint64 -> IO ()
73+
getInteger64iv p i = makeGetter (\e -> glGetInteger64i_v e i) p
74+
7275
-----------------------------------------------------------------------------
7376

7477
{-# INLINE makeGetter #-}
@@ -128,6 +131,9 @@ class GetPName p => GetIPName1I p where
128131
getSizei1i :: (GLsizei -> a) -> p -> GLuint -> IO a
129132
getSizei1i = get1i getIntegeriv
130133

134+
getInteger641i :: (GLint64 -> a) -> p -> GLuint -> IO a
135+
getInteger641i = get1i getInteger64iv
136+
131137
-- Indexed helper
132138
get1i :: (Storable b, Storable c, GetPName p)
133139
=> (p -> GLuint -> Ptr c -> IO ())
@@ -948,18 +954,36 @@ instance GetPName PName1F where
948954

949955
-----------------------------------------------------------------------------
950956

951-
data IPName1I
952-
= GetTransformFeedbackBuffer
957+
data IPName1I =
958+
GetAtomicCounterBuffer
959+
| GetAtomicCounterBufferStart
960+
| GetAtomicCounterBufferSize
961+
| GetShaderStorageBuffer
962+
| GetShaderStorageBufferStart
963+
| GetShaderStorageBufferSize
964+
| GetTransformFeedbackBuffer
953965
| GetTransformFeedbackBufferStart
954966
| GetTransformFeedbackBufferSize
967+
| GetUniformBuffer
968+
| GetUniformBufferStart
969+
| GetUniformBufferSize
955970

956971
instance GetIPName1I IPName1I where
957972

958973
instance GetPName IPName1I where
959974
marshalGetPName pn = case pn of
975+
GetAtomicCounterBuffer -> Just gl_ATOMIC_COUNTER_BUFFER
976+
GetAtomicCounterBufferStart -> Just gl_ATOMIC_COUNTER_BUFFER_START
977+
GetAtomicCounterBufferSize -> Just gl_ATOMIC_COUNTER_BUFFER_SIZE
978+
GetShaderStorageBuffer -> Just gl_SHADER_STORAGE_BUFFER
979+
GetShaderStorageBufferStart -> Just gl_SHADER_STORAGE_BUFFER_START
980+
GetShaderStorageBufferSize -> Just gl_SHADER_STORAGE_BUFFER_SIZE
960981
GetTransformFeedbackBuffer -> Just gl_TRANSFORM_FEEDBACK_BUFFER
961-
GetTransformFeedbackBufferSize -> Just gl_TRANSFORM_FEEDBACK_BUFFER_SIZE
962982
GetTransformFeedbackBufferStart -> Just gl_TRANSFORM_FEEDBACK_BUFFER_START
983+
GetTransformFeedbackBufferSize -> Just gl_TRANSFORM_FEEDBACK_BUFFER_SIZE
984+
GetUniformBuffer -> Just gl_UNIFORM_BUFFER
985+
GetUniformBufferStart -> Just gl_UNIFORM_BUFFER_START
986+
GetUniformBufferSize -> Just gl_UNIFORM_BUFFER_SIZE
963987

964988
-----------------------------------------------------------------------------
965989

@@ -1058,6 +1082,7 @@ data PName4ISemiIndexed
10581082
= GetColorWritemask -- ^ bool
10591083

10601084
instance GetPName4I PName4ISemiIndexed where
1085+
10611086
instance GetIPName4I PName4ISemiIndexed where
10621087

10631088
instance GetPName PName4ISemiIndexed where
@@ -1129,6 +1154,7 @@ data PNameNI
11291154
| GetProgramBinaryFormats
11301155

11311156
instance GetPNameNI PNameNI where
1157+
11321158
instance GetPName PNameNI where
11331159
marshalGetPName pn = case pn of
11341160
GetCompressedTextureFormats -> Just gl_COMPRESSED_TEXTURE_FORMATS

OpenGL.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ library
143143
Graphics.Rendering.OpenGL.GLU.ErrorsInternal
144144
ghc-options: -Wall -O2
145145
build-depends:
146-
base >= 3 && < 5, bytestring, text, OpenGLRaw >= 1.4.0.0, GLURaw >= 1.3.0.0
146+
base >= 3 && < 5, bytestring, text, OpenGLRaw >= 1.4.1.0, GLURaw >= 1.3.0.0
147147

148148
source-repository head
149149
type: git

0 commit comments

Comments
 (0)