@@ -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 )
156156makeUniformVar 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
173166instance Uniform GLfloat where
174- uniform = makeSimpleUniformVar
167+ uniform = single uniform
175168 uniformv = uniform1v
176169
177170instance Uniform GLint where
178- uniform = makeSimpleUniformVar
171+ uniform = single uniform
179172 uniformv = uniform1v
180173
181174instance Uniform GLuint where
182- uniform = makeSimpleUniformVar
175+ uniform = single uniform
183176 uniformv = uniform1v
184177
185178instance 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+
189186instance 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+
201214instance 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