Apply() public method

public Apply ( ) : void
return void
Ejemplo n.º 1
0
        public override void Render(GraphicsDevice myDevice, EffectPass pass)
        {
            pass.Apply();

            myDevice.Textures[0] = Texture;
            myDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, Vertices, 0, 4, Indexes, 0, 2);
        }
Ejemplo n.º 2
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
                return;

            if (effect == null)
            {
                effect = new BasicEffect(graphics.Device);
                effect.World = Microsoft.Xna.Framework.Matrix.Identity;
                effect.VertexColorEnabled = true;
            }

            effect.Projection = graphics.GetEffect().Projection;
            effect.View = graphics.GetEffect().View;

            pass = effect.CurrentTechnique.Passes[0];
            pass.Apply();

            int pointCount = lines.Count;
            int linesCount = pointCount / 2;
            VertexPositionColor[] linesArray = new VertexPositionColor[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                int color = lines[i].Color;
                linesArray[i].Color = new Color(color & 0xff, (color & 0xff00) >> 8, (color & 0xff0000) >> 16, 1);
                linesArray[i].Position = MathHelper.Convert(lines[i].Position);
            }
            graphics.Device.DrawUserPrimitives(PrimitiveType.LineList, linesArray, 0, linesCount);
            lines.Clear();
        }
        internal void Draw(Texture2D[] textures, GraphicsDevice device, BasicEffect effect, EffectPass pass)
        {
            effect.World = displayObject.WorldTransform;
            effect.Texture = textures[displayObject.TextureIndex];
            device.SetVertexBuffer(vertexBuffer);
            device.Indices = indexBuffer;
            pass.Apply();

            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
        }
        /// <summary>
        /// Draws the models managed by the batch.
        /// </summary>
        public void Draw(Effect effect, EffectParameter worldTransformsParameter, EffectParameter textureIndicesParameter, EffectPass pass)
        {
            if (vertices.Length > 0)
            {
                graphicsDevice.SetVertexBuffers(bindings);
                graphicsDevice.Indices = indexBuffer;
                worldTransformsParameter.SetValue(worldTransforms);
                textureIndicesParameter.SetValue(textureIndices);
                pass.Apply();

                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                     0, 0, vertices.Length,
                                                     0, indices.Length / 3);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sorts the batch items and then groups batch drawing into maximal allowed batch sets that do not
        /// overflow the 16 bit array indices for vertices.
        /// </summary>
        /// <param name="sortMode">The type of depth sorting desired for the rendering.</param>
        public unsafe void DrawBatch(SpriteSortMode sortMode, EffectPass defaultSpritePass)
        {
            // nothing to do
            if (_batchItemCount == 0)
            {
                return;
            }

            // sort the batch items
            switch (sortMode)
            {
            case SpriteSortMode.Texture:
            case SpriteSortMode.FrontToBack:
            case SpriteSortMode.BackToFront:
                Array.Sort(_batchItemList, 0, _batchItemCount);
                break;
            }

            // Determine how many iterations through the drawing code we need to make
            int batchIndex = 0;
            int batchCount = _batchItemCount;


            unchecked
            {
                _device._graphicsMetrics._spriteCount += batchCount;
            }

            // Iterate through the batches, doing short.MaxValue sets of vertices only.
            while (batchCount > 0)
            {
                // setup the vertexArray array
                var       startIndex = 0;
                var       index      = 0;
                Texture2D tex        = null;
                SpriteBatch.EffectWithParams effect = default;

                int numBatchesToProcess = batchCount;
                if (numBatchesToProcess > MaxBatchSize)
                {
                    numBatchesToProcess = MaxBatchSize;
                }

                // Avoid the array checking overhead by using pointer indexing!
                fixed(VertexPositionColorTexture *vertexArrayFixedPtr = _vertexArray)
                {
                    var vertexArrayPtr = vertexArrayFixedPtr;

                    // Draw the batches
                    for (int i = 0; i < numBatchesToProcess; i++, batchIndex++, index += 4, vertexArrayPtr += 4)
                    {
                        SpriteBatchItem item = _batchItemList[batchIndex];
                        // if the texture changed, we need to flush and bind the new texture
                        var shouldFlush =
                            !ReferenceEquals(item.Texture, tex) ||
                            !ReferenceEquals(item.Effect.Effect, effect.Effect) ||
                            !ReferenceEquals(item.Effect.Params, effect.Params);
                        if (shouldFlush)
                        {
                            FlushVertexArray(startIndex, index, effect.Effect, tex);

                            tex    = item.Texture;
                            effect = item.Effect;
                            if (effect.Effect is null || effect.Params is null)
                            {
                                defaultSpritePass.Apply();
                            }
                            else
                            {
                                effect.Apply();
                            }
                            startIndex          = index = 0;
                            vertexArrayPtr      = vertexArrayFixedPtr;
                            _device.Textures[0] = tex;
                        }

                        // store the SpriteBatchItem data in our vertexArray
                        *(vertexArrayPtr + 0) = item.vertexTL;
                        *(vertexArrayPtr + 1) = item.vertexTR;
                        *(vertexArrayPtr + 2) = item.vertexBL;
                        *(vertexArrayPtr + 3) = item.vertexBR;

                        // Release the texture.
                        item.Texture = null;
                        item.Effect  = default;
                    }
                }

                // flush the remaining vertexArray data
                FlushVertexArray(startIndex, index, effect.Effect, tex);
                // Update our batch count to continue the process of culling down
                // large batches
                batchCount -= numBatchesToProcess;
            }
Ejemplo n.º 6
0
        private void DrawTexture(EffectPass pass)
        {
            basicEffect.VertexColorEnabled = false;
            basicEffect.TextureEnabled = true;
            basicEffect.Texture = animals;
            pass.Apply();

            overlayVertexBuffer.SetData(OverlayVertices);
            device.SetVertexBuffer(overlayVertexBuffer);

            device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, indexBuffer.IndexCount, 0, indexBuffer.IndexCount - 2);
        }
Ejemplo n.º 7
0
        private void DrawTerrain(EffectPass pass)
        {
            basicEffect.VertexColorEnabled = true;
            basicEffect.TextureEnabled = false;
            pass.Apply();

            device.SetVertexBuffer(terrainVertexBuffer);
            device.Indices = indexBuffer;

            device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, indexBuffer.IndexCount, 0, indexBuffer.IndexCount - 2);
        }
Ejemplo n.º 8
0
        private void RenderTest(EffectPass pass, float beat)
        {
            var gemTextureOuter = Get1x1Texture(Color.Black);

            basicEffect.View = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);
            var gem = rings[0].gems[0];
            basicEffect.TextureEnabled = true;
            basicEffect.Texture = gemTextureOuter;
            //basicEffect.World = Matrix.CreateRotationY(beat);
            pass.Apply();

            device.SetVertexBuffer(gem.Model.VertexBufferOuter);
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, gem.Model.VertexBufferOuter.VertexCount / 3);

            basicEffect.TextureEnabled = true;
            basicEffect.Texture = gem.Model.Texture;
            //basicEffect.World = Matrix.CreateRotationY(beat);
            pass.Apply();

            device.SetVertexBuffer(gem.Model.VertexBufferInner);
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, gem.Model.VertexBufferInner.VertexCount / 3);
        }
Ejemplo n.º 9
0
        private void RenderRings(EffectPass pass, float beat)
        {
            int farRing = (int)((beat - STARTBEAT) * RINGSPERBEAT);
            if (farRing < 0)
                return;
            if (farRing >= rings.Length)
                farRing = rings.Length - 1;

            var cameraPos = new Vector3(
                GetRingCenter(beat - BEATSOFVISIBILITY * 3 / 4),
                GetFarRingDepth(beat) + BEATSOFVISIBILITY * RINGSPERBEAT * DEPTHPERRING
            );

            basicEffect.View = Matrix.CreateLookAt(cameraPos, Vector3.Add(cameraPos, -Vector3.UnitZ), Vector3.Up);

            var gemTextureOuter = Get1x1Texture(Color.Black);

            for (int i = farRing; i >= 0; i--)
            {
                foreach (Gem gem in rings[i].gems)
                {
                    basicEffect.World = gem.Scale;
                    basicEffect.World *= gem.Rotation;
                    basicEffect.World *= Matrix.CreateTranslation(new Vector3(rings[i].center, 0));
                    basicEffect.World *= Matrix.CreateTranslation(gem.Position);
                    basicEffect.TextureEnabled = true;
                    basicEffect.Texture = gemTextureOuter;
                    pass.Apply();

                    device.SetVertexBuffer(gem.Model.VertexBufferOuter);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, gem.Model.VertexBufferOuter.VertexCount / 3);

                    basicEffect.Texture = gem.Model.Texture;
                    pass.Apply();

                    device.SetVertexBuffer(gem.Model.VertexBufferInner);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, gem.Model.VertexBufferInner.VertexCount / 3);
                }

                //Stop drawing gems behind camera
                if (rings[i].gems[0].Position.Z > cameraPos.Z)
                    break;
            }
        }
Ejemplo n.º 10
0
        private void DrawFaceBackgrounds(EffectPass pass)
        {
            device.SetVertexBuffer(faceVertexBuffer);
            for (int i = 0; i < cubeTextures.Length; i++)
            {
                basicEffect.Texture = cubeTextures[i];
                basicEffect.World = faceWorldMatrices[i] * GetCubeWorldMatrix(Beat);
                pass.Apply();

                device.DrawPrimitives(PrimitiveType.TriangleList, 0, faceVertexBuffer.VertexCount - 2);
            }
        }
Ejemplo n.º 11
0
        private void DrawCutieMarks(EffectPass pass)
        {
            basicEffect.Texture = spriteSheet;

            //Start animation at beat 10 ramping up to full speed six beats later
            var skewBeat = Beat < 10 ? 0 : GetSkewBeat(Beat - 10, 6);

            for (int i = 0; i < cubeTextures.Length; i++)
            {
                basicEffect.World = faceWorldMatrices[i] * GetCubeWorldMatrix(Beat);
                pass.Apply();

                //List of VertexPositionNormalTextures to be drawn as a triangle list
                var vertices = GetPonyVertices(i, skewBeat);

                device.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count / 3);
            }
        }
Ejemplo n.º 12
0
        protected internal virtual bool OnNextPass(EffectTechnique technique, RenderContext context, ref int index, out EffectPass pass)
        {
            Debug.Assert(index >= 0, "Invalid index.");

              int numberOfPasses = technique.Passes.Count;
              if (index >= numberOfPasses)
              {
            // Finished: All effect passes have been applied.
            context.PassIndex = -1;
            pass = null;
            return false;
              }

              context.PassIndex = index;
              pass = technique.Passes[index];
              index++;

              if (index == numberOfPasses - 1
              && string.Equals(pass.Name, "Restore", StringComparison.OrdinalIgnoreCase))
              {
            // A last effect pass may be used to restore the default render states without
            // drawing anything. The effect pass needs to be called "Restore".
            pass.Apply();

            // Finished: All effect passes have been applied.
            context.PassIndex = -1;
            pass = null;
            return false;
              }

              return true;
        }
Ejemplo n.º 13
0
    protected override bool OnNextPass(EffectTechnique technique, RenderContext context, ref int index, out EffectPass pass)
    {
      int numberOfPasses = technique.Passes.Count;

      // Progress to next pass when the desired number of repetitions were performed.
      // (Note: We use a while statement and not an if statement, because the desired
      // number of repetitions returned by GetPassRepetitionCount() could theoretically
      // be 0.)
      while (_actualPassCount >= _desiredPassCount)
      {
        // Finished with current pass. Progress to next pass.
        _passIndex++;

        if (_passIndex >= numberOfPasses)
        {
          // Finished: All effect passes have been applied.
          context.PassIndex = -1;
          pass = null;
          return false;
        }

        _actualPassCount = 0;
        _desiredPassCount = GetPassRepetitionCount(context, _passIndex);
      }

      pass = technique.Passes[_passIndex];

      // In the parameter index and context.PassIndex, we store the total number
      // of executed passes.
      context.PassIndex = index;
      index++;

      _actualPassCount++;

      if (index == numberOfPasses - 1 && string.Equals(pass.Name, "Restore", StringComparison.OrdinalIgnoreCase))
      {
        // A last effect pass may be used to restore the default render states without 
        // drawing anything. The effect pass needs to be called "Restore".
        pass.Apply();

        // Finished: All effect passes have been applied.
        context.PassIndex = -1;
        pass = null;
        return false;
      }

      return true;
    }
Ejemplo n.º 14
0
		public void Render(EffectWrapper pEffect, EffectPass pEffectPass)
		{
			if (m_bVisible)
			{
				pEffect.SetValue("FineBlockOrig", m_tFineBlockOrig);
				pEffect.SetValue("FineBlockOrig2", m_tFineBlockOrig2);
				pEffect.SetValue("ScaleFactor", m_tScaleFactor);
				pEffectPass.Apply();

				// render
				pEffect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip,
					0,                              // base vertex
					0,                              // min vertex index
					Settings.BLOCK_NUM_VERTICES,    // total num vertices - note that is NOT just vertices that are indexed, but all vertices
					0,                              // start index
					Settings.BLOCK_NUM_PRIMITIVES); // primitive count
			}
		}
Ejemplo n.º 15
0
 /// <summary>
 /// Applies the pass to the device. This sets up the rendering state before
 /// geometry rendering commences.
 /// </summary>
 public void Apply()
 {
     _pass.Apply();
 }