Пример #1
0
        /// <summary>
        /// Gets the drawing effect for the current instance
        /// </summary>
        /// <param name="mode">Drawing mode</param>
        /// <returns>Returns the drawing effect</returns>
        protected IGeometryDrawer GetEffect(DrawerModes mode)
        {
            if (mode.HasFlag(DrawerModes.Forward))
            {
                return(DrawerPool.EffectDefaultBasic);
            }
            else if (mode.HasFlag(DrawerModes.Deferred))
            {
                return(DrawerPool.EffectDeferredBasic);
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Draws a mesh with a geometry drawer
        /// </summary>
        /// <param name="effect">Effect</param>
        /// <param name="drawingData">Drawing data</param>
        /// <param name="mode">Drawer mode</param>
        /// <param name="meshName">Mesh name</param>
        /// <param name="index">Instance buffer index</param>
        /// <param name="length">Instance buffer length</param>
        /// <returns>Returns the number of drawn triangles</returns>
        private int DrawMesh(IGeometryDrawer effect, DrawingData drawingData, DrawerModes mode, string meshName, int index, int length)
        {
            int count = 0;

            var graphics = this.Game.Graphics;

            var meshDict = drawingData.Meshes[meshName];

            foreach (string materialName in meshDict.Keys)
            {
                var mesh     = meshDict[materialName];
                var material = drawingData.Materials[materialName];

                bool transparent = material.Material.IsTransparent && this.Description.AlphaEnabled;
                if (mode.HasFlag(DrawerModes.OpaqueOnly) && transparent)
                {
                    continue;
                }
                if (mode.HasFlag(DrawerModes.TransparentOnly) && !transparent)
                {
                    continue;
                }

                count += mesh.IndexBuffer.Count > 0 ? mesh.IndexBuffer.Count / 3 : mesh.VertexBuffer.Count / 3;

                effect.UpdatePerObject(0, material, 0, this.UseAnisotropicFiltering);

                this.BufferManager.SetIndexBuffer(mesh.IndexBuffer.Slot);

                var technique = effect.GetTechnique(mesh.VertextType, true);
                this.BufferManager.SetInputAssembler(technique, mesh.VertexBuffer.Slot, mesh.Topology);

                for (int p = 0; p < technique.PassCount; p++)
                {
                    graphics.EffectPassApply(technique, p, 0);

                    mesh.Draw(graphics, index, length);
                }
            }

            return(count);
        }
Пример #3
0
        /// <summary>
        /// Drawing
        /// </summary>
        /// <param name="effect">Effect for drawing</param>
        /// <param name="drawerMode">Drawe mode</param>
        private void Draw(EffectDefaultGpuParticles effect, DrawerModes drawerMode)
        {
            var rot = this.parameters.RotateSpeed != Vector2.Zero;

            var techniqueForDrawing = rot ? effect.RotationDraw : effect.NonRotationDraw;

            if (!drawerMode.HasFlag(DrawerModes.ShadowMap))
            {
                Counters.InstancesPerFrame++;
            }

            var graphics = this.Game.Graphics;

            graphics.IAInputLayout = rot ? this.rotatingInputLayout : this.nonRotatingInputLayout;
            graphics.IASetVertexBuffers(BufferSlot, this.drawingBinding);
            graphics.IAPrimitiveTopology = PrimitiveTopology.PointList;

            graphics.SetDepthStencilRDZEnabled();

            if (this.parameters.Additive)
            {
                graphics.SetBlendAdditive();
            }
            else if (this.parameters.Transparent)
            {
                graphics.SetBlendDefaultAlpha();
            }
            else
            {
                graphics.SetBlendDefault();
            }

            for (int p = 0; p < techniqueForDrawing.PassCount; p++)
            {
                graphics.EffectPassApply(techniqueForDrawing, p, 0);

                graphics.DrawAuto();
            }
        }