9
9
name: string
10
10
componentType: GLenum
11
11
kind: BufferKind
12
- values: array [16 , float32 ]
12
+ values: array [64 , uint8 ]
13
13
location: GLint
14
14
changed: bool # Flag for if this uniform has changed since last bound.
15
15
@@ -257,7 +257,7 @@ proc setUniform(
257
257
name: string ,
258
258
componentType: GLenum,
259
259
kind: BufferKind,
260
- values: array [16 , float32 ]
260
+ values: array [64 , uint8 ]
261
261
) =
262
262
for uniform in shader.uniforms.mitems:
263
263
if uniform.name == name:
@@ -272,6 +272,26 @@ proc setUniform(
272
272
273
273
echo & " Ignoring setUniform for \" { name} \" , not active "
274
274
275
+ proc setUniform(
276
+ shader: Shader,
277
+ name: string ,
278
+ componentType: GLenum,
279
+ kind: BufferKind,
280
+ values: array [16 , float32 ]
281
+ ) =
282
+ assert componentType == cGL_FLOAT
283
+ setUniform(shader, name, componentType, kind, cast [array [64 , uint8 ]](values))
284
+
285
+ proc setUniform(
286
+ shader: Shader,
287
+ name: string ,
288
+ componentType: GLenum,
289
+ kind: BufferKind,
290
+ values: array [16 , int32 ]
291
+ ) =
292
+ assert componentType == cGL_INT
293
+ setUniform(shader, name, componentType, kind, cast [array [64 , uint8 ]](values))
294
+
275
295
proc raiseUniformVarargsException(name: string , count: int ) =
276
296
raise newException(
277
297
Exception,
@@ -295,9 +315,9 @@ proc raiseUniformKindException(name: string, kind: BufferKind) =
295
315
)
296
316
297
317
proc setUniform* (shader: Shader, name: string , args: varargs [int32 ]) =
298
- var values: array [16 , float32 ]
318
+ var values: array [16 , int32 ]
299
319
for i in 0 ..< min(len(args), 16 ):
300
- values[i] = args[i]. float32
320
+ values[i] = args[i]
301
321
302
322
var kind: BufferKind
303
323
case len(args):
@@ -353,8 +373,8 @@ proc setUniform*(shader: Shader, name: string, m: Mat4) =
353
373
shader.setUniform(name, cGL_FLOAT, bkMAT4, m)
354
374
355
375
proc setUniform* (shader: Shader, name: string , b: bool ) =
356
- var values: array [16 , float32 ]
357
- values[0 ] = b.float32
376
+ var values: array [16 , int32 ]
377
+ values[0 ] = b.int32
358
378
shader.setUniform(name, cGL_INT, bkSCALAR, values)
359
379
360
380
proc bindUniforms* (shader: Shader) =
@@ -368,62 +388,49 @@ proc bindUniforms*(shader: Shader) =
368
388
if not uniform.changed:
369
389
continue
370
390
371
- case uniform.kind:
391
+ if uniform.componentType == cGL_INT:
392
+ let values = cast [array [16 , GLint]](uniform.values)
393
+
394
+ case uniform.kind:
372
395
of bkSCALAR:
373
- if uniform.componentType == cGL_INT:
374
- glUniform1i(uniform.location, uniform.values[0 ].GLint)
375
- else :
376
- glUniform1f(uniform.location, uniform.values[0 ])
396
+ glUniform1i(uniform.location, values[0 ])
377
397
of bkVEC2:
378
- if uniform.componentType == cGL_INT:
379
- glUniform2i(
380
- uniform.location,
381
- uniform.values[0 ].GLint,
382
- uniform.values[1 ].GLint)
383
- else :
384
- glUniform2f(
385
- uniform.location,
386
- uniform.values[0 ],
387
- uniform.values[1 ]
388
- )
398
+ glUniform2i(uniform.location, values[0 ], values[1 ])
389
399
of bkVEC3:
390
- if uniform.componentType == cGL_INT:
391
- glUniform3i(
392
- uniform.location,
393
- uniform.values[0 ].GLint,
394
- uniform.values[1 ].GLint,
395
- uniform.values[2 ].GLint
396
- )
397
- else :
398
- glUniform3f(
399
- uniform.location,
400
- uniform.values[0 ],
401
- uniform.values[1 ],
402
- uniform.values[2 ]
403
- )
400
+ glUniform3i(uniform.location, values[0 ], values[1 ], values[2 ])
404
401
of bkVEC4:
405
- if uniform.componentType == cGL_INT:
406
- glUniform4i(
407
- uniform.location,
408
- uniform.values[0 ].GLint,
409
- uniform.values[1 ].GLint,
410
- uniform.values[2 ].GLint,
411
- uniform.values[3 ].GLint
412
- )
413
- else :
414
- glUniform4f(
415
- uniform.location,
416
- uniform.values[0 ],
417
- uniform.values[1 ],
418
- uniform.values[2 ],
419
- uniform.values[3 ]
420
- )
402
+ glUniform4i(
403
+ uniform.location,
404
+ values[0 ],
405
+ values[1 ],
406
+ values[2 ],
407
+ values[3 ]
408
+ )
409
+ else :
410
+ raiseUniformKindException(uniform.name, uniform.kind)
411
+ else :
412
+ let values = cast [array [16 , float32 ]](uniform.values)
413
+ case uniform.kind:
414
+ of bkSCALAR:
415
+ glUniform1f(uniform.location, values[0 ])
416
+ of bkVEC2:
417
+ glUniform2f(uniform.location, values[0 ], values[1 ])
418
+ of bkVEC3:
419
+ glUniform3f(uniform.location, values[0 ], values[1 ], values[2 ])
420
+ of bkVEC4:
421
+ glUniform4f(
422
+ uniform.location,
423
+ values[0 ],
424
+ values[1 ],
425
+ values[2 ],
426
+ values[3 ]
427
+ )
421
428
of bkMAT4:
422
429
glUniformMatrix4fv(
423
430
uniform.location,
424
431
1 ,
425
432
GL_FALSE,
426
- uniform. values[0 ].addr
433
+ values[0 ].unsafeAddr
427
434
)
428
435
else :
429
436
raiseUniformKindException(uniform.name, uniform.kind)
0 commit comments