private void UpdateState(DrawingState drawingState, PrimitiveTopologyState topologyState) { if (drawingState != _currentDrawingState) { _currentDrawingState = drawingState; switch (_currentDrawingState) { case DrawingState.Standard: _context.InputAssembler.InputLayout = _vertexLayouts.StandardLayout; _currentTechnique = _standardSmooth; break; case DrawingState.StandardFlat: _context.InputAssembler.InputLayout = _vertexLayouts.StandardLayout; _currentTechnique = _standardFlat; break; case DrawingState.StandardWirefame: _context.InputAssembler.InputLayout = _vertexLayouts.StandardLayout; _currentTechnique = _standardWireframe; break; case DrawingState.Prelit: _context.InputAssembler.InputLayout = _vertexLayouts.PrelitLayout; _currentTechnique = _prelitSmooth; break; case DrawingState.PrelitFlat: _context.InputAssembler.InputLayout = _vertexLayouts.PrelitLayout; _currentTechnique = _prelitFlat; break; case DrawingState.PrelitWireframe: _context.InputAssembler.InputLayout = _vertexLayouts.PrelitLayout; _currentTechnique = _prelitWireframe; break; default: throw new NotSupportedException(); } } if(topologyState != _currentTopologyState) { _currentTopologyState = topologyState; switch (_currentTopologyState) { case PrimitiveTopologyState.TriangleList: _context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; break; case PrimitiveTopologyState.LineList: _context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList; break; } } }
public DrawingManager(DeviceManager deviceManager) { _device = deviceManager.Device; _context = deviceManager.Context; _vertexLayouts = deviceManager.VertexLayouts; var effect = deviceManager.Effect; _standardSmooth = effect.GetTechniqueByName("Standard|Smooth"); _standardFlat = effect.GetTechniqueByName("Standard|Flat"); _standardWireframe = effect.GetTechniqueByName("Standard|Wireframe"); _prelitSmooth = effect.GetTechniqueByName("Prelit|Smooth"); _prelitFlat = effect.GetTechniqueByName("Prelit|Flat"); _prelitWireframe = effect.GetTechniqueByName("Prelit|Wireframe"); _worldMatrix = effect.GetVariableByName("g_WorldMatrix").AsMatrix(); _postWorldMatrix = effect.GetVariableByName("g_PostWorldMatrix").AsMatrix(); _viewMatrix = effect.GetVariableByName("g_ViewMatrix").AsMatrix(); _projectionMatrix = effect.GetVariableByName("g_ProjectionMatrix").AsMatrix(); _color = effect.GetVariableByName("g_Color").AsVector(); _opacity = effect.GetVariableByName("g_Opacity").AsScalar(); _ambient = effect.GetVariableByName("g_Ambient").AsScalar(); _diffuse = effect.GetVariableByName("g_Diffuse").AsScalar(); _texture = effect.GetVariableByName("g_Texture").AsShaderResource(); _mask = effect.GetVariableByName("g_Mask").AsShaderResource(); _textureSampler = effect.GetVariableByName("g_TextureSampler").AsSampler(); _hasTexture = effect.GetVariableByName("g_HasTexture").AsScalar(); _hasMask = effect.GetVariableByName("g_HasMask").AsScalar(); _isInstanced = effect.GetVariableByName("g_IsInstanced").AsScalar(); _isColorTinted = effect.GetVariableByName("g_IsColorTinted").AsScalar(); _globalLight = effect.GetVariableByName("g_GlobalLight"); _lightViewProjectionMatrix = effect.GetVariableByName("g_LightViewProjectionMatrix").AsMatrix(); //Set the states to Unknown initially. _currentDrawingState = DrawingState.Unknown; _currentTopologyState = PrimitiveTopologyState.Unknown; //Set the default of the g_PostWorldMatrix to Identity, so it isn't required to be set. _postWorldMatrix.SetMatrix(Matrix.Identity); //Setup shadow map technique. var shadowEffect = deviceManager.ShadowEffect; _shadowMapStandard = shadowEffect.GetTechniqueByName("ShadowMapTechnique|Standard"); _shadowMapPrelit = shadowEffect.GetTechniqueByName("ShadowMapTechnique|Prelit"); _isShadowInstanced = shadowEffect.GetVariableByName("g_IsInstanced").AsScalar(); _shadowWorldMatrix = shadowEffect.GetVariableByName("g_WorldMatrix").AsMatrix(); _shadowHasMask = shadowEffect.GetVariableByName("g_HasMask").AsScalar(); _shadowMask = shadowEffect.GetVariableByName("g_Mask").AsShaderResource(); _shadowLightViewProjectionMatrix = shadowEffect.GetVariableByName("g_LightViewProjectionMatrix").AsMatrix(); }
private void UpdateShadowState(bool isPrelit) { _currentDrawingState = DrawingState.Unknown; _currentTopologyState = PrimitiveTopologyState.Unknown; _context.InputAssembler.InputLayout = isPrelit ? _vertexLayouts.PrelitLayout : _vertexLayouts.StandardLayout; _currentTechnique = isPrelit ? _shadowMapPrelit : _shadowMapStandard; _context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; }