/// <summary>
        /// Converts a DigitalRune <see cref="Texture"/> to an XNA <see cref="TextureContent"/>.
        /// </summary>
        /// <param name="texture">The <see cref="Texture"/>.</param>
        /// <param name="identity">The content identity.</param>
        /// <returns>The <see cref="TextureContent"/>.</returns>
        public static TextureContent ToContent(Texture texture, ContentIdentity identity)
        {
            var description = texture.Description;
              switch (description.Dimension)
              {
            case TextureDimension.Texture1D:
            case TextureDimension.Texture2D:
              {
            var textureContent = new Texture2DContent { Identity = identity };
            for (int mipIndex = 0; mipIndex < description.MipLevels; mipIndex++)
            {
              var image = texture.Images[texture.GetImageIndex(mipIndex, 0, 0)];
              textureContent.Mipmaps.Add(ToContent(image));
            }

            return textureContent;
              }
            case TextureDimension.TextureCube:
              {
            var textureContent = new TextureCubeContent { Identity = identity };
            for (int faceIndex = 0; faceIndex < 6; faceIndex++)
            {
              for (int mipIndex = 0; mipIndex < description.MipLevels; mipIndex++)
              {
                var image = texture.Images[texture.GetImageIndex(mipIndex, faceIndex, 0)];
                textureContent.Faces[faceIndex].Add(ToContent(image));
              }
            }

            return textureContent;
              }
            case TextureDimension.Texture3D:
              {
            var textureContent = new Texture3DContent { Identity = identity };
            for (int zIndex = 0; zIndex < description.Depth; zIndex++)
            {
              textureContent.Faces.Add(new MipmapChain());
              for (int mipIndex = 0; mipIndex < description.MipLevels; mipIndex++)
              {
                var image = texture.Images[texture.GetImageIndex(mipIndex, 0, zIndex)];
                textureContent.Faces[zIndex].Add(ToContent(image));
              }
            }

            return textureContent;
              }
              }

              throw new InvalidOperationException("Invalid texture dimension.");
        }
Exemplo n.º 2
0
        public void Texture3DContent()
        {
            var content = new Texture3DContent();

            Assert.NotNull(content.Faces);
            Assert.AreEqual(0, content.Faces.Count);

            var face0 = new MipmapChain(new PixelBitmapContent<Color>(2, 2));
            content.Faces.Add(face0);
            Assert.AreEqual(1, content.Faces.Count);
            Assert.AreEqual(face0, content.Faces[0]);
            Assert.AreEqual(1, content.Faces[0].Count);

            content.Faces[0].Add(new PixelBitmapContent<Color>(1, 1));
            Assert.AreEqual(2, content.Faces[0].Count);

            var face2 = new MipmapChain(new PixelBitmapContent<Color>(2, 2));
            content.Faces.Add(face2);
            Assert.AreEqual(face2, content.Faces[1]);
            Assert.AreEqual(2, content.Faces.Count);

            var face1 = new MipmapChain(new PixelBitmapContent<Color>(2, 2));
            content.Faces.Insert(1, face1);
            Assert.AreEqual(face1, content.Faces[1]);
            Assert.AreEqual(3, content.Faces.Count);

            content.Faces.RemoveAt(0);
            Assert.AreEqual(2, content.Faces.Count);
            Assert.AreEqual(face1, content.Faces[0]);
            Assert.AreEqual(face2, content.Faces[1]);

            content.Faces.Remove(face1);
            Assert.AreEqual(1, content.Faces.Count);
            Assert.AreEqual(face2, content.Faces[0]);

            content.Faces.Clear();
            Assert.AreEqual(0, content.Faces.Count);
        }