如何设置和使用持久帧缓冲区对象来进行独特的颜色选择?
这个问题自第一次提出以来发生了很大变化,因为我不明白我对我所问的问题知之甚少。关于调整大小的一个问题使我无法理解创建和使用帧缓冲区这一更大的问题。如果您只需要一个帧缓冲区跳转到答案......对于历史,我完好无损地保留了原始问题。
新手问题。我正在处理一个 GL 项目,并尝试使用独特的颜色制定选择策略。大多数讨论/教程都围绕在后台缓冲区中绘制可选择的实体并在用户单击某处时计算选择。我希望选择缓冲区是持久的,这样我就可以快速计算任何鼠标移动的命中,并且不会重绘选择缓冲区,除非显示或对象几何形状发生变化。
看起来最好的选择是专用的帧缓冲区对象。这是我的问题。除了对帧缓冲区对象完全陌生之外,我很好奇。我最好是在窗口大小事件上删除并重新创建 frambuffer 对象,还是以最大屏幕分辨率创建一次,然后使用可能只是其中的一小部分。我的事件工作正常,对于可能是许多调整大小事件的流,仅调用一次帧缓冲区例程,但我担心 GPU 内存碎片或其他问题,可能会多次重新创建缓冲区。
此外,帧缓冲区对象(纹理和深度)在仅使用其一部分时是否会表现得连贯。
有想法吗?我完全离谱了吗?
编辑: 我已经设置了帧缓冲区对象,现在可以在窗口尺寸下工作,并且可以使用窗口调整它的大小。我认为我的问题是典型的“过度思考”。虽然确实应该尽可能避免在 GPU 上删除/重新创建对象。只要处理正确,调整大小相对较少。
我发现有效的方法是在窗口调整大小时设置一个标志并将缓冲区标记为脏缓冲区,然后在调整缓冲区大小之前等待正常的鼠标事件。正常的鼠标输入或移动表明您已完成将窗口拖动到适当大小并准备好返回工作。缓冲区重新创建一次。此外,由于主帧缓冲区通常会针对管道中的每个窗口大小事件调整大小,因此调整帧缓冲区大小不会在笔记本电脑中烧出一个洞,这是理所当然的。
危机解除,继续前行!
This question changed a lot since it was first asked because I didn't understand how little I knew about what I was asking. And one issue, regarding resizing, was clouding my ability to understand the larger issue of creating and using the framebuffer. If you just need a framebuffer jump to the answer... for history I've left the original question intact.
Newbie question. I've got a GL project I'm working on and am trying to develop a selection strategy using unique colors. Most discussion/tutorials revolve around drawing the selectable entities in the back buffer and calculating the selection when a user clicks somewhere. I want the selection buffer to be persistent so I can quickly calculate hits on any mouse movement and will not redraw the selection buffer unless display or object geometry changes.
It would seem that the best choice would be a dedicated framebuffer object. Here's my issue. On top of being completely new to framebuffer objects, I am curious. Am I better off deleting and recreating the frambuffer object on window size events or creating it once at the maximum screen resolution and then using what may be just a small portion of it. I've got my events working properly to only call the framebuffer routine once for what could be a stream of many resize events, yet I'm concerned about GPU memory fragmentation, or other issues, recreating the buffer, possibly many times.
Also, will a framebuffer object (texture & depth) even behave coherently when using just a portion of it.
Ideas? Am I completely offbase?
EDIT:
I've got my framebuffer object setup and working now at the windows dimensions, and I resize it with the window. I think my issue was classic "overthink". While it is certainly true that deleting/recreating objects on the GPU should be avoided when possible. As long as it is handled correctly the resizes are relatively few.
What I found works is to set a flag and mark the buffer as dirty on window resize, then wait for a normal mouse event before resizing the buffer. A normal mouse enter or move signals you're done dragging the window to size and are ready to get back to work. The buffers recreated once. Also, since the main framebuffer is generally resized for every window size event in the pipeline, it would stand to reason that resizing a framebuffer isn't going to burn a hole in your laptop.
Crisis averted, carry on!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在问题中提到我对这个问题想得太多了。主要原因是问题比问题更大。问题是,我不仅不知道如何控制帧缓冲区,而且不知道如何创建帧缓冲区。有太多的选择,而且似乎没有一个网络资源专门解决我想要做的事情,所以我很挣扎。如果您还在努力解决如何将选择例程移动到具有持久缓冲区的独特配色方案,或者完全不知道帧缓冲区和离屏渲染,请继续阅读。
我已将 OpenGL 画布定义为一个类,并且需要一个“选择缓冲区对象”。我将其添加到班级的私人成员中。
在我的调整大小处理程序和 OpenGL 初始化中,我为选择缓冲区设置了脏标志。
在鼠标处理程序开始时,我会检查脏位,并在适当的情况下检查 setSelectionBuffer();。
这解决了我最初对缓冲区多次删除/重新创建的担忧。在调整窗口大小后,直到鼠标指针重新进入工作区时,才会调整选择缓冲区的大小。现在我只需要弄清楚缓冲区...
然后在渲染函数结束时我测试 sbo,并在它似乎准备就绪时绘制它。
这给了我这个...
此时我相信一切都已就位,可以实际将可选项目绘制到缓冲区,并使用鼠标移动事件来测试点击。我在屏幕上有一个缩略图来显示事情的严重程度。
我希望这对您有很大的帮助,就像一周前对我的帮助一样。 :)
I mentioned in the question that I was overthinking the problem. The main reason for that is because the problem was bigger than the question. The problem was, not only did I not know how to control the framebuffer, I didn't know how to create one. There are so many options and none of the web resources seemed to specifically address what I was trying do, so I struggled with it. If you're also struggling with how to move your selection routine to a unique color scheme with a persistent buffer, or are just at a complete loss as to framebuffers and offscreen rendering, read on.
I've got my OpenGL canvas defined as a class, and I needed a "Selection Buffer Object." I added this to the private members of the class.
In both my resize handler and OpenGL initialization I set the dirty flag for the selection buffer.
At the begining of my mouse handler I check for the dirty bit and
setSelectionBuffer();
if appropriate.This tackles my initial concerns about multiple delete/recreates of the buffer. The selection buffer isn't resized until the mouse pointer reenters the client area, after resizing the window. Now I just had to figure out the buffer...
Then at the end of my render function I test for the sbo, and draw to it if it seems to be ready.
That gives me this...
At this point I believe everything is in place to actually draw selectable items to the buffer, and use mouse move events to test for hits. And I've got an onscreen thumbnail to show how bad things are blowing up.
I hope this was as big a help to you, as it would have been to me a week ago. :)