private void CreateResources() { ResourceFactory factory = device.ResourceFactory; vertexBuffer = factory.CreateBuffer(new BufferDescription(MAX_BATCH * PrimitivesInfo.GetSize(typeof(VertexPositionColorTexture)), BufferUsage.VertexBuffer)); indexBuffer = factory.CreateBuffer(new BufferDescription(MAX_BATCH * sizeof(ushort), BufferUsage.IndexBuffer)); worldMatrixBuffer = factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); var vld = PrimitivesInfo.GetVertexLayoutDescription(typeof(VertexPositionColorTexture)); VertexLayoutDescription vertexLayoutDescription; if (vld.HasValue) { vertexLayoutDescription = vld.Value; } else { throw new NotSupportedException("VertexLayout for VertexPositionColor not found"); } LoadShaders(); resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription(new ResourceLayoutElementDescription("SpriteTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("SpriteSampler", ResourceKind.Sampler, ShaderStages.Fragment))); worldResourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription(new ResourceLayoutElementDescription("World", ResourceKind.UniformBuffer, ShaderStages.Vertex))); worldResourceSet = device.ResourceFactory.CreateResourceSet(new ResourceSetDescription(worldResourceLayout, worldMatrixBuffer)); var description = new GraphicsPipelineDescription { BlendState = BlendStateDescription.SingleAlphaBlend, DepthStencilState = new DepthStencilStateDescription(true, true, ComparisonKind.LessEqual), RasterizerState = new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, true, false), PrimitiveTopology = PrimitiveTopology.TriangleList, ResourceLayouts = new[] { worldResourceLayout, resourceLayout }, ShaderSet = new ShaderSetDescription(new VertexLayoutDescription[] { vertexLayoutDescription }, new Veldrid.Shader[] { vertexShader, fragmentShader }), Outputs = device.SwapchainFramebuffer.OutputDescription }; pipeline = factory.CreateGraphicsPipeline(description); commandList = factory.CreateCommandList(); }
public VertexArray(GraphicsDevice device, int capacity, PrimitiveTopology geometryType = PrimitiveTopology.PointList) { this.device = device; factory = device.ResourceFactory; this.geometryType = geometryType; this.capacity = (uint)capacity; var vShader = BuiltinShaderRepository.GetBuiltinShader(typeof(T), ShaderStages.Vertex); var fShader = BuiltinShaderRepository.GetBuiltinShader(typeof(T), ShaderStages.Fragment); if (vShader == null || fShader == null) { throw new NotSupportedException("Not a supported vertex type"); } Shaders = new List <Shader> { vShader, fShader }; uint vertexSize = PrimitivesInfo.GetSize(typeof(T)); if (vertexSize == 0) { throw new NotSupportedException("Not a supported vertex type"); } var vld = PrimitivesInfo.GetVertexLayoutDescription(typeof(T)); if (!vld.HasValue) { throw new NotSupportedException("Not a supported vertex type"); } var resourceLayoutDescription = GetResourceLayoutDescription(typeof(T)); CreateResources(vertexSize, resourceLayoutDescription, vld.Value); }