public void RenderCube(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Matrix transform, Color color)
        {
            if (!context.IsCurrentRenderPass <I3DRenderPass>())
            {
                throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
            }

            var vertexes = _renderCache.GetOrSet(
                "rendercube3dvb:" + color,
                () =>
            {
                var vb = new VertexBuffer(context.GraphicsDevice, VertexPositionNormalColor.VertexDeclaration, 24, BufferUsage.WriteOnly);
                vb.SetData(new[]
                {
                    new VertexPositionNormalColor(new Vector3(0, 0, 0), new Vector3(-1, 0, 0), color),
                    new VertexPositionNormalColor(new Vector3(0, 0, 1), new Vector3(-1, 0, 0), color),
                    new VertexPositionNormalColor(new Vector3(0, 1, 0), new Vector3(-1, 0, 0), color),
                    new VertexPositionNormalColor(new Vector3(0, 1, 1), new Vector3(-1, 0, 0), color),

                    new VertexPositionNormalColor(new Vector3(1, 0, 0), new Vector3(1, 0, 0), color),
                    new VertexPositionNormalColor(new Vector3(1, 0, 1), new Vector3(1, 0, 0), color),
                    new VertexPositionNormalColor(new Vector3(1, 1, 0), new Vector3(1, 0, 0), color),
                    new VertexPositionNormalColor(new Vector3(1, 1, 1), new Vector3(1, 0, 0), color),

                    new VertexPositionNormalColor(new Vector3(0, 0, 0), new Vector3(0, -1, 0), color),
                    new VertexPositionNormalColor(new Vector3(0, 0, 1), new Vector3(0, -1, 0), color),
                    new VertexPositionNormalColor(new Vector3(0, 1, 0), new Vector3(0, 1, 0), color),
                    new VertexPositionNormalColor(new Vector3(0, 1, 1), new Vector3(0, 1, 0), color),

                    new VertexPositionNormalColor(new Vector3(1, 0, 0), new Vector3(0, -1, 0), color),
                    new VertexPositionNormalColor(new Vector3(1, 0, 1), new Vector3(0, -1, 0), color),
                    new VertexPositionNormalColor(new Vector3(1, 1, 0), new Vector3(0, 1, 0), color),
                    new VertexPositionNormalColor(new Vector3(1, 1, 1), new Vector3(0, 1, 0), color),

                    new VertexPositionNormalColor(new Vector3(0, 0, 0), new Vector3(0, 0, -1), color),
                    new VertexPositionNormalColor(new Vector3(0, 0, 1), new Vector3(0, 0, 1), color),
                    new VertexPositionNormalColor(new Vector3(0, 1, 0), new Vector3(0, 0, -1), color),
                    new VertexPositionNormalColor(new Vector3(0, 1, 1), new Vector3(0, 0, 1), color),

                    new VertexPositionNormalColor(new Vector3(1, 0, 0), new Vector3(0, 0, -1), color),
                    new VertexPositionNormalColor(new Vector3(1, 0, 1), new Vector3(0, 0, 1), color),
                    new VertexPositionNormalColor(new Vector3(1, 1, 0), new Vector3(0, 0, -1), color),
                    new VertexPositionNormalColor(new Vector3(1, 1, 1), new Vector3(0, 0, 1), color)
                });
                return(vb);
            });
            var indicies = _renderCache.GetOrSet(
                "rendercube3dib",
                () =>
            {
                var ib = new IndexBuffer(context.GraphicsDevice, IndexElementSize.SixteenBits, 36, BufferUsage.WriteOnly);
                ib.SetData(new short[]
                {
                    0, 2, 1,
                    3, 1, 2,

                    4, 5, 6,
                    7, 6, 5,

                    0 + 8, 1 + 8, 4 + 8,
                    5 + 8, 4 + 8, 1 + 8,

                    2 + 8, 6 + 8, 3 + 8,
                    7 + 8, 3 + 8, 6 + 8,

                    0 + 16, 4 + 16, 2 + 16,
                    6 + 16, 2 + 16, 4 + 16,

                    1 + 16, 3 + 16, 5 + 16,
                    7 + 16, 5 + 16, 3 + 16
                });
                return(ib);
            });

            _renderBatcher.QueueRequest(
                context,
                _renderBatcher.CreateSingleRequestFromState(
                    context,
                    effect,
                    effectParameterSet,
                    vertexes,
                    indicies,
                    PrimitiveType.TriangleList,
                    transform,
                    null));
        }
        public void Render(ComponentizedEntity entity, IGameContext gameContext, IRenderContext renderContext)
        {
            if (!Enabled)
            {
                return;
            }

            if (renderContext.IsCurrentRenderPass <I3DRenderPass>())
            {
                if (Effect == null)
                {
                    _useDefaultEffects = true;
                }
                else
                {
                    _useDefaultEffects = false;
                }

                if (_useDefaultEffects && _uberEffectAsset == null)
                {
                    _uberEffectAsset = _assetManager.Get <UberEffectAsset>("effect.BuiltinSurface");
                }

                if (Model != null)
                {
                    var matrix = FinalTransform.AbsoluteMatrix;

                    bool   changedRenderRequest   = _lastWorldMatrix != matrix;
                    string changedRenderRequestBy = changedRenderRequest ? "matrix" : "";

                    var material = OverrideMaterial ?? _model.Material;

                    UpdateCachedModel(material, ref changedRenderRequest, ref changedRenderRequestBy);

                    var effect = GetEffect(ref changedRenderRequest, ref changedRenderRequestBy);

                    var parameterSet = GetEffectParameterSet(material, ref changedRenderRequest, ref changedRenderRequestBy);

                    var animation = GetModelAnimation(ref changedRenderRequest, ref changedRenderRequestBy);

                    if (animation != null)
                    {
                        animation.Apply(_model, _animationTracker.ElapsedMilliseconds / 1000f, 0.5f);

                        _renderRequest = _model.CreateRenderRequest(renderContext, effect, parameterSet, matrix);
                    }
                    else if (changedRenderRequest || _renderRequest == null)
                    {
                        _renderRequest = _model.CreateRenderRequest(renderContext, effect, parameterSet, matrix);
                    }

                    _lastWorldMatrix = matrix;

                    _renderBatcher.QueueRequest(
                        renderContext,
                        _renderRequest);
                }
                else
                {
                    _lastCachedModel          = null;
                    _lastCachedDiffuseTexture = null;
                }
            }
        }