Daniel Salvadori 7 anni fa
parent
commit
2c905cb480

+ 3 - 3
experimental/physics/debug.go

@@ -33,7 +33,7 @@ func ShowWorldFace(scene *core.Node, face []math32.Vector3, color *math32.Color)
 	vertices.AppendVector3(&face[0])
 
 	geom := geometry.NewGeometry()
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(vertices))
+	geom.AddVBO(gls.NewVBO(vertices).AddAttrib(geometry.VertexPosition, 3))
 
 	mat := material.NewStandard(color)
 	faceGraphic := graphic.NewLineStrip(geom, mat)
@@ -63,7 +63,7 @@ func ShowPenAxis(scene *core.Node, axis *math32.Vector3) {//}, min, max float32)
 	vertices.AppendVector3(maxPoint)
 
 	geom := geometry.NewGeometry()
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(vertices))
+	geom.AddVBO(gls.NewVBO(vertices).AddAttrib(geometry.VertexPosition, 3))
 
 	mat := material.NewStandard(&math32.Color{1,1,1})
 	faceGraphic := graphic.NewLines(geom, mat)
@@ -86,7 +86,7 @@ func ShowContact(scene *core.Node, contact *collision.Contact) {
 	vertices.AppendVector3(otherPoint)
 
 	geom := geometry.NewGeometry()
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(vertices))
+	geom.AddVBO(gls.NewVBO(vertices).AddAttrib(geometry.VertexPosition, 3))
 
 	mat := material.NewStandard(&math32.Color{0,0,1})
 	faceGraphic := graphic.NewLines(geom, mat)

+ 3 - 3
geometry/box.go

@@ -135,9 +135,9 @@ func NewSegmentedBox(width, height, length float32, widthSegments, heightSegment
 	buildPlane("x", "y", -1, -1, box.Width, box.Height, -lHalf, 5) // nz
 
 	box.SetIndices(indices)
-	box.AddVBO(gls.NewVBO().AddAttrib(VertexPosition, 3).SetBuffer(positions))
-	box.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
-	box.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
+	box.AddVBO(gls.NewVBO(positions).AddAttrib(VertexPosition, 3))
+	box.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
+	box.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
 
 	// Update bounding box
 	box.boundingBox.Min = math32.Vector3{-wHalf, -hHalf, -lHalf}

+ 3 - 3
geometry/circle.go

@@ -82,9 +82,9 @@ func NewCircleSector(radius float64, segments int, thetaStart, thetaLength float
 	}
 
 	circ.SetIndices(indices)
-	circ.AddVBO(gls.NewVBO().AddAttrib(VertexPosition, 3).SetBuffer(positions))
-	circ.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
-	circ.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
+	circ.AddVBO(gls.NewVBO(positions).AddAttrib(VertexPosition, 3))
+	circ.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
+	circ.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
 
 	// Update volume
 	circ.volume = 0

+ 107 - 107
geometry/cylinder.go

@@ -44,10 +44,10 @@ func NewCylinder(radiusTop, radiusBottom, height float64,
 
 	heightHalf := height / 2
 	vertices := [][]int{}
-	uvs := [][]math32.Vector2{}
+	uvsOrig := [][]math32.Vector2{}
 
 	// Create buffer for vertex positions
-	Positions := math32.NewArrayF32(0, 0)
+	positions := math32.NewArrayF32(0, 0)
 
 	for y := 0; y <= heightSegments; y++ {
 		var verticesRow = []int{}
@@ -60,30 +60,30 @@ func NewCylinder(radiusTop, radiusBottom, height float64,
 			vertex.X = float32(radius * math.Sin(u*thetaLength+thetaStart))
 			vertex.Y = float32(-v*height + heightHalf)
 			vertex.Z = float32(radius * math.Cos(u*thetaLength+thetaStart))
-			Positions.AppendVector3(&vertex)
-			verticesRow = append(verticesRow, Positions.Size()/3-1)
+			positions.AppendVector3(&vertex)
+			verticesRow = append(verticesRow, positions.Size()/3-1)
 			uvsRow = append(uvsRow, math32.Vector2{float32(u), 1.0 - float32(v)})
 		}
 		vertices = append(vertices, verticesRow)
-		uvs = append(uvs, uvsRow)
+		uvsOrig = append(uvsOrig, uvsRow)
 	}
 
 	tanTheta := (radiusBottom - radiusTop) / height
 	var na, nb math32.Vector3
 
 	// Create preallocated buffers for normals and uvs and buffer for indices
-	npos := Positions.Size()
-	Normals := math32.NewArrayF32(npos, npos)
-	Uvs := math32.NewArrayF32(2*npos/3, 2*npos/3)
-	Indices := math32.NewArrayU32(0, 0)
+	npos := positions.Size()
+	normals := math32.NewArrayF32(npos, npos)
+	uvs := math32.NewArrayF32(2*npos/3, 2*npos/3)
+	indices := math32.NewArrayU32(0, 0)
 
 	for x := 0; x < radialSegments; x++ {
 		if radiusTop != 0 {
-			Positions.GetVector3(3*vertices[0][x], &na)
-			Positions.GetVector3(3*vertices[0][x+1], &nb)
+			positions.GetVector3(3*vertices[0][x], &na)
+			positions.GetVector3(3*vertices[0][x+1], &nb)
 		} else {
-			Positions.GetVector3(3*vertices[1][x], &na)
-			Positions.GetVector3(3*vertices[1][x+1], &nb)
+			positions.GetVector3(3*vertices[1][x], &na)
+			positions.GetVector3(3*vertices[1][x+1], &nb)
 		}
 
 		na.SetY(float32(math.Sqrt(float64(na.X*na.X+na.Z*na.Z)) * tanTheta)).Normalize()
@@ -100,162 +100,162 @@ func NewCylinder(radiusTop, radiusBottom, height float64,
 			n3 := nb
 			n4 := nb
 
-			uv1 := uvs[y][x]
-			uv2 := uvs[y+1][x]
-			uv3 := uvs[y+1][x+1]
-			uv4 := uvs[y][x+1]
-
-			Indices.Append(uint32(v1), uint32(v2), uint32(v4))
-			Normals.SetVector3(3*v1, &n1)
-			Normals.SetVector3(3*v2, &n2)
-			Normals.SetVector3(3*v4, &n4)
-
-			Indices.Append(uint32(v2), uint32(v3), uint32(v4))
-			Normals.SetVector3(3*v2, &n2)
-			Normals.SetVector3(3*v3, &n3)
-			Normals.SetVector3(3*v4, &n4)
-
-			Uvs.SetVector2(2*v1, &uv1)
-			Uvs.SetVector2(2*v2, &uv2)
-			Uvs.SetVector2(2*v3, &uv3)
-			Uvs.SetVector2(2*v4, &uv4)
+			uv1 := uvsOrig[y][x]
+			uv2 := uvsOrig[y+1][x]
+			uv3 := uvsOrig[y+1][x+1]
+			uv4 := uvsOrig[y][x+1]
+
+			indices.Append(uint32(v1), uint32(v2), uint32(v4))
+			normals.SetVector3(3*v1, &n1)
+			normals.SetVector3(3*v2, &n2)
+			normals.SetVector3(3*v4, &n4)
+
+			indices.Append(uint32(v2), uint32(v3), uint32(v4))
+			normals.SetVector3(3*v2, &n2)
+			normals.SetVector3(3*v3, &n3)
+			normals.SetVector3(3*v4, &n4)
+
+			uvs.SetVector2(2*v1, &uv1)
+			uvs.SetVector2(2*v2, &uv2)
+			uvs.SetVector2(2*v3, &uv3)
+			uvs.SetVector2(2*v4, &uv4)
 		}
 	}
 	// First group is the body of the cylinder
 	// without the caps
-	c.AddGroup(0, Indices.Size(), 0)
-	nextGroup := Indices.Size()
+	c.AddGroup(0, indices.Size(), 0)
+	nextGroup := indices.Size()
 
 	// Top cap
 	if top && radiusTop > 0 {
 
-		// Array of vertex indices to build used to build the faces.
-		indices := []uint32{}
-		nextidx := Positions.Size() / 3
+		// Array of vertex indicesOrig to build used to build the faces.
+		indicesOrig := []uint32{}
+		nextidx := positions.Size() / 3
 
-		// Appends top segments vertices and builds array of its indices
+		// Appends top segments vertices and builds array of its indicesOrig
 		var uv1, uv2, uv3 math32.Vector2
 		for x := 0; x < radialSegments; x++ {
-			uv1 = uvs[0][x]
-			uv2 = uvs[0][x+1]
+			uv1 = uvsOrig[0][x]
+			uv2 = uvsOrig[0][x+1]
 			uv3 = math32.Vector2{uv2.X, 0}
 			// Appends CENTER with its own UV.
-			Positions.Append(0, float32(heightHalf), 0)
-			Normals.Append(0, 1, 0)
-			Uvs.AppendVector2(&uv3)
-			indices = append(indices, uint32(nextidx))
+			positions.Append(0, float32(heightHalf), 0)
+			normals.Append(0, 1, 0)
+			uvs.AppendVector2(&uv3)
+			indicesOrig = append(indicesOrig, uint32(nextidx))
 			nextidx++
 			// Appends vertex
 			v := math32.Vector3{}
 			vi := vertices[0][x]
-			Positions.GetVector3(3*vi, &v)
-			Positions.AppendVector3(&v)
-			Normals.Append(0, 1, 0)
-			Uvs.AppendVector2(&uv1)
-			indices = append(indices, uint32(nextidx))
+			positions.GetVector3(3*vi, &v)
+			positions.AppendVector3(&v)
+			normals.Append(0, 1, 0)
+			uvs.AppendVector2(&uv1)
+			indicesOrig = append(indicesOrig, uint32(nextidx))
 			nextidx++
 		}
 		// Appends copy of first vertex (center)
 		var vertex, normal math32.Vector3
 		var uv math32.Vector2
-		Positions.GetVector3(3*int(indices[0]), &vertex)
-		Normals.GetVector3(3*int(indices[0]), &normal)
-		Uvs.GetVector2(2*int(indices[0]), &uv)
-		Positions.AppendVector3(&vertex)
-		Normals.AppendVector3(&normal)
-		Uvs.AppendVector2(&uv)
-		indices = append(indices, uint32(nextidx))
+		positions.GetVector3(3*int(indicesOrig[0]), &vertex)
+		normals.GetVector3(3*int(indicesOrig[0]), &normal)
+		uvs.GetVector2(2*int(indicesOrig[0]), &uv)
+		positions.AppendVector3(&vertex)
+		normals.AppendVector3(&normal)
+		uvs.AppendVector2(&uv)
+		indicesOrig = append(indicesOrig, uint32(nextidx))
 		nextidx++
 
 		// Appends copy of second vertex (v1) USING LAST UV2
-		Positions.GetVector3(3*int(indices[1]), &vertex)
-		Normals.GetVector3(3*int(indices[1]), &normal)
-		Positions.AppendVector3(&vertex)
-		Normals.AppendVector3(&normal)
-		Uvs.AppendVector2(&uv2)
-		indices = append(indices, uint32(nextidx))
+		positions.GetVector3(3*int(indicesOrig[1]), &vertex)
+		normals.GetVector3(3*int(indicesOrig[1]), &normal)
+		positions.AppendVector3(&vertex)
+		normals.AppendVector3(&normal)
+		uvs.AppendVector2(&uv2)
+		indicesOrig = append(indicesOrig, uint32(nextidx))
 		nextidx++
 
-		// Append faces indices
+		// Append faces indicesOrig
 		for x := 0; x < radialSegments; x++ {
 			pos := 2 * x
-			i1 := indices[pos]
-			i2 := indices[pos+1]
-			i3 := indices[pos+3]
-			Indices.Append(uint32(i1), uint32(i2), uint32(i3))
+			i1 := indicesOrig[pos]
+			i2 := indicesOrig[pos+1]
+			i3 := indicesOrig[pos+3]
+			indices.Append(uint32(i1), uint32(i2), uint32(i3))
 		}
 		// Second group is optional top cap of the cylinder
-		c.AddGroup(nextGroup, Indices.Size()-nextGroup, 1)
-		nextGroup = Indices.Size()
+		c.AddGroup(nextGroup, indices.Size()-nextGroup, 1)
+		nextGroup = indices.Size()
 	}
 
 	// Bottom cap
 	if bottom && radiusBottom > 0 {
 
-		// Array of vertex indices to build used to build the faces.
-		indices := []uint32{}
-		nextidx := Positions.Size() / 3
+		// Array of vertex indicesOrig to build used to build the faces.
+		indicesOrig := []uint32{}
+		nextidx := positions.Size() / 3
 
-		// Appends top segments vertices and builds array of its indices
+		// Appends top segments vertices and builds array of its indicesOrig
 		var uv1, uv2, uv3 math32.Vector2
 		for x := 0; x < radialSegments; x++ {
-			uv1 = uvs[heightSegments][x]
-			uv2 = uvs[heightSegments][x+1]
+			uv1 = uvsOrig[heightSegments][x]
+			uv2 = uvsOrig[heightSegments][x+1]
 			uv3 = math32.Vector2{uv2.X, 1}
 			// Appends CENTER with its own UV.
-			Positions.Append(0, float32(-heightHalf), 0)
-			Normals.Append(0, -1, 0)
-			Uvs.AppendVector2(&uv3)
-			indices = append(indices, uint32(nextidx))
+			positions.Append(0, float32(-heightHalf), 0)
+			normals.Append(0, -1, 0)
+			uvs.AppendVector2(&uv3)
+			indicesOrig = append(indicesOrig, uint32(nextidx))
 			nextidx++
 			// Appends vertex
 			v := math32.Vector3{}
 			vi := vertices[heightSegments][x]
-			Positions.GetVector3(3*vi, &v)
-			Positions.AppendVector3(&v)
-			Normals.Append(0, -1, 0)
-			Uvs.AppendVector2(&uv1)
-			indices = append(indices, uint32(nextidx))
+			positions.GetVector3(3*vi, &v)
+			positions.AppendVector3(&v)
+			normals.Append(0, -1, 0)
+			uvs.AppendVector2(&uv1)
+			indicesOrig = append(indicesOrig, uint32(nextidx))
 			nextidx++
 		}
 
 		// Appends copy of first vertex (center)
 		var vertex, normal math32.Vector3
 		var uv math32.Vector2
-		Positions.GetVector3(3*int(indices[0]), &vertex)
-		Normals.GetVector3(3*int(indices[0]), &normal)
-		Uvs.GetVector2(2*int(indices[0]), &uv)
-		Positions.AppendVector3(&vertex)
-		Normals.AppendVector3(&normal)
-		Uvs.AppendVector2(&uv)
-		indices = append(indices, uint32(nextidx))
+		positions.GetVector3(3*int(indicesOrig[0]), &vertex)
+		normals.GetVector3(3*int(indicesOrig[0]), &normal)
+		uvs.GetVector2(2*int(indicesOrig[0]), &uv)
+		positions.AppendVector3(&vertex)
+		normals.AppendVector3(&normal)
+		uvs.AppendVector2(&uv)
+		indicesOrig = append(indicesOrig, uint32(nextidx))
 		nextidx++
 
 		// Appends copy of second vertex (v1) USING LAST UV2
-		Positions.GetVector3(3*int(indices[1]), &vertex)
-		Normals.GetVector3(3*int(indices[1]), &normal)
-		Positions.AppendVector3(&vertex)
-		Normals.AppendVector3(&normal)
-		Uvs.AppendVector2(&uv2)
-		indices = append(indices, uint32(nextidx))
+		positions.GetVector3(3*int(indicesOrig[1]), &vertex)
+		normals.GetVector3(3*int(indicesOrig[1]), &normal)
+		positions.AppendVector3(&vertex)
+		normals.AppendVector3(&normal)
+		uvs.AppendVector2(&uv2)
+		indicesOrig = append(indicesOrig, uint32(nextidx))
 		nextidx++
 
-		// Appends faces indices
+		// Appends faces indicesOrig
 		for x := 0; x < radialSegments; x++ {
 			pos := 2 * x
-			i1 := indices[pos]
-			i2 := indices[pos+3]
-			i3 := indices[pos+1]
-			Indices.Append(uint32(i1), uint32(i2), uint32(i3))
+			i1 := indicesOrig[pos]
+			i2 := indicesOrig[pos+3]
+			i3 := indicesOrig[pos+1]
+			indices.Append(uint32(i1), uint32(i2), uint32(i3))
 		}
 		// Third group is optional bottom cap of the cylinder
-		c.AddGroup(nextGroup, Indices.Size()-nextGroup, 2)
+		c.AddGroup(nextGroup, indices.Size()-nextGroup, 2)
 	}
 
-	c.SetIndices(Indices)
-	c.AddVBO(gls.NewVBO().AddAttrib(VertexPosition, 3).SetBuffer(Positions))
-	c.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(Normals))
-	c.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(Uvs))
+	c.SetIndices(indices)
+	c.AddVBO(gls.NewVBO(positions).AddAttrib(VertexPosition, 3))
+	c.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
+	c.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
 
 	return c
 }

+ 3 - 3
geometry/plane.go

@@ -71,9 +71,9 @@ func NewPlane(width, height float32, widthSegments, heightSegments int) *Plane {
 	}
 
 	plane.SetIndices(indices)
-	plane.AddVBO(gls.NewVBO().AddAttrib(VertexPosition, 3).SetBuffer(positions))
-	plane.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
-	plane.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
+	plane.AddVBO(gls.NewVBO(positions).AddAttrib(VertexPosition, 3))
+	plane.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
+	plane.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
 
 	// Update area
 	plane.area = width*height

+ 3 - 3
geometry/sphere.go

@@ -83,9 +83,9 @@ func NewSphere(radius float64, widthSegments, heightSegments int, phiStart, phiL
 	}
 
 	s.SetIndices(indices)
-	s.AddVBO(gls.NewVBO().AddAttrib(VertexPosition, 3).SetBuffer(positions))
-	s.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
-	s.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
+	s.AddVBO(gls.NewVBO(positions).AddAttrib(VertexPosition, 3))
+	s.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
+	s.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
 
 	r := float32(radius)
 

+ 3 - 3
geometry/torus.go

@@ -69,9 +69,9 @@ func NewTorus(radius, tube float64, radialSegments, tubularSegments int, arc flo
 	}
 
 	t.SetIndices(indices)
-	t.AddVBO(gls.NewVBO().AddAttrib(VertexPosition, 3).SetBuffer(positions))
-	t.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
-	t.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
+	t.AddVBO(gls.NewVBO(positions).AddAttrib(VertexPosition, 3))
+	t.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
+	t.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
 
 	return t
 }

+ 2 - 1
gls/vbo.go

@@ -26,10 +26,11 @@ type VBOattrib struct {
 }
 
 // NewVBO creates and returns a pointer to a new OpenGL Vertex Buffer Object.
-func NewVBO() *VBO {
+func NewVBO(buffer math32.ArrayF32) *VBO {
 
 	vbo := new(VBO)
 	vbo.init()
+	vbo.SetBuffer(buffer)
 	return vbo
 }
 

+ 2 - 2
graphic/axis_helper.go

@@ -36,8 +36,8 @@ func NewAxisHelper(size float32) *AxisHelper {
 		0, 1, 0, 0.6, 1, 0,
 		0, 0, 1, 0, 0.6, 1,
 	)
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexColor, 3).SetBuffer(colors))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(colors).AddAttrib(geometry.VertexColor, 3))
 
 	// Creates line material
 	mat := material.NewBasic()

+ 2 - 3
graphic/grid_helper.go

@@ -36,10 +36,9 @@ func NewGridHelper(size, step float32, color *math32.Color) *GridHelper {
 	// Creates geometry
 	geom := geometry.NewGeometry()
 	geom.AddVBO(
-		gls.NewVBO().
+		gls.NewVBO(positions).
 			AddAttrib(geometry.VertexPosition, 3).
-			AddAttrib(geometry.VertexColor, 3).
-			SetBuffer(positions),
+			AddAttrib(geometry.VertexColor, 3),
 	)
 
 	// Creates material

+ 1 - 1
graphic/normals_helper.go

@@ -41,7 +41,7 @@ func NewNormalsHelper(ig IGraphic, size float32, color *math32.Color, lineWidth
 	// Creates this helper geometry
 	geom := geometry.NewGeometry()
 	positions := math32.NewArrayF32(n, n)
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
 
 	// Creates this helper material
 	mat := material.NewStandard(color)

+ 2 - 3
graphic/sprite.go

@@ -43,10 +43,9 @@ func NewSprite(width, height float32, imat material.IMaterial) *Sprite {
 	// Set geometry buffers
 	geom.SetIndices(indices)
 	geom.AddVBO(
-		gls.NewVBO().
+		gls.NewVBO(positions).
 			AddAttrib(geometry.VertexPosition, 3).
-			AddAttrib(geometry.VertexTexcoord, 2).
-			SetBuffer(positions),
+			AddAttrib(geometry.VertexTexcoord, 2),
 	)
 
 	s.Graphic.Init(geom, gls.TRIANGLES)

+ 3 - 4
gui/chart.go

@@ -476,7 +476,7 @@ func newChartScaleX(chart *Chart, lines int, color *math32.Color) *chartScaleX {
 
 	// Creates geometry and adds VBO
 	geom := geometry.NewGeometry()
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
 
 	// Initializes the panel graphic
 	gr := graphic.NewGraphic(geom, gls.LINES)
@@ -561,7 +561,7 @@ func newChartScaleY(chart *Chart, lines int, color *math32.Color) *chartScaleY {
 
 	// Creates geometry and adds VBO
 	geom := geometry.NewGeometry()
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
 
 	// Initializes the panel with this graphic
 	gr := graphic.NewGraphic(geom, gls.LINES)
@@ -629,9 +629,8 @@ func newGraph(chart *Chart, color *math32.Color, data []float32) *Graph {
 
 	// Creates geometry and adds VBO with positions
 	geom := geometry.NewGeometry()
-	lg.vbo = gls.NewVBO().AddAttrib(geometry.VertexPosition, 3)
 	lg.positions = math32.NewArrayF32(0, 0)
-	lg.vbo.SetBuffer(lg.positions)
+	lg.vbo = gls.NewVBO(lg.positions).AddAttrib(geometry.VertexPosition, 3)
 	geom.AddVBO(lg.vbo)
 
 	// Initializes the panel with this graphic

+ 2 - 3
gui/panel.go

@@ -152,10 +152,9 @@ func (p *Panel) Initialize(width, height float32) {
 		// Creates geometry
 		geom := geometry.NewGeometry()
 		geom.SetIndices(indices)
-		geom.AddVBO(gls.NewVBO().
+		geom.AddVBO(gls.NewVBO(positions).
 			AddAttrib(geometry.VertexPosition, 3).
-			AddAttrib(geometry.VertexTexcoord, 2).
-			SetBuffer(positions),
+			AddAttrib(geometry.VertexTexcoord, 2),
 		)
 		panelQuadGeometry = geom
 	}

+ 5 - 5
loader/collada/geometry.go

@@ -285,16 +285,16 @@ func newMeshPolylist(m *Mesh, pels []interface{}) (*geometry.Geometry, uint32, e
 	geom := geometry.NewGeometry()
 
 	// Creates VBO with vertex positions
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
 
 	// Creates VBO with vertex normals
 	if normals.Size() > 0 {
-		geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexNormal, 3).SetBuffer(normals))
+		geom.AddVBO(gls.NewVBO(normals).AddAttrib(geometry.VertexNormal, 3))
 	}
 
 	// Creates VBO with uv coordinates
 	if uvs.Size() > 0 {
-		geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexTexcoord, 2).SetBuffer(uvs))
+		geom.AddVBO(gls.NewVBO(uvs).AddAttrib(geometry.VertexTexcoord, 2))
 	}
 
 	// Sets the geometry indices buffer
@@ -383,7 +383,7 @@ func newMeshLines(m *Mesh, ln *Lines) (*geometry.Geometry, uint32, error) {
 	geom := geometry.NewGeometry()
 
 	// Creates VBO with vertex positions
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
 
 	// Sets the geometry indices buffer
 	geom.SetIndices(indices)
@@ -436,7 +436,7 @@ func newMeshPoints(m *Mesh) (*geometry.Geometry, uint32, error) {
 
 	// Creates geometry and add VBO with vertex positions
 	geom := geometry.NewGeometry()
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
 	return geom, gls.POINTS, nil
 }
 

+ 3 - 3
loader/obj/obj.go

@@ -259,9 +259,9 @@ func (dec *Decoder) NewGeometry(obj *Object) (*geometry.Geometry, error) {
 	}
 
 	geom.SetIndices(indices)
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexNormal, 3).SetBuffer(normals))
-	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexTexcoord, 2).SetBuffer(uvs))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(normals).AddAttrib(geometry.VertexNormal, 3))
+	geom.AddVBO(gls.NewVBO(uvs).AddAttrib(geometry.VertexTexcoord, 2))
 
 	return geom, nil
 }