Pregunta

Me gustaría hacer un juego de muchos cubos y estoy pensando en poner en plataformas móviles, y también en la web utilizando WebGL. Mi problema es cuando hago una llamada drawElements por cubo tomo un golpe en la velocidad de fotogramas. ¿Hay alguna manera de hacer una sola llamada sorteo para OpenGL ES para atraerlos? La única diferencia entre los cubos sería la posición y el color.

¿Fue útil?

Solución

Me encontré con el mismo problema a mí mismo. Pregunté pregunta similar y respondí yo mismo ayer. Echar un vistazo a:

forma eficiente de dibujo en OpenGL ES

¿Quieres crear tu buffers de vértices y cargarlas en memoria de tarjeta gráfica solamente una vez usando gl.bufferData. A continuación, utilice referencia a ese búfer cada vez que lo haga gl.drawElements o gl.drawArrays. Hasta la próxima vez que el contenido de sus cambios de escena 3D, puede utilizar esta memoria intermedia que se carga en la memoria de la tarjeta gráfica.

Otros consejos

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.

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.

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top