내 두 번째 프로그램에서 사용할 첫 번째 프로그램에서 알파 맵을 만들려고합니다.Webgl - 프로그램 1에서 텍스처를 만들고 프로그램 2로 보냅니다. 단위 0에 바인딩 된 텍스처 없음
[.Offscreen-For-WebGL-0x7fc3281a4200]RENDER WARNING: there is no texture bound to the unit 0
임을 두 개의 별도의 클래스를 사용하여 두 번째 프로그램은 때때로 처음이 마스킹없이 실행하기 때문에 이들에 대한 이후 : 나는 필자는 모든 설정있어처럼 정확하게 그러나 오류를 얻는 메신저 생각합니다.
두 프로그램 모두 동일한 gl 컨텍스트에서 차례로 실행됩니다. 첫 번째 프로그램의 순서대로 설치 코드를 실행 한 다음 두 번째 프로그램을 실행 한 다음 그 다음에 같은 순서로 그리기 기능을 실행합니다.
// Get gl, add blending ect, then...
// The webgl variable below just holds webgl constants from https://google.github.io/closure-library/api/goog.webgl.html
this.targetTexture_ = this.gl_.createTexture();
this.gl_.activeTexture(webgl.TEXTURE0);
this.gl_.bindTexture(webgl.TEXTURE_2D, this.targetTexture_);
this.gl_.texImage2D(webgl.TEXTURE_2D, 0, webgl.RGBA, this.gl_.canvas.width,
this.gl_.canvas.height, 0, webgl.RGBA, webgl.UNSIGNED_BYTE, null);
this.gl_.texParameteri(webgl.TEXTURE_2D, webgl.TEXTURE_MIN_FILTER, webgl.LINEAR);
this.gl_.texParameteri(webgl.TEXTURE_2D, webgl.TEXTURE_WRAP_S, webgl.CLAMP_TO_EDGE);
this.gl_.texParameteri(webgl.TEXTURE_2D, webgl.TEXTURE_WRAP_T, webgl.CLAMP_TO_EDGE);
this.textureFrameBuffer_ = this.gl_.createFramebuffer();
this.gl_.bindFramebuffer(webgl.FRAMEBUFFER, this.textureFrameBuffer_);
this.gl_.framebufferTexture2D(webgl.FRAMEBUFFER, webgl.COLOR_ATTACHMENT0, webgl.TEXTURE_2D, this.targetTexture_, 0);
// Now i set the maskTexture on the second programs class.
this.secondProgramClass.maskTexture = this.targetTexture_;
// Now i compile & attach the shaders and link the program
그런 다음 프로그램 2의 설정 :
: 프로그램 1// Compile, attach, link up the program...
// This is the texture location to use.
this.maskTextureLocation_ =
this.gl_.getUniformLocation(this.program_, LocationName.MASK);
그리기 기능 프로그램 1 (알파 맵 만들기)의
는설정
this.gl_.bindFramebuffer(webgl.FRAMEBUFFER, this.textureFrameBuffer_); this.gl_.bindTexture(webgl.TEXTURE_2D, this.targetTexture_); this.gl_.viewport(0, 0, this.gl_.canvas.width, this.gl_.canvas.height); // Clear to transparent this.gl_.clearColor(0, 0, 0, 0); this.gl_.clear(webgl.COLOR_BUFFER_BIT | webgl.DEPTH_BUFFER_BIT); this.gl_.useProgram(this.program_); // A helper function that runs: enableVertexAttribArray, bindBuffer, vertexAttribPointer on the objects location and buffer. // In this case its just a square the size of the viewport. renderBufferAttribute(this.gl_, this.position_); // Draw triangles this.gl_.drawArrays(webgl.TRIANGLES, 0, 6);
프로그램 2의 16,그리기 기능 : 이제이 클래스는 maskTexture 첫 번째 클래스 설정에서 설정하고 첫 번째 클래스는 텍스처의 그리기 기능을 실행 한 후, 내가이 프로그램을 그릴 수 있어야 가지고
텍스처가 지나간 것 같군, 그렇지? 순간
this.gl_.bindFramebuffer(webgl.FRAMEBUFFER, null);
this.gl_.clearColor(0, 0, 0, 0);
this.gl_.clear(webgl.COLOR_BUFFER_BIT);
this.gl_.useProgram(this.program_);
// A helper function that runs: enableVertexAttribArray, bindBuffer, vertexAttribPointer on the objects location and buffer.
renderBufferAttribute(this.gl_, this.position_);
if (this.maskTexture) {
this.gl_.activeTexture(this.gl_.TEXTURE0);
this.gl_.bindTexture(webgl.TEXTURE_2D, this.maskTexture);
this.gl_.uniform1i(this.maskTextureLocation_, 0);
}
// Draw triangles
this.gl_.drawArrays(webgl.TRIANGLES, 0,
this.particleCount_.total * PARTICLE_ARRAY_COUNT/2);
쉐이더이 질문에 아마 관련이없는, 우리는 단지 그들이 가정 모두 기대 두 번째로 블록을 렌더링 할 수 있습니다
// Stored in LocationName.MASK above.
uniform sampler2D u_mask;
내가 메신저 아무것도없는 것 같아요,하지만 어떤 방향을 인정할 것이다. 위의 모든 오류주기에서 오류를 가져 오는 중이 야. 필요할 때 자세한 정보를 제공하는 업데이트.
감사합니다.