Simplified for loops in render systems.

This commit is contained in:
Marvin Blum
2016-08-19 00:04:05 +02:00
parent 69886eff00
commit bc624295be
5 changed files with 42 additions and 42 deletions

View File

@@ -80,14 +80,14 @@ func (c *Culling2D) GetName() string {
// Updates visibility of all contained sprites. // Updates visibility of all contained sprites.
func (c *Culling2D) Update(delta float64) { func (c *Culling2D) Update(delta float64) {
for i := range c.cullables { for _, cullable := range c.cullables {
if c.cullables[i].Pos.X > c.viewport.Z || if cullable.Pos.X > c.viewport.Z ||
c.cullables[i].Pos.X+c.cullables[i].Size.X < c.viewport.X || cullable.Pos.X+cullable.Size.X < c.viewport.X ||
c.cullables[i].Pos.Y > c.viewport.W || cullable.Pos.Y > c.viewport.W ||
c.cullables[i].Pos.Y+c.cullables[i].Size.Y < c.viewport.Y { cullable.Pos.Y+cullable.Size.Y < c.viewport.Y {
c.cullables[i].Visible = false cullable.Visible = false
} else { } else {
c.cullables[i].Visible = true cullable.Visible = true
} }
} }
} }

View File

@@ -206,22 +206,22 @@ func (s *KeyframeRenderer) GetName() string {
// Updates animation state and renders sprites. // Updates animation state and renders sprites.
func (s *KeyframeRenderer) Update(delta float64) { func (s *KeyframeRenderer) Update(delta float64) {
// update animation state // update animation state
for i := range s.sprites { for _, sprite := range s.sprites {
if s.sprites[i].KeyframeAnimation == nil { if sprite.KeyframeAnimation == nil {
continue continue
} }
s.sprites[i].Interpolation += delta * s.sprites[i].KeyframeAnimation.Speed sprite.Interpolation += delta * sprite.KeyframeAnimation.Speed
if s.sprites[i].Interpolation > 1 { if sprite.Interpolation > 1 {
s.sprites[i].Interpolation = 0 sprite.Interpolation = 0
s.sprites[i].Current++ sprite.Current++
if s.sprites[i].Current > s.sprites[i].KeyframeAnimation.End { if sprite.Current > sprite.KeyframeAnimation.End {
if s.sprites[i].KeyframeAnimation.Loop { if sprite.KeyframeAnimation.Loop {
s.sprites[i].Current = s.sprites[i].KeyframeAnimation.Start sprite.Current = sprite.KeyframeAnimation.Start
} else { } else {
s.sprites[i].Current = s.sprites[i].KeyframeAnimation.End sprite.Current = sprite.KeyframeAnimation.End
} }
} }
} }
@@ -233,17 +233,17 @@ func (s *KeyframeRenderer) Update(delta float64) {
s.Shader.SendUniform1i(Default_shader_2D_tex, 0) s.Shader.SendUniform1i(Default_shader_2D_tex, 0)
s.vao.Bind() s.vao.Bind()
for i := range s.sprites { for _, sprite := range s.sprites {
if !s.sprites[i].Visible { if !sprite.Visible {
continue continue
} }
texCoord := s.sprites[i].KeyframeSet.Keyframes[s.sprites[i].Current].texCoord texCoord := sprite.KeyframeSet.Keyframes[sprite.Current].texCoord
texCoord.Bind() texCoord.Bind()
texCoord.AttribPointer(s.Shader.GetAttribLocation(Default_shader_2D_texcoord_attrib), 2, gl.FLOAT, false, 0) texCoord.AttribPointer(s.Shader.GetAttribLocation(Default_shader_2D_texcoord_attrib), 2, gl.FLOAT, false, 0)
s.Shader.SendMat3(Default_shader_2D_model, *s.sprites[i].CalcModel()) s.Shader.SendMat3(Default_shader_2D_model, *sprite.CalcModel())
s.sprites[i].Tex.Bind() sprite.Tex.Bind()
gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil) gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil)
} }

View File

@@ -174,20 +174,20 @@ func (s *ModelRenderer) Update(delta float64) {
var tid uint32 var tid uint32
for i := range s.models { for _, model := range s.models {
if !s.models[i].Visible { if !model.Visible {
continue continue
} }
s.Shader.SendMat4(Default_shader_3D_model, *s.models[i].CalcModel()) s.Shader.SendMat4(Default_shader_3D_model, *model.CalcModel())
s.models[i].Vao.Bind() model.Vao.Bind()
// prevent texture switching when not neccessary // prevent texture switching when not neccessary
if tid != s.models[i].Tex.GetId() { if tid != model.Tex.GetId() {
tid = s.models[i].Tex.GetId() tid = model.Tex.GetId()
s.models[i].Tex.Bind() model.Tex.Bind()
} }
gl.DrawElements(gl.TRIANGLES, s.models[i].Index.Size(), gl.UNSIGNED_INT, nil) gl.DrawElements(gl.TRIANGLES, model.Index.Size(), gl.UNSIGNED_INT, nil)
} }
} }

View File

@@ -140,17 +140,17 @@ func (s *SpriteRenderer) Update(delta float64) {
s.vao.Bind() s.vao.Bind()
var tid uint32 var tid uint32
for i := range s.sprites { for _, sprite := range s.sprites {
if !s.sprites[i].Visible { if !sprite.Visible {
continue continue
} }
s.Shader.SendMat3(Default_shader_2D_model, *s.sprites[i].CalcModel()) s.Shader.SendMat3(Default_shader_2D_model, *sprite.CalcModel())
// prevent texture switching when not neccessary // prevent texture switching when not neccessary
if tid != s.sprites[i].Tex.GetId() { if tid != sprite.Tex.GetId() {
tid = s.sprites[i].Tex.GetId() tid = sprite.Tex.GetId()
s.sprites[i].Tex.Bind() sprite.Tex.Bind()
} }
gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil) gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil)

12
text.go
View File

@@ -423,15 +423,15 @@ func (r *TextRenderer) Update(delta float64) {
r.Shader.SendUniform1i(Default_shader_text_tex, 0) r.Shader.SendUniform1i(Default_shader_text_tex, 0)
r.Font.Tex.Bind() r.Font.Tex.Bind()
for i := range r.texts { for _, text := range r.texts {
if !r.texts[i].Visible { if !text.Visible {
continue continue
} }
r.texts[i].vao.Bind() text.vao.Bind()
r.Shader.SendUniform4f(Default_shader_text_color, float32(r.texts[i].Color.X), float32(r.texts[i].Color.Y), float32(r.texts[i].Color.Z), float32(r.texts[i].Color.W)) r.Shader.SendUniform4f(Default_shader_text_color, float32(text.Color.X), float32(text.Color.Y), float32(text.Color.Z), float32(text.Color.W))
r.Shader.SendMat3(Default_shader_text_model, *r.texts[i].CalcModel()) r.Shader.SendMat3(Default_shader_text_model, *text.CalcModel())
gl.DrawElements(gl.TRIANGLES, r.texts[i].index.Size(), gl.UNSIGNED_INT, nil) gl.DrawElements(gl.TRIANGLES, text.index.Size(), gl.UNSIGNED_INT, nil)
} }
} }