void CheckTexture() { if (!IsImageAlive) { KillTexture(); return; } Alt.Sketch.RenderImage renderImage = ImageSourceAsRenderImage; if (renderImage == null || ModificationTime == renderImage.ModificationTime) { return; } if (SrcWidth != renderImage.PixelWidth || SrcHeight != renderImage.PixelHeight || PixelFormat != renderImage.PixelFormat) { KillTexture(); } if (SrcWidth < 1 || SrcHeight < 1 || PixelFormat == Alt.Sketch.PixelFormat.Unknown) { return; } //int bpp = renderImage.ByteDepth; if (!m_RenderManager.NonPowerOf2TexturesSupported) { TextureWidth = NextPowerOfTwo(SrcWidth); TextureHeight = NextPowerOfTwo(SrcHeight); } else { TextureWidth = SrcWidth; TextureHeight = SrcHeight; } if (m_Texture == null) { // Create a new texture m_Texture = new RenderTexture(TextureWidth, TextureHeight, 0, Unity_RenderManager.ToRenderTextureFormat(PixelFormat)); if (m_Texture != null) { TextureWidth = m_Texture.width; TextureHeight = m_Texture.height; m_Texture.filterMode = FilterMode.Point; } } }
Unity_RenderManager() { m_Instance = this; int maxTextureSize = SystemInfo.maxTextureSize; MaxTextureSize = new SizeI(maxTextureSize, maxTextureSize); //new SizeI(2048, 2048); // TEMP (need process NPOTSupport.Restricted mode - Limited NPOT support: no mip-maps and clamp wrap mode will be forced) NonPowerOf2TexturesSupported = SystemInfo.npotSupport != NPOTSupport.None; RenderLinesByPolygons = false; MaxTextureCountPerBrushMaterial = 1; MaxTextureCoordsSetCountPerBrushMaterial = MaxTextureCountPerBrushMaterial; // test RenderTexture (not available if not Unity Pro) /* * RenderTexture renderTexture = null; * try * { * renderTexture = new RenderTexture(2, 2, 0, RenderTextureFormat.ARGB32); * renderTexture.Create(); * RenderToTextureSupported = renderTexture.IsCreated(); * } * catch (Exception ex) * { * Console.WriteLine(ex.ToString()); * * RenderToTextureSupported = false; * } * finally * { * if (renderTexture != null) * { * renderTexture.Release(); * //renderTexture.Destroy(); * renderTexture = null; * } * }*/ RenderToTextureSupported = SystemInfo.supportsRenderTextures; TextureMatrixSupported = true; ClippingSupported = true; // We prefer to use Software Render BackBuffers, because it's faster in most cases and // hasn't proplems with premultiplied alpha RenderToTextureSupported = false; }
public Unity_Renderer(Unity_RenderManager renderManager, UnityEngine.RenderTexture renderTexture) : base(renderManager, Alt.Sketch.Graphics.RSN_Unity) { //NoNeed m_RenderTexture = renderTexture; TransformMatrixSupported = true; RenderLinesByPolygons = renderManager.RenderLinesByPolygons; // Now supports only 1 texture (need more shaders researches) MaxTextureCountPerBrushMaterial = 1; // renderManager.MaxTextureCountPerBrushMaterial; MaxTextureCoordsSetCountPerBrushMaterial = 1; // renderManager.MaxTextureCoordsSetCountPerBrushMaterial; NonPowerOf2TexturesSupported = renderManager.NonPowerOf2TexturesSupported; // We cah't use NeoAxis RenderToTexture yet, so use Software render RenderToTextureSupported = renderManager.RenderToTextureSupported; // Can't to set Texture Matrix yet TextureMatrixSupported = false;// renderManager.TextureMatrixSupported; // Clipping is not supported (We can't get ScissorRect or Viewport to work...) ClippingSupported = #if TRY_CLIPPINGRECT renderManager.ClippingSupported; #else false; #endif SizeI maxTextureSize = renderManager.MaxTextureSize; // LinearGradientTextureMaxSize { SizeI baseLinearGradientTextureMaxSize = base.LinearGradientTextureMaxSize; LinearGradientTextureMaxSize = new SizeI( System.Math.Min(maxTextureSize.Width, baseLinearGradientTextureMaxSize.Width), System.Math.Min(maxTextureSize.Height, baseLinearGradientTextureMaxSize.Height)); } // RadialGradientTextureMaxSize { SizeI baseRadialGradientTextureMaxSize = base.RadialGradientTextureMaxSize; RadialGradientTextureMaxSize = new SizeI( System.Math.Min(maxTextureSize.Width, baseRadialGradientTextureMaxSize.Width), System.Math.Min(maxTextureSize.Height, baseRadialGradientTextureMaxSize.Height)); } }
protected override void Dispose(bool disposing) { m_Instance = null; if (!IsDisposed) { if (disposing) { // Dispose managed resources. } // There are no unmanaged resources to release, but // if we add them, they need to be released here. } base.Dispose(disposing); }
//NoNeed UnityEngine.Camera m_CurrentUnityEngineCamera; public Unity_Renderer(Unity_RenderManager renderManager) : this(renderManager, null) { }
protected virtual void UpdateTexture() { if (!IsImageAlive) { KillTexture(); return; } Alt.Sketch.Bitmap bitmap = ImageSourceAsBitmap; if (ModificationTime == bitmap.ModificationTime) { return; } if (SrcWidth != bitmap.PixelWidth || SrcHeight != bitmap.PixelHeight || PixelFormat != bitmap.PixelFormat) { KillTexture(); } if (SrcWidth < 1 || SrcHeight < 1 || PixelFormat == Alt.Sketch.PixelFormat.Unknown) { return; } //int bpp = bitmap.ByteDepth; if (!m_RenderManager.NonPowerOf2TexturesSupported) { TextureWidth = NextPowerOfTwo(SrcWidth); TextureHeight = NextPowerOfTwo(SrcHeight); if (TextureWidth != SrcWidth || TextureHeight != SrcHeight) { bitmap = bitmap.GetScaledCopy(TextureWidth, TextureHeight); if (bitmap == null || !bitmap.IsValid) { return; } } } else { TextureWidth = SrcWidth; TextureHeight = SrcHeight; } if (m_Texture == null) { // Create a new texture m_Texture = new Texture2D(TextureWidth, TextureHeight, Unity_RenderManager.ToTextureFormat(PixelFormat), false); m_Texture.filterMode = FilterMode.Point; if (m_Texture != null) { TextureWidth = m_Texture.width; TextureHeight = m_Texture.height; } } SetTextureData(bitmap, bitmap.PixelRectangle); }
internal Unity_Texture(Unity_RenderManager renderManager, int width, int height, Alt.Sketch.PixelFormat format) : base(width, height, format) { m_RenderManager = renderManager; }
protected override void SetTextureData(Sketch.Bitmap src, Sketch.RectI srcRect) { Unity_RenderManager.SetTextureData(m_Texture as UnityEngine.Texture2D, src, srcRect); ModificationTime = src.ModificationTime; }