glColorPointer 试图提高 fps

发布于 2024-11-09 22:33:58 字数 891 浏览 0 评论 0原文

我终于达到了可以为顶点添加一些颜色的程度。但现在我想提高我的 FPS 率。这是目前的情况。我有大量顶点 (~200000),每个顶点都可以属于~150 个类之一。每个类别的区别在于它的颜色。我目前正在绘制我的顶点,如下所示:

    glEnableClientState(GL_VERTEX_ARRAY)         
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferVertices)
    glVertexPointer(3, GL_FLOAT, 0, None)          
    glEnableClientState(GL_NORMAL_ARRAY);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferNormals)
    glNormalPointer(GL_FLOAT, 0, None)     
    glEnableClientState(GL_COLOR_ARRAY)
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferColors)
    glColorPointer(3, GL_FLOAT, 0, None)
    glDrawArrays( GL_POINTS, 0, len(self.vertices) / 3 )

一切正常,FPS 约为 60。我的所有缓冲区都是在初始化时生成的。但现在代表每个类别的颜色将快速变化,大约每毫秒一次。这样颜色也会改变,所以我必须为每次绘制重新创建颜色缓冲区,对于 200000 个顶点,我感觉 FPS 将接近 0。我试图实现的修复是保持固定颜色缓冲区,但它们将保留指向其所代表的类的指针,而不是实际的颜色。这样,只有类的 200 种颜色会发生变化。问题是我不知道如何在 OpenGL 中实现这一点。这可行吗?有关如何执行此操作的任何指示?

I've finnaly reached the point that I can add some color to my vertices. But now I want to improve my FPS rate. Here is the current situation. I have a large number of vertices (~200000) , and each of them can be in one of ~150 classes. Each class is differenced by it`s color. I'm currently drawing my vertices like:

    glEnableClientState(GL_VERTEX_ARRAY)         
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferVertices)
    glVertexPointer(3, GL_FLOAT, 0, None)          
    glEnableClientState(GL_NORMAL_ARRAY);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferNormals)
    glNormalPointer(GL_FLOAT, 0, None)     
    glEnableClientState(GL_COLOR_ARRAY)
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferColors)
    glColorPointer(3, GL_FLOAT, 0, None)
    glDrawArrays( GL_POINTS, 0, len(self.vertices) / 3 )

Everything works fine and the FPS is ~60. All my buffers are generated only at init time. But now the colors that represent each class will change rapidly, once about every millisecond. With that the colors will also change so I would have to recreate my color buffer for each draw, and for 200000 vertices I have a feeling the FPS will be close to 0. The fix I'm trying to implement is to keep a fixed color buffer, but instead of the actual colors, they would retain a pointer to the class it`s represented by. That way, only the 200 colors of the classes will change. Problem is I don't know how this could be implemented in OpenGL. Is this doable ? Any pointers in how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

A君 2024-11-16 22:33:59

类应该设置一维纹理坐标,而不是颜色,然后不必更改庞大的数据集,而只需替换纹理的一部分。为了避免纹理采样插值,将纹理设置为 GL_NEAREST 过滤模式,并在每个顶点的顶点着色器中对纹理进行采样(即,不像通常那样对每个片段进行纹理采样)。

Instead of colors the classes should set a 1D texture coordinate, then instead of changing that huge dataset you have to replace only parts of the texture. To avoid texture sampling interpolation set the texture into GL_NEAREST filtering mode, and sample the texture in the vertex shader per vertex (i.e. no per fragment texture sampling as you'd do usually).

寂寞清仓 2024-11-16 22:33:59

我认为你应该认真看看着色器。您不需要每次都重新创建缓冲区。 http://en.wikipedia.org/wiki/GLSL。着色器将使用您的缓冲区来执行颜色和几何方面的各种操作。

I think you should seriously take a look at shaders. You shouldn't need to recreate your buffer every time. http://en.wikipedia.org/wiki/GLSL. The shaders will use your buffer to perform all kinds of operations in color and geometry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文