Esempio n. 1
0
 /// <summary>
 /// Function to retrieve a draw indexed call from the pool and,  initialize it.
 /// </summary>
 /// <param name="renderable">The renderable to evaluate.</param>
 /// <param name="batchState">The current global state for the batch.</param>
 /// <param name="indexBuffer">The index buffer to use when creating the draw call.</param>
 /// <param name="vertexBuffer">The vertex buffer binding to use when creating the draw call.</param>
 /// <param name="layout">The vertex input layout.</param>
 /// <returns>The draw call.</returns>
 public GorgonDrawIndexCall GetDrawIndexCall(BatchRenderable renderable, Gorgon2DBatchState batchState, GorgonIndexBuffer indexBuffer, GorgonVertexBufferBinding vertexBuffer, GorgonInputLayout layout)
 {
     SetCommonStates(_drawIndexBuilder, renderable, batchState, null);
     return(_drawIndexBuilder.VertexBuffer(layout, vertexBuffer)
            .IndexBuffer(indexBuffer)
            .Build(_drawIndexAllocator));
 }
Esempio n. 2
0
        /// <summary>
        /// Function queue a renderable item for rendering.
        /// </summary>
        /// <param name="renderable">The renderable to queue.</param>
        public void QueueRenderable(BatchRenderable renderable)
        {
            Gorgon2DVertex[] vertices = renderable.Vertices;
            int vertexCount           = renderable.ActualVertexCount;
            int lastVertex            = _allocatedVertexCount + _currentVertexIndex + vertexCount;

            // Ensure we actually have the room to cache the renderable vertices.
            if (lastVertex >= _vertexCache.Length)
            {
                ExpandCache(lastVertex - _vertexCache.Length);
            }

            for (int i = 0; i < vertexCount; ++i, ++_allocatedVertexCount)
            {
                _vertexCache[_currentVertexIndex++] = vertices[i];
            }

            if (renderable.IndexCount != 0)
            {
                _indexCount += renderable.IndexCount;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Function to set up common states for a draw call type.
        /// </summary>
        /// <typeparam name="TB">The type of draw call builder.</typeparam>
        /// <typeparam name="TD">The type of draw call to return.</typeparam>
        /// <param name="builder">The builder to pass in.</param>
        /// <param name="renderable">The renderable being rendered.</param>
        /// <param name="batchState">The current batch level state.</param>
        /// <param name="renderer">The renderer used to send renderable data to the GPU.</param>
        private void SetCommonStates <TB, TD>(GorgonDrawCallBuilderCommon <TB, TD> builder, BatchRenderable renderable, Gorgon2DBatchState batchState, ObjectRenderer renderer)
            where TB : GorgonDrawCallBuilderCommon <TB, TD>
            where TD : GorgonDrawCallCommon
        {
            // If we haven't specified values for our first texture and sampler, then do so now.
            batchState.PixelShaderState.RwSrvs[0]     = renderable.Texture ?? _defaultTexture;
            batchState.PixelShaderState.RwSamplers[0] = renderable.TextureSampler ?? GorgonSamplerState.Default;

            builder.ConstantBuffers(ShaderType.Vertex, batchState.VertexShaderState.RwConstantBuffers)
            .ConstantBuffers(ShaderType.Pixel, batchState.PixelShaderState.RwConstantBuffers)
            .ShaderResources(ShaderType.Vertex, batchState.VertexShaderState.RwSrvs)
            .ShaderResources(ShaderType.Pixel, batchState.PixelShaderState.RwSrvs)
            .SamplerStates(ShaderType.Vertex, batchState.VertexShaderState.RwSamplers)
            .SamplerStates(ShaderType.Pixel, batchState.PixelShaderState.RwSamplers)
            .PipelineState(_stateBuilder.PixelShader(batchState.PixelShaderState.Shader)
                           .VertexShader(batchState.VertexShaderState.Shader)
                           .DepthStencilState(batchState.DepthStencilState)
                           .RasterState(batchState.RasterState)
                           .BlendState(batchState.BlendState)
                           .PrimitiveType(renderable.PrimitiveType));

            // If we don't supply a renderer type, then don't assign a vertex buffer.
            if (renderer == null)
            {
                return;
            }

            builder.VertexBuffer(_inputLayout, renderer.VertexBuffer);
        }
Esempio n. 4
0
 /// <summary>
 /// Function to retrieve a draw indexed call from the pool and,  initialize it.
 /// </summary>
 /// <param name="renderable">The renderable to evaluate.</param>
 /// <param name="batchState">The current global state for the batch.</param>
 /// <param name="renderer">The renderer that will be </param>
 /// <returns>The draw call.</returns>
 public GorgonDrawIndexCall GetDrawIndexCall(BatchRenderable renderable, Gorgon2DBatchState batchState, ObjectRenderer renderer)
 {
     SetCommonStates(_drawIndexBuilder, renderable, batchState, renderer);
     return(_drawIndexBuilder.IndexBuffer(renderer.IndexBuffer)
            .Build(_drawIndexAllocator));
 }