示例#1
0
        void DoPaintBackground()
        {
            if (m_Renderer == null)
            {
                return;
            }

            m_Renderer.BeginRender(GetComponent <Camera>(), GetComponent <Renderer>(), m_Width, m_Height);
            {
                OnPaintBackground(new Alt.GUI.PaintEventArgs(Alt.Sketch.Graphics.FromRenderer(m_Renderer),
                                                             new Alt.Sketch.RectI(Alt.Sketch.PointI.Zero, m_Width, m_Height)));
            }
            m_Renderer.EndRender();
        }
示例#2
0
        internal bool DoRenderIfNeed(Camera camera, Renderer renderer)
        {
            SizeI size;

            if (!NeedsUpdate ||
                Unity_RenderManager.Instance == null ||
                (size = Size).IsEmpty)
            {
                return(false);
            }


            NeedsUpdate = false;

            m_LastRenderTime = Alt.IntervalTimer.Ticks;

            m_FPSCounter.Tick();


            if (RenderType == Alt.Sketch.Rendering.RenderType.Software)
            {
                if (!(m_Texture is Texture2D))
                {
                    KillTextures();
                }

                if (m_Texture != null &&
                    (m_Texture.width != size.Width ||
                     m_Texture.height != size.Height))
                {
                    m_Texture = null;
                }

                if (m_Texture == null)
                {
                    m_Texture = new Texture2D(
                        size.Width, size.Height,
                        Unity_RenderManager.ToTextureFormat(PixelFormat.Format32bppArgb),
                        false);
                    m_Texture.filterMode = FilterMode.Point;

                    RefreshMaterial();
                }

                Bitmap backBuffer            = SoftwareBackBuffer;
                Alt.Sketch.Graphics graphics = Alt.Sketch.Graphics.FromImage(backBuffer);

                //graphics.Clear(Alt.Sketch.Color.FromArgb(0, 128, 128, 128));
                graphics.Clear(Alt.Sketch.Color.FromArgb(0, 0, 0, 0));

                DoPaintInternal(new Alt.GUI.PaintEventArgs(graphics, new Alt.Sketch.Rect(0, 0, size)));

                Unity_RenderManager.SetTextureData(m_Texture as Texture2D, backBuffer, backBuffer.PixelRectangle, true);
            }
            else
            {
                if (m_RenderTexture != null &&
                    (m_RenderTexture.width != size.Width ||
                     m_RenderTexture.height != size.Height))
                {
                    KillTextures();
                }

                if (m_RenderTexture == null)
                {
                    m_RenderTexture = new RenderTexture(
                        size.Width, size.Height,
                        0,
                        Unity_RenderManager.ToRenderTextureFormat(PixelFormat.Format32bppArgb));
                    m_RenderTexture.filterMode = FilterMode.Point;

                    m_Texture = m_RenderTexture;

                    RefreshMaterial();
                }

                if (m_RenderTexture != null)
                {
                    RenderTexture oldRenderTexture = RenderTexture.active;
                    RenderTexture.active = m_RenderTexture;
                    try
                    {
                        GL.Clear(true, true, Unity_RenderManager.ToColor(Alt.Sketch.Color.Empty));

                        if (m_Renderer == null)
                        {
                            m_Renderer = new Unity_Renderer(Unity_RenderManager.Instance);
                            m_Renderer.DefaultSmoothingMode = Alt.Sketch.SmoothingMode.None;
                        }

                        m_Renderer.BeginRender(camera, renderer, size.Width, size.Height, true);
                        {
                            Alt.Sketch.Graphics graphics = Alt.Sketch.Graphics.FromRenderer(m_Renderer);
                            if (graphics != null)
                            {
                                DoPaintInternal(new Alt.GUI.PaintEventArgs(graphics, new Alt.Sketch.Rect(0, 0, size)));
                            }
                        }
                        m_Renderer.EndRender();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                    finally
                    {
                        RenderTexture.active = oldRenderTexture;
                    }
                }
            }

            return(true);
        }