所以我有一个粒子游戏,目标是尽可能多。我在OpenGL-es 2.0工作。每个粒子用2个点和一个矩形表示,这导致6个顶点'每粒子。
我一直在使用传统的单独缓冲区方法遇到性能问题,所以我现在尝试一些新的东西,比如用数组绘图。
以下是我如何生成缓冲区:它们基本上是
Circle(Xyzhsvas)(s的大小让我可以成为一个漂亮的点)
//Array size is preallocated at beginning
func buildArrays()
{
var circlePos:Int = 0
var rectPos:Int = 0
var indcPos:Int = 0
for obj in particles
{
let pos:Point = obj.position
let lpos:Point = obj.lastPosition
let color:ColorHSV = obj.color
let width:GLfloat = obj.width
let rect = Math.makeRectangle(pos, p2: lpos, w: width)
circles[circlePos] = pos.x
circles[circlePos + 1] = pos.y
circles[circlePos + 2] = 0.0
circles[circlePos + 3] = color.h
circles[circlePos + 4] = color.s
circles[circlePos + 5] = color.v
circles[circlePos + 6] = color.a
circles[circlePos + 7] = width
circles[circlePos + 8] = lpos.x
circles[circlePos + 9] = lpos.y
circles[circlePos + 10] = 0.0
circles[circlePos + 11] = color.h
circles[circlePos + 12] = color.s
circles[circlePos + 13] = color.v
circles[circlePos + 14] = color.a
circles[circlePos + 15] = width
circlePos += 16
squares[rectPos] = rect.0.x
squares[rectPos + 1] = rect.0.y
squares[rectPos + 2] = 0.0
squares[rectPos + 3] = color.h
squares[rectPos + 4] = color.s
squares[rectPos + 5] = color.v
squares[rectPos + 6] = color.a
squares[rectPos + 7] = rect.1.x
squares[rectPos + 8] = rect.1.y
squares[rectPos + 9] = 0.0
squares[rectPos + 10] = color.h
squares[rectPos + 11] = color.s
squares[rectPos + 12] = color.v
squares[rectPos + 13] = color.a
squares[rectPos + 14] = rect.2.x
squares[rectPos + 15] = rect.2.y
squares[rectPos + 16] = 0.0
squares[rectPos + 17] = color.h
squares[rectPos + 18] = color.s
squares[rectPos + 19] = color.v
squares[rectPos + 20] = color.a
squares[rectPos + 21] = rect.3.x
squares[rectPos + 22] = rect.3.y
squares[rectPos + 23] = 0.0
squares[rectPos + 24] = color.h
squares[rectPos + 25] = color.s
squares[rectPos + 26] = color.v
squares[rectPos + 27] = color.a
rectPos += 28
indices[indcPos] = 3
indices[indcPos + 1] = 4
indices[indcPos + 2] = 2
indices[indcPos + 3] = 3
indices[indcPos + 4] = 2
indices[indcPos + 5] = 4
indcPos += 6
}
}
我一直在研究这个问题,关于元素是4的幂,以及如何使用带三角条的指数,但仍然绘制单独的三角形。
上次我做缓冲时,每个部分都有一个单独的缓冲区,但这次我想做得更好。我知道如何将这些数据放入缓冲区对象
let sDraw = GLenum(GL_STATIC_DRAW)
let sType = GLenum(GL_ARRAY_BUFFER)
glGenBuffers(1, &buffer_point)
glBindBuffer(sType, buffer_point)
glBufferData(sType, circles.count * sizeof(GLfloat), circles, sDraw)
但是我不知道如何处理这个对象,如何告诉OpenGL所有独立组件的工作原理。当顶点数据有颜色混合
时,我也不知道如何使索引工作我也不理解有人提出的声明你可以通过索引以某种方式绘制单独的矩形来获得三角形条带。
而且我不明白OpenGL应该如何分离每个数据以将它们带到我的着色器。
此外,我不了解整个4组件数据,或者为什么苹果声称我应该在每个新顶点之前添加随机填充(我甚至不知道如何添加两个字节的空间)
如果有人能帮助我理解,并解决这个问题,那将是值得赞赏的!任何优化建议都表示赞赏。