Skip to content

Commit

Permalink
Merge pull request #4081 from andydotxyz/fix/4000
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Jul 22, 2023
2 parents 4a0f231 + 8ddd2ef commit 1626a09
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 52 deletions.
2 changes: 1 addition & 1 deletion cmd/hello/FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Name = "Fyne Hello"
ID = "io.fyne.hello"
Version = "2.3.0"
Build = 1
Build = 2
28 changes: 14 additions & 14 deletions internal/painter/gl/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (p *painter) drawRectangle(rect *canvas.Rectangle, pos fyne.Position, frame
}

// Vertex: BEG
points := p.vecRectCoords(pos, rect, frame)
bounds, points := p.vecRectCoords(pos, rect, frame)
p.ctx.UseProgram(program)
vbo := p.createBuffer(points)
p.defineVertexArray(program, "vert", 2, 4, 0)
Expand All @@ -122,7 +122,7 @@ func (p *painter) drawRectangle(rect *canvas.Rectangle, pos fyne.Position, frame
p.ctx.Uniform2f(frameSizeUniform, frameWidthScaled, frameHeightScaled)

rectCoordsUniform := p.ctx.GetUniformLocation(program, "rect_coords")
x1Scaled, x2Scaled, y1Scaled, y2Scaled := p.scaleRectCoords(points[0], points[4], points[1], points[9])
x1Scaled, x2Scaled, y1Scaled, y2Scaled := p.scaleRectCoords(bounds[0], bounds[2], bounds[1], bounds[3])
p.ctx.Uniform4f(rectCoordsUniform, x1Scaled, x2Scaled, y1Scaled, y2Scaled)

strokeWidthScaled := roundToPixel(rect.StrokeWidth*p.pixScale, 1.0)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (p *painter) drawRectangle(rect *canvas.Rectangle, pos fyne.Position, frame
p.logError()
// Fragment: END

p.ctx.DrawArrays(triangles, 0, 6)
p.ctx.DrawArrays(triangleStrip, 0, 4)
p.logError()
p.freeBuffer(vbo)
}
Expand Down Expand Up @@ -337,7 +337,7 @@ func rectInnerCoords(size fyne.Size, pos fyne.Position, fill canvas.ImageFill, a
return size, pos
}

func (p *painter) vecRectCoords(pos fyne.Position, rect *canvas.Rectangle, frame fyne.Size) []float32 {
func (p *painter) vecRectCoords(pos fyne.Position, rect *canvas.Rectangle, frame fyne.Size) ([4]float32, []float32) {
size := rect.Size()
pos1 := rect.Position()

Expand All @@ -350,21 +350,21 @@ func (p *painter) vecRectCoords(pos fyne.Position, rect *canvas.Rectangle, frame

x1Pos := pos1.X
x1Norm := -1 + x1Pos*2/frame.Width
x2Pos := (pos1.X + size.Width)
x2Pos := pos1.X + size.Width
x2Norm := -1 + x2Pos*2/frame.Width
y1Pos := pos1.Y
y1Norm := 1 - y1Pos*2/frame.Height
y2Pos := (pos1.Y + size.Height)
y2Pos := pos1.Y + size.Height
y2Norm := 1 - y2Pos*2/frame.Height

// output a norm for the fill and the vert is unused, but we pass 0 to avoid optimisation issues
coords := []float32{
x1Pos, y1Pos, x1Norm, y1Norm, // 1. triangle
x2Pos, y1Pos, x2Norm, y1Norm,
x1Pos, y2Pos, x1Norm, y2Norm,
x1Pos, y2Pos, x1Norm, y2Norm, // 2. triangle
x2Pos, y1Pos, x2Norm, y1Norm,
x2Pos, y2Pos, x2Norm, y2Norm}

return coords
0, 0, x1Norm, y1Norm, // first triangle
0, 0, x2Norm, y1Norm, // second triangle
0, 0, x1Norm, y2Norm,
0, 0, x2Norm, y2Norm}

return [4]float32{x1Pos, y1Pos, x2Pos, y2Pos}, coords
}

func roundToPixel(v float32, pixScale float32) float32 {
Expand Down
4 changes: 2 additions & 2 deletions internal/painter/gl/shaders.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions internal/painter/gl/shaders/gray.frag

This file was deleted.

21 changes: 0 additions & 21 deletions internal/painter/gl/shaders/gray_es.frag

This file was deleted.

2 changes: 1 addition & 1 deletion internal/painter/gl/shaders/rectangle.vert
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ attribute vec2 vert;
attribute vec2 normal;

void main() {
gl_Position = vec4(normal, 0, 1);
gl_Position = vec4(vert+normal, 0, 1);
}
3 changes: 1 addition & 2 deletions internal/painter/gl/shaders/rectangle_es.vert
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ attribute vec2 vert;
attribute vec2 normal;

void main() {
vert; //Workaround, because WebGL optimizes away attributes unused
gl_Position = vec4(normal, 0, 1);
gl_Position = vec4(vert+normal, 0, 1);
}

0 comments on commit 1626a09

Please sign in to comment.