MCPcopy Index your code
hub / github.com/dli/paint / WrappedProgram

Function WrappedProgram

wrappedgl.js:1156–1197  ·  view source on GitHub ↗
(wgl, vertexShaderSource, fragmentShaderSource, requestedAttributeLocations)

Source from the content-addressed store, hash-verified

1154 //we don't have to specify any or all attribute location bindings
1155 //any unspecified bindings will be assigned automatically and can be queried with program.getAttribLocation(attributeName)
1156 function WrappedProgram (wgl, vertexShaderSource, fragmentShaderSource, requestedAttributeLocations) {
1157 this.uniformLocations = {};
1158 this.uniforms = {}; //TODO: if we want to cache uniform values in the future
1159
1160 var gl = wgl.gl;
1161
1162 //build shaders from source
1163 var vertexShader = buildShader(gl, gl.VERTEX_SHADER, vertexShaderSource);
1164 var fragmentShader = buildShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
1165
1166 //create program and attach shaders
1167 var program = this.program = gl.createProgram();
1168 gl.attachShader(program, vertexShader);
1169 gl.attachShader(program, fragmentShader);
1170
1171 //bind the attribute locations that have been specified in attributeLocations
1172 if (requestedAttributeLocations !== undefined) {
1173 for (var attributeName in requestedAttributeLocations) {
1174 gl.bindAttribLocation(program, requestedAttributeLocations[attributeName], attributeName);
1175 }
1176 }
1177 gl.linkProgram(program);
1178
1179
1180 //construct this.attributeLocations (maps attribute names to locations)
1181 this.attributeLocations = {};
1182 var numberOfAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
1183 for (var i = 0; i < numberOfAttributes; ++i) {
1184 var activeAttrib = gl.getActiveAttrib(program, i);
1185 var attributeName = activeAttrib.name;
1186 this.attributeLocations[attributeName] = gl.getAttribLocation(program, attributeName);
1187 }
1188
1189 //cache uniform locations
1190 var uniformLocations = this.uniformLocations = {};
1191 var numberOfUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
1192 for (var i = 0; i < numberOfUniforms; i += 1) {
1193 var activeUniform = gl.getActiveUniform(program, i),
1194 uniformLocation = gl.getUniformLocation(program, activeUniform.name);
1195 uniformLocations[activeUniform.name] = uniformLocation;
1196 }
1197 };
1198
1199 //TODO: maybe this should be on WrappedGL?
1200 WrappedProgram.prototype.getAttribLocation = function (name) {

Callers

nothing calls this directly

Calls 1

buildShaderFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…