Kaynağa Gözat

changed uniform transfers

leonsal 8 yıl önce
ebeveyn
işleme
635944fa31

+ 4 - 7
gls/uniform.go

@@ -8,7 +8,7 @@ import (
 	"fmt"
 )
 
-type Uniform2 struct {
+type Uniform struct {
 	name      string // base name
 	nameIdx   string // cached indexed name
 	handle    uint32 // program handle
@@ -17,7 +17,7 @@ type Uniform2 struct {
 }
 
 // Init initializes this uniform location cache and sets its name
-func (u *Uniform2) Init(name string) {
+func (u *Uniform) Init(name string) {
 
 	u.name = name
 	u.handle = 0     // invalid program handle
@@ -28,13 +28,12 @@ func (u *Uniform2) Init(name string) {
 // Location returns the location of this uniform for
 // the current shader program
 // The returned location can be -1 if not found
-func (u *Uniform2) Location(gs *GLS) int32 {
+func (u *Uniform) Location(gs *GLS) int32 {
 
 	handle := gs.prog.Handle()
 	if handle != u.handle {
 		u.location = gs.prog.GetUniformLocation(u.name)
 		u.handle = handle
-		//log.Error("Uniform:%s location:%v", u.name, u.location)
 	}
 	return u.location
 }
@@ -42,19 +41,17 @@ func (u *Uniform2) Location(gs *GLS) int32 {
 // LocationIdx returns the location of this indexed uniform for
 // the current shader program
 // The returned location can be -1 if not found
-func (u *Uniform2) LocationIdx(gs *GLS, idx int32) int32 {
+func (u *Uniform) LocationIdx(gs *GLS, idx int32) int32 {
 
 	if idx != u.lastIndex {
 		u.nameIdx = fmt.Sprintf("%s[%d]", u.name, idx)
 		u.lastIndex = idx
 		u.handle = 0
-		//log.Error("Uniform:%s rebuild nameIdx", u.nameIdx)
 	}
 	handle := gs.prog.Handle()
 	if handle != u.handle {
 		u.location = gs.prog.GetUniformLocation(u.nameIdx)
 		u.handle = handle
-		//log.Error("Uniform:%s location:%v", u.nameIdx, u.location)
 	}
 	return u.location
 }

+ 2 - 2
graphic/line_strip.go

@@ -13,8 +13,8 @@ import (
 )
 
 type LineStrip struct {
-	Graphic              // Embedded graphic object
-	uniMVP  gls.Uniform2 // Model view projection matrix uniform location cache
+	Graphic             // Embedded graphic object
+	uniMVP  gls.Uniform // Model view projection matrix uniform location cache
 }
 
 // NewLineStrip creates and returns a pointer to a new LineStrip graphic

+ 2 - 2
graphic/lines.go

@@ -14,8 +14,8 @@ import (
 
 // Lines is a Graphic which is rendered as a collection of independent lines
 type Lines struct {
-	Graphic              // Embedded graphic object
-	uniMVP  gls.Uniform2 // Model view projection matrix uniform location cache
+	Graphic             // Embedded graphic object
+	uniMVP  gls.Uniform // Model view projection matrix uniform location cache
 }
 
 func (l *Lines) Init(igeom geometry.IGeometry, imat material.IMaterial) {

+ 4 - 4
graphic/mesh.go

@@ -13,10 +13,10 @@ import (
 )
 
 type Mesh struct {
-	Graphic              // Embedded graphic
-	uniMVM  gls.Uniform2 // Model view matrix uniform location cache
-	uniMVPM gls.Uniform2 // Model view projection matrix uniform cache
-	uniNM   gls.Uniform2 // Normal matrix uniform cache
+	Graphic             // Embedded graphic
+	uniMVM  gls.Uniform // Model view matrix uniform location cache
+	uniMVPM gls.Uniform // Model view projection matrix uniform cache
+	uniNM   gls.Uniform // Normal matrix uniform cache
 }
 
 // NewMesh creates and returns a pointer to a mesh with the specified geometry and material

+ 2 - 2
graphic/points.go

@@ -13,8 +13,8 @@ import (
 )
 
 type Points struct {
-	Graphic              // Embedded graphic
-	uniMVPM gls.Uniform2 // Model view projection matrix uniform location cache
+	Graphic             // Embedded graphic
+	uniMVPM gls.Uniform // Model view projection matrix uniform location cache
 }
 
 // NewPoints creates and returns a graphic points object with the specified

+ 4 - 4
graphic/skybox.go

@@ -20,10 +20,10 @@ type SkyboxData struct {
 }
 
 type Skybox struct {
-	Graphic              // embedded graphic object
-	uniMVM  gls.Uniform2 // model view matrix uniform location cache
-	uniMVPM gls.Uniform2 // model view projection matrix uniform cache
-	uniNM   gls.Uniform2 // normal matrix uniform cache
+	Graphic             // embedded graphic object
+	uniMVM  gls.Uniform // model view matrix uniform location cache
+	uniMVPM gls.Uniform // model view projection matrix uniform cache
+	uniNM   gls.Uniform // normal matrix uniform cache
 }
 
 // NewSkybox creates and returns a pointer to a skybox with the specified textures

+ 2 - 2
graphic/sprite.go

@@ -13,8 +13,8 @@ import (
 )
 
 type Sprite struct {
-	Graphic              // Embedded graphic
-	uniMVPM gls.Uniform2 // Model view projection matrix uniform location cache
+	Graphic             // Embedded graphic
+	uniMVPM gls.Uniform // Model view projection matrix uniform location cache
 }
 
 // NewSprite creates and returns a pointer to a sprite with the specified dimensions and material

+ 4 - 4
gui/chart.go

@@ -438,7 +438,7 @@ type chartScaleX struct {
 	chart     *Chart        // Container chart
 	lines     int           // Number of vertical lines
 	mat       chartMaterial // Chart material
-	uniBounds gls.Uniform2  // Bounds uniform location cache
+	uniBounds gls.Uniform   // Bounds uniform location cache
 }
 
 // newChartScaleX creates and returns a pointer to a new chartScaleX for the specified
@@ -517,7 +517,7 @@ type chartScaleY struct {
 	chart     *Chart        // Container chart
 	lines     int           // Number of horizontal lines
 	mat       chartMaterial // Chart material
-	uniBounds gls.Uniform2  // Bounds uniform location cache
+	uniBounds gls.Uniform   // Bounds uniform location cache
 }
 
 // newChartScaleY creates and returns a pointer to a new chartScaleY for the specified
@@ -604,7 +604,7 @@ type Graph struct {
 	mat       chartMaterial // Chart material
 	vbo       *gls.VBO
 	positions math32.ArrayF32
-	uniBounds gls.Uniform2 // Bounds uniform location cache
+	uniBounds gls.Uniform // Bounds uniform location cache
 }
 
 // newGraph creates and returns a pointer to a new graph for the specified chart
@@ -711,7 +711,7 @@ func (lg *Graph) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {
 type chartMaterial struct {
 	material.Material              // Embedded material
 	color             math32.Color // emissive color
-	uniColor          gls.Uniform2 // color uniform location cache
+	uniColor          gls.Uniform  // color uniform location cache
 }
 
 func (cm *chartMaterial) Init(color *math32.Color) {

+ 2 - 2
gui/panel.go

@@ -75,8 +75,8 @@ type Panel struct {
 	cursorEnter      bool               // mouse enter dispatched
 	layout           ILayout            // current layout for children
 	layoutParams     interface{}        // current layout parameters used by container panel
-	uniMatrix        gls.Uniform2       // model matrix uniform location cache
-	uniPanel         gls.Uniform2       // panel parameters uniform location cache
+	uniMatrix        gls.Uniform        // model matrix uniform location cache
+	uniPanel         gls.Uniform        // panel parameters uniform location cache
 	udata            struct {           // Combined uniform data 8 * vec4
 		bounds        math32.Vector4 // panel bounds in texture coordinates
 		borders       math32.Vector4 // panel borders in texture coordinates

+ 1 - 1
light/ambient.go

@@ -14,7 +14,7 @@ type Ambient struct {
 	core.Node              // Embedded node
 	color     math32.Color // Light color
 	intensity float32      // Light intensity
-	uni       gls.Uniform2 // Uniform location cache
+	uni       gls.Uniform  // Uniform location cache
 }
 
 // NewAmbient returns a pointer to a new ambient color with the specified

+ 1 - 1
light/directional.go

@@ -16,7 +16,7 @@ type Directional struct {
 	core.Node              // Embedded node
 	color     math32.Color // Light color
 	intensity float32      // Light intensity
-	uni       gls.Uniform2 // Uniform location cache
+	uni       gls.Uniform  // Uniform location cache
 	udata     struct {     // Combined uniform data in 2 vec3:
 		color    math32.Color   // Light color
 		position math32.Vector3 // Light position

+ 1 - 1
light/point.go

@@ -16,7 +16,7 @@ type Point struct {
 	core.Node              // Embedded node
 	color     math32.Color // Light color
 	intensity float32      // Light intensity
-	uni       gls.Uniform2 // Uniform location cache
+	uni       gls.Uniform  // Uniform location cache
 	udata     struct {     // Combined uniform data in 3 vec3:
 		color          math32.Color   // Light color
 		position       math32.Vector3 // Light position

+ 1 - 1
light/spot.go

@@ -17,7 +17,7 @@ type Spot struct {
 	color     math32.Color   // Light color
 	intensity float32        // Light intensity
 	direction math32.Vector3 // Direction in world coordinates
-	uni       gls.Uniform2   // Uniform location cache
+	uni       gls.Uniform    // Uniform location cache
 	udata     struct {       // Combined uniform data in 5 vec3:
 		color          math32.Color   // Light color
 		position       math32.Vector3 // Light position

+ 0 - 12
material/point.go

@@ -5,9 +5,6 @@
 package material
 
 import (
-	"unsafe"
-
-	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/math32"
 )
 
@@ -47,12 +44,3 @@ func (pm *Point) SetRotationZ(rot float32) {
 
 	pm.udata.protationZ = rot
 }
-
-// RenderSetup is called by the engine before drawing the object
-// which uses this material
-func (pm *Point) RenderSetup(gs *gls.GLS) {
-
-	pm.Material.RenderSetup(gs)
-	location := pm.uni.Location(gs)
-	gs.Uniform3fvUP(location, standardVec3Count, unsafe.Pointer(&pm.udata))
-}

+ 3 - 3
material/standard.go

@@ -14,9 +14,9 @@ import (
 // ambient, diffuse, specular and emissive lights.
 // The lighting calculation is implemented in the vertex shader.
 type Standard struct {
-	Material              // Embedded material
-	uni      gls.Uniform2 // Uniform location cache
-	udata    struct {     // Combined uniform data in 6 vec3:
+	Material             // Embedded material
+	uni      gls.Uniform // Uniform location cache
+	udata    struct {    // Combined uniform data in 6 vec3:
 		ambient    math32.Color // Ambient color reflectivity
 		diffuse    math32.Color // Diffuse color reflectivity
 		specular   math32.Color // Specular color reflectivity

+ 19 - 19
texture/texture2D.go

@@ -18,25 +18,25 @@ import (
 )
 
 type Texture2D struct {
-	gs           *gls.GLS     // Pointer to OpenGL state
-	refcount     int          // Current number of references
-	texname      uint32       // Texture handle
-	magFilter    uint32       // magnification filter
-	minFilter    uint32       // minification filter
-	wrapS        uint32       // wrap mode for s coordinate
-	wrapT        uint32       // wrap mode for t coordinate
-	iformat      int32        // internal format
-	width        int32        // texture width in pixels
-	height       int32        // texture height in pixels
-	format       uint32       // format of the pixel data
-	formatType   uint32       // type of the pixel data
-	updateData   bool         // texture data needs to be sent
-	updateParams bool         // texture parameters needs to be sent
-	genMipmap    bool         // generate mipmaps flag
-	data         interface{}  // array with texture data
-	uniUnit      gls.Uniform2 // Texture unit uniform location cache
-	uniInfo      gls.Uniform2 // Texture info uniform location cache
-	udata        struct {     // Combined uniform data in 3 vec2:
+	gs           *gls.GLS    // Pointer to OpenGL state
+	refcount     int         // Current number of references
+	texname      uint32      // Texture handle
+	magFilter    uint32      // magnification filter
+	minFilter    uint32      // minification filter
+	wrapS        uint32      // wrap mode for s coordinate
+	wrapT        uint32      // wrap mode for t coordinate
+	iformat      int32       // internal format
+	width        int32       // texture width in pixels
+	height       int32       // texture height in pixels
+	format       uint32      // format of the pixel data
+	formatType   uint32      // type of the pixel data
+	updateData   bool        // texture data needs to be sent
+	updateParams bool        // texture parameters needs to be sent
+	genMipmap    bool        // generate mipmaps flag
+	data         interface{} // array with texture data
+	uniUnit      gls.Uniform // Texture unit uniform location cache
+	uniInfo      gls.Uniform // Texture info uniform location cache
+	udata        struct {    // Combined uniform data in 3 vec2:
 		offsetX float32
 		offsetY float32
 		repeatX float32