Exemple #1
0
        public SkyLabel(RenderContext11 renderContext, Vector3d point, string text, LabelSytle style)
        {
            Text  = text;
            Style = style;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Properties.Resources.circle, 0);
            }


            pos = point;

            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(80);

            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                Text3d t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                // This will produce sky or orbit aligned text
                textBatch.Add(new Text3d(pos, new Vector3d(0, 1, 0), text, 20, .01));
            }
        }
        public static void Draw(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, SharpDX.Direct3D.PrimitiveTopology primitiveType, float opacity = 1.0f)
        {
            if (VertexBuffer == null)
            {
                VertexBuffer = new Buffer(renderContext.Device, System.Runtime.InteropServices.Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, System.Runtime.InteropServices.Marshal.SizeOf(points[0]));
                VertexBufferBinding = new VertexBufferBinding(VertexBuffer, System.Runtime.InteropServices.Marshal.SizeOf((points[0])), 0);

            }
            renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType;
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.setRasterizerState(TriangleCullMode.Off);
            SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(renderContext.devContext, texture != null, opacity);

            renderContext.SetVertexBuffer(VertexBufferBinding);

            DataBox box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
            Utilities.Write(box.DataPointer, points, 0, count);

            renderContext.devContext.UnmapSubresource(VertexBuffer, 0);
            if (texture != null)
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView);
            }
            else
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, null);
            }
            renderContext.devContext.Draw(count, 0);
        }
        public static void Draw2D(RenderContext11 renderContext, Texture11 srcTexture, SizeF size, PointF rotationCenter, float rotationAngle, PointF position, System.Drawing.Color color)
        {
            cornerPoints[0].Position = MakePosition(position.X, position.Y, -size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
            cornerPoints[0].Tu       = 0;
            cornerPoints[0].Tv       = 0;
            cornerPoints[0].Color    = color;


            cornerPoints[1].Position = MakePosition(position.X, position.Y, size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
            cornerPoints[1].Tu       = 1;
            cornerPoints[1].Tv       = 0;
            cornerPoints[1].Color    = color;


            cornerPoints[2].Position = MakePosition(position.X, position.Y, -size.Width / 2, size.Height / 2, rotationAngle).Vector4;
            cornerPoints[2].Tu       = 0;
            cornerPoints[2].Tv       = 1;
            cornerPoints[2].Color    = color;

            cornerPoints[3].Position = MakePosition(position.X, position.Y, size.Width / 2, size.Height / 2, rotationAngle).Vector4;
            cornerPoints[3].Tu       = 1;
            cornerPoints[3].Tv       = 1;
            cornerPoints[3].Color    = color;

            renderContext.setRasterizerState(TriangleCullMode.Off);
            renderContext.DepthStencilMode = DepthStencilMode.Off;
            DrawForScreen(renderContext, cornerPoints, 4, srcTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
        }
Exemple #4
0
        public Texture11 GetTexture(string date, string url)
        {
            if (!cache.ContainsKey(date))
            {
                Add(date, url);
            }

            WmsCahceEntry result = cache[date];

            if (result.Texture != null)
            {
                return(result.Texture);
            }

            Texture11 tempTexture = null;

            foreach (WmsCahceEntry entry in cache.Values)
            {
                if ((entry.Date.CompareTo(date) > 0 && tempTexture != null))
                {
                    return(tempTexture);
                }

                if (entry.Texture != null)
                {
                    tempTexture = entry.Texture;
                }
            }

            return(tempTexture);
        }
Exemple #5
0
        protected override void setupShader(RenderContext11 renderContext, Texture11 texture, float opacity)
        {
            SharpDX.Matrix mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mvp.Transpose();

            float aspectRatio = renderContext.ViewPort.Width / renderContext.ViewPort.Height;

            Color4 color = new Color4(TintColor.Red, TintColor.Green, TintColor.Blue, TintColor.Alpha * opacity);

            // Set up the shader
            if (renderStrategy == RenderStrategy.GeometryShader)
            {
                PointSpriteShader11.WVPMatrix         = mvp;
                PointSpriteShader11.Color             = color;
                PointSpriteShader11.ViewportScale     = new SharpDX.Vector2(1.0f, aspectRatio) * 0.001f;
                PointSpriteShader11.MinPointSize      = MinPointSize;
                PointSpriteShader11.PointScaleFactors = PointScaleFactors;
                PointSpriteShader11.Use(renderContext.Device.ImmediateContext);
            }
            else
            {
                CompatibilityPointSpriteShader.WVPMatrix         = mvp;
                CompatibilityPointSpriteShader.Color             = color;
                CompatibilityPointSpriteShader.ViewportScale     = new SharpDX.Vector2(1.0f, aspectRatio) * 0.001f;
                CompatibilityPointSpriteShader.PointScaleFactors = PointScaleFactors;
                CompatibilityPointSpriteShader.MinPointSize      = MinPointSize;
                bool useInstancing = renderStrategy == RenderStrategy.Instanced;
                CompatibilityPointSpriteShader.Use(renderContext.Device.ImmediateContext, useInstancing);
            }

            // Set shader resources
            renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, texture == null ? null : texture.ResourceView);
        }
Exemple #6
0
        public void Draw(RenderContext11 renderContext, int count, Texture11 texture, float opacity)
        {
            setupShader(renderContext, texture, opacity);

            count = Math.Min(this.count, count);

            switch (renderStrategy)
            {
            case RenderStrategy.GeometryShader:
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
                renderContext.SetVertexBuffer(0, vertexBuffer);
                renderContext.devContext.Draw(count, 0);
                renderContext.Device.ImmediateContext.GeometryShader.Set(null);
                break;

            case RenderStrategy.Instanced:
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
                renderContext.SetVertexBuffer(0, spriteCornerVertexBuffer);
                renderContext.SetVertexBuffer(1, vertexBuffer);
                renderContext.SetIndexBuffer(indexBuffer);
                renderContext.devContext.DrawIndexedInstanced(6, count, 0, 0, 0);
                break;

            case RenderStrategy.Fallback:
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
                renderContext.SetVertexBuffer(0, fallbackVertexBuffer);
                renderContext.SetIndexBuffer(indexBuffer);
                renderContext.devContext.DrawIndexed(count * 6, 0, 0);
                break;
            }
        }
 void CleanUp()
 {
     if (texture != null)
     {
         texture.Dispose();
         texture = null;
     }
 }
 public void CleanUp()
 {
     if (texture != null)
     {
         texture.Dispose();
     }
     dirty   = true;
     texture = null;
 }
        public KmlLabels()
        {
            texture = Texture11.FromBitmap( Resources.circle, 0);
            star = Texture11.FromBitmap(Resources.icon_rating_star_large_on, 0);

            center = new Vector3(10, 10, 0);
            positions = new List<Vector3>();
            names = new List<string>();
        }
Exemple #10
0
        public KmlLabels()
        {
            texture = Texture11.FromBitmap(Properties.Resources.circle, 0);
            star    = Texture11.FromBitmap(Properties.Resources.icon_rating_star_large_on, 0);

            center    = new Vector3(10, 10, 0);
            positions = new List <Vector3>();
            names     = new List <string>();
        }
Exemple #11
0
        public Texture11 GetCachedTexture(string filename, bool colorKey)
        {
            if (textureList == null)
            {
                textureList = new Dictionary <string, Texture11>();
            }

            if (textureList.ContainsKey(filename))
            {
                return(textureList[filename]);
            }
            Texture11 texture;

            if (ProjectorServer)
            {
                // Synce Layers
                try
                {
                    string dir  = Path.GetDirectoryName(filename);
                    string name = Path.GetFileName(filename);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    if (!File.Exists(filename))
                    {
                        WebClient client = new WebClient();
                        string    url    = string.Format("http://{0}:5050/Configuration/images/tour/{1}", NetControl.MasterAddress, name);
                        Byte[]    data   = client.DownloadData(url);
                        File.WriteAllBytes(filename, data);
                    }
                }
                catch
                {
                }
            }


            if (colorKey)
            {
                //todo11 Add Color Key support
                texture = Texture11.FromFile(filename);
            }
            else
            {
                texture = Texture11.FromFile(filename);
            }


            textureList[filename] = texture;

            return(texture);
        }
Exemple #12
0
        internal void Draw(RenderContext11 renderContext)
        {
            if (reticleImage == null)
            {
                reticleImage = Texture11.FromBitmap(Properties.Resources.Reticle);
            }

            ComputePoints();

            Sprite2d.Draw(renderContext, points, 4, reticleImage, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
        }
Exemple #13
0
        // Set up render context state required for drawing ground overlays when shaders
        // are enabled.
        public void SetupGroundOverlays(RenderContext11 renderContext)
        {
            // A shader should be set up already
            if (renderContext.Shader == null)
            {
                renderContext.SetupBasicEffect(BasicEffect.TextureOnly, 1.0f, Color.White);
            }

            // Count the number of overlays so that we can choose the appropriate shader
            int overlayCount = 0;

            foreach (KmlGroundOverlay overlay in GroundOverlays)
            {
                if (overlay.Icon.Texture != null)
                {
                    ++overlayCount;
                }
            }

            overlayCount = Math.Min(PlanetShader11.MaxOverlayTextures, overlayCount);
            if (overlayCount == 0)
            {
                // No work to do
                return;
            }

            // Get a shader identical to the one currently in use, but which supports
            // the required number of overlays.
            PlanetShaderKey key = renderContext.Shader.Key;

            key.overlayTextureCount = overlayCount;
            PlanetShader11 overlayShader = PlanetShader11.GetPlanetShader(renderContext.Device, key);

            renderContext.Shader = overlayShader;
            renderContext.Shader.DiffuseColor = new SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            SharpDX.Direct3D11.DeviceContext devContext = renderContext.Device.ImmediateContext;
            int overlayIndex = 0;

            foreach (KmlGroundOverlay overlay in GroundOverlays)
            {
                Texture11 texture = overlay.Icon.Texture;
                if (texture != null)
                {
                    if (overlayIndex < PlanetShader11.MaxOverlayTextures)
                    {
                        renderContext.Shader.SetOverlayTextureMatrix(overlayIndex, overlay.GetMatrix().Matrix11);
                        renderContext.Shader.SetOverlayTextureColor(overlayIndex, overlay.color);
                        renderContext.Shader.SetOverlayTexture(overlayIndex, texture.ResourceView);
                    }
                    ++overlayIndex;
                }
            }
        }
Exemple #14
0
        public void SetCurrentImage()
        {
            string timeString = GetTimeString();
            string url        = GetCurrentPath(timeString);

            Texture11 texture = WmsCache.GetTexture(timeString, url);

            Overlay.Icon         = new KmlIcon();
            Overlay.Icon.Texture = texture;

            //Earth3d.MainWindow.Text = Overlay.Icon.Href;
        }
        public void SetTexture(Bitmap bmp)
        {
            if (this.texture != null)
            {
                this.texture.Dispose();
                GC.SuppressFinalize(texture);
                this.texture = null;
            }

            texture = Texture11.FromBitmap(RenderContext11.PrepDevice, bmp);
            Width   = bmp.Width;
            Height  = bmp.Height;
        }
Exemple #16
0
        public SkyLabel(RenderContext11 renderContext, double ra, double dec, string text, LabelSytle style, double distance)
        {
            RA    = ra;
            Dec   = dec;
            Text  = text;
            Style = style;

            Distance = distance;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Properties.Resources.circle, 0);
            }

            Vector3d up      = new Vector3d();
            Vector3d textPos = new Vector3d();

            if (Earth3d.MainWindow.SolarSystemMode)
            {
                pos = Coordinates.RADecTo3d(ra, -dec, distance);
                up  = Coordinates.RADecTo3d(ra, -dec + 90, distance);

                pos.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                pos.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));

                up.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                up.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));
            }
            else
            {
                pos     = Coordinates.RADecTo3d(ra + 12, dec, distance);
                textPos = Coordinates.RADecTo3d(ra + 12, dec + 2, distance);
                up      = Coordinates.RADecTo3d(ra + 12, dec + 92, distance);
            }
            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(24);
            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                Text3d t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                up.Normalize();
                textPos.Normalize();
                textBatch.Add(new Text3d(textPos, up, text, 20, .0005));
            }
        }
Exemple #17
0
        public static Texture11 GetTexture(Bitmap bitmap)
        {
            return(Texture11.FromBitmap(RenderContext11.PrepDevice, bitmap));

            //todo11 reenable the pooling of textures
            //if (bitmap.Width != 256 || bitmap.Height != 256 | !(bitmap.PixelFormat == PixelFormat.Format32bppArgb | bitmap.PixelFormat == PixelFormat.Format24bppRgb))
            //{
            //    return UiTools.LoadTextureFromBmp(Tile.prepDevice, bitmap);
            //}

            //Texture11 texture = null;
            //if (TexturePool256.Count > 0)
            //{
            //    texture = TexturePool256.Pop();
            //}
            //else
            //{
            //    texture = new Texture11(Tile.prepDevice, 256, 256, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);

            //}

            //if (bitmap.PixelFormat == PixelFormat.Format32bppArgb | bitmap.PixelFormat == PixelFormat.Format24bppRgb)
            //{
            //    BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            //    int pitch;
            //    GraphicsStream textureData = texture.LockRectangle(0, LockFlags.Discard, out pitch);
            //    unsafe
            //    {
            //        uint* texturePointer = (uint*)textureData.InternalDataPointer;
            //        for (int y = 0; y < bitmap.Height; y++)
            //        {
            //            uint* bitmapLinePointer = (uint*)bitmapData.Scan0 + y * (bitmapData.Stride / sizeof(int));
            //            uint* textureLinePointer = texturePointer + y * (pitch / sizeof(int));
            //            int length = bitmap.Width;

            //            while (--length >= 0)
            //            {
            //                *textureLinePointer++ = *bitmapLinePointer++;
            //            }

            //        }
            //    }

            //    bitmap.UnlockBits(bitmapData);
            //    texture.UnlockRectangle(0);
            //    //   texture.GenerateMipSubLevels();
            //}

            //return texture;
        }
Exemple #18
0
        public void Dispose()
        {
            if (texture != null)
            {
                texture.Dispose();
                GC.SuppressFinalize(texture);
                texture = null;
            }

            if (labelBuffer != null)
            {
                labelBuffer.Dispose();
                GC.SuppressFinalize(labelBuffer);
                labelBuffer = null;
            }
        }
        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;
        }
Exemple #20
0
        public void Draw(RenderContext11 renderContext, int count, Texture11 texture, float opacity, IndexBuffer11 indexBufferIn)
        {
            setupShader(renderContext, texture, opacity);


            count = Math.Min(this.count, count);

            switch (renderStrategy)
            {
            case RenderStrategy.GeometryShader:
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
                renderContext.SetVertexBuffer(0, vertexBuffer);
                renderContext.SetIndexBuffer(indexBufferIn);
                renderContext.devContext.DrawIndexed(count, 0, 0);
                renderContext.Device.ImmediateContext.GeometryShader.Set(null);
                break;
            }
        }
        private Bitmap GetChartImageBitmap(Earth3d window)
        {
            Bitmap bmp = null;

            if (chartType == ChartTypes.Histogram)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetSingleColumnHistogram(TargetColumn);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);
            }

            else if (chartType == ChartTypes.BarChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDomainValueBarChart(domainColumn, targetColumn, denominatorColumn, statType);
                }
                bmp = GetBarChartBitmap(Stats);


                texture = Texture11.FromBitmap(bmp, 0);
            }
            else if (chartType == ChartTypes.TimeChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDateHistogram(TargetColumn, DateFilter);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);
            }

            Width  = bmp.Width;
            Height = bmp.Height;
            Top    = (int)window.RenderContext11.ViewPort.Height - (Height + 120);
            Left   = (int)window.RenderContext11.ViewPort.Width / 2 - (Width / 2);

            return(bmp);
        }
        static public Texture11 FromStream(Device device, Stream stream)
        {
            byte[] data = null;
            if (SaveStream)
            {
                MemoryStream ms = new MemoryStream();

                stream.CopyTo(ms);
                stream.Seek(0, SeekOrigin.Begin);
                data = ms.GetBuffer();
            }

            try
            {
                ImageLoadInformation loadInfo = new ImageLoadInformation();
                loadInfo.BindFlags      = BindFlags.ShaderResource;
                loadInfo.CpuAccessFlags = CpuAccessFlags.None;
                loadInfo.Depth          = -1;
                loadInfo.Format         = RenderContext11.DefaultTextureFormat;
                loadInfo.Filter         = FilterFlags.Box;
                loadInfo.FirstMipLevel  = 0;
                loadInfo.Height         = -1;
                loadInfo.MipFilter      = FilterFlags.Linear;
                loadInfo.MipLevels      = 0;
                loadInfo.OptionFlags    = ResourceOptionFlags.None;
                loadInfo.Usage          = ResourceUsage.Default;
                loadInfo.Width          = -1;
                if (loadInfo.Format == SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb)
                {
                    loadInfo.Filter |= FilterFlags.SRgb;
                }

                Texture2D texture = Texture2D.FromStream <Texture2D>(device, stream, (int)stream.Length, loadInfo);

                Texture11 t11 = new Texture11(texture);
                t11.savedStrem = data;
                return(t11);
            }
            catch
            {
                return(null);
            }
        }
Exemple #23
0
        public void Draw3D(RenderContext11 renderContext, float transparancy)
        {
            ratio = 1116f / (float)Earth3d.MainWindow.RenderWindow.ClientRectangle.Height;

            if (SingleSelectHandles == null)
            {
                SingleSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, (Bitmap)global::TerraViewer.Properties.Resources.Selhand);
            }

            if (MultiSelectHandles == null)
            {
                MultiSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, (Bitmap)global::TerraViewer.Properties.Resources.MultiSelhand);
            }

            if (FocusHandles == null)
            {
                FocusHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, (Bitmap)global::TerraViewer.Properties.Resources.FocusHandles);
            }

            if (selectionSet.Count > 1)
            {
                foreach (Overlay overlay in selectionSet)
                {
                    if (overlay == focus)
                    {
                        DrawSelectionHandles(renderContext, overlay, FocusHandles);
                    }
                    else
                    {
                        DrawSelectionHandles(renderContext, overlay, MultiSelectHandles);
                    }
                }
            }
            else
            {
                foreach (Overlay overlay in selectionSet)
                {
                    DrawSelectionHandles(renderContext, overlay, SingleSelectHandles);
                }
            }
        }
Exemple #24
0
        public static void ReturnTexture(Texture11 texture)
        {
            if (texture == null)
            {
                return;
            }
            texture.Dispose();
            GC.SuppressFinalize(texture);

            //todo11 reimplement pooling of textures
            //SurfaceDescription sd = texture.GetLevelDescription(0);

            //if (sd.Height != 256 || sd.Width != 256)
            //{
            //    texture.Dispose();
            //    GC.SuppressFinalize(texture);
            //}
            //else
            //{
            //BufferMutex.WaitOne();
            //    TexturePool256.Push(texture);
            //BufferMutex.ReleaseMutex();
            //}
        }
Exemple #25
0
        public static Texture11 GetPushPinTexture(int pinId)
        {
            if (pinTextureCache.ContainsKey(pinId))
            {
                return(pinTextureCache[pinId]);
            }

            Bitmap bmp = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            Graphics gOut = Graphics.FromImage(bmp);

            int row = pinId / 16;
            int col = pinId % 16;

            gOut.DrawImage(Pins, new Rectangle(0, 0, 32, 32), (col * 32), (row * 32), 32, 32, GraphicsUnit.Pixel);

            gOut.Flush();
            gOut.Dispose();
            Texture11 tex = Texture11.FromBitmap(bmp, 0xFF000000);

            bmp.Dispose();
            pinTextureCache.Add(pinId, tex);
            return(tex);
        }
Exemple #26
0
        public virtual void CleanUp(bool removeFromParent)
        {
            ReadyToRender = false;
            TextureReady = false;

            DemData = null;
            DemReady = false;
            hdTile = null;

            if (this.texture != null)
            {
                if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile:Texture Cleanup"); }
                BufferPool11.ReturnTexture(texture);
                this.texture = null;
            }
            else
            {
                if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile:Cleanup - no Texture"); }
            }

            if (this.vertexBuffer != null)
            {

                BufferPool11.ReturnPNTX2VertexBuffer(vertexBuffer);
                this.vertexBuffer = null;
            }

            if (this.indexBuffer != null)
            {
                foreach (IndexBuffer11 buffer in indexBuffer)
                {
                    if (buffer != null)
                    {
                        BufferPool11.ReturnShortIndexBuffer(buffer);
                    }
                }
                this.indexBuffer = null;
            }
        }
        public void Draw(RenderContext11 renderContext, int count, Texture11 texture, float opacity)
        {
            setupShader(renderContext, texture, opacity);

            count = Math.Min(this.count, count);

            switch (renderStrategy)
            {
                case RenderStrategy.GeometryShader:
                    renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
                    renderContext.SetVertexBuffer(0, vertexBuffer);
                    renderContext.devContext.Draw(count, 0);
                    renderContext.Device.ImmediateContext.GeometryShader.Set(null);
                    break;

                case RenderStrategy.Instanced:
                    renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                    renderContext.SetVertexBuffer(0, spriteCornerVertexBuffer);
                    renderContext.SetVertexBuffer(1, vertexBuffer);
                    renderContext.SetIndexBuffer(indexBuffer);
                    renderContext.devContext.DrawIndexedInstanced(6, count, 0, 0, 0);
                    break;

                case RenderStrategy.Fallback:
                    renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                    renderContext.SetVertexBuffer(0, fallbackVertexBuffer);
                    renderContext.SetIndexBuffer(indexBuffer);
                    renderContext.devContext.DrawIndexed(count * 6, 0, 0);
                    break;
            }
        }
        public SkyLabel(RenderContext11 renderContext, double ra, double dec, string text, LabelSytle style, double distance)
        {
            RA = ra;
            Dec = dec;
            Text = text;
            Style = style;

            Distance = distance;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Resources.circle, 0);
            }

            var up = new Vector3d();
            var textPos = new Vector3d();
            if (Earth3d.MainWindow.SolarSystemMode)
            {
                pos = Coordinates.RADecTo3d(ra, -dec, distance);
                up = Coordinates.RADecTo3d(ra, -dec + 90, distance);

                pos.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                pos.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));

                up.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                up.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));
               }
            else
            {
                pos = Coordinates.RADecTo3d(ra+12, dec, distance);
                textPos = Coordinates.RADecTo3d(ra + 12, dec + 2, distance);
                up = Coordinates.RADecTo3d(ra+12, dec + 92, distance);

            }
            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(24);
            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                var t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                up.Normalize();
                textPos.Normalize();
                textBatch.Add(new Text3d(textPos, up, text, 20, .0005));
            }
        }
        protected void InitializeRift()
        {

            // Initialize OVR Library
            OVR.Initialize();

            if (OVR.HmdDetect() < 1)
            {
                throw new IndexOutOfRangeException("No Rfft detected");
            }

            // Create our HMD
            hmd = OVR.HmdCreate(0);

            if (hmd == null)
            {
                throw new IndexOutOfRangeException("Can't create Rift");
            }

            SharpDX.Size2 left = hmd.GetFovTextureSize(EyeType.Left, hmd.DefaultEyeFov[0]);
            SharpDX.Size2 right = hmd.GetFovTextureSize(EyeType.Right, hmd.DefaultEyeFov[1]);

            leftEyeWidth = left.Width;
            leftEyeHeight = left.Height;
            rightEyeWidth = right.Width;
            rightEyeHeight = right.Height;

            // Create our render target
            eyeTexture[0] = hmd.CreateSwapTexture(RenderContext11.Device, riftFormat, left, false);
            eyeTexture[1] = hmd.CreateSwapTexture(RenderContext11.Device, riftFormat, right, false);

            swapTextures[0] = new SwapTextureSetD3D(eyeTexture[0].TextureSet);

            swapTextures[1] = new SwapTextureSetD3D(eyeTexture[1].TextureSet);

            // Create our layer
            layerEyeFov = new LayerEyeFov
            {
                Header = new LayerHeader(LayerType.EyeFov, LayerFlags.HighQuality),
                ColorTextureLeft = eyeTexture[0].TextureSet,
                ColorTextureRight = eyeTexture[1].TextureSet,
                ViewportLeft = new Rect(0, 0, eyeTexture[0].Size.Width, eyeTexture[0].Size.Height),
                ViewportRight = new Rect(0, 0, eyeTexture[1].Size.Width, eyeTexture[1].Size.Height),
                FovLeft = hmd.DefaultEyeFov[0],
                FovRight = hmd.DefaultEyeFov[1],
            };

            // Keep eye view offsets
            eyeRenderDesc[0] = hmd.GetRenderDesc(EyeType.Left, hmd.DefaultEyeFov[0]);
            eyeRenderDesc[1] = hmd.GetRenderDesc(EyeType.Right, hmd.DefaultEyeFov[1]);
            hmdToEyeViewOffset[0] = eyeRenderDesc[0].HmdToEyeViewOffset;
            hmdToEyeViewOffset[1] = eyeRenderDesc[1].HmdToEyeViewOffset;

            // Create a mirror texture
            mirrorTexture = hmd.CreateMirrorTexture(RenderContext11.Device, RenderContext11.BackBuffer.Description);
            mirror = new Texture11(mirrorTexture);
            
            // Configure tracking
            hmd.ConfigureTracking(TrackingCapabilities.Orientation | TrackingCapabilities.Position | TrackingCapabilities.MagYawCorrection, TrackingCapabilities.None);

            // Set enabled capabilities
            hmd.EnabledCaps = HMDCapabilities.LowPersistence | HMDCapabilities.DynamicPrediction;
            
            riftInit = true;
           
        }
        public static void DrawForScreen(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, SharpDX.Direct3D.PrimitiveTopology primitiveType)
        {
            if (VertexBuffer == null)
            {
                VertexBuffer        = new Buffer(renderContext.Device, System.Runtime.InteropServices.Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, System.Runtime.InteropServices.Marshal.SizeOf(points[0]));
                VertexBufferBinding = new VertexBufferBinding(VertexBuffer, System.Runtime.InteropServices.Marshal.SizeOf((points[0])), 0);
            }

            renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType;
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.setRasterizerState(TriangleCullMode.Off);

            SharpDX.Matrix mat =
                SharpDX.Matrix.Translation(-renderContext.ViewPort.Width / 2, -renderContext.ViewPort.Height / 2, 0) *
                SharpDX.Matrix.Scaling(1f, -1f, 1f)
                * SharpDX.Matrix.OrthoLH(renderContext.ViewPort.Width, renderContext.ViewPort.Height, 1, -1);
            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(renderContext.devContext, texture != null);

            renderContext.SetVertexBuffer(VertexBufferBinding);

            DataBox box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);

            Utilities.Write(box.DataPointer, points, 0, count);

            renderContext.devContext.UnmapSubresource(VertexBuffer, 0);
            if (texture != null)
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView);
            }
            else
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, null);
            }
            renderContext.devContext.Draw(count, 0);
        }
        public void MakeSphere(SharpDX.Direct3D11.Device d3dDevice)
        {
            // Layout from VertexShader input signature


            texture = Texture11.FromFile(d3dDevice, "earthMap.jpg");

            uint[] indexes = new uint[subDivisionsX * subDivisionsY * 6];
            float[] verts = new float[((subDivisionsX + 1) * (subDivisionsY + 1)) * 6];


            double lat, lng;

            uint index = 0;
            double latMin = 90;
            double latMax = -90;
            double lngMin = -180;
            double lngMax = 180;


            uint x1, y1;

            double latDegrees = latMax - latMin;
            double lngDegrees = lngMax - lngMin;

            double textureStepX = 1.0f / subDivisionsX;
            double textureStepY = 1.0f / subDivisionsY;
            for (y1 = 0; y1 <= subDivisionsY; y1++)
            {

                if (y1 != subDivisionsY)
                {
                    lat = latMax - (textureStepY * latDegrees * (double)y1);
                }
                else
                {
                    lat = latMin;
                }

                for (x1 = 0; x1 <= subDivisionsX; x1++)
                {
                    if (x1 != subDivisionsX)
                    {
                        lng = lngMin + (textureStepX * lngDegrees * (double)x1);
                    }
                    else
                    {
                        lng = lngMax;
                    }
                    index = (y1 * (subDivisionsX + 1) + x1) * 6;

                    GeoTo3d(verts, (int)index, lat, lng);
                }
            }

            triangleCount = (subDivisionsX) * (subDivisionsY) * 2;

            for (y1 = 0; y1 < subDivisionsY; y1++)
            {
                for (x1 = 0; x1 < subDivisionsX; x1++)
                {
                    index = (y1 * subDivisionsX * 6) + 6 * x1;
                    // First triangle in quad
                    indexes[index] = (y1 * (subDivisionsX + 1) + x1);
                    indexes[index + 1] = ((y1 + 1) * (subDivisionsX + 1) + x1);
                    indexes[index + 2] = (y1 * (subDivisionsX + 1) + (x1 + 1));

                    // Second triangle in quad
                    indexes[index + 3] = (y1 * (subDivisionsX + 1) + (x1 + 1));
                    indexes[index + 4] = ((y1 + 1) * (subDivisionsX + 1) + x1);
                    indexes[index + 5] = ((y1 + 1) * (subDivisionsX + 1) + (x1 + 1));
                }
            }

            vertices = SharpDX.Direct3D11.Buffer.Create(d3dDevice, SharpDX.Direct3D11.BindFlags.VertexBuffer, verts);

            vertexBufferBinding = new SharpDX.Direct3D11.VertexBufferBinding(vertices, sizeof(float) * 6, 0);

            indexBuffer = SharpDX.Direct3D11.Buffer.Create(d3dDevice, SharpDX.Direct3D11.BindFlags.IndexBuffer, indexes);


        }
Exemple #32
0
        public void DrawPlaceMarks()
        {
            // todo11 port this Maybe instancing later?
            Matrix   projection = Earth3d.MainWindow.RenderContext11.Projection.Matrix11;
            Matrix   view       = Earth3d.MainWindow.RenderContext11.View.Matrix11;
            Matrix   world      = Earth3d.MainWindow.RenderContext11.World.Matrix11;
            Matrix3d worldD     = Earth3d.MainWindow.RenderContext11.World;
            Matrix   wvp        = (world * view * projection);

            try
            {
                Vector3 center = new Vector3(0f, 0f, 0);

                foreach (KmlPlacemark placemark in Placemarks)
                {
                    if (placemark.ShouldDisplay())
                    {
                        SharpDX.Direct3D11.Viewport vp = Earth3d.MainWindow.RenderContext11.ViewPort;
                        double   alt     = placemark.Point.altitude + EGM96Geoid.Height(placemark.Point.latitude, placemark.Point.longitude);
                        Vector3d point3d = Coordinates.GeoTo3dDouble(placemark.Point.latitude, placemark.Point.longitude, 1 + (alt / Earth3d.MainWindow.RenderContext11.NominalRadius));
                        Vector3  point   = Vector3.Project(point3d.Vector311, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0, 1, wvp);
                        // point.Z = 1;
                        KmlStyle  style   = placemark.Style.GetStyle(placemark.Selected);
                        Texture11 texture = style.IconStyle.Icon.Texture;

                        if (String.IsNullOrEmpty(style.IconStyle.Icon.Href))
                        {
                            texture = Star;
                        }

                        double sizeFactor = 1;

                        if (placemark.Selected)
                        {
                            double ticks          = HiResTimer.TickCount;
                            double elapsedSeconds = ((double)(ticks - TicksAtLastSelect)) / HiResTimer.Frequency;
                            sizeFactor = 1 + .3 * (Math.Sin(elapsedSeconds * 15) * Math.Max(0, (1 - elapsedSeconds)));
                        }

                        point3d.TransformCoordinate(worldD);
                        Vector3d dist     = Earth3d.MainWindow.RenderContext11.CameraPosition - point3d;
                        double   distance = dist.Length() * Earth3d.MainWindow.RenderContext11.NominalRadius;
                        dist.Normalize();
                        double dot = Vector3d.Dot(point3d, dist);
                        // if (dot > -.2)
                        {
                            double baseSize = Math.Min(40, 25 * ((2 * Math.Atan(.5 * (5884764 / distance))) / .7853)) * sizeFactor;
                            float  size     = (float)baseSize * style.IconStyle.Scale;
                            //todo fix this with real centers and offset by KML data
                            placemark.hitTestRect = new Rectangle((int)(point.X - (size / 2)), (int)(point.Y - (size / 2)), (int)(size + .5), (int)(size + .5));
                            if (texture != null)
                            {
                                center = new Vector3((float)texture.Width / 2f, (float)texture.Height / 2f, 0);

                                Sprite2d.Draw2D(Earth3d.MainWindow.RenderContext11, texture, new SizeF(size, size), new PointF(center.X, center.Y), (float)(style.IconStyle.Heading * Math.PI / 180f), new PointF(point.X, point.Y), Color.White);
                            }

                            if (style.LabelStyle.Color.A > 0 && style.LabelStyle.Scale > 0)
                            {
                                Rectangle recttext = new Rectangle((int)(point.X + (size / 2) + 10), (int)(point.Y - (size / 2)), 1000, 100);
                                //todo11 Earth3d.MainWindow.labelFont.DrawText(null, placemark.Name, recttext, DrawTextFormat.NoClip, style.LabelStyle.Color);
                            }
                        }
                    }
                }
            }
            finally
            {
            }
        }
        // Set up a shader for the specified material properties and the
        // current lighting environment.
        public void SetMaterial(Material material, Texture11 diffuseTex, Texture11 specularTex, Texture11 normalMap, float opacity)
        {
            PlanetSurfaceStyle surfaceStyle = PlanetSurfaceStyle.Diffuse;
            if (material.Specular != System.Drawing.Color.Black)
            {
                surfaceStyle = PlanetSurfaceStyle.Specular;
            }

            // Force the emissive style when lighting is disabled
            if (!lightingEnabled)
            {
                surfaceStyle = PlanetSurfaceStyle.Emissive;
            }

            PlanetShaderKey key = new PlanetShaderKey(surfaceStyle, false, 0);
            if (reflectedLightColor != System.Drawing.Color.Black)
            {
                key.lightCount = 2;
            }

            key.textures = 0;
            if (diffuseTex != null)
            {
                key.textures |= PlanetShaderKey.SurfaceProperty.Diffuse;
            }

            if (specularTex != null)
            {
                key.textures |= PlanetShaderKey.SurfaceProperty.Specular;
            }

            if (normalMap != null)
            {
                key.textures |= PlanetShaderKey.SurfaceProperty.Normal;
            }

            key.TwoSidedLighting = twoSidedLighting;

            SetupPlanetSurfaceEffect(key, material.Opacity * opacity);

            shader.DiffuseColor = new Vector4(material.Diffuse.R / 255.0f, material.Diffuse.G / 255.0f, material.Diffuse.B / 255.0f, material.Opacity*opacity);
            if (surfaceStyle == PlanetSurfaceStyle.Specular || surfaceStyle == PlanetSurfaceStyle.SpecularPass)
            {
                shader.SpecularColor = new Vector4(material.Specular.R / 255.0f, material.Specular.G / 255.0f, material.Specular.B / 255.0f, 0.0f);
                shader.SpecularPower = material.SpecularSharpness;
            }

            if (diffuseTex != null)
            {
                shader.MainTexture = diffuseTex.ResourceView;
            }

            if (specularTex != null)
            {
                shader.SpecularTexture = specularTex.ResourceView;
            }

            if (normalMap != null)
            {
                shader.NormalTexture = normalMap.ResourceView;
            }
        }
        public static void DrawForScreen(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, PrimitiveTopology primitiveType)
        {
            if (VertexBuffer == null)
            {
                VertexBuffer = new Buffer(renderContext.Device, Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, Marshal.SizeOf(points[0]));
                VertexBufferBinding = new VertexBufferBinding(VertexBuffer, Marshal.SizeOf((points[0])), 0);

            }

            renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType;
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.setRasterizerState(TriangleCullMode.Off);

            var mat =
                Matrix.Translation(-renderContext.ViewPort.Width / 2, -renderContext.ViewPort.Height / 2, 0) *
                Matrix.Scaling(1f, -1f, 1f)
            * Matrix.OrthoLH(renderContext.ViewPort.Width, renderContext.ViewPort.Height, 1, -1);
            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(renderContext.devContext, texture != null);

            renderContext.SetVertexBuffer(VertexBufferBinding);

            var box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
            Utilities.Write(box.DataPointer, points, 0, count);

            renderContext.devContext.UnmapSubresource(VertexBuffer, 0);
            if (texture != null)
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView);
            }
            else
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, null);
            }
            renderContext.devContext.Draw(count, 0);
        }
        private Bitmap GetChartImageBitmap(Earth3d window)
        {
            Bitmap bmp = null;
            if (chartType == ChartTypes.Histogram)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetSingleColumnHistogram(TargetColumn);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap( bmp, 0);

            }

            else if (chartType == ChartTypes.BarChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDomainValueBarChart(domainColumn, targetColumn, denominatorColumn, statType);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);

            }
            else if (chartType == ChartTypes.TimeChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDateHistogram(TargetColumn, DateFilter);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);

            }

            Width = bmp.Width;
            Height = bmp.Height;
            Top = (int)window.RenderContext11.ViewPort.Height - (Height + 120);
            Left = (int)window.RenderContext11.ViewPort.Width / 2 - (Width / 2);

            return bmp;
        }
 void CleanUp()
 {
     if (texture != null)
     {
         texture.Dispose();
         texture = null;
     }
 }
Exemple #37
0
        public virtual bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (uiThread && !ReadyToRender)
            {
                return false;
            }

            if (texture == null)
            {
                if (PreCreateGeometry(renderContext))
                {
                    ReadyToRender = true;
                    TextureReady = true;
                    blendMode = false;
                    if (DemEnabled && DemReady && DemData == null)
                    {
                        if (!LoadDemData())
                        {
                            if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile:CreateGeometry:Loading Dem Failed"); }
                            return false;
                        }
                    }
                    return true;
                }

                blendMode = (dataset.DataSetType == ImageSetType.Sky || dataset.DataSetType == ImageSetType.Panorama) && !Settings.DomeView;
                //blendMode = false;
                if (this.texture == null)
                {
                    if (TextureReady)
                    {
                        iTileBuildCount++;

                        string localFilename = FileName;
                        if (GrayscaleStyle)
                        {
                            localFilename = UiTools.MakeGrayScaleImage(localFilename);
                        }

                        if (FileExists)
                        {
                            if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile:CreateGeometry:Loading Texture"); }
                            texture = BufferPool11.GetTexture(localFilename);
                            if (texture == null)
                            {
                                try
                                {
                                    // bad texture
                                    TextureReady = false;
                                    File.Delete(localFilename);
                                }
                                catch
                                {
                                    if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile:CreateGeometry:Loading Texture: Exception"); }
                                    errored = true;
                                }
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }

                        TexturesLoaded++;

                    }
                    else
                    {
                        return false;
                    }
                }

                if (DemEnabled  && DemReady && DemData == null)
                {
                    if (!LoadDemData())
                    {
                        if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile:CreateGeometry:Loading Dem Failed"); }
                        return false;
                    }
                }

                if (DemEnabled && DemData == null)
                {
                    return false;
                }
            }

            if (vertexBuffer == null)
            {
                vertexBuffer = BufferPool11.GetPNTX2VertexBuffer(VertexCount);
                vertexBuffer.ComputeSphereOnUnlock = true;
                indexBuffer = new IndexBuffer11[4];

                if (vertexBuffer != null)
                {
                    this.OnCreateVertexBuffer(vertexBuffer);

                    sphereRadius = vertexBuffer.SphereRadius;
                    sphereCenter = vertexBuffer.SphereCenter;
                    sphereCenter.Add(localCenter);
                }

            }

            ReadyToRender = true;
            return true;
        }
        private void FadeFrame()
        {

            SettingParameter sp = Settings.Active.GetSetting(StockSkyOverlayTypes.FadeToBlack);

            

            if ((sp.Opacity > 0) && !(Settings.MasterController && Properties.Settings.Default.FadeRemoteOnly))
            {
                Color color = Color.FromArgb(255 - (int)UiTools.Gamma(255 - (int)(sp.Opacity * 255), 1 / 2.2f), Color.Black);

                if (!(sp.Opacity > 0))
                {
                    color = Color.FromArgb(255 - (int)UiTools.Gamma(255 - (int)(sp.Opacity * 255), 1 / 2.2f), Color.Black);
                }


                if (crossFadeFrame)
                {
                    color = Color.FromArgb((int)UiTools.Gamma((int)((sp.Opacity) * 255), 1 / 2.2f), Color.White);
                }
                else
                {
                    if (crossFadeTexture != null)
                    {
                        crossFadeTexture.Dispose();
                        crossFadeTexture = null;
                    }
                }

                fadePoints[0].X = 0;
                fadePoints[0].Y = renderWindow.Height;
                fadePoints[0].Z = 0;
                fadePoints[0].Tu = 0;
                fadePoints[0].Tv = 1;
                fadePoints[0].W = 1;
                fadePoints[0].Color = color;
                fadePoints[1].X = 0;
                fadePoints[1].Y = 0;
                fadePoints[1].Z = 0;
                fadePoints[1].Tu = 0;
                fadePoints[1].Tv = 0;
                fadePoints[1].W = 1;
                fadePoints[1].Color = color;
                fadePoints[2].X = renderWindow.Width;
                fadePoints[2].Y = renderWindow.Height;
                fadePoints[2].Z = 0;
                fadePoints[2].Tu = 1;
                fadePoints[2].Tv = 1;
                fadePoints[2].W = 1;
                fadePoints[2].Color = color;
                fadePoints[3].X = renderWindow.Width;
                fadePoints[3].Y = 0;
                fadePoints[3].Z = 0;
                fadePoints[3].Tu = 1;
                fadePoints[3].Tv = 0;
                fadePoints[3].W = 1;
                fadePoints[3].Color = color;

                Sprite2d.DrawForScreen(RenderContext11, fadePoints, 4, crossFadeTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
            }
        }
        private void DrawTouchControls()
        {

            if (Properties.Settings.Default.ShowTouchControls && !TourEditor.Capturing && !CaptureVideo)
            {

                MakeTouchPoints();

                if (trackerButton == null)
                {
                    trackerButton = Planets.LoadPlanetTexture(Properties.Resources.TrackerButton);
                }

                if (touchControl == null)
                {
                    string appdir = Path.GetDirectoryName(Application.ExecutablePath);
                    string customImageFile = appdir + "\\TouchControls.png";
                    string customImageFileNoHold = appdir + "\\TouchControlsNoHold.png";
                    if (File.Exists(customImageFile))
                    {
                        Bitmap bmp = new Bitmap(customImageFile);
                        touchControl = Planets.LoadPlanetTexture(bmp); 
                        bmp.Dispose();
                    }
                    else
                    {
                        touchControl = Planets.LoadPlanetTexture(Properties.Resources.TouchControls);
                    }

                    if (File.Exists(customImageFileNoHold))
                    {
                        Bitmap bmp = new Bitmap(customImageFileNoHold);
                        touchControlNoHold = Planets.LoadPlanetTexture(bmp); 
                        bmp.Dispose();
                    }
                    else
                    {
                        touchControlNoHold = Planets.LoadPlanetTexture(Properties.Resources.TouchControlsNoHold);
                    }

                }

                float x = RenderContext11.ViewPort.Width - 207;
                float y = RenderContext11.ViewPort.Height - (234 + 120);
                float w = 197;
                float h = 224;

                TouchControlPoints[0].X = x;
                TouchControlPoints[0].Y = y;
                TouchControlPoints[0].Z = .9f;
                TouchControlPoints[0].W = 1;
                TouchControlPoints[0].Tu = 0;
                TouchControlPoints[0].Tv = 0;
                TouchControlPoints[0].Color = Color.FromArgb(64, 255, 255, 255);

                TouchControlPoints[1].X = (float)(x + w);
                TouchControlPoints[1].Y = (float)(y);
                TouchControlPoints[1].Tu = 1;
                TouchControlPoints[1].Tv = 0;
                TouchControlPoints[1].Color = Color.FromArgb(64, 255, 255, 255);
                TouchControlPoints[1].Z = .9f;
                TouchControlPoints[1].W = 1;

                TouchControlPoints[2].X = (float)(x);
                TouchControlPoints[2].Y = (float)(y + h);
                TouchControlPoints[2].Tu = 0;
                TouchControlPoints[2].Tv = 1;
                TouchControlPoints[2].Color = Color.FromArgb(64, 255, 255, 255);
                TouchControlPoints[2].Z = .9f;
                TouchControlPoints[2].W = 1;

                TouchControlPoints[3].X = (float)(x + w);
                TouchControlPoints[3].Y = (float)(y + h);
                TouchControlPoints[3].Tu = 1;
                TouchControlPoints[3].Tv = 1;
                TouchControlPoints[3].Color = Color.FromArgb(64, 255, 255, 255);
                TouchControlPoints[3].Z = .9f;
                TouchControlPoints[3].W = 1;

                if (Friction)
                {
                    Sprite2d.DrawForScreen(RenderContext11, TouchControlPoints, 4, touchControlNoHold, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
                }
                else
                {
                    Sprite2d.DrawForScreen(RenderContext11, TouchControlPoints, 4, touchControl, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
                }

                if (!kioskControl)
                {
                    if (Friction && activeTouch == TouchControls.None)
                    {
                        float frictionFactor = (float)(1 - (lastFrameTime / 2));
                        moveVector.X *= frictionFactor;
                        moveVector.Y *= frictionFactor;
                        OrbitVector *= frictionFactor;
                        ZoomVector *= frictionFactor;
                    }


                    // Calculate Arc for Zoom
                    Vector2d zoomArc = new Vector2d(zoomTracker.X - ZoomVector, (zoomTracker.Y - Math.Cos(ZoomVector / 54 * Math.PI / 2) * 20) + 39);
                    touchPoints[(int)TouchControls.ZoomTrack] = zoomArc;

                    // Calculate Arc for Orbit
                    Vector2d orbitArc = new Vector2d(99 - (Math.Sin(OrbitVector / 70 * Math.PI / 2) * 68), 113 + (Math.Cos(OrbitVector / 70 * Math.PI / 2) * 75));
                    touchPoints[(int)TouchControls.OrbitTrack] = orbitArc;

                    // Calculate Current Pan Position
                    Vector2d panPos = new Vector2d(panTracker.X - moveVector.X, panTracker.Y - moveVector.Y);

                    touchPoints[(int)TouchControls.PanTrack] = panPos;

                    Sprite2d.Draw2D(RenderContext11, trackerButton, new SizeF(32, 32), new PointF(15, 15), 0, new PointF((float)touchPoints[(int)TouchControls.PanTrack].X + x, (float)touchPoints[(int)TouchControls.PanTrack].Y + y), Color.FromArgb(128, 255, 255, 255));
                    Sprite2d.Draw2D(RenderContext11, trackerButton, new SizeF(32, 32), new PointF(15, 15), 0, new PointF((float)touchPoints[(int)TouchControls.OrbitTrack].X + x, (float)touchPoints[(int)TouchControls.OrbitTrack].Y + y), Color.FromArgb(128, 255, 255, 255));
                    Sprite2d.Draw2D(RenderContext11, trackerButton, new SizeF(32, 32), new PointF(15, 15), 0, new PointF((float)touchPoints[(int)TouchControls.ZoomTrack].X + x, (float)touchPoints[(int)TouchControls.ZoomTrack].Y + y), Color.FromArgb(128, 255, 255, 255));
                }
            }
        }
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null || (Volitile && !ReadyToRender))
            {
                GetParameters();
                if (ImageData != null)
                {
                    try
                    {
                        MemoryStream ms = new MemoryStream(ImageData);

                        Texture11 old = this.texture;

                        texture = Texture11.FromStream(RenderContext11.PrepDevice, ms);

                        ReadyToRender = true;
                        if (old != null)
                        {
                            old.Dispose();
                            GC.SuppressFinalize(old);
                        }

                        if (Width == 0 && Height == 0)
                        {
                            Width  = texture.Width;
                            Height = texture.Height;
                            if (dataset.WcsImage != null)
                            {
                                if (dataset.WcsImage.SizeX != 0)
                                {
                                    Width = dataset.WcsImage.SizeX;
                                }
                                if (dataset.WcsImage.SizeY != 0)
                                {
                                    Height = dataset.WcsImage.SizeY;
                                }
                            }
                        }
                        ms.Dispose();
                        ImageData = null;
                    }
                    catch
                    {
                        return(false);
                    }
                }

                if (TextureReady)
                {
                    if (dataset.WcsImage != null)
                    {
                        if (dataset.WcsImage is FitsImage)
                        {
                            SetTexture(dataset.WcsImage.GetBitmap());
                            ReadyToRender = true;
                        }
                    }
                }
                if (this.texture == null)
                {
                    if (dataset.WcsImage != null)
                    {
                        if (dataset.WcsImage is FitsImage)
                        {
                            SetTexture(dataset.WcsImage.GetBitmap());
                            ReadyToRender = true;
                        }
                    }

                    if (TextureReady)
                    {
                        paintColor = Color.White;
                        if (dataset.WcsImage != null)
                        {
                            paintColor = dataset.WcsImage.Color;
                            blend      = !dataset.WcsImage.ColorCombine;
                        }


                        if (string.IsNullOrEmpty(FileName))
                        {
                            texture       = Texture11.FromBitmap(RenderContext11.PrepDevice, Image);
                            ReadyToRender = true;
                        }
                        else
                        {
                            try
                            {
                                texture       = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                ReadyToRender = true;


                                ReadyToRender = true;
                                if (Width == 0 && Height == 0)
                                {
                                    Width  = texture.Width;
                                    Height = texture.Height;
                                    if (dataset.WcsImage != null)
                                    {
                                        if (dataset.WcsImage.SizeX != 0)
                                        {
                                            Width = dataset.WcsImage.SizeX;
                                        }
                                        if (dataset.WcsImage.SizeY != 0)
                                        {
                                            Height = dataset.WcsImage.SizeY;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                                try
                                {
                                    //texture = Texture.FromBitmap(prepDevice, bmp, Usage.AutoGenerateMipMap, Tile.PoolToUse);

                                    texture       = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                    ReadyToRender = true;
                                    Width         = texture.Width;
                                    Height        = texture.Height;
                                    if (dataset.WcsImage.SizeX != 0)
                                    {
                                        Width = dataset.WcsImage.SizeX;
                                    }
                                    if (dataset.WcsImage.SizeY != 0)
                                    {
                                        Height = dataset.WcsImage.SizeY;
                                    }
                                }
                                catch
                                {
                                    errored = true;
                                }
                            }
                        }
                    }
                }
            }

            if (vertexBuffer == null)
            {
                GetParameters();
                vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), 4, RenderContext11.PrepDevice);
                indexBuffer  = new IndexBuffer11(typeof(short), 6, RenderContext11.PrepDevice);
                this.OnCreateVertexBuffer(vertexBuffer);
            }



            return(true);
        }
        protected override void setupShader(RenderContext11 renderContext, Texture11 texture, float opacity)
        {
            var mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mvp.Transpose();

            var aspectRatio = renderContext.ViewPort.Width / renderContext.ViewPort.Height;

            var color = new Color4(TintColor.Red, TintColor.Green, TintColor.Blue, TintColor.Alpha * opacity);

            // Set up the shader
            if (renderStrategy == RenderStrategy.GeometryShader)
            {
                PointSpriteShader11.WVPMatrix = mvp;
                PointSpriteShader11.Color = color;
                PointSpriteShader11.ViewportScale = new Vector2(1.0f, aspectRatio) * 0.001f;
                PointSpriteShader11.MinPointSize = MinPointSize;
                PointSpriteShader11.PointScaleFactors = PointScaleFactors;
                PointSpriteShader11.Use(renderContext.Device.ImmediateContext);

            }
            else
            {
                CompatibilityPointSpriteShader.WVPMatrix = mvp;
                CompatibilityPointSpriteShader.Color = color;
                CompatibilityPointSpriteShader.ViewportScale = new Vector2(1.0f, aspectRatio) * 0.001f;
                CompatibilityPointSpriteShader.PointScaleFactors = PointScaleFactors;
                CompatibilityPointSpriteShader.MinPointSize = MinPointSize;
                var useInstancing = renderStrategy == RenderStrategy.Instanced;
                CompatibilityPointSpriteShader.Use(renderContext.Device.ImmediateContext, useInstancing);
            }

            // Set shader resources
            renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, texture == null ? null : texture.ResourceView);
        }
        public static void Draw2D(RenderContext11 renderContext, Texture11 srcTexture, SizeF size, PointF rotationCenter, float rotationAngle, PointF position, System.Drawing.Color color)
        {
            cornerPoints[0].Position = MakePosition(position.X, position.Y, -size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
            cornerPoints[0].Tu = 0;
            cornerPoints[0].Tv = 0;
            cornerPoints[0].Color = color;

            cornerPoints[1].Position = MakePosition(position.X, position.Y, size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
            cornerPoints[1].Tu = 1;
            cornerPoints[1].Tv = 0;
            cornerPoints[1].Color = color;

            cornerPoints[2].Position = MakePosition(position.X, position.Y, -size.Width / 2, size.Height / 2, rotationAngle).Vector4;
            cornerPoints[2].Tu = 0;
            cornerPoints[2].Tv = 1;
            cornerPoints[2].Color = color;

            cornerPoints[3].Position = MakePosition(position.X, position.Y, size.Width / 2, size.Height / 2, rotationAngle).Vector4;
            cornerPoints[3].Tu = 1;
            cornerPoints[3].Tv = 1;
            cornerPoints[3].Color = color;

            renderContext.setRasterizerState(TriangleCullMode.Off);
            renderContext.DepthStencilMode = DepthStencilMode.Off;
            DrawForScreen(renderContext, cornerPoints, 4, srcTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
        }
        public void Draw(RenderContext11 renderContext, int count, Texture11 texture, float opacity, IndexBuffer11 indexBufferIn)
        {
            setupShader(renderContext, texture, opacity);

            count = Math.Min(this.count, count);

            switch (renderStrategy)
            {
                case RenderStrategy.GeometryShader:
                    renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
                    renderContext.SetVertexBuffer(0, vertexBuffer);
                    renderContext.SetIndexBuffer(indexBufferIn);
                    renderContext.devContext.DrawIndexed(count, 0, 0);
                    renderContext.Device.ImmediateContext.GeometryShader.Set(null);
                    break;

            }
        }
        private void CalcOrMake(bool makeTexture)
        {
            gridSize = 1;

            while ((gridSize * gridSize) < GlyphItems.Count)
            {
                gridSize *= 2;
            }

            int cellSize = 2;

            while (cellSize < cellHeight)
            {
                cellSize *= 2;
            }
            cellHeight = cellSize;

            int textureSize = cellHeight * gridSize;

            TextObject.Text = "";
            TextObject.FontSize = (float)cellHeight * .50f;

            System.Drawing.Font font = TextObject.Font;
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Near;

            Bitmap bmp;
            if (makeTexture)
            {
                bmp = new Bitmap(textureSize, textureSize);
            }
            else
            {
                bmp = new Bitmap(20, 20);
            }

            Graphics g = Graphics.FromImage(bmp);

            int count = 0;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            CharacterRange[] ranges = new CharacterRange[1];
            ranges[0] = new CharacterRange(0, 1);

            sf.SetMeasurableCharacterRanges(ranges);

            foreach (GlyphItem item in GlyphItems.Values)
            {
                int x = (int)(count % gridSize) * cellHeight;
                int y = (int)(count / gridSize) * cellHeight;
                string text = new string(item.Glyph, 1);
                item.Size = g.MeasureString(text, font);
                Region[] reg = g.MeasureCharacterRanges(text, font, new RectangleF(new PointF(0, 0), item.Size), sf);
                RectangleF rectf = reg[0].GetBounds(g);
                item.Extents = new SizeF(rectf.Width, rectf.Height);

                if (item.Extents.Width == 0)
                {
                    item.Extents = item.Size;
                }

                float div = textureSize;
                item.UVRect = new RectangleF(x / div, y / div, item.Size.Width / div, item.Size.Height / div);
                item.UVRect = new RectangleF((x + rectf.X) / div, (y + rectf.Y) / div, rectf.Width / div, rectf.Height / div);
                if (makeTexture)
                {
                    g.DrawString(text, font, Brushes.White, x, y, sf);
                }
                count++;
            }

            g.Dispose();
            GC.SuppressFinalize(g);
            if (makeTexture)
            {
                if (texture != null)
                {
                    texture.Dispose();
                    GC.SuppressFinalize(texture);
                    texture = null;
                }
                texture = Texture11.FromBitmap(RenderContext11.PrepDevice, bmp);
                textureDirty = false;
             }
            else
            {
                textureDirty = true;
            }
            bmp.Dispose();
            GC.SuppressFinalize(bmp);
            dirty = false;
        }
        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;
        }
        private void DrawSelectionHandles(RenderContext11 renderContext, Overlay overlay, Texture11 handleTexture)
        {
            var handles = MakeHandles(overlay);
            var angle = overlay.RotationAngle;

            var i = 0;
            var j = 0;
            foreach (var handle in handles)
            {
                points[i + 0].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 0].Tu = j * (1f / 9f);
                points[i + 0].Tv = 0;
                points[i + 0].Color = Color.White;

                points[i + 1].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 1].Tu = (j + 1) * (1f / 9f);
                points[i + 1].Tv = 0;
                points[i + 1].Color = Color.White;

                points[i + 2].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 2].Tu = j * (1f / 9f);
                points[i + 2].Tv = 1;
                points[i + 2].Color = Color.White;

                points[i + 3].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 3].Tu = (j + 1) * (1f / 9f);
                points[i + 3].Tv = 0;
                points[i + 3].Color = Color.White;

                points[i + 4].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 4].Tu = (j + 1) * (1f / 9f);
                points[i + 4].Tv = 1;
                points[i + 4].Color = Color.White;

                points[i + 5].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 5].Tu = j * (1f / 9f);
                points[i + 5].Tv = 1;
                points[i + 5].Color = Color.White;

                i += 6;
                j++;
            }

            if (MultiSelect)
            {
                Sprite2d.Draw(renderContext, points, points.Length - 6, handleTexture, PrimitiveTopology.TriangleList);
            }
            else
            {
                Sprite2d.Draw(renderContext, points, points.Length, handleTexture, PrimitiveTopology.TriangleList);
            }
        }
        public void Dispose()
        {
            if (texture != null)
            {
                texture.Dispose();
                GC.SuppressFinalize(texture);
                texture = null;
            }

            if (labelBuffer != null)
            {
                labelBuffer.Dispose();
                GC.SuppressFinalize(labelBuffer);
                labelBuffer = null;
            }
        }
        internal void Draw(RenderContext11 renderContext)
        {
            if (reticleImage == null)
            {
                reticleImage = Texture11.FromBitmap(Properties.Resources.Reticle);
            }

            ComputePoints();

            Sprite2d.Draw(renderContext, points, 4, reticleImage, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
        }
        public SkyLabel(RenderContext11 renderContext, Vector3d point, string text, LabelSytle style)
        {
            Text = text;
            Style = style;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Resources.circle, 0);
            }

            pos = point;

            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(80);

            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                var t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                // This will produce sky or orbit aligned text
                textBatch.Add(new Text3d(pos, new Vector3d(0,1,0), text, 20, .01));
            }
        }
 protected override void setupShader(RenderContext11 renderContext, Texture11 texture, float opacity)
 {
     // Let the caller handle the setup for now
 }
Exemple #51
0
        private void CalcOrMake(bool makeTexture)
        {
            gridSize = 1;

            while ((gridSize * gridSize) < GlyphItems.Count)
            {
                gridSize *= 2;
            }

            int cellSize = 2;

            while (cellSize < cellHeight)
            {
                cellSize *= 2;
            }
            cellHeight = cellSize;

            int textureSize = cellHeight * gridSize;

            TextObject.Text     = "";
            TextObject.FontSize = (float)cellHeight * .50f;


            System.Drawing.Font font = TextObject.Font;
            StringFormat        sf   = new StringFormat();

            sf.Alignment = StringAlignment.Near;

            Bitmap bmp;

            if (makeTexture)
            {
                bmp = new Bitmap(textureSize, textureSize);
            }
            else
            {
                bmp = new Bitmap(20, 20);
            }

            Graphics g = Graphics.FromImage(bmp);

            int count = 0;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;


            CharacterRange[] ranges = new CharacterRange[1];
            ranges[0] = new CharacterRange(0, 1);

            sf.SetMeasurableCharacterRanges(ranges);



            foreach (GlyphItem item in GlyphItems.Values)
            {
                int    x    = (int)(count % gridSize) * cellHeight;
                int    y    = (int)(count / gridSize) * cellHeight;
                string text = new string(item.Glyph, 1);
                item.Size = g.MeasureString(text, font);
                Region[]   reg   = g.MeasureCharacterRanges(text, font, new RectangleF(new PointF(0, 0), item.Size), sf);
                RectangleF rectf = reg[0].GetBounds(g);
                item.Extents = new SizeF(rectf.Width, rectf.Height);

                if (item.Extents.Width == 0)
                {
                    item.Extents = item.Size;
                }

                float div = textureSize;
                item.UVRect = new RectangleF(x / div, y / div, item.Size.Width / div, item.Size.Height / div);
                item.UVRect = new RectangleF((x + rectf.X) / div, (y + rectf.Y) / div, rectf.Width / div, rectf.Height / div);
                if (makeTexture)
                {
                    g.DrawString(text, font, Brushes.White, x, y, sf);
                }
                count++;
            }

            g.Dispose();
            GC.SuppressFinalize(g);
            if (makeTexture)
            {
                if (texture != null)
                {
                    texture.Dispose();
                    GC.SuppressFinalize(texture);
                    texture = null;
                }
                texture      = Texture11.FromBitmap(RenderContext11.PrepDevice, bmp);
                textureDirty = false;
            }
            else
            {
                textureDirty = true;
            }
            bmp.Dispose();
            GC.SuppressFinalize(bmp);
            dirty = false;
        }
Exemple #52
0
        public void DrawScreenOverlays(RenderContext11 renderContext)
        {
            foreach (KmlScreenOverlay overlay in ScreenOverlays)
            {
                Texture11 texture = overlay.Icon.Texture;

                if (texture != null)
                {
                    PointF center = new PointF();
                    PointF screen = new PointF();

                    SizeF size = new SizeF();

                    if (overlay.RotationSpot.UnitsX == KmlPixelUnits.Fraction)
                    {
                        center.X = overlay.RotationSpot.X * texture.Width;
                    }


                    if (overlay.RotationSpot.UnitsY == KmlPixelUnits.Fraction)
                    {
                        center.Y = overlay.RotationSpot.Y * texture.Height;
                    }

                    Rectangle clientRect = Earth3d.MainWindow.ClearClientArea;

                    Size clientSize = clientRect.Size;

                    if (overlay.ScreenSpot.UnitsX == KmlPixelUnits.Fraction)
                    {
                        screen.X = overlay.ScreenSpot.X * clientSize.Width;
                    }
                    else if (overlay.Size.UnitsX == KmlPixelUnits.Pixels)
                    {
                        screen.X = overlay.ScreenSpot.X;
                    }

                    if (overlay.ScreenSpot.UnitsY == KmlPixelUnits.Fraction)
                    {
                        screen.Y = overlay.ScreenSpot.Y * clientSize.Height;
                    }
                    else if (overlay.Size.UnitsY == KmlPixelUnits.Pixels)
                    {
                        screen.Y = overlay.ScreenSpot.Y;
                    }

                    if (overlay.Size.UnitsX == KmlPixelUnits.Fraction)
                    {
                        if (overlay.Size.X == -1)
                        {
                            size.Width = texture.Width;
                        }
                        else
                        {
                            size.Width = overlay.Size.X * clientSize.Width;
                        }
                    }
                    else if (overlay.Size.UnitsX == KmlPixelUnits.Pixels)
                    {
                        if (overlay.Size.X == -1)
                        {
                            size.Width = texture.Width;
                        }
                        else
                        {
                            size.Width = overlay.Size.X;
                        }
                    }

                    if (overlay.Size.UnitsY == KmlPixelUnits.Fraction)
                    {
                        size.Height = overlay.Size.Y * clientSize.Height;
                    }
                    else if (overlay.Size.UnitsY == KmlPixelUnits.Pixels)
                    {
                        if (overlay.Size.Y == -1)
                        {
                            size.Height = texture.Height;
                        }
                        else
                        {
                            size.Height = overlay.Size.Y;
                        }
                    }
                    screen.Y = clientRect.Bottom - screen.Y - size.Height + center.Y;
                    screen.X = clientRect.Left + screen.X + center.X;


                    Sprite2d.Draw2D(renderContext, texture, size, center, (float)overlay.Rotation, screen, overlay.color);
                    //sprite.Draw2D(texture, Rectangle.Empty, size, center, (float)overlay.Rotation, screen, Color.White);
                }
            }
        }
 public void CleanUp()
 {
     if (texture != null)
     {
         texture.Dispose();
     }
     dirty = true;
     texture = null;
 }
 protected abstract void setupShader(RenderContext11 renderContext, Texture11 texture, float opacity);
Exemple #55
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);
        }
        public static void ReturnTexture(Texture11 texture)
        {
            if (texture == null)
            {
                return;
            }
            texture.Dispose();
            GC.SuppressFinalize(texture);

            //todo11 reimplement pooling of textures
            //SurfaceDescription sd = texture.GetLevelDescription(0);

            //if (sd.Height != 256 || sd.Width != 256)
            //{
            //    texture.Dispose();
            //    GC.SuppressFinalize(texture);
            //}
            //else
            //{
            //BufferMutex.WaitOne();
            //    TexturePool256.Push(texture);
            //BufferMutex.ReleaseMutex();
            //}
        }
        public void Draw3D(RenderContext11 renderContext, float transparancy)
        {
            ratio = 1116f / Earth3d.MainWindow.RenderWindow.ClientRectangle.Height;

            if (SingleSelectHandles == null)
            {
                SingleSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, Resources.Selhand);
            }

            if (MultiSelectHandles == null)
            {
                MultiSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, Resources.MultiSelhand);
            }

            if (FocusHandles == null)
            {
                FocusHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, Resources.FocusHandles);
            }

            if (selectionSet.Count > 1)
            {
                foreach (var overlay in selectionSet)
                {
                    if (overlay == focus)
                    {

                        DrawSelectionHandles(renderContext, overlay, FocusHandles);
                    }
                    else
                    {

                        DrawSelectionHandles(renderContext, overlay, MultiSelectHandles);
                    }
                }
            }
            else
            {
                foreach (var overlay in selectionSet)
                {
                    DrawSelectionHandles(renderContext, overlay, SingleSelectHandles);
                }
            }
        }
Exemple #58
0
        private void DrawSelectionHandles(RenderContext11 renderContext, Overlay overlay, Texture11 handleTexture)
        {
            RectangleF[] handles = MakeHandles(overlay);
            float        angle   = overlay.RotationAngle;

            int i = 0;
            int j = 0;

            foreach (RectangleF handle in handles)
            {
                points[i + 0].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 0].Tu       = j * (1f / 9f);
                points[i + 0].Tv       = 0;
                points[i + 0].Color    = Color.White;


                points[i + 1].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 1].Tu       = (j + 1) * (1f / 9f);
                points[i + 1].Tv       = 0;
                points[i + 1].Color    = Color.White;

                points[i + 2].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 2].Tu       = j * (1f / 9f);
                points[i + 2].Tv       = 1;
                points[i + 2].Color    = Color.White;

                points[i + 3].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 3].Tu       = (j + 1) * (1f / 9f);
                points[i + 3].Tv       = 0;
                points[i + 3].Color    = Color.White;


                points[i + 4].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 4].Tu       = (j + 1) * (1f / 9f);
                points[i + 4].Tv       = 1;
                points[i + 4].Color    = Color.White;


                points[i + 5].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 5].Tu       = j * (1f / 9f);
                points[i + 5].Tv       = 1;
                points[i + 5].Color    = Color.White;

                i += 6;
                j++;
            }

            if (MultiSelect)
            {
                Sprite2d.Draw(renderContext, points, points.Length - 6, handleTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleList);
            }
            else
            {
                Sprite2d.Draw(renderContext, points, points.Length, handleTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleList);
            }
        }
 public virtual void CleanUp()
 {
     if (texture != null)
     {
         texture.Dispose();
         GC.SuppressFinalize(texture);
         texture = null;
     }
 }
Exemple #60
0
 public static Texture11 GetTexture(Stream stream)
 {
     return(Texture11.FromStream(RenderContext11.PrepDevice, stream));
 }