From defb4b37782b1034cc2fd7e367b8fe2d54490b1a Mon Sep 17 00:00:00 2001 From: faiface Date: Fri, 2 Dec 2016 19:29:39 +0100 Subject: [PATCH] fix --- pixelgl/vertex.go | 14 ++++---------- window.go | 12 ++++++------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pixelgl/vertex.go b/pixelgl/vertex.go index 7ab94c7..19cef47 100644 --- a/pixelgl/vertex.go +++ b/pixelgl/vertex.go @@ -1,7 +1,6 @@ package pixelgl import ( - "fmt" "unsafe" "github.com/go-gl/gl/v3.3-core/gl" @@ -16,7 +15,7 @@ import ( // VertexFormat{"position": {Position, Vec2}, "colr": {Color, Vec4}, "texCoord": {TexCoord, Vec2}} // // Note: vertex array currently doesn't support matrices in vertex format. -type VertexFormat map[string]Attr +type VertexFormat []Attr // Size calculates the total size of a single vertex in this vertex format (sum of the sizes of all vertex attributes). func (vf VertexFormat) Size() int { @@ -118,12 +117,7 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage gl.BufferData(gl.ARRAY_BUFFER, len(emptyData), gl.Ptr(emptyData), uint32(usage)) offset := 0 - for name, attr := range format { - location := gl.GetAttribLocation(ctx.Shader().ID(), gl.Str(name+"\x00")) - if location == -1 { - return fmt.Errorf("shader does not contain vertex attribute '%s'", name) - } - + for i, attr := range format { var size int32 switch attr.Type { case Float: @@ -137,14 +131,14 @@ func NewVertexArray(parent Doer, format VertexFormat, mode VertexDrawMode, usage } gl.VertexAttribPointer( - uint32(location), + uint32(i), size, gl.FLOAT, false, int32(va.stride), gl.PtrOffset(offset), ) - gl.EnableVertexAttribArray(uint32(location)) + gl.EnableVertexAttribArray(uint32(i)) offset += attr.Type.Size() } diff --git a/window.go b/window.go index 46195d9..e8ef87a 100644 --- a/window.go +++ b/window.go @@ -315,9 +315,9 @@ func (w *Window) Do(sub func(pixelgl.Context)) { } var defaultVertexFormat = pixelgl.VertexFormat{ - "position": {Purpose: pixelgl.Position, Type: pixelgl.Vec2}, - "color": {Purpose: pixelgl.Color, Type: pixelgl.Vec4}, - "texCoord": {Purpose: pixelgl.TexCoord, Type: pixelgl.Vec2}, + {Purpose: pixelgl.Position, Type: pixelgl.Vec2}, + {Purpose: pixelgl.Color, Type: pixelgl.Vec4}, + {Purpose: pixelgl.TexCoord, Type: pixelgl.Vec2}, } var defaultUniformFormat = pixelgl.UniformFormat{ @@ -328,9 +328,9 @@ var defaultUniformFormat = pixelgl.UniformFormat{ var defaultVertexShader = ` #version 330 core -in vec2 position; -in vec4 color; -in vec2 texCoord; +layout (location = 0) in vec2 position; +layout (location = 1) in vec4 color; +layout (location = 2) in vec2 texCoord; out vec4 Color; out vec2 TexCoord;