Exemplo n.º 1
0
// Launch this in its own go-routine if you want to occassionally
// delete textures that haven't been used in a while.
func (m *Manager) Scavenger() {
	var unused []string
	for {
		time.Sleep(time.Minute)
		unused = unused[0:0]
		m.mutex.RLock()
		for s, d := range m.registry {
			if generation-d.accessed >= 2 {
				unused = append(unused, s)
			}
		}
		m.mutex.RUnlock()

		m.mutex.Lock()
		generation++
		if len(unused) == 0 {
			m.mutex.Unlock()
			continue
		}

		var unused_data []*Data
		for _, s := range unused {
			unused_data = append(unused_data, m.registry[s])
			m.deleted[s] = m.registry[s]
			delete(m.registry, s)
		}
		render.Queue(func() {
			for _, d := range unused_data {
				gl.DeleteTextures(1, (*gl.Uint)(&d.texture))
				d.texture = 0
			}
		})
		m.mutex.Unlock()
	}
}
Exemplo n.º 2
0
func reuploadTexture(tex *gl.Uint, w, h int, data []byte) {
	if *tex > 0 {
		gl.BindTexture(gl.TEXTURE_2D, *tex)
		gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.Sizei(w), gl.Sizei(h), 0,
			gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))
		if gl.GetError() != gl.NO_ERROR {
			gl.DeleteTextures(1, tex)
			panic("Failed to reupload texture")
		}
		return
	}
	*tex = uploadTexture_RGBA32(w, h, data)
}
Exemplo n.º 3
0
func uploadTexture_RGBA32(w, h int, data []byte) gl.Uint {
	var id gl.Uint
	gl.GenTextures(1, &id)
	gl.BindTexture(gl.TEXTURE_2D, id)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_R, gl.CLAMP_TO_EDGE)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.Sizei(w), gl.Sizei(h), 0, gl.RGBA,
		gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))

	if gl.GetError() != gl.NO_ERROR {
		gl.DeleteTextures(1, &id)
		panic("Failed to load a texture")
	}
	return id
}
Exemplo n.º 4
0
func (s *sheet) loadRoutine() {
	ready := make(chan bool, 1)
	pixer := make(chan []byte)
	for load := range s.load_chan {
		if load {
			go s.compose(pixer)
			go func() {
				render.Queue(func() {
					s.makeTexture(pixer)
					ready <- true
				})
			}()
		} else {
			go func() {
				<-ready
				render.Queue(func() {
					gl.DeleteTextures(1, &s.texture)
					s.texture = 0
				})
			}()
		}
	}
}
Exemplo n.º 5
0
func destroyScene() {
	gl.DeleteTextures(1, &texture)
}
Exemplo n.º 6
0
func (m *Model) destroy() {
	gl.DeleteBuffers(1, &m.buffer)
	gl.DeleteBuffers(1, &m.index)
	gl.DeleteTextures(1, &m.texture_id)
	m.shader.destroy()
}
Exemplo n.º 7
0
func CloseTextures() {
	gl.DeleteTextures(1, &texture)
}