Esempio n. 1
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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public static Texture11 GetTexture(string filename)
 {
     return(Texture11.FromFile(RenderContext11.PrepDevice, filename));
 }
Esempio n. 4
0
        public static void LoadTexture(object objEntry)
        {
            WmsCahceEntry entry = objEntry as WmsCahceEntry;

            entry.Requested = true;
            try
            {
                String dir = Properties.Settings.Default.CahceDirectory + "Data\\KmlCache\\";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                // This is a expanded timeout version of WebClient
                MyWebClient Client = new MyWebClient();


                string filename = dir + ((uint)entry.URL.GetHashCode32()).ToString() + ".png";


                Stream stream = null;

                if (Uri.IsWellFormedUriString(entry.URL, UriKind.Absolute))
                {
                    byte[] data = Client.DownloadData(entry.URL);
                    stream = new MemoryStream(data);
                }
                else
                {
                    stream = File.Open(entry.URL, FileMode.Open);
                }


                FileStream fileStream = File.OpenWrite(filename);
                byte[]     buffer     = new byte[32768];
                while (true)
                {
                    int read = stream.Read(buffer, 0, buffer.Length);
                    if (read <= 0)
                    {
                        break;
                    }
                    fileStream.Write(buffer, 0, read);
                }
                stream.Close();
                fileStream.Close();
                //todo this was loaded from the kmlicon API. Any Problems with that?
                entry.Texture = Texture11.FromFile(filename);

                entry.Loaded = true;
            }
            catch
            {
                entry.ErrorCount++;

                // retry until sucsess or MaxError Count exceeded
                if (entry.ErrorCount < MaxErrorCount)
                {
                    entry.Requested = false;
                    entry.Loaded    = false;
                }
                else
                {
                    entry.Loaded = true;
                }
            }
            finally
            {
                //    mut.ReleaseMutex();
            }
        }