Skip to content

Commit

Permalink
Reverted previous commit, now share the same Model but create unique …
Browse files Browse the repository at this point in the history
…vertex arrays
  • Loading branch information
lilleyse committed Oct 21, 2015
1 parent bc10897 commit 948ad72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 15 additions & 0 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,11 @@ define([
resources.textures = cachedResources.textures;
resources.samplers = cachedResources.samplers;
resources.renderStates = cachedResources.renderStates;

// Vertex arrays are unique to this model, create instead of using the cache.
if (defined(model._precreatedAttributes)) {
createVertexArrays(model, context);
}
} else {
createDecompressedViews(model, context);
createBuffers(model, context, frameState); // using glTF bufferViews
Expand Down Expand Up @@ -3302,6 +3307,11 @@ define([
cachedResources.renderStates = resources.renderStates;
cachedResources.ready = true;

// Vertex arrays are unique to this model, do not store in cache.
if (defined(this._precreatedAttributes)) {
cachedResources.vertexArrays = {};
}

if (this.releaseGltfJson) {
releaseCachedGltf(this);
}
Expand Down Expand Up @@ -3422,6 +3432,11 @@ define([
* model = model && model.destroy();
*/
Model.prototype.destroy = function() {
// Vertex arrays are unique to this model, destroy here.
if (defined(this._precreatedAttributes)) {
destroy(this._rendererResources.vertexArrays);
}

this._rendererResources = undefined;
this._cachedRendererResources = this._cachedRendererResources && this._cachedRendererResources.release();

Expand Down
7 changes: 3 additions & 4 deletions Source/Scene/ModelInstanceCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ define([
cacheKey : undefined,
asynchronous : collection._asynchronous,
allowPicking : collection._allowPicking,
releaseGltfJson : false,
precreatedAttributes : undefined,
vertexShaderLoaded : undefined,
fragmentShaderLoaded : undefined,
Expand Down Expand Up @@ -594,10 +593,10 @@ define([
modelOptions.pickFragmentShaderLoaded = getPickFragmentShaderCallback(collection);
modelOptions.pickUniformMapLoaded = getPickUniformMapCallback(collection);
modelOptions.ignoreCommands = true;
modelOptions.releaseGltfJson = true;

// Collections cannot share the same models, so create a unique cache key
modelOptions.cacheKey = 'ModelInstanceCollection' + Math.random();
if (defined(collection._url)) {
modelOptions.cacheKey = collection._url + '#instanced';
}
} else {
modelOptions.fragmentShaderLoaded = getFragmentShaderNonInstancedCallback();
}
Expand Down

0 comments on commit 948ad72

Please sign in to comment.