/* * TextureSizeProcessor.cs * Authors: Mike DeMauro * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content.Pipeline; using Microsoft.Xna.Framework.Content.Pipeline.Graphics; using Microsoft.Xna.Framework.Content.Pipeline.Processors; using TInput = Microsoft.Xna.Framework.Content.Pipeline.Graphics.TextureContent; using TOutput = Microsoft.Xna.Framework.Content.Pipeline.Graphics.TextureContent; namespace ContentPipelineExtension { /// /// This class will be instantiated by the XNA Framework Content Pipeline /// to apply custom processing to content data, converting an object of /// type TInput to TOutput. The input and output types may be the same if /// the processor wishes to alter data without changing its type. /// /// This should be part of a Content Pipeline Extension Library project. /// [ContentProcessor(DisplayName = "ContentPipelineExtension.TextureSizeProcessor")] public class TextureSizeProcessor : TextureProcessor { /// /// These values should be set to the smallest maximum size that will be supported. /// /// /// Maximum width allowed for a texture. /// const int MAX_WIDTH = 2048; /// /// Maximum height allowed for a texture. /// const int MAX_HEIGHT = 2048; public override TOutput Process(TInput input, ContentProcessorContext context) { BitmapContent bmp = input.Faces[0][0]; if (bmp.Width > MAX_WIDTH || bmp.Height > MAX_HEIGHT) throw new Exception("Texture '" + context.OutputFilename + "' exceeds maximum dimensions: " + MAX_WIDTH + "x" + MAX_HEIGHT); return base.Process(input, context); } } }