@@ -36,12 +36,11 @@ import System.IO.Unsafe ( unsafePerformIO )
36
36
data Error = Error ErrorCategory String
37
37
deriving ( Eq , Ord , Show )
38
38
39
- --------------------------------------------------------------------------------
40
-
41
39
-- | General GL\/GLU error categories
42
40
43
41
data ErrorCategory
44
- = InvalidEnum
42
+ = ContextLost
43
+ | InvalidEnum
45
44
| InvalidValue
46
45
| InvalidOperation
47
46
| InvalidFramebufferOperation
@@ -53,61 +52,130 @@ data ErrorCategory
53
52
| NURBSError
54
53
deriving ( Eq , Ord , Show )
55
54
56
- unmarshalErrorCategory :: GLenum -> ErrorCategory
57
- unmarshalErrorCategory c
58
- | isInvalidEnum c = InvalidEnum
59
- | isInvalidValue c = InvalidValue
60
- | isInvalidOperation c = InvalidOperation
61
- | isInvalidFramebufferOperation c = InvalidFramebufferOperation
62
- | isOutOfMemory c = OutOfMemory
63
- | isStackOverflow c = StackOverflow
64
- | isStackUnderflow c = StackUnderflow
65
- | isTableTooLarge c = TableTooLarge
66
- | isTesselatorError c = TesselatorError
67
- | isNURBSError c = NURBSError
68
- | otherwise = error " unmarshalErrorCategory"
69
-
70
- isInvalidEnum :: GLenum -> Bool
71
- isInvalidEnum c = c == gl_INVALID_ENUM || c == glu_INVALID_ENUM
72
-
73
- isInvalidValue :: GLenum -> Bool
74
- isInvalidValue c = c == gl_INVALID_VALUE || c == glu_INVALID_VALUE
75
-
76
- isInvalidOperation :: GLenum -> Bool
77
- isInvalidOperation c = c == gl_INVALID_OPERATION || c == glu_INVALID_OPERATION
78
-
79
- isInvalidFramebufferOperation :: GLenum -> Bool
80
- isInvalidFramebufferOperation c = c == gl_INVALID_FRAMEBUFFER_OPERATION
81
-
82
- isOutOfMemory :: GLenum -> Bool
83
- isOutOfMemory c = c == gl_OUT_OF_MEMORY || c == glu_OUT_OF_MEMORY
84
-
85
- isStackOverflow :: GLenum -> Bool
86
- isStackOverflow c = c == gl_STACK_OVERFLOW
87
-
88
- isStackUnderflow :: GLenum -> Bool
89
- isStackUnderflow c = c == gl_STACK_UNDERFLOW
90
-
91
- isTableTooLarge :: GLenum -> Bool
92
- isTableTooLarge c = c == gl_TABLE_TOO_LARGE
93
-
94
- isTesselatorError :: GLenum -> Bool
95
- isTesselatorError c = glu_TESS_ERROR1 <= c && c <= glu_TESS_ERROR8
96
-
97
- isNURBSError :: GLenum -> Bool
98
- isNURBSError c = glu_NURBS_ERROR1 <= c && c <= glu_NURBS_ERROR37
99
-
100
- --------------------------------------------------------------------------------
101
-
102
- -- The returned error string is statically allocated, so peekCString
103
- -- does the right thing here. No malloc/free necessary here.
104
-
105
- makeError :: GLenum -> IO Error
106
- makeError e = do
107
- let category = unmarshalErrorCategory e
108
- ptr <- gluErrorString e
109
- description <- peekCString (castPtr ptr)
110
- return $ Error category description
55
+ makeError :: GLenum -> Error
56
+ makeError c
57
+ -- GL errors
58
+ | c == gl_CONTEXT_LOST =
59
+ Error ContextLost " context lost"
60
+ | c == gl_INVALID_ENUM =
61
+ Error InvalidEnum " invalid enumerant"
62
+ | c == gl_INVALID_VALUE =
63
+ Error InvalidValue " invalid value"
64
+ | c == gl_INVALID_OPERATION =
65
+ Error InvalidOperation " invalid operation"
66
+ | c == gl_INVALID_FRAMEBUFFER_OPERATION =
67
+ Error InvalidFramebufferOperation " invalid framebuffer operation"
68
+ | c == gl_OUT_OF_MEMORY
69
+ = Error OutOfMemory " out of memory"
70
+ | c == gl_STACK_OVERFLOW =
71
+ Error StackOverflow " stack overflow"
72
+ | c == gl_STACK_UNDERFLOW =
73
+ Error StackUnderflow " stack underflow"
74
+ | c == gl_TABLE_TOO_LARGE =
75
+ Error TableTooLarge " table too large"
76
+ -- GLU errors
77
+ | c == glu_INVALID_ENUM =
78
+ Error InvalidEnum " invalid enumerant"
79
+ | c == glu_INVALID_VALUE =
80
+ Error InvalidValue " invalid value"
81
+ | c == glu_INVALID_OPERATION =
82
+ Error InvalidOperation " invalid operation"
83
+ | c == glu_OUT_OF_MEMORY
84
+ = Error OutOfMemory " out of memory"
85
+ -- GLU tesselator error
86
+ | c == glu_TESS_ERROR1 =
87
+ Error TesselatorError " gluTessBeginPolygon() must precede a gluTessEndPolygon()"
88
+ | c == glu_TESS_ERROR2 =
89
+ Error TesselatorError " gluTessBeginContour() must precede a gluTessEndContour()"
90
+ | c == glu_TESS_ERROR3 =
91
+ Error TesselatorError " gluTessEndPolygon() must follow a gluTessBeginPolygon()"
92
+ | c == glu_TESS_ERROR4 =
93
+ Error TesselatorError " gluTessEndContour() must follow a gluTessBeginContour()"
94
+ | c == glu_TESS_ERROR5 =
95
+ Error TesselatorError " a coordinate is too large"
96
+ | c == glu_TESS_ERROR6 =
97
+ Error TesselatorError " need combine callback"
98
+ | c == glu_TESS_ERROR7 =
99
+ Error TesselatorError " tesselation error 7"
100
+ | c == glu_TESS_ERROR8 =
101
+ Error TesselatorError " tesselation error 8"
102
+ -- GLU NUBRS errors
103
+ | c == glu_NURBS_ERROR1 =
104
+ Error NURBSError " spline order un-supported"
105
+ | c == glu_NURBS_ERROR2 =
106
+ Error NURBSError " too few knots"
107
+ | c == glu_NURBS_ERROR3 =
108
+ Error NURBSError " valid knot range is empty"
109
+ | c == glu_NURBS_ERROR4 =
110
+ Error NURBSError " decreasing knot sequence knot"
111
+ | c == glu_NURBS_ERROR5 =
112
+ Error NURBSError " knot multiplicity greater than order of spline"
113
+ | c == glu_NURBS_ERROR6 =
114
+ Error NURBSError " gluEndCurve() must follow gluBeginCurve()"
115
+ | c == glu_NURBS_ERROR7 =
116
+ Error NURBSError " gluBeginCurve() must precede gluEndCurve()"
117
+ | c == glu_NURBS_ERROR8 =
118
+ Error NURBSError " missing or extra geometric data"
119
+ | c == glu_NURBS_ERROR9 =
120
+ Error NURBSError " can't draw piecewise linear trimming curves"
121
+ | c == glu_NURBS_ERROR10 =
122
+ Error NURBSError " missing or extra domain data"
123
+ | c == glu_NURBS_ERROR11 =
124
+ Error NURBSError " missing or extra domain data"
125
+ | c == glu_NURBS_ERROR12 =
126
+ Error NURBSError " gluEndTrim() must precede gluEndSurface()"
127
+ | c == glu_NURBS_ERROR13 =
128
+ Error NURBSError " gluBeginSurface() must precede gluEndSurface()"
129
+ | c == glu_NURBS_ERROR14 =
130
+ Error NURBSError " curve of improper type passed as trim curve"
131
+ | c == glu_NURBS_ERROR15 =
132
+ Error NURBSError " gluBeginSurface() must precede gluBeginTrim()"
133
+ | c == glu_NURBS_ERROR16 =
134
+ Error NURBSError " gluEndTrim() must follow gluBeginTrim()"
135
+ | c == glu_NURBS_ERROR17 =
136
+ Error NURBSError " gluBeginTrim() must precede gluEndTrim()"
137
+ | c == glu_NURBS_ERROR18 =
138
+ Error NURBSError " invalid or missing trim curve"
139
+ | c == glu_NURBS_ERROR19 =
140
+ Error NURBSError " gluBeginTrim() must precede gluPwlCurve()"
141
+ | c == glu_NURBS_ERROR20 =
142
+ Error NURBSError " piecewise linear trimming curve referenced twice"
143
+ | c == glu_NURBS_ERROR21 =
144
+ Error NURBSError " piecewise linear trimming curve and nurbs curve mixed"
145
+ | c == glu_NURBS_ERROR22 =
146
+ Error NURBSError " improper usage of trim data type"
147
+ | c == glu_NURBS_ERROR23 =
148
+ Error NURBSError " nurbs curve referenced twice"
149
+ | c == glu_NURBS_ERROR24 =
150
+ Error NURBSError " nurbs curve and piecewise linear trimming curve mixed"
151
+ | c == glu_NURBS_ERROR25 =
152
+ Error NURBSError " nurbs surface referenced twice"
153
+ | c == glu_NURBS_ERROR26 =
154
+ Error NURBSError " invalid property"
155
+ | c == glu_NURBS_ERROR27 =
156
+ Error NURBSError " gluEndSurface() must follow gluBeginSurface()"
157
+ | c == glu_NURBS_ERROR28 =
158
+ Error NURBSError " intersecting or misoriented trim curves"
159
+ | c == glu_NURBS_ERROR29 =
160
+ Error NURBSError " intersecting trim curves"
161
+ | c == glu_NURBS_ERROR30 =
162
+ Error NURBSError " UNUSED"
163
+ | c == glu_NURBS_ERROR31 =
164
+ Error NURBSError " unconnected trim curves"
165
+ | c == glu_NURBS_ERROR32 =
166
+ Error NURBSError " unknown knot error"
167
+ | c == glu_NURBS_ERROR33 =
168
+ Error NURBSError " negative vertex count encountered"
169
+ | c == glu_NURBS_ERROR34 =
170
+ Error NURBSError " negative byte-stride encounteed"
171
+ | c == glu_NURBS_ERROR35 =
172
+ Error NURBSError " unknown type descriptor"
173
+ | c == glu_NURBS_ERROR36 =
174
+ Error NURBSError " null control point reference"
175
+ | c == glu_NURBS_ERROR37 =
176
+ Error NURBSError " duplicate point on piecewise linear trimming curve"
177
+ -- Something went terribly wrong...
178
+ | otherwise = error " makeError"
111
179
112
180
--------------------------------------------------------------------------------
113
181
@@ -141,9 +209,7 @@ isError = (/= gl_NO_ERROR)
141
209
--------------------------------------------------------------------------------
142
210
143
211
getErrors :: IO [Error ]
144
- getErrors = do
145
- es <- getErrorCodesAux (const ([] , True ))
146
- mapM makeError es
212
+ getErrors = map makeError `fmap` getErrorCodesAux (const ([] , True ))
147
213
148
214
recordErrorCode :: GLenum -> IO ()
149
215
recordErrorCode e = do
0 commit comments