Merge pull request #245 from dusk125/master

Adding Clipping rectangle support in GLTriangles
This commit is contained in:
Alex R. Delp 2020-06-28 16:54:03 -07:00 committed by GitHub
commit 88b1e1c2d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support hiding the window initially - Support hiding the window initially
- Support creating maximized windows - Support creating maximized windows
- Support waiting for events to reduce CPU load - Support waiting for events to reduce CPU load
- Adding clipping rectangle support in GLTriangles
## [v0.10.0-beta] 2020-05-10 ## [v0.10.0-beta] 2020-05-10
- Add `WindowConfig.TransparentFramebuffer` option to support window transparency onto the background - Add `WindowConfig.TransparentFramebuffer` option to support window transparency onto the background

View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/faiface/glhf" "github.com/faiface/glhf"
"github.com/faiface/mainthread" "github.com/faiface/mainthread"
"github.com/faiface/pixel" "github.com/faiface/pixel"
@ -315,6 +317,10 @@ func (ct *canvasTriangles) draw(tex *glhf.Texture, bounds pixel.Rect) {
ct.dst.shader.s.SetUniformAttr(loc, u.Value()) 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 { if tex == nil {
ct.vs.Begin() ct.vs.Begin()
ct.vs.Draw() ct.vs.Draw()

View File

@ -16,6 +16,7 @@ type GLTriangles struct {
vs *glhf.VertexSlice vs *glhf.VertexSlice
data []float32 data []float32
shader *glhf.Shader shader *glhf.Shader
clip pixel.Rect
} }
var ( 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]) intensity = float64(gt.data[i*gt.vs.Stride()+8])
return pixel.V(float64(tx), float64(ty)), intensity 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
}