public override void SetData <T>(CubeMapFace face, T[] data, int mipLevel, Rectangle?subimage, int startIndex, int elementCount)
 {
     if (subimage.HasValue)
     {
         XNA.Rectangle rect;
         Rectangle     v = subimage.Value;
         XNAHelper.ConvertRectangle(ref v, out rect);                _textureCube.SetData <T>(XNAHelper.ToXNACubeMapFace(face), mipLevel, rect, data, startIndex, elementCount);
     }
     else
     {
         _textureCube.SetData <T>(XNAHelper.ToXNACubeMapFace(face), mipLevel, null, data, startIndex, elementCount);
     }
 }
Пример #2
0
        public static TextureCube DDSFromStreamEXT(
            GraphicsDevice graphicsDevice,
            Stream stream
            )
        {
            TextureCube result;

            // Begin BinaryReader, ignoring a tab!
            using (BinaryReader reader = new BinaryReader(stream))
            {
                int           width, height, levels;
                SurfaceFormat format;
                Texture.ParseDDS(
                    reader,
                    out format,
                    out width,
                    out height,
                    out levels
                    );

                // Allocate/Load texture
                result = new TextureCube(
                    graphicsDevice,
                    width,
                    levels > 1,
                    format
                    );

                byte[] tex = null;
                if (stream is MemoryStream &&
                    ((MemoryStream)stream).TryGetBuffer(out tex))
                {
                    for (int face = 0; face < 6; face += 1)
                    {
                        for (int i = 0; i < levels; i += 1)
                        {
                            int mipLevelSize = Texture.CalculateDDSLevelSize(
                                width >> i,
                                width >> i,
                                format
                                );
                            result.SetData(
                                (CubeMapFace)face,
                                i,
                                null,
                                tex,
                                (int)stream.Seek(0, SeekOrigin.Current),
                                mipLevelSize
                                );
                            stream.Seek(
                                mipLevelSize,
                                SeekOrigin.Current
                                );
                        }
                    }
                }
                else
                {
                    for (int face = 0; face < 6; face += 1)
                    {
                        for (int i = 0; i < levels; i += 1)
                        {
                            tex = reader.ReadBytes(Texture.CalculateDDSLevelSize(
                                                       width >> i,
                                                       width >> i,
                                                       format
                                                       ));
                            result.SetData(
                                (CubeMapFace)face,
                                i,
                                null,
                                tex,
                                0,
                                tex.Length
                                );
                        }
                    }
                }

                // End BinaryReader
            }

            // Finally.
            return(result);
        }