Skip to content

Commit

Permalink
Merge branch 'contextObjectCache' into oneTexturePerLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Feb 22, 2013
2 parents 1ff9d1d + 15e2008 commit bdf584d
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,12 @@ define([
function getDirectionsVertexBuffer(context) {
var sixteenK = 16 * 1024;

// Per-context cache for billboard collections
context._primitivesCache = context._primitivesCache || {};
var primitivesCache = context._primitivesCache;
primitivesCache._billboardCollection = primitivesCache._billboardCollection || {};
var c = primitivesCache._billboardCollection;
var c = getContextCache(context);

if (c.directionsVertexBuffer) {
if (typeof c.directionsVertexBuffer !== 'undefined') {
return c.directionsVertexBuffer;
}

c.directionsVertexBuffer = c.directionsVertexBuffer && c.directionsVertexBuffer.destroy();

var directions = new Uint8Array(sixteenK * 4 * 2);
for (var i = 0, j = 0; i < sixteenK; ++i) {
directions[j++] = 0;
Expand All @@ -588,13 +582,9 @@ define([
function getIndexBuffer(context) {
var sixteenK = 16 * 1024;

// Per-context cache for billboard collections
context._primitivesCache = context._primitivesCache || {};
var primitivesCache = context._primitivesCache;
primitivesCache._billboardCollection = primitivesCache._billboardCollection || {};
var c = primitivesCache._billboardCollection;
var c = getContextCache(context);

if (c.indexBuffer) {
if (typeof c.indexBuffer !== 'undefined') {
return c.indexBuffer;
}

Expand All @@ -617,6 +607,26 @@ define([
return c.indexBuffer;
}

function getContextCache(context) {
// Per-context cache for billboard collections
var c = context.cache.billboardCollection;
if (typeof c === 'undefined') {
c = context.cache.billboardCollection = {
directionsVertexBuffer : undefined,
indexBuffer : undefined,
destroy : function() {
if (typeof this.directionsVertexBuffer !== 'undefined') {
this.directionsVertexBuffer.destroy();
}
if (typeof this.indexBuffer !== 'undefined') {
this.indexBuffer.destroy();
}
}
};
}
return c;
}

BillboardCollection.prototype.computeNewBuffersUsage = function() {
var buffersUsage = this._buffersUsage;
var usageChanged = false;
Expand Down

0 comments on commit bdf584d

Please sign in to comment.