diff --git a/ebiten.go b/ebiten.go index 7d2f26226..2caa8cd80 100644 --- a/ebiten.go +++ b/ebiten.go @@ -12,7 +12,7 @@ type Game interface { Draw(g graphics.GraphicsContext, offscreen graphics.Texture) } -func Run(game Game, u ui.UI) { +func OpenGLRun(game Game, u ui.UI) { ch := make(chan bool, 1) device := opengl.NewDevice( u.ScreenWidth(), u.ScreenHeight(), u.ScreenScale(), diff --git a/graphics/opengl/shader.go b/graphics/opengl/shader.go index 1a10db11c..23912d1eb 100644 --- a/graphics/opengl/shader.go +++ b/graphics/opengl/shader.go @@ -137,19 +137,23 @@ func initializeShaders() { C.glDeleteShader(colorMatrixShader.id) } -func isOpenGLES2() bool { - // TODO: Implement! - return false -} - const ( qualifierVariableTypeAttribute = iota qualifierVariableTypeUniform ) -// This method should be called on the UI thread. -// TODO: Can we cache the locations? +var ( + shaderLocationCache = map[int]map[string]C.GLint{ + qualifierVariableTypeAttribute: map[string]C.GLint{}, + qualifierVariableTypeUniform: map[string]C.GLint{}, + } +) + func getLocation(program C.GLuint, name string, qualifierVariableType int) C.GLint { + if location, ok := shaderLocationCache[qualifierVariableType][name]; ok { + return location + } + locationName := C.CString(name) defer C.free(unsafe.Pointer(locationName)) @@ -165,16 +169,15 @@ func getLocation(program C.GLuint, name string, qualifierVariableType int) C.GLi if location == -1 { panic("glGetUniformLocation failed") } + shaderLocationCache[qualifierVariableType][name] = location return location } -// This method should be called on the UI thread. func getAttributeLocation(program C.GLuint, name string) C.GLint { return getLocation(program, name, qualifierVariableTypeAttribute) } -// This method should be called on the UI thread. func getUniformLocation(program C.GLuint, name string) C.GLint { return getLocation(program, name, qualifierVariableTypeUniform) }