zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

locationcache.go (1435B)


      1 // Copyright 2014 Hajime Hoshi
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package opengl
     16 
     17 // Since js.Object (Program) can't be keys of a map, use integers (programID) instead.
     18 
     19 type locationCache struct {
     20 	uniformLocationCache map[programID]map[string]uniformLocation
     21 }
     22 
     23 func newLocationCache() *locationCache {
     24 	return &locationCache{
     25 		uniformLocationCache: map[programID]map[string]uniformLocation{},
     26 	}
     27 }
     28 
     29 func (c *locationCache) GetUniformLocation(context *context, p program, location string) uniformLocation {
     30 	id := getProgramID(p)
     31 	if _, ok := c.uniformLocationCache[id]; !ok {
     32 		c.uniformLocationCache[id] = map[string]uniformLocation{}
     33 	}
     34 	l, ok := c.uniformLocationCache[id][location]
     35 	if !ok {
     36 		l = context.getUniformLocationImpl(p, location)
     37 		c.uniformLocationCache[id][location] = l
     38 	}
     39 	return l
     40 }
     41 
     42 func (c *locationCache) deleteProgram(p program) {
     43 	delete(c.uniformLocationCache, getProgramID(p))
     44 }