Skip to content

Commit 98c6cfb

Browse files
committed
Implement Uniform instances for GLint, GLfloat, GLuint, GLdouble
1 parent ae3701a commit 98c6cfb

File tree

1 file changed

+27
-0
lines changed
  • src/Graphics/Rendering/OpenGL/GL/Shaders

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,33 @@ makeUniformVar setter location = makeStateVar getter (setter location)
157157
getUniform program location buf
158158
peek buf
159159

160+
getSimpleUniform :: Storable a => Program -> UniformLocation -> Ptr a -> IO ()
161+
getSimpleUniform (Program p) (UniformLocation ul) = glGetUniformfv p ul . castPtr
162+
163+
makeSimpleUniformVar :: (UniformComponent a)
164+
=> UniformLocation -> StateVar a
165+
makeSimpleUniformVar location = makeStateVar getter (uniform1 location)
166+
where getter = do program <- fmap fromJust $ get currentProgram
167+
allocaBytes maxUniformBufferSize $ \buf -> do
168+
getSimpleUniform program location buf
169+
peek buf
170+
171+
instance Uniform GLfloat where
172+
uniform = makeSimpleUniformVar
173+
uniformv = uniform1v
174+
175+
instance Uniform GLint where
176+
uniform = makeSimpleUniformVar
177+
uniformv = uniform1v
178+
179+
instance Uniform GLuint where
180+
uniform = makeSimpleUniformVar
181+
uniformv = uniform1v
182+
183+
instance Uniform GLdouble where
184+
uniform = makeSimpleUniformVar
185+
uniformv = uniform1v
186+
160187
instance UniformComponent a => Uniform (Vertex2 a) where
161188
uniform = makeUniformVar $ \location (Vertex2 x y) -> uniform2 location x y
162189
uniformv location count = uniform2v location count . (castPtr :: Ptr (Vertex2 b) -> Ptr b)

0 commit comments

Comments
 (0)