I would like to make a game out of many cubes and am planning on putting it on mobile platforms and also on the web using webgl. My problem is when I make a drawelements call per cube I take a hit on the frame rate. Is there a way I can make a single draw call to opengl es to draw them? The only difference between the cubes would be position and color.
我想用许多立方*作游戏,并计划将其放在移动平台上,也可以使用webgl在网络上。我的问题是,当我为每个多维数据集进行一次drawelements调用时,我会对帧速率产生影响。有没有办法可以对opengl进行单次绘制调用来绘制它们?立方体之间的唯一区别是位置和颜色。
3 个解决方案
#1
4
I ran into same problem myself. I asked similar question and answered it myself yesterday. Take a look at:
我自己遇到了同样的问题。我问了类似的问题并且昨天自己回答了。看一眼:
Efficient way of drawing in OpenGL ES
在OpenGL ES中绘制的有效方法
You want to create your vertex buffers and upload them to graphics card memory only once using gl.bufferData. Then use reference to that buffer each time you do gl.drawElements or gl.drawArrays. Until the next time the content of your 3D scene changes, you can use this buffer that is uploaded in graphics card memory.
您想创建顶点缓冲区并使用gl.bufferData将它们上传到图形卡内存一次。然后在每次执行gl.drawElements或gl.drawArrays时使用对该缓冲区的引用。在下次3D场景的内容发生变化之前,您可以使用上传到显卡内存中的此缓冲区。
#2
0
Follow the model of UITableView in how they dequeue cells. I would build an object that keeps track of objects you've drawn and links them to an Identifier. Then you can simply dequeue them with said identifier. If you know you're going to draw many versions of the same object, use that object to minimize rendering/allocations.
遵循UITableView的模型,了解它们如何使单元格出列。我会构建一个对象来跟踪你绘制的对象并将它们链接到一个Identifier。然后你可以简单地用所述标识符将它们出列。如果您知道要绘制同一对象的许多版本,请使用该对象最小化渲染/分配。
#3
0
If you're using Vertex Arrays for your glDrawElements(), I'd suggest instead using Vertex Buffer Objects. This will store the data server side (in GRAM) instead of client side (in system RAM). That way you can make glDrawElements() calls with much less CPU<->GPU data transfer overhead.
如果你正在为glDrawElements()使用Vertex Arrays,我建议使用Vertex Buffer Objects。这将存储数据服务器端(在GRAM中)而不是客户端(在系统RAM中)。这样你就可以用更少的CPU < - > GPU数据传输开销来调用glDrawElements()。
Alternatively, you can store you're cubes in display lists. This way you could use glTranlate() to move a cube around and then just call the display list to render it. The only caveat to using display lists is that whatever you do in the display list is immutable; you can't change the calls in the display list without completely recompiling it.
或者,您可以将多维数据集存储在显示列表中。这样你就可以使用glTranlate()来移动一个立方体,然后只需调用显示列表来渲染它。使用显示列表的唯一警告是,无论你在显示列表中做什么都是不可变的;如果不完全重新编译,则无法更改显示列表中的调用。
#1
4
I ran into same problem myself. I asked similar question and answered it myself yesterday. Take a look at:
我自己遇到了同样的问题。我问了类似的问题并且昨天自己回答了。看一眼:
Efficient way of drawing in OpenGL ES
在OpenGL ES中绘制的有效方法
You want to create your vertex buffers and upload them to graphics card memory only once using gl.bufferData. Then use reference to that buffer each time you do gl.drawElements or gl.drawArrays. Until the next time the content of your 3D scene changes, you can use this buffer that is uploaded in graphics card memory.
您想创建顶点缓冲区并使用gl.bufferData将它们上传到图形卡内存一次。然后在每次执行gl.drawElements或gl.drawArrays时使用对该缓冲区的引用。在下次3D场景的内容发生变化之前,您可以使用上传到显卡内存中的此缓冲区。
#2
0
Follow the model of UITableView in how they dequeue cells. I would build an object that keeps track of objects you've drawn and links them to an Identifier. Then you can simply dequeue them with said identifier. If you know you're going to draw many versions of the same object, use that object to minimize rendering/allocations.
遵循UITableView的模型,了解它们如何使单元格出列。我会构建一个对象来跟踪你绘制的对象并将它们链接到一个Identifier。然后你可以简单地用所述标识符将它们出列。如果您知道要绘制同一对象的许多版本,请使用该对象最小化渲染/分配。
#3
0
If you're using Vertex Arrays for your glDrawElements(), I'd suggest instead using Vertex Buffer Objects. This will store the data server side (in GRAM) instead of client side (in system RAM). That way you can make glDrawElements() calls with much less CPU<->GPU data transfer overhead.
如果你正在为glDrawElements()使用Vertex Arrays,我建议使用Vertex Buffer Objects。这将存储数据服务器端(在GRAM中)而不是客户端(在系统RAM中)。这样你就可以用更少的CPU < - > GPU数据传输开销来调用glDrawElements()。
Alternatively, you can store you're cubes in display lists. This way you could use glTranlate() to move a cube around and then just call the display list to render it. The only caveat to using display lists is that whatever you do in the display list is immutable; you can't change the calls in the display list without completely recompiling it.
或者,您可以将多维数据集存储在显示列表中。这样你就可以使用glTranlate()来移动一个立方体,然后只需调用显示列表来渲染它。使用显示列表的唯一警告是,无论你在显示列表中做什么都是不可变的;如果不完全重新编译,则无法更改显示列表中的调用。