/// <summary> /// /// </summary> void SetupShadersAndLayouts() { ps = PixelShader == null ? null : new D3DPixelShader(device.Device, PixelShader.Bytecode); vs = VertexShader == null ? null : new D3DVertexShader(device.Device, VertexShader.Bytecode); gs = GeometryShader == null ? null : new D3DGeometryShader(device.Device, GeometryShader.Bytecode); hs = HullShader == null ? null : new D3DHullShader(device.Device, HullShader.Bytecode); ds = DomainShader == null ? null : new D3DDomainShader(device.Device, DomainShader.Bytecode); cs = ComputeShader == null ? null : new D3DComputeShader(device.Device, ComputeShader.Bytecode); if (cs != null) { if (ps != null || vs != null || gs != null || hs != null || ds != null) { throw new InvalidOperationException("If ComputeShader is set, other shader must be set null."); } } else { if (vs == null) { throw new InvalidOperationException("Vertex shader must be set."); } } if (VertexInputElements == null) { inputLayout = null; } else { inputLayout = new InputLayout(device.Device, VertexShader.Bytecode, VertexInputElement.Convert(VertexInputElements)); } if (VertexOutputElements != null) { if (GeometryShader == null) { throw new InvalidOperationException("Geometry shader is required for vertex output."); } var outputElements = VertexOutputElement.Convert(VertexOutputElements); int maxBuffers = outputElements.Max(oe => oe.OutputSlot) + 1; var bufferedStrides = new int[maxBuffers]; for (int i = 0; i < maxBuffers; i++) { bufferedStrides[i] = outputElements .Where(oe1 => oe1.OutputSlot == i) .Sum(oe2 => oe2.ComponentCount) * 4; } gs = new D3DGeometryShader(device.Device, GeometryShader.Bytecode, outputElements, bufferedStrides, RasterizedStream); } }
void LoadContent() { fontTexture = device.Game.Content.Load <Texture2D>(@"debugFont.tga"); shader = Game.Content.Load <Ubershader>(@"spriteBatch.hlsl"); DisposePSO(); foreach (SpriteBlend blend in Enum.GetValues(typeof(SpriteBlend))) { var ps = new PipelineState(Game.GraphicsDevice); ps.RasterizerState = RasterizerState.CullNone; ps.DepthStencilState = DepthStencilState.None; if (blend == SpriteBlend.Opaque) { ps.BlendState = BlendState.Opaque; } if (blend == SpriteBlend.AlphaBlend) { ps.BlendState = BlendState.AlphaBlend; } if (blend == SpriteBlend.AlphaBlendPreMul) { ps.BlendState = BlendState.AlphaBlendPreMul; } if (blend == SpriteBlend.Additive) { ps.BlendState = BlendState.Additive; } if (blend == SpriteBlend.Screen) { ps.BlendState = BlendState.Screen; } if (blend == SpriteBlend.Multiply) { ps.BlendState = BlendState.Multiply; } if (blend == SpriteBlend.NegMultiply) { ps.BlendState = BlendState.NegMultiply; } if (blend == SpriteBlend.ClearAlpha) { ps.BlendState = BlendState.ClearAlpha; } ps.VertexInputElements = VertexInputElement.FromStructure(typeof(SpriteVertex)); ps.PixelShader = shader.GetPixelShader(""); ps.VertexShader = shader.GetVertexShader(""); ps.Primitive = Primitive.TriangleList; pipelineStates.Add(blend, ps); } }
/// <summary> /// /// </summary> /// <param name="scene"></param> /// <param name="bakeFunc"></param> public SceneDrawer(GraphicsDevice device, Scene scene) { Game = device.Game; this.device = device; this.scene = scene; int meshCount = scene.Meshes.Count; ibs = new IndexBuffer[scene.Meshes.Count]; vbs = new VertexBuffer[scene.Meshes.Count]; vie = VertexInputElement.FromStructure(typeof(TVertex)); materials = new TMaterial[scene.Materials.Count]; // convert materials : for (int i = 0; i < scene.Materials.Count; i++) { materials[i] = Convert(scene.Materials[i]); } // convert meshes to vb in ib : for (int i = 0; i < meshCount; i++) { var mesh = scene.Meshes[i]; // index buffer : ibs[i] = new IndexBuffer(device, mesh.IndexCount); ibs[i].SetData(mesh.GetIndices()); // vertex buffer : vbs[i] = new VertexBuffer(device, typeof(TVertex), mesh.VertexCount); var vdata = new TVertex[mesh.VertexCount]; for (int j = 0; j < mesh.VertexCount; j++) { vdata[j] = Convert(mesh.Vertices[j]); } vbs[i].SetData(vdata); } localMatricies = new Matrix[scene.Nodes.Count]; worldMatricies = new Matrix[scene.Nodes.Count]; boneMatricies = new Matrix[scene.Nodes.Count]; EvaluateScene(); }
/// <summary> /// Initialization /// </summary> public override void Initialize() { base.Initialize(); var dev = Game.GraphicsDevice; effect = Game.Content.Load <Ubershader>("debugRender.hlsl"); factory = new StateFactory(effect, typeof(RenderFlags), Primitive.LineList, VertexInputElement.FromStructure(typeof(LineVertex)), BlendState.AlphaBlend, RasterizerState.CullNone); constData = new ConstData(); constBuffer = new ConstantBuffer(dev, typeof(ConstData)); // create vertex buffer : vertexBuffer = new VertexBuffer(dev, typeof(LineVertex), vertexBufferSize, VertexBufferOptions.Dynamic); vertexDataAccum.Capacity = vertexBufferSize; }