mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Cache shader location
This commit is contained in:
parent
ca0250f13c
commit
b5df3231e3
@ -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(),
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user