Skip to content

Commit 01f5ccc

Browse files
committed
Shader: Support setting float arrays
1 parent f5607af commit 01f5ccc

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

demosys/opengl/shader.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def uniform_check(self, name, expected_type):
206206
raise ShaderError("Incorrect data type: Uniform '{}' is of type {}".format(name, uniform.type.name))
207207
return uniform
208208

209-
# --- Setting uniforms ---
209+
# --- Float uniforms ---
210210

211211
def uniform_1f(self, name, value):
212212
"""
@@ -254,6 +254,52 @@ def uniform_4f(self, name, x, y, z, w):
254254
uniform = self.uniform_check(name, GL.GL_FLOAT_VEC4)
255255
GL.glUniform4f(uniform.location, x, y, z, w)
256256

257+
# --- Float uniform arrays ---
258+
259+
def uniform_1fv(self, name, value, count=1):
260+
"""
261+
Set a float uniform
262+
263+
:param name: Name of the uniform
264+
:param count: Length of the uniform array (default 1)
265+
:param value: float array
266+
"""
267+
uniform = self.uniform_check(name, GL.GL_FLOAT)
268+
GL.glUniform1fv(uniform.location, count, value)
269+
270+
def uniform_2fv(self, name, value, count=1):
271+
"""
272+
Set a vec2 uniform
273+
274+
:param name: name of the uniform
275+
:param count: Length of the uniform array (default 1)
276+
:param value: float array
277+
"""
278+
uniform = self.uniform_check(name, GL.GL_FLOAT_VEC2)
279+
GL.glUniform2fv(uniform.location, count, value)
280+
281+
def uniform_3fv(self, name, value, count=1):
282+
"""
283+
Set a vec3 uniform
284+
285+
:param name: Name of the uniform
286+
:param count: Length of the uniform array (default 1)
287+
:param value: float array
288+
"""
289+
uniform = self.uniform_check(name, GL.GL_FLOAT_VEC3)
290+
GL.glUniform3fv(uniform.location, count, value)
291+
292+
def uniform_4fv(self, name, value, count=1):
293+
"""
294+
Set a vec4 uniform
295+
296+
:param name: Name of the uniform
297+
:param count: Length of the uniform array (default 1)
298+
:param value: float array
299+
"""
300+
uniform = self.uniform_check(name, GL.GL_FLOAT_VEC4)
301+
GL.glUniform4fv(uniform.location, count, value)
302+
257303
# --- Signed Integers ---
258304

259305
def uniform_1i(self, name, value):

0 commit comments

Comments
 (0)