コード例 #1
0
        /// <summary>
        /// Builds the vertex buffer using vertices with position and normal data.
        /// </summary>
        public void BuildVertices_PositionNormal()
        {
            GraphicsStream stream;

            DataCore.VertexFormats.PositionNormal[] tri =
                new DataCore.VertexFormats.PositionNormal[_page.TerrainPatch.NumVertices];

            for (int i = 0; i < tri.Length; i++)
            {
                tri[i].Position = _page.TerrainPatch.Vertices[i].Position;
                tri[i].Normal   = _page.TerrainPatch.Vertices[i].Normal;
            }


            if (_vb != null)
            {
                if (!_vb.Disposed)
                {
                    _vb.Dispose();
                }

                _vb = null;
            }

            _vb = new D3D.VertexBuffer(typeof(DataCore.VertexFormats.PositionNormal),
                                       tri.Length, _viewport.Device, D3D.Usage.WriteOnly,
                                       DataCore.VertexFormats.PositionNormal.Format, D3D.Pool.Managed);

            stream = _vb.Lock(0, 0, D3D.LockFlags.None);
            stream.Write(tri);
            _vb.Unlock();

            _vbSize = tri.Length;
        }
コード例 #2
0
    /// <summary>
    /// Restore the font after a device has been reset
    /// </summary>
    public void RestoreDeviceObjects(object sender, EventArgs e)
    {
        vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColoredTextured), MaxNumfontVertices,
                                        device, Usage.WriteOnly | Usage.Dynamic, 0, Pool.Default);

        // Create the state blocks for rendering text
        for (int which = 0; which < 2; which++)
        {
            device.BeginStateBlock();
            device.SetTexture(0, fontTexture);

            if (isZEnable)
            {
                renderState.ZBufferEnable = true;
            }
            else
            {
                renderState.ZBufferEnable = false;
            }

            renderState.AlphaBlendEnable = true;
            renderState.SourceBlend      = Blend.SourceAlpha;
            renderState.DestinationBlend = Blend.InvSourceAlpha;
            renderState.AlphaTestEnable  = true;
            renderState.ReferenceAlpha   = 0x08;
            renderState.AlphaFunction    = Compare.GreaterEqual;
            renderState.FillMode         = FillMode.Solid;
            renderState.CullMode         = Cull.CounterClockwise;
            renderState.StencilEnable    = false;
            renderState.Clipping         = true;
            device.ClipPlanes.DisableAll();
            renderState.VertexBlend = VertexBlend.Disable;
            renderState.IndexedVertexBlendEnable = false;
            renderState.FogEnable                = false;
            renderState.ColorWriteEnable         = ColorWriteEnable.RedGreenBlueAlpha;
            textureState0.ColorOperation         = TextureOperation.Modulate;
            textureState0.ColorArgument1         = TextureArgument.TextureColor;
            textureState0.ColorArgument2         = TextureArgument.Diffuse;
            textureState0.AlphaOperation         = TextureOperation.Modulate;
            textureState0.AlphaArgument1         = TextureArgument.TextureColor;
            textureState0.AlphaArgument2         = TextureArgument.Diffuse;
            textureState0.TextureCoordinateIndex = 0;
            textureState0.TextureTransform       = TextureTransform.Disable; // REVIEW
            textureState1.ColorOperation         = TextureOperation.Disable;
            textureState1.AlphaOperation         = TextureOperation.Disable;
            samplerState0.MinFilter              = TextureFilter.Point;
            samplerState0.MagFilter              = TextureFilter.Point;
            samplerState0.MipFilter              = TextureFilter.None;

            if (which == 0)
            {
                savedStateBlock = device.EndStateBlock();
            }
            else
            {
                drawTextStateBlock = device.EndStateBlock();
            }
        }
    }
コード例 #3
0
 public override void Dispose()
 {
     if (d3dBuffer != null)
     {
         d3dBuffer.Dispose();
     }
     d3dBuffer = null;
 }
コード例 #4
0
        public void OnDeviceReset(object sender, System.EventArgs e)
        {
            Direct3D.Device dev = (Direct3D.Device)sender;

            dev.RenderState.Lighting = false;

            if(null != vertexBuffer)
            {
                vertexBuffer.Dispose();
            }

            vertexBuffer = new Direct3D.VertexBuffer(m_aVertices[0].GetType(),
                                                     m_aVertices.Length,
                                                     dev,
                                                     Direct3D.Usage.WriteOnly,
                                                     Direct3D.CustomVertex.TransformedColoredTextured.Format,
                                                     Direct3D.Pool.Default);

            vertexBuffer.SetData(m_aVertices, 0, Direct3D.LockFlags.None);

            dev.VertexShader = null;
            dev.VertexFormat = Direct3D.CustomVertex.TransformedColoredTextured.Format;
            dev.SetStreamSource(0, vertexBuffer, 0);

            if(null != indexBuffer)
            {
                indexBuffer.Dispose();
            }

            indexBuffer = new Direct3D.IndexBuffer(m_aIndices[0].GetType(),
                                                   m_aIndices.Length,
                                                   dev,
                                                   Direct3D.Usage.WriteOnly,
                                                   Direct3D.Pool.Default);
            indexBuffer.SetData(m_aIndices, 0, Direct3D.LockFlags.None);

            dev.Indices = indexBuffer;

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.Stream stream = assembly.GetManifestResourceStream("_4_Texture.photo.png");

            // If you want to know the names of all of the embedded resources,
            // you can get an array of strings with the names.
            // string[] resourceNames = assembly.GetManifestResourceNames();

            // If you want to load the texture from a file instead of an embedded resource, you can do this:
            // texture = Direct3D.TextureLoader.FromFile(dev, "photo.png");

            if(null != texture)
            {
                texture.Dispose();
            }

            texture = Direct3D.TextureLoader.FromStream(dev, stream);
            stream.Close();

            dev.SetTexture(0, texture);
        }
コード例 #5
0
 public static void GetBoundingBox(D3D.Mesh mesh, float scale, out DX.Vector3 min, out DX.Vector3 max)
 {
     D3D.VertexBuffer  verts  = mesh.VertexBuffer;
     DX.GraphicsStream stream = verts.Lock(0, 0, D3D.LockFlags.None);
     D3D.Geometry.ComputeBoundingBox(stream, mesh.NumberVertices, mesh.VertexFormat, out min, out max);
     verts.Unlock();
     stream = null;
     verts  = null;
 }
コード例 #6
0
ファイル: Devices.cs プロジェクト: itamargreen/metalx
        void init()
        {
            Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters();
            pps.SwapEffect           = Microsoft.DirectX.Direct3D.SwapEffect.Discard;
            pps.Windowed             = true;
            pps.BackBufferCount      = 1;
            pps.PresentationInterval = PresentInterval.One;
            pps.BackBufferFormat     = Format.A8R8G8B8;

            if (GameWindow == null)
            {
                //pps.BackBufferWidth = GameControl.Width;
                //pps.BackBufferHeight = GameControl.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            else
            {
                //pps.BackBufferWidth = GameWindow.Width;
                //pps.BackBufferHeight = GameWindow.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format;


            //D3DDev.ShowCursor(false);

            DSoundDev = new Microsoft.DirectX.DirectSound.Device();
            if (GameWindow == null)
            {
                DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }
            else
            {
                DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }

            DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            DKeyboardDev.Acquire();

            DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);
            DMouseDev.Acquire();

            VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed);

            D3DDev.SetStreamSource(0, VertexBuffer, 0);
            D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            Sprite = new Sprite(D3DDev);

            FontDescription fd = new FontDescription();

            fd.FaceName = "新宋体";
            fd.Height   = -12;
            Font2D      = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd);

            Font3D = new System.Drawing.Font("新宋体", 12);
        }
コード例 #7
0
        public static float GetBoundingRadius(D3D.Mesh mesh, float scale)
        {
            D3D.VertexBuffer  verts  = mesh.VertexBuffer;
            DX.GraphicsStream stream = verts.Lock(0, 0, D3D.LockFlags.None);
            DX.Vector3        meshCenter;
            float             radius = D3D.Geometry.ComputeBoundingSphere(stream, mesh.NumberVertices, mesh.VertexFormat, out meshCenter) * scale;

            verts.Unlock();
            stream = null;
            verts  = null;
            return(radius);
        }
コード例 #8
0
 //---------------------------------------------------------------------
 public bool ReleaseIfDefaultPool()
 {
     if (d3dPool == Pool.Default)
     {
         if (d3dBuffer != null)
         {
             d3dBuffer.Dispose();
             d3dBuffer = null;
         }
         return(true);
     }
     return(false);
 }
コード例 #9
0
        public void Draw()
        {
            vertices = new Direct3D.CustomVertex.PositionColored[700];
            LowestPartVertexes(0);
            //highest vertex is now 36
            HiltVertexes(36);
            //highest vertex is now 104
            BladeVertexes(104);
            //highes vertex should now be about 424

            vb = new Direct3D.VertexBuffer(typeof(Direct3D.CustomVertex.PositionColored), vertices.Length, DXDevice, Direct3D.Usage.Dynamic | Direct3D.Usage.WriteOnly, Direct3D.CustomVertex.PositionColored.Format, Direct3D.Pool.Default);
            vb.SetData(vertices, 0, Direct3D.LockFlags.None);
        }
コード例 #10
0
        private bool Initialize(GeometryManager manager, Type vertexType, int size, bool pointsprites, bool dynamic)
        {
            if (IsTypeValid(vertexType))
            {
                try
                {
                    D3d.Pool  d3dPool  = D3d.Pool.Managed;
                    D3d.Usage d3dUsage = D3d.Usage.WriteOnly;

                    if (dynamic)
                    {
                        d3dUsage |= D3d.Usage.Dynamic;
                    }

                    if (pointsprites)
                    {
                        d3dUsage |= D3d.Usage.Points;
                    }

                    d3dManager    = manager;
                    d3dVertexType = vertexType;
                    d3dVertexSize = size;

                    d3dVertexBuffer = new D3d.VertexBuffer(vertexType,
                                                           size,
                                                           manager.Device.D3dDevice,
                                                           d3dUsage,
                                                           D3d.VertexFormats.None,
                                                           d3dPool);

                    return(true);
                }
                catch (D3d.InvalidCallException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
                catch (D3d.OutOfVideoMemoryException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
                catch (OutOfMemoryException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
            }

            return(false);
        }
コード例 #11
0
 //---------------------------------------------------------------------
 public bool RecreateIfDefaultPool(D3D.Device device)
 {
     if (d3dPool == Pool.Default)
     {
         // Create the d3d vertex buffer
         d3dBuffer = new D3D.VertexBuffer(
             typeof(byte),
             sizeInBytes,
             device,
             D3DHelper.ConvertEnum(usage),
             VertexFormats.None,
             d3dPool);
         return(true);
     }
     return(false);
 }
コード例 #12
0
        /// <summary>
        /// Builds the vertex buffer using vertices with position, normal, and eight sets of texture data.
        /// </summary>
        public void BuildVertices_PositionNormalTextured8()
        {
            GraphicsStream stream;

            DataCore.VertexFormats.PositionNormalTextured8[] tri =
                new DataCore.VertexFormats.PositionNormalTextured8[_page.TerrainPatch.NumVertices];

            for (int i = 0; i < tri.Length; i++)
            {
                tri[i].Position = _page.TerrainPatch.Vertices[i].Position;
                tri[i].Normal   = _page.TerrainPatch.Vertices[i].Normal;

                if (_page.TerrainPatch.NumTextures > 0)
                {
                    for (int j = 0; j < _page.TerrainPatch.NumTextures && j < 8; j++)
                    {
                        tri[i].SetTextureCoordinates(_page.TerrainPatch.GetTextureCoordinateList(j)[i],
                                                     j);
                    }
                }
                else
                {
                    tri[i].SetTextureCoordinates(new Vector2(0f, 0f), 0);
                }
            }

            if (_vb != null)
            {
                if (!_vb.Disposed)
                {
                    _vb.Dispose();
                }

                _vb = null;
            }

            _vb = new D3D.VertexBuffer(typeof(DataCore.VertexFormats.PositionNormalTextured8),
                                       tri.Length, _viewport.Device, D3D.Usage.WriteOnly,
                                       DataCore.VertexFormats.PositionNormalTextured8.Format, D3D.Pool.Managed);

            stream = _vb.Lock(0, 0, D3D.LockFlags.None);
            stream.Write(tri);
            _vb.Unlock();

            _vbSize = tri.Length;
        }
コード例 #13
0
        public D3DHardwareVertexBuffer(int vertexSize, int numVertices, BufferUsage usage,
                                       D3D.Device device, bool useSystemMemory, bool useShadowBuffer)
            : base(vertexSize, numVertices, usage, useSystemMemory, useShadowBuffer)
        {
#if !NO_OGRE_D3D_MANAGE_BUFFERS
            d3dPool = useSystemMemory? Pool.SystemMemory :
                      // If not system mem, use managed pool UNLESS buffer is discardable
                      // if discardable, keeping the software backing is expensive
                      ((usage & BufferUsage.Discardable) != 0) ? Pool.Default : Pool.Managed;
#else
            d3dPool = useSystemMemory ? Pool.SystemMemory : Pool.Default;
#endif
            // Create the d3d vertex buffer
            d3dBuffer = new D3D.VertexBuffer(device,
                                             sizeInBytes,
                                             D3DHelper.ConvertEnum(usage),
                                             VertexFormats.None,
                                             d3dPool);
        }
コード例 #14
0
        public void OnDeviceReset(object sender, System.EventArgs e)
        {
            Direct3D.Device dev = (Direct3D.Device)sender;

            dev.RenderState.Lighting = false;

            if(null != vertexBuffer)
            {
                vertexBuffer.Dispose();
            }

            vertexBuffer = new Direct3D.VertexBuffer(m_aVertices[0].GetType(),
                                                     m_aVertices.Length,
                                                     dev,
                                                     Direct3D.Usage.WriteOnly,
                                                     Direct3D.CustomVertex.TransformedColored.Format,
                                                     Direct3D.Pool.Default);

            vertexBuffer.SetData(m_aVertices, 0, Direct3D.LockFlags.None);

            dev.VertexShader = null;
            dev.VertexFormat = Direct3D.CustomVertex.TransformedColored.Format;
            dev.SetStreamSource(0, vertexBuffer, 0);

            if(null != indexBuffer)
            {
                indexBuffer.Dispose();
            }

            indexBuffer = new Direct3D.IndexBuffer(m_aIndices[0].GetType(),
                                                   m_aIndices.Length,
                                                   dev,
                                                   Direct3D.Usage.WriteOnly,
                                                   Direct3D.Pool.Default);
            indexBuffer.SetData(m_aIndices, 0, Direct3D.LockFlags.None);

            dev.Indices = indexBuffer;
        }
コード例 #15
0
        /// <summary>
        /// Clears the buffers used.
        /// </summary>
        public void ClearBuffers()
        {
            if (_vb != null && !_vb.Disposed)
            {
                _vb.Dispose();
                _vb     = null;
                _vbSize = 0;
            }

            if (_vbVerts != null && !_vbVerts.Disposed)
            {
                _vbVerts.Dispose();
                _vbVerts    = null;
                _vbVertSize = 0;
            }

            if (_vbByHeight != null && !_vbByHeight.Disposed)
            {
                _vbByHeight.Dispose();
                _vbByHeight = null;
                _vbSize     = 0;
            }

            if (_ib != null && !_ib.Disposed)
            {
                _ib.Dispose();
                _ib     = null;
                _ibSize = 0;
            }

            if (_ibVerts != null && !_ibVerts.Disposed)
            {
                _ibVerts.Dispose();
                _ibVerts    = null;
                _ibVertSize = 0;
            }
        }
コード例 #16
0
ファイル: Cell.cs プロジェクト: d3x0r/xperdex
        // cells are setup as x, y index of col, row, and 1, 1 wide,high, and a total rows and cols they are of.

        // okay so this computes from that,
        public void SetupCell(D3DState state, float x, float y, float width, float height, float rows, float cols)
        {
            x_ofs     = (int)x;
            y_ofs     = (int)y;
            this.rows = (int)rows;
            this.cols = (int)cols;

            if (state == null)
            {
                return;
            }

            cell_verts = new Direct3D.VertexBuffer(
                typeof(Direct3D.CustomVertex.PositionTextured),
                4,
                state.graphics,
                0,
                Direct3D.CustomVertex.PositionTextured.Format,
                Direct3D.Pool.Default);


            Direct3D.CustomVertex.PositionTextured[] verts =
                (Direct3D.CustomVertex.PositionTextured[])cell_verts.Lock(0, 0);
            verts[0].X  = -1.0f; verts[0].Y = -1.0f; verts[0].Z = 0.0f;
            verts[0].Tu = (x * width) / cols; verts[0].Tv = (y * height) / rows;

            verts[1].X  = -1.0f; verts[1].Y = 1.0f; verts[1].Z = 0.0f;
            verts[1].Tu = ((x + 1) * width) / cols; verts[1].Tv = (y * height) / rows;

            verts[2].X  = 1.0f; verts[2].Y = -1.0f; verts[2].Z = 0.0f;
            verts[2].Tu = (x * width) / cols; verts[2].Tv = ((y + 1) * height) / rows;

            verts[3].X  = 1.0f; verts[3].Y = 1.0f; verts[3].Z = 0.0f;
            verts[3].Tu = ((x + 1) * width) / cols; verts[3].Tv = ((y + 1) * height) / rows;
            cell_verts.Unlock();
        }
コード例 #17
0
        public void Build(Renderer renderer)
        {
            FinalizeSubset();
            vertices = new Vertex[vertexAddresses.Count];
            int i = 0;

            foreach (KeyValuePair <int, Vertex> a in vertexAddresses)
            {
                vertices[i++] = a.Value;
            }
            foreach (Subset sub in subsets)
            {
                sub.indexBuffer = new D3D.IndexBuffer(typeof(int), sub.indices.Length, renderer.device, D3D.Usage.None, D3D.Pool.Managed);
                sub.indexBuffer.SetData(sub.indices, 0, D3D.LockFlags.Discard);
            }
            if (tmpMaxVertex == 0)
            {
                tmpMaxVertex = 1;
            }
            vertexBuffer = new D3D.VertexBuffer(typeof(Vertex), tmpMaxVertex, renderer.device, D3D.Usage.None, D3D.VertexFormats.Position, D3D.Pool.Managed);
            vertexBuffer.SetData(vertices, 0, D3D.LockFlags.Discard);

            usedEffect = renderer.defaultEffect;
        }
コード例 #18
0
ファイル: BufferObjects.cs プロジェクト: stormont/terraingine
        /// <summary>
        /// Reloads the VertexBuffer for the TerrainPage for displaying vertices.
        /// </summary>
        public void RefreshVertexBuffer_Vertices()
        {
            if ( _page != null )
            {
                GraphicsStream stream;
                D3D.CustomVertex.PositionColored[] vertices = new
                    D3D.CustomVertex.PositionColored[_page.TerrainPatch.NumVertices * 4];
                D3D.CustomVertex.PositionNormal[] tri = _page.TerrainPatch.Vertices;
                int color = Color.Black.ToArgb();
                int red, blue;
                float zoomFactor = _viewport.Camera.FollowDistance / _originalZoomFactor;
                Vector3 position;
                float distance;
                float vDist = _page.TerrainPatch.NearestVertices * _vertexSize;

                for ( int i = 0; i < tri.Length; i++ )
                {
                    if ( _showSelectedVertices && _page.TerrainPatch.SelectedVertices[i] )
                        color = Color.Red.ToArgb();
                    else if ( _showSelectedVertices && _softSelection &&
                        _page.TerrainPatch.AreVerticesSelected )
                    {
                        position = _page.TerrainPatch.Vertices[i].Position;
                        distance = _page.TerrainPatch.FindShortestDistanceToSelectedVertex( position );

                        if ( distance <= _softDistanceSquared )
                        {
                            if ( _falloff )
                            {
                                red = Convert.ToInt32( Color.Red.R * ( 1 - distance / _softDistanceSquared ) );
                                blue = Convert.ToInt32( Color.Blue.B * ( distance / _softDistanceSquared ) );
                                color = Color.FromArgb( red, 0, blue ).ToArgb();
                            }
                            else
                                color = Color.Red.ToArgb();
                        }
                        else
                        {
                            color = Color.Blue.ToArgb();
                        }
                    }
                    else
                    {
                        color = Color.Blue.ToArgb();
                    }

                    vertices[i * 4].Position = new Vector3( tri[i].Position.X - ( vDist * zoomFactor ),
                        tri[i].Position.Y, tri[i].Position.Z - ( vDist * zoomFactor ) );
                    vertices[i * 4].Color = color;
                    vertices[i * 4 + 1].Position = new Vector3( tri[i].Position.X - ( vDist * zoomFactor ),
                        tri[i].Position.Y, tri[i].Position.Z + ( vDist * zoomFactor ) );
                    vertices[i * 4 + 1].Color = color;
                    vertices[i * 4 + 2].Position = new Vector3( tri[i].Position.X + ( vDist * zoomFactor ),
                        tri[i].Position.Y, tri[i].Position.Z + ( vDist * zoomFactor ) );
                    vertices[i * 4 + 2].Color = color;
                    vertices[i * 4 + 3].Position = new Vector3( tri[i].Position.X + ( vDist * zoomFactor ),
                        tri[i].Position.Y, tri[i].Position.Z - ( vDist * zoomFactor ) );
                    vertices[i * 4 + 3].Color = color;
                }

                if ( _vbVerts != null )
                {
                    if ( !_vbVerts.Disposed )
                        _vbVerts.Dispose();

                    _vbVerts = null;
                }

                _vbVerts = new D3D.VertexBuffer( typeof( D3D.CustomVertex.PositionColored ),
                    vertices.Length, _viewport.Device, D3D.Usage.WriteOnly,
                    D3D.CustomVertex.PositionColored.Format, D3D.Pool.Managed );

                stream = _vbVerts.Lock( 0, 0, D3D.LockFlags.None );
                stream.Write( vertices );
                _vbVerts.Unlock();

                _vbVertSize = vertices.Length;
                _page.TerrainPatch.RefreshVertices = false;
            }
            else if ( _vbVerts != null )
            {
                if ( !_vbVerts.Disposed )
                    _vbVerts.Dispose();

                _vbVerts = null;
                _vbVertSize = 0;
            }
        }
コード例 #19
0
ファイル: Devices.cs プロジェクト: itamargreen/metalx
        void init()
        {
            Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters();
            pps.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard;
            pps.Windowed = true;
            pps.BackBufferCount = 1;
            pps.PresentationInterval = PresentInterval.One;
            pps.BackBufferFormat = Format.A8R8G8B8;

            if (GameWindow == null)
            {
                //pps.BackBufferWidth = GameControl.Width;
                //pps.BackBufferHeight = GameControl.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            else
            {
                //pps.BackBufferWidth = GameWindow.Width;
                //pps.BackBufferHeight = GameWindow.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format;

            //D3DDev.ShowCursor(false);

            DSoundDev = new Microsoft.DirectX.DirectSound.Device();
            if (GameWindow == null)
            {
                DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }
            else
            {
                DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }

            DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            DKeyboardDev.Acquire();

            DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);
            DMouseDev.Acquire();

            VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed);

            D3DDev.SetStreamSource(0, VertexBuffer, 0);
            D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            Sprite = new Sprite(D3DDev);

            FontDescription fd = new FontDescription();
            fd.FaceName = "新宋体";
            fd.Height = -12;
            Font2D = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd);

            Font3D = new System.Drawing.Font("新宋体", 12);
        }
コード例 #20
0
ファイル: DXGraphics.cs プロジェクト: polytronicgr/eresys
 public VPListElement(VertexPool vp, Microsoft.DirectX.Direct3D.VertexBuffer vb)
 {
     this.vp = vp;
     this.vb = vb;
 }
コード例 #21
0
ファイル: BufferObjects.cs プロジェクト: stormont/terraingine
        /// <summary>
        /// Builds the vertex buffer using vertices with position and normal data.
        /// </summary>
        public void BuildVertices_PositionNormal()
        {
            GraphicsStream stream;
            DataCore.VertexFormats.PositionNormal[] tri =
                new DataCore.VertexFormats.PositionNormal[_page.TerrainPatch.NumVertices];

            for ( int i = 0; i < tri.Length; i++ )
            {
                tri[i].Position = _page.TerrainPatch.Vertices[i].Position;
                tri[i].Normal = _page.TerrainPatch.Vertices[i].Normal;
            }

            if ( _vb != null )
            {
                if ( !_vb.Disposed )
                    _vb.Dispose();

                _vb = null;
            }

            _vb = new D3D.VertexBuffer( typeof( DataCore.VertexFormats.PositionNormal ),
                tri.Length, _viewport.Device, D3D.Usage.WriteOnly,
                DataCore.VertexFormats.PositionNormal.Format, D3D.Pool.Managed );

            stream = _vb.Lock( 0, 0, D3D.LockFlags.None );
            stream.Write( tri );
            _vb.Unlock();

            _vbSize = tri.Length;
        }
コード例 #22
0
ファイル: BufferObjects.cs プロジェクト: stormont/terraingine
        /// <summary>
        /// Builds the vertex buffer using vertices with position, normal, and eight sets of texture data.
        /// </summary>
        public void BuildVertices_PositionNormalTextured8()
        {
            GraphicsStream stream;
            DataCore.VertexFormats.PositionNormalTextured8[] tri =
                new DataCore.VertexFormats.PositionNormalTextured8[_page.TerrainPatch.NumVertices];

            for ( int i = 0; i < tri.Length; i++ )
            {
                tri[i].Position = _page.TerrainPatch.Vertices[i].Position;
                tri[i].Normal = _page.TerrainPatch.Vertices[i].Normal;

                if ( _page.TerrainPatch.NumTextures > 0 )
                {
                    for ( int j = 0; j < _page.TerrainPatch.NumTextures && j < 8; j++ )
                        tri[i].SetTextureCoordinates( _page.TerrainPatch.GetTextureCoordinateList( j )[i],
                            j );
                }
                else
                    tri[i].SetTextureCoordinates( new Vector2( 0f, 0f ), 0 );
            }

            if ( _vb != null )
            {
                if ( !_vb.Disposed )
                    _vb.Dispose();

                _vb = null;
            }

            _vb = new D3D.VertexBuffer( typeof( DataCore.VertexFormats.PositionNormalTextured8 ),
                tri.Length, _viewport.Device, D3D.Usage.WriteOnly,
                DataCore.VertexFormats.PositionNormalTextured8.Format, D3D.Pool.Managed );

            stream = _vb.Lock( 0, 0, D3D.LockFlags.None );
            stream.Write( tri );
            _vb.Unlock();

            _vbSize = tri.Length;
        }
コード例 #23
0
        /// <summary>
        /// Reloads the VertexBuffer for the TerrainPage for displaying vertices.
        /// </summary>
        public void RefreshVertexBuffer_Vertices()
        {
            if (_page != null)
            {
                GraphicsStream stream;
                D3D.CustomVertex.PositionColored[] vertices = new
                                                              D3D.CustomVertex.PositionColored[_page.TerrainPatch.NumVertices * 4];
                D3D.CustomVertex.PositionNormal[] tri = _page.TerrainPatch.Vertices;
                int     color = Color.Black.ToArgb();
                int     red, blue;
                float   zoomFactor = _viewport.Camera.FollowDistance / _originalZoomFactor;
                Vector3 position;
                float   distance;
                float   vDist = _page.TerrainPatch.NearestVertices * _vertexSize;

                for (int i = 0; i < tri.Length; i++)
                {
                    if (_showSelectedVertices && _page.TerrainPatch.SelectedVertices[i])
                    {
                        color = Color.Red.ToArgb();
                    }
                    else if (_showSelectedVertices && _softSelection &&
                             _page.TerrainPatch.AreVerticesSelected)
                    {
                        position = _page.TerrainPatch.Vertices[i].Position;
                        distance = _page.TerrainPatch.FindShortestDistanceToSelectedVertex(position);

                        if (distance <= _softDistanceSquared)
                        {
                            if (_falloff)
                            {
                                red   = Convert.ToInt32(Color.Red.R * (1 - distance / _softDistanceSquared));
                                blue  = Convert.ToInt32(Color.Blue.B * (distance / _softDistanceSquared));
                                color = Color.FromArgb(red, 0, blue).ToArgb();
                            }
                            else
                            {
                                color = Color.Red.ToArgb();
                            }
                        }
                        else
                        {
                            color = Color.Blue.ToArgb();
                        }
                    }
                    else
                    {
                        color = Color.Blue.ToArgb();
                    }

                    vertices[i * 4].Position = new Vector3(tri[i].Position.X - (vDist * zoomFactor),
                                                           tri[i].Position.Y, tri[i].Position.Z - (vDist * zoomFactor));
                    vertices[i * 4].Color        = color;
                    vertices[i * 4 + 1].Position = new Vector3(tri[i].Position.X - (vDist * zoomFactor),
                                                               tri[i].Position.Y, tri[i].Position.Z + (vDist * zoomFactor));
                    vertices[i * 4 + 1].Color    = color;
                    vertices[i * 4 + 2].Position = new Vector3(tri[i].Position.X + (vDist * zoomFactor),
                                                               tri[i].Position.Y, tri[i].Position.Z + (vDist * zoomFactor));
                    vertices[i * 4 + 2].Color    = color;
                    vertices[i * 4 + 3].Position = new Vector3(tri[i].Position.X + (vDist * zoomFactor),
                                                               tri[i].Position.Y, tri[i].Position.Z - (vDist * zoomFactor));
                    vertices[i * 4 + 3].Color = color;
                }

                if (_vbVerts != null)
                {
                    if (!_vbVerts.Disposed)
                    {
                        _vbVerts.Dispose();
                    }

                    _vbVerts = null;
                }

                _vbVerts = new D3D.VertexBuffer(typeof(D3D.CustomVertex.PositionColored),
                                                vertices.Length, _viewport.Device, D3D.Usage.WriteOnly,
                                                D3D.CustomVertex.PositionColored.Format, D3D.Pool.Managed);

                stream = _vbVerts.Lock(0, 0, D3D.LockFlags.None);
                stream.Write(vertices);
                _vbVerts.Unlock();

                _vbVertSize = vertices.Length;
                _page.TerrainPatch.RefreshVertices = false;
            }
            else if (_vbVerts != null)
            {
                if (!_vbVerts.Disposed)
                {
                    _vbVerts.Dispose();
                }

                _vbVerts    = null;
                _vbVertSize = 0;
            }
        }
コード例 #24
0
ファイル: BufferObjects.cs プロジェクト: stormont/terraingine
        /// <summary>
        /// Clears the buffers used.
        /// </summary>
        public void ClearBuffers()
        {
            if ( _vb != null && !_vb.Disposed )
            {
                _vb.Dispose();
                _vb = null;
                _vbSize = 0;
            }

            if ( _vbVerts != null && !_vbVerts.Disposed )
            {
                _vbVerts.Dispose();
                _vbVerts = null;
                _vbVertSize = 0;
            }

            if ( _vbByHeight != null && !_vbByHeight.Disposed )
            {
                _vbByHeight.Dispose();
                _vbByHeight = null;
                _vbSize = 0;
            }

            if ( _ib != null && !_ib.Disposed )
            {
                _ib.Dispose();
                _ib = null;
                _ibSize = 0;
            }

            if ( _ibVerts != null && !_ibVerts.Disposed )
            {
                _ibVerts.Dispose();
                _ibVerts = null;
                _ibVertSize = 0;
            }
        }
コード例 #25
0
        /// <summary>
        /// Reloads the VertexBuffer for the TerrainPage.
        /// </summary>
        public void RefreshVertexBuffer_Page()
        {
            if (_page != null)
            {
                if (!_colorByHeight)
                {
                    // Determine which list of vertices to build
                    switch (_viewport.Device.DeviceCaps.MaxSimultaneousTextures)
                    {
                    case 0:
                        BuildVertices_PositionNormal();
                        break;

                    case 1:
                        BuildVertices_PositionNormalTextured1();
                        break;

                    case 2:
                        BuildVertices_PositionNormalTextured2();
                        break;

                    case 3:
                        BuildVertices_PositionNormalTextured3();
                        break;

                    case 4:
                        BuildVertices_PositionNormalTextured4();
                        break;

                    case 5:
                        BuildVertices_PositionNormalTextured5();
                        break;

                    case 6:
                        BuildVertices_PositionNormalTextured6();
                        break;

                    case 7:
                        BuildVertices_PositionNormalTextured7();
                        break;

                    case 8:
                    default:
                        BuildVertices_PositionNormalTextured8();
                        break;
                    }
                }
                else
                {
                    // Build non-textured vertex buffer
                    GraphicsStream stream;
                    int            vertColor;
                    D3D.CustomVertex.PositionNormalColored[] tri =
                        new D3D.CustomVertex.PositionNormalColored[_page.TerrainPatch.NumVertices];

                    for (int i = 0; i < tri.Length; i++)
                    {
                        tri[i].Position = _page.TerrainPatch.Vertices[i].Position;
                        tri[i].Normal   = _page.TerrainPatch.Vertices[i].Normal;
                        vertColor       = (int)((tri[i].Position.Y / _page.MaximumVertexHeight) * 255.0f);
                        tri[i].Color    = Color.FromArgb(vertColor, vertColor, vertColor).ToArgb();
                    }

                    if (_vbByHeight == null)
                    {
                        _vbByHeight = new D3D.VertexBuffer(typeof(D3D.CustomVertex.PositionNormalColored),
                                                           tri.Length, _viewport.Device, D3D.Usage.Dynamic | D3D.Usage.WriteOnly,
                                                           D3D.CustomVertex.PositionNormalColored.Format, D3D.Pool.Default);
                    }

                    stream = _vbByHeight.Lock(0, 0, D3D.LockFlags.Discard);
                    stream.Write(tri);
                    _vbByHeight.Unlock();

                    _vbSize = tri.Length;
                }

                _page.TerrainPatch.RefreshBuffers = false;
            }
            else
            {
                if (_vb != null)
                {
                    if (!_vb.Disposed)
                    {
                        _vb.Dispose();
                    }

                    _vb     = null;
                    _vbSize = 0;
                }

                if (_vbByHeight != null)
                {
                    if (!_vbByHeight.Disposed)
                    {
                        _vbByHeight.Dispose();
                    }

                    _vbByHeight = null;
                    _vbSize     = 0;
                }
            }
        }
コード例 #26
0
ファイル: BufferObjects.cs プロジェクト: stormont/terraingine
        /// <summary>
        /// Reloads the VertexBuffer for the TerrainPage.
        /// </summary>
        public void RefreshVertexBuffer_Page()
        {
            if ( _page != null )
            {
                if ( !_colorByHeight )
                {
                    // Determine which list of vertices to build
                    switch ( _viewport.Device.DeviceCaps.MaxSimultaneousTextures )
                    {
                        case 0:
                            BuildVertices_PositionNormal();
                            break;

                        case 1:
                            BuildVertices_PositionNormalTextured1();
                            break;

                        case 2:
                            BuildVertices_PositionNormalTextured2();
                            break;

                        case 3:
                            BuildVertices_PositionNormalTextured3();
                            break;

                        case 4:
                            BuildVertices_PositionNormalTextured4();
                            break;

                        case 5:
                            BuildVertices_PositionNormalTextured5();
                            break;

                        case 6:
                            BuildVertices_PositionNormalTextured6();
                            break;

                        case 7:
                            BuildVertices_PositionNormalTextured7();
                            break;

                        case 8:
                        default:
                            BuildVertices_PositionNormalTextured8();
                            break;
                    }
                }
                else
                {
                    // Build non-textured vertex buffer
                    GraphicsStream stream;
                    int vertColor;
                    D3D.CustomVertex.PositionNormalColored[] tri =
                        new D3D.CustomVertex.PositionNormalColored[_page.TerrainPatch.NumVertices];

                    for ( int i = 0; i < tri.Length; i++ )
                    {
                        tri[i].Position = _page.TerrainPatch.Vertices[i].Position;
                        tri[i].Normal = _page.TerrainPatch.Vertices[i].Normal;
                        vertColor = (int) ( ( tri[i].Position.Y / _page.MaximumVertexHeight ) * 255.0f );
                        tri[i].Color = Color.FromArgb( vertColor, vertColor, vertColor ).ToArgb();
                    }

                    if ( _vbByHeight == null )
                        _vbByHeight = new D3D.VertexBuffer( typeof( D3D.CustomVertex.PositionNormalColored ),
                            tri.Length, _viewport.Device, D3D.Usage.Dynamic | D3D.Usage.WriteOnly,
                            D3D.CustomVertex.PositionNormalColored.Format, D3D.Pool.Default );

                    stream = _vbByHeight.Lock( 0, 0, D3D.LockFlags.Discard );
                    stream.Write( tri );
                    _vbByHeight.Unlock();

                    _vbSize = tri.Length;
                }

                _page.TerrainPatch.RefreshBuffers = false;
            }
            else
            {
                if ( _vb != null )
                {
                    if ( !_vb.Disposed )
                        _vb.Dispose();

                    _vb = null;
                    _vbSize = 0;
                }

                if ( _vbByHeight != null )
                {
                    if ( !_vbByHeight.Disposed )
                        _vbByHeight.Dispose();

                    _vbByHeight = null;
                    _vbSize = 0;
                }
            }
        }
コード例 #27
0
        private bool Initialize(GeometryManager manager, Type vertexType, int size,bool pointsprites,bool dynamic )
        {
            if (IsTypeValid(vertexType))
            {
                try
                {
                    D3d.Pool d3dPool = D3d.Pool.Managed;
                    D3d.Usage d3dUsage = D3d.Usage.WriteOnly;

                    if ( dynamic )
                    {
                        d3dUsage |= D3d.Usage.Dynamic;
                    }

                    if (pointsprites)
                    {
                        d3dUsage |= D3d.Usage.Points;
                    }

                    d3dManager      = manager;
                    d3dVertexType   = vertexType;
                    d3dVertexSize   = size;

                    d3dVertexBuffer = new D3d.VertexBuffer( vertexType,
                                                            size,
                                                            manager.Device.D3dDevice,
                                                            d3dUsage,
                                                            D3d.VertexFormats.None,
                                                            d3dPool);

                    return true;
                }
                catch (D3d.InvalidCallException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
                catch (D3d.OutOfVideoMemoryException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
                catch (OutOfMemoryException e)
                {
                    log.Warning("Unable to create vertex stream: {0}", e.Message);
                }
               }

               return false;
        }
コード例 #28
0
 public void SetStreamSource(int streamNumber, VertexBuffer streamData, int offsetInBytes, int stride)
 {
     throw new NotImplementedException();
 }
コード例 #29
0
    /// <summary>
    /// Restore the font after a device has been reset
    /// </summary>
    public void RestoreDeviceObjects(object sender, EventArgs e)
    {
        vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColoredTextured), MaxNumfontVertices,
            device, Usage.WriteOnly | Usage.Dynamic, 0, Pool.Default);

        Surface surf = device.GetRenderTarget( 0 );
        bool bSupportsAlphaBlend = Manager.CheckDeviceFormat(device.DeviceCaps.AdapterOrdinal,
            device.DeviceCaps.DeviceType, device.DisplayMode.Format,
            Usage.RenderTarget | Usage.QueryPostPixelShaderBlending, ResourceType.Surface,
            surf.Description.Format );

        // Create the state blocks for rendering text
        for (int which=0; which < 2; which++) {
            device.BeginStateBlock();
            device.SetTexture(0, fontTexture);

            if (isZEnable)
                renderState.ZBufferEnable = true;
            else
                renderState.ZBufferEnable = false;

            if( bSupportsAlphaBlend ) {
                renderState.AlphaBlendEnable = true;
                renderState.SourceBlend = Blend.SourceAlpha;
                renderState.DestinationBlend = Blend.InvSourceAlpha;
            }
            else {
                renderState.AlphaBlendEnable = false;
            }
            renderState.AlphaTestEnable = true;
            renderState.ReferenceAlpha = 0x08;
            renderState.AlphaFunction = Compare.GreaterEqual;
            renderState.FillMode = FillMode.Solid;
            renderState.CullMode = Cull.CounterClockwise;
            renderState.StencilEnable = false;
            renderState.Clipping = true;
            device.ClipPlanes.DisableAll();
            renderState.VertexBlend = VertexBlend.Disable;
            renderState.IndexedVertexBlendEnable = false;
            renderState.FogEnable = false;
            renderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;
            textureState0.ColorOperation = TextureOperation.Modulate;
            textureState0.ColorArgument1 = TextureArgument.TextureColor;
            textureState0.ColorArgument2 = TextureArgument.Diffuse;
            textureState0.AlphaOperation = TextureOperation.Modulate;
            textureState0.AlphaArgument1 = TextureArgument.TextureColor;
            textureState0.AlphaArgument2 = TextureArgument.Diffuse;
            textureState0.TextureCoordinateIndex = 0;
            textureState0.TextureTransform = TextureTransform.Disable; // REVIEW
            textureState1.ColorOperation = TextureOperation.Disable;
            textureState1.AlphaOperation = TextureOperation.Disable;
            samplerState0.MinFilter = TextureFilter.Point;
            samplerState0.MagFilter = TextureFilter.Point;
            samplerState0.MipFilter = TextureFilter.None;

            if (which==0)
                savedStateBlock = device.EndStateBlock();
            else
                drawTextStateBlock = device.EndStateBlock();
        }
    }
コード例 #30
0
 public void ProcessVertices(int srcStartIndex, int destIndex, int vertexCount, VertexBuffer destBuffer, VertexDeclaration vertexDeclaration, bool copyData)
 {
     throw new NotImplementedException();
 }