Skip to content

Commit 64fc1c3

Browse files
committed
Added/fixed various Uniform instances. Relaxed upper version bound for OpenGLRaw.
1 parent b1b5003 commit 64fc1c3

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
3.0.1.0
22
-------
3-
* Added Uniform instance for `GLmatrix`.
3+
* Added `Uniform` instances for `GLmatrix`, `Vertex1`, `Vector1`, `Vector2`, `Vector3`, and `Vector4`.
4+
* Unbreak `Uniform` instances for `GLint`, `GLuint` and `Gldouble`.
5+
* Relaxed upper version bound for `OpenGLRaw`.
46

57
3.0.0.2
68
-------

OpenGL.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ library
163163
transformers >= 0.2 && < 0.6,
164164
ObjectName >= 1.1 && < 1.2,
165165
StateVar >= 1.1 && < 1.2,
166-
OpenGLRaw >= 3.0 && < 3.2,
166+
OpenGLRaw >= 3.0 && < 3.3,
167167
GLURaw >= 2.0 && < 2.1
168168
default-language: Haskell2010
169169
other-extensions:

src/Graphics/Rendering/OpenGL/GL/Shaders/Uniform.hs

+37-24
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Storable a => UniformComponent a where
7676
uniform3 :: UniformLocation -> a -> a -> a -> IO ()
7777
uniform4 :: UniformLocation -> a -> a -> a -> a -> IO ()
7878

79-
getUniform :: Storable (b a) => Program -> UniformLocation -> Ptr (b a) -> IO ()
79+
getUniform :: Storable (b a) => GLuint -> GLint -> Ptr (b a) -> IO ()
8080

8181
uniform1v :: UniformLocation -> GLsizei -> Ptr a -> IO ()
8282
uniform2v :: UniformLocation -> GLsizei -> Ptr a -> IO ()
@@ -89,7 +89,7 @@ instance UniformComponent GLint where
8989
uniform3 (UniformLocation ul) = glUniform3i ul
9090
uniform4 (UniformLocation ul) = glUniform4i ul
9191

92-
getUniform (Program p) (UniformLocation ul) = glGetUniformiv p ul . castPtr
92+
getUniform p ul = glGetUniformiv p ul . castPtr
9393

9494
uniform1v (UniformLocation ul) = glUniform1iv ul
9595
uniform2v (UniformLocation ul) = glUniform2iv ul
@@ -102,7 +102,7 @@ instance UniformComponent GLuint where
102102
uniform3 (UniformLocation ul) = glUniform3ui ul
103103
uniform4 (UniformLocation ul) = glUniform4ui ul
104104

105-
getUniform (Program p) (UniformLocation ul) = glGetUniformuiv p ul . castPtr
105+
getUniform p ul = glGetUniformuiv p ul . castPtr
106106

107107
uniform1v (UniformLocation ul) = glUniform1uiv ul
108108
uniform2v (UniformLocation ul) = glUniform2uiv ul
@@ -115,7 +115,7 @@ instance UniformComponent GLfloat where
115115
uniform3 (UniformLocation ul) = glUniform3f ul
116116
uniform4 (UniformLocation ul) = glUniform4f ul
117117

118-
getUniform (Program p) (UniformLocation ul) = glGetUniformfv p ul . castPtr
118+
getUniform p ul = glGetUniformfv p ul . castPtr
119119

120120
uniform1v (UniformLocation ul) = glUniform1fv ul
121121
uniform2v (UniformLocation ul) = glUniform2fv ul
@@ -128,7 +128,7 @@ instance UniformComponent GLdouble where
128128
uniform3 (UniformLocation ul) = glUniform3d ul
129129
uniform4 (UniformLocation ul) = glUniform4d ul
130130

131-
getUniform (Program p) (UniformLocation ul) = glGetUniformdv p ul . castPtr
131+
getUniform p ul = glGetUniformdv p ul . castPtr
132132

133133
uniform1v (UniformLocation ul) = glUniform1dv ul
134134
uniform2v (UniformLocation ul) = glUniform2dv ul
@@ -154,38 +154,35 @@ makeUniformVar :: (UniformComponent a, Storable (b a))
154154
=> (UniformLocation -> b a -> IO ())
155155
-> UniformLocation -> StateVar (b a)
156156
makeUniformVar setter location = makeStateVar getter (setter location)
157-
where getter = do program <- fmap fromJust $ get currentProgram
158-
allocaBytes maxUniformBufferSize $ \buf -> do
159-
getUniform program location buf
160-
peek buf
161-
162-
getSimpleUniform :: Program -> UniformLocation -> Ptr a -> IO ()
163-
getSimpleUniform (Program p) (UniformLocation ul) = glGetUniformfv p ul . castPtr
164-
165-
makeSimpleUniformVar :: (UniformComponent a)
166-
=> UniformLocation -> StateVar a
167-
makeSimpleUniformVar location = makeStateVar getter (uniform1 location)
168-
where getter = do program <- fmap fromJust $ get currentProgram
169-
allocaBytes maxUniformBufferSize $ \buf -> do
170-
getSimpleUniform program location buf
171-
peek buf
157+
where getter = allocaBytes maxUniformBufferSize $ \buf -> do
158+
getUniformWith getUniform location buf
159+
peek buf
160+
161+
single :: (UniformLocation -> StateVar (Vertex1 a))
162+
-> (UniformLocation -> StateVar a)
163+
single var location = makeStateVar (do Vertex1 x <- get (var location); return x)
164+
(\x -> var location $= Vertex1 x)
172165

173166
instance Uniform GLfloat where
174-
uniform = makeSimpleUniformVar
167+
uniform = single uniform
175168
uniformv = uniform1v
176169

177170
instance Uniform GLint where
178-
uniform = makeSimpleUniformVar
171+
uniform = single uniform
179172
uniformv = uniform1v
180173

181174
instance Uniform GLuint where
182-
uniform = makeSimpleUniformVar
175+
uniform = single uniform
183176
uniformv = uniform1v
184177

185178
instance Uniform GLdouble where
186-
uniform = makeSimpleUniformVar
179+
uniform = single uniform
187180
uniformv = uniform1v
188181

182+
instance UniformComponent a => Uniform (Vertex1 a) where
183+
uniform = makeUniformVar $ \location (Vertex1 x) -> uniform1 location x
184+
uniformv location count = uniform1v location count . (castPtr :: Ptr (Vertex1 b) -> Ptr b)
185+
189186
instance UniformComponent a => Uniform (Vertex2 a) where
190187
uniform = makeUniformVar $ \location (Vertex2 x y) -> uniform2 location x y
191188
uniformv location count = uniform2v location count . (castPtr :: Ptr (Vertex2 b) -> Ptr b)
@@ -198,6 +195,22 @@ instance UniformComponent a => Uniform (Vertex4 a) where
198195
uniform = makeUniformVar $ \location (Vertex4 x y z w) -> uniform4 location x y z w
199196
uniformv location count = uniform4v location count . (castPtr :: Ptr (Vertex4 b) -> Ptr b)
200197

198+
instance UniformComponent a => Uniform (Vector1 a) where
199+
uniform = makeUniformVar $ \location (Vector1 x) -> uniform1 location x
200+
uniformv location count = uniform1v location count . (castPtr :: Ptr (Vector1 b) -> Ptr b)
201+
202+
instance UniformComponent a => Uniform (Vector2 a) where
203+
uniform = makeUniformVar $ \location (Vector2 x y) -> uniform2 location x y
204+
uniformv location count = uniform2v location count . (castPtr :: Ptr (Vector2 b) -> Ptr b)
205+
206+
instance UniformComponent a => Uniform (Vector3 a) where
207+
uniform = makeUniformVar $ \location (Vector3 x y z) -> uniform3 location x y z
208+
uniformv location count = uniform3v location count . (castPtr :: Ptr (Vector3 b) -> Ptr b)
209+
210+
instance UniformComponent a => Uniform (Vector4 a) where
211+
uniform = makeUniformVar $ \location (Vector4 x y z w) -> uniform4 location x y z w
212+
uniformv location count = uniform4v location count . (castPtr :: Ptr (Vector4 b) -> Ptr b)
213+
201214
instance UniformComponent a => Uniform (TexCoord1 a) where
202215
uniform = makeUniformVar $ \location (TexCoord1 s) -> uniform1 location s
203216
uniformv location count = uniform1v location count . (castPtr :: Ptr (TexCoord1 b) -> Ptr b)

0 commit comments

Comments
 (0)