OpenGL中的Scissor

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

一、Scissor box是什么?

中文译为:剪裁测试,用于限制绘制区域。我们可以指定一个矩形的剪裁窗口,当启用剪裁测试后,只有在这个窗口之内的像素才能被绘制,其它像素则会被丢弃。换句话说,无论怎么绘制,剪裁窗口以外的像素将不会被修改。可以通过glScissor(x, y, width, height)代码来指定一个位置在(x, y),宽度为width,高度为height的剪裁窗口。一般来说指定出来的剪裁矩形是视口中的一个子区域,但是这两个区域不一定真正交叉。当两个区域不交叉时,剪裁操作将在视口区域外渲染的像素上进行(归根结底是因为只渲染裁剪窗口内的像素)。注意,视口的变换发生在片段(着色器阶段之前,而剪裁测试发生在片段着色器阶段之后。

二、Clipping、Viewport transformation和Scissor的关系

Clipping是在从世界坐标系变换到视口变换过程中所用到的。
Viewport transformation:世界坐标系->观察坐标系->投影变换->归一化、裁剪->视口变换。
这里视口变换是将归一化、裁剪之后的那个单位立方体内的几何体坐标变换到了屏幕空间坐标系,所谓视口,也就是以屏幕坐标系指定的一个矩形区域,它在我们所创建的窗口之内,参考原点就在窗口的左下角,之所以说是屏幕空间坐标系(很明显,屏幕是二维的啊),是因为我们在这里还保存了针对顶点的深度信息(z向坐标)。这个过程可以发现的是,裁剪之后,变换到视口区域内的几何体信息,丢掉的是处在裁剪(Clipping)立方体之外的顶点信息。

而事实上,顶点信息和像素信息是有区别的。顶点信息存储在顶点缓冲区,而像素信息是在帧缓冲区里面的。比如我们要是定义一个点的SIZE很大,占据了10个像素的话,从顶点信息来判断,它是处在视口之内的,但是在转换成像素的时候,却又有像素点超出了视口范围(它管不了)。
Scissor在片段着色阶段之后,处理的就是像素信息,它所划定的一块矩形区域,就是最终的像素信息所被限定的范围。可以推断的是,当我们不对这个矩形域作限制的时候,我们所能管理的像素区域就是整个的窗口。所以像glClear()之类的直接处理帧缓冲区的函数作用的像素范围就是整个窗口,并不受视口限制。只有当我们的限制了scissor test之后,我们的所处理的像素范围也被限制起来了。


参考的博客

https://blog.csdn.net/danshiming/article/details/54291311
https://blog.csdn.net/sfesly/article/details/23456199

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenGL ES 2.0 is the industry's leading software interface and graphics library for rendering sophisticated 3D graphics on handheld and embedded devices. With OpenGL ES 2.0, the full programmability of shaders is now available on small and portable devices-including cell phones, PDAs, consoles, appliances, and vehicles. However, OpenGL ES differs significantly from OpenGL. Graphics programmers and mobile developers have had very little information about it-until now. In the OpenGL(R) ES 2.0 Programming Guide, three leading authorities on the Open GL ES 2.0 interface-including the specification's editor-provide start-to-finish guidance for maximizing the interface's value in a wide range of high-performance applications. The authors cover the entire API, including Khronos-ratified extensions. Using detailed C-based code examples, they demonstrate how to set up and program every aspect of the graphics pipeline. You'll move from introductory techniques all the way to advanced per-pixel lighting, particle systems, and performance optimization. Coverage includes: * Shaders in depth: creating shader objects, compiling shaders, checking for compile errors, attaching shader objects to program objects, and linking final program objects * The OpenGL ES Shading Language: variables, types, constructors, structures, arrays, attributes, uniforms, varyings, precision qualifiers, and invariance * Inputting geometry into the graphics pipeline, and assembling geometry into primitives * Vertex shaders, their special variables, and their use in per-vertex lighting, skinning, and other applications * Using fragment shaders-including examples of multitexturing, fog, alpha test, and user clip planes * Fragment operations: scissor test, stencil test, depth test, multisampling, blending, and dithering * Advanced rendering: per-pixel lighting with normal maps, environment mapping, particle systems, image post-processing, and projective texturing * Real-world programming challenges: platform diversity, C++ portability, OpenKODE, and platform-specific shader binaries

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值