第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 WebGL 支持模板緩沖區(qū)

使用 WebGL 支持模板緩沖區(qū)

千萬里不及你 2022-12-22 13:45:22
使用模板緩沖區(qū)請求初始化 webgl canvas.getContext("webgl", {stencil : true}),但并非所有瀏覽器實際上都會給你一個(對我來說,Ubuntu 20.04 LTS 上的 Firefox 79.0 不起作用,但 Chrome 84.0.4147.89 可以。我的顯卡是 NVIDIA RTX 2060,我正在使用nvidia-driver-440-server 驅動程序)。我想知道模板緩沖區(qū)的支持有多廣泛,但我找不到有關支持哪些瀏覽器的信息。像 之類的函數(shù)glStencilOp是我唯一能找到支持信息的東西,它們?nèi)匀豢梢允褂茫鼈冎皇遣皇褂?0 模板位做任何事情。是否有支持此功能的瀏覽器列表?
查看完整描述

1 回答

?
翻閱古今

TA貢獻1780條經(jīng)驗 獲得超5個贊

老實說,這聽起來像是 firefox 中的錯誤,盡管鑒于規(guī)范允許實現(xiàn)無法出于任何原因在畫布上提供模板緩沖區(qū),但從技術上講這不是錯誤。我會考慮填一個。使用 Chromium 瀏覽器進行測試,以檢查這是 Firefox 選擇不提供模板緩沖區(qū),而不是驅動程序問題或其他問題。


您應該能夠始終制作DEPTH_STENCIL渲染緩沖區(qū)。沒有允許實現(xiàn)不支持的 WebGL 版本。因此,您可以通過渲染到附加到幀緩沖區(qū)的紋理+深度模板渲染緩沖區(qū)來解決該錯誤,然后將幀緩沖區(qū)顏色紋理渲染到畫布。


這是一個測試。您應該會看到一個右下角為綠色的紅色正方形。那將在紫色方塊內(nèi)的藍色方塊內(nèi)。


藍色方塊用于顯示幀緩沖區(qū)紋理的范圍。如果綠色方塊沒有被模板緩沖區(qū)遮蓋,它就會滲入藍色。


紫色方塊顯示畫布的大小,我們繪制的幀緩沖區(qū)紋理小于整個畫布。這只是為了表明模板緩沖區(qū)可以在您的機器上工作。對于您自己的解決方案,您希望繪制一個由頂點組成的四邊形而不是使用如下所示的點,并且您希望使附加到幀緩沖區(qū)的紋理和渲染緩沖區(qū)與畫布的大小相同。


"use strict";


function main() {

  const gl = document.querySelector("canvas").getContext("webgl");

  

  const vs = `

  attribute vec4 position;

"use strict";


function main() {

  const gl = document.querySelector("canvas").getContext("webgl");

  

  const vs = `

  attribute vec4 position;


  void main() {

    gl_Position = position;

    gl_PointSize = 64.0;

  }

  `;


  const fs = `

  precision mediump float;


  uniform sampler2D tex;


  void main() {

     gl_FragColor = texture2D(tex, gl_PointCoord.xy);

  }

  `;


  const program = twgl.createProgram(gl, [vs, fs]);

  const posLoc = gl.getAttribLocation(program, "position");


  // Create a texture to render to

  const targetTextureWidth = 128;

  const targetTextureHeight = 128;

  const targetTexture = createTexture(gl);


  {

    // define size and format of level 0

    const level = 0;

    const internalFormat = gl.RGBA;

    const border = 0;

    const format = gl.RGBA;

    const type = gl.UNSIGNED_BYTE;

    const data = null;

    gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,

                  targetTextureWidth, targetTextureHeight, border,

                  format, type, data);


  }


  // Create and bind the framebuffer

  const fb = gl.createFramebuffer();

  gl.bindFramebuffer(gl.FRAMEBUFFER, fb);


  // attach the texture as the first color attachment

  const attachmentPoint = gl.COLOR_ATTACHMENT0;

  const level = 0;

  gl.framebufferTexture2D(gl.FRAMEBUFFER, attachmentPoint, gl.TEXTURE_2D, targetTexture, level);


  // create a depth-stencil renderbuffer

  const depthStencilBuffer = gl.createRenderbuffer();

  gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);


  // make a depth-stencil buffer and the same size as the targetTexture

  gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, targetTextureWidth, targetTextureHeight);

  gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);

  

  function createTexture(gl, color) {

    const tex = gl.createTexture();

    gl.bindTexture(gl.TEXTURE_2D, tex);

    // set the filtering so we don't need mips

    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);

    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);

    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

    if (color) {

      gl.texImage2D(

          gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0,

          gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(color));

    }

    return tex;

  }

  

  // create a red texture and a green texture

  const redTex = createTexture(gl, [255, 0, 0, 255]);

  const greenTex = createTexture(gl, [0, 255, 0, 255]);


  gl.enable(gl.STENCIL_TEST);


  gl.useProgram(program);

  gl.clearColor(0, 0, 1, 1);

  gl.clear(gl.COLOR_BUFFER_BIT);

  

  gl.bindTexture(gl.TEXTURE_2D, redTex);

  gl.stencilFunc(

       gl.ALWAYS,    // the test

       1,            // reference value

       0xFF,         // mask

    );  

  gl.stencilOp(

     gl.KEEP,     // what to do if the stencil test fails

     gl.KEEP,     // what to do if the depth test fails

     gl.REPLACE,  // what to do if both tests pass

  );

  

  // draw a 64x64 pixel red rect in middle

  gl.drawArrays(gl.POINTS, 0, 1);

  


  gl.stencilFunc(

       gl.EQUAL,     // the test

       1,            // reference value

       0xFF,         // mask

    );  

  gl.stencilOp(

     gl.KEEP,     // what to do if the stencil test fails

     gl.KEEP,     // what to do if the depth test fails

     gl.KEEP,  // what to do if both tests pass

  );



  // draw a green 64x64 pixel square in the

  // upper right corner. The stencil will make

  // it not go outside the red square

  gl.vertexAttrib2f(posLoc, 0.5, 0.5);

  gl.bindTexture(gl.TEXTURE_2D, greenTex);

  gl.drawArrays(gl.POINTS, 0, 1);


  // draw the framebuffer's texture to

  // the canvas. we should see a 32x32

  // red square with the bottom right corner

  // green showing the stencil worked. That will

  // be surrounded by blue to show the texture

  // we were rendering to is larger than the

  // red square. And that will be surrounded

  // by purple since we're drawing a 64x64

  // point on a 128x128 canvas which we clear 

  // purple.

  gl.bindFramebuffer(gl.FRAMEBUFFER, null);

  gl.clearColor(1, 0, 1, 1);

  gl.clear(gl.COLOR_BUFFER_BIT);

  

  gl.vertexAttrib2f(posLoc, 0.0, 0.0);

  gl.bindTexture(gl.TEXTURE_2D, targetTexture);

  gl.drawArrays(gl.POINTS, 0, 1);  


}


main();

canvas { border: 1px solid black; }

<script src="https://twgljs.org/dist/4.x/twgl.min.js"></script>

<canvas width="128" height="128"></canvas>

  void main() {

    gl_Position = position;

    gl_PointSize = 64.0;

  }

  `;


  const fs = `

  precision mediump float;


  uniform sampler2D tex;


  void main() {

     gl_FragColor = texture2D(tex, gl_PointCoord.xy);

  }

  `;


  const program = twgl.createProgram(gl, [vs, fs]);

  const posLoc = gl.getAttribLocation(program, "position");


  // Create a texture to render to

  const targetTextureWidth = 128;

  const targetTextureHeight = 128;

  const targetTexture = createTexture(gl);


  {

    // define size and format of level 0

    const level = 0;

    const internalFormat = gl.RGBA;

    const border = 0;

    const format = gl.RGBA;

    const type = gl.UNSIGNED_BYTE;

    const data = null;

    gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,

                  targetTextureWidth, targetTextureHeight, border,

                  format, type, data);


  }


  // Create and bind the framebuffer

  const fb = gl.createFramebuffer();

  gl.bindFramebuffer(gl.FRAMEBUFFER, fb);


  // attach the texture as the first color attachment

  const attachmentPoint = gl.COLOR_ATTACHMENT0;

  const level = 0;

  gl.framebufferTexture2D(gl.FRAMEBUFFER, attachmentPoint, gl.TEXTURE_2D, targetTexture, level);


  // create a depth-stencil renderbuffer

  const depthStencilBuffer = gl.createRenderbuffer();

  gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);


  // make a depth-stencil buffer and the same size as the targetTexture

  gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, targetTextureWidth, targetTextureHeight);

  gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);

  

  function createTexture(gl, color) {

    const tex = gl.createTexture();

    gl.bindTexture(gl.TEXTURE_2D, tex);

    // set the filtering so we don't need mips

    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);

    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);

    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

    if (color) {

      gl.texImage2D(

          gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0,

          gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(color));

    }

    return tex;

  }

  

  // create a red texture and a green texture

  const redTex = createTexture(gl, [255, 0, 0, 255]);

  const greenTex = createTexture(gl, [0, 255, 0, 255]);


  gl.enable(gl.STENCIL_TEST);


  gl.useProgram(program);

  gl.clearColor(0, 0, 1, 1);

  gl.clear(gl.COLOR_BUFFER_BIT);

  

  gl.bindTexture(gl.TEXTURE_2D, redTex);

  gl.stencilFunc(

       gl.ALWAYS,    // the test

       1,            // reference value

       0xFF,         // mask

    );  

  gl.stencilOp(

     gl.KEEP,     // what to do if the stencil test fails

     gl.KEEP,     // what to do if the depth test fails

     gl.REPLACE,  // what to do if both tests pass

  );

  

  // draw a 64x64 pixel red rect in middle

  gl.drawArrays(gl.POINTS, 0, 1);

  


  gl.stencilFunc(

       gl.EQUAL,     // the test

       1,            // reference value

       0xFF,         // mask

    );  

  gl.stencilOp(

     gl.KEEP,     // what to do if the stencil test fails

     gl.KEEP,     // what to do if the depth test fails

     gl.KEEP,  // what to do if both tests pass

  );



  // draw a green 64x64 pixel square in the

  // upper right corner. The stencil will make

  // it not go outside the red square

  gl.vertexAttrib2f(posLoc, 0.5, 0.5);

  gl.bindTexture(gl.TEXTURE_2D, greenTex);

  gl.drawArrays(gl.POINTS, 0, 1);


  // draw the framebuffer's texture to

  // the canvas. we should see a 32x32

  // red square with the bottom right corner

  // green showing the stencil worked. That will

  // be surrounded by blue to show the texture

  // we were rendering to is larger than the

  // red square. And that will be surrounded

  // by purple since we're drawing a 64x64

  // point on a 128x128 canvas which we clear 

  // purple.

  gl.bindFramebuffer(gl.FRAMEBUFFER, null);

  gl.clearColor(1, 0, 1, 1);

  gl.clear(gl.COLOR_BUFFER_BIT);

  

  gl.vertexAttrib2f(posLoc, 0.0, 0.0);

  gl.bindTexture(gl.TEXTURE_2D, targetTexture);

  gl.drawArrays(gl.POINTS, 0, 1);  


}


main();

canvas { border: 1px solid black; }

<script src="https://twgljs.org/dist/4.x/twgl.min.js"></script>

<canvas width="128" height="128"></canvas>

如果將渲染緩沖區(qū)格式更改為 DEPTH_COMPONENT16 并將附著點更改為 DEPTH_ATTACHMENT,那么您將看到綠色方塊不再被模板遮蓋


您應該能夠調(diào)用gl.getContextAttributes以檢查您是否有模板緩沖區(qū),因此如果它告訴您您沒有在畫布上獲得模板緩沖區(qū),您可以使用建議的解決方案。



查看完整回答
反對 回復 2022-12-22
  • 1 回答
  • 0 關注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號