Skip to content

Commit 4f9bc7d

Browse files
committed
Partial support for multisample textures.
1 parent a5025d4 commit 4f9bc7d

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ data PName1I
511511
| GetMaxCubeMapTextureSize -- ^ int
512512
| GetMaxRectangleTextureSize -- ^ int
513513
| GetMaxArrayTextureLayers -- ^ int
514+
| GetMaxSampleMaskWords -- ^ int
515+
| GetMaxColorTextureSamples -- ^ int
516+
| GetMaxDepthTextureSamples -- ^ int
517+
| GetMaxIntegerSamples -- ^ int
514518
-- ReadCopyPixels
515519
| GetReadBuffer -- ^ enum
516520
-- Texture Objects
@@ -767,6 +771,10 @@ instance GetPName PName1I where
767771
GetMaxCubeMapTextureSize -> Just gl_MAX_CUBE_MAP_TEXTURE_SIZE
768772
GetMaxRectangleTextureSize -> Just gl_MAX_RECTANGLE_TEXTURE_SIZE
769773
GetMaxArrayTextureLayers -> Just gl_MAX_ARRAY_TEXTURE_LAYERS
774+
GetMaxSampleMaskWords -> Just gl_MAX_SAMPLE_MASK_WORDS
775+
GetMaxColorTextureSamples -> Just gl_MAX_COLOR_TEXTURE_SAMPLES
776+
GetMaxDepthTextureSamples -> Just gl_MAX_DEPTH_TEXTURE_SAMPLES
777+
GetMaxIntegerSamples -> Just gl_MAX_INTEGER_SAMPLES
770778
-- ReadCopyPixels
771779
GetReadBuffer -> Just gl_READ_BUFFER
772780
-- Texture Objects

Graphics/Rendering/OpenGL/GL/Texturing/Specification.hs

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ module Graphics.Rendering.OpenGL.GL.Texturing.Specification (
6363
compressedTexSubImage1D, compressedTexSubImage2D, compressedTexSubImage3D,
6464
getCompressedTexImage,
6565

66-
-- * Implementation-Dependent Limits
67-
maxTextureSize, maxCubeMapTextureSize, maxRectangleTextureSize,
68-
max3DTextureSize, maxArrayTextureLayers
66+
-- * Multisample Texture Images
67+
SampleLocations(..), texImage2DMultisample, texImage3DMultisample,
68+
69+
-- * Implementation-Dependent Limits
70+
maxTextureSize, maxCubeMapTextureSize, maxRectangleTextureSize,
71+
max3DTextureSize, maxArrayTextureLayers, maxSampleMaskWords,
72+
maxColorTextureSamples, maxDepthTextureSamples, maxIntegerSamples
6973
) where
7074

7175
import Foreign.Ptr
7276
import Graphics.Rendering.OpenGL.GL.CoordTrans
77+
import Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferTarget
78+
import Graphics.Rendering.OpenGL.GL.GLboolean
7379
import Graphics.Rendering.OpenGL.GL.PixelData
7480
import Graphics.Rendering.OpenGL.GL.PixelRectangles
7581
import Graphics.Rendering.OpenGL.GL.QueryUtils
@@ -339,6 +345,54 @@ compressedTexSubImage3D target level (TexturePosition3D xOff yOff zOff) (Texture
339345

340346
--------------------------------------------------------------------------------
341347

348+
data SampleLocations =
349+
FlexibleSampleLocations
350+
| FixedSampleLocations
351+
deriving ( Eq, Ord, Show )
352+
353+
marshalSampleLocations :: SampleLocations -> GLboolean
354+
marshalSampleLocations = marshalGLboolean . (FixedSampleLocations ==)
355+
356+
{-
357+
unmarshalSampleLocations :: GLboolean -> SampleLocations
358+
unmarshalSampleLocations x =
359+
if unmarshalGLboolean x
360+
then FixedSampleLocations
361+
else FlexibleSampleLocations
362+
-}
363+
364+
--------------------------------------------------------------------------------
365+
366+
texImage2DMultisample :: TextureTarget2DMultisample
367+
-> Proxy
368+
-> Samples
369+
-> PixelInternalFormat
370+
-> TextureSize2D
371+
-> SampleLocations
372+
-> IO ()
373+
texImage2DMultisample target proxy (Samples s) int (TextureSize2D w h) loc =
374+
glTexImage2DMultisample
375+
(marshalMultisample proxy target) s (marshalPixelInternalFormat int)
376+
w h (marshalSampleLocations loc)
377+
378+
marshalMultisample :: ParameterizedTextureTarget t => Proxy -> t -> GLenum
379+
marshalMultisample proxy = case proxy of
380+
NoProxy -> marshalParameterizedTextureTarget
381+
Proxy -> marshalParameterizedTextureTargetProxy
382+
383+
texImage3DMultisample :: TextureTarget2DMultisampleArray
384+
-> Proxy
385+
-> Samples
386+
-> PixelInternalFormat
387+
-> TextureSize3D
388+
-> SampleLocations
389+
-> IO ()
390+
texImage3DMultisample target proxy (Samples s) int (TextureSize3D w h d) loc =
391+
glTexImage3DMultisample
392+
(marshalMultisample proxy target) s (marshalPixelInternalFormat int)
393+
w h d (marshalSampleLocations loc)
394+
395+
--------------------------------------------------------------------------------
342396
maxTextureSize :: GettableStateVar GLsizei
343397
maxTextureSize = maxTextureSizeWith GetMaxTextureSize
344398

@@ -354,5 +408,17 @@ max3DTextureSize = maxTextureSizeWith GetMax3DTextureSize
354408
maxArrayTextureLayers :: GettableStateVar GLsizei
355409
maxArrayTextureLayers = maxTextureSizeWith GetMaxArrayTextureLayers
356410

411+
maxSampleMaskWords :: GettableStateVar GLsizei
412+
maxSampleMaskWords = maxTextureSizeWith GetMaxSampleMaskWords
413+
414+
maxColorTextureSamples :: GettableStateVar GLsizei
415+
maxColorTextureSamples = maxTextureSizeWith GetMaxColorTextureSamples
416+
417+
maxDepthTextureSamples :: GettableStateVar GLsizei
418+
maxDepthTextureSamples = maxTextureSizeWith GetMaxDepthTextureSamples
419+
420+
maxIntegerSamples :: GettableStateVar GLsizei
421+
maxIntegerSamples = maxTextureSizeWith GetMaxIntegerSamples
422+
357423
maxTextureSizeWith :: PName1I -> GettableStateVar GLsizei
358424
maxTextureSizeWith = makeGettableStateVar . getInteger1 fromIntegral

0 commit comments

Comments
 (0)