Adding support for clipping rectangles in GLTriangles
This commit is contained in:
parent
d65a63e962
commit
e79a8c37e6
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue