Browse Source

Adapt to WASM version

Daniel Salvadori 6 years ago
parent
commit
95d9fbac66
2 changed files with 11 additions and 5 deletions
  1. 5 5
      gls/vbo.go
  2. 6 0
      math32/array.go

+ 5 - 5
gls/vbo.go

@@ -320,7 +320,7 @@ func (vbo *VBO) Transfer(gs *GLS) {
 
 	// Transfer the VBO data to OpenGL
 	gs.BindBuffer(ARRAY_BUFFER, vbo.handle)
-	gs.BufferData(ARRAY_BUFFER, vbo.buffer.Bytes(), &vbo.buffer[0], vbo.usage)
+	gs.BufferData(ARRAY_BUFFER, vbo.buffer.Bytes(), vbo.buffer.ToFloat32(), vbo.usage)
 	vbo.update = false
 }
 
@@ -376,15 +376,15 @@ func (vbo *VBO) ReadTripleVectors3(attribType AttribType, cb func(vec1, vec2, ve
 	offset := vbo.AttribOffset(attribType)
 	positions := vbo.Buffer()
 
-	doubleStride := 2*stride
-	loopStride := 3*stride
+	doubleStride := 2 * stride
+	loopStride := 3 * stride
 
 	// Call callback for each vector3 triple
 	var vec1, vec2, vec3 math32.Vector3
 	for i := offset; i < positions.Size(); i += loopStride {
 		positions.GetVector3(i, &vec1)
-		positions.GetVector3(i + stride, &vec2)
-		positions.GetVector3(i + doubleStride, &vec3)
+		positions.GetVector3(i+stride, &vec2)
+		positions.GetVector3(i+doubleStride, &vec3)
 		brk := cb(vec1, vec2, vec3)
 		if brk {
 			break

+ 6 - 0
math32/array.go

@@ -206,6 +206,12 @@ func (a ArrayF32) SetColor4(pos int, v *Color4) {
 	a[pos+3] = v.A
 }
 
+// ToFloat32 converts this array to an array of float32
+func (a ArrayF32) ToFloat32() []float32 {
+
+	return (*[1 << 27]float32)(unsafe.Pointer(&a[0]))[:len(a)]
+}
+
 // ArrayU32 is a slice of uint32 with additional convenience methods
 type ArrayU32 []uint32