Ejemplo n.º 1
0
        public override void CleanUp(bool removeFromParent)
        {
            if (starVertexBuffer != null)
            {
                starVertexBuffer.Dispose();
                starVertexBuffer = null;
            }

            if (starProfile != null)
            {
                starProfile.Dispose();
                GC.SuppressFinalize(starProfile);
                starProfile = null;
            }
            TextureReady = false;
        }
Ejemplo n.º 2
0
        public void Dispose()
        {
            if (texture != null)
            {
                texture.Dispose();
                GC.SuppressFinalize(texture);
                texture = null;
            }

            if (labelBuffer != null)
            {
                labelBuffer.Dispose();
                GC.SuppressFinalize(labelBuffer);
                labelBuffer = null;
            }
        }
Ejemplo n.º 3
0
        void InitLabelBuffer()
        {
            if (labelBuffer == null)
            {
                int count = positions.Count;

                labelBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice);

                PositionColorSize[] labelPoints = (PositionColorSize[])labelBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)

                int index = 0;
                foreach (Vector3 point in positions)
                {
                    labelPoints[index].Position = new SharpDX.Vector3(point.X, point.Y, point.Z);
                    labelPoints[index].Color    = Color.White;
                    labelPoints[index].size     = 20f;
                    index++;
                }

                labelBuffer.Unlock();
            }
        }
Ejemplo n.º 4
0
        public override bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent)
        {
            InViewFrustum      = true;
            RenderedGeneration = CurrentRenderGeneration;
            if (!ReadyToRender)
            {
                TileCache.AddTileToQueue(this);
                return(false);
            }

            InViewFrustum = true;

            if (starVertexBuffer == null)
            {
                starProfile = Texture11.FromBitmap(Properties.Resources.StarProfile);

                int count = stars.Count;
                int index = 0;
                starCount = count;

                starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice);

                PositionColorSize[] points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)
                foreach (Star star in stars)
                {
                    Vector3d pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f);
                    points[index].Position = pos.Vector3;
                    points[index].Color    = star.Col;
                    double radDec = (.5) / Math.Pow(1.6, star.Magnitude);
                    points[index].size = (float)radDec;
                    index++;
                }
                starVertexBuffer.Unlock();
            }

            renderContext.SetVertexBuffer(starVertexBuffer);
            renderContext.BlendMode        = BlendMode.Additive;
            renderContext.DepthStencilMode = DepthStencilMode.Off;
            renderContext.setRasterizerState(TriangleCullMode.Off);
            SharpDX.Matrix mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mvp.Transpose();
            PointSpriteShader11.WVPMatrix = mvp;
            PointSpriteShader11.Color     = SharpDX.Color.White;

            float adjustedScale = (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360));

            PointSpriteShader11.ViewportScale     = new SharpDX.Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale);
            PointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10000.0f);
            PointSpriteShader11.Use(renderContext.Device.ImmediateContext);

            renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, starProfile.ResourceView);


            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
            renderContext.devContext.Draw(starCount, 0);

            renderContext.Device.ImmediateContext.GeometryShader.Set(null);

            // Reset blend mode so we don't mess up subsequent sky layer rendering
            renderContext.BlendMode = BlendMode.Alpha;

            return(true);
        }
Ejemplo n.º 5
0
        void InitLabelBuffer()
        {
            if (labelBuffer == null)
            {
                var count = positions.Count;

                labelBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice);

                var labelPoints = (PositionColorSize[])labelBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)

                var index = 0;
                foreach (var point in positions)
                {
                    labelPoints[index].Position = new Vector3(point.X, point.Y, point.Z);
                    labelPoints[index].Color = Color.White;
                    labelPoints[index].size = 20f;
                    index++;
                }

                labelBuffer.Unlock();

            }
        }
Ejemplo n.º 6
0
 void EmptyLabelBuffer()
 {
     //todo11
     if (labelBuffer != null)
     {
         labelBuffer.Dispose();
         GC.SuppressFinalize(labelBuffer);
         labelBuffer = null;
     }
 }
Ejemplo n.º 7
0
        public void Dispose()
        {
            if (texture != null)
            {
                texture.Dispose();
                GC.SuppressFinalize(texture);
                texture = null;
            }

            if (labelBuffer != null)
            {
                labelBuffer.Dispose();
                GC.SuppressFinalize(labelBuffer);
                labelBuffer = null;
            }
        }
Ejemplo n.º 8
0
        public override bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent)
        {
            InViewFrustum = true;
            RenderedGeneration = CurrentRenderGeneration;
            if (!ReadyToRender)
            {
                TileCache.AddTileToQueue(this);
                return false;
            }

            InViewFrustum = true;

            if (starVertexBuffer == null)
            {
                starProfile = Texture11.FromBitmap( Resources.StarProfile);

                var count = stars.Count;
                var index = 0;
                starCount = count;

                starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice);

                var points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)
                foreach (var star in stars)
                {
                    var pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f);
                    points[index].Position = pos.Vector3;
                    points[index].Color = star.Col;
                    var radDec = (.5) / Math.Pow(1.6, star.Magnitude);
                    points[index].size = (float)radDec;
                    index++;
                }
                starVertexBuffer.Unlock();
            }

            renderContext.SetVertexBuffer(starVertexBuffer);
            renderContext.BlendMode = BlendMode.Additive;
            renderContext.DepthStencilMode = DepthStencilMode.Off;
            renderContext.setRasterizerState(TriangleCullMode.Off);
            var mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mvp.Transpose();
            PointSpriteShader11.WVPMatrix = mvp;
            PointSpriteShader11.Color = Color.White;

            var adjustedScale = (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360));

            PointSpriteShader11.ViewportScale = new Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale);
            PointSpriteShader11.PointScaleFactors = new Vector3(0.0f, 0.0f, 10000.0f);
            PointSpriteShader11.Use(renderContext.Device.ImmediateContext);

            renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, starProfile.ResourceView);

            renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
            renderContext.devContext.Draw(starCount, 0);

            renderContext.Device.ImmediateContext.GeometryShader.Set(null);

            // Reset blend mode so we don't mess up subsequent sky layer rendering
            renderContext.BlendMode = BlendMode.Alpha;

            return true;
        }