Repository: fyne-io/fyne
File: internal/painter/gl/draw.go (Go)

Code before:

func (p *painter) createBuffer(points []float32) Buffer {
	vbo := p.ctx.CreateBuffer()
	p.logError()
	p.ctx.BindBuffer(arrayBuffer, vbo)
	p.logError()
	p.ctx.BufferData(arrayBuffer, points, staticDraw)
	p.logError()
	return vbo
}

func (p *painter) defineVertexArray(prog Program, name string, size, stride, offset int) {
	vertAttrib := p.ctx.GetAttribLocation(prog, name)
	p.ctx.EnableVertexAttribArray(vertAttrib)
	p.ctx.VertexAttribPointerWithOffset(vertAttrib, size, float, false, stride*floatSize, offset*floatSize)
	p.logError()
}

func (p *painter) drawCircle(circle *canvas.Circle, pos fyne.Position, frame fyne.Size) {
	p.drawTextureWithDetails(circle, p.newGlCircleTexture, pos, circle.Size(), frame, canvas.ImageFillStretch,
		1.0, paint.VectorPad(circle))

	radius := circle.Size().Width / 2
	if circle.Size().Height < circle.Size().Width {
		radius = circle.Size().Height / 2
	}
	program := p.roundRectangleProgram

	// Vertex: BEG
	bounds, points := p.vecSquareCoords(pos, circle, frame)
	p.ctx.UseProgram(program)
	vbo := p.createBuffer(points)
	p.defineVertexArray(program, "vert", 2, 4, 0)
	p.defineVertexArray(program, "normal", 2, 4, 2)

	p.ctx.BlendFunc(srcAlpha, oneMinusSrcAlpha)
	p.logError()
	// Vertex: END

	// Fragment: BEG
	frameSizeUniform := p.ctx.GetUniformLocation(program, "frame_size")
	frameWidthScaled, frameHeightScaled := p.scaleFrameSize(frame)
	p.ctx.Uniform2f(frameSizeUniform, frameWidthScaled, frameHeightScaled)

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

	strokeWidthScaled := roundToPixel(circle.StrokeWidth*p.pixScale, 1.0)
	strokeUniform := p.ctx.GetUniformLocation(program, "stroke_width_half")
	p.ctx.Uniform1f(strokeUniform, strokeWidthScaled*0.5)

Review comment (suggestion):
```suggestion
	size := circe.Size()
	radius := size.Width / 2
	if size.Height < size.Width {
		radius = size.Height / 2
	}
```

Code after:

func (p *painter) createBuffer(points []float32) Buffer {
	vbo := p.ctx.CreateBuffer()
	p.logError()
	p.ctx.BindBuffer(arrayBuffer, vbo)
	p.logError()
	p.ctx.BufferData(arrayBuffer, points, staticDraw)
	p.logError()
	return vbo
}

func (p *painter) defineVertexArray(prog Program, name string, size, stride, offset int) {
	vertAttrib := p.ctx.GetAttribLocation(prog, name)
	p.ctx.EnableVertexAttribArray(vertAttrib)
	p.ctx.VertexAttribPointerWithOffset(vertAttrib, size, float, false, stride*floatSize, offset*floatSize)
	p.logError()
}

func (p *painter) drawCircle(circle *canvas.Circle, pos fyne.Position, frame fyne.Size) {
	p.drawTextureWithDetails(circle, p.newGlCircleTexture, pos, circle.Size(), frame, canvas.ImageFillStretch,
		1.0, paint.VectorPad(circle))

	size := circle.Size()
	radius := size.Width / 2
	if size.Height < size.Width {
		radius = size.Height / 2
	}
	program := p.roundRectangleProgram

	// Vertex: BEG
	bounds, points := p.vecSquareCoords(pos, circle, frame)
	p.ctx.UseProgram(program)
	vbo := p.createBuffer(points)
	p.defineVertexArray(program, "vert", 2, 4, 0)
	p.defineVertexArray(program, "normal", 2, 4, 2)

	p.ctx.BlendFunc(srcAlpha, oneMinusSrcAlpha)
	p.logError()
	// Vertex: END

	// Fragment: BEG
	frameSizeUniform := p.ctx.GetUniformLocation(program, "frame_size")
	frameWidthScaled, frameHeightScaled := p.scaleFrameSize(frame)
	p.ctx.Uniform2f(frameSizeUniform, frameWidthScaled, frameHeightScaled)

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

	strokeWidthScaled := roundToPixel(circle.StrokeWidth*p.pixScale, 1.0)
	strokeUniform := p.ctx.GetUniformLocation(program, "stroke_width_half")