using System;
using Manager;
using UnityEngine;
// Token: 0x020002BE RID: 702
public class CustomTextureControl
{
	// Token: 0x06001116 RID: 4374 RVA: 0x0000D09F File Offset: 0x0000B29F
	public CustomTextureControl()
	{
		this.InitEnd = false;
		this.matDraw = null;
	}
	// Token: 0x17000267 RID: 615
	// (get) Token: 0x06001117 RID: 4375 RVA: 0x0000D0B5 File Offset: 0x0000B2B5
	// (set) Token: 0x06001118 RID: 4376 RVA: 0x0000D0BD File Offset: 0x0000B2BD
	public Material matDraw
	{
		get;
		private set;
	}
	// Token: 0x17000268 RID: 616
	// (get) Token: 0x06001119 RID: 4377 RVA: 0x0000D0C6 File Offset: 0x0000B2C6
	// (set) Token: 0x0600111A RID: 4378 RVA: 0x0000D0CE File Offset: 0x0000B2CE
	public bool InitEnd
	{
		get;
		private set;
	}
	// Token: 0x0600111B RID: 4379 RVA: 0x0009D320 File Offset: 0x0009B520
	public void Initialize(string drawMatABName, string drawMatName, string createMatABName, string createMatName, int width, int height)
	{
		this.InitEnd = false;
		this.matDraw = CommonLib.LoadAsset<Material>(drawMatABName, drawMatName, true, string.Empty);
		if (null == this.matDraw)
		{
			return;
		}
		Singleton<Character>.Instance.AddLoadAssetBundle(drawMatABName);
		this.matCreate = CommonLib.LoadAsset<Material>(createMatABName, createMatName, true, string.Empty);
		if (null == this.matCreate)
		{
			UnityEngine.Object.Destroy(this.matDraw);
			this.matDraw = null;
			return;
		}
		Singleton<Character>.Instance.AddLoadAssetBundle(createMatABName);
		this.texMain = this.matCreate.GetTexture(Singleton<Character>.Instance._MainTex);
		if (Config.BasicSettings.enable4KSkinDiffuse)
		{
			width = 4096;
			height = 4096;
		}
		this.createTex = new RenderTexture(width, height, 0);
		if (Config.BasicSettings.enableSkinDiffuseMipMap)
		{
			this.createTex.filterMode = FilterMode.Trilinear;
			this.createTex.useMipMap = true;
		}
		this.InitEnd = true;
	}
	// Token: 0x0600111C RID: 4380 RVA: 0x0000D0D7 File Offset: 0x0000B2D7
	public void Release()
	{
		UnityEngine.Object.Destroy(this.createTex);
		this.createTex = null;
		UnityEngine.Object.Destroy(this.matDraw);
		this.matDraw = null;
		UnityEngine.Object.Destroy(this.matCreate);
		this.matCreate = null;
		this.InitEnd = false;
	}
	// Token: 0x0600111D RID: 4381 RVA: 0x0000D116 File Offset: 0x0000B316
	public void SetMainTexture(Texture tex)
	{
		if (!this.InitEnd)
		{
			return;
		}
		this.texMain = tex;
	}
	// Token: 0x0600111E RID: 4382 RVA: 0x0000D128 File Offset: 0x0000B328
	public void SetTexture(string propertyName, Texture tex)
	{
		if (!this.InitEnd)
		{
			return;
		}
		this.matCreate.SetTexture(propertyName, tex);
	}
	// Token: 0x0600111F RID: 4383 RVA: 0x0000D140 File Offset: 0x0000B340
	public void SetTexture(int propertyID, Texture tex)
	{
		if (!this.InitEnd)
		{
			return;
		}
		this.matCreate.SetTexture(propertyID, tex);
	}
	// Token: 0x06001120 RID: 4384 RVA: 0x0000D158 File Offset: 0x0000B358
	public void SetColor(string propertyName, Color color)
	{
		if (!this.InitEnd)
		{
			return;
		}
		this.matCreate.SetColor(propertyName, color);
	}
	// Token: 0x06001121 RID: 4385 RVA: 0x0000D170 File Offset: 0x0000B370
	public void SetColor(int propertyID, Color color)
	{
		if (!this.InitEnd)
		{
			return;
		}
		this.matCreate.SetColor(propertyID, color);
	}
	// Token: 0x06001122 RID: 4386 RVA: 0x0000D188 File Offset: 0x0000B388
	public void SetOffsetAndTiling(string propertyName, float tx, float ty, float ox, float oy)
	{
		if (!this.InitEnd)
		{
			return;
		}
		this.matCreate.SetTextureOffset(propertyName, new Vector2(ox, oy));
		this.matCreate.SetTextureScale(propertyName, new Vector2(tx, ty));
	}
	// Token: 0x06001123 RID: 4387 RVA: 0x0009D414 File Offset: 0x0009B614
	public void SetOffsetAndTiling(string propertyName, int baseW, int baseH, int addW, int addH, float addPx, float addPy)
	{
		if (!this.InitEnd)
		{
			return;
		}
		if (addPx >= 0f & addPy >= 0f & (float)addW + addPx <= 1024f & (float)addH + addPy <= 1024f)
		{
			baseW = 1024;
			baseH = 1024;
		}
		else
		{
			addPx = Mathf.Abs(addPx);
			addPy = Mathf.Abs(addPy);
			baseH = 4096;
			baseW = 4096;
		}
		float num = (float)baseW / (float)addW;
		float num2 = (float)baseH / (float)addH;
		float ox = -(addPx / (float)baseW) * num;
		float oy = -(((float)baseH - addPy - (float)addH) / (float)baseH) * num2;
		this.SetOffsetAndTiling(propertyName, num, num2, ox, oy);
	}
	// Token: 0x06001124 RID: 4388 RVA: 0x0009D4CC File Offset: 0x0009B6CC
	public bool RebuildTextureAndSetMaterial()
	{
		if (!this.InitEnd)
		{
			return false;
		}
		RenderTexture arg_75_0 = RenderTexture.active;
		RenderTexture.active = null;
		bool arg_55_0 = GL.sRGBWrite;
		GL.sRGBWrite = false;
		Graphics.SetRenderTarget(this.createTex);
		GL.Clear(false, true, Color.white);
		Graphics.SetRenderTarget(null);
		Graphics.Blit(this.texMain, this.createTex, this.matCreate, 0);
		GL.sRGBWrite = arg_55_0;
		this.matDraw.SetTexture(Singleton<Character>.Instance._MainTex, this.createTex);
		RenderTexture.active = arg_75_0;
		return true;
	}
	// Token: 0x040016CC RID: 5836
	private RenderTexture createTex;
	// Token: 0x040016CD RID: 5837
	private Material matCreate;
	// Token: 0x040016CE RID: 5838
	private Texture texMain;
}