Skip to content

Commit 70abec2

Browse files
TannerRogalskykripken
authored andcommitted
Fix stride for GL state query functions (#5219)
* fix stride for emscriptenWebGLGetUniform and emscriptenWebGLGetVertexAttrib * add a test for gl uniform array querying
1 parent 4f42f6b commit 70abec2

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/library_gl.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,8 +2633,8 @@ var LibraryGL = {
26332633
} else {
26342634
for (var i = 0; i < data.length; i++) {
26352635
switch (type) {
2636-
case 'Integer': {{{ makeSetValue('params', 'i', 'data[i]', 'i32') }}}; break;
2637-
case 'Float': {{{ makeSetValue('params', 'i', 'data[i]', 'float') }}}; break;
2636+
case 'Integer': {{{ makeSetValue('params', 'i*4', 'data[i]', 'i32') }}}; break;
2637+
case 'Float': {{{ makeSetValue('params', 'i*4', 'data[i]', 'float') }}}; break;
26382638
default: throw 'internal emscriptenWebGLGetUniform() error, bad type: ' + type;
26392639
}
26402640
}
@@ -2731,9 +2731,9 @@ var LibraryGL = {
27312731
} else {
27322732
for (var i = 0; i < data.length; i++) {
27332733
switch (type) {
2734-
case 'Integer': {{{ makeSetValue('params', 'i', 'data[i]', 'i32') }}}; break;
2735-
case 'Float': {{{ makeSetValue('params', 'i', 'data[i]', 'float') }}}; break;
2736-
case 'FloatToInteger': {{{ makeSetValue('params', 'i', 'Math.fround(data[i])', 'i32') }}}; break;
2734+
case 'Integer': {{{ makeSetValue('params', 'i*4', 'data[i]', 'i32') }}}; break;
2735+
case 'Float': {{{ makeSetValue('params', 'i*4', 'data[i]', 'float') }}}; break;
2736+
case 'FloatToInteger': {{{ makeSetValue('params', 'i*4', 'Math.fround(data[i])', 'i32') }}}; break;
27372737
default: throw 'internal emscriptenWebGLGetVertexAttrib() error, bad type: ' + type;
27382738
}
27392739
}

tests/full_es2_sdlproc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <unistd.h>
4949
#include <GL/gl.h>
5050
#include <GL/glut.h>
51+
#include <assert.h>
5152

5253
#ifndef HAVE_BUILTIN_SINCOS
5354
#include "sincos.h"
@@ -698,6 +699,14 @@ gears_init(void)
698699
/* Set the LightSourcePosition uniform which is constant throught the program */
699700
glUniform4fv(LightSourcePosition_location, 1, LightSourcePosition);
700701

702+
{
703+
GLfloat LightSourcePosition_copy[4];
704+
glGetUniformfv(program, LightSourcePosition_location, LightSourcePosition_copy);
705+
for (uint32_t i = 0; i < 4; ++i) {
706+
assert(LightSourcePosition[i] == LightSourcePosition_copy[i]);
707+
}
708+
}
709+
701710
/* make the gears */
702711
gear1 = create_gear(1.0, 4.0, 1.0, 20, 0.7);
703712
gear2 = create_gear(0.5, 2.0, 2.0, 10, 0.7);

0 commit comments

Comments
 (0)