如何摆脱glClear(GL_STENCIL_BUFFER_BIT)
How to get rid of glClear(GL_STENCIL_BUFFER_BIT)
我试图将OpenGL绘制限制在窗口的一部分。为了做到这一点,我尝试使用GL_STENCIL_TEST选项。这是我的代码:
// Enable stencil and clear the stencil buffer
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
// Enable func and Op so drawing will effect the stencil buffer
glStencilFunc(GL_NEVER, 0x0, 0x0);
glStencilOp(GL_INCR, GL_INCR, GL_INCR);
// Draw a rect to the stencil
DrawSolidRect(rectDrawArea);
// Enable func and Op so drawing will not effect the stencil buffer
// but will only effect places where the stencil was drawn to in the previous step.
glStencilFunc(GL_EQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
问题是glClear(GL_STENCIL_BUFFER_BIT)函数非常耗时,而且由于我以每秒25帧的速度绘制,它确实会减慢应用程序的速度。
我试着删除这个函数-这解决了速度慢的问题,但当我初始化应用程序时,它会导致闪烁-大约10秒。然后它消失了,工作正常。
有人能告诉我为什么闪烁,或者我可以使用其他什么不那么耗时的功能吗?
如果您使用矩形剪辑区域,使用glScissor可能会更容易、更快。http://www.opengl.org/sdk/docs/man/xhtml/glScissor.xml
如上面链接中所述,也可以调用glEnable(GL_SCISSOR_TEST)来启用剪刀测试。
感谢@datenwolf
相关文章:
- 如何"buffer" UNIX 信号
- 如何在C++中设置演员的"Render Custom Depth Pass"和"Depth Stencil Value"?
- 什么是 Direct3D 12.0 上的"Map Default Buffer"?
- VC++ wcscpy_s随机断言"Buffer is too small"
- 将uint8_t*buffer和size_tbufferlen从C++传递到C中的API函数的最佳方式是什么
- boost::asio::buffer 如何遍历字节
- 在 boost::<double>asio::buffer 中使用像 std::vector<std::complex> 这样的参数
- Cppcheck 静态代码分析器实际上可以检测到不太常见的警告(如 "Relative Path Traversal (CWE-23)" 或"Buffer Under-read(CWE-127)")吗
- tf2_ros::Buffer::canTransform() 为现有转换返回 False
- OpenCL/C++ - 返回一个 cl::Buffer 对象
- 如何在方法参数中使用boost :: asio :: buffer
- 尝试运行 NVIDIA FleX 时"buffer overflow detected"
- C++: buffer the cin istream
- 如何将 std::array 转换为 boost::asio::buffer
- 如何从节点本机插件正确创建Buffer对象
- Buffer.BlockCopy Array 2d c++ to C# 共享内存
- opencv imencode() buffer exception
- boost::asio::buffer与矢量结构
- 在类中声明tf2_ros::Buffer时生成错误
- Buffer上次收到Zeromq消息作为类成员