Example #1
0
        public ImageTileBuffer(GraphicsDevice graphicsDevice, Texture2D rendered, ISector sector)
        {
            buffer = new VertexIndiceBuffer();
            List <VertexPositionNormalTexture> vertices = new List <VertexPositionNormalTexture>();
            // TODO: are all of these names wrong everywhere? the topleft etc?
            Vector2d topLeft     = new Vector2d(0, 0);
            Vector2d topRight    = new Vector2d(1, 0);
            Vector2d bottomLeft  = new Vector2d(0, 1);
            Vector2d bottomRight = new Vector2d(1, 1);

            vertices.Add(new VertexPositionNormalTexture(new Vector3((float)topLeft.X, (float)topLeft.Y, 0), new Vector3(0, 0, 1), new Vector2(0, 0)));
            vertices.Add(new VertexPositionNormalTexture(new Vector3((float)topRight.X, (float)topRight.Y, 0), new Vector3(0, 0, 1), new Vector2(1, 0)));
            vertices.Add(new VertexPositionNormalTexture(new Vector3((float)bottomLeft.X, (float)bottomLeft.Y, 0), new Vector3(0, 0, 1), new Vector2(0, 1)));
            vertices.Add(new VertexPositionNormalTexture(new Vector3((float)bottomRight.X, (float)bottomRight.Y, 0), new Vector3(0, 0, 1), new Vector2(1, 1)));
            List <int> indices = new List <int>()
            {
                0, 1, 3, 0, 3, 2
            };

            buffer.vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Count, BufferUsage.WriteOnly);
            buffer.vertices.SetData(vertices.ToArray());
            buffer.indices = new IndexBuffer(graphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Count, BufferUsage.WriteOnly);
            buffer.indices.SetData(indices.ToArray());
            buffer.texture = rendered;
        }
Example #2
0
        public override void Draw(RenderContext renderContext, GameTime gameTime)
        {
            if (renderContext.layerPass == RenderContext.LayerPass.MAIN_PASS && !Game1.DEFERRED_RENDERING)
            {
                var effect = this.GetDefaultEffect(renderContext.graphicsDevice);

                camera.ApplyMatrices(effect);
                float distance = (float)(9 * Math.Pow(0.5, camera.cameraZoom)); // TODO: this is hacky
                effect.View = CameraMatrixManager.GetWorldRelativeView(distance);

                effect.TextureEnabled = true;
                foreach (var rootSector in ZCoords.GetSectorManager().GetTopmostOSMSectors())
                {
                    SectorBounds       bounds = GetSectorBounds(renderContext.graphicsDevice, rootSector);
                    VertexIndiceBuffer sphere = SphereBuilder.MakeSphereSegExplicit(renderContext.graphicsDevice, rootSector, 2, bounds.minX, bounds.minY, bounds.maxX, bounds.maxY, camera);
                    effect.Texture = renderTargets[rootSector];
                    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        renderContext.graphicsDevice.Indices = sphere.indices;
                        renderContext.graphicsDevice.SetVertexBuffer(sphere.vertices);
                        renderContext.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, sphere.indices.IndexCount / 3);
                    }
                    sphere.vertices.Dispose();
                    sphere.indices.Dispose();
                }
            }
            if (renderContext.layerPass == RenderContext.LayerPass.MAIN_PASS && Game1.DEFERRED_RENDERING)
            {
                var    effect   = GlobalContent.DeferredBasicNormalTextureShader;
                float  distance = (float)(9 * Math.Pow(0.5, camera.cameraZoom)); // TODO: this is hacky
                Matrix view     = CameraMatrixManager.GetWorldRelativeView(distance);
                effect.Parameters["WVP"].SetValue(camera.world * view * camera.projection);
                foreach (var rootSector in ZCoords.GetSectorManager().GetTopmostOSMSectors())
                {
                    SectorBounds       bounds = GetSectorBounds(renderContext.graphicsDevice, rootSector);
                    VertexIndiceBuffer sphere = SphereBuilder.MakeSphereSegExplicit(renderContext.graphicsDevice, rootSector, 2, bounds.minX, bounds.minY, bounds.maxX, bounds.maxY, camera);
                    effect.Parameters["Texture"].SetValue(renderTargets[rootSector]);
                    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        renderContext.graphicsDevice.Indices = sphere.indices;
                        renderContext.graphicsDevice.SetVertexBuffer(sphere.vertices);
                        renderContext.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, sphere.indices.IndexCount / 3);
                    }
                    sphere.vertices.Dispose();
                    sphere.indices.Dispose();
                }
            }
            foreach (var rootSector in ZCoords.GetSectorManager().GetTopmostOSMSectors())
            {
                Draw3D(renderContext.graphicsDevice, allBounds[rootSector], rootSector, renderContext.layerPass);
            }
        }
Example #3
0
 public TreeGeometryBuffer(GraphicsDevice graphicsDevice)
 {
     // make that square, sure
     if (buffer == null)
     {
         buffer = new VertexIndiceBuffer();
         List <VertexPositionTexture> vertices = new List <VertexPositionTexture>();
         List <int> indices = new List <int>();
         // TODO: are all of these names wrong everywhere? the topleft etc?
         int    size = 256;
         Random rand = new Random();
         for (int i = 0; i < size * size; i++)
         {
             int     x           = i % size;
             int     y           = i / size;
             Vector3 randVec     = new Vector3((float)rand.NextDouble() / 2 - 0.25f, (float)rand.NextDouble() / 2 - 0.25f, 0) / size;
             Vector3 topLeft     = new Vector3((x + 0.5f) / size, (y + 0.5f) / size, 0) + randVec;
             Vector3 topRight    = new Vector3((x + 0.5f) / size, (y + 0.5f) / size, 0) + randVec;
             Vector3 bottomLeft  = new Vector3((x + 0.5f) / size, (y + 0.5f) / size, 0) + randVec;
             Vector3 bottomRight = new Vector3((x + 0.5f) / size, (y + 0.5f) / size, 0) + randVec;
             vertices.Add(new VertexPositionTexture(topLeft, new Vector2(0, 0)));
             vertices.Add(new VertexPositionTexture(topRight, new Vector2(1, 0)));
             vertices.Add(new VertexPositionTexture(bottomLeft, new Vector2(0, 1)));
             vertices.Add(new VertexPositionTexture(bottomRight, new Vector2(1, 1)));
             indices.Add(i * 4);
             indices.Add(i * 4 + 1);
             indices.Add(i * 4 + 3);
             indices.Add(i * 4);
             indices.Add(i * 4 + 3);
             indices.Add(i * 4 + 2);
         }
         if (graphicsDevice != null)
         {
             buffer.vertices = new VertexBuffer(graphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Count, BufferUsage.WriteOnly);
             buffer.vertices.SetData(vertices.OrderBy(x => x.Position.Y).ToArray());
             buffer.indices = new IndexBuffer(graphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Count, BufferUsage.WriteOnly);
             buffer.indices.SetData(indices.ToArray());
         }
     }
 }