copyteximage2D在状态机方面

时间:2016-10-10 21:57:12

标签: webgl

我不知道copyteximage2D是如何工作的, 我想用webgl状态机来解释一下:

感谢gman我有这个:

gl = { 
    activeTextureUnit: 0,
    textureUnits: [],
};

gl.activeTexture = function(unit) {
    this.activeTextureUnit = unit - this.TEXTURE_0;  
};

gl.bindTexture = function(bindPoint, texture) {
    var textureUnit = this.textureUnits[this.activeTextureUnit];
    switch (bindPoint) {
       case this.TEXTURE_2D:
         textureUnit.texture2D = texture;
         break;
       case ....
    }
};
gl.copyTexImage2D = function( target, level, iformat, x, y, w,h,b) {
.....
..... gman please your code here thanks very much!!!
.....
}

1 个答案:

答案 0 :(得分:0)

copyTexImage2D从当前帧缓冲区或画布复制到当前纹理单元的给定目标

gl = {
  activeTextureUnit: 0,
  textureUnits: [
    { gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
    { gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
    { gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
    { gl.TEXTURE_2D: null, gl.TEXTURE_CUBE_MAP: null, ... },
    ...
  ],
  framebufferBindPoints: {
    gl.FRAMEBUFFER: gl.canvas.internalFramebuffer,
  },
};

gl.bindFramebuffer = function(bindPoint, framebuffer) {
  this.framebufferBindPoints[bindPoint] = 
     framebuffer ? framebuffer : gl.canvas.internalFramebuffer;
}; 

gl.copyTexImage2D = function( target, level, iformat, x, y, w,h,b) {
  var textureUnit = this.textureUnits[this.activeTextureUnit];
  var texture = textureUnit[target];
  var framebuffer = this.framebufferBindPoints[gl.FRAMEBUFFER];
  // copy from framebuffer into texture
}