public VertexDeclaration GetDeclaration <T>(GraphicsDevice device) { ValidateDevice(device); int index = Ident.TypeIndex <T>(); while (index > this.declarations.Length) { Array.Resize(ref this.declarations, this.declarations.Length * 2); } if (this.declarations[index] != null) { return(this.declarations[index]); } VertexElement[] elements = GetDeclaration(typeof(T)); if (device == null) { return(null); } VertexDeclaration declaration; lock (hashingDecl) { hashingDecl.SetFrom(typeof(T), typeHash, ref typeIndex); if (declarationHash.TryGetValue(hashingDecl, out declaration)) { this.declarations[index] = declaration; return(declaration); } } for (int i = 0; i < elements.Length; i++) { ValidateFormat(typeof(T), elements[i].VertexElementFormat); } ElementHash ehash = new ElementHash(elements); elementHash.TryGetValue(ehash, out declaration); if (declaration == null) { declaration = new VertexDeclaration(device, elements); } this.declarations[index] = declaration; declarationHash.Add(new DeclarationHash(typeof(T), typeHash, ref typeIndex), declaration); if (elementHash.ContainsKey(ehash) == false) { elementHash.Add(ehash, declaration); } return(declaration); }
public VertexDeclaration GetDeclaration <T>() { int index = Ident.TypeIndex <T>(); while (index > _declarations.Length) { Array.Resize(ref _declarations, _declarations.Length * 2); } if (_declarations[index] != null) { return(_declarations[index]); } VertexElement[] elements = GetDeclaration(typeof(T)); if (_context == null) { return(null); } VertexDeclaration declaration; lock (_hashingDecl) { _hashingDecl.SetFrom(typeof(T), _typeHash, ref _typeIndex); if (_declarationHash.TryGetValue(_hashingDecl, out declaration)) { _declarations[index] = declaration; return(declaration); } } for (int i = 0; i < elements.Length; i++) { ValidateFormat(typeof(T), elements[i].Type); } ElementHash ehash = new ElementHash(elements); _elementHash.TryGetValue(ehash, out declaration); if (declaration == null) { declaration = new VertexDeclaration(_context, elements); } _declarations[index] = declaration; _declarationHash.Add(new DeclarationHash(typeof(T), _typeHash, ref _typeIndex), declaration); if (_elementHash.ContainsKey(ehash) == false) { _elementHash.Add(ehash, declaration); } return(declaration); }