最近研究Cesium的实例化,尽管该技术需要在WebGL2.0,也就是OpenGL ES3.0才支持。调试源码的时候眼前一亮,发现VAO和glDrawBuffers都不是WebGL1.0的标准函数,都是扩展功能,看来WebGL2.0标准的推广势在必行啊。同时发现,通过ANGLE_instanced_arrays的扩展,也可以在WebGL1.0下实现实例化,创建实例化方法的代码如下:
var glDrawElementsInstanced;
var glDrawArraysInstanced;
var glVertexAttribDivisor;
var instancedArrays;
// WebGL2.0标准直接提供了实例化接口 if (webgl2) {
glDrawElementsInstanced = function(mode, count, type, offset, instanceCount) {
gl.drawElementsInstanced(mode, count, type, offset, instanceCount);
};
glDrawArraysInstanced = function(mode, first, count, instanceCount) {
gl.drawArraysInstanced(mode, first, count, instanceCount);
};
glVertexAttribDivisor = function(index, divisor) {
gl.vertexAttribDivisor(index, divisor);
};
} else {
// WebGL1.0下
// 扩展ANGLE_instanced_arrays
instancedArrays = getExtension(gl, ['ANGLE_instanced_arrays']);
if (defined(instancedArrays)) {
glDrawElementsInstanced = function(mode, count, type, offset, instanceCount) {
instancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount);
 


