예제 #1
0
        /// <summary>
        /// Creates a new Painter object. Normally, it's not necessary to create any custom
        ///  painters; instead, use the global painter found on the Sparrow instance.
        /// </summary>
        public Painter(float width, float height)
        {
            _framebufferCache = new Dictionary <uint, uint>();
            _actualBlendMode  = BlendMode.NORMAL;

            _backBufferWidth  = width;
            _backBufferHeight = height;
            PixelSize         = 1.0f;
            _clipRectStack    = new Stack <Rectangle>();

            _batchProcessorCurr = new BatchProcessor();
            _batchProcessorCurr.OnBatchComplete = DrawBatch;

            _batchProcessorPrev = new BatchProcessor();
            _batchProcessorPrev.OnBatchComplete = DrawBatch;

            _batchProcessorSpec = new BatchProcessor();
            _batchProcessorSpec.OnBatchComplete = DrawBatch;

            _batchProcessor       = _batchProcessorCurr;
            _batchCacheExclusions = new List <DisplayObject>();

            _state = new RenderState();
            _state.OnDrawRequired = FinishMeshBatch;
            _stateStack           = new List <RenderState>();
            _stateStackPos        = -1;
            _stateStackLength     = 0;
        }
예제 #2
0
        private BatchProcessor SwapBatchProcessors()
        {
            BatchProcessor tmp = _batchProcessorPrev;

            _batchProcessorPrev = _batchProcessorCurr;
            return(_batchProcessorCurr = tmp);
        }
예제 #3
0
        /// <summary>
        /// Completes all unfinished batches, cleanup procedures.
        /// </summary>
        public void FinishFrame()
        {
            if (_frameId % 99 == 0)
            {
                _batchProcessorCurr.Trim();                     // odd number -> alternating processors
            }
            if (_frameId % 150 == 0)
            {
                _batchProcessorSpec.Trim();
            }

            _batchProcessor.FinishBatch();
            _batchProcessor = _batchProcessorSpec; // no cache between frames
            ProcessCacheExclusions();
        }
예제 #4
0
        /// <summary>
        /// Resets the current state, state stack, batch processor, stencil reference value,
        /// clipping rectangle, and draw count. Furthermore, depth testing is disabled.
        /// </summary>
        public void NextFrame()
        {
            // update batch processors
            _batchProcessor = SwapBatchProcessors();
            _batchProcessor.Clear();
            _batchProcessorSpec.Clear();

            // enforce reset of basic context settings
            _actualBlendMode = BlendMode.NORMAL;
            Gl.DepthFunc(DepthFunction.Always);

            // reset everything else
            _clipRectStack.Clear();
            DrawCount      = 0;
            _stateStackPos = -1;
            _state.Reset();
        }