如何在WebGL中清除矩形区域? [英] How to clear a rectangle area in WebGL?

查看:115
本文介绍了如何在WebGL中清除矩形区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebGL具有 clear 方法,可清除整个表面。仅清除表面的特定矩形的最佳方法是什么?例如,我想将一个像素为100x100的框(从(50,50)开始)设置为全零(ARGB 0、0、0、0)。我现在所能想到的就是绘制一个带有片段着色器的四边形,该着色器写入零。有没有更简单的方法?

WebGL has a clear method that clears an entire surface. What's the best way to clear just a particular rectangle of the surface? For example I want to set a 100x100 box of pixels starting at (50, 50) to all zeroes (ARGB 0, 0, 0, 0). All I can think of right now is drawing a quad with a fragment shader that writes zeroes. Is there not an easier way?

推荐答案

您可以使用SCISSOR测试将清除(和渲染)限制为一个矩形

You can use the SCISSOR test to constrain clearing (and rendering in general) to a rectangle.

// turn on the scissor test.
gl.enable(gl.SCISSOR_TEST);

// set the scissor rectangle.
gl.scissor(x, y, width, height);

// clear.
gl.clearColor(r, g, b, a);
gl.clear(gl.COLOR_BUFFER_BIT ...);

// turn off the scissor test so you can render like normal again.
gl.disable(gl.SCISSOR_TEST);

这篇关于如何在WebGL中清除矩形区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆