Quellcode durchsuchen

Remove unsafe pointer methods and make API consistent

Daniel Salvadori vor 6 Jahren
Ursprung
Commit
17e2b2f7ae
9 geänderte Dateien mit 17 neuen und 46 gelöschten Zeilen
  1. 7 7
      geometry/morph.go
  2. 3 21
      gls/gls.go
  3. 1 2
      gui/panel.go
  4. 1 3
      light/directional.go
  5. 1 3
      light/point.go
  6. 1 3
      light/spot.go
  7. 1 3
      material/physical.go
  8. 1 2
      material/standard.go
  9. 1 2
      texture/texture2D.go

+ 7 - 7
geometry/morph.go

@@ -7,17 +7,17 @@ package geometry
 import (
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
-	"strconv"
 	"sort"
+	"strconv"
 )
 
 // MorphGeometry represents a base geometry and its morph targets.
 type MorphGeometry struct {
-	baseGeometry  *Geometry   // The base geometry
-	targets       []*Geometry // The morph target geometries (containing deltas)
-	weights       []float32   // The weights for each morph target
-	uniWeights    gls.Uniform // Texture unit uniform location cache
-	morphGeom     *Geometry   // Cache of the last CPU-morphed geometry
+	baseGeometry *Geometry   // The base geometry
+	targets      []*Geometry // The morph target geometries (containing deltas)
+	weights      []float32   // The weights for each morph target
+	uniWeights   gls.Uniform // Texture unit uniform location cache
+	morphGeom    *Geometry   // Cache of the last CPU-morphed geometry
 }
 
 // MaxActiveMorphTargets is the maximum number of active morph targets.
@@ -207,5 +207,5 @@ func (mg *MorphGeometry) RenderSetup(gs *gls.GLS) {
 
 	// Transfer active weights uniform
 	location := mg.uniWeights.Location(gs)
-	gs.Uniform1fv(location, int32(len(activeWeights)), activeWeights)
+	gs.Uniform1fv(location, int32(len(activeWeights)), &activeWeights[0])
 }

+ 3 - 21
gls/gls.go

@@ -664,9 +664,9 @@ func (gs *GLS) UniformMatrix4fv(location int32, count int32, transpose bool, pm
 }
 
 // Uniform1fv sets the value of one or many float uniform variables for the current program object.
-func (gs *GLS) Uniform1fv(location int32, count int32, v []float32) {
+func (gs *GLS) Uniform1fv(location int32, count int32, v *float32) {
 
-	C.glUniform1fv(C.GLint(location), C.GLsizei(count), (*C.GLfloat)(&v[0]))
+	C.glUniform1fv(C.GLint(location), C.GLsizei(count), (*C.GLfloat)(v))
 	gs.stats.Unisets++
 }
 
@@ -677,12 +677,6 @@ func (gs *GLS) Uniform2fv(location int32, count int32, v *float32) {
 	gs.stats.Unisets++
 }
 
-func (gs *GLS) Uniform2fvUP(location int32, count int32, v unsafe.Pointer) {
-
-	C.glUniform2fv(C.GLint(location), C.GLsizei(count), (*C.GLfloat)(v))
-	gs.stats.Unisets++
-}
-
 // Uniform3fv sets the value of one or many vec3 uniform variables for the current program object.
 func (gs *GLS) Uniform3fv(location int32, count int32, v *float32) {
 
@@ -690,20 +684,8 @@ func (gs *GLS) Uniform3fv(location int32, count int32, v *float32) {
 	gs.stats.Unisets++
 }
 
-func (gs *GLS) Uniform3fvUP(location int32, count int32, v unsafe.Pointer) {
-
-	C.glUniform3fv(C.GLint(location), C.GLsizei(count), (*C.GLfloat)(v))
-	gs.stats.Unisets++
-}
-
 // Uniform4fv sets the value of one or many vec4 uniform variables for the current program object.
-func (gs *GLS) Uniform4fv(location int32, count int32, v []float32) {
-
-	C.glUniform4fv(C.GLint(location), C.GLsizei(count), (*C.GLfloat)(&v[0]))
-	gs.stats.Unisets++
-}
-
-func (gs *GLS) Uniform4fvUP(location int32, count int32, v unsafe.Pointer) {
+func (gs *GLS) Uniform4fv(location int32, count int32, v *float32) {
 
 	C.glUniform4fv(C.GLint(location), C.GLsizei(count), (*C.GLfloat)(v))
 	gs.stats.Unisets++

+ 1 - 2
gui/panel.go

@@ -6,7 +6,6 @@ package gui
 
 import (
 	"math"
-	"unsafe"
 
 	"github.com/g3n/engine/core"
 	"github.com/g3n/engine/geometry"
@@ -961,7 +960,7 @@ func (p *Panel) RenderSetup(gl *gls.GLS, rinfo *core.RenderInfo) {
 	// Transfer panel parameters combined uniform
 	location = p.uniPanel.Location(gl)
 	const vec4count = 8
-	gl.Uniform4fvUP(location, vec4count, unsafe.Pointer(&p.udata))
+	gl.Uniform4fv(location, vec4count, &p.udata.bounds.X)
 }
 
 // SetModelMatrix calculates and sets the specified matrix with the model matrix for this panel

+ 1 - 3
light/directional.go

@@ -5,8 +5,6 @@
 package light
 
 import (
-	"unsafe"
-
 	"github.com/g3n/engine/core"
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
@@ -81,5 +79,5 @@ func (ld *Directional) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int)
 	// Transfer uniform data
 	const vec3count = 2
 	location := ld.uni.LocationIdx(gs, vec3count*int32(idx))
-	gs.Uniform3fvUP(location, vec3count, unsafe.Pointer(&ld.udata))
+	gs.Uniform3fv(location, vec3count, &ld.udata.color.R)
 }

+ 1 - 3
light/point.go

@@ -5,8 +5,6 @@
 package light
 
 import (
-	"unsafe"
-
 	"github.com/g3n/engine/core"
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
@@ -111,5 +109,5 @@ func (lp *Point) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int) {
 	// Transfer uniform data
 	const vec3count = 3
 	location := lp.uni.LocationIdx(gs, vec3count*int32(idx))
-	gs.Uniform3fvUP(location, vec3count, unsafe.Pointer(&lp.udata))
+	gs.Uniform3fv(location, vec3count, &lp.udata.color.R)
 }

+ 1 - 3
light/spot.go

@@ -5,8 +5,6 @@
 package light
 
 import (
-	"unsafe"
-
 	"github.com/g3n/engine/core"
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
@@ -148,5 +146,5 @@ func (l *Spot) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int) {
 	// Transfer uniform data
 	const vec3count = 5
 	location := l.uni.LocationIdx(gs, vec3count*int32(idx))
-	gs.Uniform3fvUP(location, vec3count, unsafe.Pointer(&l.udata))
+	gs.Uniform3fv(location, vec3count, &l.udata.color.R)
 }

+ 1 - 3
material/physical.go

@@ -5,8 +5,6 @@
 package material
 
 import (
-	"unsafe"
-
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
 	"github.com/g3n/engine/texture"
@@ -172,5 +170,5 @@ func (m *Physical) RenderSetup(gl *gls.GLS) {
 
 	m.Material.RenderSetup(gl)
 	location := m.uni.Location(gl)
-	gl.Uniform4fvUP(location, physicalVec4Count, unsafe.Pointer(&m.udata))
+	gl.Uniform4fv(location, physicalVec4Count, &m.udata.baseColorFactor.R)
 }

+ 1 - 2
material/standard.go

@@ -7,7 +7,6 @@ package material
 import (
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
-	"unsafe"
 )
 
 // Standard material supports the classic lighting model with
@@ -114,5 +113,5 @@ func (ms *Standard) RenderSetup(gs *gls.GLS) {
 
 	ms.Material.RenderSetup(gs)
 	location := ms.uni.Location(gs)
-	gs.Uniform3fvUP(location, standardVec3Count, unsafe.Pointer(&ms.udata))
+	gs.Uniform3fv(location, standardVec3Count, &ms.udata.ambient.R)
 }

+ 1 - 2
texture/texture2D.go

@@ -12,7 +12,6 @@ import (
 	_ "image/jpeg"
 	_ "image/png"
 	"os"
-	"unsafe"
 
 	"github.com/g3n/engine/gls"
 )
@@ -359,5 +358,5 @@ func (t *Texture2D) RenderSetup(gs *gls.GLS, slotIdx, uniIdx int) { // Could hav
 	// Transfer texture info combined uniform
 	const vec2count = 3
 	location = t.uniInfo.LocationIdx(gs, vec2count*int32(uniIdx))
-	gs.Uniform2fvUP(location, vec2count, unsafe.Pointer(&t.udata))
+	gs.Uniform2fv(location, vec2count, &t.udata.offsetX)
 }