Game Development Reference
In-Depth Information
dataType: 'xml'
});
$.ajax({
async: false,
url: shaderFilenames[i] + '.vs',
success: function (data) {
vertexShaderSRC = data.firstChild.textContent;
},
dataType: 'xml'
});
setupShaders(fragmentShaderSRC, vertexShaderSRC, i);
}
}
function attachShaders(i){
gl.attachShader(shaderPrograms[i], vertexShaders[i]);
gl.attachShader(shaderPrograms[i], fragmentShaders[i]);
gl.linkProgram(shaderPrograms[i]);
if (!gl.getProgramParameter(shaderPrograms[i], gl.LINK_STATUS)) {
alert("Unable to initialize the shader program.");
}
}
function createShaderProgram(i){
shaderPrograms[i] = gl.createProgram();
attachShaders(i);
}
function setupShaders(fragmentShaderSRC, vertexShaderSRC, i){
fragmentShaders[i] = makeShader(fragmentShaderSRC, gl.FRAGMENT_SHADER);
vertexShaders[i] = makeShader(vertexShaderSRC, gl.VERTEX_SHADER);
createShaderProgram(i);
}
As shown in Listing 7-26, next we set up our vertex uniforms and attributes for each program. The texture
shader sets a sampler uniform. We use the vertex attribute in our color shader and texture coordinate
attribute in our texture shader.
Listing 7-26. Setting Our Shader Uniform and Attributes
function getMatrixUniforms(i){
shaderPrograms[i].pMatrixUniform = gl.getUniformLocation(shaderPrograms[i],
"uPMatrix");
shaderPrograms[i].mvMatrixUniform = gl.getUniformLocation(shaderPrograms[i],
"uMVMatrix");
if( i==TEXTURE_SHADER ){
shaderPrograms[i].samplerUniform = gl.getUniformLocation
(shaderPrograms[i], "uSampler");
}
}
 
Search WWH ::




Custom Search