Ejemplo n.º 1
0
        public void OnEnable(PathResolver pathResolver)
        {
            _okIcon = new CachedTexture
                      (
                pathResolver.ResolvePath("noun_Ok_108699-32x32.png")
                      );

            _errorIcon = new CachedTexture
                         (
                pathResolver.ResolvePath("noun_Error_2190948-32x32.png")
                         );

            _okSummaryHeaderStyle    = new StyleCache(new SummaryHeaderStyle(StyleConstants.OKColor));
            _errorSummaryHeaderStyle = new StyleCache(new SummaryHeaderStyle(StyleConstants.ErrorColor));
        }
Ejemplo n.º 2
0
        public void OnEnable()
        {
            Logger.LogDebug($"Loading UI images from {ImagePathResolver.ProjectRelativeBasePath}");

            _analyseIcon = new CachedTexture
                           (
                ImagePathResolver.ResolvePath("noun_play_5206-32x32.png")
                           );

            _buddyIcon = new CachedTexture
                         (
                ImagePathResolver.ResolvePath("noun_Buddy_3361021-32x32.png")
                         );

            _summaryView.OnEnable(ImagePathResolver);

            titleContent = new GUIContent(Product.Name, _buddyIcon.Get);

            _errorsView = new ErrorListGUI();
        }
Ejemplo n.º 3
0
 public static CachedTexture GetTexture(string name, bool addUser = true)
 {
     if (CachedAssetsByName.ContainsKey(name))
     {
         var cach = CachedAssetsByName[name];
         if (addUser)
         {
             cach.users += 1;
         }
         return(cach as CachedTexture);
     }
     else
     {
         var reference = new RCOLFile(Environment.GetReference(name));
         var cachmat   = new CachedTexture(reference.dataBlocks[0] as TXTRDataBlock, name);
         if (addUser)
         {
             cachmat.users = 1;
         }
         CachedAssetsByName[name] = cachmat;
         return(cachmat);
     }
 }
Ejemplo n.º 4
0
        /**
         * Attempt to retrieve a new Texture2D asset preview.
         */
        public static Texture2D GetAssetPreview(Object o, int size = 128)
        {
            CachedTexture cached;

            if (cache.TryGetValue(o, out cached))
            {
                cached.lastAccessed = EditorApplication.timeSinceStartup;
                PurgeCache();
                return(cached.texture);
            }

            cached = new CachedTexture();
            cached.lastAccessed = EditorApplication.timeSinceStartup;

            // Unity crashes in this case
            if (o != null && o.GetInstanceID() != 0)
            {
                // cached.texture = AssetPreview.GetAssetPreview(o);

                if (cached.texture == null)
                {
                    Editor.CreateCachedEditor(o, null, ref cachedEditor);

                    if (cachedEditor != null)
                    {
                        cached.texture = cachedEditor.RenderStaticPreview(AssetDatabase.GetAssetPath(o.GetInstanceID()), null, size, size);
                    }
                }
            }

            PurgeCache();

            cache.Add(o, cached);

            return(cached.texture);
        }
Ejemplo n.º 5
0
        public override void Render(GraphicsPipeline gPipe)
        {
            // draw visible tree
            if (geomPlaneVerts != null)
            {
                gDevice.RenderState.Lighting = false;
                gDevice.SetTexture(0, null);

                ShaderInterface shader = gPipe.ShaderIf;

                foreach (GpuDemSubGeometry subGeom in geometryTree)
                {
                    //if (subGeom.Level != 2 || subGeom.Code == 60)
                    //    continue;
                    gPipe.Push();

                    shader.Effect.Technique = shader.Effect.GetTechnique("Basic");
                    shader.Effect.Begin(FX.None);
                    shader.Effect.BeginPass(0);

                    // draw main chunks - i.e. the middles
                    gDevice.Indices = geomPlaneIndices;
                    gDevice.SetStreamSource(0, geomPlaneVerts, 0);

                    gDevice.VertexFormat = CustomVertex.PositionTextured.Format;

                    gPipe.ShaderIf.Effect.SetValue("dem_level", subGeom.Level);
                    gPipe.ShaderIf.Effect.SetValue("DiffuseTexture", texturesCache[subGeom.Code].Heights);
                    gPipe.ShaderIf.Effect.SetValue("NormalMapTexture", texturesCache[subGeom.Code].Normals);

                    gPipe.WorldMatrix = Matrix.Scaling(new Vector3(subGeom.Dimensions.X, 1, subGeom.Dimensions.Y)) *
                                        Matrix.Translation(new Vector3(subGeom.Position.X, 0, subGeom.Position.Y)) *
                                        gPipe.WorldMatrix;

                    gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 14 * 14, 0, 13 * 13 * 2);

                    // draw any non-blending patches - i.e. fill the gaps
                    //gDevice.VertexFormat = PlaneHelper.PatchVertex.Format;
                    gDevice.VertexFormat = CustomVertex.PositionColoredTextured.Format;
                    gDevice.SetStreamSource(0, geomPatchVerts, 0);
                    gDevice.Indices = geomPatchIndices;

                    if (subGeom.SideCodes[3] == ulong.MaxValue)
                    {
                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, (16 * 4) /* + 2*/, 0, 16 * 2, 3 * 15 * 2, 15 * 2);
                    }
                    if (subGeom.SideCodes[2] == ulong.MaxValue)
                    {
                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, (16 * 6) /* + 2*/, 0, 16 * 2, 3 * 15 * 2, 15 * 2);
                    }
                    if (subGeom.SideCodes[0] == ulong.MaxValue)
                    {
                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, /*2*/ 0, 0, 16 * 2, 0, 15 * 2);
                    }
                    if (subGeom.SideCodes[1] == ulong.MaxValue)
                    {
                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, (16 * 2) /* + 2*/, 0, 16 * 2, 0, 15 * 2);
                    }

                    shader.Effect.EndPass();
                    shader.Effect.End();

                    // draw patches required
                    if (subGeom.SideCodes[3] != ulong.MaxValue)
                    {
                        CachedTexture tex = texturesCache[subGeom.SideCodes[3]];
                        gPipe.ShaderIf.Effect.SetValue("NextLevelHeightTexture", tex.Heights);
                        if (tex.Level == subGeom.Level)
                        {
                            shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Int");
                            shader.Effect.Begin(FX.None);
                            shader.Effect.BeginPass(0);
                        }
                        else
                        {
                            if (subGeom.ChildNum == 1)
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Inv");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0.5f);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                            else
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                        }
                        gPipe.ShaderIf.Effect.SetValue("NormalMapTexture", texturesCache[subGeom.Code].Normals);
                        gPipe.ShaderIf.Effect.SetValue("axis", 0);
                        gPipe.ShaderIf.Effect.CommitChanges();

                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, (16 * 4) + 2, 0, 16 * 2, 3 * 15 * 2, 13 * 2);

                        shader.Effect.EndPass();
                        shader.Effect.End();
                    }
                    if (subGeom.SideCodes[2] != ulong.MaxValue)
                    {
                        CachedTexture tex = texturesCache[subGeom.SideCodes[2]];
                        gPipe.ShaderIf.Effect.SetValue("NextLevelHeightTexture", tex.Heights);
                        if (tex.Level == subGeom.Level)
                        {
                            shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Int");
                            shader.Effect.Begin(FX.None);
                            shader.Effect.BeginPass(0);
                        }
                        else
                        {
                            if (subGeom.ChildNum == 3)
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Inv");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0.5f);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                            else
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                        }
                        gPipe.ShaderIf.Effect.SetValue("NormalMapTexture", texturesCache[subGeom.Code].Normals);
                        gPipe.ShaderIf.Effect.SetValue("axis", 0);
                        gPipe.ShaderIf.Effect.CommitChanges();

                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, (16 * 6) + 2, 0, 16 * 2, 3 * 15 * 2, 13 * 2);

                        shader.Effect.EndPass();
                        shader.Effect.End();
                    }
                    if (subGeom.SideCodes[0] != ulong.MaxValue)
                    {
                        CachedTexture tex = texturesCache[subGeom.SideCodes[0]];
                        gPipe.ShaderIf.Effect.SetValue("NextLevelHeightTexture", tex.Heights);
                        if (tex.Level == subGeom.Level)
                        {
                            shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Int");
                            shader.Effect.Begin(FX.None);
                            shader.Effect.BeginPass(0);
                        }
                        else
                        {
                            if (subGeom.ChildNum == 2)
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Inv");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0.5f);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                            else
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                        }
                        gPipe.ShaderIf.Effect.SetValue("NormalMapTexture", texturesCache[subGeom.Code].Normals);
                        gPipe.ShaderIf.Effect.SetValue("axis", 1);
                        gPipe.ShaderIf.Effect.CommitChanges();

                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 2, 0, 16 * 2, 0, 13 * 2);

                        shader.Effect.EndPass();
                        shader.Effect.End();
                    }
                    if (subGeom.SideCodes[1] != ulong.MaxValue)
                    {
                        CachedTexture tex = texturesCache[subGeom.SideCodes[1]];
                        gPipe.ShaderIf.Effect.SetValue("NextLevelHeightTexture", tex.Heights);
                        if (tex.Level == subGeom.Level)
                        {
                            shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Int");
                            shader.Effect.Begin(FX.None);
                            shader.Effect.BeginPass(0);
                        }
                        else
                        {
                            if (subGeom.ChildNum == 0)
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch_Inv");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0.5f);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                            else
                            {
                                shader.Effect.Technique = shader.Effect.GetTechnique("Basic_Patch");
                                shader.Effect.Begin(FX.None);
                                shader.Effect.BeginPass(0);

                                gPipe.ShaderIf.Effect.SetValue("shift", 0);
                                gPipe.ShaderIf.Effect.SetValue("scale", 0.5f);
                            }
                        }
                        gPipe.ShaderIf.Effect.SetValue("NormalMapTexture", texturesCache[subGeom.Code].Normals);
                        gPipe.ShaderIf.Effect.SetValue("axis", 1);
                        gPipe.ShaderIf.Effect.CommitChanges();

                        gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, (16 * 2) + 2, 0, 16 * 2, 0, 13 * 2);

                        shader.Effect.EndPass();
                        shader.Effect.End();
                    }

                    //TextureLoader.Save("c:/" + subGeom.Code + ".jpg", ImageFileFormat.Jpg, texturesCache[subGeom.Code].Tex);

                    gPipe.Pop();
                }
            }
        }
Ejemplo n.º 6
0
    public static int LoadFromMemoryEx(Image memoryImage, string name, long lColorKey, out Texture texture)
    {
      Log.Debug("TextureManagerEx: load from memory: {0}", name);

      string cacheName = name;
      string cacheKey = cacheName.ToLowerInvariant();

      texture = null;
      CachedTexture cached;
      if (_cacheTextures.TryGetValue(cacheKey, out cached))
      {
        return cached.Frames;
      }

      if (memoryImage == null)
      {
        return 0;
      }
      try
      {
        CachedTexture newCache = new CachedTexture();

        newCache.Name = cacheName;
        newCache.Frames = 1;

        //load gif into texture
        using (MemoryStream stream = new MemoryStream())
        {
          memoryImage.Save(stream, ImageFormat.Png);
          ImageInformation info2 = new ImageInformation();
          stream.Flush();
          stream.Seek(0, SeekOrigin.Begin);
          texture = TextureLoader.FromStream(
            GUIGraphicsContext.DX9Device,
            stream,
            0, 0, //width/height
            1, //mipslevels
            Usage.Dynamic, //Usage.Dynamic,
            Format.A8R8G8B8,
            Pool.Default,
            Filter.None,
            Filter.None,
            (int)lColorKey,
            ref info2);
          newCache.Width = info2.Width;
          newCache.Height = info2.Height;
          newCache.Texture = new TextureFrame(cacheName, texture, 0);
        }

        newCache.Disposed += new EventHandler(cachedTexture_Disposed);

        _cacheTextures[cacheKey] = newCache;

        Log.Debug("TextureManager: added: memoryImage  " + " total count: " + _cacheTextures.Count + ", mem left (MB): " +
                  ((uint)GUIGraphicsContext.DX9Device.AvailableTextureMemory / 1048576));
        return newCache.Frames;
      }
      catch (Exception ex)
      {
        Log.Error("TextureManager: exception loading texture memoryImage");
        Log.Error(ex);
      }
      return 0;
    }
Ejemplo n.º 7
0
    public static int Load(string fileNameOrg, long lColorKey, int iMaxWidth, int iMaxHeight, bool persistent)
    {
      string fileName = GetFileName(fileNameOrg);
      string cacheKey = fileName.ToLowerInvariant();
      if (String.IsNullOrEmpty(fileName))
      {
        return 0;
      }

      CachedTexture cached;
      if (_cacheTextures.TryGetValue(cacheKey, out cached))
      {
        return cached.Frames;
      }

      string extension = Path.GetExtension(fileName).ToLowerInvariant();
      if (extension == ".gif")
      {
        Image theImage = null;
        try
        {
          try
          {
            theImage = ImageFast.FromFile(fileName);
          }
          catch (FileNotFoundException)
          {
            Log.Warn("TextureManager: texture: {0} does not exist", fileName);
            return 0;
          }
          catch (Exception)
          {
            Log.Warn("TextureManager: Fast loading texture {0} failed using safer fallback", fileName);
            theImage = Image.FromFile(fileName);
          }
          if (theImage != null)
          {
            CachedTexture newCache = new CachedTexture();

            newCache.Name = fileName;
            FrameDimension oDimension = new FrameDimension(theImage.FrameDimensionsList[0]);
            newCache.Frames = theImage.GetFrameCount(oDimension);
            int[] frameDelay = new int[newCache.Frames];
            for (int num2 = 0; (num2 < newCache.Frames); ++num2)
            {
              frameDelay[num2] = 0;
            }

            // Getting Frame duration of an animated Gif image            
            try
            {
              int num1 = 20736;
              PropertyItem item1 = theImage.GetPropertyItem(num1);
              if (item1 != null)
              {
                byte[] buffer1 = item1.Value;
                for (int num2 = 0; (num2 < newCache.Frames); ++num2)
                {
                  frameDelay[num2] = (((buffer1[(num2 * 4)] + (256 * buffer1[((num2 * 4) + 1)])) +
                                       (65536 * buffer1[((num2 * 4) + 2)])) + (16777216 * buffer1[((num2 * 4) + 3)]));
                }
              }
            }
            catch (Exception) { }

            for (int i = 0; i < newCache.Frames; ++i)
            {
              theImage.SelectActiveFrame(oDimension, i);

              //load gif into texture
              using (MemoryStream stream = new MemoryStream())
              {
                theImage.Save(stream, ImageFormat.Png);
                ImageInformation info2 = new ImageInformation();
                stream.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                Texture texture = TextureLoader.FromStream(
                  GUIGraphicsContext.DX9Device,
                  stream,
                  0, 0, //width/height
                  1, //mipslevels
                  0, //Usage.Dynamic,
                  Format.A8R8G8B8,
                  GUIGraphicsContext.GetTexturePoolType(),
                  Filter.None,
                  Filter.None,
                  (int)lColorKey,
                  ref info2);
                newCache.Width = info2.Width;
                newCache.Height = info2.Height;
                newCache[i] = new TextureFrame(fileName, texture, (frameDelay[i] / 5) * 50);
              }
            }

            theImage.SafeDispose();
            theImage = null;
            newCache.Disposed += new EventHandler(cachedTexture_Disposed);
            if (persistent && !_persistentTextures.ContainsKey(cacheKey))
            {
              _persistentTextures[cacheKey] = true;
            }

            _cacheTextures[cacheKey] = newCache;

            //Log.Info("  TextureManager:added:" + fileName + " total:" + _cache.Count + " mem left:" + GUIGraphicsContext.DX9Device.AvailableTextureMemory.ToString());
            return newCache.Frames;
          }
        }
        catch (Exception ex)
        {
          Log.Error("TextureManager: exception loading texture {0}", fileName);
          Log.Error(ex);
        }
        return 0;
      }

      try
      {
        int width, height;

        if (MediaPortal.Util.Utils.FileExistsInCache(fileName))
        {
          Texture dxtexture = LoadGraphic(fileName, lColorKey, iMaxWidth, iMaxHeight, out width, out height);
          if (dxtexture != null)
          {
            CachedTexture newCache = new CachedTexture();
            newCache.Name = fileName;
            newCache.Frames = 1;
            newCache.Width = width;
            newCache.Height = height;
            newCache.Texture = new TextureFrame(fileName, dxtexture, 0);
            newCache.Disposed += new EventHandler(cachedTexture_Disposed);
            
            if (persistent && !_persistentTextures.ContainsKey(cacheKey))
            {
              _persistentTextures[cacheKey] = true;
            }

            _cacheTextures[cacheKey] = newCache;
            return 1;
          }
        }
      }
      catch (Exception)
      {
        return 0;
      }
      return 0;
    }
Ejemplo n.º 8
0
 CachedTexture MakeTextTexture(Text_ t)
 {
     CachedTexture ct = new CachedTexture();
     BitmapCi bmp = textColorRenderer.CreateTextTexture(t);
     ct.sizeX = platform.BitmapGetWidth(bmp);
     ct.sizeY = platform.BitmapGetHeight(bmp);
     ct.textureId = platform.LoadTextureFromBitmap(bmp);
     platform.BitmapDelete(bmp);
     return ct;
 }