示例#1
0
        /// <summary>
        /// Gets all points contained within a <see cref="Mesh"/>.
        /// </summary>
        /// <param name="mesh">The <see cref="Mesh"/> to get points from.</param>
        /// <returns>An array of points defined by the object.</returns>
        private static Vector3[] GetPoints(Mesh mesh)
        {
            DataStream vertexStream = mesh.LockVertexBuffer(LockFlags.ReadOnly);
            var        points       = D3DX.GetVectors(vertexStream, mesh.VertexCount, mesh.VertexFormat);

            mesh.UnlockVertexBuffer();
            vertexStream.Dispose();

            return(points);
        }
示例#2
0
        /// <summary>
        /// Gets all points contained within a <see cref="VertexBuffer"/>.
        /// </summary>
        /// <param name="buffer">The <see cref="VertexBuffer"/> to get points from.</param>
        /// <param name="vertexCount">The total number of vertex contained within <paramref name="buffer"/>.</param>
        /// <returns>An array of points defined by the object.</returns>
        private static Vector3[] GetPoints(VertexBuffer buffer, int vertexCount)
        {
            DataStream vertexStream = buffer.Lock(0, buffer.Description.SizeInBytes, LockFlags.ReadOnly);
            var        points       = D3DX.GetVectors(vertexStream, vertexCount, buffer.Description.SizeInBytes / vertexCount);

            buffer.Unlock();
            vertexStream.Dispose();

            return(points);
        }
示例#3
0
        //--------------------//

        #region Vertex buffer
        /// <summary>
        /// Sets a <see cref="VertexBuffer"/> with a fixed-function vertex format as the current active stream source.
        /// </summary>
        /// <param name="buffer">The <see cref="VertexBuffer"/> with a fixed-function vertex format.</param>
        public void SetVertexBuffer(VertexBuffer buffer)
        {
            #region Sanity checks
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (buffer.Description.FVF == VertexFormat.None)
            {
                throw new ArgumentException(Resources.VBMustBeFVF, nameof(buffer));
            }
            #endregion

            _device.SetStreamSource(0, buffer, 0, D3DX.GetFVFVertexSize(buffer.Description.FVF));
            _device.VertexFormat = buffer.Description.FVF;
        }
示例#4
0
        //this method gets called, when Reinitialize() was called in evaluate,
        //or a graphics device asks for its data
        protected override Texture CreateTexture(int slice, Device device)
        {
            int    p     = unchecked ((int)FHandleIn[slice]);
            IntPtr share = new IntPtr(p);
            Format format;

            if (FFormat[slice].Name == "INTZ")
            {
                format = D3DX.MakeFourCC((byte)'I', (byte)'N', (byte)'T', (byte)'Z');
            }
            else if (FFormat[slice].Name == "RAWZ")
            {
                format = D3DX.MakeFourCC((byte)'R', (byte)'A', (byte)'W', (byte)'Z');
            }
            else if (FFormat[slice].Name == "RESZ")
            {
                format = D3DX.MakeFourCC((byte)'R', (byte)'E', (byte)'S', (byte)'Z');
            }
            else
            {
                format = (Format)Enum.Parse(typeof(Format), FFormat[slice], true);
            }

            Texture texture = null;

            try
            {
                var usage = Usage.Dynamic;
                if (FUsage[slice].Index == (int)(TextureType.RenderTarget))
                {
                    usage = Usage.RenderTarget;
                }
                else if (FUsage[slice].Index == (int)(TextureType.DepthStencil))
                {
                    usage = Usage.DepthStencil;
                }

                texture = new Texture(device, Math.Max(FWidthIn[slice], 1), Math.Max(FHeightIn[slice], 1), 1, usage, format, Pool.Default, ref share);
            }
            catch (Exception e)
            {
                FLogger.Log(LogType.Debug, e.Message + " Handle: " + FHandleIn[slice] + " Format: " + format.ToString());
            }
            return(texture);
        }
        public ReadTexture(int width, int height, uint handle, EnumEntry formatEnum, EnumEntry usageEnum)
        {
            Format format;

            if (formatEnum.Name == "INTZ")
            {
                format = D3DX.MakeFourCC((byte)'I', (byte)'N', (byte)'T', (byte)'Z');
            }
            else if (formatEnum.Name == "RAWZ")
            {
                format = D3DX.MakeFourCC((byte)'R', (byte)'A', (byte)'W', (byte)'Z');
            }
            else if (formatEnum.Name == "RESZ")
            {
                format = D3DX.MakeFourCC((byte)'R', (byte)'E', (byte)'S', (byte)'Z');
            }
            else if (formatEnum.Name == "No Specific")
            {
                throw (new Exception("Texture mode not supported"));
            }
            else
            {
                format = (Format)Enum.Parse(typeof(Format), formatEnum, true);
            }

            var usage = Usage.Dynamic;

            if (usageEnum.Index == (int)(TextureType.RenderTarget))
            {
                usage = Usage.RenderTarget;
            }
            else if (usageEnum.Index == (int)(TextureType.DepthStencil))
            {
                usage = Usage.DepthStencil;
            }

            this.FWidth  = width;
            this.FHeight = height;
            this.FHandle = (IntPtr) unchecked ((int)handle);
            this.FFormat = format;
            this.FUsage  = usage;

            Initialise();
        }
示例#6
0
        public unsafe SkyBox(Device dev)
        {
            device = dev;

            // sqrt(3)/3
            const float l = 1f / MathEx.Root3;

            vtxDecl = new VertexDeclaration(device, D3DX.DeclaratorFromFVF(SkyVertex.Format));
            box     = new VertexBuffer(dev, sizeof(SkyVertex) * 8, Usage.WriteOnly, VertexPT1.Format, Pool.Managed);

            SkyVertex *dst = (SkyVertex *)box.Lock(0, 0, LockFlags.None).DataPointer.ToPointer();

            dst[0] = new SkyVertex {
                pos = new Vector3(-50f, -50f, -50f), texCoord = new Vector3(-l, -l, -l)
            };
            dst[1] = new SkyVertex {
                pos = new Vector3(50f, -50f, -50f), texCoord = new Vector3(l, -l, -l)
            };
            dst[2] = new SkyVertex {
                pos = new Vector3(-50f, -50f, 50f), texCoord = new Vector3(-l, -l, l)
            };
            dst[3] = new SkyVertex {
                pos = new Vector3(50f, -50f, 50f), texCoord = new Vector3(l, -l, l)
            };
            dst[4] = new SkyVertex {
                pos = new Vector3(-50f, 50f, -50f), texCoord = new Vector3(-l, l, -l)
            };
            dst[5] = new SkyVertex {
                pos = new Vector3(50f, 50f, -50f), texCoord = new Vector3(l, l, -l)
            };
            dst[6] = new SkyVertex {
                pos = new Vector3(-50f, 50f, 50f), texCoord = new Vector3(-l, l, l)
            };
            dst[7] = new SkyVertex {
                pos = new Vector3(50f, 50, 50f), texCoord = new Vector3(l, l, l)
            };

            box.Unlock();

            indexBuffer = new IndexBuffer(dev, sizeof(ushort) * 36, Usage.WriteOnly, Pool.Managed, true);

            ushort *ibDst = (ushort *)indexBuffer.Lock(0, 0, LockFlags.None).DataPointer.ToPointer();

            ibDst[0] = 0;
            ibDst[1] = 1;
            ibDst[2] = 3;

            ibDst[3] = 0;
            ibDst[4] = 3;
            ibDst[5] = 2;


            ibDst[6] = 0;
            ibDst[7] = 4;
            ibDst[8] = 5;

            ibDst[9]  = 0;
            ibDst[10] = 5;
            ibDst[11] = 1;



            ibDst[12] = 2;
            ibDst[13] = 6;
            ibDst[14] = 4;

            ibDst[15] = 2;
            ibDst[16] = 4;
            ibDst[17] = 0;


            ibDst[18] = 3;
            ibDst[19] = 7;
            ibDst[20] = 6;

            ibDst[21] = 3;
            ibDst[22] = 6;
            ibDst[23] = 2;


            ibDst[24] = 1;
            ibDst[25] = 5;
            ibDst[26] = 7;

            ibDst[27] = 1;
            ibDst[28] = 7;
            ibDst[29] = 3;


            ibDst[30] = 6;
            ibDst[31] = 7;
            ibDst[32] = 5;

            ibDst[33] = 6;
            ibDst[34] = 5;
            ibDst[35] = 4;

            //ibDst[0] = 0;
            //ibDst[1] = 1;
            //ibDst[2] = 3;

            //ibDst[3] = 0;
            //ibDst[4] = 2;
            //ibDst[5] = 3;


            //ibDst[6] = 4;
            //ibDst[7] = 5;
            //ibDst[8] = 7;

            //ibDst[9] = 4;
            //ibDst[10] = 6;
            //ibDst[11] = 7;



            //ibDst[12] = 0;
            //ibDst[13] = 1;
            //ibDst[14] = 4;

            //ibDst[15] = 1;
            //ibDst[16] = 4;
            //ibDst[17] = 5;


            //ibDst[18] = 0;
            //ibDst[19] = 4;
            //ibDst[20] = 2;

            //ibDst[21] = 4;
            //ibDst[22] = 6;
            //ibDst[23] = 2;


            //ibDst[24] = 1;
            //ibDst[25] = 3;
            //ibDst[26] = 5;

            //ibDst[27] = 5;
            //ibDst[28] = 7;
            //ibDst[29] = 3;


            //ibDst[30] = 2;
            //ibDst[31] = 3;
            //ibDst[32] = 6;

            //ibDst[33] = 2;
            //ibDst[34] = 7;
            //ibDst[35] = 3;

            indexBuffer.Unlock();



            FileLocation        fl = FileSystem.Instance.Locate(FileSystem.CombinePath(Paths.Effects, "DayNight.fx"), FileLocateRules.Default);
            ContentStreamReader sr = new ContentStreamReader(fl);
            string code            = sr.ReadToEnd();
            string err;

            effect = Effect.FromString(device, code, null, IncludeHandler.Instance, null, ShaderFlags.None, null, out err);

            effect.Technique = new EffectHandle("DayNight");

            nightAlpha = new EffectHandle("nightAlpha");

            day   = new EffectHandle("Day");
            night = new EffectHandle("Night");
        }
示例#7
0
 public Rectangle(Rectangle rectangle, D3DX d3dx) : base(rectangle, d3dx)
 {
 }