コード例 #1
0
ファイル: IRenderer.cs プロジェクト: shff/gk3tools
        public VertexElementSet(VertexElement[] elements)
        {
            Stride = (int)elements[elements.Length - 1].Offset +
                     (int)elements[elements.Length - 1].Format * sizeof(float);

            Elements = elements;

#if !D3D_DISABLED
            Direct3D9.Direct3D9Renderer renderer = RendererManager.CurrentRenderer as Direct3D9.Direct3D9Renderer;

            if (renderer != null)
            {
                SharpDX.Direct3D9.VertexElement[] d3d9Elements = new SharpDX.Direct3D9.VertexElement[elements.Length + 1];
                for (int i = 0; i < elements.Length; i++)
                {
                    d3d9Elements[i].Offset = (short)elements[i].Offset;

                    if (elements[i].Format == VertexElementFormat.Float)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float1;
                    }
                    else if (elements[i].Format == VertexElementFormat.Float2)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float2;
                    }
                    else if (elements[i].Format == VertexElementFormat.Float3)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float3;
                    }
                    else if (elements[i].Format == VertexElementFormat.Float4)
                    {
                        d3d9Elements[i].Type = SharpDX.Direct3D9.DeclarationType.Float4;
                    }

                    if (elements[i].Usage == VertexElementUsage.Position)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.Position;
                    }
                    else if (elements[i].Usage == VertexElementUsage.TexCoord)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.TextureCoordinate;
                    }
                    else if (elements[i].Usage == VertexElementUsage.Normal)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.Normal;
                    }
                    else if (elements[i].Usage == VertexElementUsage.Color)
                    {
                        d3d9Elements[i].Usage = SharpDX.Direct3D9.DeclarationUsage.Color;
                    }

                    d3d9Elements[i].Stream     = 0;
                    d3d9Elements[i].UsageIndex = (byte)elements[i].UsageIndex;
                    d3d9Elements[i].Method     = SharpDX.Direct3D9.DeclarationMethod.Default;
                }
                d3d9Elements[d3d9Elements.Length - 1] = SharpDX.Direct3D9.VertexElement.VertexDeclarationEnd;
                D3D9Declaration = new SharpDX.Direct3D9.VertexDeclaration(renderer.Direct3D9Device, d3d9Elements);
            }
#endif
        }
コード例 #2
0
ファイル: Direct3D9Renderer.cs プロジェクト: shff/gk3tools
        public Direct3D9UpdatableTexture(string name, int width, int height)
            : base(name, width, height)
        {
            //if (Gk3Main.Utils.IsPowerOfTwo(width) == false ||
            //    Gk3Main.Utils.IsPowerOfTwo(height) == false)
            //    throw new ArgumentException("Width and height must be power-of-two");

            Direct3D9Renderer renderer = (Direct3D9Renderer)RendererManager.CurrentRenderer;

            _texture = new Texture(renderer.Direct3D9Device, width, height, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);
        }
コード例 #3
0
ファイル: Direct3D9Effect.cs プロジェクト: shff/gk3tools
        public Direct3D9Effect(string name, System.IO.Stream stream)
            : base(name, stream)
        {
            Direct3D9Renderer renderer = (Direct3D9Renderer)RendererManager.CurrentRenderer;
            string            errors;

            _effect = SharpDX.Direct3D9.Effect.FromString(renderer.Direct3D9Device, Text, null, null, null, ShaderFlags.None, null);

            _effect.Technique = _effect.GetTechnique(0);
            _parameters       = new Dictionary <string, EffectHandle>();
        }
コード例 #4
0
ファイル: Direct3D9Texture.cs プロジェクト: shff/gk3tools
        private void convertToDirect3D9Texture(bool resizeToPowerOfTwo, bool clamp)
        {
            byte[] pixels = _pixels;
            _actualPixelWidth  = _width;
            _actualPixelHeight = _height;

            _actualWidth  = 1.0f;
            _actualHeight = 1.0f;

            if (resizeToPowerOfTwo &&
                ((_width & (_width - 1)) != 0 ||
                 (_height & (_height - 1)) != 0))
            {
                byte[] newPixels;
                ConvertToPowerOfTwo(pixels, _width, _height, out newPixels, out _actualPixelWidth, out _actualPixelHeight);

                _actualWidth  = _width / (float)_actualPixelWidth;
                _actualHeight = _height / (float)_actualPixelHeight;

                pixels = fixupAlpha(newPixels, true);
            }
            else
            {
                pixels = fixupAlpha(null, true);
                if (pixels == null)
                {
                    pixels = _pixels;
                }
            }

            Direct3D9Renderer renderer = (Direct3D9Renderer)RendererManager.CurrentRenderer;

            _texture = new Texture(renderer.Direct3D9Device, _actualPixelWidth, _actualPixelHeight, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);

            Surface s = _texture.GetSurfaceLevel(0);

            SharpDX.DataStream    stream;
            SharpDX.DataRectangle r = s.LockRectangle(LockFlags.None, out stream);

            WritePixelsToTextureDataStream(stream, pixels, _actualPixelWidth, _actualPixelHeight);

            s.UnlockRectangle();
        }