RESOLVED FIXED 52190
getUniform should support SAMPLER_2D or SAMPLER_CUBE
https://bugs.webkit.org/show_bug.cgi?id=52190
Summary getUniform should support SAMPLER_2D or SAMPLER_CUBE
Ben Vanik
Reported 2011-01-10 19:22:45 PST
The getUniform call will return 'null' and set INVALID_VALUE when any uniforms of type SAMPLER_2D or SAMPLER_CUBE are queried. Looking at the implementation in WebGLRenderContext.cpp line 2122, there is a '// FIXME: what to do about samplers?' and both type values get ignored. SAMPLER_2D and SAMPLER_CUBE are both integer values set with glUniformi[v] and as such can be queried from GL with glGetUniformiv. Firefox currently implements this and as such in that browser getUniform works for these types. I've tested Chromium on both OSX and Windows (with ANGLE) with the following simple change and it works in my tests: @@ -2117,9 +2117,13 @@ baseType = GraphicsContext3D::FLOAT; length = 16; break; + case GraphicsContext3D::SAMPLER_2D: + case GraphicsContext3D::SAMPLER_CUBE: + baseType = GraphicsContext3D::INT; + length = 1; + break; default: // Can't handle this type - // FIXME: what to do about samplers? m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); return WebGLGetInfo(); } With these changes, you should actually be able to do things like this: var samplerLoc = gl.getUniformLocation(program, "mySampler"); gl.uniform1i(samplerLoc, 1); var value = gl.getUniform(program, samplerLoc); assert(value == 1);
Attachments
Patch (5.49 KB, patch)
2011-02-01 10:07 PST, Zhenyao Mo
kbr: review+
Ben Vanik
Comment 1 2011-01-10 19:47:22 PST
Here's the current workaround I'm using until this is fixed, in case anyone else needs it - just call installUniformHack after getting the gl context. function installUniformHack(gl) { var uniqueUniformId = 0; var original_getUniformLocation = gl.getUniformLocation; gl.getUniformLocation = function (program, name) { var result = original_getUniformLocation.apply(this, arguments); if (result) { if (!result.hasOwnProperty("__uniqueId")) { result.__uniqueId = String(uniqueUniformId++); } } return result; }; var original_uniform1i = gl.uniform1i; gl.uniform1i = function (loc, value) { var program = this.getParameter(this.CURRENT_PROGRAM); var lookaside = program.__uniformLookaside; if (!lookaside) { lookaside = program.__uniformLookaside = {}; } lookaside[loc.__uniqueId] = value; original_uniform1i.apply(this, arguments); }; var original_uniform1iv = gl.uniform1iv; gl.uniform1iv = function (loc, value) { var program = this.getParameter(this.CURRENT_PROGRAM); var lookaside = program.__uniformLookaside; if (!lookaside) { lookaside = program.__uniformLookaside = {}; } lookaside[loc.__uniqueId] = value[0]; original_uniform1iv.apply(this, arguments); }; var original_getUniform = gl.getUniform; gl.getUniform = function (program, loc) { var lookaside = program.__uniformLookaside; if (lookaside) { if (lookaside.hasOwnProperty(loc.__uniqueId)) { return lookaside[loc.__uniqueId]; } } return original_getUniform.apply(this, arguments); }; };
Zhenyao Mo
Comment 2 2011-01-27 20:36:06 PST
I'll incorporate Ben's patch and add some test cases.
Zhenyao Mo
Comment 3 2011-02-01 10:07:23 PST
Zhenyao Mo
Comment 4 2011-02-01 10:07:51 PST
Will update the khronos side test once this is reviewed.
Kenneth Russell
Comment 5 2011-02-01 14:18:13 PST
Comment on attachment 80779 [details] Patch Looks good. Thanks for cleaning this up.
Zhenyao Mo
Comment 6 2011-02-01 14:43:16 PST
Note You need to log in before you can comment on or make changes to this bug.