Просмотр исходного кода

made constants for VBO attributes

Daniel Salvadori 7 лет назад
Родитель
Сommit
b350a760ac

+ 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("VertexPosition", 3).SetBuffer(vertices))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(vertices))
 
 	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("VertexPosition", 3).SetBuffer(vertices))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(vertices))
 
 	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("VertexPosition", 3).SetBuffer(vertices))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(vertices))
 
 	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().AddAttrib(VertexPosition, 3).SetBuffer(positions))
+	box.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
+	box.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
 
 	// 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().AddAttrib(VertexPosition, 3).SetBuffer(positions))
+	circ.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
+	circ.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
 
 	// Update volume
 	circ.volume = 0

+ 3 - 3
geometry/cylinder.go

@@ -253,9 +253,9 @@ func NewCylinder(radiusTop, radiusBottom, height float64,
 	}
 
 	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.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))
 
 	return c
 }

+ 17 - 10
geometry/geometry.go

@@ -50,6 +50,13 @@ type Group struct {
 	Matid    string // Material id used when loading external models
 }
 
+const (
+	VertexPosition = "VertexPosition"
+	VertexNormal = "VertexNormal"
+	VertexColor = "VertexColor"
+	VertexTexcoord = "VertexTexcoord"
+)
+
 // NewGeometry creates and returns a pointer to a new Geometry.
 func NewGeometry() *Geometry {
 
@@ -200,11 +207,11 @@ func (g *Geometry) Items() int {
 func (g *Geometry) OperateOnVertices(cb func(vertex *math32.Vector3) bool) {
 
 	// Get buffer with position vertices
-	vbo := g.VBO("VertexPosition")
+	vbo := g.VBO(VertexPosition)
 	if vbo == nil {
 		return
 	}
-	vbo.OperateOnVectors3("VertexPosition", cb)
+	vbo.OperateOnVectors3(VertexPosition, cb)
 }
 
 // ReadVertices iterates over all the vertices and calls
@@ -213,11 +220,11 @@ func (g *Geometry) OperateOnVertices(cb func(vertex *math32.Vector3) bool) {
 func (g *Geometry) ReadVertices(cb func(vertex math32.Vector3) bool) {
 
 	// Get buffer with position vertices
-	vbo := g.VBO("VertexPosition")
+	vbo := g.VBO(VertexPosition)
 	if vbo == nil {
 		return
 	}
-	vbo.ReadVectors3("VertexPosition", cb)
+	vbo.ReadVectors3(VertexPosition, cb)
 }
 
 // OperateOnVertexNormals iterates over all the vertex normals
@@ -228,11 +235,11 @@ func (g *Geometry) ReadVertices(cb func(vertex math32.Vector3) bool) {
 func (g *Geometry) OperateOnVertexNormals(cb func(normal *math32.Vector3) bool) {
 
 	// Get buffer with position vertices
-	vbo := g.VBO("VertexNormal")
+	vbo := g.VBO(VertexNormal)
 	if vbo == nil {
 		return
 	}
-	vbo.OperateOnVectors3("VertexNormal", cb)
+	vbo.OperateOnVectors3(VertexNormal, cb)
 }
 
 // ReadVertexNormals iterates over all the vertex normals and calls
@@ -241,11 +248,11 @@ func (g *Geometry) OperateOnVertexNormals(cb func(normal *math32.Vector3) bool)
 func (g *Geometry) ReadVertexNormals(cb func(vertex math32.Vector3) bool) {
 
 	// Get buffer with position vertices
-	vbo := g.VBO("VertexNormal")
+	vbo := g.VBO(VertexNormal)
 	if vbo == nil {
 		return
 	}
-	vbo.ReadVectors3("VertexNormal", cb)
+	vbo.ReadVectors3(VertexNormal, cb)
 }
 
 // ReadFaces iterates over all the vertices and calls
@@ -254,7 +261,7 @@ func (g *Geometry) ReadVertexNormals(cb func(vertex math32.Vector3) bool) {
 func (g *Geometry) ReadFaces(cb func(vA, vB, vC math32.Vector3) bool) {
 
 	// Get buffer with position vertices
-	vbo := g.VBO("VertexPosition")
+	vbo := g.VBO(VertexPosition)
 	if vbo == nil {
 		return
 	}
@@ -276,7 +283,7 @@ func (g *Geometry) ReadFaces(cb func(vA, vB, vC math32.Vector3) bool) {
 		}
 	} else {
 		// Geometry does NOT have indexed vertices - can read vertices in sequence
-		vbo.ReadTripleVectors3("VertexPosition", cb)
+		vbo.ReadTripleVectors3(VertexPosition, cb)
 	}
 }
 

+ 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().AddAttrib(VertexPosition, 3).SetBuffer(positions))
+	plane.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
+	plane.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
 
 	// 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().AddAttrib(VertexPosition, 3).SetBuffer(positions))
+	s.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
+	s.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
 
 	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().AddAttrib(VertexPosition, 3).SetBuffer(positions))
+	t.AddVBO(gls.NewVBO().AddAttrib(VertexNormal, 3).SetBuffer(normals))
+	t.AddVBO(gls.NewVBO().AddAttrib(VertexTexcoord, 2).SetBuffer(uvs))
 
 	return t
 }

+ 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("VertexPosition", 3).SetBuffer(positions))
-	geom.AddVBO(gls.NewVBO().AddAttrib("VertexColor", 3).SetBuffer(colors))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexColor, 3).SetBuffer(colors))
 
 	// Creates line material
 	mat := material.NewBasic()

+ 2 - 2
graphic/grid_helper.go

@@ -37,8 +37,8 @@ func NewGridHelper(size, step float32, color *math32.Color) *GridHelper {
 	geom := geometry.NewGeometry()
 	geom.AddVBO(
 		gls.NewVBO().
-			AddAttrib("VertexPosition", 3).
-			AddAttrib("VertexColor", 3).
+			AddAttrib(geometry.VertexPosition, 3).
+			AddAttrib(geometry.VertexColor, 3).
 			SetBuffer(positions),
 	)
 

+ 1 - 1
graphic/lines.go

@@ -81,7 +81,7 @@ func lineRaycast(igr IGraphic, rc *core.Raycaster, intersects *[]core.Intersect,
 	var interRay math32.Vector3
 
 	// Get geometry positions and indices buffers
-	vboPos := geom.VBO("VertexPosition")
+	vboPos := geom.VBO(geometry.VertexPosition)
 	if vboPos == nil {
 		return
 	}

+ 5 - 5
graphic/normals_helper.go

@@ -35,13 +35,13 @@ func NewNormalsHelper(ig IGraphic, size float32, color *math32.Color, lineWidth
 	nh.targetGeometry = ig.GetGeometry()
 
 	// Get the number of target vertex positions
-	vertices := nh.targetGeometry.VBO("VertexPosition")
+	vertices := nh.targetGeometry.VBO(geometry.VertexPosition)
 	n := vertices.Buffer().Size() * 2
 
 	// Creates this helper geometry
 	geom := geometry.NewGeometry()
 	positions := math32.NewArrayF32(n, n)
-	geom.AddVBO(gls.NewVBO().AddAttrib("VertexPosition", 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
 
 	// Creates this helper material
 	mat := material.NewStandard(color)
@@ -67,14 +67,14 @@ func (nh *NormalsHelper) Update() {
 	normalMatrix.GetNormalMatrix(&matrixWorld)
 
 	// Get the target positions and normals buffers
-	tPosVBO := nh.targetGeometry.VBO("VertexPosition")
+	tPosVBO := nh.targetGeometry.VBO(geometry.VertexPosition)
 	tPositions := tPosVBO.Buffer()
-	tNormVBO := nh.targetGeometry.VBO("VertexNormal")
+	tNormVBO := nh.targetGeometry.VBO(geometry.VertexNormal)
 	tNormals := tNormVBO.Buffer()
 
 	// Get this object positions buffer
 	geom := nh.GetGeometry()
-	posVBO := geom.VBO("VertexPosition")
+	posVBO := geom.VBO(geometry.VertexPosition)
 	positions := posVBO.Buffer()
 
 	// For each target object vertex position:

+ 3 - 3
graphic/sprite.go

@@ -44,8 +44,8 @@ func NewSprite(width, height float32, imat material.IMaterial) *Sprite {
 	geom.SetIndices(indices)
 	geom.AddVBO(
 		gls.NewVBO().
-			AddAttrib("VertexPosition", 3).
-			AddAttrib("VertexTexcoord", 2).
+			AddAttrib(geometry.VertexPosition, 3).
+			AddAttrib(geometry.VertexTexcoord, 2).
 			SetBuffer(positions),
 	)
 
@@ -114,7 +114,7 @@ func (s *Sprite) Raycast(rc *core.Raycaster, intersects *[]core.Intersect) {
 
 	// Get buffer with vertices and uvs
 	geom := s.GetGeometry()
-	vboPos := geom.VBO("VertexPosition")
+	vboPos := geom.VBO(geometry.VertexPosition)
 	if vboPos == nil {
 		panic("sprite.Raycast(): VertexPosition VBO not found")
 	}

+ 3 - 3
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("VertexPosition", 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
 
 	// 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("VertexPosition", 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
 
 	// Initializes the panel with this graphic
 	gr := graphic.NewGraphic(geom, gls.LINES)
@@ -629,7 +629,7 @@ 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("VertexPosition", 3)
+	lg.vbo = gls.NewVBO().AddAttrib(geometry.VertexPosition, 3)
 	lg.positions = math32.NewArrayF32(0, 0)
 	lg.vbo.SetBuffer(lg.positions)
 	geom.AddVBO(lg.vbo)

+ 2 - 2
gui/panel.go

@@ -153,8 +153,8 @@ func (p *Panel) Initialize(width, height float32) {
 		geom := geometry.NewGeometry()
 		geom.SetIndices(indices)
 		geom.AddVBO(gls.NewVBO().
-			AddAttrib("VertexPosition", 3).
-			AddAttrib("VertexTexcoord", 2).
+			AddAttrib(geometry.VertexPosition, 3).
+			AddAttrib(geometry.VertexTexcoord, 2).
 			SetBuffer(positions),
 		)
 		panelQuadGeometry = geom

+ 5 - 13
loader/collada/geometry.go

@@ -285,22 +285,16 @@ func newMeshPolylist(m *Mesh, pels []interface{}) (*geometry.Geometry, uint32, e
 	geom := geometry.NewGeometry()
 
 	// Creates VBO with vertex positions
-	vboPositions := gls.NewVBO()
-	vboPositions.AddAttrib("VertexPosition", 3).SetBuffer(positions)
-	geom.AddVBO(vboPositions)
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
 
 	// Creates VBO with vertex normals
 	if normals.Size() > 0 {
-		vboNormals := gls.NewVBO()
-		vboNormals.AddAttrib("VertexNormal", 3).SetBuffer(normals)
-		geom.AddVBO(vboNormals)
+		geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexNormal, 3).SetBuffer(normals))
 	}
 
 	// Creates VBO with uv coordinates
 	if uvs.Size() > 0 {
-		vboUvs := gls.NewVBO()
-		vboUvs.AddAttrib("VertexTexcoord", 2).SetBuffer(uvs)
-		geom.AddVBO(vboUvs)
+		geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexTexcoord, 2).SetBuffer(uvs))
 	}
 
 	// Sets the geometry indices buffer
@@ -389,9 +383,7 @@ func newMeshLines(m *Mesh, ln *Lines) (*geometry.Geometry, uint32, error) {
 	geom := geometry.NewGeometry()
 
 	// Creates VBO with vertex positions
-	vboPositions := gls.NewVBO()
-	vboPositions.AddAttrib("VertexPosition", 3).SetBuffer(positions)
-	geom.AddVBO(vboPositions)
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
 
 	// Sets the geometry indices buffer
 	geom.SetIndices(indices)
@@ -444,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("VertexPosition", 3).SetBuffer(positions))
+	geom.AddVBO(gls.NewVBO().AddAttrib(geometry.VertexPosition, 3).SetBuffer(positions))
 	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("VertexPosition", 3).SetBuffer(positions))
-	geom.AddVBO(gls.NewVBO().AddAttrib("VertexNormal", 3).SetBuffer(normals))
-	geom.AddVBO(gls.NewVBO().AddAttrib("VertexTexcoord", 2).SetBuffer(uvs))
+	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))
 
 	return geom, nil
 }