mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Reduce calls of glBindTexture
This commit is contained in:
parent
4812f2e76e
commit
4c2650c721
@ -29,9 +29,14 @@ type openGLState struct {
|
|||||||
lastModelviewMatrix []float32
|
lastModelviewMatrix []float32
|
||||||
lastColorMatrix []float32
|
lastColorMatrix []float32
|
||||||
lastColorMatrixTranslation []float32
|
lastColorMatrixTranslation []float32
|
||||||
|
lastTexture opengl.Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
var theOpenGLState openGLState
|
var theOpenGLState openGLState
|
||||||
|
var (
|
||||||
|
zeroProgram opengl.Program
|
||||||
|
zeroTexture opengl.Texture
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
indicesNum = 1 << 16
|
indicesNum = 1 << 16
|
||||||
@ -53,12 +58,12 @@ func Finalize(c *opengl.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *openGLState) initialize(c *opengl.Context) error {
|
func (s *openGLState) initialize(c *opengl.Context) error {
|
||||||
var zeroProgram opengl.Program
|
|
||||||
s.lastProgram = zeroProgram
|
s.lastProgram = zeroProgram
|
||||||
s.lastProjectionMatrix = nil
|
s.lastProjectionMatrix = nil
|
||||||
s.lastModelviewMatrix = nil
|
s.lastModelviewMatrix = nil
|
||||||
s.lastColorMatrix = nil
|
s.lastColorMatrix = nil
|
||||||
s.lastColorMatrixTranslation = nil
|
s.lastColorMatrixTranslation = nil
|
||||||
|
s.lastTexture = zeroTexture
|
||||||
|
|
||||||
shaderVertexModelviewNative, err := c.NewShader(c.VertexShader, shader(c, shaderVertexModelview))
|
shaderVertexModelviewNative, err := c.NewShader(c.VertexShader, shader(c, shaderVertexModelview))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -98,12 +103,12 @@ func (s *openGLState) initialize(c *opengl.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *openGLState) finalize(c *opengl.Context) error {
|
func (s *openGLState) finalize(c *opengl.Context) error {
|
||||||
var zeroProgram opengl.Program
|
|
||||||
s.lastProgram = zeroProgram
|
s.lastProgram = zeroProgram
|
||||||
s.lastProjectionMatrix = nil
|
s.lastProjectionMatrix = nil
|
||||||
s.lastModelviewMatrix = nil
|
s.lastModelviewMatrix = nil
|
||||||
s.lastColorMatrix = nil
|
s.lastColorMatrix = nil
|
||||||
s.lastColorMatrixTranslation = nil
|
s.lastColorMatrixTranslation = nil
|
||||||
|
s.lastTexture = zeroTexture
|
||||||
c.DeleteBuffer(s.indexBufferQuads)
|
c.DeleteBuffer(s.indexBufferQuads)
|
||||||
c.DeleteProgram(s.programTexture)
|
c.DeleteProgram(s.programTexture)
|
||||||
return nil
|
return nil
|
||||||
@ -135,7 +140,6 @@ func (p *programContext) begin() {
|
|||||||
c := p.context
|
c := p.context
|
||||||
if p.state.lastProgram != p.program {
|
if p.state.lastProgram != p.program {
|
||||||
c.UseProgram(p.program)
|
c.UseProgram(p.program)
|
||||||
var zeroProgram opengl.Program
|
|
||||||
if p.state.lastProgram != zeroProgram {
|
if p.state.lastProgram != zeroProgram {
|
||||||
c.DisableVertexAttribArray(p.state.lastProgram, "tex_coord")
|
c.DisableVertexAttribArray(p.state.lastProgram, "tex_coord")
|
||||||
c.DisableVertexAttribArray(p.state.lastProgram, "vertex")
|
c.DisableVertexAttribArray(p.state.lastProgram, "vertex")
|
||||||
@ -150,6 +154,7 @@ func (p *programContext) begin() {
|
|||||||
p.state.lastModelviewMatrix = nil
|
p.state.lastModelviewMatrix = nil
|
||||||
p.state.lastColorMatrix = nil
|
p.state.lastColorMatrix = nil
|
||||||
p.state.lastColorMatrixTranslation = nil
|
p.state.lastColorMatrixTranslation = nil
|
||||||
|
p.state.lastTexture = zeroTexture
|
||||||
c.BindElementArrayBuffer(p.state.indexBufferQuads)
|
c.BindElementArrayBuffer(p.state.indexBufferQuads)
|
||||||
c.UniformInt(p.program, "texture", 0)
|
c.UniformInt(p.program, "texture", 0)
|
||||||
}
|
}
|
||||||
@ -215,7 +220,10 @@ func (p *programContext) begin() {
|
|||||||
|
|
||||||
// We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture
|
// We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture
|
||||||
// See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml
|
// See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml
|
||||||
|
if p.state.lastTexture != p.texture {
|
||||||
c.BindTexture(p.texture)
|
c.BindTexture(p.texture)
|
||||||
|
p.state.lastTexture = p.texture
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *programContext) end() {
|
func (p *programContext) end() {
|
||||||
|
Loading…
Reference in New Issue
Block a user