コード例 #1
0
        // This begins a drawing session
        public bool StartRendering(bool clear, Color4 backcolor, Surface target, Surface depthbuffer)
        {
            // Check if we can render
            if (CheckAvailability() && !isrendering)            //mxd. Added isrendering check
            {
                // Set rendertarget
                device.DepthStencilSurface = depthbuffer;
                device.SetRenderTarget(0, target);

                // Clear the screen
                if (clear)
                {
                    if (depthbuffer != null)
                    {
                        device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, backcolor, 1f, 0);
                    }
                    else
                    {
                        device.Clear(ClearFlags.Target, backcolor, 1f, 0);
                    }
                }

                // Ready to render
                // [ZZ] Sometimes (apparently during massive lag) this may cause invalid call exception.
                //      Let's put this code here until proper fix is available.
                //      For now, eat the initial exception and try to recover.
                for (int i = 0; i < 2; i++)
                {
                    try
                    {
                        device.BeginScene();
                        break;
                    }
                    catch (SlimDXException e)
                    {
                        if (i != 0)
                        {
                            throw e;
                        }
                        else
                        {
                            if (!CheckAvailability())
                            {
                                isrendering = false;
                                return(false);
                            }

                            Reset();
                        }
                    }
                }

                isrendering = true;                 //mxd
                return(true);
            }
            else
            {
                // Minimized, you cannot see anything
                isrendering = false;                 //mxd
                return(false);
            }
        }