11from __future__ import annotations
22
3+ import struct
34from ctypes import POINTER , cast
45
56from pyglet import gl
@@ -274,12 +275,18 @@ def _create_setter_func(
274275 is_matrix ,
275276 ):
276277 """Create setters for OpenGL data."""
278+ # Matrix uniforms
277279 if is_matrix :
278280 if ctx ._ext_separate_shader_objects_enabled :
279281
280282 def setter_func (value ): # type: ignore #conditional function variants must have identical signature
281283 """Set OpenGL matrix uniform data."""
282- c_array [:] = value
284+ try :
285+ # FIXME: Configure the struct format on the uniform to support
286+ # other types than float
287+ c_array [:] = struct .unpack (f"{ length } f" , value )
288+ except Exception :
289+ c_array [:] = value
283290 gl_program_setter (program_id , location , array_length , gl .GL_FALSE , ptr )
284291
285292 else :
@@ -290,6 +297,7 @@ def setter_func(value): # type: ignore #conditional function variants must have
290297 gl .glUseProgram (program_id )
291298 gl_setter (location , array_length , gl .GL_FALSE , ptr )
292299
300+ # Single value uniforms
293301 elif length == 1 and count == 1 :
294302 if ctx ._ext_separate_shader_objects_enabled :
295303
@@ -306,12 +314,20 @@ def setter_func(value): # type: ignore #conditional function variants must have
306314 gl .glUseProgram (program_id )
307315 gl_setter (location , array_length , ptr )
308316
317+ # Uniforms types with multiple components
309318 elif length > 1 and count == 1 :
310319 if ctx ._ext_separate_shader_objects_enabled :
311320
312321 def setter_func (values ): # type: ignore #conditional function variants must have identical signature
313322 """Set list of OpenGL uniform data."""
314- c_array [:] = values
323+ # Support buffer protocol
324+ try :
325+ # FIXME: Configure the struct format on the uniform to support
326+ # other types than float
327+ c_array [:] = struct .unpack (f"{ length } f" , values )
328+ except Exception :
329+ c_array [:] = values
330+
315331 gl_program_setter (program_id , location , array_length , ptr )
316332
317333 else :
0 commit comments