浏览代码

changing uniform transfers...

leonsal 8 年之前
父节点
当前提交
99daeb5f8e
共有 4 个文件被更改,包括 11 次插入10 次删除
  1. 1 1
      light/ambient.go
  2. 3 5
      light/directional.go
  3. 5 2
      material/point.go
  4. 2 2
      material/standard.go

+ 1 - 1
light/ambient.go

@@ -58,6 +58,6 @@ func (la *Ambient) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int) {
 
 	color := la.color
 	color.MultiplyScalar(la.intensity)
-	location := la.uni.Location(gs)
+	location := la.uni.LocationIdx(gs, int32(idx))
 	gs.Uniform3f(location, color.R, color.G, color.B)
 }

+ 3 - 5
light/directional.go

@@ -23,9 +23,6 @@ type Directional struct {
 	}
 }
 
-// Number of glsl shader vec3 elements used by uniform data
-const udataVec3 = 2
-
 // NewDirectional creates and returns a pointer of a new directional light
 // the specified color and intensity.
 func NewDirectional(color *math32.Color, intensity float32) *Directional {
@@ -82,6 +79,7 @@ func (ld *Directional) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int)
 	ld.udata.position.Z = pos4.Z
 
 	// Transfer uniform data
-	location := ld.uni.LocationIdx(gs, int32(idx))
-	gs.Uniform3fvUP(location, udataVec3, unsafe.Pointer(&ld.udata))
+	const vec3count = 2
+	location := ld.uni.LocationIdx(gs, vec3count*int32(idx))
+	gs.Uniform3fvUP(location, vec3count, unsafe.Pointer(&ld.udata))
 }

+ 5 - 2
material/point.go

@@ -5,6 +5,8 @@
 package material
 
 import (
+	"unsafe"
+
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
 )
@@ -50,6 +52,7 @@ func (pm *Point) SetRotationZ(rot float32) {
 // which uses this material
 func (pm *Point) RenderSetup(gs *gls.GLS) {
 
-	//	pm.Material.RenderSetup(gs)
-	//	pm.uni.Transfer(gs)
+	pm.Material.RenderSetup(gs)
+	location := pm.uni.Location(gs)
+	gs.Uniform3fvUP(location, standardVec3Count, unsafe.Pointer(&pm.udata))
 }

+ 2 - 2
material/standard.go

@@ -29,7 +29,7 @@ type Standard struct {
 }
 
 // Number of glsl shader vec3 elements used by uniform data
-const udataVec3 = 6
+const standardVec3Count = 6
 
 // NewStandard creates and returns a pointer to a new standard material
 func NewStandard(color *math32.Color) *Standard {
@@ -114,5 +114,5 @@ func (ms *Standard) RenderSetup(gs *gls.GLS) {
 
 	ms.Material.RenderSetup(gs)
 	location := ms.uni.Location(gs)
-	gs.Uniform3fvUP(location, udataVec3, unsafe.Pointer(&ms.udata))
+	gs.Uniform3fvUP(location, standardVec3Count, unsafe.Pointer(&ms.udata))
 }