mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
app/internal/gpu: clip in floating point
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+26
-13
@@ -576,7 +576,7 @@ func (r *renderer) intersectPath(p *pathOp, clip image.Rectangle) {
|
|||||||
}
|
}
|
||||||
fbo := r.pather.stenciler.cover(p.place.Idx)
|
fbo := r.pather.stenciler.cover(p.place.Idx)
|
||||||
r.ctx.BindTexture(gl.TEXTURE_2D, fbo.tex)
|
r.ctx.BindTexture(gl.TEXTURE_2D, fbo.tex)
|
||||||
coverScale, coverOff := texSpaceTransform(uv, fbo.size)
|
coverScale, coverOff := texSpaceTransform(toRectF(uv), fbo.size)
|
||||||
r.ctx.Uniform2f(r.pather.stenciler.uIntersectUVScale, coverScale.X, coverScale.Y)
|
r.ctx.Uniform2f(r.pather.stenciler.uIntersectUVScale, coverScale.X, coverScale.Y)
|
||||||
r.ctx.Uniform2f(r.pather.stenciler.uIntersectUVOffset, coverOff.X, coverOff.Y)
|
r.ctx.Uniform2f(r.pather.stenciler.uIntersectUVOffset, coverOff.X, coverOff.Y)
|
||||||
r.ctx.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
|
r.ctx.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
|
||||||
@@ -652,6 +652,19 @@ func boundRectF(r f32.Rectangle) image.Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toRectF(r image.Rectangle) f32.Rectangle {
|
||||||
|
return f32.Rectangle{
|
||||||
|
Min: f32.Point{
|
||||||
|
X: float32(r.Min.X),
|
||||||
|
Y: float32(r.Min.Y),
|
||||||
|
},
|
||||||
|
Max: f32.Point{
|
||||||
|
X: float32(r.Max.X),
|
||||||
|
Y: float32(r.Max.Y),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ceil(v float32) int {
|
func ceil(v float32) int {
|
||||||
return int(math.Ceil(float64(v)))
|
return int(math.Ceil(float64(v)))
|
||||||
}
|
}
|
||||||
@@ -802,21 +815,21 @@ func (d *drawState) materialFor(cache *resourceCache, rect f32.Rectangle, off f3
|
|||||||
} else {
|
} else {
|
||||||
m.material = materialTexture
|
m.material = materialTexture
|
||||||
dr := boundRectF(rect.Add(off))
|
dr := boundRectF(rect.Add(off))
|
||||||
sr := image.Rectangle{
|
sr := f32.Rectangle{
|
||||||
Max: d.imgSize,
|
Max: f32.Point{X: float32(d.imgSize.X), Y: float32(d.imgSize.Y)},
|
||||||
}
|
}
|
||||||
if dx := dr.Dx(); dx != 0 {
|
if dx := float32(dr.Dx()); dx != 0 {
|
||||||
// Don't clip 1 px width sources.
|
// Don't clip 1 px width sources.
|
||||||
if sdx := sr.Dx(); sdx > 1 {
|
if sdx := sr.Dx(); sdx > 1 {
|
||||||
sr.Min.X += ((clip.Min.X-dr.Min.X)*sdx + dx/2) / dx
|
sr.Min.X += (float32(clip.Min.X-dr.Min.X)*sdx + dx/2) / dx
|
||||||
sr.Max.X -= ((dr.Max.X-clip.Max.X)*sdx + dx/2) / dx
|
sr.Max.X -= (float32(dr.Max.X-clip.Max.X)*sdx + dx/2) / dx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if dy := dr.Dy(); dy != 0 {
|
if dy := float32(dr.Dy()); dy != 0 {
|
||||||
// Don't clip 1 px height sources.
|
// Don't clip 1 px height sources.
|
||||||
if sdy := sr.Dy(); sdy > 1 {
|
if sdy := sr.Dy(); sdy > 1 {
|
||||||
sr.Min.Y += ((clip.Min.Y-dr.Min.Y)*sdy + dy/2) / dy
|
sr.Min.Y += (float32(clip.Min.Y-dr.Min.Y)*sdy + dy/2) / dy
|
||||||
sr.Max.Y -= ((dr.Max.Y-clip.Max.Y)*sdy + dy/2) / dy
|
sr.Max.Y -= (float32(dr.Max.Y-clip.Max.Y)*sdy + dy/2) / dy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tex, exists := cache.get(d.img)
|
tex, exists := cache.get(d.img)
|
||||||
@@ -895,7 +908,7 @@ func (r *renderer) drawOps(ops []imageOp) {
|
|||||||
Min: img.place.Pos,
|
Min: img.place.Pos,
|
||||||
Max: img.place.Pos.Add(drc.Size()),
|
Max: img.place.Pos.Add(drc.Size()),
|
||||||
}
|
}
|
||||||
coverScale, coverOff := texSpaceTransform(uv, fbo.size)
|
coverScale, coverOff := texSpaceTransform(toRectF(uv), fbo.size)
|
||||||
r.pather.cover(img.z, m.material, m.color, scale, off, m.uvScale, m.uvOffset, coverScale, coverOff)
|
r.pather.cover(img.z, m.material, m.color, scale, off, m.uvScale, m.uvOffset, coverScale, coverOff)
|
||||||
}
|
}
|
||||||
r.ctx.DisableVertexAttribArray(attribPos)
|
r.ctx.DisableVertexAttribArray(attribPos)
|
||||||
@@ -951,10 +964,10 @@ func (b *blitter) blit(z float32, mat materialType, col [4]float32, scale, off,
|
|||||||
|
|
||||||
// texSpaceTransform return the scale and offset that transforms the given subimage
|
// texSpaceTransform return the scale and offset that transforms the given subimage
|
||||||
// into quad texture coordinates.
|
// into quad texture coordinates.
|
||||||
func texSpaceTransform(r image.Rectangle, bounds image.Point) (f32.Point, f32.Point) {
|
func texSpaceTransform(r f32.Rectangle, bounds image.Point) (f32.Point, f32.Point) {
|
||||||
size := f32.Point{X: float32(bounds.X), Y: float32(bounds.Y)}
|
size := f32.Point{X: float32(bounds.X), Y: float32(bounds.Y)}
|
||||||
scale := f32.Point{X: float32(r.Dx()) / size.X, Y: float32(r.Dy()) / size.Y}
|
scale := f32.Point{X: r.Dx() / size.X, Y: r.Dy() / size.Y}
|
||||||
offset := f32.Point{X: float32(r.Min.X) / size.X, Y: float32(r.Min.Y) / size.Y}
|
offset := f32.Point{X: r.Min.X / size.X, Y: r.Min.Y / size.Y}
|
||||||
return scale, offset
|
return scale, offset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user