// Get a back-buffer-sized quadrilateral public VertexInput[] GetBackBufferQuad() { // Entry logging #if IS_LOGGING_METHODS Log.Write(String.Format("Entering method for {0}", this.Name)); #endif // Initialize result VertexInput[] vertices = new VertexInput[4]; // Get back buffer dimensions int w = this.BackBuffer.Width; int h = this.BackBuffer.Height; // Create vertices vertices[0] = new VertexInput(new Vector2(0, 0), Color.White, new Vector2(0, 0)); vertices[1] = new VertexInput(new Vector2(w, 0), Color.White, new Vector2(1, 0)); vertices[2] = new VertexInput(new Vector2(w, h), Color.White, new Vector2(1, 1)); vertices[3] = new VertexInput(new Vector2(0, h), Color.White, new Vector2(0, 1)); // Exit logging #if IS_LOGGING_METHODS Log.Write(String.Format("Exiting method for {0}", this.Name)); #endif // Return result return(vertices); }
// Update vertex and index buffers public void UpdateBuffers() { // Entry logging #if IS_LOGGING_METHODS Log.Write(String.Format("Entering method for {0}", this.Name)); #endif // Create an array of vertex data VertexInput[] vertexData = new VertexInput[this.VertexCount]; // Create an array of index data int[] indexData = new int[this.IndexCount]; // Initialize i, the current sprite index int i = 0; // Initialize k1, the current vertex index offset int k1 = 0; // Initialize k2, the current index index offset int k2 = 0; // Loop over sprites while (i < this.SpriteCount) { // Get the current sprite's vertices VertexInput[] vertices = this.Sprites[i].Vertices; // Get the current sprite's indices int[] indices = this.Sprites[i].Indices; // Get the current sprite's vertex count int n1 = vertices.Length; // Get the current sprite's index count int n2 = indices.Length; // Add vertices for (int j = 0; j < n1; j++) { vertexData[k1 + j] = vertices[j]; } // Add indices for (int j = 0; j < n2; j++) { indexData[k2 + j] = k1 + indices[j]; } // Increment vertex offset k1 += n1; // Increment index offset k2 += n2; // Increment sprite i++; } // Check vertex buffer size if (this.VertexCount > this.VertexBuffer.VertexCount) { // If too small, expand // First, calculate new size int newSize = (int)Math.Ceiling((double)this.VertexCount / (4 * this.ExtensionSize) + 1) * (4 * this.ExtensionSize); // Log #if IS_LOGGING_DRAW Log.Write(String.Format("WARNING: Layer {0}'s vertex buffer is too small! inboundSize = {1}, bufferSize = {2}, newSize = {3}", this.Name, this.VertexCount, this.VertexBuffer.VertexCount, n)); #endif // Create a new, expanded buffer this.VertexBuffer = new WrappedVertexBuffer(newSize); } // Check index buffer size if (this.IndexCount > this.IndexBuffer.IndexCount) { // If too small, expand // First, calculate new size int newSize = (int)Math.Ceiling((double)this.VertexCount / (6 * this.ExtensionSize) + 1) * (6 * this.ExtensionSize); // Log #if IS_LOGGING_DRAW Log.Write(String.Format("WARNING: Layer {0}'s index buffer is too small! inboundSize = {1}, bufferSize = {2}, newSize = {3}", this.Name, this.IndexCount, this.IndexBuffer.IndexCount, n)); #endif // Create a new, expanded buffer this.IndexBuffer = new WrappedIndexBuffer(newSize); } //Trace.WriteLine("vd = " + vertexData.Length); //Trace.WriteLine("vb = " + this.vertexBuffer.VertexCount); //Trace.WriteLine("id = " + indexData.Length); //Trace.WriteLine("ib = " + this.indexBuffer.IndexCount); // Send data to vertex buffer this.VertexBuffer.SetData(vertexData); // Send data to index buffer this.IndexBuffer.SetData(indexData); // Temporary: Save data for debugging purposes this.vertices = vertexData; this.indices = indexData; // Exit logging #if IS_LOGGING_METHODS Log.Write(String.Format("Exiting method for {0}", this.Name)); #endif }