Пример #1
0
        protected internal override IndexBuffer Read(ContentReader input, IndexBuffer existingInstance)
        {
            IndexBuffer indexBuffer = existingInstance;

            bool sixteenBits = input.ReadBoolean();
            int  dataSize    = input.ReadInt32();

            var elementType  = sixteenBits ? IndexElementType.Int16 : IndexElementType.Int32;
            int elementCount = dataSize / elementType.TypeSize();

            using (var buffer = input.ContentManager.GetScratchBuffer(dataSize))
            {
                if (input.Read(buffer.AsSpan(0, dataSize)) != dataSize)
                {
                    throw new InvalidDataException();
                }

                if (indexBuffer == null ||
                    indexBuffer.ElementType != elementType ||
                    indexBuffer.Capacity < elementCount)
                {
                    indexBuffer = new IndexBuffer(
                        input.GetGraphicsDevice(), elementType, elementCount, BufferUsage.None);
                }

                indexBuffer.SetData(buffer.AsSpan().Slice(0, dataSize));
                return(indexBuffer);
            }
        }
Пример #2
0
        protected internal override T?Read(ContentReader input, T?existingInstance)
        {
            if (input.ReadBoolean())
            {
                return(input.ReadObject <T>(elementReader));
            }

            return(null);
        }
        protected internal override SpriteFont Read(ContentReader input, SpriteFont existingInstance)
        {
            if (existingInstance != null)
            {
                // Read the texture into the existing texture instance
                input.ReadObject(existingInstance.Texture);

                // FIXME: is it really needed to read theses objects?

                // discard the rest of the SpriteFont data as
                // we are only reloading GPU resources for now

                input.ReadObject <List <Rectangle> >();
                input.ReadObject <List <Rectangle> >();
                input.ReadObject <List <Rune> >();
                input.ReadInt32();
                input.ReadSingle();
                input.ReadObject <List <Vector3> >();
                if (input.ReadBoolean())
                {
                    input.ReadInt32();
                }

                return(existingInstance);
            }
            else
            {
                // Create a fresh SpriteFont instance
                var   texture          = input.ReadObject <Texture2D>();
                var   glyphs           = input.ReadObject <List <Rectangle> >();
                var   cropping         = input.ReadObject <List <Rectangle> >();
                var   charMap          = input.ReadObject <List <Rune> >();
                int   lineSpacing      = input.ReadInt32();
                float spacing          = input.ReadSingle();
                var   kerning          = input.ReadObject <List <Vector3> >();
                var   defaultCharacter = input.ReadBoolean() ? (Rune)input.ReadInt32() : (Rune?)null;

                return(new SpriteFont(
                           texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultCharacter));
            }
        }
        protected internal override DualTextureEffect Read(ContentReader input, DualTextureEffect existingInstance)
        {
            DualTextureEffect effect = new DualTextureEffect(input.GetGraphicsDevice())
            {
                Texture            = input.ReadExternalReference <Texture>() as Texture2D,
                Texture2           = input.ReadExternalReference <Texture>() as Texture2D,
                DiffuseColor       = input.ReadVector3(),
                Alpha              = input.ReadSingle(),
                VertexColorEnabled = input.ReadBoolean()
            };

            return(effect);
        }
Пример #5
0
        protected internal override AlphaTestEffect Read(ContentReader input, AlphaTestEffect existingInstance)
        {
            var effect = new AlphaTestEffect(input.GetGraphicsDevice())
            {
                Texture            = input.ReadExternalReference <Texture>() as Texture2D,
                AlphaFunction      = (CompareFunction)input.ReadInt32(),
                ReferenceAlpha     = (int)input.ReadUInt32(),
                DiffuseColor       = input.ReadVector3(),
                Alpha              = input.ReadSingle(),
                VertexColorEnabled = input.ReadBoolean()
            };

            return(effect);
        }
Пример #6
0
        protected internal override BasicEffect Read(ContentReader input, BasicEffect existingInstance)
        {
            var effect = new BasicEffect(input.GetGraphicsDevice());

            if (input.ReadExternalReference <Texture>() is Texture2D texture)
            {
                effect.Texture        = texture;
                effect.TextureEnabled = true;
            }

            effect.DiffuseColor       = input.ReadVector3();
            effect.EmissiveColor      = input.ReadVector3();
            effect.SpecularColor      = input.ReadVector3();
            effect.SpecularPower      = input.ReadSingle();
            effect.Alpha              = input.ReadSingle();
            effect.VertexColorEnabled = input.ReadBoolean();
            return(effect);
        }
Пример #7
0
 protected internal override bool Read(ContentReader input, bool existingInstance)
 {
     return(input.ReadBoolean());
 }