示例#1
0
        public Texture2D( TextureNativeSectionData tex )
            : base(TextureTarget.Texture2D)
        {
            Width = tex.Width;
            Height = tex.Height;

            WrapModeU = FindWrapMode( tex.WrapU );
            WrapModeV = FindWrapMode( tex.WrapV );

            InternalFormat = FindInternalFormat( tex.Compression, tex.Format );
            ExternalFormat = FindExternalFormat( tex.Compression, tex.Format );

            Compressed = tex.Compression != TextureNativeSectionData.CompressionMode.None;
            Alpha = tex.Alpha;

            MinFilter = FindMinFilter( tex.FilterFlags );

            MipMapCount = 1; // tex.MipMapCount;
            ContainsMipMaps = ( tex.Format & TextureNativeSectionData.RasterFormat.ExtMipMap ) != 0;
            GenerateMipMaps = true; // ( tex.Format & TextureNativeSectionData.RasterFormat.ExtAutoMipMap ) != 0;

            ImageLevelSizes = new int[ MipMapCount ];
            for ( int i = 0; i < MipMapCount; ++i )
                ImageLevelSizes[ i ] = FindImageDataSize( Width >> i, Height >> i, tex.Compression, tex.Format );

            ImageLevelData = new byte[ MipMapCount ][];
            for ( int i = 0; i < MipMapCount; ++i )
                ImageLevelData[ i ] = tex.ImageLevelData[ i ];
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the Texture class. Generates and stores a bitmap in VRAM.
        /// </summary>
        /// <param name="bmp">The bitmap to be copied to VRAM.</param>
        /// <param name="minFilter">A filter applied when the rendered texture is smaller than the texture at 100%.</param>
        /// <param name="magFilter">A filter applied when the rendered texture is larger than the texture at 100%.</param>
        /// <param name="wrapS">The way OpenGL will handle texture coordinates larger than <c>1.0f</c> on the S axis (X axis).</param>
        /// <param name="wrapT">The way OpenGL will handle texture coordinates larger than <c>1.0f</c> on the T axis (Y axis).</param>
        public Texture(Bitmap bmp, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapS, TextureWrapMode wrapT)
        {
            this.Size = bmp.Size;

            //Generate a new texture ID
            ID = GL.GenTexture();

            //Texture parameters
            MinFilter = minFilter;
            MagFilter = magFilter;
            WrapS = wrapS;
            WrapT = wrapT;

            //Bind texture
            GL.BindTexture(TextureTarget.Texture2D, ID);

            //Send bitmap data up to VRAM
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            BitmapData bmpData = bmp.LockBits(new Rectangle(new Point(0, 0), Size), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Size.Width, Size.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0);
            bmp.UnlockBits(bmpData);

            //unbind texture
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
示例#3
0
        public VO64SimpleTexture(Bitmap texture, TextureWrapMode wrapS, TextureWrapMode wrapT)
        {
            Texture = texture;

            WrapS = wrapS;
            WrapT = wrapT;
        }
示例#4
0
 /// <summary>
 /// Sets the given wrap mode on all dimensions R, S and T.
 /// </summary>
 /// <param name="wrapMode">The wrap mode to apply.</param>
 public void SetWrapMode(TextureWrapMode wrapMode)
 {
     var mode = (int) wrapMode;
     SetParameter(SamplerParameterName.TextureWrapR, mode);
     SetParameter(SamplerParameterName.TextureWrapS, mode);
     SetParameter(SamplerParameterName.TextureWrapT, mode);
 }
示例#5
0
 private static void ApplyWrapMode(Texture2D lut2D, TextureWrapMode prevWrapMode)
 {
     TextureImporter importer = GetTextureImporter(lut2D);
     importer.wrapMode = prevWrapMode;
     AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(lut2D));
     AssetDatabase.Refresh();
 }
示例#6
0
        public VO64SimpleTexture(Bitmap texture)
        {
            Texture = texture;

            WrapS = TextureWrapMode.Repeat;
            WrapT = TextureWrapMode.Repeat;
        }
示例#7
0
    /// <summary>
    /// Get GIF texture list (This is a possibility of lock up)
    /// </summary>
    /// <param name="bytes">GIF file byte data</param>
    /// <param name="loopCount">out Animation loop count</param>
    /// <param name="width">out GIF image width (px)</param>
    /// <param name="height">out GIF image height (px)</param>
    /// <param name="filterMode">Textures filter mode</param>
    /// <param name="wrapMode">Textures wrap mode</param>
    /// <param name="debugLog">Debug Log Flag</param>
    /// <returns>GIF texture list</returns>
    public static List<GifTexture> GetTextureList (byte[] bytes, out int loopCount, out int width, out int height,
        FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, bool debugLog = false)
    {
        loopCount = -1;
        width = 0;
        height = 0;

        // Set GIF data
        var gifData = new GifData ();
        if (SetGifData (bytes, ref gifData, debugLog) == false) {
            Debug.LogError ("GIF file data set error.");
            return null;
        }

        // Decode to textures from GIF data
        var gifTexList = new List<GifTexture> ();
        if (DecodeTexture (gifData, gifTexList, filterMode, wrapMode) == false) {
            Debug.LogError ("GIF texture decode error.");
            return null;
        }

        loopCount = gifData.appEx.loopCount;
        width = gifData.logicalScreenWidth;
        height = gifData.logicalScreenHeight;
        return gifTexList;
    }
        public Texture(Bitmap bmp, int xTiles, int yTiles, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapS, TextureWrapMode wrapT)
        {
            this.bmp = bmp;
            this.xSize = bmp.Width;
            this.ySize = bmp.Height;
            this.xTiles = xTiles;
            this.yTiles = yTiles;
            if (xTiles == 0 || yTiles == 0)
            {
                this.xPixels = xSize;
                this.yPixels = ySize;
            }
            else
            {
                this.xPixels = xSize / xTiles;
                this.yPixels = ySize / yTiles;
            }

            this.minFilter = minFilter;
            this.magFilter = magFilter;
            this.wrapS = wrapS;
            this.wrapT = wrapT;

            offsetX = 1.0f / (float)(2 * xSize);
            offsetY = 1.0f / (float)(2 * ySize);

            Load();
        }
示例#9
0
		public Texture Find(string file, TextureMagFilter magFilter, TextureMinFilter minFilter, TextureWrapMode wrapModeS, TextureWrapMode wrapModeT)
		{
			try
			{
				string key = string.Format("{0}:{1}:{2}:{3}:{4}", file, magFilter, minFilter, wrapModeS, wrapModeT);
			
				Texture texture;
				if(textures.TryGetValue(key, out texture))return texture;

				TextureLoaderParameters.MagnificationFilter = magFilter;
				TextureLoaderParameters.MinificationFilter = minFilter;
				TextureLoaderParameters.WrapModeS = wrapModeS;
				TextureLoaderParameters.WrapModeT = wrapModeT;
				
				uint handle;
				TextureTarget dimension;
				ImageDDS.LoadFromDisk(file, out handle, out dimension);
				
				texture = new Texture(handle);
				
				textures[key]=texture;
				
				return texture;
			}
			catch
			{
				Console.WriteLine(string.Format("TextureManager: Failed to load texture {0}", file));
				return new Texture(0); // TODO remove
			}
		}
示例#10
0
		///<summary>
		/// Create new texture generator
		///</summary>
		///<param name="texture">Texture to use. It must be readable. The texture is read in constructor, so any later changes to it will not affect this generator</param>
		///<param name="wrapMode">Wrapping mode</param>
		public TexturePattern(Texture2D texture, TextureWrapMode wrapMode)
		{
			m_colors = texture.GetPixels();
			m_width = texture.width;
			m_height = texture.height;

			m_wrapMode = wrapMode;
		}
    /// <summary>
    /// Decode to textures from GIF data
    /// </summary>
    /// <param name="gifData">GIF data</param>
    /// <param name="gifTexList">GIF texture list</param>
    /// <param name="filterMode">Textures filter mode</param>
    /// <param name="wrapMode">Textures wrap mode</param>
    /// <returns>IEnumerator</returns>
    static IEnumerator DecodeTextureCoroutine(GifData gifData, List<GifTexture> gifTexList, FilterMode filterMode, TextureWrapMode wrapMode)
    {
        if (gifData.imageBlockList == null || gifData.imageBlockList.Count < 1) {
            yield break;
        }

        Color32? bgColor = GetGlobalBgColor (gifData);

        // Disposal Method
        // 0 (No disposal specified)
        // 1 (Do not dispose)
        // 2 (Restore to background color)
        // 3 (Restore to previous)
        ushort disposalMethod = 0;

        int imgBlockIndex = 0;
        foreach (var imgBlock in gifData.imageBlockList) {
            var decodedData = GetDecodedData (imgBlock);

            var colorTable = GetColorTable (gifData, imgBlock, ref bgColor);

            var graphicCtrlEx = GetGraphicCtrlExt (gifData, imgBlockIndex);

            int transparentIndex = GetTransparentIndex (graphicCtrlEx);

            // avoid lock up
            yield return 0;

            bool useBeforeTex = false;
            var tex = CreateTexture2D (gifData, gifTexList, imgBlockIndex, disposalMethod, filterMode, wrapMode, ref useBeforeTex);

            // Set pixel data
            int dataIndex = 0;
            // Reverse set pixels. because GIF data starts from the top left.
            for (int y = tex.height - 1; y >= 0; y--) {
                SetTexturePixelRow (tex, y, imgBlock, decodedData, ref dataIndex, colorTable, bgColor, transparentIndex, useBeforeTex);

                // avoid lock up
                //if (y % 10 == 0) {
                //    yield return 0;
                //}
            }
            tex.Apply ();

            float delaySec = GetDelaySec (graphicCtrlEx);

            // Add to GIF texture list
            gifTexList.Add (new GifTexture (tex, delaySec));

            disposalMethod = GetDisposalMethod (graphicCtrlEx);

            imgBlockIndex++;

            // avoid lock up
            yield return 0;
        }
    }
示例#12
0
 public RenderTexture Get(int width, int height, int depthBuffer = 0, RenderTextureFormat format = RenderTextureFormat.ARGBHalf, RenderTextureReadWrite rw = RenderTextureReadWrite.Default, FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, string name = "FactoryTempTexture")
 {
     var rt = RenderTexture.GetTemporary(width, height, depthBuffer, format);
     rt.filterMode = filterMode;
     rt.wrapMode = wrapMode;
     rt.name = name;
     m_TemporaryRTs.Add(rt);
     return rt;
 }
示例#13
0
        /// <summary>
        /// Creates a texture instance
        /// </summary>
        /// <param name="_Name"></param>
        /// <param name="_Width"></param>
        /// <param name="_Height"></param>
        /// <param name="_Format"></param>
        /// <param name="_bUseMipMaps">Create mip maps for the texture</param>
        /// <param name="_FilterMode">Filter mode to use to sample the texture</param>
        /// <param name="_WrapMode">Wrap mode to use to address the texture</param>
        /// <returns></returns>
        public NuajTexture2D( string _Name, int _Width, int _Height, TextureFormat _Format, bool _bUseMipMaps, FilterMode _FilterMode, TextureWrapMode _WrapMode )
        {
            Help.LogDebug( "Nuaj.Help.CreateTexture() \"" + _Name + "\" => " + _Width + "x" + _Height + "x" + _Format );
            if ( _Width < 1 || _Height < 1 )
                throw new Exception( "NuajTexture2D.ctor() => Invalid resolution !" );

            m_Texture = new Texture2D( _Width, _Height, _Format, _bUseMipMaps );
            m_Texture.name = _Name;
            m_Texture.filterMode = _FilterMode;
            m_Texture.wrapMode = _WrapMode;
            m_Texture.hideFlags = HideFlags.HideAndDontSave;
        }
 public static void CheckMaterialMode(Material aMat, TextureWrapMode aDesiredMode)
 {
     if (aMat != null && aMat.mainTexture != null && aMat.mainTexture.wrapMode != aDesiredMode) {
         if (EditorUtility.DisplayDialog("Ferr2D Terrain", "The Material's texture 'Wrap Mode' generally works best when set to "+aDesiredMode+"! Would you like this texture to be updated?", "Yes", "No")) {
             string          path = AssetDatabase.GetAssetPath(aMat.mainTexture);
             TextureImporter imp  = AssetImporter.GetAtPath   (path) as TextureImporter;
             if (imp != null) {
                 imp.wrapMode = aDesiredMode;
                 AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
             }
         }
     }
 }
示例#15
0
 /// <summary>
 /// Constructs a new TextureSlot.
 /// </summary>
 /// <param name="filePath">Texture filepath</param>
 /// <param name="typeSemantic">Texture type semantic</param>
 /// <param name="texIndex">Texture index in the material</param>
 /// <param name="mapping">Texture mapping</param>
 /// <param name="uvIndex">UV channel in mesh that corresponds to this texture</param>
 /// <param name="blendFactor">Blend factor</param>
 /// <param name="texOp">Texture operation</param>
 /// <param name="wrapMode">Texture wrap mode</param>
 /// <param name="flags">Misc flags</param>
 public TextureSlot(String filePath, TextureType typeSemantic, uint texIndex, TextureMapping mapping, uint uvIndex, float blendFactor,
     TextureOperation texOp, TextureWrapMode wrapMode, uint flags)
 {
     _filePath = (filePath == null) ? String.Empty : filePath;
         _type = typeSemantic;
         _index = texIndex;
         _mapping = mapping;
         _uvIndex = uvIndex;
         _blendFactor = blendFactor;
         _texOp = texOp;
         _wrapMode = wrapMode;
         _flags = flags;
 }
示例#16
0
 public MRT(int width, int height, RenderTextureFormat format = RenderTextureFormat.ARGBFloat, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat)
 {
     RTs = new RenderTexture[3];
     for(int i = 0, n = RTs.Length; i < n; i++) {
         int depth = (i == 0) ? 24 : 0;
         RTs[i] = new RenderTexture(width, height, depth);
         RTs[i].hideFlags = HideFlags.DontSave;
         RTs[i].format = format;
         RTs[i].filterMode = filterMode;
         RTs[i].wrapMode = wrapMode;
         RTs[i].Create();
     }
 }
示例#17
0
        private SamplerState(GraphicsDevice device, SamplerStateDescription samplerStateDescription) : base(device)
        {
            Description = samplerStateDescription;

            textureWrapS = samplerStateDescription.AddressU.ToOpenGL();
            textureWrapT = samplerStateDescription.AddressV.ToOpenGL();
            textureWrapR = samplerStateDescription.AddressW.ToOpenGL();
      
            compareFunc = samplerStateDescription.CompareFunction.ToOpenGLDepthFunction();
            borderColor = samplerStateDescription.BorderColor.ToArray();
            // TODO: How to do MipLinear vs MipPoint?
            switch (samplerStateDescription.Filter)
            {
                case TextureFilter.ComparisonMinMagLinearMipPoint:
                case TextureFilter.MinMagLinearMipPoint:
                    minFilter = TextureMinFilter.Linear;
                    magFilter = TextureMagFilter.Linear;
                    break;
                case TextureFilter.Anisotropic:
                case TextureFilter.Linear:
                    minFilter = TextureMinFilter.LinearMipmapLinear;
                    magFilter = TextureMagFilter.Linear;
                    break;
                case TextureFilter.MinPointMagMipLinear:
                case TextureFilter.ComparisonMinPointMagMipLinear:
                    minFilter = TextureMinFilter.NearestMipmapLinear;
                    magFilter = TextureMagFilter.Linear;
                    break;
                case TextureFilter.Point:
                    minFilter = TextureMinFilter.Nearest;
                    magFilter = TextureMagFilter.Nearest;
                    break;
                default:
                    throw new NotImplementedException();
            }

#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            // On OpenGL ES, we need to choose the appropriate min filter ourself if the texture doesn't contain mipmaps (done at PreDraw)
            minFilterNoMipmap = minFilter;
            if (minFilterNoMipmap == TextureMinFilter.LinearMipmapLinear)
                minFilterNoMipmap = TextureMinFilter.Linear;
            else if (minFilterNoMipmap == TextureMinFilter.NearestMipmapLinear)
                minFilterNoMipmap = TextureMinFilter.Nearest;
#endif
        }
示例#18
0
        public SamplerStateDesc(SamplerStateTypes type)
        {
            switch (type)
            {
                case SamplerStateTypes.Point_Wrap:
                    filterMin = TextureFilterMode.Nearest;
                    filterMinMiped = TextureFilterMode.Nearest;
                    filterMag = TextureFilterMode.Nearest;
                    addressU = TextureWrapMode.Repeat;
                    addressV = TextureWrapMode.Repeat;
                    addressW = TextureWrapMode.Repeat;
                    break;

                case SamplerStateTypes.Point_Clamp:
                    filterMin = TextureFilterMode.Nearest;
                    filterMinMiped = TextureFilterMode.Nearest;
                    filterMag = TextureFilterMode.Nearest;
                    addressU = TextureWrapMode.ClampToEdge;
                    addressV = TextureWrapMode.ClampToEdge;
                    addressW = TextureWrapMode.ClampToEdge;
                    break;

                case SamplerStateTypes.Linear_Wrap:
                    filterMin = TextureFilterMode.Linear;
                    filterMinMiped = TextureFilterMode.Linear;
                    filterMag = TextureFilterMode.Linear;
                    addressU = TextureWrapMode.Repeat;
                    addressV = TextureWrapMode.Repeat;
                    addressW = TextureWrapMode.Repeat;
                    break;

                case SamplerStateTypes.Linear_Clamp:
                    filterMin = TextureFilterMode.Linear;
                    filterMinMiped = TextureFilterMode.Linear;
                    filterMag = TextureFilterMode.Linear;
                    addressU = TextureWrapMode.ClampToEdge;
                    addressV = TextureWrapMode.ClampToEdge;
                    addressW = TextureWrapMode.ClampToEdge;
                    break;

                default:
                    Debug.ThrowError("SamplerStateDesc", "Unsuported SamplerStateType");
                    break;
            }
        }
	public TextureAtlasInfo()
	{
		anisoLevel = 1;
		compressTexturesInMemory = true;
		filterMode = FilterMode.Trilinear;
		ignoreAlpha = true;
		wrapMode = TextureWrapMode.Clamp;	
	
		shaderPropertiesToLookFor = new ShaderProperties[]
		{
			new ShaderProperties(false, "_MainTex"), 
			new ShaderProperties(true, "_BumpMap"), 
			new ShaderProperties(false, "_Cube"), 
			new ShaderProperties(false, "_DecalTex"), 
			new ShaderProperties(false, "_Detail"), 
			new ShaderProperties(false, "_ParallaxMap")
		};
	}
示例#20
0
 private void ConvertTextureWrapSettings(TextureWrapMode mode,
     out F3DEX_G_SetTile.TextureMirrorSetting mirror, out F3DEX_G_SetTile.TextureWrapSetting wrap)
 {
     if (mode == TextureWrapMode.MirroredRepeat)
     {
         mirror = F3DEX_G_SetTile.TextureMirrorSetting.G_TX_MIRROR;
         wrap = F3DEX_G_SetTile.TextureWrapSetting.G_TX_WRAP;
     }
     else if (mode == TextureWrapMode.Repeat)
     {
         mirror = F3DEX_G_SetTile.TextureMirrorSetting.G_TX_NOMIRROR;
         wrap = F3DEX_G_SetTile.TextureWrapSetting.G_TX_WRAP;
     }
     else
     {
         mirror = F3DEX_G_SetTile.TextureMirrorSetting.G_TX_NOMIRROR;
         wrap = F3DEX_G_SetTile.TextureWrapSetting.G_TX_CLAMP;
     }
 }
示例#21
0
文件: UniGif.cs 项目: ifnt/UniGif
    /// <summary>
    /// Get GIF texture list Coroutine (Avoid lock up but more slow)
    /// </summary>
    /// <param name="mb">MonoBehaviour to start the coroutine</param>
    /// <param name="bytes">GIF file byte data</param>
    /// <param name="cb">Callback method(param is GIF texture list, Animation loop count, GIF image width (px), GIF image height (px))</param>
    /// <param name="filterMode">Textures filter mode</param>
    /// <param name="wrapMode">Textures wrap mode</param>
    /// <param name="debugLog">Debug Log Flag</param>
    /// <returns>IEnumerator</returns>
    public static IEnumerator GetTextureListCoroutine (MonoBehaviour mb, byte[] bytes, Action<List<GifTexture>, int, int, int> cb,
        FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, bool debugLog = false)
    {
        int loopCount = -1;
        int width = 0;
        int height = 0;

        // Set GIF data
        var gifData = new GifData ();
        if (SetGifData (bytes, ref gifData, debugLog) == false) {
            Debug.LogError ("GIF file data set error.");
            if (cb != null) {
                cb (null, loopCount, width, height);
            }
            yield break;
        }

        // avoid lock up
        yield return 0;

        // Decode to textures from GIF data
        List<GifTexture> gifTexList = null;
        yield return mb.StartCoroutine (UniGif.DecodeTextureCoroutine (gifData, gtList => {
            gifTexList = gtList;
        }, filterMode, wrapMode));

        if (gifTexList == null) {
            Debug.LogError ("GIF texture decode error.");
            if (cb != null) {
                cb (null, loopCount, width, height);
            }
            yield break;
        }

        loopCount = gifData.appEx.loopCount;
        width = gifData.logicalScreenWidth;
        height = gifData.logicalScreenHeight;

        if (cb != null) {
            cb (gifTexList, loopCount, width, height);
        }
    }
示例#22
0
 public Texture(Bitmap bitmap, TextureMagFilter minMagFilter = TextureMagFilter.Linear,
                               TextureWrapMode wrapMode = TextureWrapMode.ClampToEdge)
 {
     GL.GenTextures(1, out _object);
     GL.BindTexture(TextureTarget.Texture2D, _object);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)minMagFilter);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)minMagFilter);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)wrapMode);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)wrapMode);
     GL.TexImage2D(TextureTarget.Texture2D,
                   0,
                   TextureFormatForBitmapFormat(bitmap.Format),
                   (int)bitmap.Width,
                   (int)bitmap.Height,
                   0,
                   PixelFormatForBitmap(bitmap.Format),
                   PixelType.UnsignedByte,
                   bitmap.PixelBuffer);
     GL.BindTexture(TextureTarget.Texture2D, 0);
     bitmap.Unlock();
 }
示例#23
0
        public Texture(Bitmap bitmap, TextureMinFilter minFilter = TextureMinFilter.Linear, TextureMagFilter magFilter = TextureMagFilter.Nearest, TextureWrapMode wrapS = TextureWrapMode.ClampToBorderSgis, TextureWrapMode wrapT = TextureWrapMode.ClampToBorderSgis)
        {
            int textureID;
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

            GL.GenTextures(1, out textureID);
            GL.BindTexture(TextureTarget.Texture2D, textureID);
            GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D);
            BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            bitmap.UnlockBits(data);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)minFilter);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)magFilter);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)wrapS);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)wrapT);

            GL.BindTexture(TextureTarget.Texture2D, 0);

            this.textureID = textureID;
            Width = bitmap.Width;
            Height = bitmap.Height;
        }
示例#24
0
	void OnGUI()
	{
		Object	tarPath		= EditorGUILayout.ObjectField	("AutoTarget", null, typeof(Object), false, GUILayout.MaxWidth(Screen.width));
		m_assetPath			= EditorGUILayout.TextField		("AssetPath", m_assetPath, GUILayout.MaxWidth(Screen.width));
		m_bRecursively		= EditorGUILayout.Toggle		("Recursively", m_bRecursively, GUILayout.MaxWidth(Screen.width));

		EnableSet(ref m_bSetGUI, "SetGUI");
		m_bGUI				= EditorGUILayout.Toggle("GUITexture", m_bGUI, GUILayout.MaxWidth(Screen.width));

		EnableSet(ref m_bSetFilterMode, "SetFilterMode");
		m_filterMode		= (FilterMode)EditorGUILayout.EnumPopup("filterMode", m_filterMode, GUILayout.MaxWidth(Screen.width));

		if (m_bSetGUI == false || m_bGUI == false)
		{
			EnableSet(ref m_bSetWrapMode, "SetWrapMode");
			m_wrapMode		= (TextureWrapMode)EditorGUILayout.EnumPopup("wrapMode", m_wrapMode, GUILayout.MaxWidth(Screen.width));
			EnableSet(ref m_bSetAnisoLevel, "SetAnisoLevel");
			m_anisoLevel	= EditorGUILayout.IntSlider("anisoLevel", m_anisoLevel, 0, 9, GUILayout.MaxWidth(Screen.width));
		}

		EnableSet(ref m_bSetMaxTextureSizeIdx, "SetMaxTextureSizeIdx");
		m_maxTextureSizeIdx	= EditorGUILayout.Popup("maxTextureSize", m_maxTextureSizeIdx, textureSizeStr, GUILayout.MaxWidth(Screen.width));

		EnableSet(ref m_bSetTextureFormatIdx, "SetTextureFormatIdx");
		m_textureFormatIdx	= EditorGUILayout.Popup("textureFormat", m_textureFormatIdx, textureFormatStr, GUILayout.MaxWidth(Screen.width));
		GUI.enabled	= true;

		if (tarPath != null)
		{
			string path = AssetDatabase.GetAssetPath(tarPath);
			path = path.Replace("Assets/", "");
			m_assetPath = path.Replace(Path.GetFileName(path), "");
		}

		EditorGUILayout.Space();
		FXMakerLayout.GUIEnableBackup((m_assetPath.Trim() != ""));
		if (GUILayout.Button("Start Reimport", GUILayout.Height(40)))
			ReimportTextures(m_assetPath, m_bRecursively, m_wrapMode, m_filterMode, m_anisoLevel, System.Convert.ToInt32(textureSizeStr[m_maxTextureSizeIdx]), textureFormatVal[m_textureFormatIdx]);
		FXMakerLayout.GUIEnableRestore();
	}
示例#25
0
        public static Texture LoadTexture(string filename, System.Drawing.Bitmap bitmap, TextureMinFilter textureMinFilter, TextureWrapMode textureWrapS, TextureWrapMode textureWrapT)
        {
            Texture output = new Texture();

            if (!filename.Contains("::") && !File.Exists(filename))
            {
                return(output);
            }
            for (int i = 0; i < Textures.Count; i++)
            {
                if (Textures[i].Filename.Length == filename.Length &&
                    Textures[i].Filename == filename)
                {
                    return(Textures[i]);
                }
            }

            output          = new Texture();
            output.Filename = filename;

            System.Drawing.Bitmap bmp = bitmap == null ? (System.Drawing.Bitmap)System.Drawing.Image.FromFile(filename) : bitmap;

            int depth = System.Drawing.Bitmap.GetPixelFormatSize(bmp.PixelFormat);

            if (depth != 32)
            {
                bmp = bmp.Clone(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            textureID++;
            output.Integer = textureID;
            GL.GenTextures(1, out textureID);
            GL.BindTexture(TextureTarget.Texture2D, textureID);

            System.Drawing.Imaging.BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);


            PixelInternalFormat format = PixelInternalFormat.Rgba;


            if (CountAlphaPixels)
            {
                byte[] pixelBytes = new byte[bmp.Width * bmp.Height * 4];
                Marshal.Copy(data.Scan0, pixelBytes, 0, pixelBytes.Length);
                AlphaPercentage = 0;
                for (int i = 0; i < pixelBytes.Length; i += 4)
                {
                    AlphaPercentage += pixelBytes[i + 3];
                }
                AlphaPercentage /= (ulong)(bmp.Width * bmp.Height);
            }
            GL.TexImage2D(TextureTarget.Texture2D, 0, format, bmp.Width, bmp.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);


            bmp.UnlockBits(data);
            bmp.Dispose();

            output.TextureMinFilter = (int)textureMinFilter;
            output.TextureWrapS     = (int)textureWrapS;
            output.TextureWrapT     = (int)textureWrapT;

            Textures.Add(output);
            return(output);
        }
示例#26
0
        void OnGUI()
        {
            if (m_pathButtonStyle == null)
            {
                m_pathButtonStyle = "minibutton";
            }

            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, GUILayout.Height(position.height));
            float cachedWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;
            EditorGUILayout.BeginVertical(m_contentStyle);

            string buildButtonStr = m_tex3DMode ? BuildTexture3DMessage : BuildArrayMessage;

            // build button
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(m_allTextures.Count <= 0);
            if (GUILayout.Button(buildButtonStr, "prebutton", GUILayout.Height(20)))
            {
                bool showWarning = false;
                for (int i = 0; i < m_allTextures.Count; i++)
                {
                    if (m_allTextures[i].width != m_sizes[m_selectedSizeX] || m_allTextures[i].height != m_sizes[m_selectedSizeY])
                    {
                        showWarning = true;
                    }
                }

                if (!showWarning)
                {
                    m_message = string.Empty;
                    if (m_tex3DMode)
                    {
                        BuildTexture3D();
                    }
                    else
                    {
                        BuildArray();
                    }
                }
                else if (EditorUtility.DisplayDialog("Warning!", "Some textures need to be resized to fit the selected size. Do you want to continue?", "Yes", "No"))
                {
                    m_message = string.Empty;
                    if (m_tex3DMode)
                    {
                        BuildTexture3D();
                    }
                    else
                    {
                        BuildArray();
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(m_lastSaved == null);
            GUIContent icon = EditorGUIUtility.IconContent("icons/d_ViewToolZoom.png");

            if (GUILayout.Button(icon, "prebutton", GUILayout.Width(28), GUILayout.Height(20)))
            {
                EditorGUIUtility.PingObject(m_lastSaved);
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            // message
            if (!string.IsNullOrEmpty(m_message))
            {
                if (GUILayout.Button("BUILD REPORT (click to hide):\n\n" + m_message, "helpbox"))
                {
                    m_message = string.Empty;
                }
            }

            // options
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Size");
            EditorGUIUtility.labelWidth = 16;
            m_selectedSizeX             = EditorGUILayout.Popup("X", m_selectedSizeX, m_sizesStr);
            EditorGUI.BeginDisabledGroup(m_lockRatio);
            m_selectedSizeY = EditorGUILayout.Popup("Y", m_lockRatio ? m_selectedSizeX : m_selectedSizeY, m_sizesStr);
            EditorGUI.EndDisabledGroup();
            EditorGUIUtility.labelWidth = 100;
            m_lockRatio = GUILayout.Toggle(m_lockRatio, "L", "minibutton", GUILayout.Width(18));
            EditorGUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();
            m_tex3DMode = EditorGUILayout.Toggle("Texture 3D", m_tex3DMode);
            if (EditorGUI.EndChangeCheck())
            {
                if (!m_filenameChanged)
                {
                    m_fileName = m_tex3DMode ? Texture3DFilename:ArrayFilename;
                }
            }

            m_linearMode = EditorGUILayout.Toggle("Linear", m_linearMode);
            m_mipMaps    = EditorGUILayout.Toggle("Mip Maps", m_mipMaps);
            m_wrapMode   = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", m_wrapMode);
            m_filterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", m_filterMode);
            m_anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_anisoLevel, 0, 16);

            m_selectedFormatEnum = (TextureFormat)EditorGUILayout.EnumPopup("Format", m_selectedFormatEnum);
            if (m_selectedFormatEnum == TextureFormat.DXT1Crunched)
            {
                m_selectedFormatEnum = TextureFormat.DXT1;
                Debug.Log("Texture Array does not support crunched DXT1 format. Changing to DXT1...");
            }
            else if (m_selectedFormatEnum == TextureFormat.DXT5Crunched)
            {
                m_selectedFormatEnum = TextureFormat.DXT5;
                Debug.Log("Texture Array does not support crunched DXT5 format. Changing to DXT5...");
            }

            m_quality = EditorGUILayout.IntSlider("Format Quality", m_quality, 0, 100);
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Path and Name");
            EditorGUILayout.BeginHorizontal();
            m_pathButtonContent.text = m_folderPath;
            Vector2 buttonSize = m_pathButtonStyle.CalcSize(m_pathButtonContent);

            if (GUILayout.Button(m_pathButtonContent, m_pathButtonStyle, GUILayout.MaxWidth(Mathf.Min(position.width * 0.5f, buttonSize.x))))
            {
                string folderpath = EditorUtility.OpenFolderPanel("Save Texture Array to folder", "Assets/", "");
                folderpath = FileUtil.GetProjectRelativePath(folderpath);
                if (string.IsNullOrEmpty(folderpath))
                {
                    m_folderPath = "Assets/";
                }
                else
                {
                    m_folderPath = folderpath + "/";
                }
            }
            EditorGUI.BeginChangeCheck();
            m_fileName = EditorGUILayout.TextField(m_fileName, GUILayout.ExpandWidth(true));
            if (EditorGUI.EndChangeCheck())
            {
                m_filenameChanged = true;
            }
            EditorGUILayout.LabelField(".asset", GUILayout.MaxWidth(40));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            // list
            EditorGUILayout.Separator();
            if (GUILayout.Button(ClearButtonStr))
            {
                m_allTextures.Clear();
            }

            if (m_listTextures != null)
            {
                m_listTextures.DoLayoutList();
            }

            GUILayout.Space(20);
            EditorGUILayout.EndVertical();
            EditorGUIUtility.labelWidth = cachedWidth;
            EditorGUILayout.EndScrollView();
            m_draggableArea.size = position.size;
            m_dragAndDropTool.TestDragAndDrop(m_draggableArea);
        }
示例#27
0
        public static void GetSamplerParameteri(uint sampler, SamplerParameterName pname, out TextureWrapMode param)
        {
            int p;

            _GetSamplerParameteri(sampler, pname, out p);
            param = (TextureWrapMode)p;
        }
示例#28
0
        private static Texture2D ProccessTextureData(Texture2D tempTexture2D, string name, ref bool checkAlphaChannel, TextureWrapMode textureWrapMode, string finalPath, TextureCompression textureCompression, bool isNormalMap)
        {
            if (tempTexture2D == null)
            {
                return(null);
            }
            tempTexture2D.name     = name;
            tempTexture2D.wrapMode = textureWrapMode;
            var       colors = tempTexture2D.GetPixels32();
            Texture2D finalTexture2D;

            if (isNormalMap)
            {
#if UNITY_5
                finalTexture2D = new Texture2D(tempTexture2D.width, tempTexture2D.height, TextureFormat.ARGB32, true);
                for (var i = 0; i < colors.Length; i++)
                {
                    var color = colors[i];
                    color.a   = color.r;
                    color.r   = 0;
                    color.b   = 0;
                    colors[i] = color;
                }
                finalTexture2D.SetPixels32(colors);
                finalTexture2D.Apply();
#else
                finalTexture2D            = Object.Instantiate(AssetLoaderBase.NormalBaseTexture);
                finalTexture2D.filterMode = tempTexture2D.filterMode;
                finalTexture2D.wrapMode   = tempTexture2D.wrapMode;
                finalTexture2D.Resize(tempTexture2D.width, tempTexture2D.height);
                finalTexture2D.SetPixels32(colors);
                finalTexture2D.Apply();
#endif
            }
            else
            {
                finalTexture2D = new Texture2D(tempTexture2D.width, tempTexture2D.height, TextureFormat.ARGB32, true);
                finalTexture2D.SetPixels32(colors);
                finalTexture2D.Apply();
                if (textureCompression != TextureCompression.None)
                {
                    tempTexture2D.Compress(textureCompression == TextureCompression.HighQuality);
                }
            }
            if (checkAlphaChannel)
            {
                checkAlphaChannel = false;
                foreach (var color in colors)
                {
                    if (color.a == 255)
                    {
                        continue;
                    }
                    checkAlphaChannel = true;
                    break;
                }
            }
            return(finalTexture2D);
        }
示例#29
0
 public VoxelTexture(int prefferedResolution, RenderTextureFormat format, FilterMode filter, TextureWrapMode wrap,
                     RenderTextureReadWrite gamma)
 {
     this.textureIsValid    = false;
     this.currentResolution = -1;
     this.format            = format;
     this.filter            = filter;
     this.wrap  = wrap;
     this.gamma = gamma;
     SetResolution(prefferedResolution, true);
 }
示例#30
0
 public abstract Texture2D Create(int width, int height, TextureWrapMode wrapMode = TextureWrapMode.Repeat);
示例#31
0
        public void DefineMaterial(int materialId, int textureId, TextureWrapMode wrapModeS, TextureWrapMode wrapModeT)
        {
            // TODO implement wrap mode - think it's not supported in MTL :(
            mtlStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "newmtl gxmat{0}", currentMaterialIdx));
            mtlStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "map_Kd {0}.png", textureId));
            mtlStream.WriteLine();

            materialIdToMtlMaterialIdx[materialId] = currentMaterialIdx;

            currentMaterialIdx++;
        }
示例#32
0
 public SamplerKey(Sampler sampler)
 {
     m_FilterMode = sampler.filterMode;
     m_WrapModeU  = sampler.wrapU;
     m_WrapModeV  = sampler.wrapV;
 }
示例#33
0
文件: Texture.cs 项目: KSLcom/duality
		/// <summary>
		/// Creates a new Texture based on a <see cref="Duality.Resources.Pixmap"/>.
		/// </summary>
		/// <param name="basePixmap">The <see cref="Duality.Resources.Pixmap"/> to use as source for pixel data.</param>
		/// <param name="sizeMode">Specifies behaviour in case the source data has non-power-of-two dimensions.</param>
		/// <param name="filterMag">The OpenGL filter mode for drawing the Texture bigger than it is.</param>
		/// <param name="filterMin">The OpenGL fitler mode for drawing the Texture smaller than it is.</param>
		/// <param name="wrapX">The OpenGL wrap mode on the texel x axis.</param>
		/// <param name="wrapY">The OpenGL wrap mode on the texel y axis.</param>
		/// <param name="format">The format in which OpenGL stores the pixel data.</param>
		public Texture(ContentRef<Pixmap> basePixmap, 
			SizeMode sizeMode			= SizeMode.Default, 
			TextureMagFilter filterMag	= TextureMagFilter.Linear, 
			TextureMinFilter filterMin	= TextureMinFilter.LinearMipmapLinear,
			TextureWrapMode wrapX		= TextureWrapMode.ClampToEdge,
			TextureWrapMode wrapY		= TextureWrapMode.ClampToEdge,
			PixelInternalFormat format	= PixelInternalFormat.Rgba)
		{
			this.filterMag = filterMag;
			this.filterMin = filterMin;
			this.wrapX = wrapX;
			this.wrapY = wrapY;
			this.pixelformat = format;
			this.LoadData(basePixmap, sizeMode);
		}
示例#34
0
        public Texture2D( int width, int height, byte[] data )
            : base(TextureTarget.Texture2D)
        {
            Width = width;
            Height = height;

            WrapModeU = TextureWrapMode.Repeat;
            WrapModeV = TextureWrapMode.Repeat;

            InternalFormat = PixelInternalFormat.Rgba;
            ExternalFormat = PixelFormat.Bgra;

            Compressed = false;
            Alpha = true;

            MinFilter = TextureMinFilter.Linear;

            MipMapCount = 1;
            ContainsMipMaps = false;
            GenerateMipMaps = false;

            ImageLevelSizes = new int[] { ( width * height ) << 2 };
            ImageLevelData = new byte[][] { data };
        }
示例#35
0
        public RenderTexture Get(int width, int height, int depthBuffer = 0, RenderTextureFormat format = RenderTextureFormat.ARGBHalf, RenderTextureReadWrite rw = RenderTextureReadWrite.Default, FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, string name = "FactoryTempTexture")
        {
            var rt = RenderTexture.GetTemporary(width, height, depthBuffer, format, rw); // add forgotten param rw

            rt.filterMode = filterMode;
            rt.wrapMode   = wrapMode;
            rt.name       = name;
            m_TemporaryRTs.Add(rt);
            return(rt);
        }
示例#36
0
 public static void SamplerParameteri(uint sampler, SamplerParameterName pname, TextureWrapMode param)
 {
     _SamplerParameteri(sampler, pname, (int)param);
 }
 public void SetTextureProperties(FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, int anisoLevel = 0)
 {
     _defaultTextureFilterMode = filterMode;
     _defaultTextureWrapMode   = wrapMode;
     _defaultTextureAnisoLevel = anisoLevel;
     ApplyTextureProperties(GetTexture());
 }
示例#38
0
        // Internal function
        RTHandle AllocAutoSizedRenderTexture(
            int width,
            int height,
            int slices,
            DepthBits depthBufferBits,
            GraphicsFormat colorFormat,
            FilterMode filterMode,
            TextureWrapMode wrapMode,
            TextureDimension dimension,
            bool enableRandomWrite,
            bool useMipMap,
            bool autoGenerateMips,
            bool isShadowMap,
            int anisoLevel,
            float mipMapBias,
            bool enableMSAA,
            bool bindTextureMS,
            bool useDynamicScale,
            bool xrInstancing,
            RenderTextureMemoryless memoryless,
            string name
            )
        {
            // Here user made a mistake in setting up msaa/bindMS, hence the warning
            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            bool allocForMSAA = m_ScaledRTSupportsMSAA ? enableMSAA : false;

            // Here we purposefully disable MSAA so we just force the bindMS param to false.
            if (!allocForMSAA)
            {
                bindTextureMS = false;
            }

            // MSAA Does not support random read/write.
            bool UAV = enableRandomWrite;

            if (allocForMSAA && (UAV == true))
            {
                Debug.LogWarning("RTHandle that is MSAA-enabled cannot allocate MSAA RT with 'enableRandomWrite = true'.");
                UAV = false;
            }

            int        msaaSamples = allocForMSAA ? (int)m_ScaledRTCurrentMSAASamples : 1;
            RTCategory category    = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

            // XR override for instancing support
            VRTextureUsage vrUsage = XRGraphics.OverrideRenderTexture(xrInstancing, ref dimension, ref slices);

            // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
            RenderTexture rt;

            if (isShadowMap || depthBufferBits != DepthBits.None)
            {
                RenderTextureFormat format = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
                rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = UAV,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    vrUsage           = vrUsage,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
                };
            }
            else
            {
                rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = UAV,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    vrUsage           = vrUsage,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
                };
            }

            rt.Create();

            var rth = new RTHandle(this);

            rth.SetRenderTexture(rt, category);
            rth.m_EnableMSAA           = enableMSAA;
            rth.m_EnableRandomWrite    = enableRandomWrite;
            rth.useScaling             = true;
            rth.m_EnableHWDynamicScale = useDynamicScale;
            rth.m_Name = name;
            m_AutoSizedRTs.Add(rth);
            return(rth);
        }
示例#39
0
 public static SpriteDrawingContext TextureWrapHorizontal(this SpriteDrawingContext context, TextureWrapMode mode, float left, float right)
 {
     context.TextureWrapU       = mode;
     context.TextureRegionLeft  = left;
     context.TextureRegionRight = right;
     return(context);
 }
示例#40
0
 public static SpriteDrawingContext TextureWrapVertical(this SpriteDrawingContext context, TextureWrapMode mode, float top, float bottom)
 {
     context.TextureWrapV        = mode;
     context.TextureRegionTop    = top;
     context.TextureRegionBottom = bottom;
     return(context);
 }
示例#41
0
 void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps)
 {
 }
    void OnGUI()
    {
        Undo.RecordObject(this, "lb");

        scrollPos = EditorGUILayout.BeginScrollView(scrollPos,
                                                    false,
                                                    false,
                                                    GUILayout.Width(Screen.width),
                                                    GUILayout.Height(Screen.height));

        EditorGUILayout.Space(); EditorGUILayout.Space();
        EditorGUILayout.Space(); EditorGUILayout.Space();

        importerType = (TexImporterType)EditorGUILayout.EnumPopup("Importer Mode", importerType, GUILayout.Width(343));
        if (GUILayout.Button("Batch Import"))
        {
            if (importerType == TexImporterType.AllTextures)
            {
                var files = Directory.GetFiles("Assets", "*.*", SearchOption.AllDirectories)
                            .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".psd") || s.EndsWith(".gif") ||
                                   s.EndsWith(".iff") || s.EndsWith(".tga") || s.EndsWith(".tiff") || s.EndsWith(".bmp") ||
                                   s.EndsWith(".pict"));

                foreach (string s in files)
                {
                    TextureImporter tImporter = AssetImporter.GetAtPath(s) as TextureImporter;
                    tImporter.maxTextureSize = textureSize;

                    if (comprissonMode == TextureCompressionType.None)
                    {
                        tImporter.textureCompression = TextureImporterCompression.Uncompressed;
                    }
                    if (comprissonMode == TextureCompressionType.LowQuality)
                    {
                        tImporter.textureCompression = TextureImporterCompression.CompressedLQ;
                    }
                    if (comprissonMode == TextureCompressionType.HighQuality)
                    {
                        tImporter.textureCompression = TextureImporterCompression.CompressedHQ;
                    }

                    if (advancedMode)
                    {
                        tImporter.textureType         = textureType;
                        tImporter.textureShape        = textureShape;
                        tImporter.sRGBTexture         = textureRGB;
                        tImporter.alphaSource         = textureAlphaSource;
                        tImporter.alphaIsTransparency = AlphaIsTransparent;
                        tImporter.isReadable          = ReadWriteEnabled;
                        tImporter.mipmapEnabled       = GenerateMipMaps;
                        tImporter.wrapMode            = wrapMode;
                        tImporter.filterMode          = filterMode;
                        tImporter.anisoLevel          = AnisoLevel;
                    }

                    AssetDatabase.ImportAsset(s, ImportAssetOptions.ForceUpdate);
                }
            }

            if (importerType == TexImporterType.CustomPath)
            {
                if (CustomPath.Length > 0)
                {
                    foreach (string f in CustomPath)
                    {
                        var files = Directory.GetFiles(f, "*.*", SearchOption.AllDirectories)
                                    .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".psd") || s.EndsWith(".gif") ||
                                           s.EndsWith(".iff") || s.EndsWith(".tga") || s.EndsWith(".tiff") || s.EndsWith(".bmp") ||
                                           s.EndsWith(".pict"));

                        foreach (string ss in files)
                        {
                            TextureImporter tImporter = AssetImporter.GetAtPath(ss) as TextureImporter;
                            tImporter.maxTextureSize = textureSize;

                            if (comprissonMode == TextureCompressionType.None)
                            {
                                tImporter.textureCompression = TextureImporterCompression.Uncompressed;
                            }
                            if (comprissonMode == TextureCompressionType.LowQuality)
                            {
                                tImporter.textureCompression = TextureImporterCompression.CompressedLQ;
                            }
                            if (comprissonMode == TextureCompressionType.HighQuality)
                            {
                                tImporter.textureCompression = TextureImporterCompression.CompressedHQ;
                            }

                            if (advancedMode)
                            {
                                tImporter.textureType         = textureType;
                                tImporter.textureShape        = textureShape;
                                tImporter.sRGBTexture         = textureRGB;
                                tImporter.alphaSource         = textureAlphaSource;
                                tImporter.alphaIsTransparency = AlphaIsTransparent;
                                tImporter.isReadable          = ReadWriteEnabled;
                                tImporter.mipmapEnabled       = GenerateMipMaps;
                                tImporter.wrapMode            = wrapMode;
                                tImporter.filterMode          = filterMode;
                                tImporter.anisoLevel          = AnisoLevel;
                            }
                            AssetDatabase.ImportAsset(ss, ImportAssetOptions.ForceUpdate);
                        }
                    }
                }
            }


            if (importerType == TexImporterType.CustomTextures)
            {
                if (targets.Length > 0)
                {
                    foreach (Texture2D s in targets)
                    {
                        TextureImporter tImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(s)) as TextureImporter;
                        tImporter.maxTextureSize = textureSize;

                        if (comprissonMode == TextureCompressionType.None)
                        {
                            tImporter.textureCompression = TextureImporterCompression.Uncompressed;
                        }
                        if (comprissonMode == TextureCompressionType.LowQuality)
                        {
                            tImporter.textureCompression = TextureImporterCompression.CompressedLQ;
                        }
                        if (comprissonMode == TextureCompressionType.HighQuality)
                        {
                            tImporter.textureCompression = TextureImporterCompression.CompressedHQ;
                        }

                        if (advancedMode)
                        {
                            tImporter.textureType         = textureType;
                            tImporter.textureShape        = textureShape;
                            tImporter.sRGBTexture         = textureRGB;
                            tImporter.alphaSource         = textureAlphaSource;
                            tImporter.alphaIsTransparency = AlphaIsTransparent;
                            tImporter.isReadable          = ReadWriteEnabled;
                            tImporter.mipmapEnabled       = GenerateMipMaps;
                            tImporter.wrapMode            = wrapMode;
                            tImporter.filterMode          = filterMode;
                            tImporter.anisoLevel          = AnisoLevel;
                        }
                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(s), ImportAssetOptions.ForceUpdate);
                    }
                }
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        if (importerType == TexImporterType.CustomTextures)
        {
            ScriptableObject   target          = this;
            SerializedObject   so              = new SerializedObject(target);
            SerializedProperty stringsProperty = so.FindProperty("targets");
            EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
            so.ApplyModifiedProperties();                         // Remember to apply modified properties
        }

        if (importerType == TexImporterType.CustomPath)
        {
            ScriptableObject   target          = this;
            SerializedObject   so              = new SerializedObject(target);
            SerializedProperty stringsProperty = so.FindProperty("CustomPath");
            EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
            so.ApplyModifiedProperties();                         // Remember to apply modified properties
        }

        textureSize = EditorGUILayout.IntField("Texture Size", textureSize, GUILayout.Width(343));
        EditorGUILayout.Space(); EditorGUILayout.Space();

        comprissonMode = (TextureCompressionType)EditorGUILayout.EnumPopup("Comprisson Mode", comprissonMode, GUILayout.Width(343));
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        advancedMode = EditorGUILayout.Toggle("Show Advanced Options", advancedMode);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        if (advancedMode)
        {
            EditorGUILayout.LabelField("Recommended non-advanced mode to avoid problems");

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            textureType        = (TextureImporterType)EditorGUILayout.EnumPopup("Texture Type", textureType, GUILayout.Width(343));
            textureShape       = (TextureImporterShape)EditorGUILayout.EnumPopup("Texture Shape", textureShape, GUILayout.Width(343));
            textureRGB         = EditorGUILayout.Toggle("sRGB Mode", textureRGB, GUILayout.Width(343));
            textureAlphaSource = (TextureImporterAlphaSource)EditorGUILayout.EnumPopup("Alpha Source", textureAlphaSource, GUILayout.Width(343));
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            AlphaIsTransparent = EditorGUILayout.Toggle("Alpha Is Transparent", AlphaIsTransparent, GUILayout.Width(343));
            ReadWriteEnabled   = EditorGUILayout.Toggle("Read Write Enabled", ReadWriteEnabled, GUILayout.Width(343));
            GenerateMipMaps    = EditorGUILayout.Toggle("Generate Mip Maps", GenerateMipMaps, GUILayout.Width(343));
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            wrapMode   = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", wrapMode, GUILayout.Width(343));
            filterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", filterMode, GUILayout.Width(343));
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            AnisoLevel = EditorGUILayout.IntField("Aniso Level", AnisoLevel, GUILayout.Width(343));
        }
        EditorGUILayout.EndScrollView();
    }
示例#43
0
        public static Texture2D LoadTextureFromMemory(byte[] data, string path, ref bool checkAlphaChannel, TextureWrapMode textureWrapMode = TextureWrapMode.Repeat, TextureCompression textureCompression = TextureCompression.None, bool isNormalMap = false, bool isRawData = false, int width = 0, int height = 0)
        {
            if (data.Length == 0 || string.IsNullOrEmpty(path))
            {
                return(null);
            }
            Texture2D tempTexture2D;

            if (ApplyTextureData(data, isRawData, out tempTexture2D, width, height))
            {
                return(ProccessTextureData(tempTexture2D, StringUtils.GenerateUniqueName(path.GetHashCode()), ref checkAlphaChannel, textureWrapMode, null, textureCompression, isNormalMap));
            }
#if TRILIB_OUTPUT_MESSAGES || ASSIMP_OUTPUT_MESSAGES
            Debug.LogErrorFormat("Unable to load texture '{0}'", path);
#endif
            return(null);
        }
示例#44
0
    void ReimportTexture(string assetPath, TextureWrapMode wrapMode, FilterMode filterMode, int anisoLevel, int maxTextureSize, TextureImporterFormat textureFormat)
    {
//      Debug.Log("ChangeImportTextureToGUI - " + assetPath);
        TextureImporter texImporter = TextureImporter.GetAtPath(assetPath) as TextureImporter;

        TextureImporterSettings settings = new TextureImporterSettings();

        texImporter.ReadTextureSettings(settings);
//      settings.ApplyTextureType(TextureImporterType.GUI, false);
//      texImporter.SetTextureSettings(settings);

        if (m_bSetGUI)
        {
            if (m_bGUI)
            {
                texImporter.textureType = TextureImporterType.GUI;
            }
            else
            {
                texImporter.textureType = TextureImporterType.Default;
            }
        }

        if (m_bSetWrapMode)
        {
            texImporter.wrapMode = wrapMode;
        }

        if (m_bSetGUI)
        {
            if (!m_bGUI)
            {
                if (m_bSetFilterMode)
                {
                    texImporter.filterMode = filterMode;
                }
                if (m_bSetAnisoLevel)
                {
                    texImporter.anisoLevel = anisoLevel;
                }
            }
        }
        else
        {
            if (m_bSetFilterMode)
            {
                texImporter.filterMode = filterMode;
            }
            if (m_bSetAnisoLevel)
            {
                texImporter.anisoLevel = anisoLevel;
            }
        }

        if (m_bSetMaxTextureSizeIdx)
        {
            texImporter.maxTextureSize = maxTextureSize;
        }
        if (m_bSetTextureFormatIdx)
        {
            texImporter.textureFormat = textureFormat;
        }
//      texImporter.npotScale = TextureImporterNPOTScale.None;
        AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceSynchronousImport);
    }
示例#45
0
 public static string TransformWrapMode(TextureWrapMode mode)
 {
     return(mWrapModeTransform[mode]);
 }
示例#46
0
 public TextureAtlas(Bitmap bitmap, TextureWrapMode wrapS, TextureWrapMode wrapT, TextureFilterMode minFilter, TextureFilterMode magFilter, int textureID)
     : base(bitmap, wrapS, wrapT, minFilter, magFilter, textureID)
 {
     this.atlas = new Dictionary <string, SubTexture2D>();
 }
示例#47
0
 // register texture
 internal static int RegisterTexture(string FileName, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload)
 {
     return(RegisterTexture(FileName, new World.ColorRGB(0, 0, 0), 0, TextureLoadMode.Normal, WrapModeX, WrapModeY, DontAllowUnload, 0, 0, 0, 0));
 }
示例#48
0
 public SamplerKey(FilterMode filterMode, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV)
 {
     m_FilterMode = filterMode;
     m_WrapModeU  = wrapModeU;
     m_WrapModeV  = wrapModeV;
 }
示例#49
0
 internal static int RegisterTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload)
 {
     return(RegisterTexture(FileName, TransparentColor, TransparentColorUsed, TextureLoadMode.Normal, WrapModeX, WrapModeY, DontAllowUnload, 0, 0, 0, 0));
 }
示例#50
0
        internal static int RegisterTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
        {
            int i = FindTexture(FileName, TransparentColor, TransparentColorUsed, LoadMode, WrapModeX, WrapModeY, ClipLeft, ClipTop, ClipWidth, ClipHeight);

            if (i >= 0)
            {
                return(i);
            }
            else
            {
                i                                = GetFreeTexture();
                Textures[i]                      = new Texture();
                Textures[i].Queried              = false;
                Textures[i].Loaded               = false;
                Textures[i].FileName             = FileName;
                Textures[i].TransparentColor     = TransparentColor;
                Textures[i].TransparentColorUsed = TransparentColorUsed;
                Textures[i].LoadMode             = LoadMode;
                Textures[i].WrapModeX            = WrapModeX;
                Textures[i].WrapModeY            = WrapModeY;
                Textures[i].ClipLeft             = ClipLeft;
                Textures[i].ClipTop              = ClipTop;
                Textures[i].ClipWidth            = ClipWidth;
                Textures[i].ClipHeight           = ClipHeight;
                Textures[i].DontAllowUnload      = DontAllowUnload;
                Textures[i].LoadImmediately      = false;
                Textures[i].OpenGlTextureIndex   = 0;
                bool alpha = false;
                switch (System.IO.Path.GetExtension(Textures[i].FileName).ToLowerInvariant())
                {
                case ".gif":
                case ".png":
                    alpha = true;
                    Textures[i].LoadImmediately = true;
                    break;
                }
                if (alpha)
                {
                    Textures[i].Transparency = TextureTransparencyMode.Alpha;
                }
                else if (TransparentColorUsed != 0)
                {
                    Textures[i].Transparency = TextureTransparencyMode.TransparentColor;
                }
                else
                {
                    Textures[i].Transparency = TextureTransparencyMode.None;
                }
                Textures[i].IsRGBA = Textures[i].Transparency != TextureTransparencyMode.None | LoadMode != TextureLoadMode.Normal;
                return(i);
            }
        }
示例#51
0
	void ReimportTexture(string assetPath, TextureWrapMode wrapMode, FilterMode filterMode, int anisoLevel, int maxTextureSize, TextureImporterFormat textureFormat)
	{
// 		Debug.Log("ChangeImportTextureToGUI - " + assetPath);
		TextureImporter	texImporter = TextureImporter.GetAtPath(assetPath) as TextureImporter;

		TextureImporterSettings settings = new TextureImporterSettings();
		texImporter.ReadTextureSettings(settings);
// 		settings.ApplyTextureType(TextureImporterType.GUI, false);
// 		texImporter.SetTextureSettings(settings);

		if (m_bSetGUI)
		{
			if (m_bGUI)
		 		 texImporter.textureType	= TextureImporterType.GUI;
			else texImporter.textureType	= TextureImporterType.Image;
		}

		if (m_bSetWrapMode)
			texImporter.wrapMode			= wrapMode;

		if (m_bSetGUI)
		{
			if (!m_bGUI)
			{
				if (m_bSetFilterMode)
					texImporter.filterMode	= filterMode;
				if (m_bSetAnisoLevel)
					texImporter.anisoLevel	= anisoLevel;
			}
		} else {
				if (m_bSetFilterMode)
					texImporter.filterMode	= filterMode;
				if (m_bSetAnisoLevel)
					texImporter.anisoLevel	= anisoLevel;
		}

		if (m_bSetMaxTextureSizeIdx)
			texImporter.maxTextureSize		= maxTextureSize;
		if (m_bSetTextureFormatIdx)
 			texImporter.textureFormat		= textureFormat;
//  	texImporter.npotScale = TextureImporterNPOTScale.None;
		AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceSynchronousImport);
	}
示例#52
0
 // find texture
 private static int FindTexture(string FileName, World.ColorRGB TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight)
 {
     for (int i = 1; i < Textures.Length; i++)
     {
         if (Textures[i] != null && Textures[i].FileName != null)
         {
             if (string.Compare(Textures[i].FileName, FileName, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 if (Textures[i].LoadMode == LoadMode & Textures[i].WrapModeX == WrapModeX & Textures[i].WrapModeY == WrapModeY)
                 {
                     if (Textures[i].ClipLeft == ClipLeft & Textures[i].ClipTop == ClipTop & Textures[i].ClipWidth == ClipWidth & Textures[i].ClipHeight == ClipHeight)
                     {
                         if (TransparentColorUsed == 0)
                         {
                             if (Textures[i].TransparentColorUsed == 0)
                             {
                                 return(i);
                             }
                         }
                         else
                         {
                             if (Textures[i].TransparentColorUsed != 0)
                             {
                                 if (Textures[i].TransparentColor.R == TransparentColor.R & Textures[i].TransparentColor.G == TransparentColor.G & Textures[i].TransparentColor.B == TransparentColor.B)
                                 {
                                     return(i);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(-1);
 }
示例#53
0
    }//initializeLookuptable

    //*******************************************************
    //*******************************************************
    public GameObject makeObject(float width, float height, Vector3 pivotOffset, Vector2 texScale, TextureWrapMode wrapMode = TextureWrapMode.Repeat)
    {
        texture.wrapMode = wrapMode;

        Shader shader = Shader.Find("Diffuse");

        GameObject quad = MakePlane(width, height, (int)width, (int)height, color, pivotOffset, false, theName, shader);

        //quad.transform.localScale = new Vector3(width, height, 1.0f);
        quad.GetComponent <Renderer>().material.mainTexture = texture;

        quad.GetComponent <Renderer>().material.mainTextureScale = texScale;

        if (pivotOffset != Vector3.zero)
        {
            MeshFilter mf   = quad.GetComponent <MeshFilter>();
            Mesh       mesh = mf.mesh;

            //This next bit is to set the origin of the mesh as the top-left For science
            Vector3[] verts = mesh.vertices;
            for (int i = 0; i < verts.Length; i++)
            {
                verts[i] += pivotOffset;
            } //for
            mesh.vertices = verts;
        }     //if

        if (theName != "")
        {
            quad.name = "Tile from: " + theName;
        }
        else
        {
            quad.name = "Texturizer texture: " + color.ToString();
        }


        return(quad);
    }//makeObject
示例#54
0
 public void SetWrap(TextureCoordinate coord, TextureWrapMode mode)
 {
     _gl.TextureParameter(GlTexture, (TextureParameterName)coord, (int)mode);
 }
示例#55
0
文件: Texture.cs 项目: dzamkov/DUIP
 /// <summary>
 /// Sets the technique used for wrapping the currently-bound texture.
 /// </summary>
 public static void SetWrapMode(TextureWrapMode Horizontal, TextureWrapMode Vertical)
 {
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)Horizontal);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)Vertical);
 }
示例#56
0
 static extern void SetSkybox(IntPtr _skybox, TextureWrapMode _wrapModeU, TextureWrapMode _wrapModeV, TextureWrapMode _wrapModeW, int _anisoLevel, int _meshId);
 public void TexParameter(TextureTarget target, TextureParameterName pname, TextureWrapMode param)
 {
     this.TexParameter(target, pname, (uint)param);
 }
示例#58
0
 public void SetWrapMode(TextureWrapMode wrapHorizontal, TextureWrapMode wrapVertical)
 {
     GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)wrapHorizontal);
     GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)wrapVertical);
 }
示例#59
0
文件: Texture.cs 项目: KSLcom/duality
		/// <summary>
		/// Creates a new empty Texture with the specified size.
		/// </summary>
		/// <param name="width">The Textures width.</param>
		/// <param name="height">The Textures height</param>
		/// <param name="sizeMode">Specifies behaviour in case the specified size has non-power-of-two dimensions.</param>
		/// <param name="filterMag">The OpenGL filter mode for drawing the Texture bigger than it is.</param>
		/// <param name="filterMin">The OpenGL fitler mode for drawing the Texture smaller than it is.</param>
		/// <param name="wrapX">The OpenGL wrap mode on the texel x axis.</param>
		/// <param name="wrapY">The OpenGL wrap mode on the texel y axis.</param>
		/// <param name="format">The format in which OpenGL stores the pixel data.</param>
		public Texture(int width, int height, 
			SizeMode sizeMode			= SizeMode.Default, 
			TextureMagFilter filterMag	= TextureMagFilter.Linear, 
			TextureMinFilter filterMin	= TextureMinFilter.LinearMipmapLinear,
			TextureWrapMode wrapX		= TextureWrapMode.ClampToEdge,
			TextureWrapMode wrapY		= TextureWrapMode.ClampToEdge,
			PixelInternalFormat format	= PixelInternalFormat.Rgba)
		{
			this.filterMag = filterMag;
			this.filterMin = filterMin;
			this.wrapX = wrapX;
			this.wrapY = wrapY;
			this.pixelformat = format;
			this.texSizeMode = sizeMode;
			this.AdjustSize(width, height);
			this.SetupOpenGLRes();
		}
示例#60
0
        // This method wraps around regular RenderTexture creation.
        // There is no specific logic applied to RenderTextures created this way.
        public RTHandle Alloc(
            int width,
            int height,
            int slices = 1,
            DepthBits depthBufferBits          = DepthBits.None,
            GraphicsFormat colorFormat         = GraphicsFormat.R8G8B8A8_SRGB,
            FilterMode filterMode              = FilterMode.Point,
            TextureWrapMode wrapMode           = TextureWrapMode.Repeat,
            TextureDimension dimension         = TextureDimension.Tex2D,
            bool enableRandomWrite             = false,
            bool useMipMap                     = false,
            bool autoGenerateMips              = true,
            bool isShadowMap                   = false,
            int anisoLevel                     = 1,
            float mipMapBias                   = 0f,
            MSAASamples msaaSamples            = MSAASamples.None,
            bool bindTextureMS                 = false,
            bool useDynamicScale               = false,
            bool xrInstancing                  = false,
            RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
            string name = ""
            )
        {
            bool enableMSAA = msaaSamples != MSAASamples.None;

            if (!enableMSAA && bindTextureMS == true)
            {
                Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
                bindTextureMS = false;
            }

            // XR override for instancing support
            VRTextureUsage vrUsage = XRGraphics.OverrideRenderTexture(xrInstancing, ref dimension, ref slices);

            // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
            RenderTexture rt;

            if (isShadowMap || depthBufferBits != DepthBits.None)
            {
                RenderTextureFormat format = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
                rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = enableRandomWrite,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = (int)msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    vrUsage           = vrUsage,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, format, name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
                };
            }
            else
            {
                rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
                {
                    hideFlags         = HideFlags.HideAndDontSave,
                    volumeDepth       = slices,
                    filterMode        = filterMode,
                    wrapMode          = wrapMode,
                    dimension         = dimension,
                    enableRandomWrite = enableRandomWrite,
                    useMipMap         = useMipMap,
                    autoGenerateMips  = autoGenerateMips,
                    anisoLevel        = anisoLevel,
                    mipMapBias        = mipMapBias,
                    antiAliasing      = (int)msaaSamples,
                    bindTextureMS     = bindTextureMS,
                    useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                    vrUsage           = vrUsage,
                    memorylessMode    = memoryless,
                    name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
                };
            }

            rt.Create();

            RTCategory category = enableMSAA ? RTCategory.MSAA : RTCategory.Regular;
            var        newRT    = new RTHandle(this);

            newRT.SetRenderTexture(rt, category);
            newRT.useScaling             = false;
            newRT.m_EnableRandomWrite    = enableRandomWrite;
            newRT.m_EnableMSAA           = enableMSAA;
            newRT.m_EnableHWDynamicScale = useDynamicScale;
            newRT.m_Name = name;

            newRT.referenceSize = new Vector2Int(width, height);

            return(newRT);
        }