Beispiel #1
0
            public DeviceResourceContext(GraphicsDevice device, VertexDeclaration declaration, int vertexCount, int indexStructSize, int indexCount)
            {
                var vertexSize = declaration.CalculateSize();

                VertexCount = vertexCount;
                IndexCount  = indexCount;

                // Workaround: due to graphics refactor sometimes empty emitters will try to draw 0 particles
                // TODO Avoid calling this method if LivingParticles == 0
                {
                    if (VertexCount <= 0)
                    {
                        VertexCount = 1;
                    }
                    if (IndexCount <= 0)
                    {
                        IndexCount = 1;
                    }
                }

                var vertexBuffer = Buffer.Vertex.New(device, VertexCount * vertexSize, GraphicsResourceUsage.Dynamic).DisposeBy(this);
                var indexBuffer  = Buffer.Index.New(device, IndexCount * indexStructSize, GraphicsResourceUsage.Dynamic).DisposeBy(this);

                IndexBuffer  = new IndexBufferBinding(indexBuffer, indexStructSize == sizeof(int), IndexCount);
                VertexBuffer = new VertexBufferBinding(vertexBuffer, declaration, VertexCount, vertexSize);
            }
            public DeviceResourceContext(GraphicsDevice device, VertexDeclaration declaration, int vertexCount, int indexStructSize, int indexCount)
            {
                var vertexSize = declaration.CalculateSize();

                VertexCount = vertexCount;
                IndexCount  = indexCount;

                VertexBuffer = Buffer.Vertex.New(device, VertexCount * vertexSize, GraphicsResourceUsage.Dynamic).DisposeBy(this);

                IndexBuffer = Buffer.Index.New(device, IndexCount * indexStructSize, GraphicsResourceUsage.Dynamic).DisposeBy(this);

                dirty = true;
            }
Beispiel #3
0
        protected BatchBase(GraphicsDevice device, EffectBytecode defaultEffectByteCode, EffectBytecode defaultEffectByteCodeSRgb, ResourceBufferInfo resourceBufferInfo, VertexDeclaration vertexDeclaration, int indexSize = sizeof(short))
        {
            if (defaultEffectByteCode == null)
            {
                throw new ArgumentNullException(nameof(defaultEffectByteCode));
            }
            if (defaultEffectByteCodeSRgb == null)
            {
                throw new ArgumentNullException(nameof(defaultEffectByteCodeSRgb));
            }
            if (resourceBufferInfo == null)
            {
                throw new ArgumentNullException("resourceBufferInfo");
            }
            if (vertexDeclaration == null)
            {
                throw new ArgumentNullException("vertexDeclaration");
            }

            graphicsDevice  = device;
            mutablePipeline = new MutablePipelineState(device);
            // TODO GRAPHICS REFACTOR Should we initialize FX lazily?
            DefaultEffect = new EffectInstance(new Effect(device, defaultEffectByteCode)
            {
                Name = "BatchDefaultEffect"
            });
            DefaultEffectSRgb = new EffectInstance(new Effect(device, defaultEffectByteCodeSRgb)
            {
                Name = "BatchDefaultEffectSRgb"
            });

            drawsQueue   = new ElementInfo[resourceBufferInfo.BatchCapacity];
            drawTextures = new Texture[resourceBufferInfo.BatchCapacity];

            TextureComparer     = new TextureIdComparer();
            BackToFrontComparer = new SpriteBackToFrontComparer();
            FrontToBackComparer = new SpriteFrontToBackComparer();

            // set the vertex layout and size
            indexStructSize  = indexSize;
            vertexStructSize = vertexDeclaration.CalculateSize();

            // Creates the vertex buffer (shared by within a device context).
            ResourceContext = graphicsDevice.GetOrCreateSharedData(GraphicsDeviceSharedDataType.PerContext, resourceBufferInfo.ResourceKey, d => new DeviceResourceContext(graphicsDevice, vertexDeclaration, resourceBufferInfo));
        }
            public void CreateVAO(GraphicsDevice device, Effect effect, VertexDeclaration declaration, int indexStructSize)
            {
                if (!dirty)
                {
                    return;
                }
                dirty = false;

                var vertexSize = declaration.CalculateSize();

                EffectInputSignature = effect.InputSignature;

                var indexBufferBinding  = new IndexBufferBinding(IndexBuffer, indexStructSize == sizeof(int), IndexBuffer.Description.SizeInBytes / indexStructSize);
                var vertexBufferBinding = new VertexBufferBinding(VertexBuffer, declaration, VertexCount, vertexSize);

                // Creates a VAO
                VertexArrayObject = VertexArrayObject.New(device, effect.InputSignature, indexBufferBinding, vertexBufferBinding).DisposeBy(this);
            }
Beispiel #5
0
        void CreateDeviceObjects()
        {
            // set up a commandlist
            commandList = context.CommandList;

            // compile de shader
            imShader = new EffectInstance(effectSystem.LoadEffect("ImGuiShader").WaitForResult());
            imShader.UpdateEffect(device);

            var layout = new VertexDeclaration(
                VertexElement.Position <Vector2>(),
                VertexElement.TextureCoordinate <Vector2>(),
                VertexElement.Color(PixelFormat.R8G8B8A8_UNorm)
                );

            imVertLayout = layout;

            // de pipeline desc
            var pipeline = new PipelineStateDescription()
            {
                BlendState = BlendStates.NonPremultiplied,

                RasterizerState = new RasterizerStateDescription()
                {
                    CullMode  = CullMode.None,
                    DepthBias = 0,
                    FillMode  = FillMode.Solid,
                    MultisampleAntiAliasLine = false,
                    ScissorTestEnable        = true,
                    SlopeScaleDepthBias      = 0,
                },

                PrimitiveType     = PrimitiveType.TriangleList,
                InputElements     = imVertLayout.CreateInputElements(),
                DepthStencilState = DepthStencilStates.Default,

                EffectBytecode = imShader.Effect.Bytecode,
                RootSignature  = imShader.RootSignature,

                Output = new RenderOutputDescription(PixelFormat.R8G8B8A8_UNorm)
            };

            // finally set up the pipeline
            var pipelineState = PipelineState.New(device, ref pipeline);

            imPipeline = pipelineState;

            var is32Bits           = false;
            var indexBuffer        = Xenko.Graphics.Buffer.Index.New(device, INITIAL_INDEX_BUFFER_SIZE * sizeof(ushort), GraphicsResourceUsage.Dynamic);
            var indexBufferBinding = new IndexBufferBinding(indexBuffer, is32Bits, 0);

            indexBinding = indexBufferBinding;

            var vertexBuffer        = Xenko.Graphics.Buffer.Vertex.New(device, INITIAL_VERTEX_BUFFER_SIZE * imVertLayout.CalculateSize(), GraphicsResourceUsage.Dynamic);
            var vertexBufferBinding = new VertexBufferBinding(vertexBuffer, layout, 0);

            vertexBinding = vertexBufferBinding;
        }