Example #1
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, DefaultEffect.Effect, vertexDeclaration, resourceBufferInfo, indexStructSize));
        }
Example #2
0
        protected BatchBase(GraphicsDevice device, Shaders.EffectBytecode defaultEffectByteCode, ResourceBufferInfo resourceBufferInfo, VertexDeclaration vertexDeclaration, int indexSize = sizeof(short))
        {
            if (resourceBufferInfo == null)
            {
                throw new ArgumentNullException("resourceBufferInfo");
            }
            if (vertexDeclaration == null)
            {
                throw new ArgumentNullException("vertexDeclaration");
            }

            GraphicsDevice = device;
            DefaultEffect  = new Effect(device, defaultEffectByteCode)
            {
                Name = "BatchDefaultEffect"
            };

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

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

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

            parameters = new ParameterCollection();

            // Creates the vertex buffer (shared by within a device context).
            ResourceContext = GraphicsDevice.GetOrCreateSharedData(GraphicsDeviceSharedDataType.PerContext, resourceBufferInfo.ResourceKey, () => new DeviceResourceContext(GraphicsDevice, DefaultEffect, vertexDeclaration, resourceBufferInfo, indexStructSize));
        }
Example #3
0
            public DeviceResourceContext(GraphicsDevice device, Effect effect, VertexDeclaration declaration, ResourceBufferInfo resourceBufferInfo, int indexStructSize)
            {
                var vertexSize = declaration.CalculateSize();

                VertexCount          = resourceBufferInfo.VertexCount;
                IndexCount           = resourceBufferInfo.IndexCount;
                IsIndexBufferDynamic = resourceBufferInfo.IsIndexBufferDynamic;

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

                if (IsIndexBufferDynamic)
                {
                    IndexBuffer = Buffer.Index.New(device, IndexCount * indexStructSize, GraphicsResourceUsage.Dynamic).DisposeBy(this);
                }
                else
                {
                    IndexBuffer        = Buffer.Index.New(device, resourceBufferInfo.StaticIndices).DisposeBy(this);
                    IndexBuffer.Reload = graphicsResource => ((Buffer)graphicsResource).Recreate(resourceBufferInfo.StaticIndices);
                }

                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);
            }
Example #4
0
            public DeviceResourceContext(GraphicsDevice device, VertexDeclaration declaration, ResourceBufferInfo resourceBufferInfo)
            {
                VertexDeclaration    = declaration;
                VertexCount          = resourceBufferInfo.VertexCount;
                IndexCount           = resourceBufferInfo.IndexCount;
                IsIndexBufferDynamic = resourceBufferInfo.IsIndexBufferDynamic;

                if (!IsIndexBufferDynamic)
                {
                    IndexBuffer        = Buffer.Index.New(device, resourceBufferInfo.StaticIndices).DisposeBy(this);
                    IndexBuffer.Reload = graphicsResource => ((Buffer)graphicsResource).Recreate(resourceBufferInfo.StaticIndices);
                }

                InputElements = declaration.CreateInputElements();
            }