mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/graphicsdriver/opengl: Bug fix: getBufferSubData was available only with WebGL2
This commit is contained in:
parent
bd8367588e
commit
6fe6543b4b
@ -587,15 +587,15 @@ func (c *context) replacePixelsWithPBO(buffer buffer, t textureNative, width, he
|
||||
}
|
||||
|
||||
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)
|
||||
if isWebGL2Available {
|
||||
gl.getBufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, 0, arr, 0, l)
|
||||
} else {
|
||||
gl.getBufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, 0, arr.Call("subarray", 0, l))
|
||||
}
|
||||
gl.getBufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, 0, arr, 0, l)
|
||||
gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, nil)
|
||||
return jsutil.Uint8ArrayToSlice(arr, l)
|
||||
}
|
||||
|
@ -112,7 +112,6 @@ func newGL(v js.Value) *gl {
|
||||
enableVertexAttribArray: v.Get("enableVertexAttribArray").Call("bind", v),
|
||||
framebufferTexture2D: v.Get("framebufferTexture2D").Call("bind", v),
|
||||
flush: v.Get("flush").Call("bind", v),
|
||||
getBufferSubData: v.Get("getBufferSubData").Call("bind", v),
|
||||
getParameter: v.Get("getParameter").Call("bind", v),
|
||||
getProgramInfoLog: v.Get("getProgramInfoLog").Call("bind", v),
|
||||
getProgramParameter: v.Get("getProgramParameter").Call("bind", v),
|
||||
@ -145,7 +144,9 @@ func newGL(v js.Value) *gl {
|
||||
vertexAttribPointer: v.Get("vertexAttribPointer").Call("bind", v),
|
||||
viewport: v.Get("viewport").Call("bind", v),
|
||||
}
|
||||
if !isWebGL2Available {
|
||||
if isWebGL2Available {
|
||||
g.getExtension = v.Get("getBufferSubData").Call("bind", v)
|
||||
} else {
|
||||
g.getExtension = v.Get("getExtension").Call("bind", v)
|
||||
}
|
||||
return g
|
||||
|
Loading…
Reference in New Issue
Block a user