mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/graphicsdriver/opengl: Remove unused code using PBO
Updates #1678
This commit is contained in:
parent
b249fe889d
commit
50d2d7ed61
@ -496,10 +496,6 @@ func (c *context) needsRestoring() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) canUsePBO() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *context) texSubImage2D(t textureNative, args []*driver.ReplacePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
for _, a := range args {
|
||||
@ -507,39 +503,6 @@ func (c *context) texSubImage2D(t textureNative, args []*driver.ReplacePixelsArg
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) newPixelBufferObject(width, height int) buffer {
|
||||
var b uint32
|
||||
gl.GenBuffers(1, &b)
|
||||
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, b)
|
||||
gl.BufferData(gl.PIXEL_UNPACK_BUFFER, 4*width*height, nil, gl.STREAM_DRAW)
|
||||
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, 0)
|
||||
return buffer(b)
|
||||
}
|
||||
|
||||
func (c *context) replacePixelsWithPBO(buffer buffer, t textureNative, width, height int, args []*driver.ReplacePixelsArgs) {
|
||||
c.bindTexture(t)
|
||||
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, uint32(buffer))
|
||||
|
||||
stride := 4 * width
|
||||
for _, a := range args {
|
||||
offset := 4 * (a.Y*width + a.X)
|
||||
for j := 0; j < a.Height; j++ {
|
||||
gl.BufferSubData(gl.PIXEL_UNPACK_BUFFER, offset+stride*j, 4*a.Width, gl.Ptr(a.Pixels[4*a.Width*j:4*a.Width*(j+1)]))
|
||||
}
|
||||
}
|
||||
|
||||
gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, nil)
|
||||
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, 0)
|
||||
}
|
||||
|
||||
func (c *context) getBufferSubData(buffer buffer, width, height int) []byte {
|
||||
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, uint32(buffer))
|
||||
pixels := make([]byte, 4*width*height)
|
||||
gl.GetBufferSubData(gl.PIXEL_UNPACK_BUFFER, 0, 4*width*height, gl.Ptr(pixels))
|
||||
gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, 0)
|
||||
return pixels
|
||||
}
|
||||
|
||||
func (c *context) enableStencilTest() {
|
||||
gl.Enable(gl.STENCIL_TEST)
|
||||
}
|
||||
|
@ -599,54 +599,6 @@ func (c *context) texSubImage2D(t textureNative, args []*driver.ReplacePixelsArg
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) newPixelBufferObject(width, height int) buffer {
|
||||
gl := c.gl
|
||||
b := gl.createBuffer.Invoke()
|
||||
gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, js.Value(b))
|
||||
gl.bufferData.Invoke(gles.PIXEL_UNPACK_BUFFER, 4*width*height, gles.STREAM_DRAW)
|
||||
gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, nil)
|
||||
return buffer(b)
|
||||
}
|
||||
|
||||
func (c *context) replacePixelsWithPBO(buffer buffer, t textureNative, width, height int, args []*driver.ReplacePixelsArgs) {
|
||||
if !isWebGL2Available {
|
||||
panic("opengl: WebGL2 must be available when replacePixelsWithPBO is called")
|
||||
}
|
||||
|
||||
c.bindTexture(t)
|
||||
gl := c.gl
|
||||
gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, js.Value(buffer))
|
||||
|
||||
stride := 4 * width
|
||||
for _, a := range args {
|
||||
arr := jsutil.TemporaryUint8Array(len(a.Pixels), a.Pixels)
|
||||
offset := 4 * (a.Y*width + a.X)
|
||||
for j := 0; j < a.Height; j++ {
|
||||
gl.bufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, offset+stride*j, arr, 4*a.Width*j, 4*a.Width)
|
||||
}
|
||||
}
|
||||
|
||||
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
// GLsizei width, GLsizei height,
|
||||
// GLenum format, GLenum type, GLintptr offset);
|
||||
gl.texSubImage2D.Invoke(gles.TEXTURE_2D, 0, 0, 0, width, height, gles.RGBA, gles.UNSIGNED_BYTE, 0)
|
||||
gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, nil)
|
||||
}
|
||||
|
||||
func (c *context) getBufferSubData(buffer buffer, width, height int) []byte {
|
||||
if !isWebGL2Available {
|
||||
panic("opengl: WebGL2 must be available when getBufferSubData is called")
|
||||
}
|
||||
|
||||
gl := c.gl
|
||||
gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, js.Value(buffer))
|
||||
l := 4 * width * height
|
||||
arr := jsutil.TemporaryUint8Array(l, nil)
|
||||
gl.getBufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, 0, arr, 0, l)
|
||||
gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, nil)
|
||||
return jsutil.Uint8ArrayToSlice(arr, l)
|
||||
}
|
||||
|
||||
func (c *context) enableStencilTest() {
|
||||
gl := c.gl
|
||||
gl.enable.Invoke(gles.STENCIL_TEST)
|
||||
|
@ -469,38 +469,6 @@ func (c *context) texSubImage2D(t textureNative, args []*driver.ReplacePixelsArg
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) newPixelBufferObject(width, height int) buffer {
|
||||
b := c.ctx.GenBuffers(1)[0]
|
||||
c.ctx.BindBuffer(gles.PIXEL_UNPACK_BUFFER, b)
|
||||
c.ctx.BufferData(gles.PIXEL_UNPACK_BUFFER, 4*width*height, nil, gles.STREAM_DRAW)
|
||||
c.ctx.BindBuffer(gles.PIXEL_UNPACK_BUFFER, 0)
|
||||
return buffer(b)
|
||||
}
|
||||
|
||||
func (c *context) replacePixelsWithPBO(buffer buffer, t textureNative, width, height int, args []*driver.ReplacePixelsArgs) {
|
||||
// This implementation is not used yet so far. See the comment at canUsePBO.
|
||||
|
||||
c.bindTexture(t)
|
||||
c.ctx.BindBuffer(gles.PIXEL_UNPACK_BUFFER, uint32(buffer))
|
||||
|
||||
stride := 4 * width
|
||||
for _, a := range args {
|
||||
offset := 4 * (a.Y*width + a.X)
|
||||
for j := 0; j < a.Height; j++ {
|
||||
c.ctx.BufferSubData(gles.PIXEL_UNPACK_BUFFER, offset+stride*j, a.Pixels[4*a.Width*j:4*a.Width*(j+1)])
|
||||
}
|
||||
}
|
||||
|
||||
c.ctx.TexSubImage2D(gles.TEXTURE_2D, 0, 0, 0, int32(width), int32(height), gles.RGBA, gles.UNSIGNED_BYTE, nil)
|
||||
c.ctx.BindBuffer(gles.PIXEL_UNPACK_BUFFER, 0)
|
||||
}
|
||||
|
||||
func (c *context) getBufferSubData(buffer buffer, width, height int) []byte {
|
||||
// gl.GetBufferSubData doesn't exist on OpenGL ES 2 and 3.
|
||||
// As PBO is not used in mobiles, leave this unimplemented so far.
|
||||
panic("opengl: getBufferSubData is not implemented for mobiles")
|
||||
}
|
||||
|
||||
func (c *context) enableStencilTest() {
|
||||
c.ctx.Enable(gles.STENCIL_TEST)
|
||||
}
|
||||
|
@ -149,11 +149,6 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint16) {
|
||||
func (g *Graphics) DrawTriangles(dstID driver.ImageID, srcIDs [graphics.ShaderImageNum]driver.ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shaderID driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address, dstRegion, srcRegion driver.Region, uniforms []interface{}, evenOdd bool) error {
|
||||
destination := g.images[dstID]
|
||||
|
||||
if !destination.pbo.equal(*new(buffer)) {
|
||||
g.context.deleteBuffer(destination.pbo)
|
||||
destination.pbo = *new(buffer)
|
||||
}
|
||||
|
||||
g.drawCalled = true
|
||||
|
||||
if err := destination.setViewport(); err != nil {
|
||||
|
@ -25,7 +25,6 @@ type Image struct {
|
||||
texture textureNative
|
||||
stencil renderbufferNative
|
||||
framebuffer *framebuffer
|
||||
pbo buffer
|
||||
width int
|
||||
height int
|
||||
screen bool
|
||||
@ -40,9 +39,6 @@ func (i *Image) IsInvalidated() bool {
|
||||
}
|
||||
|
||||
func (i *Image) Dispose() {
|
||||
if !i.pbo.equal(*new(buffer)) {
|
||||
i.graphics.context.deleteBuffer(i.pbo)
|
||||
}
|
||||
if i.framebuffer != nil {
|
||||
i.framebuffer.delete(&i.graphics.context)
|
||||
}
|
||||
@ -69,15 +65,7 @@ func (i *Image) Pixels() ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// PBO is created only when PBO is enabled AND ReplacePixels is called.
|
||||
// If PBO is enabled but the buffer doesn't exist, this means either ReplacePixels is not called or
|
||||
// different draw calls than ReplacePixels were called.
|
||||
if !i.graphics.context.canUsePBO() || i.pbo.equal(*new(buffer)) {
|
||||
p := i.graphics.context.framebufferPixels(i.framebuffer, i.width, i.height)
|
||||
return p, nil
|
||||
}
|
||||
|
||||
p := i.graphics.context.getBufferSubData(i.pbo, i.width, i.height)
|
||||
p := i.graphics.context.framebufferPixels(i.framebuffer, i.width, i.height)
|
||||
return p, nil
|
||||
}
|
||||
|
||||
@ -144,25 +132,5 @@ func (i *Image) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
||||
i.graphics.context.flush()
|
||||
}
|
||||
i.graphics.drawCalled = false
|
||||
|
||||
// TODO: Now canUsePBO always returns false (#1678). Remove the code for PBO.
|
||||
if !i.graphics.context.canUsePBO() {
|
||||
i.graphics.context.texSubImage2D(i.texture, args)
|
||||
return
|
||||
}
|
||||
|
||||
w, h := i.width, i.height
|
||||
if i.pbo.equal(*new(buffer)) {
|
||||
i.pbo = i.graphics.context.newPixelBufferObject(w, h)
|
||||
if i.pbo.equal(*new(buffer)) {
|
||||
panic("opengl: newPixelBufferObject failed")
|
||||
}
|
||||
if i.framebuffer != nil {
|
||||
i.graphics.context.framebufferPixelsToBuffer(i.framebuffer, i.pbo, i.width, i.height)
|
||||
}
|
||||
}
|
||||
if i.pbo.equal(*new(buffer)) {
|
||||
panic("opengl: newPixelBufferObject failed")
|
||||
}
|
||||
i.graphics.context.replacePixelsWithPBO(i.pbo, i.texture, w, h, args)
|
||||
i.graphics.context.texSubImage2D(i.texture, args)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user