mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +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)
|
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)
|
ch := make(chan bool, 1)
|
||||||
device := opengl.NewDevice(
|
device := opengl.NewDevice(
|
||||||
u.ScreenWidth(), u.ScreenHeight(), u.ScreenScale(),
|
u.ScreenWidth(), u.ScreenHeight(), u.ScreenScale(),
|
||||||
|
@ -137,19 +137,23 @@ func initializeShaders() {
|
|||||||
C.glDeleteShader(colorMatrixShader.id)
|
C.glDeleteShader(colorMatrixShader.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isOpenGLES2() bool {
|
|
||||||
// TODO: Implement!
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
qualifierVariableTypeAttribute = iota
|
qualifierVariableTypeAttribute = iota
|
||||||
qualifierVariableTypeUniform
|
qualifierVariableTypeUniform
|
||||||
)
|
)
|
||||||
|
|
||||||
// This method should be called on the UI thread.
|
var (
|
||||||
// TODO: Can we cache the locations?
|
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 {
|
func getLocation(program C.GLuint, name string, qualifierVariableType int) C.GLint {
|
||||||
|
if location, ok := shaderLocationCache[qualifierVariableType][name]; ok {
|
||||||
|
return location
|
||||||
|
}
|
||||||
|
|
||||||
locationName := C.CString(name)
|
locationName := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(locationName))
|
defer C.free(unsafe.Pointer(locationName))
|
||||||
|
|
||||||
@ -165,16 +169,15 @@ func getLocation(program C.GLuint, name string, qualifierVariableType int) C.GLi
|
|||||||
if location == -1 {
|
if location == -1 {
|
||||||
panic("glGetUniformLocation failed")
|
panic("glGetUniformLocation failed")
|
||||||
}
|
}
|
||||||
|
shaderLocationCache[qualifierVariableType][name] = location
|
||||||
|
|
||||||
return location
|
return location
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method should be called on the UI thread.
|
|
||||||
func getAttributeLocation(program C.GLuint, name string) C.GLint {
|
func getAttributeLocation(program C.GLuint, name string) C.GLint {
|
||||||
return getLocation(program, name, qualifierVariableTypeAttribute)
|
return getLocation(program, name, qualifierVariableTypeAttribute)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method should be called on the UI thread.
|
|
||||||
func getUniformLocation(program C.GLuint, name string) C.GLint {
|
func getUniformLocation(program C.GLuint, name string) C.GLint {
|
||||||
return getLocation(program, name, qualifierVariableTypeUniform)
|
return getLocation(program, name, qualifierVariableTypeUniform)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user