2016-10-10 53 views
0

我不知道copyteximage2D是如何工作的, 我想在WebGL的狀態機的任期解釋:copyteximage2D在狀態機方面

感謝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!!! 
..... 
} 

回答

0

copyTexImage2D副本從當前framebuffer或canvas到當前紋理單元的給定目標

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 
} 
+0

不錯!所以,如果,在gl.copyTex之前..我把'fbPV2 = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER,fbPV2); gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,pvTex2,0); '所以pvTex2會複製到綁定到當前紋理單元的紋理? –

+0

是的'pxTex2'將成爲您決定複製TexImage2D到任何紋理的源代碼。 – gman

+0

好!現在我面臨着另一個問題:pvTex2是一個浮動紋理。它似乎可能是問題?或者可能是問題在於我沒有在copyTexImage2D之後製作generatemimap(或設置過濾器)? –