Пример #1
0
func (self *MeshBuffer) CopyArraysToVBO() {
	self.AllocBuffers()

	vs := self.CalcVertexSize()
	self.VertexBuffer.Bind(gl.ARRAY_BUFFER)
	gl.BufferData(gl.ARRAY_BUFFER, vs*self.VertexCount,
		self.vertexArray, gl.STATIC_DRAW)
	gl.BufferUnbind(gl.ARRAY_BUFFER)

	self.IndiceBuffer.Bind(gl.ELEMENT_ARRAY_BUFFER)
	gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, 2*self.IndiceCount,
		self.indiceArray, gl.STATIC_DRAW)
	gl.BufferUnbind(gl.ELEMENT_ARRAY_BUFFER)
}
Пример #2
0
func DrawVBO(buffer *MeshBuffer) {
	vertexSize := buffer.CalcVertexSize()

	buffer.VertexBuffer.Bind(gl.ARRAY_BUFFER)
	buffer.IndiceBuffer.Bind(gl.ELEMENT_ARRAY_BUFFER)

	gl.EnableClientState(gl.VERTEX_ARRAY)
	gl.VertexPointerVBO(3, gl.FLOAT, vertexSize, 0)

	if (buffer.Buffers & BUF_NORMAL) != 0 {
		off := buffer.CalcVertexOffset(BUF_NORMAL)
		gl.EnableClientState(gl.NORMAL_ARRAY)
		gl.NormalPointerVBO(gl.FLOAT, vertexSize, off)
	}

	if (buffer.Buffers & BUF_COLOUR) != 0 {
		off := buffer.CalcVertexOffset(BUF_COLOUR)
		gl.EnableClientState(gl.COLOR_ARRAY)
		gl.ColorPointerVBO(4, gl.UNSIGNED_BYTE, vertexSize, off)
	}

	if (buffer.Buffers & BUF_TEX_COORD0) != 0 {
		off := buffer.CalcVertexOffset(BUF_TEX_COORD0)
		gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
		gl.TexCoordPointerVBO(2, gl.FLOAT, vertexSize, off)
	}

	gl.DrawElementsVBO(gl.TRIANGLES, gl.UNSIGNED_SHORT, buffer.IndiceCount)

	if (buffer.Buffers & BUF_NORMAL) != 0 {
		gl.DisableClientState(gl.NORMAL_ARRAY)
	}
	if (buffer.Buffers & BUF_COLOUR) != 0 {
		gl.DisableClientState(gl.COLOR_ARRAY)
	}
	if (buffer.Buffers & BUF_TEX_COORD0) != 0 {
		gl.DisableClientState(gl.TEXTURE_COORD_ARRAY)
	}

	gl.DisableClientState(gl.VERTEX_ARRAY)

	gl.BufferUnbind(gl.ARRAY_BUFFER)
	gl.BufferUnbind(gl.ELEMENT_ARRAY_BUFFER)
}