Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tessellation functionality #74

Merged
merged 5 commits into from
Feb 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion OpenGL.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ library
Graphics.Rendering.OpenGL.GL.PixellikeObject
Graphics.Rendering.OpenGL.GL.Points
Graphics.Rendering.OpenGL.GL.Polygons
Graphics.Rendering.OpenGL.GL.PrimitiveMode
Graphics.Rendering.OpenGL.GL.QueryObjects
Graphics.Rendering.OpenGL.GL.RasterPos
Graphics.Rendering.OpenGL.GL.ReadCopyPixels
Expand Down Expand Up @@ -126,7 +127,7 @@ library
Graphics.Rendering.OpenGL.GL.PixelRectangles.Sink
Graphics.Rendering.OpenGL.GL.PointParameter
Graphics.Rendering.OpenGL.GL.PolygonMode
Graphics.Rendering.OpenGL.GL.PrimitiveMode
Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal
Graphics.Rendering.OpenGL.GL.QueryObject
Graphics.Rendering.OpenGL.GL.QueryUtils
Graphics.Rendering.OpenGL.GL.QueryUtils.PName
Expand Down
2 changes: 2 additions & 0 deletions src/Graphics/Rendering/OpenGL/GL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Graphics.Rendering.OpenGL.GL (
module Graphics.Rendering.OpenGL.GL.QueryObjects,

-- * Vertex Specification and Drawing Commands
module Graphics.Rendering.OpenGL.GL.PrimitiveMode,
module Graphics.Rendering.OpenGL.GL.BeginEnd,
module Graphics.Rendering.OpenGL.GL.Rectangles,
module Graphics.Rendering.OpenGL.GL.ConditionalRendering,
Expand Down Expand Up @@ -79,6 +80,7 @@ import Graphics.Rendering.OpenGL.GL.ObjectName
import Graphics.Rendering.OpenGL.GL.SyncObjects
import Graphics.Rendering.OpenGL.GL.QueryObjects

import Graphics.Rendering.OpenGL.GL.PrimitiveMode
import Graphics.Rendering.OpenGL.GL.BeginEnd
import Graphics.Rendering.OpenGL.GL.Rectangles
import Graphics.Rendering.OpenGL.GL.ConditionalRendering
Expand Down
4 changes: 2 additions & 2 deletions src/Graphics/Rendering/OpenGL/GL/BeginEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module : Graphics.Rendering.OpenGL.GL.BeginEnd
-- Copyright : (c) Sven Panne 2002-2013
-- License : BSD3
--
--
-- Maintainer : Sven Panne <[email protected]>
-- Stability : stable
-- Portability : portable
Expand All @@ -15,7 +15,6 @@

module Graphics.Rendering.OpenGL.GL.BeginEnd (
-- * Begin and End Objects
PrimitiveMode(..),
renderPrimitive, unsafeRenderPrimitive, primitiveRestart,

-- * Polygon Edges
Expand All @@ -27,6 +26,7 @@ import Graphics.Rendering.OpenGL.GL.StateVar
import Graphics.Rendering.OpenGL.GL.EdgeFlag
import Graphics.Rendering.OpenGL.GL.Exception
import Graphics.Rendering.OpenGL.GL.PrimitiveMode
import Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.Rendering.OpenGL.Raw

Expand Down
55 changes: 25 additions & 30 deletions src/Graphics/Rendering/OpenGL/GL/PrimitiveMode.hs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
{-# OPTIONS_HADDOCK hide #-}
--------------------------------------------------------------------------------
-- |
-- Module : Graphics.Rendering.OpenGL.GL.PrimitiveMode
-- Copyright : (c) Sven Panne 2002-2013
-- Copyright : (c) Sven Panne 2002-2013, Tobias Markus 2015
-- License : BSD3
--
--
-- Maintainer : Sven Panne <[email protected]>
-- Stability : stable
-- Portability : portable
--
-- This is a purely internal module for (un-)marshaling PrimitiveMode.
-- This module corresponds to section 10.1 (Primitive Types) of the OpenGL 4.4
-- specs.
--
--------------------------------------------------------------------------------

module Graphics.Rendering.OpenGL.GL.PrimitiveMode (
PrimitiveMode(..), marshalPrimitiveMode, unmarshalPrimitiveMode
-- * Primitive Modes
PrimitiveMode(..),
-- * Patches (Tessellation)
patchVertices, maxPatchVertices
) where

import Graphics.Rendering.OpenGL.GL.StateVar
import Graphics.Rendering.OpenGL.GL.QueryUtils.PName
import Graphics.Rendering.OpenGL.Raw

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -66,31 +71,21 @@ data PrimitiveMode =
| Polygon
-- ^ Draws a single, convex polygon. Vertices 1 through /N/ define this
-- polygon.
| Patches
-- ^ Only used in conjunction with tessellation. The number of vertices per
-- patch can be set with 'patchVertices'.
deriving ( Eq, Ord, Show )

marshalPrimitiveMode :: PrimitiveMode -> GLenum
marshalPrimitiveMode x = case x of
Points -> gl_POINTS
Lines -> gl_LINES
LineLoop -> gl_LINE_LOOP
LineStrip -> gl_LINE_STRIP
Triangles -> gl_TRIANGLES
TriangleStrip -> gl_TRIANGLE_STRIP
TriangleFan -> gl_TRIANGLE_FAN
Quads -> gl_QUADS
QuadStrip -> gl_QUAD_STRIP
Polygon -> gl_POLYGON
-- | 'patchVertices' is the number of vertices per patch primitive.
--
-- An 'Graphics.Rendering.OpenGL.GLU.Errors.InvalidValue' is generated if
-- 'patchVertices' is set to a value less than or equal to zero or greater
-- than the implementation-dependent maximum value 'maxPatchVertices'.

patchVertices :: SettableStateVar GLint
patchVertices = makeSettableStateVar $ glPatchParameteri gl_PATCH_VERTICES

-- | Contains the maximumum number of vertices in a single patch.

unmarshalPrimitiveMode :: GLenum -> PrimitiveMode
unmarshalPrimitiveMode x
| x == gl_POINTS = Points
| x == gl_LINES = Lines
| x == gl_LINE_LOOP = LineLoop
| x == gl_LINE_STRIP = LineStrip
| x == gl_TRIANGLES = Triangles
| x == gl_TRIANGLE_STRIP = TriangleStrip
| x == gl_TRIANGLE_FAN = TriangleFan
| x == gl_QUADS = Quads
| x == gl_QUAD_STRIP = QuadStrip
| x == gl_POLYGON = Polygon
| otherwise = error ("unmarshalPrimitiveMode: illegal value " ++ show x)
maxPatchVertices :: GettableStateVar GLint
maxPatchVertices = makeGettableStateVar $ getInteger1 id GetMaxPatchVertices
52 changes: 52 additions & 0 deletions src/Graphics/Rendering/OpenGL/GL/PrimitiveModeInternal.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{-# OPTIONS_HADDOCK hide #-}
--------------------------------------------------------------------------------
-- |
-- Module : Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal
-- Copyright : (c) Sven Panne 2002-2013
-- License : BSD3
--
-- Maintainer : Sven Panne <[email protected]>
-- Stability : stable
-- Portability : portable
--
-- This is a purely internal module for (un-)marshaling PrimitiveMode.
--
--------------------------------------------------------------------------------

module Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal (
marshalPrimitiveMode, unmarshalPrimitiveMode
) where

import Graphics.Rendering.OpenGL.Raw
import Graphics.Rendering.OpenGL.GL.PrimitiveMode

--------------------------------------------------------------------------------

marshalPrimitiveMode :: PrimitiveMode -> GLenum
marshalPrimitiveMode x = case x of
Points -> gl_POINTS
Lines -> gl_LINES
LineLoop -> gl_LINE_LOOP
LineStrip -> gl_LINE_STRIP
Triangles -> gl_TRIANGLES
TriangleStrip -> gl_TRIANGLE_STRIP
TriangleFan -> gl_TRIANGLE_FAN
Quads -> gl_QUADS
QuadStrip -> gl_QUAD_STRIP
Polygon -> gl_POLYGON
Patches -> gl_PATCHES

unmarshalPrimitiveMode :: GLenum -> PrimitiveMode
unmarshalPrimitiveMode x
| x == gl_POINTS = Points
| x == gl_LINES = Lines
| x == gl_LINE_LOOP = LineLoop
| x == gl_LINE_STRIP = LineStrip
| x == gl_TRIANGLES = Triangles
| x == gl_TRIANGLE_STRIP = TriangleStrip
| x == gl_TRIANGLE_FAN = TriangleFan
| x == gl_QUADS = Quads
| x == gl_QUAD_STRIP = QuadStrip
| x == gl_POLYGON = Polygon
| x == gl_PATCHES = Patches
| otherwise = error ("unmarshalPrimitiveMode: illegal value " ++ show x)
6 changes: 6 additions & 0 deletions src/Graphics/Rendering/OpenGL/GL/QueryUtils/PName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ data PName1I
| GetMaxFragmentUniformComponents -- ^ sizei
| GetMaxVertexAttribs -- ^ sizei
| GetMaxVaryingFloats -- ^ sizei
-- tessellation
| GetMaxPatchVertices -- ^ int
| GetMaxTessellationLevel -- ^ int
-- coordtrans
| GetMatrixMode -- ^ enum
| GetModelviewStackDepth -- ^ sizei
Expand Down Expand Up @@ -625,6 +628,9 @@ instance GetPName PName1I where
GetMaxFragmentUniformComponents -> Just gl_MAX_FRAGMENT_UNIFORM_COMPONENTS
GetMaxVaryingFloats -> Just gl_MAX_VARYING_COMPONENTS
GetMaxVertexAttribs -> Just gl_MAX_VERTEX_ATTRIBS
-- tessellation
GetMaxPatchVertices -> Just gl_MAX_PATCH_VERTICES
GetMaxTessellationLevel -> Just gl_MAX_TESS_GEN_LEVEL
-- coordtrans
GetMatrixMode -> Just gl_MATRIX_MODE
GetModelviewStackDepth -> Just gl_MODELVIEW_STACK_DEPTH
Expand Down
8 changes: 7 additions & 1 deletion src/Graphics/Rendering/OpenGL/GL/Shaders/Limits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
module Graphics.Rendering.OpenGL.GL.Shaders.Limits (
maxVertexTextureImageUnits, maxTextureImageUnits,
maxCombinedTextureImageUnits, maxTextureCoords, maxVertexUniformComponents,
maxFragmentUniformComponents, maxVertexAttribs, maxVaryingFloats
maxFragmentUniformComponents, maxVertexAttribs, maxVaryingFloats,
maxTessellationLevel
) where

import Graphics.Rendering.OpenGL.GL.StateVar
Expand Down Expand Up @@ -76,5 +77,10 @@ maxVertexAttribs = getLimit GetMaxVertexAttribs
maxVaryingFloats :: GettableStateVar GLsizei
maxVaryingFloats = getLimit GetMaxVaryingFloats

-- | Contains the maximum allowed tessellation level.

maxTessellationLevel :: GettableStateVar GLint
maxTessellationLevel = makeGettableStateVar $ getInteger1 id GetMaxTessellationLevel

getLimit :: PName1I -> GettableStateVar GLsizei
getLimit = makeGettableStateVar . getSizei1 id
1 change: 1 addition & 0 deletions src/Graphics/Rendering/OpenGL/GL/TransformFeedback.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Foreign.Marshal.Array
import Graphics.Rendering.OpenGL.GL.ByteString
import Graphics.Rendering.OpenGL.GL.DataType
import Graphics.Rendering.OpenGL.GL.PrimitiveMode
import Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.Rendering.OpenGL.GL.Shaders.Program
import Graphics.Rendering.OpenGL.GL.Shaders.Variables
Expand Down
1 change: 1 addition & 0 deletions src/Graphics/Rendering/OpenGL/GL/VertexArrays.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Graphics.Rendering.OpenGL.GL.Capability
import Graphics.Rendering.OpenGL.GL.DataType
import Graphics.Rendering.OpenGL.GL.GLboolean
import Graphics.Rendering.OpenGL.GL.PrimitiveMode
import Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.Rendering.OpenGL.GL.StateVar
import Graphics.Rendering.OpenGL.GL.Texturing.TextureUnit
Expand Down
1 change: 1 addition & 0 deletions src/Graphics/Rendering/OpenGL/GLU/NURBS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Graphics.Rendering.OpenGL.GL.CoordTrans
import Graphics.Rendering.OpenGL.GL.Exception
import Graphics.Rendering.OpenGL.GL.GLboolean
import Graphics.Rendering.OpenGL.GL.PrimitiveMode
import Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal
import Graphics.Rendering.OpenGL.GL.VertexSpec
import Graphics.Rendering.OpenGL.GLU.ErrorsInternal
import Graphics.Rendering.OpenGL.Raw
Expand Down
8 changes: 4 additions & 4 deletions src/Graphics/Rendering/OpenGL/GLU/Tessellation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module : Graphics.Rendering.OpenGL.GLU.Tessellation
-- Copyright : (c) Sven Panne 2002-2013
-- License : BSD3
--
--
-- Maintainer : Sven Panne <[email protected]>
-- Stability : stable
-- Portability : portable
Expand Down Expand Up @@ -48,9 +48,9 @@ import Graphics.Rendering.OpenGL.GL.Tensor
import Graphics.Rendering.OpenGL.GL.EdgeFlag ( unmarshalEdgeFlag )
import Graphics.Rendering.OpenGL.GL.Exception ( bracket )
import Graphics.Rendering.OpenGL.GL.GLboolean ( marshalGLboolean )
import Graphics.Rendering.OpenGL.GL.PrimitiveMode ( unmarshalPrimitiveMode )
import Graphics.Rendering.OpenGL.GL.BeginEnd (
PrimitiveMode, EdgeFlag(BeginsInteriorEdge) )
import Graphics.Rendering.OpenGL.GL.PrimitiveMode ( PrimitiveMode )
import Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal ( unmarshalPrimitiveMode )
import Graphics.Rendering.OpenGL.GL.BeginEnd ( EdgeFlag(BeginsInteriorEdge) )
import Graphics.Rendering.OpenGL.GL.VertexSpec
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.Rendering.OpenGL.GLU.ErrorsInternal
Expand Down