コード例 #1
0
        public void LoadCompressedMips(TextureTarget textureTarget, STGenericTexture.Surface ImageData, int mipwidth, int mipheight, int MipLevel = 0)
        {
            GL.CompressedTexImage2D <byte>(textureTarget, MipLevel, (InternalFormat)pixelInternalFormat,
                                           mipwidth, mipheight, 0, getImageSize(this), ImageData.mipmaps[MipLevel]);

            //  GL.GenerateMipmap((GenerateMipmapTarget)textureTarget);
        }
コード例 #2
0
        public void LoadUncompressedMips(TextureTarget textureTarget, STGenericTexture.Surface ImageData, int mipwidth, int mipheight, int MipLevel = 0)
        {
            GL.TexImage2D <byte>(textureTarget, MipLevel, pixelInternalFormat, mipwidth, mipheight, 0,
                                 pixelFormat, PixelType.UnsignedByte, ImageData.mipmaps[MipLevel]);

            //   GL.GenerateMipmap((GenerateMipmapTarget)textureTarget);
        }
コード例 #3
0
        public static List <STGenericTexture.Surface> GetArrayFaces(DDS dds, uint Length, int DepthLevel = 0)
        {
            int Dx10Size = dds.IsDX10 ? 20 : 0;

            using (FileReader reader = new FileReader(dds.FileInfo.FilePath)) {
                reader.TemporarySeek((int)(dds.MainHeader.Size + Dx10Size), SeekOrigin.Begin);
                var format = dds.Platform.OutputFormat;

                var  Surfaces   = new List <STGenericTexture.Surface>();
                uint formatSize = TextureFormatHelper.GetBytesPerPixel(format);

                bool isBlock = TextureFormatHelper.IsBCNCompressed(format);
                uint Offset  = 0;

                if (dds.Depth > 1 && dds.MipCount > 1)
                {
                    var Surface = new STGenericTexture.Surface();

                    uint MipWidth = dds.Width, MipHeight = dds.Height;
                    for (int j = 0; j < dds.MipCount; ++j)
                    {
                        MipWidth  = (uint)Math.Max(1, dds.Width >> j);
                        MipHeight = (uint)Math.Max(1, dds.Height >> j);
                        for (byte d = 0; d < dds.Depth; ++d)
                        {
                            uint size = (MipWidth * MipHeight); //Total pixels
                            if (isBlock)
                            {
                                size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
                                if (size < formatSize)
                                {
                                    size = formatSize;
                                }
                            }
                            else
                            {
                                size = (uint)(size * (TextureFormatHelper.GetBytesPerPixel(format))); //Bytes per pixel
                            }


                            //Only add mips to the depth level needed
                            if (d == DepthLevel)
                            {
                                Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
                            }

                            Offset += size;

                            //Add the current depth level and only once
                            if (d == DepthLevel && j == 0)
                            {
                                Surfaces.Add(Surface);
                            }
                        }
                    }
                }
                else
                {
                    for (byte d = 0; d < dds.Depth; ++d)
                    {
                        for (byte i = 0; i < Length; ++i)
                        {
                            var Surface = new STGenericTexture.Surface();

                            uint MipWidth = dds.Width, MipHeight = dds.Height;
                            for (int j = 0; j < dds.MipCount; ++j)
                            {
                                MipWidth  = (uint)Math.Max(1, dds.Width >> j);
                                MipHeight = (uint)Math.Max(1, dds.Height >> j);

                                uint size = (MipWidth * MipHeight); //Total pixels
                                if (isBlock)
                                {
                                    size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
                                    if (size < formatSize)
                                    {
                                        size = formatSize;
                                    }
                                }
                                else
                                {
                                    size = (uint)(size * (TextureFormatHelper.GetBytesPerPixel(format))); //Bytes per pixel
                                }

                                Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
                                Offset += size;
                            }

                            if (d == DepthLevel)
                            {
                                Surfaces.Add(Surface);
                            }
                        }
                    }
                }

                return(Surfaces);
            }
        }