webgl2 - Explanation for gl.TEXTURE0 ... n -


i spot in debugger number of gl.texture0 .... 31 . 0 + 31 = 32 32 objects textures have 1 textures .

i found on mozilla dev site : "gl provides 32 texture registers; first of these gl.texture0" .

when bind next (second tex) did use :

  gl.activetexture(gl.texture0);   gl.bindtexture(gl.texture_2d, textures[0]);   gl.activetexture(gl.texture1);   gl.bindtexture(gl.texture_2d, textures[1]); 

or :

  gl.activetexture(gl.texture0);   gl.bindtexture(gl.texture_2d, textures[0]);   gl.activetexture(gl.texture33);   gl.bindtexture(gl.texture_2d, textures[1]); 

if mozilla's site says

"gl provides 32 texture registers

the site wrong

webgl , webgl2 have many texture units driver/gpu supports. both webgl1 , webgl2 have minimum number though. webgl1's 8 (8 fragment shader textures , 0 vertex shader textures), webgl2's 32 (16 fragment shader textures , 16 vertex shader textures)

so, it's best start @ unit 0 , work up. if need use more 8 on webgl1 or more 32 in webgl2 should query how many available , either tell user can't use site or fallback simpler method works within minimums.

as higher numbers it's easier use

var unit = ???; gl.activetexture(gl.texture0 + unit); ... 

because matches need setting sampler uniform

// bind texture texture unit 7 var unit = 7; gl.activetexture(gl.texture0 + unit); gl.bindtexture(gl.texture_2d, sometexture);  // , tell sampler uniform use texture unit 7 gl.uniform1i(somesampleruniformlocation, unit); 

if you're not using more minimum there's nothing query. if using more minimum can query calling

 const maxvertextextureunits = gl.getparameter(gl.max_vertex_texture_image_units);  const maxfragmenttextureunits = gl.getparameter(gl.max_texture_image_units);  const maxcombinedtextureunits = gl.getparameter(gl.max_combined_texture_image_units); 

max_combined_texture_image_units absolute max of first 2. in webgl1 it's 8. in webgl2 it's 32. means example let's in webgl1 that

max_vertex_texture_image_units = 4 max_texture_image_units = 8 max_combined_texture_image_units = 8

that means @ can use 8 units. of those, 4 can used in vertex shader , 8 can used in fragment shader total used can't more 8. so, if used 2 in vertex shader use 6 linked fragment shader total of 8.

checking webglstats.com see plenty of gpus support 64 combined texture units, 32 in vertex shader , 32 in fragment shader.

as binding textures bind them particular draw call. in other words can have 1000s of textures can use max_combined_texture_image_units in single draw call.

typically

 pseudo code  each thing want draw     use program thing     set attributes (bind vertex array) thing     set uniforms , bind textures thing     draw 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -