Ejemplo n.º 1
0
        /// <summary>
        ///     Creates a pointer to a texture, which can be passed through ImGui calls such as <see cref="MediaTypeNames.Image" />.
        ///     That pointer is then used by ImGui to let us know what texture to draw
        /// </summary>
        public IntPtr BindTexture(Texture2D texture)
        {
            var id = new IntPtr(TextureId++);

            LoadedTextures.Add(id, texture);

            return(id);
        }
Ejemplo n.º 2
0
        public int LoadTexture(string name)
        {
            var textureResource = VrfGuiContext.LoadFileByAnyMeansNecessary(name + "_c");

            if (textureResource == null)
            {
                return(GetErrorTexture());
            }

            LoadedTextures.Add(name);

            return(LoadTexture(textureResource));
        }
        int GenerateMapTextureButton(string loadPath, string absolutePath, GameObject Prefab)
        {
            Texture2D LoadedTex;

            string RelativePath = "/" + absolutePath.Replace(MapLuaParser.LoadedMapFolderPath, MapLuaParser.RelativeLoadedMapFolderPath);

            //Debug.Log(RelativePath);

            try
            {
                LoadedTex = GetGamedataFile.LoadTexture2D(RelativePath, false, false);
            }
            catch (System.Exception e)
            {
                LoadedTex = new Texture2D(128, 128);
                Debug.LogWarning("Can't load DDS texture: " + e);
                return(0);
            }


            string TexPath = "";

            if (RelativePath.EndsWith(".dds"))
            {
                TexPath = RelativePath.Replace(".dds", "");
            }
            else if (RelativePath.EndsWith(".DDS"))
            {
                TexPath = RelativePath.Replace(".DDS", "");
            }


            GameObject NewButton = Instantiate(Prefab) as GameObject;

            NewButton.transform.SetParent(Pivot, false);
            NewButton.GetComponent <ResourceObject>().SetImages(LoadedTex);
            NewButton.GetComponent <ResourceObject>().InstanceId     = LoadedTextures.Count;
            NewButton.GetComponent <ResourceObject>().NameField.text = TexPath;
            LoadedTextures.Add(LoadedTex);
            LoadedPaths.Add(RelativePath);

            if (RelativePath.ToLower() == SelectedObject.ToLower())
            {
                LastSelection = NewButton.GetComponent <ResourceObject>().Selected;
                LastSelection.SetActive(true);
                Pivot.GetComponent <RectTransform>().anchoredPosition = Vector2.up * 250 * Mathf.FloorToInt(LoadedPaths.Count / 5f);
            }

            return(1);
        }
Ejemplo n.º 4
0
        public int LoadTexture(string name)
        {
            var textureResource = FileExtensions.LoadFileByAnyMeansNecessary(name + "_c", CurrentFileName, CurrentPackage);

            if (textureResource == null)
            {
                Console.Error.WriteLine("File " + name + " not found");

                return(GetErrorTexture());
            }

            LoadedTextures.Add(name);

            return(LoadTexture(textureResource));
        }
Ejemplo n.º 5
0
        private int LoadTexture(string name)
        {
            var textureResource = FileExtensions.LoadFileByAnyMeansNecessary(name + "_c", CurrentFileName, CurrentPackage);

            if (textureResource == null)
            {
                Console.Error.WriteLine("File " + name + " not found");

                return(GetErrorTexture());
            }

            LoadedTextures.Add(name);

            var tex = (Texture)textureResource.Blocks[BlockType.DATA];

            var id = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, id);

            var textureReader = textureResource.Reader;

            textureReader.BaseStream.Position = tex.Offset + tex.Size;

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, tex.NumMipLevels - 1);

            var width  = tex.Width / (int)Math.Pow(2.0, tex.NumMipLevels);
            var height = tex.Height / (int)Math.Pow(2.0, tex.NumMipLevels);

            int blockSize;
            PixelInternalFormat format;

            if (tex.Format.HasFlag(VTexFormat.DXT1))
            {
                blockSize = 8;
                format    = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
            }
            else if (tex.Format.HasFlag(VTexFormat.DXT5))
            {
                blockSize = 16;
                format    = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
            }
            else if (tex.Format.HasFlag(VTexFormat.RGBA8888))
            {
                //blockSize = 4;
                //format = PixelInternalFormat.Rgba8i;
                Console.Error.WriteLine("Don't support RGBA8888 but don't want to crash either. Using error texture!");
                return(GetErrorTexture());
            }
            else
            {
                throw new Exception("Unsupported texture format: " + tex.Format);
            }

            for (var i = tex.NumMipLevels - 1; i >= 0; i--)
            {
                if ((width *= 2) == 0)
                {
                    width = 1;
                }

                if ((height *= 2) == 0)
                {
                    height = 1;
                }

                var size = ((width + 3) / 4) * ((height + 3) / 4) * blockSize;

                GL.CompressedTexImage2D(TextureTarget.Texture2D, i, format, width, height, 0, size, textureReader.ReadBytes(size));
            }

            // Dispose texture otherwise we run out of memory
            // TODO: This might conflict when opening multiple files due to shit caching
            textureResource.Dispose();

            if (MaxTextureMaxAnisotropy > 0)
            {
                GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, MaxTextureMaxAnisotropy);
            }

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)(tex.Flags.HasFlag(VTexFlags.SUGGEST_CLAMPS) ? TextureWrapMode.Clamp : TextureWrapMode.Repeat));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)(tex.Flags.HasFlag(VTexFlags.SUGGEST_CLAMPT) ? TextureWrapMode.Clamp : TextureWrapMode.Repeat));

            return(id);
        }