2013-11-03 10 views
6

तो मेरे कोड के जावास्क्रिप्ट भाग में, यहां स्निपेट है जो वास्तव में कशेरुक और टुकड़े के शेडरों में पिक्सल की एक सरणी भेजता है- लेकिन जब मैं उन शेडरों पर जाता हूं तो मैं केवल 1 बनावट के साथ काम कर रहा हूं- वैसे भी मैं कर सकता हूं एक समय में दो बनावट भेजें? यदि हां, तो मैं दोनों को कोडे के जीएलएसएल पक्ष पर कैसे पकड़ूंगा?वेबजीएल में एक टुकड़े टुकड़े में एकाधिक बनावट कैसे भेजें?

 if (it > 0){ 

      gl.activeTexture(gl.TEXTURE1); 

      gl.bindTexture(gl.TEXTURE_2D, texture); 

      gl.activeTexture(gl.TEXTURE0); 

      gl.bindFramebuffer(gl.FRAMEBUFFER, FBO2);} 

     else{ 

      gl.activeTexture(gl.TEXTURE1); 

      gl.bindTexture(gl.TEXTURE_2D, texture2); 

      gl.activeTexture(gl.TEXTURE0); 

      gl.bindFramebuffer(gl.FRAMEBUFFER, FBO);} 

     gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); 

उत्तर

9

आप एक से अधिक नमूना वर्दी

uniform sampler2D u_myFirstTexture; 
uniform sampler2D u_mySecondTexture; 

... 

vec4 colorFrom1stTexture = texture2D(u_myFirstTexture, someUVCoords); 
vec4 colorFrom2ndTexture = texture2D(u_mySecondTexture, someOtherUVCoords); 

की घोषणा के द्वारा GLSL में एक से अधिक बनावट संदर्भ आप कर सकते हैं विशिष्ट जो बनावट इकाइयों उन 2 samplers gl.uniform1i

var location1 = gl.getUniformLocation(program, "u_myFirstTexture"); 
var location2 = gl.getUniformLocation(program, "u_mySecondTexture"); 

... 

// tell u_myFirstTexture to use texture unit #7 
gl.uniform1i(location1, 7); 

// tell u_mySecondTexture to use texture unit #4 
gl.uniform1i(location2, 4); 

और आप सेटअप में के रूप में फोन करके का उपयोग gl.activeTexture और gl.bindTexture

का उपयोग करके बनावट इकाइयां
// setup texture unit #7 
gl.activeTexture(gl.TEXTURE7); // or gl.TEXTURE0 + 7 
gl.bindTexture(gl.TEXTURE_2D, someTexture); 
... 

// setup texture unit #4 
gl.activeTexture(gl.TEXTURE4); // or gl.TEXTURE0 + 4 
gl.bindTexture(gl.TEXTURE_2D, someOtherTexture); 
... 
संबंधित मुद्दे