From 6962ba1bda863c878baf99447fa65420874f7606 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Thu, 1 Dec 2016 16:44:54 +0100
Subject: [PATCH] fix Shader.SetUniform* methods

---
 pixelgl/attr.go   |  26 +++++------
 pixelgl/shader.go | 112 +++++++++++++++++++++++++++++-----------------
 pixelgl/vertex.go |  12 ++---
 3 files changed, 89 insertions(+), 61 deletions(-)

diff --git a/pixelgl/attr.go b/pixelgl/attr.go
index 4f649df..5c42cb9 100644
--- a/pixelgl/attr.go
+++ b/pixelgl/attr.go
@@ -51,19 +51,19 @@ const (
 func (at AttrType) Size() int {
 	sizeOf := map[AttrType]int{
 		Int:   4,
-		Float: 8,
-		Vec2:  2 * 8,
-		Vec3:  3 * 8,
-		Vec4:  4 * 8,
-		Mat2:  2 * 2 * 8,
-		Mat23: 2 * 3 * 8,
-		Mat24: 2 * 4 * 8,
-		Mat3:  3 * 3 * 8,
-		Mat32: 3 * 2 * 8,
-		Mat34: 3 * 4 * 8,
-		Mat4:  4 * 4 * 8,
-		Mat42: 4 * 2 * 8,
-		Mat43: 4 * 3 * 8,
+		Float: 4,
+		Vec2:  2 * 4,
+		Vec3:  3 * 4,
+		Vec4:  4 * 4,
+		Mat2:  2 * 2 * 4,
+		Mat23: 2 * 3 * 4,
+		Mat24: 2 * 4 * 4,
+		Mat3:  3 * 3 * 4,
+		Mat32: 3 * 2 * 4,
+		Mat34: 3 * 4 * 4,
+		Mat4:  4 * 4 * 4,
+		Mat42: 4 * 2 * 4,
+		Mat43: 4 * 3 * 4,
 	}
 	return sizeOf[at]
 }
diff --git a/pixelgl/shader.go b/pixelgl/shader.go
index 6c175fb..38ebc56 100644
--- a/pixelgl/shader.go
+++ b/pixelgl/shader.go
@@ -4,7 +4,7 @@ import (
 	"fmt"
 
 	"github.com/go-gl/gl/v3.3-core/gl"
-	"github.com/go-gl/mathgl/mgl64"
+	"github.com/go-gl/mathgl/mgl32"
 	"github.com/pkg/errors"
 )
 
@@ -141,8 +141,10 @@ func (s *Shader) SetUniformInt(purpose AttrPurpose, value int32) (ok bool) {
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.Uniform1i(s.uniforms[attr], value)
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.Uniform1i(s.uniforms[attr], value)
+		})
 	})
 	return true
 }
@@ -150,13 +152,15 @@ func (s *Shader) SetUniformInt(purpose AttrPurpose, value int32) (ok bool) {
 // SetUniformFloat sets the value of an uniform attribute Attr{Purpose: purpose, Type: Float}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformFloat(purpose AttrPurpose, value float64) (ok bool) {
+func (s *Shader) SetUniformFloat(purpose AttrPurpose, value float32) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Float}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.Uniform1d(s.uniforms[attr], value)
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.Uniform1f(s.uniforms[attr], value)
+		})
 	})
 	return true
 }
@@ -164,13 +168,15 @@ func (s *Shader) SetUniformFloat(purpose AttrPurpose, value float64) (ok bool) {
 // SetUniformVec2 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Vec2}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformVec2(purpose AttrPurpose, value mgl64.Vec2) (ok bool) {
+func (s *Shader) SetUniformVec2(purpose AttrPurpose, value mgl32.Vec2) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Vec2}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.Uniform2d(s.uniforms[attr], value[0], value[1])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.Uniform2f(s.uniforms[attr], value[0], value[1])
+		})
 	})
 	return true
 }
@@ -178,13 +184,15 @@ func (s *Shader) SetUniformVec2(purpose AttrPurpose, value mgl64.Vec2) (ok bool)
 // SetUniformVec3 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Vec3}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformVec3(purpose AttrPurpose, value mgl64.Vec3) (ok bool) {
+func (s *Shader) SetUniformVec3(purpose AttrPurpose, value mgl32.Vec3) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Vec3}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.Uniform3d(s.uniforms[attr], value[0], value[1], value[2])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.Uniform3f(s.uniforms[attr], value[0], value[1], value[2])
+		})
 	})
 	return true
 }
@@ -192,13 +200,15 @@ func (s *Shader) SetUniformVec3(purpose AttrPurpose, value mgl64.Vec3) (ok bool)
 // SetUniformVec4 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Vec4}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformVec4(purpose AttrPurpose, value mgl64.Vec4) (ok bool) {
+func (s *Shader) SetUniformVec4(purpose AttrPurpose, value mgl32.Vec4) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Vec4}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.Uniform4d(s.uniforms[attr], value[0], value[1], value[2], value[3])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.Uniform4f(s.uniforms[attr], value[0], value[1], value[2], value[3])
+		})
 	})
 	return true
 }
@@ -206,13 +216,15 @@ func (s *Shader) SetUniformVec4(purpose AttrPurpose, value mgl64.Vec4) (ok bool)
 // SetUniformMat2 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat2}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat2(purpose AttrPurpose, value mgl64.Mat2) (ok bool) {
+func (s *Shader) SetUniformMat2(purpose AttrPurpose, value mgl32.Mat2) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat2}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix2dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix2fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -220,13 +232,15 @@ func (s *Shader) SetUniformMat2(purpose AttrPurpose, value mgl64.Mat2) (ok bool)
 // SetUniformMat23 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat23}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat23(purpose AttrPurpose, value mgl64.Mat2x3) (ok bool) {
+func (s *Shader) SetUniformMat23(purpose AttrPurpose, value mgl32.Mat2x3) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat23}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix2x3dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix2x3fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -234,13 +248,15 @@ func (s *Shader) SetUniformMat23(purpose AttrPurpose, value mgl64.Mat2x3) (ok bo
 // SetUniformMat24 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat24}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat24(purpose AttrPurpose, value mgl64.Mat2x4) (ok bool) {
+func (s *Shader) SetUniformMat24(purpose AttrPurpose, value mgl32.Mat2x4) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat24}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix2x4dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix2x4fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -248,13 +264,15 @@ func (s *Shader) SetUniformMat24(purpose AttrPurpose, value mgl64.Mat2x4) (ok bo
 // SetUniformMat3 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat3}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat3(purpose AttrPurpose, value mgl64.Mat3) (ok bool) {
+func (s *Shader) SetUniformMat3(purpose AttrPurpose, value mgl32.Mat3) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat3}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix3dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix3fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -262,13 +280,15 @@ func (s *Shader) SetUniformMat3(purpose AttrPurpose, value mgl64.Mat3) (ok bool)
 // SetUniformMat32 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat32}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat32(purpose AttrPurpose, value mgl64.Mat3x2) (ok bool) {
+func (s *Shader) SetUniformMat32(purpose AttrPurpose, value mgl32.Mat3x2) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat32}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix3x2dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix3x2fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -276,13 +296,15 @@ func (s *Shader) SetUniformMat32(purpose AttrPurpose, value mgl64.Mat3x2) (ok bo
 // SetUniformMat34 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat34}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat34(purpose AttrPurpose, value mgl64.Mat3x4) (ok bool) {
+func (s *Shader) SetUniformMat34(purpose AttrPurpose, value mgl32.Mat3x4) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat34}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix3x4dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix3x4fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -290,13 +312,15 @@ func (s *Shader) SetUniformMat34(purpose AttrPurpose, value mgl64.Mat3x4) (ok bo
 // SetUniformMat4 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat4}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat4(purpose AttrPurpose, value mgl64.Mat4) (ok bool) {
+func (s *Shader) SetUniformMat4(purpose AttrPurpose, value mgl32.Mat4) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat4}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix4dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix4fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -304,13 +328,15 @@ func (s *Shader) SetUniformMat4(purpose AttrPurpose, value mgl64.Mat4) (ok bool)
 // SetUniformMat42 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat42}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat42(purpose AttrPurpose, value mgl64.Mat4x2) (ok bool) {
+func (s *Shader) SetUniformMat42(purpose AttrPurpose, value mgl32.Mat4x2) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat42}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix4x2dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix4x2fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
@@ -318,13 +344,15 @@ func (s *Shader) SetUniformMat42(purpose AttrPurpose, value mgl64.Mat4x2) (ok bo
 // SetUniformMat43 sets the value of an uniform attribute Attr{Purpose: purpose, Type: Mat43}.
 //
 // Returns false if the attribute does not exist.
-func (s *Shader) SetUniformMat43(purpose AttrPurpose, value mgl64.Mat4x3) (ok bool) {
+func (s *Shader) SetUniformMat43(purpose AttrPurpose, value mgl32.Mat4x3) (ok bool) {
 	attr := Attr{Purpose: purpose, Type: Mat43}
 	if _, ok := s.uniforms[attr]; !ok {
 		return false
 	}
-	DoNoBlock(func() {
-		gl.UniformMatrix4x3dv(s.uniforms[attr], 1, false, &value[0])
+	s.Do(func(Context) {
+		DoNoBlock(func() {
+			gl.UniformMatrix4x3fv(s.uniforms[attr], 1, false, &value[0])
+		})
 	})
 	return true
 }
diff --git a/pixelgl/vertex.go b/pixelgl/vertex.go
index f696995..c302be6 100644
--- a/pixelgl/vertex.go
+++ b/pixelgl/vertex.go
@@ -4,7 +4,7 @@ import (
 	"unsafe"
 
 	"github.com/go-gl/gl/v3.3-core/gl"
-	"github.com/go-gl/mathgl/mgl64"
+	"github.com/go-gl/mathgl/mgl32"
 	"github.com/pkg/errors"
 )
 
@@ -137,7 +137,7 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage
 				case Int:
 					xtype = gl.INT
 				case Float, Vec2, Vec3, Vec4:
-					xtype = gl.DOUBLE
+					xtype = gl.FLOAT
 				}
 
 				gl.VertexAttribPointer(
@@ -262,7 +262,7 @@ func (va *VertexArray) SetVertexAttributeInt(vertex int, purpose AttrPurpose, va
 //
 // This function returns false if the specified vertex attribute does not exist. Note that the function panics if
 // the vertex if out of range.
-func (va *VertexArray) SetVertexAttributeFloat(vertex int, purpose AttrPurpose, value float64) (ok bool) {
+func (va *VertexArray) SetVertexAttributeFloat(vertex int, purpose AttrPurpose, value float32) (ok bool) {
 	va.checkVertex(vertex)
 	attr := Attr{Purpose: purpose, Type: Float}
 	if _, ok := va.attrs[attr]; !ok {
@@ -288,7 +288,7 @@ func (va *VertexArray) SetVertexAttributeFloat(vertex int, purpose AttrPurpose,
 //
 // This function returns false if the specified vertex attribute does not exist. Note that the function panics if
 // the vertex if out of range.
-func (va *VertexArray) SetVertexAttributeVec2(vertex int, purpose AttrPurpose, value mgl64.Vec2) (ok bool) {
+func (va *VertexArray) SetVertexAttributeVec2(vertex int, purpose AttrPurpose, value mgl32.Vec2) (ok bool) {
 	va.checkVertex(vertex)
 	attr := Attr{Purpose: purpose, Type: Vec2}
 	if _, ok := va.attrs[attr]; !ok {
@@ -314,7 +314,7 @@ func (va *VertexArray) SetVertexAttributeVec2(vertex int, purpose AttrPurpose, v
 //
 // This function returns false if the specified vertex attribute does not exist. Note that the function panics if
 // the vertex if out of range.
-func (va *VertexArray) SetVertexAttributeVec3(vertex int, purpose AttrPurpose, value mgl64.Vec3) (ok bool) {
+func (va *VertexArray) SetVertexAttributeVec3(vertex int, purpose AttrPurpose, value mgl32.Vec3) (ok bool) {
 	va.checkVertex(vertex)
 	attr := Attr{Purpose: purpose, Type: Vec3}
 	if _, ok := va.attrs[attr]; !ok {
@@ -340,7 +340,7 @@ func (va *VertexArray) SetVertexAttributeVec3(vertex int, purpose AttrPurpose, v
 //
 // This function returns false if the specified vertex attribute does not exist. Note that the function panics if
 // the vertex if out of range.
-func (va *VertexArray) SetVertexAttributeVec4(vertex int, purpose AttrPurpose, value mgl64.Vec4) (ok bool) {
+func (va *VertexArray) SetVertexAttributeVec4(vertex int, purpose AttrPurpose, value mgl32.Vec4) (ok bool) {
 	va.checkVertex(vertex)
 	attr := Attr{Purpose: purpose, Type: Vec4}
 	if _, ok := va.attrs[attr]; !ok {
-- 
GitLab