graphicsdriver/opengl: Refactoring

This commit is contained in:
Hajime Hoshi 2019-11-24 00:08:38 +09:00
parent 3df198f68e
commit 4296c11256
2 changed files with 5 additions and 8 deletions

View File

@ -525,7 +525,8 @@ func (c *context) newPixelBufferObject(width, height int) buffer {
return bf return bf
} }
func (c *context) mapPixelBuffer(buffer buffer) unsafe.Pointer { func (c *context) mapPixelBuffer(buffer buffer, t textureNative) unsafe.Pointer {
c.bindTexture(t)
var ptr unsafe.Pointer var ptr unsafe.Pointer
_ = c.t.Call(func() error { _ = c.t.Call(func() error {
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, uint32(buffer)) gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, uint32(buffer))
@ -535,13 +536,9 @@ func (c *context) mapPixelBuffer(buffer buffer) unsafe.Pointer {
return ptr return ptr
} }
func (c *context) unmapPixelBuffer(buffer buffer, t textureNative, width, height int) { func (c *context) unmapPixelBuffer(buffer buffer, width, height int) {
_ = c.t.Call(func() error { _ = c.t.Call(func() error {
gl.UnmapBuffer(gl.PIXEL_UNPACK_BUFFER) gl.UnmapBuffer(gl.PIXEL_UNPACK_BUFFER)
return nil
})
c.bindTexture(t)
_ = c.t.Call(func() error {
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil) gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, 0) gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, 0)
return nil return nil

View File

@ -42,7 +42,7 @@ func (s *pboState) mapPBO(img *Image) {
img.pbo = img.driver.context.newPixelBufferObject(w, h) img.pbo = img.driver.context.newPixelBufferObject(w, h)
} }
s.image = img s.image = img
s.mappedPBO = img.driver.context.mapPixelBuffer(img.pbo) s.mappedPBO = img.driver.context.mapPixelBuffer(img.pbo, img.textureNative)
if s.mappedPBO == nil { if s.mappedPBO == nil {
panic("opengl: mapPixelBuffer failed") panic("opengl: mapPixelBuffer failed")
@ -68,7 +68,7 @@ func (s *pboState) draw(pix []byte, x, y, width, height int) {
func (s *pboState) unmapPBO() { func (s *pboState) unmapPBO() {
i := s.image i := s.image
w, h := graphics.InternalImageSize(i.width), graphics.InternalImageSize(i.height) w, h := graphics.InternalImageSize(i.width), graphics.InternalImageSize(i.height)
i.driver.context.unmapPixelBuffer(i.pbo, i.textureNative, w, h) i.driver.context.unmapPixelBuffer(i.pbo, w, h)
s.image = nil s.image = nil
s.mappedPBO = nil s.mappedPBO = nil