xaero59 Posted November 11, 2016 Share Posted November 11, 2016 Hello there, I was looking for a way to count uniforms in Babylon.js and found this article that applies to webgl : link I'm wondering how to adapt the code to work with babylon.js, I know that webgl is inside BABYLON.Engine._gl but what about "program" , since it's the shader it has to be defined somewhere , if someone could point me to it , I could adapt the function and post the code in this thread so it could provide additional tool to optimize babylon.js scenes. Thanks ! Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted November 12, 2016 Share Posted November 12, 2016 hi and welcome you most read Effect Class in here "Effect Ts" (for adapt code ) and some material shaders in here : https://github.com/BabylonJS/Babylon.js/tree/master/src/Shaders Quote Link to comment Share on other sites More sharing options...
xaero59 Posted November 12, 2016 Author Share Posted November 12, 2016 Awesome, thanks a lot ! Turns out everything I need is under engine , here is the code for those interested : function getProgramInfo(engine) { var gl = engine._currentEffect._engine._gl; var program = engine._currentEffect._program; var result = { attributes: [], uniforms: [], attributeCount: 0, uniformCount: 0 }, activeUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS), activeAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES); // Taken from the WebGl spec: // http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14 var enums = { 0x8B50: 'FLOAT_VEC2', 0x8B51: 'FLOAT_VEC3', 0x8B52: 'FLOAT_VEC4', 0x8B53: 'INT_VEC2', 0x8B54: 'INT_VEC3', 0x8B55: 'INT_VEC4', 0x8B56: 'BOOL', 0x8B57: 'BOOL_VEC2', 0x8B58: 'BOOL_VEC3', 0x8B59: 'BOOL_VEC4', 0x8B5A: 'FLOAT_MAT2', 0x8B5B: 'FLOAT_MAT3', 0x8B5C: 'FLOAT_MAT4', 0x8B5E: 'SAMPLER_2D', 0x8B60: 'SAMPLER_CUBE', 0x1400: 'BYTE', 0x1401: 'UNSIGNED_BYTE', 0x1402: 'SHORT', 0x1403: 'UNSIGNED_SHORT', 0x1404: 'INT', 0x1405: 'UNSIGNED_INT', 0x1406: 'FLOAT' }; // Loop through active uniforms for (var i = 0; i < activeUniforms; i++) { var uniform = gl.getActiveUniform(program, i); uniform.typeName = enums[uniform.type]; result.uniforms.push(uniform); result.uniformCount += uniform.size; } // Loop through active attributes for (var i = 0; i < activeAttributes; i++) { var attribute = gl.getActiveAttrib(program, i); attribute.typeName = enums[attribute.type]; result.attributes.push(attribute); result.attributeCount += attribute.size; } return result; } engine is the object result of new BABYLON.Engine(canvas,true) so in the console, to get the data, one should type : console.table(getProgramInfo(your engine obj).uniforms) Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted November 12, 2016 Share Posted November 12, 2016 what you want wanna do it in OpenGL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.