Reduce init functions

This mitigates the init-order issue on jsgo.io.
This commit is contained in:
Hajime Hoshi 2018-12-26 01:51:04 +09:00
parent de788603d6
commit 99e4c874fe
5 changed files with 68 additions and 113 deletions

View File

@ -18,24 +18,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphics"
)
var (
vertexShader shaderType
fragmentShader shaderType
arrayBuffer bufferType
elementArrayBuffer bufferType
dynamicDraw bufferUsage
staticDraw bufferUsage
short dataType
float dataType
zero operation
one operation
srcAlpha operation
dstAlpha operation
oneMinusSrcAlpha operation
oneMinusDstAlpha operation
)
func convertOperation(op graphics.Operation) operation {
switch op {
case graphics.Zero:

View File

@ -54,22 +54,22 @@ func getProgramID(p program) programID {
return programID(p)
}
func init() {
vertexShader = gl.VERTEX_SHADER
fragmentShader = gl.FRAGMENT_SHADER
arrayBuffer = gl.ARRAY_BUFFER
elementArrayBuffer = gl.ELEMENT_ARRAY_BUFFER
dynamicDraw = gl.DYNAMIC_DRAW
short = gl.SHORT
float = gl.FLOAT
const (
vertexShader = shaderType(gl.VERTEX_SHADER)
fragmentShader = shaderType(gl.FRAGMENT_SHADER)
arrayBuffer = bufferType(gl.ARRAY_BUFFER)
elementArrayBuffer = bufferType(gl.ELEMENT_ARRAY_BUFFER)
dynamicDraw = bufferUsage(gl.DYNAMIC_DRAW)
short = dataType(gl.SHORT)
float = dataType(gl.FLOAT)
zero = gl.ZERO
one = gl.ONE
srcAlpha = gl.SRC_ALPHA
dstAlpha = gl.DST_ALPHA
oneMinusSrcAlpha = gl.ONE_MINUS_SRC_ALPHA
oneMinusDstAlpha = gl.ONE_MINUS_DST_ALPHA
}
zero = operation(gl.ZERO)
one = operation(gl.ONE)
srcAlpha = operation(gl.SRC_ALPHA)
dstAlpha = operation(gl.DST_ALPHA)
oneMinusSrcAlpha = operation(gl.ONE_MINUS_SRC_ALPHA)
oneMinusDstAlpha = operation(gl.ONE_MINUS_DST_ALPHA)
)
type contextImpl struct {
init bool

View File

@ -47,69 +47,46 @@ func getProgramID(p program) programID {
}
var (
blend js.Value
clampToEdge js.Value
colorAttachment0 js.Value
compileStatus js.Value
framebuffer_ js.Value
framebufferBinding js.Value
framebufferComplete js.Value
linkStatus js.Value
maxTextureSize js.Value
nearest js.Value
noError js.Value
texture2d js.Value
textureMagFilter js.Value
textureMinFilter js.Value
textureWrapS js.Value
textureWrapT js.Value
triangles js.Value
rgba js.Value
unpackAlignment js.Value
unsignedByte js.Value
unsignedShort js.Value
)
func init() {
// Accessing the prototype is rquired on Safari.
c := js.Global().Get("WebGLRenderingContext").Get("prototype")
vertexShader = shaderType(c.Get("VERTEX_SHADER").Int())
fragmentShader = shaderType(c.Get("FRAGMENT_SHADER").Int())
arrayBuffer = bufferType(c.Get("ARRAY_BUFFER").Int())
elementArrayBuffer = bufferType(c.Get("ELEMENT_ARRAY_BUFFER").Int())
dynamicDraw = bufferUsage(c.Get("DYNAMIC_DRAW").Int())
short = dataType(c.Get("SHORT").Int())
float = dataType(c.Get("FLOAT").Int())
contextPrototype = js.Global().Get("WebGLRenderingContext").Get("prototype")
zero = operation(c.Get("ZERO").Int())
one = operation(c.Get("ONE").Int())
srcAlpha = operation(c.Get("SRC_ALPHA").Int())
dstAlpha = operation(c.Get("DST_ALPHA").Int())
oneMinusSrcAlpha = operation(c.Get("ONE_MINUS_SRC_ALPHA").Int())
oneMinusDstAlpha = operation(c.Get("ONE_MINUS_DST_ALPHA").Int())
vertexShader = shaderType(contextPrototype.Get("VERTEX_SHADER").Int())
fragmentShader = shaderType(contextPrototype.Get("FRAGMENT_SHADER").Int())
arrayBuffer = bufferType(contextPrototype.Get("ARRAY_BUFFER").Int())
elementArrayBuffer = bufferType(contextPrototype.Get("ELEMENT_ARRAY_BUFFER").Int())
dynamicDraw = bufferUsage(contextPrototype.Get("DYNAMIC_DRAW").Int())
short = dataType(contextPrototype.Get("SHORT").Int())
float = dataType(contextPrototype.Get("FLOAT").Int())
blend = c.Get("BLEND")
clampToEdge = c.Get("CLAMP_TO_EDGE")
compileStatus = c.Get("COMPILE_STATUS")
colorAttachment0 = c.Get("COLOR_ATTACHMENT0")
framebuffer_ = c.Get("FRAMEBUFFER")
framebufferBinding = c.Get("FRAMEBUFFER_BINDING")
framebufferComplete = c.Get("FRAMEBUFFER_COMPLETE")
linkStatus = c.Get("LINK_STATUS")
maxTextureSize = c.Get("MAX_TEXTURE_SIZE")
nearest = c.Get("NEAREST")
noError = c.Get("NO_ERROR")
rgba = c.Get("RGBA")
texture2d = c.Get("TEXTURE_2D")
textureMagFilter = c.Get("TEXTURE_MAG_FILTER")
textureMinFilter = c.Get("TEXTURE_MIN_FILTER")
textureWrapS = c.Get("TEXTURE_WRAP_S")
textureWrapT = c.Get("TEXTURE_WRAP_T")
triangles = c.Get("TRIANGLES")
unpackAlignment = c.Get("UNPACK_ALIGNMENT")
unsignedByte = c.Get("UNSIGNED_BYTE")
unsignedShort = c.Get("UNSIGNED_SHORT")
}
zero = operation(contextPrototype.Get("ZERO").Int())
one = operation(contextPrototype.Get("ONE").Int())
srcAlpha = operation(contextPrototype.Get("SRC_ALPHA").Int())
dstAlpha = operation(contextPrototype.Get("DST_ALPHA").Int())
oneMinusSrcAlpha = operation(contextPrototype.Get("ONE_MINUS_SRC_ALPHA").Int())
oneMinusDstAlpha = operation(contextPrototype.Get("ONE_MINUS_DST_ALPHA").Int())
blend = contextPrototype.Get("BLEND")
clampToEdge = contextPrototype.Get("CLAMP_TO_EDGE")
compileStatus = contextPrototype.Get("COMPILE_STATUS")
colorAttachment0 = contextPrototype.Get("COLOR_ATTACHMENT0")
framebuffer_ = contextPrototype.Get("FRAMEBUFFER")
framebufferBinding = contextPrototype.Get("FRAMEBUFFER_BINDING")
framebufferComplete = contextPrototype.Get("FRAMEBUFFER_COMPLETE")
linkStatus = contextPrototype.Get("LINK_STATUS")
maxTextureSize = contextPrototype.Get("MAX_TEXTURE_SIZE")
nearest = contextPrototype.Get("NEAREST")
noError = contextPrototype.Get("NO_ERROR")
rgba = contextPrototype.Get("RGBA")
texture2d = contextPrototype.Get("TEXTURE_2D")
textureMagFilter = contextPrototype.Get("TEXTURE_MAG_FILTER")
textureMinFilter = contextPrototype.Get("TEXTURE_MIN_FILTER")
textureWrapS = contextPrototype.Get("TEXTURE_WRAP_S")
textureWrapT = contextPrototype.Get("TEXTURE_WRAP_T")
triangles = contextPrototype.Get("TRIANGLES")
unpackAlignment = contextPrototype.Get("UNPACK_ALIGNMENT")
unsignedByte = contextPrototype.Get("UNSIGNED_BYTE")
unsignedShort = contextPrototype.Get("UNSIGNED_SHORT")
)
type contextImpl struct {
gl js.Value

View File

@ -51,22 +51,22 @@ func getProgramID(p program) programID {
return programID(p.Value)
}
func init() {
vertexShader = mgl.VERTEX_SHADER
fragmentShader = mgl.FRAGMENT_SHADER
arrayBuffer = mgl.ARRAY_BUFFER
elementArrayBuffer = mgl.ELEMENT_ARRAY_BUFFER
dynamicDraw = mgl.DYNAMIC_DRAW
short = mgl.SHORT
float = mgl.FLOAT
const (
vertexShader = shaderType(mgl.VERTEX_SHADER)
fragmentShader = shaderType(mgl.FRAGMENT_SHADER)
arrayBuffer = bufferType(mgl.ARRAY_BUFFER)
elementArrayBuffer = bufferType(mgl.ELEMENT_ARRAY_BUFFER)
dynamicDraw = bufferUsage(mgl.DYNAMIC_DRAW)
short = dataType(mgl.SHORT)
float = dataType(mgl.FLOAT)
zero = mgl.ZERO
one = mgl.ONE
srcAlpha = mgl.SRC_ALPHA
dstAlpha = mgl.DST_ALPHA
oneMinusSrcAlpha = mgl.ONE_MINUS_SRC_ALPHA
oneMinusDstAlpha = mgl.ONE_MINUS_DST_ALPHA
}
zero = operation(mgl.ZERO)
one = operation(mgl.ONE)
srcAlpha = operation(mgl.SRC_ALPHA)
dstAlpha = operation(mgl.DST_ALPHA)
oneMinusSrcAlpha = operation(mgl.ONE_MINUS_SRC_ALPHA)
oneMinusDstAlpha = operation(mgl.ONE_MINUS_DST_ALPHA)
)
type contextImpl struct {
gl mgl.Context

6
run.go
View File

@ -41,13 +41,9 @@ func CurrentFPS() float64 {
var (
isDrawingSkipped = int32(0)
currentMaxTPS = int32(0)
currentMaxTPS = int32(DefaultTPS)
)
func init() {
atomic.StoreInt32(&currentMaxTPS, DefaultTPS)
}
func setDrawingSkipped(skipped bool) {
v := int32(0)
if skipped {