From e79a8c37e60ff00111fe91cd97bf5ad15bc9f9a8 Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Sun, 21 Jun 2020 22:51:08 -0400 Subject: [PATCH 1/4] Adding support for clipping rectangles in GLTriangles --- pixelgl/canvas.go | 3 +++ pixelgl/gltriangles.go | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pixelgl/canvas.go b/pixelgl/canvas.go index 25da939..5bc8437 100644 --- a/pixelgl/canvas.go +++ b/pixelgl/canvas.go @@ -327,6 +327,9 @@ func (ct *canvasTriangles) draw(tex *glhf.Texture, bounds pixel.Rect) { } ct.vs.Begin() + if clip, has := ct.ClipRect(); has { + gl.Scissor(int32(clip.Min.X), int32(clip.Min.Y), int32(clip.W()), int32(clip.H())) + } ct.vs.Draw() ct.vs.End() diff --git a/pixelgl/gltriangles.go b/pixelgl/gltriangles.go index f258102..557f420 100644 --- a/pixelgl/gltriangles.go +++ b/pixelgl/gltriangles.go @@ -16,6 +16,7 @@ type GLTriangles struct { vs *glhf.VertexSlice data []float32 shader *glhf.Shader + clip pixel.Rect } var ( @@ -213,3 +214,14 @@ func (gt *GLTriangles) Picture(i int) (pic pixel.Vec, intensity float64) { intensity = float64(gt.data[i*gt.vs.Stride()+8]) return pixel.V(float64(tx), float64(ty)), intensity } + +// SetClipRect sets the rectangle to scissor the triangles by +func (gt *GLTriangles) SetClipRect(r pixel.Rect) { + gt.clip = r.Norm() +} + +// ClipRect gets the clipping rectangle and returns true if that +// rectangle is not the Zero Rectangle +func (gt *GLTriangles) ClipRect() (pixel.Rect, bool) { + return gt.clip, gt.clip.Area() != 0 +} From c3e5e4fdb25c720207f6d8d6093b327512d08f11 Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Sun, 21 Jun 2020 22:54:23 -0400 Subject: [PATCH 2/4] Moved triangle clipping to the proper location --- pixelgl/canvas.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pixelgl/canvas.go b/pixelgl/canvas.go index 5bc8437..ff60479 100644 --- a/pixelgl/canvas.go +++ b/pixelgl/canvas.go @@ -315,6 +315,10 @@ func (ct *canvasTriangles) draw(tex *glhf.Texture, bounds pixel.Rect) { ct.dst.shader.s.SetUniformAttr(loc, u.Value()) } + if clip, has := ct.ClipRect(); has { + gl.Scissor(int32(clip.Min.X), int32(clip.Min.Y), int32(clip.W()), int32(clip.H())) + } + if tex == nil { ct.vs.Begin() ct.vs.Draw() @@ -327,9 +331,6 @@ func (ct *canvasTriangles) draw(tex *glhf.Texture, bounds pixel.Rect) { } ct.vs.Begin() - if clip, has := ct.ClipRect(); has { - gl.Scissor(int32(clip.Min.X), int32(clip.Min.Y), int32(clip.W()), int32(clip.H())) - } ct.vs.Draw() ct.vs.End() From 543819d066b4320972e2aa05943e69cd57690674 Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Sun, 21 Jun 2020 23:09:08 -0400 Subject: [PATCH 3/4] Forgot to add import in PR --- pixelgl/canvas.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pixelgl/canvas.go b/pixelgl/canvas.go index ff60479..e04df06 100644 --- a/pixelgl/canvas.go +++ b/pixelgl/canvas.go @@ -4,6 +4,8 @@ import ( "fmt" "image/color" + "github.com/go-gl/gl/v3.3-core/gl" + "github.com/faiface/glhf" "github.com/faiface/mainthread" "github.com/faiface/pixel" From 850dd62a984f34febb4a22e7dfc6f83e36b63f71 Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Sun, 28 Jun 2020 12:58:13 -0400 Subject: [PATCH 4/4] Updating changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f76339c..65080ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support hiding the window initially - Support creating maximized windows - Support waiting for events to reduce CPU load +- Adding clipping rectangle support in GLTriangles ## [v0.10.0-beta] 2020-05-10 - Add `WindowConfig.TransparentFramebuffer` option to support window transparency onto the background