public void QueueRequest(IRenderContext renderContext, IRenderRequest request)
        {
            if (renderContext.IsCurrentRenderPass <I3DBatchedRenderPass>())
            {
                if (!_requestLookup.ContainsKey(request.StateHash))
                {
                    _requestLookup[request.StateHash] = request;
                }

                if (!_requestInstances.ContainsKey(request.StateHash))
                {
                    _requestInstances[request.StateHash] = new List <Matrix>();
                }

                if (request.Instances.Length > 1)
                {
                    _requestInstances[request.StateHash].AddRange(request.Instances);
                }
                else
                {
                    _requestInstances[request.StateHash].Add(request.Instances[0]);
                }
            }
            else
            {
                RenderRequestImmediate(renderContext, request);
            }
        }
        public void QueueRequest(IRenderContext renderContext, IRenderRequest request)
        {
            if (renderContext.IsCurrentRenderPass<I3DBatchedRenderPass>())
            {
                if (!_requestLookup.ContainsKey(request.StateHash))
                {
                    _requestLookup[request.StateHash] = request;
                }

                if (!_requestInstances.ContainsKey(request.StateHash))
                {
                    _requestInstances[request.StateHash] = new List<Matrix>();
                }

                if (request.Instances.Length > 1)
                {
                    _requestInstances[request.StateHash].AddRange(request.Instances);
                }
                else
                {
                    _requestInstances[request.StateHash].Add(request.Instances[0]);
                }
            }
            else
            {
                RenderRequestImmediate(renderContext, request);
            }
        }
        public void RenderRequestImmediate(IRenderContext renderContext, IRenderRequest request)
        {
            int pc;

            SetupForRequest(renderContext, request, out pc, true);

            for (var i = 0; i < request.Instances.Length; i++)
            {
                request.Effect.NativeEffect.Parameters["World"]?.SetValue(request.Instances[i]);

                foreach (var pass in request.Effect.NativeEffect.Techniques[request.TechniqueName].Passes)
                {
                    pass.Apply();

                    renderContext.GraphicsDevice.DrawIndexedPrimitives(
                        request.PrimitiveType,
                        0,
                        0,
                        pc);
                }
            }
        }
        private void SetupForRequest(IRenderContext renderContext, IRenderRequest request, out int pc, bool setVertexBuffers)
        {
            renderContext.GraphicsDevice.RasterizerState   = request.RasterizerState;
            renderContext.GraphicsDevice.BlendState        = request.BlendState;
            renderContext.GraphicsDevice.DepthStencilState = request.DepthStencilState;

            if (setVertexBuffers)
            {
                renderContext.GraphicsDevice.SetVertexBuffer(request.MeshVertexBuffer);
            }
            renderContext.GraphicsDevice.Indices = request.MeshIndexBuffer;

            switch (request.PrimitiveType)
            {
            case PrimitiveType.TriangleStrip:
                pc = request.MeshIndexBuffer.IndexCount - 2;
                break;

            case PrimitiveType.TriangleList:
                pc = request.MeshIndexBuffer.IndexCount / 3;
                break;

            case PrimitiveType.LineStrip:
                pc = request.MeshIndexBuffer.IndexCount - 1;
                break;

            case PrimitiveType.LineList:
                pc = request.MeshIndexBuffer.IndexCount / 2;
                break;

            default:
                throw new InvalidOperationException("Unknown primitive type!");
            }

            request.Effect.LoadParameterSet(renderContext, request.EffectParameterSet, true);
            request.Effect.NativeEffect.Parameters["View"]?.SetValue(renderContext.View);
            request.Effect.NativeEffect.Parameters["Projection"]?.SetValue(renderContext.Projection);
        }
Example #5
0
 public void RenderRequestImmediate(IRenderContext renderContext, IRenderRequest request)
 {
     throw new NotSupportedException();
 }
Example #6
0
 public void QueueRequest(IRenderContext renderContext, IRenderRequest request)
 {
     throw new NotSupportedException();
 }
        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;
                }
            }
        }
Example #8
0
 public void EnqueueRequest(IRenderRequest request)
 {
     m_dirtyRenderRequestQueue.Add((IRenderRequestBaseInternal <TWorld>)request);
 }
        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;
                }
            }
        }
 public void RenderRequestImmediate(IRenderContext renderContext, IRenderRequest request)
 {
     throw new NotImplementedException();
 }
 public void QueueRequest(IRenderContext renderContext, IRenderRequest request)
 {
     throw new NotImplementedException();
 }
        public void RenderRequestImmediate(IRenderContext renderContext, IRenderRequest request)
        {
            int pc;
            SetupForRequest(renderContext, request, out pc, true);
            
            for (var i = 0; i < request.Instances.Length; i++)
            {
                request.Effect.NativeEffect.Parameters["World"]?.SetValue(request.Instances[i]);

                foreach (var pass in request.Effect.NativeEffect.Techniques[request.TechniqueName].Passes)
                {
                    pass.Apply();
                    
                    renderContext.GraphicsDevice.DrawIndexedPrimitives(
                        request.PrimitiveType,
                        0,
                        0,
                        pc);
                }
            }
        }
        private void SetupForRequest(IRenderContext renderContext, IRenderRequest request, out int pc, bool setVertexBuffers)
        {
            renderContext.GraphicsDevice.RasterizerState = request.RasterizerState;
            renderContext.GraphicsDevice.BlendState = request.BlendState;
            renderContext.GraphicsDevice.DepthStencilState = request.DepthStencilState;

            if (setVertexBuffers)
            {
                renderContext.GraphicsDevice.SetVertexBuffer(request.MeshVertexBuffer);
            }
            renderContext.GraphicsDevice.Indices = request.MeshIndexBuffer;
            
            switch (request.PrimitiveType)
            {
                case PrimitiveType.TriangleStrip:
                    pc = request.MeshIndexBuffer.IndexCount - 2;
                    break;
                case PrimitiveType.TriangleList:
                    pc = request.MeshIndexBuffer.IndexCount / 3;
                    break;
                case PrimitiveType.LineStrip:
                    pc = request.MeshIndexBuffer.IndexCount - 1;
                    break;
                case PrimitiveType.LineList:
                    pc = request.MeshIndexBuffer.IndexCount / 2;
                    break;
                default:
                    throw new InvalidOperationException("Unknown primitive type!");
            }

            request.Effect.LoadParameterSet(renderContext, request.EffectParameterSet, true);
            request.Effect.NativeEffect.Parameters["View"]?.SetValue(renderContext.View);
            request.Effect.NativeEffect.Parameters["Projection"]?.SetValue(renderContext.Projection);
        }