Skip to content

Commit

Permalink
more efficient alpha texture loading
Browse files Browse the repository at this point in the history
  • Loading branch information
tfriedel6 committed Mar 21, 2020
1 parent 7830bb2 commit 59ddfe5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
13 changes: 5 additions & 8 deletions backend/goglbackend/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,12 @@ func (b *GoGLBackend) FillImageMask(style *backendbase.FillStyle, mask *image.Al

gl.ActiveTexture(gl.TEXTURE1)
gl.BindTexture(gl.TEXTURE_2D, b.alphaTex)
for y := 0; y < h; y++ {
off := y * mask.Stride
gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, int32(alphaTexSize-1-y), int32(w), 1, gl.ALPHA, gl.UNSIGNED_BYTE, gl.Ptr(&mask.Pix[off]))
gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, int32(mask.Stride), int32(h), gl.ALPHA, gl.UNSIGNED_BYTE, gl.Ptr(&mask.Pix[0]))
if w < alphaTexSize {
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(w), 0, 1, int32(h), gl.ALPHA, gl.UNSIGNED_BYTE, gl.Ptr(&zeroes[0]))
}
if h < alphaTexSize {
gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, int32(alphaTexSize-1-h), int32(w), 1, gl.ALPHA, gl.UNSIGNED_BYTE, gl.Ptr(&zeroes[0]))
}
if w < alphaTexSize {
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(w), int32(alphaTexSize-1-h), 1, int32(h), gl.ALPHA, gl.UNSIGNED_BYTE, gl.Ptr(&zeroes[0]))
gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, int32(h), int32(w), 1, gl.ALPHA, gl.UNSIGNED_BYTE, gl.Ptr(&zeroes[0]))
}

if style.Blur > 0 {
Expand All @@ -205,7 +202,7 @@ func (b *GoGLBackend) FillImageMask(style *backendbase.FillStyle, mask *image.Al
for _, pt := range pts {
data = append(data, float32(pt[0]), float32(pt[1]))
}
data = append(data, 0, 1, 0, float32(1-th), float32(tw), float32(1-th), float32(tw), 1)
data = append(data, 0, 0, 0, float32(th), float32(tw), float32(th), float32(tw), 0)

gl.BufferData(gl.ARRAY_BUFFER, len(data)*4, unsafe.Pointer(&data[0]), gl.STREAM_DRAW)

Expand Down
15 changes: 7 additions & 8 deletions backend/xmobilebackend/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ func (b *XMobileBackend) FillImageMask(style *backendbase.FillStyle, mask *image

b.glctx.ActiveTexture(gl.TEXTURE1)
b.glctx.BindTexture(gl.TEXTURE_2D, b.alphaTex)
for y := 0; y < h; y++ {
off := y * mask.Stride
b.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, 0, alphaTexSize-1-y, w, 1, gl.ALPHA, gl.UNSIGNED_BYTE, mask.Pix[off:])
b.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, mask.Stride, h, gl.ALPHA, gl.UNSIGNED_BYTE, mask.Pix[0:])
if w < alphaTexSize {
b.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, w, 0, 1, h, gl.ALPHA, gl.UNSIGNED_BYTE, zeroes[0:])
}
if h < alphaTexSize {
b.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, 0, h, w, 1, gl.ALPHA, gl.UNSIGNED_BYTE, zeroes[0:])
}

if style.Blur > 0 {
Expand All @@ -199,7 +202,7 @@ func (b *XMobileBackend) FillImageMask(style *backendbase.FillStyle, mask *image
for _, pt := range pts {
data = append(data, float32(pt[0]), float32(pt[1]))
}
data = append(data, 0, 1, 0, float32(1-th), float32(tw), float32(1-th), float32(tw), 1)
data = append(data, 0, 0, 0, float32(th), float32(tw), float32(th), float32(tw), 0)

b.glctx.BufferData(gl.ARRAY_BUFFER, byteSlice(unsafe.Pointer(&data[0]), len(data)*4), gl.STREAM_DRAW)

Expand All @@ -215,10 +218,6 @@ func (b *XMobileBackend) FillImageMask(style *backendbase.FillStyle, mask *image

b.glctx.StencilFunc(gl.ALWAYS, 0, 0xFF)

for y := 0; y < h; y++ {
b.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, 0, alphaTexSize-1-y, w, 1, gl.ALPHA, gl.UNSIGNED_BYTE, zeroes[0:])
}

b.glctx.ActiveTexture(gl.TEXTURE0)

if style.Blur > 0 {
Expand Down

0 comments on commit 59ddfe5

Please sign in to comment.