Explorar el Código

improved vbo API

Daniel Salvadori hace 7 años
padre
commit
a188143bdf

+ 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(vertices).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(vertices).AddAttrib(gls.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(vertices).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(vertices).AddAttrib(gls.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(vertices).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(vertices).AddAttrib(gls.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(positions).AddAttrib(VertexPosition, 3))
-	box.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
-	box.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
+	box.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
+	box.AddVBO(gls.NewVBO(normals).AddAttrib(gls.VertexNormal, 3))
+	box.AddVBO(gls.NewVBO(uvs).AddAttrib(gls.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(positions).AddAttrib(VertexPosition, 3))
-	circ.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
-	circ.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
+	circ.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
+	circ.AddVBO(gls.NewVBO(normals).AddAttrib(gls.VertexNormal, 3))
+	circ.AddVBO(gls.NewVBO(uvs).AddAttrib(gls.VertexTexcoord, 2))
 
 	// 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(positions).AddAttrib(VertexPosition, 3))
-	c.AddVBO(gls.NewVBO(normals).AddAttrib(VertexNormal, 3))
-	c.AddVBO(gls.NewVBO(uvs).AddAttrib(VertexTexcoord, 2))
+	c.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
+	c.AddVBO(gls.NewVBO(normals).AddAttrib(gls.VertexNormal, 3))
+	c.AddVBO(gls.NewVBO(uvs).AddAttrib(gls.VertexTexcoord, 2))
 
 	return c
 }

+ 41 - 64
geometry/geometry.go

@@ -18,19 +18,15 @@ type IGeometry interface {
 
 // Geometry encapsulates a three-dimensional vertex-based geometry.
 type Geometry struct {
-	refcount      int             // Current number of references
-	vbos          []*gls.VBO      // Array of VBOs
-	groups        []Group         // Array geometry groups
-	indices       math32.ArrayU32 // Buffer with indices
-	gs            *gls.GLS        // Pointer to gl context. Valid after first render setup
-	handleVAO     uint32          // Handle to OpenGL VAO
-	handleIndices uint32          // Handle to OpenGL buffer for indices
-	updateIndices bool            // Flag to indicate that indices must be transferred
-
-	// Map from attribute type to actual vbo attribute name
-	// Allows the user to use arbitrary attribute names while
-	// maintaining functionality of methods such as "ReadVertices"
-	attribNameMap map[attribType]string
+	refcount      int               // Current number of references
+	vbos          []*gls.VBO        // Array of VBOs
+	groups        []Group           // Array geometry groups
+	indices       math32.ArrayU32   // Buffer with indices
+	gs            *gls.GLS          // Pointer to gl context. Valid after first render setup
+	ShaderDefines gls.ShaderDefines // Geometry-specific shader defines
+	handleVAO     uint32            // Handle to OpenGL VAO
+	handleIndices uint32            // Handle to OpenGL buffer for indices
+	updateIndices bool              // Flag to indicate that indices must be transferred
 
 	// Geometric properties
 	boundingBox    math32.Box3    // Last calculated bounding box
@@ -55,24 +51,6 @@ type Group struct {
 	Matid    string // Material id used when loading external models
 }
 
-// attribType is the functional type of an attribute.
-type attribType int
-
-const (
-	vPosition = attribType(iota)
-	vNormal
-	vColor
-	vTexcoord
-)
-
-// The various default attribute names as recognized by shaders.
-const (
-	VertexPosition = "VertexPosition"
-	VertexNormal   = "VertexNormal"
-	VertexColor    = "VertexColor"
-	VertexTexcoord = "VertexTexcoord"
-)
-
 // NewGeometry creates and returns a pointer to a new Geometry.
 func NewGeometry() *Geometry {
 
@@ -91,12 +69,7 @@ func (g *Geometry) Init() {
 	g.handleVAO = 0
 	g.handleIndices = 0
 	g.updateIndices = true
-	g.attribNameMap = map[attribType]string{
-		vPosition: VertexPosition,
-		vNormal:   VertexNormal,
-		vColor:    VertexColor,
-		vTexcoord: VertexTexcoord,
-	}
+	g.ShaderDefines = *gls.NewShaderDefines()
 }
 
 // Incref increments the reference count for this geometry
@@ -110,7 +83,7 @@ func (g *Geometry) Incref() *Geometry {
 }
 
 // Dispose decrements this geometry reference count and
-// if necessary releases OpenGL resources, C memory
+// if possible releases OpenGL resources, C memory
 // and VBOs associated with this geometry.
 func (g *Geometry) Dispose() {
 
@@ -185,8 +158,8 @@ func (g *Geometry) AddVBO(vbo *gls.VBO) {
 	// Check that the provided VBO doesn't have conflicting attributes with existing VBOs
 	for _, existingVbo := range g.vbos {
 		for _, attrib := range vbo.Attributes() {
-			if existingVbo.Attrib(attrib.Name) != nil {
-				panic("Geometry.AddVBO: geometry already has a VBO with attribute " + attrib.Name)
+			if existingVbo.AttribName(attrib.Name) != nil {
+				panic("Geometry.AddVBO: geometry already has a VBO with attribute named:" + attrib.Name)
 			}
 		}
 	}
@@ -196,16 +169,22 @@ func (g *Geometry) AddVBO(vbo *gls.VBO) {
 
 // VBO returns a pointer to this geometry's VBO which contain the specified attribute.
 // Returns nil if the VBO is not found.
-func (g *Geometry) VBO(attrib string) *gls.VBO {
+func (g *Geometry) VBO(atype gls.AttribType) *gls.VBO {
 
 	for _, vbo := range g.vbos {
-		if vbo.Attrib(attrib) != nil {
+		if vbo.Attrib(atype) != nil {
 			return vbo
 		}
 	}
 	return nil
 }
 
+// VBOs returns all of this geometry's VBOs.
+func (g *Geometry) VBOs() []*gls.VBO {
+
+	return g.vbos
+}
+
 // Items returns the number of items in the first VBO.
 // (The number of items should be same for all VBOs)
 // An item is a complete group of attributes in the VBO buffer.
@@ -222,15 +201,18 @@ func (g *Geometry) Items() int {
 }
 
 // SetAttributeName sets the name of the VBO attribute associated with the provided attribute type.
-func (g *Geometry) SetAttributeName(atype attribType, attribName string) {
+func (g *Geometry) SetAttributeName(atype gls.AttribType, attribName string) {
 
-	g.attribNameMap[atype] = attribName
+	vbo := g.VBO(atype)
+	if vbo != nil {
+		vbo.Attrib(atype).Name = attribName
+	}
 }
 
 // AttributeName returns the name of the VBO attribute associated with the provided attribute type.
-func (g *Geometry) AttributeName(atype attribType) string {
+func (g *Geometry) AttributeName(atype gls.AttribType) string {
 
-	return g.attribNameMap[atype]
+	return g.VBO(atype).Attrib(atype).Name
 }
 
 // OperateOnVertices iterates over all the vertices and calls
@@ -241,12 +223,11 @@ func (g *Geometry) AttributeName(atype attribType) string {
 func (g *Geometry) OperateOnVertices(cb func(vertex *math32.Vector3) bool) {
 
 	// Get buffer with position vertices
-	posAttribName := g.attribNameMap[vPosition]
-	vbo := g.VBO(posAttribName)
+	vbo := g.VBO(gls.VertexPosition)
 	if vbo == nil {
 		return
 	}
-	vbo.OperateOnVectors3(posAttribName, cb)
+	vbo.OperateOnVectors3(gls.VertexPosition, cb)
 }
 
 // ReadVertices iterates over all the vertices and calls
@@ -255,12 +236,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
-	posAttribName := g.attribNameMap[vPosition]
-	vbo := g.VBO(posAttribName)
+	vbo := g.VBO(gls.VertexPosition)
 	if vbo == nil {
 		return
 	}
-	vbo.ReadVectors3(posAttribName, cb)
+	vbo.ReadVectors3(gls.VertexPosition, cb)
 }
 
 // OperateOnVertexNormals iterates over all the vertex normals
@@ -271,12 +251,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
-	normAttribName := g.attribNameMap[vNormal]
-	vbo := g.VBO(normAttribName)
+	vbo := g.VBO(gls.VertexNormal)
 	if vbo == nil {
 		return
 	}
-	vbo.OperateOnVectors3(normAttribName, cb)
+	vbo.OperateOnVectors3(gls.VertexNormal, cb)
 }
 
 // ReadVertexNormals iterates over all the vertex normals and calls
@@ -285,12 +264,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
-	normAttribName := g.attribNameMap[vNormal]
-	vbo := g.VBO(normAttribName)
+	vbo := g.VBO(gls.VertexNormal)
 	if vbo == nil {
 		return
 	}
-	vbo.ReadVectors3(normAttribName, cb)
+	vbo.ReadVectors3(gls.VertexNormal, cb)
 }
 
 // ReadFaces iterates over all the vertices and calls
@@ -299,8 +277,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
-	posAttribName := g.attribNameMap[vPosition]
-	vbo := g.VBO(posAttribName)
+	vbo := g.VBO(gls.VertexPosition)
 	if vbo == nil {
 		return
 	}
@@ -322,7 +299,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(posAttribName, cb)
+		vbo.ReadTripleVectors3(gls.VertexPosition, cb)
 	}
 }
 
@@ -510,12 +487,12 @@ func (g *Geometry) RenderSetup(gs *gls.GLS) {
 
 	// First time initialization
 	if g.gs == nil {
-		// Generates VAO and binds it
+		// Generate VAO and binds it
 		g.handleVAO = gs.GenVertexArray()
 		gs.BindVertexArray(g.handleVAO)
-		// Generates VBO for indices
+		// Generate VBO for indices
 		g.handleIndices = gs.GenBuffer()
-		// Saves pointer to gl indicating initialization was done.
+		// Saves pointer to gs indicating initialization was done.
 		g.gs = gs
 	}
 

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

+ 76 - 17
gls/vbo.go

@@ -21,8 +21,28 @@ type VBO struct {
 
 // VBOattrib describes one attribute of an OpenGL Vertex Buffer Object.
 type VBOattrib struct {
-	Name     string // Name of of the attribute
-	ItemSize int32  // Number of elements
+	Type     AttribType // Type of the attribute
+	Name     string     // Name of the attribute
+	ItemSize int32      // Number of elements
+}
+
+// AttribType is the functional type of a vbo attribute.
+type AttribType int
+
+const (
+	Undefined = AttribType(iota)
+	VertexPosition
+	VertexNormal
+	VertexColor
+	VertexTexcoord
+)
+
+// Map from attribute type to default attribute name.
+var attribTypeMap = map[AttribType]string{
+	VertexPosition: "VertexPosition",
+	VertexNormal:   "VertexNormal",
+	VertexColor:    "VertexColor",
+	VertexTexcoord: "VertexTexcoord",
 }
 
 // NewVBO creates and returns a pointer to a new OpenGL Vertex Buffer Object.
@@ -44,23 +64,47 @@ func (vbo *VBO) init() {
 	vbo.attribs = make([]VBOattrib, 0)
 }
 
-// AddAttrib adds a new attribute to the VBO.
-func (vbo *VBO) AddAttrib(name string, itemSize int32) *VBO {
+// AddAttrib adds a new attribute to the VBO by attribute type.
+func (vbo *VBO) AddAttrib(atype AttribType, itemSize int32) *VBO {
+
+	vbo.attribs = append(vbo.attribs, VBOattrib{
+		Type:     atype,
+		Name:     attribTypeMap[atype],
+		ItemSize: itemSize,
+	})
+	return vbo
+}
+
+// AddAttribName adds a new attribute to the VBO by name.
+func (vbo *VBO) AddAttribName(name string, itemSize int32) *VBO {
 
 	vbo.attribs = append(vbo.attribs, VBOattrib{
+		Type:     Undefined,
 		Name:     name,
 		ItemSize: itemSize,
 	})
 	return vbo
 }
 
-// Attrib finds and returns a pointer to the VBO attribute with the specified name.
+// Attrib finds and returns a pointer to the VBO attribute with the specified type.
 // Returns nil if not found.
-func (vbo *VBO) Attrib(name string) *VBOattrib {
+func (vbo *VBO) Attrib(atype AttribType) *VBOattrib {
 
-	for _, attr := range vbo.attribs {
-		if attr.Name == name {
-			return &attr
+	for i := range vbo.attribs {
+		if vbo.attribs[i].Type == atype {
+			return &vbo.attribs[i]
+		}
+	}
+	return nil
+}
+
+// AttribName finds and returns a pointer to the VBO attribute with the specified name.
+// Returns nil if not found.
+func (vbo *VBO) AttribName(name string) *VBOattrib {
+
+	for i := range vbo.attribs {
+		if vbo.attribs[i].Name == name {
+			return &vbo.attribs[i]
 		}
 	}
 	return nil
@@ -123,8 +167,22 @@ func (vbo *VBO) Update() {
 }
 
 // AttribOffset returns the total number of elements from
-// all attributes preceding the specified attribute.
-func (vbo *VBO) AttribOffset(name string) int {
+// all attributes preceding the attribute specified by type.
+func (vbo *VBO) AttribOffset(attribType AttribType) int {
+
+	elementCount := 0
+	for _, attr := range vbo.attribs {
+		if attr.Type == attribType {
+			return elementCount
+		}
+		elementCount += int(attr.ItemSize)
+	}
+	return elementCount
+}
+
+// AttribOffsetName returns the total number of elements from
+// all attributes preceding the attribute specified by name.
+func (vbo *VBO) AttribOffsetName(name string) int {
 
 	elementCount := 0
 	for _, attr := range vbo.attribs {
@@ -183,6 +241,7 @@ func (vbo *VBO) Transfer(gs *GLS) {
 			// Get attribute location in the current program
 			loc := gs.prog.GetAttribLocation(attrib.Name)
 			if loc < 0 {
+				log.Warn("Attribute not found: %v", attrib.Name)
 				continue
 			}
 			// Enables attribute and sets its stride and offset in the buffer
@@ -209,10 +268,10 @@ func (vbo *VBO) Transfer(gs *GLS) {
 // and calls the specified callback function with a pointer to each item as a Vector3.
 // The vector pointers can be modified inside the callback and the modifications will be applied to the buffer at each iteration.
 // The callback function returns false to continue or true to break.
-func (vbo *VBO) OperateOnVectors3(vboAttrib string, cb func(vec *math32.Vector3) bool) {
+func (vbo *VBO) OperateOnVectors3(attribType AttribType, cb func(vec *math32.Vector3) bool) {
 
 	stride := vbo.Stride()
-	offset := vbo.AttribOffset(vboAttrib)
+	offset := vbo.AttribOffset(attribType)
 	buffer := vbo.Buffer()
 
 	// Call callback for each vector3, updating the buffer afterward
@@ -231,10 +290,10 @@ func (vbo *VBO) OperateOnVectors3(vboAttrib string, cb func(vec *math32.Vector3)
 // ReadVectors3 iterates over all 3-float32 items for the specified attribute
 // and calls the specified callback function with the value of each item as a Vector3.
 // The callback function returns false to continue or true to break.
-func (vbo *VBO) ReadVectors3(vboAttrib string, cb func(vec math32.Vector3) bool) {
+func (vbo *VBO) ReadVectors3(attribType AttribType, cb func(vec math32.Vector3) bool) {
 
 	stride := vbo.Stride()
-	offset := vbo.AttribOffset(vboAttrib)
+	offset := vbo.AttribOffset(attribType)
 	positions := vbo.Buffer()
 
 	// Call callback for each vector3
@@ -252,10 +311,10 @@ func (vbo *VBO) ReadVectors3(vboAttrib string, cb func(vec math32.Vector3) bool)
 // Read3Vectors3 iterates over all 3-float32 items (3 items at a time) for the specified attribute
 // and calls the specified callback function with the value of each of the 3 items as Vector3.
 // The callback function returns false to continue or true to break.
-func (vbo *VBO) ReadTripleVectors3(vboAttrib string, cb func(vec1, vec2, vec3 math32.Vector3) bool) {
+func (vbo *VBO) ReadTripleVectors3(attribType AttribType, cb func(vec1, vec2, vec3 math32.Vector3) bool) {
 
 	stride := vbo.Stride()
-	offset := vbo.AttribOffset(vboAttrib)
+	offset := vbo.AttribOffset(attribType)
 	positions := vbo.Buffer()
 
 	doubleStride := 2*stride

+ 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(positions).AddAttrib(geometry.VertexPosition, 3))
-	geom.AddVBO(gls.NewVBO(colors).AddAttrib(geometry.VertexColor, 3))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(colors).AddAttrib(gls.VertexColor, 3))
 
 	// 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(positions).
-			AddAttrib(geometry.VertexPosition, 3).
-			AddAttrib(geometry.VertexColor, 3),
+			AddAttrib(gls.VertexPosition, 3).
+			AddAttrib(gls.VertexColor, 3),
 	)
 
 	// Creates material

+ 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(geometry.VertexPosition)
+	vboPos := geom.VBO(gls.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(geometry.VertexPosition)
+	vertices := nh.targetGeometry.VBO(gls.VertexPosition)
 	n := vertices.Buffer().Size() * 2
 
 	// Creates this helper geometry
 	geom := geometry.NewGeometry()
 	positions := math32.NewArrayF32(n, n)
-	geom.AddVBO(gls.NewVBO(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
 
 	// 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(geometry.VertexPosition)
+	tPosVBO := nh.targetGeometry.VBO(gls.VertexPosition)
 	tPositions := tPosVBO.Buffer()
-	tNormVBO := nh.targetGeometry.VBO(geometry.VertexNormal)
+	tNormVBO := nh.targetGeometry.VBO(gls.VertexNormal)
 	tNormals := tNormVBO.Buffer()
 
 	// Get this object positions buffer
 	geom := nh.GetGeometry()
-	posVBO := geom.VBO(geometry.VertexPosition)
+	posVBO := geom.VBO(gls.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(positions).
-			AddAttrib(geometry.VertexPosition, 3).
-			AddAttrib(geometry.VertexTexcoord, 2),
+			AddAttrib(gls.VertexPosition, 3).
+			AddAttrib(gls.VertexTexcoord, 2),
 	)
 
 	s.Graphic.Init(geom, gls.TRIANGLES)
@@ -113,7 +113,7 @@ func (s *Sprite) Raycast(rc *core.Raycaster, intersects *[]core.Intersect) {
 
 	// Get buffer with vertices and uvs
 	geom := s.GetGeometry()
-	vboPos := geom.VBO(geometry.VertexPosition)
+	vboPos := geom.VBO(gls.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(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.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(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
 
 	// Initializes the panel with this graphic
 	gr := graphic.NewGraphic(geom, gls.LINES)
@@ -630,7 +630,7 @@ func newGraph(chart *Chart, color *math32.Color, data []float32) *Graph {
 	// Creates geometry and adds VBO with positions
 	geom := geometry.NewGeometry()
 	lg.positions = math32.NewArrayF32(0, 0)
-	lg.vbo = gls.NewVBO(lg.positions).AddAttrib(geometry.VertexPosition, 3)
+	lg.vbo = gls.NewVBO(lg.positions).AddAttrib(gls.VertexPosition, 3)
 	geom.AddVBO(lg.vbo)
 
 	// Initializes the panel with this graphic

+ 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(positions).
-			AddAttrib(geometry.VertexPosition, 3).
-			AddAttrib(geometry.VertexTexcoord, 2),
+			AddAttrib(gls.VertexPosition, 3).
+			AddAttrib(gls.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(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
 
 	// Creates VBO with vertex normals
 	if normals.Size() > 0 {
-		geom.AddVBO(gls.NewVBO(normals).AddAttrib(geometry.VertexNormal, 3))
+		geom.AddVBO(gls.NewVBO(normals).AddAttrib(gls.VertexNormal, 3))
 	}
 
 	// Creates VBO with uv coordinates
 	if uvs.Size() > 0 {
-		geom.AddVBO(gls.NewVBO(uvs).AddAttrib(geometry.VertexTexcoord, 2))
+		geom.AddVBO(gls.NewVBO(uvs).AddAttrib(gls.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(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.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(positions).AddAttrib(geometry.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.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(positions).AddAttrib(geometry.VertexPosition, 3))
-	geom.AddVBO(gls.NewVBO(normals).AddAttrib(geometry.VertexNormal, 3))
-	geom.AddVBO(gls.NewVBO(uvs).AddAttrib(geometry.VertexTexcoord, 2))
+	geom.AddVBO(gls.NewVBO(positions).AddAttrib(gls.VertexPosition, 3))
+	geom.AddVBO(gls.NewVBO(normals).AddAttrib(gls.VertexNormal, 3))
+	geom.AddVBO(gls.NewVBO(uvs).AddAttrib(gls.VertexTexcoord, 2))
 
 	return geom, nil
 }