Skip to content

Commit

Permalink
graphicsdriver/opengl: Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Nov 23, 2019
1 parent 3df198f commit 4296c11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions internal/graphicsdriver/opengl/context_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ func (c *context) newPixelBufferObject(width, height int) buffer {
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
_ = c.t.Call(func() error {
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, uint32(buffer))
Expand All @@ -535,13 +536,9 @@ func (c *context) mapPixelBuffer(buffer buffer) unsafe.Pointer {
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 {
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.BindBuffer(gl.PIXEL_UNPACK_BUFFER, 0)
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/graphicsdriver/opengl/pbo_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *pboState) mapPBO(img *Image) {
img.pbo = img.driver.context.newPixelBufferObject(w, h)
}
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 {
panic("opengl: mapPixelBuffer failed")
Expand All @@ -68,7 +68,7 @@ func (s *pboState) draw(pix []byte, x, y, width, height int) {
func (s *pboState) unmapPBO() {
i := s.image
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.mappedPBO = nil
Expand Down

0 comments on commit 4296c11

Please sign in to comment.