public DrawContext(DeviceContext context, CommonInitParam initParam) { m_initParam = initParam; m_context = context; var d3d = m_initParam.D3D; m_mainVtxConst = DrawUtil.CreateConstantBuffer <_VertexShaderConst_Main>(d3d, m_maxInstanceCount); m_boneVtxConst = DrawUtil.CreateConstantBuffer(d3d, Utilities.SizeOf <Matrix>() * MaxBoneMatrices); m_modelVtxConst = DrawUtil.CreateConstantBuffer <_VertexShaderConst_Model>(d3d, 1); m_mainPixConst = DrawUtil.CreateConstantBuffer <_PixelShaderConst_Main>(d3d, m_maxInstanceCount); m_modelPixConst = DrawUtil.CreateConstantBuffer <_PixelShaderConst_Model>(d3d, 1); m_modelMinimapPixConst = DrawUtil.CreateConstantBuffer <_PixelShaderConst_ModelMinimap>(d3d, 1); m_instanceMainVtxConst = new _VertexShaderConst_Main[m_maxInstanceCount]; m_instanceMainPixConst = new _PixelShaderConst_Main[m_maxInstanceCount]; m_lastTextureSlots = new _TextureSlot[2]; for (int index = 0; index < m_lastTextureSlots.Count(); ++index) { m_lastTextureSlots[index] = _TextureSlot.Create(index); } }
public Factory(DrawSystem.D3DData d3d, DrawResourceRepository repository) { m_initParam.D3D = d3d; m_initParam.Repository = repository; m_initParam.WorldVtxConst = DrawUtil.CreateConstantBuffer <_VertexShaderConst_World>(d3d, 1); m_initParam.WorldPixConst = DrawUtil.CreateConstantBuffer <_PixelShaderConst_World>(d3d, 1); m_initParam.RasterizerState = new RasterizerState(d3d.Device, new RasterizerStateDescription() { CullMode = CullMode.Back, FillMode = FillMode.Solid, IsAntialiasedLineEnabled = false, // we do not use wireframe IsDepthClipEnabled = true, IsMultisampleEnabled = false, }); var renderModes = new[] { DrawSystem.RenderMode.Opaque, DrawSystem.RenderMode.Transparency }; m_initParam.BlendStates = new BlendState[renderModes.Length]; foreach (DrawSystem.RenderMode mode in renderModes) { int index = (int)mode; m_initParam.BlendStates[index] = _CreateBlendState(d3d, mode); } m_initParam.DepthStencilStates = new DepthStencilState[renderModes.Length]; foreach (DrawSystem.RenderMode mode in renderModes) { int index = (int)mode; m_initParam.DepthStencilStates[index] = _CreateDepthStencilState(d3d, mode); } { var shader = new Effect( "Std", d3d, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, 16, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 28, 0), new InputElement("TANGENT", 0, Format.R32G32B32_Float, 0, 1), new InputElement("BONEINDEX", 0, Format.R32G32B32A32_UInt, 0, 2), new InputElement("BONEWEIGHT", 0, Format.R32G32B32A32_Float, 16, 2), }, "Shader/VS_Std.fx", "Shader/PS_Std.fx"); repository.AddResource(shader); } { var shader = new Effect( "Minimap", d3d, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, 16, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 28, 0), new InputElement("TANGENT", 0, Format.R32G32B32_Float, 0, 1), new InputElement("BONEINDEX", 0, Format.R32G32B32A32_UInt, 0, 2), new InputElement("BONEWEIGHT", 0, Format.R32G32B32A32_Float, 16, 2), }, "Shader/VS_Std.fx", "Shader/PS_Minimap.fx"); repository.AddResource(shader); } { var shader = new Effect( "Debug", d3d, new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0), }, "Shader/VS_Debug.fx", "Shader/PS_Debug.fx"); repository.AddResource(shader); } }