示例#1
0
文件: D3D.cs 项目: jaron780/TagTool
        public static void SetTextureHeader(D3D9xTypes.D3DRESOURCETYPE resourceType, int width, int height, int depth, int levels, D3D9xTypes.D3DUSAGE usage, int format,
                                            D3D9xTypes.D3DMIPPACKINGTYPE mipPackingType, int hasBorder, int expBias, uint nBlocksPitch, ref D3DTexture9 pTexture, ref uint baseSize, ref uint mipmapSize)
        {
            var someType = 0;

            switch (resourceType)
            {
            case D3D9xTypes.D3DRESOURCETYPE.D3DRTYPE_ARRAYTEXTURE:
            case D3D9xTypes.D3DRESOURCETYPE.D3DRTYPE_TEXTURE:
                someType = 1;
                break;

            case D3D9xTypes.D3DRESOURCETYPE.D3DRTYPE_CUBETEXTURE:
                someType = 3;
                depth    = 1;
                break;

            case D3D9xTypes.D3DRESOURCETYPE.D3DRTYPE_VOLUMETEXTURE:
                someType = 2;
                break;

            case D3D9xTypes.D3DRESOURCETYPE.D3DRTYPE_LINETEXTURE:
                someType       = 0;
                mipPackingType = D3D9xTypes.D3DMIPPACKINGTYPE.None;
                break;

            default:
                someType = 0;
                depth    = 1;
                break;
            }

            if (levels == 0)
            {
                levels = GetMaxMipLevels(width, height, depth, hasBorder);
            }

            bool mipsPacked = false;

            if (mipPackingType == D3D9xTypes.D3DMIPPACKINGTYPE.Packed)
            {
                mipsPacked = true;
            }

            int tempUnknown2 = 0;
            int tempWidth    = 0;
            int tempHeight   = 0;

            FindTextureSize(width, height, depth, levels, GpuFormat(format), someType, (format >> 8) & 0xFF, mipsPacked,
                            hasBorder, expBias, nBlocksPitch, ref tempUnknown2, ref tempWidth, ref tempHeight);

            pTexture.Unknown4  = 1;
            pTexture.Unknown8  = 0;
            pTexture.Unknown14 = 0xFFFF0000;
            pTexture.Unknown18 = 0xFFFF0000;

            pTexture.Flags = D3DTexture9Flags.Unknown1 | D3DTexture9Flags.Unknown2 | D3DTexture9Flags.Unknown3;
            if (usage.HasFlag(D3D9xTypes.D3DUSAGE.D3DUSAGE_CPU_CACHED_MEMORY))
            {
                pTexture.Flags |= D3DTexture9Flags.CPU_CACHED_MEMORY;
            }
            if (usage.HasFlag(D3D9xTypes.D3DUSAGE.D3DUSAGE_RUNCOMMANDBUFFER_TIMESTAMP))
            {
                pTexture.Flags |= D3DTexture9Flags.RUNCOMMANDBUFFER_TIMESTAMP;
            }
        }
示例#2
0
        public static RealArgbColor DecodeBitmapPixelXbox(byte[] bitmapData, Bitmap.Image image, D3DTexture9 pTexture, int layerIndex, int mipmapIndex)
        {
            RealArgbColor result = new RealArgbColor(1, 0, 0, 0);

            if (image.Type != BitmapType.Texture3D && (
                    (image.Type == BitmapType.Texture2D && layerIndex == 1) ||
                    (image.Type == BitmapType.CubeMap && layerIndex >= 0 && layerIndex < 6) ||
                    (image.Type == BitmapType.Array && layerIndex >= 0 && layerIndex < image.Depth)) &&
                (pTexture.GetBaseOffset() > 0 || pTexture.GetMipOffset() > 0))
            {
                uint blockWidth  = 0;
                uint blockHeight = 0;
                int  dataOffset  = 0;
                int  layerOffset = 0;

                // verify the mipmap level index
                var minMipLevel = pTexture.GetMinMipLevel();
                var maxMipLevel = pTexture.GetMaxMipLevel();

                // if mipmapIndex is too low
                if (mipmapIndex < minMipLevel)
                {
                    mipmapIndex = minMipLevel;
                }
                // if mipmapIndex is too high
                if (mipmapIndex > maxMipLevel)
                {
                    mipmapIndex = maxMipLevel;
                }

                var currentHeight = image.Height >> mipmapIndex;
                var currentWidth  = image.Width >> mipmapIndex;

                if (currentWidth < 1)
                {
                    currentWidth = 1;
                }

                if (currentHeight < 1)
                {
                    currentHeight = 1;
                }


                //XGGetTextureDesc
                XboxGraphics.XGTEXTURE_DESC textureDesc = new XboxGraphics.XGTEXTURE_DESC();


                XboxGraphics.XGGetBlockDimensions(XboxGraphics.XGGetGpuFormat(textureDesc.D3DFormat), out blockWidth, out blockHeight);

                layerOffset = 0; // Unknown XG function


                if (mipmapIndex > 0 && pTexture.GetMipOffset() > 0)
                {
                    dataOffset = pTexture.GetMipOffset() + layerOffset;
                }
                else
                {
                    dataOffset = pTexture.GetBaseOffset() + layerOffset;
                }

                for (int h = 0; h < currentHeight; h++)
                {
                    for (int w = 0; w < currentWidth; w++)
                    {
                    }
                }
            }


            return(result);
        }