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); }
public VertexDeclaration GetDeclaration(VertexElement[] elements) { VertexDeclaration declaration; ElementHash ehash = new ElementHash(elements); if (_elementHash.TryGetValue(ehash, out declaration)) { return(declaration); } declaration = new VertexDeclaration(_context, elements); _elementHash.Add(ehash, declaration); return(declaration); }
public VertexDeclaration GetDeclaration(GraphicsDevice device, VertexElement[] elements) { ValidateDevice(device); VertexDeclaration declaration; ElementHash ehash = new ElementHash(elements); if (elementHash.TryGetValue(ehash, out declaration)) { return(declaration); } declaration = new VertexDeclaration(device, elements); elementHash.Add(ehash, declaration); return(declaration); }
public VertexDeclaration GetDeclaration(Type[] streamTypes, IVertices[] buffers) { VertexDeclaration declaration; lock (_hashingDecl) { _hashingDecl.SetFrom(streamTypes, _typeHash, ref _typeIndex); if (_declarationHash.TryGetValue(_hashingDecl, out declaration)) { return(declaration); } } VertexElement[][] mappings = new VertexElement[streamTypes.Length][]; int i = 0; for (i = 0; i < streamTypes.Length; i++) { //buffer provides the vertex elements itself if (buffers[i] is IDeviceVertexBuffer && (buffers[i] as IDeviceVertexBuffer).IsImplementationUserSpecifiedVertexElements(out mappings[i])) { continue; } mappings[i] = GetDeclaration(streamTypes[i]); } List <VertexElement> mapping = new List <VertexElement>(); short stream = 0; foreach (VertexElement[] map in mappings) { foreach (VertexElement el in map) { bool skip = false; foreach (VertexElement check in mapping) { if (el.UsageIndex == check.UsageIndex && el.Usage == check.Usage) { skip = true; break; } } if (skip) { continue; } VertexElement v = el; v.Stream = stream; mapping.Add(v); } stream++; } VertexElement[] elements = mapping.ToArray(); ElementHash ehash = new ElementHash(elements); _elementHash.TryGetValue(ehash, out declaration); if (declaration == null) { declaration = new VertexDeclaration(_context, elements); } _declarationHash.Add(new DeclarationHash(streamTypes, _typeHash, ref _typeIndex), declaration); if (_elementHash.ContainsKey(ehash) == false) { _elementHash.Add(ehash, declaration); } return(declaration); }