public override List <Vertices> Process(TextureContent input, ContentProcessorContext context)
        {
            BitmapContent bitmap = input.Faces[0][0];

            byte[] bytes = bitmap.GetPixelData();
            Debug.Assert(bytes.Length % 4 == 0);

            // Note(manu): If this were C/C++, we could simply reinterpret the byte-array as a uint-array...
            uint[] data = new uint[bytes.Length / 4];
            for (int dataIndex = 0; dataIndex < data.Length; dataIndex++)
            {
                int byteIndex = dataIndex * 4;
                data[dataIndex] = BitConverter.ToUInt32(bytes, byteIndex);
            }

            DateTime         vertStart        = DateTime.Now;
            TextureConverter textureConverter = new TextureConverter(data, bitmap.Width)
            {
                PolygonDetectionType    = PolygonDetectionType,
                HoleDetection           = HoleDetection,
                MultipartDetection      = MultipartDetection,
                PixelOffsetOptimization = PixelOffsetOptimization,
                Transform      = Matrix.CreateScale(UniformScale * Conversion.RenderScale), // TODO(manu): Use z=1 instead?
                AlphaTolerance = (byte)AlphaTolerance,
                HullTolerance  = HullTolerance,
            };
            List <Vertices> vertices     = textureConverter.DetectVertices();
            TimeSpan        vertDuration = DateTime.Now - vertStart;

            Diagnostic(context.Logger, $"Parsing vertices took {vertDuration.TotalSeconds.ToString("0.000")} seconds (VelcroPhysics).");

            return(vertices);
        }
        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!this.ForceDXT5)
            {
                return(base.Process(input, context));
            }

            TextureContent ret = null;
            TextureProcessorOutputFormat fmt = this.TextureFormat;

            this.TextureFormat = TextureProcessorOutputFormat.NoChange;
            try
            {
                ret = base.Process(input, context);
                Type originalType = ret.Faces[0][0].GetType();
                if (originalType != typeof(Dxt5BitmapContent))
                {
                    ret.ConvertBitmapType(typeof(Dxt5BitmapContent));
                }
            }
            finally
            {
                this.TextureFormat = fmt;
            }
            return(ret);
        }
        private void SaveAndVerifyFrame(TextureContent frame, string name)
        {
            var expectedFile = $"{ OutputPath }/{ name }.png";

            if (File.Exists(expectedFile))
            {
                using (var expectedStream = File.OpenRead(expectedFile))
                {
                    var expectedImage = new Image(expectedStream);

                    try
                    {
                        Assert.Equal(expectedImage.PixelWidth, frame.Width);
                        Assert.Equal(expectedImage.PixelHeight, frame.Height);
                        Assert.Equal(expectedImage.Pixels, frame.Pixels);
                        return;
                    }
                    catch
                    {
                        SaveFrame(frame, $"{ OutputPath }/{ name }.actual.png", true);
                        throw;
                    }
                }
            }

            SaveFrame(frame, expectedFile);
        }
        /// <summary>
        /// Converts an array of sprite filenames into a sprite sheet object.
        /// </summary>
        public override SpriteSheetContent Process(string[] input,
                                                   ContentProcessorContext context)
        {
            SpriteSheetContent   spriteSheet   = new SpriteSheetContent();
            List <BitmapContent> sourceSprites = new List <BitmapContent>();

            // Loop over each input sprite filename.
            foreach (string inputFilename in input)
            {
                // Store the name of this sprite.
                string spriteName = Path.GetFileNameWithoutExtension(inputFilename);

                spriteSheet.SpriteNames.Add(spriteName, sourceSprites.Count);

                // Load the sprite texture into memory.
                ExternalReference <TextureContent> textureReference =
                    new ExternalReference <TextureContent>(inputFilename);

                TextureContent texture =
                    context.BuildAndLoadAsset <TextureContent,
                                               TextureContent>(textureReference, "TextureProcessor");

                sourceSprites.Add(texture.Faces[0][0]);
            }

            // Pack all the sprites into a single large texture.
            BitmapContent packedSprites = SpritePacker.PackSprites(sourceSprites,
                                                                   spriteSheet.SpriteRectangles, context);

            spriteSheet.Texture.Mipmaps.Add(packedSprites);

            return(spriteSheet);
        }
Esempio n. 5
0
    public override TextureContent Process(TextureContent input, ContentProcessorContext context)
    {
        TextureContent data = base.Process(input, context);

        // Convert data
        return(data);
    }
        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            // Fallback if we aren't buiding for iOS.
            var platform = ContentHelper.GetMonoGamePlatform();

            if (platform != MonoGamePlatform.iOS)
            {
                return(base.Process(input, context));
            }

            // Only go this path if we are compressing the texture
            if (TextureFormat != TextureProcessorOutputFormat.DxtCompressed)
            {
                return(base.Process(input, context));
            }

            // TODO: Reflector ResizeToPowerOfTwo(TextureContent tex)
            // Resize the first face and let mips get generated from the dll.

            /*if (ResizeToPowerOfTwo)
             * {
             *
             * }*/

            var height    = input.Faces[0][0].Height;
            var width     = input.Faces[0][0].Width;
            var mipLevels = 1;

            var invalidBounds = height != width || !(isPowerOfTwo(height) && isPowerOfTwo(width));

            // Only PVR compress square, power of two textures.
            if (invalidBounds || compressionMode == MGCompressionMode.NoCompression)
            {
                if (compressionMode != MGCompressionMode.NoCompression)
                {
                    context.Logger.LogImportantMessage("WARNING: PVR Texture {0} must be a square, power of two texture. Skipping Compression.",
                                                       Path.GetFileName(context.OutputFilename));
                }

                // Skip compressing this texture and process it normally.
                this.TextureFormat = TextureProcessorOutputFormat.Color;

                return(base.Process(input, context));
            }

            // Calculate how many mip levels will be created, and pass that to our DLL.
            if (GenerateMipmaps)
            {
                while (height != 1 || width != 1)
                {
                    height = Math.Max(height / 2, 1);
                    width  = Math.Max(width / 2, 1);
                    mipLevels++;
                }
            }

            ConvertToPVRTC(input, mipLevels, PremultiplyAlpha, compressionMode);

            return(input);
        }
Esempio n. 7
0
        internal static void ChangeTextureToRequestedFormat(TextureContent texture,
                                                            Type originalType,
                                                            TextureProcessorOutputFormat textureFormat)
        {
            switch (textureFormat)
            {
            case TextureProcessorOutputFormat.NoChange:
                if (originalType == null)
                {
                    break;
                }
                texture.ConvertBitmapType(originalType);
                return;

            case TextureProcessorOutputFormat.Color:
                texture.ConvertBitmapType(typeof(PixelBitmapContent <Color>));
                return;

            case TextureProcessorOutputFormat.DxtCompressed:
                BestGuessCompress(texture);
                break;

            default:
                return;
            }
        }
Esempio n. 8
0
        private TextureContent GenerateCubemap(TextureContent input, ContentProcessorContext context)
        {
            if (input.Faces[1].Count != 0)
            {
                //its already a cubemap
                return(base.Process(input, context));
            }
            TextureCubeContent cubeContent = new TextureCubeContent();

            // Convert the input data to Color format, for ease of processing.
            input.ConvertBitmapType(typeof(PixelBitmapContent <Color>));

            int height = input.Faces[0][0].Height;
            int width  = input.Faces[0][0].Width / 6;

            //split the image into 6 pieces, setup: X+,X-, Y+,Y-, Z+, Z-
            cubeContent.Faces[(int)CubeMapFace.PositiveX] = CreateFace(input.Faces[0][0], width, height, 0);
            cubeContent.Faces[(int)CubeMapFace.NegativeX] = CreateFace(input.Faces[0][0], width, height, width * 1);
            cubeContent.Faces[(int)CubeMapFace.PositiveY] = CreateFace(input.Faces[0][0], width, height, width * 2);
            cubeContent.Faces[(int)CubeMapFace.NegativeY] = CreateFace(input.Faces[0][0], width, height, width * 3);
            cubeContent.Faces[(int)CubeMapFace.PositiveZ] = CreateFace(input.Faces[0][0], width, height, width * 4);
            cubeContent.Faces[(int)CubeMapFace.NegativeZ] = CreateFace(input.Faces[0][0], width, height, width * 5);

            // Calculate mipmap data.
            cubeContent.GenerateMipmaps(true);

            // Compress the cubemap into DXT1 format.
            cubeContent.ConvertBitmapType(typeof(Dxt1BitmapContent));
            return(cubeContent);
        }
Esempio n. 9
0
 /// <summary>
 /// UnloadContent will be called once per game and is the place to unload
 /// game-specific content.
 /// </summary>
 protected override void UnloadContent()
 {
     DebugLog.LogInfo("Flushed all Textures and unloaded all content.");
     // TODO: Unload any non ContentManager content here
     TextureContent.FlushAllTextures();
     FontContent.FlushAllFonts();
 }
Esempio n. 10
0
 private static void CheckDdsFace(TextureContent content, int faceIndex, int mipMapCount, int width, int height)
 {
     Assert.AreEqual(content.Faces[faceIndex].Count, mipMapCount);
     for (int i = 0; i < mipMapCount; ++i)
     {
         Assert.AreEqual(content.Faces[faceIndex][i].Width, width >> i);
         Assert.AreEqual(content.Faces[faceIndex][i].Height, height >> i);
     }
 }
        public RendererParameters(SpriteBatch spriteBatch, Rectangle viewportRectangle, TextureContent textureContent)
        {
            spriteBatch.ThrowIfNull("spriteBatch");
            textureContent.ThrowIfNull("textureContent");

            _spriteBatch = spriteBatch;
            _viewportRectangle = viewportRectangle;
            _textureContent = textureContent;
        }
        public RendererParameters(SpriteBatch spriteBatch, Rectangle viewportRectangle, TextureContent textureContent)
        {
            spriteBatch.ThrowIfNull("spriteBatch");
            textureContent.ThrowIfNull("textureContent");

            _spriteBatch       = spriteBatch;
            _viewportRectangle = viewportRectangle;
            _textureContent    = textureContent;
        }
Esempio n. 13
0
 private static void BestGuessCompress(TextureContent texture)
 {
     texture.ConvertBitmapType(typeof(PixelBitmapContent <Color>));
     if (!(texture is Texture3DContent))
     {
         texture.ConvertBitmapType(HasFractionalAlpha(texture)
                                       ? typeof(Dxt5BitmapContent)
                                       : typeof(Dxt1BitmapContent));
     }
 }
        private TextureContent ExpandMonoTexture(TextureContent texture)
        {
            var pixels = new byte[texture.Width * texture.Height * 4];

            for (var i = 0; i < texture.Pixels.Length; i++)
            {
                pixels[i * 4 + 0] = pixels[i * 4 + 1] = pixels[i * 4 + 2] = texture.Pixels[i];
                pixels[i * 4 + 3] = 255;
            }
            return(new TextureContent(texture.Width, texture.Height, pixels, texture.IsTransparent));
        }
Esempio n. 15
0
        public RendererParameters(IXnaGameTime gameTime, SpriteBatch spriteBatch, FontContent fontContent, TextureContent textureContent)
        {
            gameTime.ThrowIfNull("gameTime");
            spriteBatch.ThrowIfNull("spriteBatch");
            fontContent.ThrowIfNull("fontContent");
            textureContent.ThrowIfNull("textureContent");

            _gameTime       = gameTime;
            _spriteBatch    = spriteBatch;
            _fontContent    = fontContent;
            _textureContent = textureContent;
        }
        public RendererParameters(IXnaGameTime gameTime, SpriteBatch spriteBatch, FontContent fontContent, TextureContent textureContent)
        {
            gameTime.ThrowIfNull("gameTime");
            spriteBatch.ThrowIfNull("spriteBatch");
            fontContent.ThrowIfNull("fontContent");
            textureContent.ThrowIfNull("textureContent");

            _gameTime = gameTime;
            _spriteBatch = spriteBatch;
            _fontContent = fontContent;
            _textureContent = textureContent;
        }
Esempio n. 17
0
        public void Render(SpriteBatch spriteBatch, Rectangle viewRectangle, TextureContent textureContent)
        {
            spriteBatch.ThrowIfNull("spriteBatch");
            textureContent.ThrowIfNull("textureContent");

            // Must call ToArray() because collection could be modified during iteration
            foreach (IRenderer renderer in _renderers.ToArray())
            {
                var parameters = new RendererParameters(spriteBatch, viewRectangle, textureContent);

                renderer.Render(parameters);
            }
        }
        public TextureContent AddTexture(string name)
        {
            TextureContent tex = new TextureContent(name);

            if (!_textures.Contains(tex))
            {
                _textures.Add(tex);
                return(tex);
            }
            int index = _textures.IndexOf(tex);

            return(_textures[index]);
        }
        public override Texture <int> CreateTexture(TextureContent data)
        {
            GLDebug.CheckAccess();

            var texture = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texture);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Pixels);

            return(new Texture <int>(texture, data.Width, data.Height, data.Left, data.Right, data.Top, data.Bottom, data.IsTransparent));
        }
        public void Render(SpriteBatch spriteBatch, Rectangle viewRectangle, TextureContent textureContent)
        {
            spriteBatch.ThrowIfNull("spriteBatch");
            textureContent.ThrowIfNull("textureContent");

            // Must call ToArray() because collection could be modified during iteration
            foreach (IRenderer renderer in _renderers.ToArray())
            {
                var parameters = new RendererParameters(spriteBatch, viewRectangle, textureContent);

                renderer.Render(parameters);
            }
        }
Esempio n. 21
0
        public override Texture <SharpDX.Direct3D12.Resource> CreateTexture(TextureContent data)
        {
            DXDebug.CheckAccess(graphicsHost.Device);

            SharpDX.Direct3D12.Resource texture = null;

            var textureDesc = ResourceDescription.Texture2D(Format.R8G8B8A8_UNorm, data.Width, data.Height);

            texture = graphicsHost.Device.CreateCommittedResource(new HeapProperties(HeapType.Default), HeapFlags.None, textureDesc, ResourceStates.CopyDestination);

            long uploadBufferSize = GetRequiredIntermediateSize(texture, 0, 1);

            // Create the GPU upload buffer.
            var textureUploadHeap = graphicsHost.Device.CreateCommittedResource(new HeapProperties(CpuPageProperty.WriteBack, MemoryPool.L0), HeapFlags.None,
                                                                                ResourceDescription.Texture2D(Format.R8G8B8A8_UNorm, data.Width, data.Height), ResourceStates.GenericRead);

            // Copy data to the intermediate upload heap and then schedule a copy
            // from the upload heap to the Texture2D.
            var handle = GCHandle.Alloc(data.Pixels, GCHandleType.Pinned);
            var ptr    = Marshal.UnsafeAddrOfPinnedArrayElement(data.Pixels, 0);

            textureUploadHeap.WriteToSubresource(0, null, ptr, (sizeof(byte) * 4) * data.Width, data.Pixels.Length);
            handle.Free();

            // TODO: Runtime invalid call error below

            //var commandList = graphicsHost.RequestCommandList();
            //commandList.CopyTextureRegion(new TextureCopyLocation(texture, 0), 0, 0, 0, new TextureCopyLocation(textureUploadHeap, 0), null);
            //commandList.ResourceBarrierTransition(texture, ResourceStates.CopyDestination, ResourceStates.PixelShaderResource);

            //// Describe and create a SRV for the texture.
            //var srvDesc = new ShaderResourceViewDescription
            //{
            //    Shader4ComponentMapping = DXHelper.DefaultComponentMapping(),
            //    Format = textureDesc.Format,
            //    Dimension = ShaderResourceViewDimension.Texture2D,
            //    Texture2D = { MipLevels = 1 },
            //};

            //graphicsHost.Device.CreateShaderResourceView(texture, srvDesc, graphicsHost.SRVHeap.CPUDescriptorHandleForHeapStart);

            //// Command lists are created in the recording state, but there is nothing
            //// to record yet. The main loop expects it to be closed, so close it now.
            //commandList.Close();

            //graphicsHost.CommandQueue.ExecuteCommandList(commandList);

            textureUploadHeap.Dispose();

            return(new Texture <SharpDX.Direct3D12.Resource>(texture, data.Width, data.Height, data.Left, data.Right, data.Top, data.Bottom, data.IsTransparent));
        }
Esempio n. 22
0
    public bool AddTypeElement(XElement elemtype)
    {
        _normalTexture = new NormalContent();
        _normalTexture.ExternalStorage = storeContainer.shapeStore;
        if (!_normalTexture.AddTypeElement(elemtype))
            _normalTexture = null;

        _matTexture = new TextureContent();
        _matTexture.ExternalStorage = storeContainer.materialStore;
        if (!_matTexture.AddTypeElement(elemtype))
            _matTexture = null;

        return _normalTexture != null && _matTexture != null;
    }
        public void Render(SpriteBatch spriteBatch, IXnaGameTime gameTime, FontContent fontContent, TextureContent textureContent)
        {
            spriteBatch.ThrowIfNull("spriteBatch");
            gameTime.ThrowIfNull("gameTime");
            fontContent.ThrowIfNull("fontContent");
            textureContent.ThrowIfNull("textureContent");

            var parameters = new RendererParameters(gameTime, spriteBatch, fontContent, textureContent);

            // Must call ToArray() because collection could be modified during iteration
            foreach (IRenderer renderer in _renderers.ToArray())
            {
                renderer.Render(parameters);
            }
        }
Esempio n. 24
0
        private void SaveFrame(TextureContent textureContent, string path)
        {
            path = $"TestResults/{nameof(FontTest)}/{path}";

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }

            using (var stream = File.OpenWrite(path))
            {
                var img = new Image(textureContent.Width, textureContent.Height, textureContent.Pixels);
                img.SaveAsPng(stream);
            }
        }
Esempio n. 25
0
 public static void PremultiplyAlpha(TextureContent texture)
 {
     foreach (MipmapChain chain in texture.Faces)
     {
         foreach (BitmapContent content3 in chain)
         {
             var content2 = content3 as PixelBitmapContent <Color>;
             if (content2 != null)
             {
                 for (int i = 0; i < content2.Height; i++)
                 {
                     Color[] row = content2.GetRow(i);
                     for (int j = 0; j < row.Length; j++)
                     {
                         Color color = row[j];
                         if (color.A < 0xff)
                         {
                             row[j] = Color.FromNonPremultiplied(color.R, color.G, color.B, color.A);
                         }
                     }
                 }
             }
             else
             {
                 var content = content3 as PixelBitmapContent <Vector4>;
                 if (content == null)
                 {
                     throw new NotSupportedException();
                 }
                 for (int k = 0; k < content.Height; k++)
                 {
                     Vector4[] vectorArray = content.GetRow(k);
                     for (int m = 0; m < vectorArray.Length; m++)
                     {
                         Vector4 vector = vectorArray[m];
                         if (vector.W < 1f)
                         {
                             vector.X      *= vector.W;
                             vector.Y      *= vector.W;
                             vector.Z      *= vector.W;
                             vectorArray[m] = vector;
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 26
0
            protected GeneralOutputHandler(TextureType textureType)
            {
                switch (textureType)
                {
                case TextureType.Texture2D:
                    outputTextureContent = new Texture2DContent();
                    break;

                case TextureType.TextureCube:
                    outputTextureContent = new TextureCubeContent();
                    break;

                default:
                    throw new NotSupportedException("Unknown texture type: " + textureType);
                }
            }
Esempio n. 27
0
 public static void ResizeToPowerOfTwo(TextureContent texture)
 {
     foreach (MipmapChain chain in texture.Faces)
     {
         for (int i = 0; i < chain.Count; i++)
         {
             BitmapContent source = chain[i];
             int           width  = RoundUpToPowerOfTwo(source.Width);
             int           height = RoundUpToPowerOfTwo(source.Height);
             if ((width != source.Width) || (height != source.Height))
             {
                 chain[i] = ConvertBitmap(source, source.GetType(), width, height);
             }
         }
     }
 }
Esempio n. 28
0
        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            PixelBitmapContent <Color> texture = ((PixelBitmapContent <Color>)input.Faces[0][0]);

            PixelBitmapContent <Color> alphaMap = CreateAlphaChannel(texture);

            Texture2DContent result = new Texture2DContent();

            result.Faces[0] = alphaMap;

            // The TextureProcessor class presents all of the same parameters as a the regular texture processor
            // to the developer in the content pipeline.  In order for it to act on those parameters,
            // you must call the base class!
            base.Process(result, context);

            return(result);
        }
Esempio n. 29
0
 private static bool HasFractionalAlpha(TextureContent texture)
 {
     foreach (MipmapChain chain in texture.Faces)
     {
         foreach (PixelBitmapContent <Color> content in chain)
         {
             for (int i = 0; i < content.Height; i++)
             {
                 if (content.GetRow(i).Select(color => color.A).Any(a => (a != 0xff) && (a != 0)))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
 /// <summary>
 /// Checks that the face of the texture contains 7 mipmaps and that their sizes decline from 64x64 to 1x1
 /// </summary>
 /// <param name="content">Texture to check</param>
 /// <param name="faceIndex">Index of the face from the texture</param>
 private static void CheckDdsFace(TextureContent content, int faceIndex)
 {
     Assert.AreEqual(content.Faces[faceIndex].Count, 7);
     Assert.AreEqual(content.Faces[faceIndex][0].Width, 64);
     Assert.AreEqual(content.Faces[faceIndex][0].Height, 64);
     Assert.AreEqual(content.Faces[faceIndex][1].Width, 32);
     Assert.AreEqual(content.Faces[faceIndex][1].Height, 32);
     Assert.AreEqual(content.Faces[faceIndex][2].Width, 16);
     Assert.AreEqual(content.Faces[faceIndex][2].Height, 16);
     Assert.AreEqual(content.Faces[faceIndex][3].Width, 8);
     Assert.AreEqual(content.Faces[faceIndex][3].Height, 8);
     Assert.AreEqual(content.Faces[faceIndex][4].Width, 4);
     Assert.AreEqual(content.Faces[faceIndex][4].Height, 4);
     Assert.AreEqual(content.Faces[faceIndex][5].Width, 2);
     Assert.AreEqual(content.Faces[faceIndex][5].Height, 2);
     Assert.AreEqual(content.Faces[faceIndex][6].Width, 1);
     Assert.AreEqual(content.Faces[faceIndex][6].Height, 1);
 }
Esempio n. 31
0
    public bool AddTypeElement(XElement elemtype)
    {
        _normalTexture = new NormalContent();
        _normalTexture.ExternalStorage = storeContainer.shapeStore;
        if (!_normalTexture.AddTypeElement(elemtype))
        {
            _normalTexture = null;
        }

        _matTexture = new TextureContent();
        _matTexture.ExternalStorage = storeContainer.materialStore;
        if (!_matTexture.AddTypeElement(elemtype))
        {
            _matTexture = null;
        }

        return(_normalTexture != null && _matTexture != null);
    }
        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            TextureContent texContent = base.Process(input, context);

            texContent.ConvertBitmapType(typeof(PixelBitmapContent <Color>));

            for (int face = 0; face < texContent.Faces.Count; face++)
            {
                MipmapChain mipChain = texContent.Faces[face];
                for (int mipLevel = 0; mipLevel < mipChain.Count; mipLevel++)
                {
                    PixelBitmapContent <Color> image = (PixelBitmapContent <Color>)input.Faces[face][mipLevel];
                    Color toReplace = new Color(81, 92, 164);
                    image.ReplaceColor(toReplace, Color.Yellow);
                }
            }

            return(texContent);
        }
Esempio n. 33
0
        public int UseTexture(TextureContent texture)
        {
            if (texture == null)
            {
                return(-1);
            }

            for (int i = 0; i < _SharedTextures.Count; ++i)
            {
                if (TextureContent.ContentComparer.Equals(texture, _SharedTextures[i]))
                {
                    return(i);
                }
            }

            _SharedTextures.Add(texture);

            return(_SharedTextures.Count - 1);
        }
        public void Load()
        {
            // Load player sprites
            this.settings.addSprite(TextureContent.LoadDictionaryContent <Texture2D>(this.game.Content, @"Graphics\Sprites\Adventurer"));
            this.settings.addSprite(TextureContent.LoadDictionaryContent <Texture2D>(this.game.Content, @"Graphics\Sprites\Female"));
            this.settings.addSprite(TextureContent.LoadDictionaryContent <Texture2D>(this.game.Content, @"Graphics\Sprites\Player"));
            this.settings.addSprite(TextureContent.LoadDictionaryContent <Texture2D>(this.game.Content, @"Graphics\Sprites\Soldier"));
            this.settings.addSprite(TextureContent.LoadDictionaryContent <Texture2D>(this.game.Content, @"Graphics\Sprites\Zombie"));

            this.settings.avaibleRamps       = TextureContent.LoadListContent <Texture2D>(this.game.Content, @"Graphics\Ramps");
            this.settings.avaibleBackgrounds = TextureContent.LoadListContent <Texture2D>(this.game.Content, @"Graphics\Backgrounds\ingame");

            // TEXTURES - MISC
            this.settings.textures.Add("hearth", this.game.Content.Load <Texture2D>(@"Graphics\hearth"));
            this.settings.textures.Add("star", this.game.Content.Load <Texture2D>(@"Graphics\star"));
            this.settings.textures.Add("sound.enabled", this.game.Content.Load <Texture2D>(@"Graphics\sound_enabled"));
            this.settings.textures.Add("sound.disabled", this.game.Content.Load <Texture2D>(@"Graphics\sound_disabled"));
            this.settings.textures.Add("vim-mode", this.game.Content.Load <Texture2D>(@"Graphics\vim_mode"));
            this.settings.textures.Add("logo", this.game.Content.Load <Texture2D>(@"Graphics\logo"));

            // SOUNDS
            this.settings.sounds.Add("menu.select", this.game.Content.Load <SoundEffect>(@"SFX\menu\menu_select"));
            this.settings.sounds.Add("menu.confirm", this.game.Content.Load <SoundEffect>(@"SFX\menu\menu_confirm"));

            this.settings.sounds.Add("game.jump.1", this.game.Content.Load <SoundEffect>(@"SFX\ingame\jump1"));
            this.settings.sounds.Add("game.jump.2", this.game.Content.Load <SoundEffect>(@"SFX\ingame\jump2"));
            this.settings.sounds.Add("game.jump.3", this.game.Content.Load <SoundEffect>(@"SFX\ingame\jump3"));
            this.settings.sounds.Add("game.jump.4", this.game.Content.Load <SoundEffect>(@"SFX\ingame\jump4"));

            this.settings.sounds.Add("game.death", this.game.Content.Load <SoundEffect>(@"SFX\ingame\death"));
            this.settings.sounds.Add("game.end", this.game.Content.Load <SoundEffect>(@"SFX\ingame\end"));

            // FONTS
            this.settings.fonts.Add("ingame", this.game.Content.Load <SpriteFont>(@"Fonts\ingameFont"));
            this.settings.fonts.Add("ingame.bigger", this.game.Content.Load <SpriteFont>(@"Fonts\biggerIngameFont"));
            this.settings.fonts.Add("menu.bigger", this.game.Content.Load <SpriteFont>(@"Fonts\biggerMenuFont"));
            this.settings.fonts.Add("paragraph", this.game.Content.Load <SpriteFont>(@"Fonts\paragraphFont"));

            Thread.Sleep(3000); // In case someone has NASA pc :D

            this.game.gameState = GameState.Menu;
        }
Esempio n. 35
0
        public static void ConvertToPVRTC(TextureContent sourceContent, int mipLevels, bool premultipliedAlpha, MGCompressionMode bpp)
        {
            IntPtr dataSizesPtr = IntPtr.Zero;

            var texDataPtr = ManagedPVRTC.ManagedPVRTC.CompressTexture(sourceContent.Faces[0][0].GetPixelData(),
                                                                       sourceContent.Faces[0][0].Height,
                                                                       sourceContent.Faces[0][0].Width,
                                                                       mipLevels,
                                                                       premultipliedAlpha,
                                                                       bpp == MGCompressionMode.PVRTCFourBitsPerPixel,
                                                                       ref dataSizesPtr);

            // Store the size of each mipLevel
            var dataSizesArray = new int[mipLevels];

            Marshal.Copy(dataSizesPtr, dataSizesArray, 0, dataSizesArray.Length);

            var levelSize = 0;

            byte[] levelData;
            var    sourceWidth  = sourceContent.Faces[0][0].Width;
            var    sourceHeight = sourceContent.Faces[0][0].Height;

            // Set the pixel data for each mip level.
            sourceContent.Faces[0].Clear();

            for (int x = 0; x < mipLevels; x++)
            {
                levelSize = dataSizesArray[x];
                levelData = new byte[levelSize];

                Marshal.Copy(texDataPtr, levelData, 0, levelSize);

                var levelWidth  = Math.Max(sourceWidth >> x, 1);
                var levelHeight = Math.Max(sourceHeight >> x, 1);

                sourceContent.Faces[0].Add(new MGBitmapContent(levelData, levelWidth, levelHeight, bpp));

                texDataPtr = IntPtr.Add(texDataPtr, levelSize);
            }
        }
Esempio n. 36
0
    public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
    {
        XAttribute fileAtt = elemtype.Attribute("file");
        if (fileAtt == null)
        {
            //Add error message here
            return false;
        }

        if ((elemtype.Attribute("normal") != null
            || elemtype.Attribute("occlusion") != null
            || elemtype.Attribute("alpha") != null
            || elemtype.Attribute("pattern") != null
            ))
        {
            _normalTexture = new NormalContent();
            _normalTexture.ExternalStorage = storeContainer.shapeStore;
            if (!_normalTexture.AddTypeElement(elemtype))
                _normalTexture = null;
        }

        if ((elemtype.Attribute("metallic") != null
            || elemtype.Attribute("illumination") != null
            ))
        {
            _specialTexture = new SpecialMapContent();
            _specialTexture.ExternalStorage = storeContainer.specialStore;
            if (!_specialTexture.AddTypeElement(elemtype))
                _specialTexture = null;
        }

        if ((elemtype.Attribute("pattern") != null
            || elemtype.Attribute("specular") != null
            ))
        {
            _matTexture = new TextureContent();
            _matTexture.ExternalStorage = storeContainer.materialStore;
            if (!_matTexture.AddTypeElement(elemtype))
                _matTexture = null;
        }

        if (fileAtt.Value == "NONE")
        {
            //This means we don't want to actually store a mesh,
            //but still want to use the category.
            MeshData = new Dictionary<MeshLayer, CPUMesh>();
        }
        else
        {
            string filePath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), fileAtt.Value);
            filePath = Path.GetFullPath(filePath);

            //	Load the OBJ in
            if (!File.Exists(filePath))
                return false;
            var lStream = new FileStream(filePath, FileMode.Open);
            var lOBJData = OBJLoader.LoadOBJ(lStream);
            lStream.Close();
            MeshData = new Dictionary<MeshLayer, CPUMesh>();
            Mesh tempMesh = new Mesh();
            foreach(MeshLayer layer in Enum.GetValues(typeof(MeshLayer)))
            {
                MeshLayer translatedLayer;
                if (layer == MeshLayer.GrowthCutout1
                    || layer == MeshLayer.GrowthCutout2
                    || layer == MeshLayer.GrowthCutout3)
                    translatedLayer = MeshLayer.GrowthCutout;
                else if (layer == MeshLayer.GrowthMaterial1
                    || layer == MeshLayer.GrowthMaterial2
                    || layer == MeshLayer.GrowthMaterial3)
                    translatedLayer = MeshLayer.GrowthMaterial;
                else if (layer == MeshLayer.GrowthTransparent1
                    || layer == MeshLayer.GrowthTransparent2
                    || layer == MeshLayer.GrowthTransparent3)
                    translatedLayer = MeshLayer.GrowthTransparent;
                else translatedLayer = layer;
                tempMesh.LoadOBJ(lOBJData, (layer.ToString()));
                if (tempMesh == null || tempMesh.vertexCount == 0)
                    continue;
                tempMesh.name = filePath + "." + layer.ToString();
                if(translatedLayer == MeshLayer.GrowthCutout
                    || translatedLayer == MeshLayer.GrowthMaterial
                    || translatedLayer == MeshLayer.GrowthTransparent)
                {
                    for(int i = (int)translatedLayer; i < (int)translatedLayer + 4; i++)
                    {
                        //This is because the tree growths can be in any order
                        //So we just copy the un-numbered one onto the rest.
                        MeshData[(MeshLayer)i] = new CPUMesh(tempMesh);
                    }
                }
                else MeshData[layer] = new CPUMesh(tempMesh);
                tempMesh.Clear();
            }
            lStream = null;
            lOBJData = null;
        }

        XAttribute rotAtt = elemtype.Attribute("rotation");
        if (rotAtt == null)
            rotationType = RotationType.None;
        else
        {
            try
            {
                rotationType = (RotationType)Enum.Parse(typeof(RotationType), rotAtt.Value);
            }
            catch
            {
                rotationType = RotationType.None;
                Debug.Log("Unknown rotation value: " + rotAtt.Value);
            }
        }
        UniqueIndex = num_created;
        num_created++;
        return true;
    }
 public GlyphLoadResult(TextureContent texture, bool createsNewTexture)
 {
     this.Texture = texture;
     this.CreatesNewTexture = createsNewTexture;
 }
 protected override void LoadContent()
 {
     _fontContent = new FontContent(Content);
     _textureContent = new TextureContent(Content);
 }
        protected override void LoadContent()
        {
            _textureContent = new TextureContent(Content);

            base.LoadContent();
        }