コード例 #1
0
            private void CommitLevel()
            {
                if (faceIndex >= 0)
                {
                    BitmapContent newBitmap = CreateBitmapContent(dataWidth, dataHeight);

                    newBitmap.SetPixelData(tempBitmapData);

                    outputTextureContent.Faces[faceIndex].Add(newBitmap);

                    dataSize  = -1;
                    dataWidth = dataHeight = -1;
                    faceIndex = -1;
                    mipIndex  = -1;
                    dataIndex = 0;
                }
            }
コード例 #2
0
ファイル: DDSImporter.cs プロジェクト: ykafia/Aether.Extras
        public override TextureContent Import(string filename, ContentImporterContext context)
        {
            TextureContent output;

            using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var reader = new BinaryReader(stream))
                {
                    var header = new DDSHeader(reader);
                    if (header.PixelFormat.Flags == PF_Flags.FOURCC && header.PixelFormat.FourCC == PF_FourCC.DX10)
                    {
                        throw new NotImplementedException("DX10 Header not supported");
                    }
                    if (header.PitchOrLinearSize != 0)
                    {
                        throw new NotImplementedException();
                    }


                    if (header.Caps2.HasFlag(DDS_Caps2.CUBEMAP))
                    {
                        var cube   = new TextureCubeContent();
                        var format = GetFormat(header.PixelFormat);
                        for (int f = 0; f < 6; f++)
                        {
                            var           width  = header.Width;
                            var           height = header.Height;
                            BitmapContent bitmap = CreateBitmap(format, width, height);
                            var           size   = GetBitmapSize(format, width, height);
                            byte[]        src    = reader.ReadBytes(size);
                            bitmap.SetPixelData(src);
                            cube.Faces[f].Add(bitmap);

                            if (header.Caps.HasFlag(DDS_Caps.MIPMAP))
                            {
                                for (int m = 0; m < header.MipMapCount - 1; m++)
                                {
                                    width  = width / 2;
                                    height = height / 2;

                                    bitmap = CreateBitmap(format, width, height);
                                    size   = GetBitmapSize(format, width, height);
                                    src    = reader.ReadBytes(size);
                                    bitmap.SetPixelData(src);
                                    cube.Faces[f].Add(bitmap);
                                }
                            }
                        }
                        output = cube;
                    }
                    else
                    {
                        throw new NotImplementedException(header.Caps2 + " not supported");
                    }

                    reader.Close();
                    stream.Close();
                }
            }

            return(output);
        }