implemented clearRect

This commit is contained in:
Thomas Friedel 2018-05-23 12:32:43 +02:00
parent d877b57424
commit 964380f673
6 changed files with 61 additions and 1 deletions

View file

@ -112,6 +112,7 @@ These features *should* work just like their HTML5 counterparts, but there are l
- drawImage
- getImageData
- putImageData
- clearRect
# Missing features
@ -120,7 +121,6 @@ These features *should* work just like their HTML5 counterparts, but there are l
- miterLimit
- shadows
- textBaseline
- clearRect
- getLineDash
- isPointInPath
- isPointInStroke

View file

@ -64,6 +64,9 @@ func (_ GLImpl) BufferData(target uint32, size int, data unsafe.Pointer, usage u
func (_ GLImpl) Clear(mask uint32) {
C.glClear(C.uint(mask))
}
func (_ GLImpl) ClearColor(red float32, green float32, blue float32, alpha float32) {
C.glClearColor(C.float(red), C.float(green), C.float(blue), C.float(alpha))
}
func (_ GLImpl) ColorMask(red bool, green bool, blue bool, alpha bool) {
var r, g, b, a C.uchar
if red {
@ -95,6 +98,9 @@ func (_ GLImpl) DeleteShader(shader uint32) {
func (_ GLImpl) DeleteTextures(n int32, textures *uint32) {
C.glDeleteTextures(C.int(n), (*C.uint)(textures))
}
func (_ GLImpl) Disable(cap uint32) {
C.glDisable(C.uint(cap))
}
func (_ GLImpl) DisableVertexAttribArray(index uint32) {
C.glDisableVertexAttribArray(C.uint(index))
}

View file

@ -36,6 +36,9 @@ func (_ GLImpl) BufferData(target uint32, size int, data unsafe.Pointer, usage u
func (_ GLImpl) Clear(mask uint32) {
gl.Clear(mask)
}
func (_ GLImpl) ClearColor(red float32, green float32, blue float32, alpha float32) {
gl.ClearColor(red, green, blue, alpha)
}
func (_ GLImpl) ColorMask(red bool, green bool, blue bool, alpha bool) {
gl.ColorMask(red, green, blue, alpha)
}
@ -54,6 +57,9 @@ func (_ GLImpl) DeleteShader(shader uint32) {
func (_ GLImpl) DeleteTextures(n int32, textures *uint32) {
gl.DeleteTextures(n, textures)
}
func (_ GLImpl) Disable(cap uint32) {
gl.Disable(cap)
}
func (_ GLImpl) DisableVertexAttribArray(index uint32) {
gl.DisableVertexAttribArray(index)
}

View file

@ -64,6 +64,9 @@ func (_ GLImpl) BufferData(target uint32, size int, data unsafe.Pointer, usage u
func (_ GLImpl) Clear(mask uint32) {
C.glClear(C.GLbitfield(mask))
}
func (_ GLImpl) ClearColor(red float32, green float32, blue float32, alpha float32) {
C.glClearColor(C.GLfloat(red), C.GLfloat(green), C.GLfloat(blue), C.GLfloat(alpha))
}
func (_ GLImpl) ColorMask(red bool, green bool, blue bool, alpha bool) {
var r, g, b, a C.GLboolean
if red {
@ -95,6 +98,9 @@ func (_ GLImpl) DeleteShader(shader uint32) {
func (_ GLImpl) DeleteTextures(n int32, textures *uint32) {
C.glDeleteTextures(C.GLsizei(n), (*C.GLuint)(textures))
}
func (_ GLImpl) Disable(cap uint32) {
C.glDisable(C.GLenum(cap))
}
func (_ GLImpl) DisableVertexAttribArray(index uint32) {
C.glDisableVertexAttribArray(C.GLuint(index))
}

View file

@ -801,12 +801,14 @@ type GL interface {
BlendFunc(sfactor uint32, dfactor uint32)
BufferData(target uint32, size int, data unsafe.Pointer, usage uint32)
Clear(mask uint32)
ClearColor(red float32, green float32, blue float32, alpha float32)
ColorMask(red bool, green bool, blue bool, alpha bool)
CompileShader(shader uint32)
CreateProgram() uint32
CreateShader(xtype uint32) uint32
DeleteShader(shader uint32)
DeleteTextures(n int32, textures *uint32)
Disable(cap uint32)
DisableVertexAttribArray(index uint32)
DrawArrays(mode uint32, first int32, count int32)
Enable(cap uint32)

View file

@ -714,3 +714,43 @@ func (cv *Canvas) FillRect(x, y, w, h float64) {
gli.StencilFunc(gl_ALWAYS, 0, 0xFF)
}
// ClearRect sets the color of the rectangle to transparent black
func (cv *Canvas) ClearRect(x, y, w, h float64) {
cv.activate()
if cv.state.transform == matIdentity() {
gli.Scissor(int32(x+0.5), int32(cv.fh-y-h+0.5), int32(w+0.5), int32(h+0.5))
gli.ClearColor(0, 0, 0, 0)
gli.Clear(gl_COLOR_BUFFER_BIT)
cv.applyScissor()
return
}
gli.UseProgram(sr.id)
gli.Uniform2f(sr.canvasSize, float32(cv.fw), float32(cv.fh))
gli.Uniform4f(sr.color, 0, 0, 0, 0)
gli.Uniform1f(sr.globalAlpha, 1)
gli.Disable(gl_BLEND)
p0 := cv.tf(vec{x, y})
p1 := cv.tf(vec{x, y + h})
p2 := cv.tf(vec{x + w, y + h})
p3 := cv.tf(vec{x + w, y})
gli.BindBuffer(gl_ARRAY_BUFFER, buf)
data := [8]float32{float32(p0[0]), float32(p0[1]), float32(p1[0]), float32(p1[1]), float32(p2[0]), float32(p2[1]), float32(p3[0]), float32(p3[1])}
gli.BufferData(gl_ARRAY_BUFFER, len(data)*4, unsafe.Pointer(&data[0]), gl_STREAM_DRAW)
gli.StencilFunc(gl_EQUAL, 0, 0xFF)
gli.VertexAttribPointer(sr.vertex, 2, gl_FLOAT, false, 0, 0)
gli.EnableVertexAttribArray(sr.vertex)
gli.DrawArrays(gl_TRIANGLE_FAN, 0, 4)
gli.DisableVertexAttribArray(sr.vertex)
gli.StencilFunc(gl_ALWAYS, 0, 0xFF)
gli.Enable(gl_BLEND)
}