2021-04-05 16:53:17 +02:00
|
|
|
// Copyright 2021 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package opengl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall/js"
|
|
|
|
)
|
|
|
|
|
2022-11-13 05:24:54 +01:00
|
|
|
type jsGL struct {
|
2021-04-05 16:53:17 +02:00
|
|
|
activeTexture js.Value
|
|
|
|
attachShader js.Value
|
|
|
|
bindAttribLocation js.Value
|
|
|
|
bindBuffer js.Value
|
|
|
|
bindFramebuffer js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
bindRenderbuffer js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
bindTexture js.Value
|
2022-10-15 11:58:56 +02:00
|
|
|
blendEquationSeparate js.Value
|
|
|
|
blendFuncSeparate js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
bufferData js.Value
|
|
|
|
bufferSubData js.Value
|
|
|
|
checkFramebufferStatus js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
clear js.Value
|
|
|
|
colorMask js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
compileShader js.Value
|
|
|
|
createBuffer js.Value
|
|
|
|
createFramebuffer js.Value
|
|
|
|
createProgram js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
createRenderbuffer js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
createShader js.Value
|
|
|
|
createTexture js.Value
|
|
|
|
deleteBuffer js.Value
|
|
|
|
deleteFramebuffer js.Value
|
|
|
|
deleteProgram js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
deleteRenderbuffer js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
deleteShader js.Value
|
|
|
|
deleteTexture js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
disable js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
disableVertexAttribArray js.Value
|
|
|
|
drawElements js.Value
|
|
|
|
enable js.Value
|
|
|
|
enableVertexAttribArray js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
framebufferRenderbuffer js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
framebufferTexture2D js.Value
|
|
|
|
flush js.Value
|
|
|
|
getExtension js.Value
|
|
|
|
getParameter js.Value
|
|
|
|
getProgramInfoLog js.Value
|
|
|
|
getProgramParameter js.Value
|
|
|
|
getShaderInfoLog js.Value
|
|
|
|
getShaderParameter js.Value
|
|
|
|
getUniformLocation js.Value
|
|
|
|
isContextLost js.Value
|
|
|
|
isFramebuffer js.Value
|
|
|
|
isProgram js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
isRenderbuffer js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
isTexture js.Value
|
|
|
|
linkProgram js.Value
|
|
|
|
pixelStorei js.Value
|
|
|
|
readPixels js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
renderbufferStorage js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
scissor js.Value
|
|
|
|
shaderSource js.Value
|
2021-07-04 17:10:48 +02:00
|
|
|
stencilFunc js.Value
|
|
|
|
stencilMask js.Value
|
|
|
|
stencilOp js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
texImage2D js.Value
|
|
|
|
texSubImage2D js.Value
|
|
|
|
texParameteri js.Value
|
|
|
|
uniform1fv js.Value
|
2022-11-12 10:38:15 +01:00
|
|
|
uniform1i js.Value
|
|
|
|
uniform1iv js.Value
|
2021-04-05 16:53:17 +02:00
|
|
|
uniform2fv js.Value
|
|
|
|
uniform3fv js.Value
|
|
|
|
uniform4fv js.Value
|
|
|
|
uniformMatrix2fv js.Value
|
|
|
|
uniformMatrix3fv js.Value
|
|
|
|
uniformMatrix4fv js.Value
|
|
|
|
useProgram js.Value
|
|
|
|
vertexAttribPointer js.Value
|
|
|
|
viewport js.Value
|
|
|
|
}
|
|
|
|
|
2022-11-13 05:24:54 +01:00
|
|
|
func (c *context) newJSGL(v js.Value) *jsGL {
|
2021-04-05 16:53:17 +02:00
|
|
|
// Passing a Go string to the JS world is expensive. This causes conversion to UTF-16 (#1438).
|
|
|
|
// In order to reduce the cost when calling functions, create the function objects by bind and use them.
|
2022-11-13 05:24:54 +01:00
|
|
|
g := &jsGL{
|
2021-04-05 16:53:17 +02:00
|
|
|
activeTexture: v.Get("activeTexture").Call("bind", v),
|
|
|
|
attachShader: v.Get("attachShader").Call("bind", v),
|
|
|
|
bindAttribLocation: v.Get("bindAttribLocation").Call("bind", v),
|
|
|
|
bindBuffer: v.Get("bindBuffer").Call("bind", v),
|
|
|
|
bindFramebuffer: v.Get("bindFramebuffer").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
bindRenderbuffer: v.Get("bindRenderbuffer").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
bindTexture: v.Get("bindTexture").Call("bind", v),
|
2022-10-15 11:58:56 +02:00
|
|
|
blendEquationSeparate: v.Get("blendEquationSeparate").Call("bind", v),
|
|
|
|
blendFuncSeparate: v.Get("blendFuncSeparate").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
bufferData: v.Get("bufferData").Call("bind", v),
|
|
|
|
bufferSubData: v.Get("bufferSubData").Call("bind", v),
|
|
|
|
checkFramebufferStatus: v.Get("checkFramebufferStatus").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
clear: v.Get("clear").Call("bind", v),
|
|
|
|
colorMask: v.Get("colorMask").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
compileShader: v.Get("compileShader").Call("bind", v),
|
|
|
|
createBuffer: v.Get("createBuffer").Call("bind", v),
|
|
|
|
createFramebuffer: v.Get("createFramebuffer").Call("bind", v),
|
|
|
|
createProgram: v.Get("createProgram").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
createRenderbuffer: v.Get("createRenderbuffer").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
createShader: v.Get("createShader").Call("bind", v),
|
|
|
|
createTexture: v.Get("createTexture").Call("bind", v),
|
|
|
|
deleteBuffer: v.Get("deleteBuffer").Call("bind", v),
|
|
|
|
deleteFramebuffer: v.Get("deleteFramebuffer").Call("bind", v),
|
|
|
|
deleteProgram: v.Get("deleteProgram").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
deleteRenderbuffer: v.Get("deleteRenderbuffer").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
deleteShader: v.Get("deleteShader").Call("bind", v),
|
|
|
|
deleteTexture: v.Get("deleteTexture").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
disable: v.Get("disable").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
disableVertexAttribArray: v.Get("disableVertexAttribArray").Call("bind", v),
|
|
|
|
drawElements: v.Get("drawElements").Call("bind", v),
|
|
|
|
enable: v.Get("enable").Call("bind", v),
|
|
|
|
enableVertexAttribArray: v.Get("enableVertexAttribArray").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
framebufferRenderbuffer: v.Get("framebufferRenderbuffer").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
framebufferTexture2D: v.Get("framebufferTexture2D").Call("bind", v),
|
|
|
|
flush: v.Get("flush").Call("bind", v),
|
|
|
|
getParameter: v.Get("getParameter").Call("bind", v),
|
|
|
|
getProgramInfoLog: v.Get("getProgramInfoLog").Call("bind", v),
|
|
|
|
getProgramParameter: v.Get("getProgramParameter").Call("bind", v),
|
|
|
|
getShaderInfoLog: v.Get("getShaderInfoLog").Call("bind", v),
|
|
|
|
getShaderParameter: v.Get("getShaderParameter").Call("bind", v),
|
|
|
|
getUniformLocation: v.Get("getUniformLocation").Call("bind", v),
|
|
|
|
isContextLost: v.Get("isContextLost").Call("bind", v),
|
|
|
|
isFramebuffer: v.Get("isFramebuffer").Call("bind", v),
|
|
|
|
isProgram: v.Get("isProgram").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
isRenderbuffer: v.Get("isRenderbuffer").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
isTexture: v.Get("isTexture").Call("bind", v),
|
|
|
|
linkProgram: v.Get("linkProgram").Call("bind", v),
|
|
|
|
pixelStorei: v.Get("pixelStorei").Call("bind", v),
|
|
|
|
readPixels: v.Get("readPixels").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
renderbufferStorage: v.Get("renderbufferStorage").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
scissor: v.Get("scissor").Call("bind", v),
|
|
|
|
shaderSource: v.Get("shaderSource").Call("bind", v),
|
2021-07-04 17:10:48 +02:00
|
|
|
stencilFunc: v.Get("stencilFunc").Call("bind", v),
|
|
|
|
stencilMask: v.Get("stencilMask").Call("bind", v),
|
|
|
|
stencilOp: v.Get("stencilOp").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
texImage2D: v.Get("texImage2D").Call("bind", v),
|
|
|
|
texSubImage2D: v.Get("texSubImage2D").Call("bind", v),
|
|
|
|
texParameteri: v.Get("texParameteri").Call("bind", v),
|
|
|
|
uniform1fv: v.Get("uniform1fv").Call("bind", v),
|
2022-11-12 10:38:15 +01:00
|
|
|
uniform1i: v.Get("uniform1i").Call("bind", v),
|
|
|
|
uniform1iv: v.Get("uniform1iv").Call("bind", v),
|
2021-04-05 16:53:17 +02:00
|
|
|
uniform2fv: v.Get("uniform2fv").Call("bind", v),
|
|
|
|
uniform3fv: v.Get("uniform3fv").Call("bind", v),
|
|
|
|
uniform4fv: v.Get("uniform4fv").Call("bind", v),
|
|
|
|
uniformMatrix2fv: v.Get("uniformMatrix2fv").Call("bind", v),
|
|
|
|
uniformMatrix3fv: v.Get("uniformMatrix3fv").Call("bind", v),
|
|
|
|
uniformMatrix4fv: v.Get("uniformMatrix4fv").Call("bind", v),
|
|
|
|
useProgram: v.Get("useProgram").Call("bind", v),
|
|
|
|
vertexAttribPointer: v.Get("vertexAttribPointer").Call("bind", v),
|
|
|
|
viewport: v.Get("viewport").Call("bind", v),
|
|
|
|
}
|
2022-05-24 13:40:53 +02:00
|
|
|
if !c.usesWebGL2() {
|
2021-04-05 16:53:17 +02:00
|
|
|
g.getExtension = v.Get("getExtension").Call("bind", v)
|
|
|
|
}
|
|
|
|
return g
|
|
|
|
}
|