Inheritance: GraphicsResource
Exemplo n.º 1
0
 /// <summary>
 /// Constructor of VertexBufferObject class
 /// </summary>
 /// <param name="device">Graphics device</param>
 /// <param name="type">Type of buffer to use</param>
 /// <param name="buffer">Underlying vertex buffer</param>
 internal VertexBufferObject(GraphicsDevice device, BufferType type, VertexBuffer buffer)
 {
     _device = device;
     _bufferType = type;
     _vertexDeclaration = buffer.VertexDeclaration;
     CreateWrapper(buffer);
 }
        public void LoadContent()
        {
            generateTerrainEffect = game.Content.Load<Effect>(@"effects\GenerateSphereNode");

              // texture declaration
              vertexPositionTexture = VertexPositionTexture.VertexDeclaration; //  new VertexDeclaration(device, VertexPositionTexture.VertexElements);
        }
 static VertexPositionNormalTexture()
 {
     VertexDeclaration = new VertexDeclaration(
         new VertexElement[]
         {
             new VertexElement(
                 0,
                 VertexElementFormat.Vector3,
                 VertexElementUsage.Position,
                 0
             ),
             new VertexElement(
                 12,
                 VertexElementFormat.Vector3,
                 VertexElementUsage.Normal,
                 0
             ),
             new VertexElement(
                 24,
                 VertexElementFormat.Vector2,
                 VertexElementUsage.TextureCoordinate,
                 0
             )
         }
     );
 }
Exemplo n.º 4
0
        public void loadContent(ContentManager contentManager, GraphicsDeviceManager graphicsManager, ModelGeometry collisionGeometry)
        {
            mGraphicsDevice = graphicsManager.GraphicsDevice;

            mInstanceVertexDeclaration = new VertexDeclaration(new[]
            {
                new VertexElement(0, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, 2),
                new VertexElement(16, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, 3),
                new VertexElement(32, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, 4),
                new VertexElement(48, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, 5)
            });

            mCollidingFacesVertexDeclaration = new VertexDeclaration(new[]
            {
                // ideally we'd use Byte4 for Color0 but it's so much easier to fill vertex buffers with Vector3. There's only very little data anyway
                new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0 ),
                new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0 ),
                new VertexElement(24, VertexElementFormat.Vector3, VertexElementUsage.Color, 0 )
            });

            mCollidingFacesVertices = new VertexBuffer(mGraphicsDevice, mCollidingFacesVertexDeclaration, collisionGeometry.faces.Length * 3, BufferUsage.WriteOnly);

            // load collisions shader and configure material properties
            mCollisionsShader = contentManager.Load<Effect>("Effects/CollisionsShader");
            mCollisionsShader.Parameters["MaterialColor"].SetValue(new Vector3(0.39f, 0.8f, 1f));

            mAlphaBlendState = new BlendState();
            mAlphaBlendState.ColorSourceBlend = Blend.SourceAlpha;
            mAlphaBlendState.AlphaSourceBlend = Blend.SourceAlpha;
            mAlphaBlendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
            mAlphaBlendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
        }
    public void LoadContent()
    {
#if gradient
      generateTextureEffect = game.Content.Load<Effect>(@"effects\GenerateTerrainTextureGradient");
      gradientTexture = game.Content.Load<Texture2D>(@"textures\gradient_01");

      generateTextureEffect.Parameters["gradient"].SetValue(gradientTexture);

#else
      string[] textureNames = { 
                                "dirt_01", "dirt_03",
                                "sand_02", "sand_03",
                                "grass_01", "grass_02", "grass_03",
                                "water_01", "stone_02", "stone_03",
                                "snow_01", "snow_03"
                              };

      generateTextureEffect = game.Content.Load<Effect>(@"effects\GenerateTerrainTexturePack");
      slopemapTexture = game.Content.Load<Texture2D>(@"textures\slopemap");

      // load diffuse textures
      textures = new Texture2D[textureNames.Length];
      for (int i = 0; i < textures.Length; i++)
        textures[i] = game.Content.Load<Texture2D>(@"textures\" + textureNames[i]);


#endif

      // texture declaration
      vertexPositionTexture = VertexPositionTexture.VertexDeclaration; // new VertexDeclaration(device, VertexPositionTexture.VertexElements);
    }
Exemplo n.º 6
0
        public InstancedModelDrawer(Game game)
            : base(game)
        {
            instancingEffect = game.Content.Load<Effect>("InstancedEffect");

            worldTransformsParameter = instancingEffect.Parameters["WorldTransforms"];
            textureIndicesParameter = instancingEffect.Parameters["TextureIndices"];
            viewParameter = instancingEffect.Parameters["View"];
            projectionParameter = instancingEffect.Parameters["Projection"];

            instancingEffect.Parameters["LightDirection1"].SetValue(Vector3.Normalize(new Vector3(.8f, -1.5f, -1.2f)));
            instancingEffect.Parameters["DiffuseColor1"].SetValue(new Vector3(.66f, .66f, .66f));
            instancingEffect.Parameters["LightDirection2"].SetValue(Vector3.Normalize(new Vector3(-.8f, 1.5f, 1.2f)));
            instancingEffect.Parameters["DiffuseColor2"].SetValue(new Vector3(.3f, .3f, .5f));
            instancingEffect.Parameters["AmbientAmount"].SetValue(.5f);

            instancingEffect.Parameters["Texture0"].SetValue(textures[0]);
            instancingEffect.Parameters["Texture1"].SetValue(textures[1]);
            instancingEffect.Parameters["Texture2"].SetValue(textures[2]);
            instancingEffect.Parameters["Texture3"].SetValue(textures[3]);
            instancingEffect.Parameters["Texture4"].SetValue(textures[4]);
            instancingEffect.Parameters["Texture5"].SetValue(textures[5]);
            instancingEffect.Parameters["Texture6"].SetValue(textures[6]);
            instancingEffect.Parameters["Texture7"].SetValue(textures[7]);

            //This vertex declaration could be compressed or made more efficient, but such optimizations weren't critical.
            instancingVertexDeclaration = new VertexDeclaration(new[] {new VertexElement(0, VertexElementFormat.Single, VertexElementUsage.TextureCoordinate, 1)});
        }
Exemplo n.º 7
0
        private void CreateVertexBuffer()
        {
            vertexDeclaration = new VertexDeclaration(new VertexElement[1]
                {
                    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0)
                }
            );

            vertexBuffer = new VertexBuffer(
                GraphicsDevice,
                vertexDeclaration,
                number_of_vertices,
                BufferUsage.None
                );

            Vector3[] vertices = new Vector3[number_of_vertices];
            vertices[0] = new Vector3(-1, 0, 0); // cw
            vertices[1] = new Vector3(0, 1, 0);
            vertices[2] = new Vector3(0, 0, 0);
            vertices[3] = new Vector3(0, 0, 0); // ccw
            vertices[4] = new Vector3(1, 0, 0);
            vertices[5] = new Vector3(0, 1, 0);

            vertexBuffer.SetData(vertices);

        }
Exemplo n.º 8
0
        public void Resolve(bool injectHardEdges)
        {
            _vertices = new List<VertexPositionNormalTexture>();
            //ushort indIdx = 0;

            List<UInt16> indices = new List<UInt16>(_vertexPositions.Count);

            foreach (CModel model in _models)
            {
                model.HardEdgesInserted = injectHardEdges;
                model.IndexBufferStart = indices.Count;
                model.Polygons.Sort(delegate(Polygon p1, Polygon p2) { return p1.MaterialIndex.CompareTo(p2.MaterialIndex); });

                model.Resolve(indices, _vertices, _vertexTextureMap, _vertexPositions);
            }

            if (_vertices.Count > 0)
            {
                _vertexBuffer = new VertexBuffer(Engine.Device, VertexPositionNormalTexture.SizeInBytes * _vertices.Count, BufferUsage.WriteOnly);
                _vertexBuffer.SetData<VertexPositionNormalTexture>(_vertices.ToArray());

                if (!injectHardEdges)
                {
                    _indexBuffer = new IndexBuffer(Engine.Device, typeof(UInt16), indices.Count, BufferUsage.WriteOnly);
                    _indexBuffer.SetData<UInt16>(indices.ToArray());
                    _indices = indices;
                }
            }

            _vertexDeclaration = new VertexDeclaration(Engine.Device, VertexPositionNormalTexture.VertexElements);
            _vertexTextureMap = null; //dont need this data anymore
        }
		public override void LoadContent()
		{
			vertexDecl = VertexPositionTexture.VertexDeclaration;

			verts = new VertexPositionTexture[]
            {
                new VertexPositionTexture(
                    new Vector3(0,0,1),
                    new Vector2(1,1)),
                new VertexPositionTexture(
                    new Vector3(0,0,1),
                    new Vector2(0,1)),
                new VertexPositionTexture(
                    new Vector3(0,0,1),
                    new Vector2(0,0)),
                new VertexPositionTexture(
                    new Vector3(0,0,1),
                    new Vector2(1,0))
            };

			ib = new short[] { 0, 1, 2, 2, 3, 0 }; // 0 -- 1
												   // |    |
												   // 2 -- 3

			base.LoadContent();
		}
Exemplo n.º 10
0
        public LineBatch(GraphicsDevice graphicsDevice)
        {
            // assign the graphics device parameter after safety-checking
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }
            this.graphicsDevice = graphicsDevice;

            // create and configure the effect
            this.effect = new BasicEffect(graphicsDevice);
            this.effect.VertexColorEnabled = true;
            this.effect.TextureEnabled = false;
            this.effect.LightingEnabled = false;
            // configure the effect
            this.effect.World = Matrix.Identity;
            this.effect.View = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward,
                Vector3.Up);
            
            // create the vertex declaration
            //this.vertexDeclaration = new VertexDeclaration(graphicsDevice,
            //    VertexPositionColor.VertexElements);
            this.vertexDeclaration = new VertexDeclaration(new VertexElement());

            // create the vertex array
            this.vertices = new VertexPositionColor[maxVertexCount];
        }
Exemplo n.º 11
0
        WheelMenu wheel; // the parent wheel

        #endregion Fields

        #region Constructors

        public WheelMenuEntry( WheelMenu wheel, Texture2D texture )
        {
            this.wheel = wheel;
              this.texture = texture;

              segments = 10;

              extendedSpring = new SpringInterpolater( 1, 800, SpringInterpolater.GetCriticalDamping( 800 ) );
              extendedSpring.SetSource( 0 );
              extendedSpring.SetDest( 0 );
              extendedSpring.Active = true;

              growSpring = new SpringInterpolater( 1, 700, .25f * SpringInterpolater.GetCriticalDamping( 700 ) );
              growSpring.SetSource( 0 );
              growSpring.SetDest( 0 );
              growSpring.Active = true;

              float height = WheelMenu.EntryIdleSize;
              float width = height * (float)texture.Width / (float)texture.Height;
              GenerateVerts( width, height, segments, out idleVerts );
              GenerateVerts( width * WheelMenu.EntryActiveScale, height * WheelMenu.EntryActiveScale, segments, out activeVerts );

              vertexBuffer = new VertexPositionNormalTexture[( segments + 1 ) * 2];
              vertexDeclaration = new VertexDeclaration( wheel.Screen.ScreenManager.GraphicsDevice,
                                                 VertexPositionNormalTexture.VertexElements );
        }
Exemplo n.º 12
0
		private void SetupVertices() {
			vertices = new VertexPositionColor[size.X * size.Y + 2];
			vertexDeclaration = new VertexDeclaration(vertices);
			vertexBuffer = new VertexBuffer(CamTest.graphics.GraphicsDevice, typeof(VertexPositionColor), vertices.Length, BufferUsage.None);

			int vertID = 0;

			for (int x = 0; x < size.X + 1; x++) {
				vertices[vertID].Position = new Vector3(x * cellSize.X, 0f, 0f);
				vertices[vertID].Color = color;
				vertices[vertID + 1].Position = new Vector3(x * cellSize.X, 0f, size.Y * cellSize.Y);
				vertices[vertID + 1].Color = color;
				vertID += 2;
			}

			for (int y = 0; y < size.Y + 1; y++) {
				vertices[vertID].Position = new Vector3(0f, 0f, y * cellSize.Y);
				vertices[vertID].Color = color;
				vertices[vertID + 1].Position = new Vector3(size.X * cellSize.X, 0f, y * cellSize.Y);
				vertices[vertID + 1].Color = color;
				vertID += 2;
			}

			vertexBuffer.SetData<VertexPositionColor>(vertices);
		}
Exemplo n.º 13
0
        public virtual void Flush()
        {
            if (this.vertexCount > 0)
            {
                if (this.declaration == null || this.declaration.IsDisposed)
                    this.declaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements);

                device.VertexDeclaration = this.declaration;

                Effect effect = this.Effect;
                //  set the only parameter this effect takes.
                effect.Parameters["viewProjection"].SetValue(this.View * this.Projection);

                EffectTechnique technique = effect.CurrentTechnique;
                effect.Begin();
                EffectPassCollection passes = technique.Passes;
                for (int i = 0; i < passes.Count; i++)
                {
                    EffectPass pass = passes[i];
                    pass.Begin();

                    device.DrawUserIndexedPrimitives<VertexPositionTexture>(
                        PrimitiveType.TriangleList, this.vertices, 0, this.vertexCount,
                        this.indices, 0, this.indexCount / 3);

                    pass.End();
                }
                effect.End();

                this.vertexCount = 0;
                this.indexCount = 0;
            }
        }
Exemplo n.º 14
0
        public Quad( Vector3[] verts, Vector3 position, Texture2D texture )
        {
            if ( verts.Length != 4 )
            throw new InvalidOperationException( "Quad must have four vertices." );
              localPositions = verts;
              vertices = new VertexPositionTexture[4];
              Array.Copy( verts, localPositions, 4 );
              vertices[0].TextureCoordinate = new Vector2( 0, 0 );
              vertices[1].TextureCoordinate = new Vector2( 1, 0 );
              vertices[2].TextureCoordinate = new Vector2( 1, 1 );
              vertices[3].TextureCoordinate = new Vector2( 0, 1 );

              Position = position;
              Scale = 1f;

              device = ZombieCraft.Instance.GraphicsDevice;
              vertexDeclaraion = new VertexDeclaration( device, VertexPositionTexture.VertexElements );
              effect = ZombieCraft.Instance.Content.Load<Effect>( "Effects/Primitive" ).Clone( device );
              effect.CurrentTechnique = effect.Techniques["Texture"];
              viewParam = effect.Parameters["View"];
              projectionParam = effect.Parameters["Projection"];
              textureParam = effect.Parameters["Texture"];
              colorParam = effect.Parameters["Color"];

              Texture = texture;
        }
Exemplo n.º 15
0
        public void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            if (_dEffect == null)
                _dEffect = content.Load<Effect>("Content/Effects/Series4Effects");

            _texture1 = content.Load<Texture2D>("Content/Textures/Ground/sand");
            _texture2 = content.Load<Texture2D>("Content/Textures/Ground/grass");
            _texture3 = content.Load<Texture2D>("Content/Textures/Ground/rock");
            _texture4 = content.Load<Texture2D>("Content/Textures/Ground/snow");

            _skyDome = content.Load<Model>("Content/Models/dome");
            _skyDome.Meshes[0].MeshParts[0].Effect = _dEffect.Clone();

            _cloudMap = content.Load<Texture2D>("Content/Models/cloudMap");

            //PresentationParameters pp = _dDevice.PresentationParameters;
            //refractionRenderTarget = new RenderTarget2D(_dDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat);
            //reflectionRenderTarget = new RenderTarget2D(_dDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat);

            SetUpWaterVertices();

            waterBumpMap = content.Load<Texture2D>("Content/Textures/Ground/water");

            VertexPositionTexture[] fullScreenVertices = SetUpFullscreenVertices();
            //fullScreenVertexDeclaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements);

            VertexDeclaration vertexDeclaration = new VertexDeclaration(VertexMultitextured.VertexElements);
            fullScreenBuffer = new VertexBuffer(_dDevice, vertexDeclaration, fullScreenVertices.Length, BufferUsage.WriteOnly);
            fullScreenBuffer.SetData(fullScreenVertices);

            fullScreenVertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements());
        }
Exemplo n.º 16
0
 static VertexPositionVectorColorTexture()
 {
     VertexElement[] elements = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color, 0), new VertexElement(28, VertexElementFormat.HalfVector2, VertexElementUsage.TextureCoordinate, 0) };
     VertexDeclaration declaration = new VertexDeclaration(elements);
     declaration.Name = "VertexPositionVectorColorTexture.VertexDeclaration";
     VertexDeclaration = declaration;
 }
Exemplo n.º 17
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            texture = Content.Load<Texture2D>("Glass");
            quadEffect = new BasicEffect(graphics.GraphicsDevice);
			// We still do not have lighting implemented in the shaders
            //quadEffect.EnableDefaultLighting();

            quadEffect.World = Matrix.Identity;
            quadEffect.View = View;
            quadEffect.Projection = Projection;
            quadEffect.TextureEnabled = true;
            quadEffect.Texture = texture;

            vertexDeclaration = new VertexDeclaration(new VertexElement[]
                {
                    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                    new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                    new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
                }
            );


        }
Exemplo n.º 18
0
        protected override void LoadContent()
        {
            IGraphicsDeviceService graphicsService =
                    (IGraphicsDeviceService)base.Game.Services.GetService(
                                                typeof(IGraphicsDeviceService));

                vertexDecl = VertexPositionColor.VertexDeclaration;

                verts = new VertexPositionTexture[]
                        {
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(1,1)),
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(0,1)),
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(0,0)),
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(1,0))
                        };

                ib = new short[] { 0, 1, 2, 2, 3, 0 };
        }
 public static void Add(Type vertexType,VertexDeclaration dec)
 {
     if(!_declarations.Keys.Contains(vertexType))
     {
         _declarations.Add(vertexType, dec);
     }
 }
Exemplo n.º 20
0
        public static void RenderVertexPositionColorList(GraphicsDevice gd, 
            BasicEffect effect, Matrix world, Matrix view, Matrix proj,
            VertexPositionColor[] vertices, VertexDeclaration vertexDeclaration,
            VertexBuffer vertex_buffer)
        {
            // gd.VertexDeclaration = vertexDeclaration;

              effect.World = world;
              effect.View = view;
              effect.Projection = proj;
              effect.VertexColorEnabled = true;

              if (vertex_buffer == null)
              {
            vertex_buffer = new VertexBuffer(gd, typeof(VertexPositionColor), vertices.Length, BufferUsage.WriteOnly);
            vertex_buffer.SetData<VertexPositionColor>(vertices);
              }

              foreach (EffectPass pass in effect.CurrentTechnique.Passes)
              {
              pass.Apply();
            gd.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, vertices.Length / 3);

              }
        }
Exemplo n.º 21
0
        public SkyBox(ContentReader input)
        {
            // Graphics Device-Instanz abrufen
              this.GraphicsDevice = ((IGraphicsDeviceService)input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService))).GraphicsDevice;

              // Vertices einlesen und Vertex Buffer initialisieren
              VertexPositionTexture[] vertices = input.ReadObject<VertexPositionTexture[]>();
              this.vertexBuffer = new VertexBuffer(this.GraphicsDevice, typeof(VertexPositionTexture), vertices.Length, BufferUsage.None);
              this.vertexBuffer.SetData<VertexPositionTexture>(vertices);

              // Anzahl der Vertices speichern
              this.numVertices = vertices.Length;

              // Division durch 3 ergibt die Anzahl der Primitive, da eine Dreiecksliste verwendet wird
              this.numPrimitives = this.numPrimitives / 3;

              // Vertex-Beschreibung erzeugen
              this.vertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements());

              // BasicEffect-Instanz erzeugen
              this.effect = new BasicEffect(this.GraphicsDevice);

              // Texturen einlesen
              this.frontTexture = input.ReadExternalReference<Texture2D>();
              this.backTexture = input.ReadExternalReference<Texture2D>();
              this.leftTexture = input.ReadExternalReference<Texture2D>();
              this.rightTexture = input.ReadExternalReference<Texture2D>();
              this.topTexture = input.ReadExternalReference<Texture2D>();
              this.bottomTexture = input.ReadExternalReference<Texture2D>();
        }
Exemplo n.º 22
0
        public InstancedModelDrawer(Game game)
            : base(game)
        {
#if WINDOWS
            var resourceContentManager = new ResourceContentManager(game.Services, Indiefreaks.Xna.BEPU.Resources.WindowsPhysicsResources.ResourceManager);
#elif XBOX360
            var resourceContentManager = new ResourceContentManager(game.Services, Indiefreaks.Xna.BEPU.Resources.Xbox360PhysicsResources.ResourceManager);
#else
            ResourceContentManager resourceContentManager = null;
#endif
            instancingEffect = resourceContentManager.Load<Effect>("InstancedEffect");

            worldTransformsParameter = instancingEffect.Parameters["WorldTransforms"];
            textureIndicesParameter = instancingEffect.Parameters["TextureIndices"];
            viewParameter = instancingEffect.Parameters["View"];
            projectionParameter = instancingEffect.Parameters["Projection"];

            instancingEffect.Parameters["LightDirection1"].SetValue(Vector3.Normalize(new Vector3(.8f, -1.5f, -1.2f)));
            instancingEffect.Parameters["DiffuseColor1"].SetValue(new Vector3(.66f, .66f, .66f));
            instancingEffect.Parameters["LightDirection2"].SetValue(Vector3.Normalize(new Vector3(-.8f, 1.5f, 1.2f)));
            instancingEffect.Parameters["DiffuseColor2"].SetValue(new Vector3(.3f, .3f, .5f));
            instancingEffect.Parameters["AmbientAmount"].SetValue(.5f);

            instancingEffect.Parameters["Texture0"].SetValue(textures[0]);
            instancingEffect.Parameters["Texture1"].SetValue(textures[1]);
            instancingEffect.Parameters["Texture2"].SetValue(textures[2]);
            instancingEffect.Parameters["Texture3"].SetValue(textures[3]);
            instancingEffect.Parameters["Texture4"].SetValue(textures[4]);
            instancingEffect.Parameters["Texture5"].SetValue(textures[5]);
            instancingEffect.Parameters["Texture6"].SetValue(textures[6]);
            instancingEffect.Parameters["Texture7"].SetValue(textures[7]);

            //This vertex declaration could be compressed or made more efficient, but such optimizations weren't critical.
            instancingVertexDeclaration = new VertexDeclaration(new[] {new VertexElement(0, VertexElementFormat.Single, VertexElementUsage.TextureCoordinate, 1)});
        }
        // Constructor
        public QuadRenderComponent(Game game)
            : base(game)
        {
            IGraphicsDeviceService graphicsService =
                    (IGraphicsDeviceService)base.Game.Services.GetService(
                                                typeof(IGraphicsDeviceService));

            vertexDecl = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements());

            verts = new VertexPositionTexture[]
                        {
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(1,1)),
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(0,1)),
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(0,0)),
                            new VertexPositionTexture(
                                new Vector3(0,0,0),
                                new Vector2(1,0))
                        };

            ib = new short[] { 0, 1, 2, 2, 3, 0 };
        }
Exemplo n.º 24
0
        public Room(Game game)
        {
            this.Skin.DefaultMaterial = new Material(1f, 0.5f);
            this.Skin.Add(
                new PlanePart(new Vector3(0, 0, 1), -Vector3.UnitZ),
                new PlanePart(new Vector3(0, 0, 0), Vector3.UnitZ),
                new PlanePart(new Vector3(0, 1, 0), -Vector3.UnitY),
                new PlanePart(new Vector3(0, -1, 0), Vector3.UnitY),
                new PlanePart(new Vector3(1, 0, 0), -Vector3.UnitX),
                new PlanePart(new Vector3(-1, 0, 0), Vector3.UnitX)
                );
            this.SetWorld(_scale, Vector3.Zero, Quaternion.Identity);

            int ts = 32;
            Texture2D wallTexture = new Texture2D(game.GraphicsDevice, ts, ts);
            Color[] pixels = new Color[ts * ts];
            for (int i = 0; i < ts; i++)
            {
                pixels[i] = Color.Yellow;
                pixels[i * ts] = Color.Yellow;
                pixels[i * ts + (ts - 1)] = Color.Yellow;
                pixels[(ts - 1) * ts + i] = Color.Yellow;
            }
            wallTexture.SetData(pixels);

            _effect = new BasicEffect(game.GraphicsDevice);
            _vertexDeclaration = VertexPositionNormalTexture.VertexDeclaration;
            _effect.AmbientLightColor = Vector3.One;
            _effect.TextureEnabled = true;
            _effect.Texture = wallTexture;
        }
Exemplo n.º 25
0
 public void Unload()
 {
   dev_ = null;
   vb_ = null;
   vdecl_ = null;
   fx_ = null;
 }
Exemplo n.º 26
0
		static VertexPositionColorTexture()
		{
			VertexDeclaration = new VertexDeclaration(
				new VertexElement[]
				{
					new VertexElement(
						0,
						VertexElementFormat.Vector3,
						VertexElementUsage.Position,
						0
					),
					new VertexElement(
						12,
						VertexElementFormat.Color,
						VertexElementUsage.Color,
						0
					),
					new VertexElement(
						16,
						VertexElementFormat.Vector2,
						VertexElementUsage.TextureCoordinate,
						0
					)
				}
			);
		}
Exemplo n.º 27
0
        public SkyplaneEngine(InfiniminerGame gameInstance)
        {
            this.gameInstance = gameInstance;

            // Generate a noise texture.
            randGen = new Random();
            texNoise = new Texture2D(gameInstance.GraphicsDevice, 64, 64);
            uint[] noiseData = new uint[64*64];
            for (int i = 0; i < 64 * 64; i++)
                if (randGen.Next(32) == 0)
                    noiseData[i] = Color.White.PackedValue;
                else
                    noiseData[i] = Color.Black.PackedValue;
            texNoise.SetData(noiseData);

            // Load the effect file.
            effect = gameInstance.Content.Load<Effect>("effect_skyplane");

            // Create our vertices.
            vertexDeclaration = new VertexDeclaration(gameInstance.GraphicsDevice, VertexPositionTexture.VertexElements);
            vertices = new VertexPositionTexture[6];
            vertices[0] = new VertexPositionTexture(new Vector3(-210, 100, -210), new Vector2(0, 0));
            vertices[1] = new VertexPositionTexture(new Vector3(274, 100, -210), new Vector2(1, 0));
            vertices[2] = new VertexPositionTexture(new Vector3(274, 100, 274), new Vector2(1, 1));
            vertices[3] = new VertexPositionTexture(new Vector3(-210, 100, -210), new Vector2(0, 0));
            vertices[4] = new VertexPositionTexture(new Vector3(274, 100, 274), new Vector2(1, 1));
            vertices[5] = new VertexPositionTexture(new Vector3(-210, 100, 274), new Vector2(0, 1));
        }
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            int iWidth = graphics.Viewport.Width;
            int iHeight = graphics.Viewport.Height;

            for (int i = 0; i < DefaultBufferSize; i++)
            {
                vertices[i] = new VertexPositionColor();
                vertices[i].Position.X = rand.Next(iWidth);
                vertices[i].Position.Y = rand.Next(iHeight);
                vertices[i].Color = Color.White; //new Color(128, 128, 128);
            }
            graphics.RenderState.PointSize = 1;

            // create a vertex declaration, which tells the graphics card what kind of
            // data to expect during a draw call. We're drawing using
            // VertexPositionColors, so we'll use those vertex elements.
            vertexDeclaration = new VertexDeclaration(graphics,
                VertexPositionColor.VertexElements);

            // set up a new basic effect, and enable vertex colors.
            basicEffect = new BasicEffect(graphics, null);
            basicEffect.VertexColorEnabled = true;

            // projection uses CreateOrthographicOffCenter to create 2d projection
            // matrix with 0,0 in the upper left.
            basicEffect.Projection = Matrix.CreateOrthographicOffCenter
                (0, iWidth,
                iHeight, 0,
                0, 1);

            base.Initialize();
        }
Exemplo n.º 29
0
        public override void Create()
        {
            buffer = Plane(xCount, yCount);

            //Load the correct shader and set up the parameters
            IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)GameInstance.Services.GetService(typeof(IGraphicsDeviceService));

            effect = SpacewarGame.ContentManager.Load<Effect>(SpacewarGame.Settings.MediaPath + @"shaders\sun");

            worldParam = effect.Parameters["world"];
            worldViewProjectionParam = effect.Parameters["worldViewProjection"];
            sun0TextureParam = effect.Parameters["Sun_Tex0"];
            sun1TextureParam = effect.Parameters["Sun_Tex1"];
            blendFactor = effect.Parameters["blendFactor"];

            //Preload the textures into the cache
            int numFrames = 5;
            sun = new Texture2D[numFrames];

            sun[0] = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\suntest1");
            sun[1] = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\suntest2");
            sun[2] = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\suntest3");
            sun[3] = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\suntest4");
            sun[4] = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\suntest5");

            vertexDecl = new VertexDeclaration(graphicsService.GraphicsDevice, VertexPositionColor.VertexElements);
        }
        public void drawMe(GraphicsDevice device, Effect effect)
        {
            if (mDecl == null)
            {
                mDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements);
            }

            // update vert buffer.
            for (int i = 0; i < mPointMasses.Count; i++)
            {
                mVerts[i].Position = JelloPhysics.VectorTools.vec3FromVec2(mPointMasses[i].Position);

                float dist = (mPointMasses[i].Position - mGlobalShape[i]).Length() * 2.0f;
                if (dist > 1f) { dist = 1f; }

                mVerts[i].Color = mColor;
            }

            device.VertexDeclaration = mDecl;

            // draw me!
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, mVerts, 0, mVerts.Length, mIndices, 0, mIndices.Length / 3);
                pass.End();
            }
            effect.End();
        }
        /// <summary>
        /// Creates a new instance of <see cref="XNAVertexBufferImplementation"/>.
        /// </summary>
        /// <param name="renderer">The XNA renderer.</param>
        /// <param name="decl">The vertex declaration.</param>
        /// <param name="vertexCount">The vertex count.</param>
        /// <param name="usage">The resource usage.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if there was an error creating the XNA buffer</exception>
        internal XNAVertexBufferImplementation(XNARenderer renderer, VertexDeclaration decl, int vertexCount, ResourceUsage usage)
            : base(decl, vertexCount, usage)
        {
            _renderer       = renderer;
            _graphicsDevice = renderer.GraphicsDevice;

            try {
                XFG.VertexDeclaration xnaDecl = XNAHelper.ToXNAVertexDeclaration(decl);
                if (usage == ResourceUsage.Static)
                {
                    _vertexBuffer = new XFG.VertexBuffer(_graphicsDevice, xnaDecl, vertexCount, XFG.BufferUsage.None);
                }
                else
                {
                    _vertexBuffer = new XFG.DynamicVertexBuffer(_graphicsDevice, xnaDecl, vertexCount, XFG.BufferUsage.None);
                }
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating XNA buffer: \n" + e.Message, e);
            }
        }
Exemplo n.º 32
0
 public DynamicVertexBuffer(GraphicsDevice graphicsDevice, Type type, int vertexCount, BufferUsage bufferUsage)
     : base(graphicsDevice, VertexDeclaration.FromType(type), vertexCount, bufferUsage, true)
 {
 }
Exemplo n.º 33
0
 public DynamicVertexBuffer(GraphicsDevice graphics, VertexDeclaration vertexDecs, int vertexCount, BufferUsage bufferUsage)
     : base(graphics, vertexDecs.GetType(), vertexCount, bufferUsage)
 {
 }
Exemplo n.º 34
0
        public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
        {
            // These parameter checks are a duplicate of the checks in the short[] overload of DrawUserIndexedPrimitives.
            // Inlined here for efficiency.

            if (vertexData == null || vertexData.Length == 0)
            {
                throw new ArgumentNullException("vertexData");
            }

            if (vertexOffset < 0 || vertexOffset >= vertexData.Length)
            {
                throw new ArgumentOutOfRangeException("vertexOffset");
            }

            if (numVertices <= 0 || numVertices > vertexData.Length)
            {
                throw new ArgumentOutOfRangeException("numVertices");
            }

            if (vertexOffset + numVertices > vertexData.Length)
            {
                throw new ArgumentOutOfRangeException("numVertices");
            }

            if (indexData == null || indexData.Length == 0)
            {
                throw new ArgumentNullException("indexData");
            }

            if (indexOffset < 0 || indexOffset >= indexData.Length)
            {
                throw new ArgumentOutOfRangeException("indexOffset");
            }

            if (primitiveCount <= 0)
            {
                throw new ArgumentOutOfRangeException("primitiveCount");
            }

            if (indexOffset + GetElementCountArray(primitiveType, primitiveCount) > indexData.Length)
            {
                throw new ArgumentOutOfRangeException("primitiveCount");
            }

            if (vertexDeclaration == null)
            {
                throw new ArgumentNullException("vertexDeclaration");
            }

            PlatformDrawUserIndexedPrimitives <T>(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration);

            unchecked
            {
                _graphicsMetrics._drawCount++;
                _graphicsMetrics._primitiveCount += (ulong)primitiveCount;
            }
        }
Exemplo n.º 35
0
 public DynamicVertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage bufferUsage)
     : base(graphicsDevice, vertexDeclaration, vertexCount, bufferUsage, true)
 {
 }
Exemplo n.º 36
0
 public VertexDeclaration(params VertexElement[] elements)
     : this(VertexDeclaration.GetVertexStride(elements), elements)
 {
 }
Exemplo n.º 37
0
        public void DrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
        {
            if (vertexData == null)
            {
                throw new ArgumentNullException("vertexData");
            }

            if (vertexData.Length == 0)
            {
                throw new ArgumentOutOfRangeException("vertexData");
            }

            if (vertexOffset < 0 || vertexOffset >= vertexData.Length)
            {
                throw new ArgumentOutOfRangeException("vertexOffset");
            }

            if (primitiveCount <= 0)
            {
                throw new ArgumentOutOfRangeException("primitiveCount");
            }

            var vertexCount = GetElementCountArray(primitiveType, primitiveCount);

            if (vertexOffset + vertexCount > vertexData.Length)
            {
                throw new ArgumentOutOfRangeException("primitiveCount");
            }

            if (vertexDeclaration == null)
            {
                throw new ArgumentNullException("vertexDeclaration");
            }

            PlatformDrawUserPrimitives <T>(primitiveType, vertexData, vertexOffset, vertexDeclaration, vertexCount);

            unchecked
            {
                _graphicsMetrics._drawCount++;
                _graphicsMetrics._primitiveCount += (ulong)primitiveCount;
            }
        }
Exemplo n.º 38
0
        public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
        {
            Debug.Assert(vertexData != null && vertexData.Length > 0, "The vertexData must not be null or zero length!");
            Debug.Assert(indexData != null && indexData.Length > 0, "The indexData must not be null or zero length!");

            PlatformDrawUserIndexedPrimitives <T>(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration);
        }
Exemplo n.º 39
0
 public VertexBuffer(GraphicsDevice graphicsDevice, Type type, int vertexCount, BufferUsage bufferUsage) :
     this(graphicsDevice, VertexDeclaration.FromType(type), vertexCount, bufferUsage, false)
 {
 }
Exemplo n.º 40
0
 private void PlatformDrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
 {
 }
Exemplo n.º 41
0
 public VertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage bufferUsage) :
     this(graphicsDevice, vertexDeclaration, vertexCount, bufferUsage, false)
 {
 }
Exemplo n.º 42
0
        private void PlatformDrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, VertexDeclaration vertexDeclaration, int vertexCount) where T : struct
        {
            PlatformApplyState(true);

            // Unbind current VBOs.
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            _vertexBufferDirty = _indexBufferDirty = true;

            // Pin the buffers.
            var vbHandle = GCHandle.Alloc(vertexData, GCHandleType.Pinned);

            // Setup the vertex declaration to point at the VB data.
            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(_vertexShader, vbHandle.AddrOfPinnedObject());

            //Draw
            GL.DrawArrays(PrimitiveTypeGL(primitiveType),
                          vertexOffset,
                          vertexCount);
            GraphicsExtensions.CheckGLError();

            // Release the handles.
            vbHandle.Free();
        }
Exemplo n.º 43
0
        public void DrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
        {
            Debug.Assert(vertexData != null && vertexData.Length > 0, "The vertexData must not be null or zero length!");

            var vertexCount = GetElementCountArray(primitiveType, primitiveCount);

            PlatformDrawUserPrimitives <T>(primitiveType, vertexData, vertexOffset, vertexDeclaration, vertexCount);
        }
Exemplo n.º 44
0
 private void PlatformDrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
 {
     throw new NotImplementedException("Not implemented");
 }
Exemplo n.º 45
0
 private void PlatformDrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, VertexDeclaration vertexDeclaration, int vertexCount) where T : struct
 {
 }
Exemplo n.º 46
0
 private void PlatformDrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, VertexDeclaration vertexDeclaration, int vertexCount) where T : struct
 {
     throw new NotImplementedException("Not implemented");
 }
Exemplo n.º 47
0
        private void PlatformDrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
        {
            PlatformApplyState(true);

            // Unbind current VBOs.
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            _vertexBufferDirty = _indexBufferDirty = true;

            // Pin the buffers.
            var vbHandle = GCHandle.Alloc(vertexData, GCHandleType.Pinned);
            var ibHandle = GCHandle.Alloc(indexData, GCHandleType.Pinned);

            var vertexAddr = (IntPtr)(vbHandle.AddrOfPinnedObject().ToInt64() + vertexDeclaration.VertexStride * vertexOffset);

            // Setup the vertex declaration to point at the VB data.
            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(_vertexShader, vertexAddr);

            //Draw
            GL.DrawElements(PrimitiveTypeGL(primitiveType),
                            GetElementCountArray(primitiveType, primitiveCount),
                            DrawElementsType.UnsignedInt,
                            (IntPtr)(ibHandle.AddrOfPinnedObject().ToInt64() + (indexOffset * sizeof(int))));
            GraphicsExtensions.CheckGLError();

            // Release the handles.
            ibHandle.Free();
            vbHandle.Free();
        }