Bug fix: image.Pixels didn't work on WebGL

This commit is contained in:
Hajime Hoshi
2015-01-17 18:22:58 +09:00
parent d91a467c53
commit 683ffafe8d
6 changed files with 21 additions and 16 deletions

View File

@@ -64,6 +64,8 @@ type context struct {
gl *webgl.Context
}
var lastFramebuffer Framebuffer
func NewContext(gl *webgl.Context) *Context {
c := &Context{
Nearest: Filter(gl.NEAREST),
@@ -113,12 +115,14 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
return Texture{t}, nil
}
func (c *Context) TexturePixels(t Texture, width, height int) ([]uint8, error) {
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {
gl := c.gl
gl.Flush()
// TODO: Use glGetTexLevelParameteri and GL_TEXTURE_WIDTH?
lastFramebuffer = Framebuffer{nil}
gl.BindFramebuffer(gl.FRAMEBUFFER, f.Object)
pixels := js.Global.Get("Uint8Array").New(4 * width * height)
gl.BindTexture(gl.TEXTURE_2D, t.Object)
gl.ReadPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
if e := gl.GetError(); e != gl.NO_ERROR {
return nil, errors.New(fmt.Sprintf("gl error: %d", e))
@@ -148,6 +152,7 @@ func (c *Context) GlslHighpSupported() bool {
func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) {
gl := c.gl
f := gl.CreateFramebuffer()
lastFramebuffer = Framebuffer{nil}
gl.BindFramebuffer(gl.FRAMEBUFFER, f)
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t.Object, 0)
@@ -158,8 +163,6 @@ func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) {
return Framebuffer{f}, nil
}
var lastFramebuffer Framebuffer
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
gl := c.gl
// TODO: Fix this after the GopherJS bug was fixed (#159)