///<summary> /// Find the suitable bucket for the quad in the list of /// buckets. If create is false and you don't find it in /// the list, create the bucket and add it to the list. /// If create is false and the bucket doesn't exist, return /// null. ///</summary> public QuadBucket FindBucketForQuad(QuadInfo quad, List <QuadBucket> buckets, bool create) { float z = quad.z; int textureHandle = quad.texture.Handle; int hashCode = (quad.clipRect != null ? quad.clipRect.GetHashCode() : 0); QuadBucket quadBucket = null; foreach (QuadBucket bucket in quadBuckets) { if (bucket.z == z && bucket.textureHandle == textureHandle && bucket.clipRectHash == hashCode) { quadBucket = bucket; break; } } if (create && quadBucket == null) { quadBucket = new QuadBucket(z, textureHandle, hashCode, this); buckets.Add(quadBucket); } return(quadBucket); }
///<summary> /// The TextureAndClipRect value is interned, so we can just /// look it up, and don't have to iterate. ///</summary> public void AddQuad(QuadInfo quad) { QuadBucket quadBucket = FindBucketForQuad(quad, quadBuckets, true); quadBucket.quads.Add(quad); }