Example #1
0
        public void Draw(
            ref BitmapDrawCall drawCall,
            int?layer             = null, bool?worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null,
            Material material     = null
            )
        {
            if (Container == null)
            {
                throw new InvalidOperationException("You cannot use the argumentless ImperativeRenderer constructor.");
            }
            else if (Container.IsReleased)
            {
                throw new ObjectDisposedException("The container this ImperativeRenderer is drawing into has been disposed.");
            }

            using (var batch = GetBitmapBatch(
                       layer, worldSpace,
                       blendState, samplerState, material
                       )) {
                if (LowPriorityMaterialOrdering)
                {
                    if (material != null)
                    {
                        material = Materials.Get(material, RasterizerState, DepthStencilState, blendState ?? BlendState);
                    }
                    else
                    {
                        material = Materials.GetBitmapMaterial(worldSpace ?? WorldSpace, RasterizerState, DepthStencilState, blendState ?? BlendState);
                    }

                    var mmbb = (MultimaterialBitmapBatch)batch;
                    mmbb.Add(ref drawCall, material, samplerState, samplerState);
                }
                else
                {
                    batch.Add(ref drawCall);
                }
            }
        }
Example #2
0
        public BitmapBatch GetBitmapBatch(int?layer, bool?worldSpace, BlendState blendState, SamplerState samplerState)
        {
            if (Materials == null)
            {
                throw new InvalidOperationException("You cannot use the argumentless ImperativeRenderer constructor.");
            }

            var actualLayer         = layer.GetValueOrDefault(Layer);
            var actualWorldSpace    = worldSpace.GetValueOrDefault(WorldSpace);
            var desiredBlendState   = blendState ?? BlendState;
            var desiredSamplerState = samplerState ?? SamplerState;

            CachedBatch cacheEntry;

            if (!Cache.TryGet <BitmapBatch>(
                    out cacheEntry,
                    container: Container,
                    layer: actualLayer,
                    worldSpace: actualWorldSpace,
                    rasterizerState: RasterizerState,
                    depthStencilState: DepthStencilState,
                    blendState: desiredBlendState,
                    samplerState: desiredSamplerState,
                    useZBuffer: UseZBuffer
                    ))
            {
                var material = Materials.GetBitmapMaterial(
                    actualWorldSpace,
                    RasterizerState, DepthStencilState, desiredBlendState
                    );

                cacheEntry.Batch = BitmapBatch.New(Container, actualLayer, material, desiredSamplerState, desiredSamplerState, UseZBuffer);
                Cache.InsertAtFront(ref cacheEntry, null);
            }

            if (AutoIncrementLayer && !layer.HasValue)
            {
                Layer += 1;
            }

            return((BitmapBatch)cacheEntry.Batch);
        }