Exemple #1
0
        public override void Issue(DeviceManager manager)
        {
            if (Count > 0)
            {
                using (manager.ApplyMaterial(Material)) {
                    var hwb = _SoftwareBuffer.HardwareBuffer;
                    if (hwb == null)
                    {
                        throw new ThreadStateException("Could not get a hardware buffer for this batch");
                    }

                    hwb.SetActive(manager.Device);
                    foreach (var da in _DrawArguments)
                    {
                        manager.Device.DrawIndexedPrimitives(da.PrimitiveType, 0, da.VertexOffset, da.VertexCount, da.IndexOffset, da.PrimitiveCount);
                    }
                    hwb.SetInactive(manager.Device);
                }
            }

            _DrawArgumentsListPool.Release(ref _DrawArguments);
            _SoftwareBuffer = null;

            base.Issue(manager);
        }
Exemple #2
0
        public override void Issue(DeviceManager manager)
        {
            using (manager.ApplyMaterial(Material)) {
                var clearOptions = default(ClearOptions);

                if (ClearColor.HasValue)
                {
                    clearOptions |= ClearOptions.Target;
                }
                if (ClearZ.HasValue)
                {
                    clearOptions |= ClearOptions.DepthBuffer;
                }
                if (ClearStencil.HasValue)
                {
                    clearOptions |= ClearOptions.Stencil;
                }

                manager.Device.Clear(
                    clearOptions,
                    ClearColor.GetValueOrDefault(Color.Black), ClearZ.GetValueOrDefault(0), ClearStencil.GetValueOrDefault(0)
                    );
            }

            base.Issue(manager);
        }
        public override void Issue(DeviceManager manager)
        {
            if (_DrawCalls.Count == 0)
            {
                return;
            }

            if (_BatchSetup != null)
            {
                _BatchSetup(manager, _UserData);
            }

            using (manager.ApplyMaterial(Material)) {
                var device = manager.Device;

                foreach (var call in _DrawCalls)
                {
                    if (call.Indices != null)
                    {
                        device.DrawUserIndexedPrimitives <T>(
                            call.PrimitiveType, call.Vertices, call.VertexOffset, call.VertexCount, call.Indices, call.IndexOffset, call.PrimitiveCount
                            );
                    }
                    else
                    {
                        device.DrawUserPrimitives <T>(
                            call.PrimitiveType, call.Vertices, call.VertexOffset, call.PrimitiveCount
                            );
                    }
                }
            }

            base.Issue(manager);
        }
        public override void Issue(DeviceManager manager)
        {
            if (_DrawCalls.Count == 0)
            {
                return;
            }

            if (_BatchSetup != null)
            {
                _BatchSetup(manager, _UserData);
            }

            using (manager.ApplyMaterial(Material)) {
                var device = manager.Device;

                foreach (var call in _DrawCalls)
                {
#if PSM
                    device.SetVertexBuffer(call.VertexBuffer);
#elif SDL2
                    // TODO: Check if we _really_ have to implement this for MG-SDL2 -flibit
                    if (call.VertexOffset != 0)
                    {
                        System.Console.WriteLine("OH GOD WHY");
                    }
                    device.SetVertexBuffer(call.VertexBuffer);
#else
                    device.SetVertexBuffer(call.VertexBuffer, call.VertexOffset);
#endif
                    device.Indices = call.IndexBuffer;

                    if (call.IndexBuffer != null)
                    {
                        device.DrawIndexedPrimitives(call.PrimitiveType, call.BaseVertex, call.MinVertexIndex, call.NumVertices, call.StartIndex, call.PrimitiveCount);
                    }
                    else
                    {
                        device.DrawPrimitives(call.PrimitiveType, call.StartVertex, call.PrimitiveCount);
                    }
                }

                device.SetVertexBuffer(null);
                device.Indices = null;
            }

            base.Issue(manager);
        }
Exemple #5
0
        public override void Issue(DeviceManager manager)
        {
            if (_DrawCalls.Count == 0)
            {
                return;
            }

            if (_BatchSetup != null)
            {
                _BatchSetup(manager, _UserData);
            }

            using (manager.ApplyMaterial(Material)) {
                var device = manager.Device;

                PrimitiveDrawCall <T> call;
                for (int i = 0, c = _DrawCalls.Count; i < c; i++)
                {
                    _DrawCalls.GetItem(i, out call);

                    if (call.BeforeDraw != null)
                    {
                        call.BeforeDraw(manager, call.UserData);
                    }

                    if (call.Indices != null)
                    {
                        device.DrawUserIndexedPrimitives <T>(
                            call.PrimitiveType, call.Vertices, call.VertexOffset, call.VertexCount, call.Indices, call.IndexOffset, call.PrimitiveCount
                            );
                    }
                    else
                    {
                        device.DrawUserPrimitives <T>(
                            call.PrimitiveType, call.Vertices, call.VertexOffset, call.PrimitiveCount
                            );
                    }
                }
            }

            base.Issue(manager);
        }
Exemple #6
0
        public override void Issue(DeviceManager manager)
        {
            if (_BatchSetup != null)
            {
                _BatchSetup(manager, _UserData);
            }

            if (_DrawCalls.Count > 0)
            {
                using (manager.ApplyMaterial(Material)) {
                    var device = manager.Device;

                    NativeDrawCall call;
                    for (int i = 0, c = _DrawCalls.Count; i < c; i++)
                    {
                        _DrawCalls.GetItem(i, out call);

                        if (call.InstanceCount.HasValue)
                        {
                            if (call.VertexBuffer3 != null)
                            {
                                device.SetVertexBuffers(
                                    call.VertexBuffer, new VertexBufferBinding(call.VertexBuffer2, call.VertexOffset2, 1),
                                    new VertexBufferBinding(call.VertexBuffer3, call.VertexOffset3, 1)
                                    );
                            }
                            else if (call.VertexBuffer2 != null)
                            {
                                device.SetVertexBuffers(
                                    call.VertexBuffer, new VertexBufferBinding(call.VertexBuffer2, call.VertexOffset2, 1)
                                    );
                            }
                            else
                            {
                                // FIXME: Throw?
                                device.SetVertexBuffers(call.VertexBuffer);
                            }
                            device.Indices = call.IndexBuffer;
                            device.DrawInstancedPrimitives(
                                call.PrimitiveType, call.BaseVertex, call.MinVertexIndex,
                                call.NumVertices, call.StartIndex, call.PrimitiveCount,
                                call.InstanceCount.Value
                                );
                            continue;
                        }

                        device.SetVertexBuffer(call.VertexBuffer, call.VertexOffset);
                        device.Indices = call.IndexBuffer;

                        if (call.IndexBuffer != null)
                        {
                            device.DrawIndexedPrimitives(call.PrimitiveType, call.BaseVertex, call.MinVertexIndex, call.NumVertices, call.StartIndex, call.PrimitiveCount);
                        }
                        else
                        {
                            device.DrawPrimitives(call.PrimitiveType, call.StartVertex, call.PrimitiveCount);
                        }
                    }

                    device.SetVertexBuffer(null);
                    device.Indices = null;
                }
            }

            if (_BatchTeardown != null)
            {
                _BatchTeardown(manager, _UserData);
            }

            base.Issue(manager);
        }
Exemple #7
0
        public override void Issue(DeviceManager manager)
        {
            if (IsCombined)
            {
                throw new InvalidOperationException("Batch was combined into another batch");
            }

            if (_DrawCalls.Count == 0)
            {
                return;
            }

            if (_Prepared == false)
            {
                throw new InvalidOperationException("Not prepared");
            }

            if (_BufferGenerator == null)
            {
                throw new InvalidOperationException("Already issued");
            }

            var device = manager.Device;

            IHardwareBuffer previousHardwareBuffer = null;

            // if (RenderTrace.EnableTracing)
            //    RenderTrace.ImmediateMarker("BitmapBatch.Issue(layer={0}, count={1})", Layer, _DrawCalls.Count);

            using (manager.ApplyMaterial(Material)) {
                TextureSet currentTexture = new TextureSet();
                var        paramSize      = manager.CurrentParameters.BitmapTextureSize;
                var        paramHalfTexel = manager.CurrentParameters.HalfTexel;

                foreach (var nb in _NativeBatches)
                {
                    if (nb.TextureSet != currentTexture)
                    {
                        currentTexture = nb.TextureSet;
                        var tex1 = currentTexture.Texture1;

                        device.Textures[0]      = tex1;
                        device.Textures[1]      = currentTexture.Texture2;
                        device.SamplerStates[0] = SamplerState;
                        device.SamplerStates[1] = SamplerState2;

                        var vSize = new Vector2(tex1.Width, tex1.Height);
                        paramSize.SetValue(vSize);
#if !SDL2
                        // This is only ever used by Blur, which is never used -flibit
                        paramHalfTexel.SetValue(new Vector2(1.0f / vSize.X, 1.0f / vSize.Y) * 0.5f);
#endif

                        manager.CurrentMaterial.Flush();
                    }

                    if (UseZBuffer)
                    {
                        var dss = device.DepthStencilState;
                        if (dss.DepthBufferEnable == false)
                        {
                            throw new InvalidOperationException("UseZBuffer set to true but depth buffer is disabled");
                        }
                    }

                    var swb = nb.SoftwareBuffer;
                    var hwb = swb.HardwareBuffer;
                    if (previousHardwareBuffer != hwb)
                    {
                        if (previousHardwareBuffer != null)
                        {
                            previousHardwareBuffer.SetInactive(device);
                        }

                        hwb.SetActive(device);
                        previousHardwareBuffer = hwb;
                    }

#if PSM
                    // MonoGame and PSM are both retarded.
                    device.ApplyState(false);
                    device.Textures.SetTextures(device);
                    device.SamplerStates.SetSamplers(device);

                    device._graphics.DrawArrays(
                        Sce.PlayStation.Core.Graphics.DrawMode.Triangles,
                        nb.IndexOffset, (nb.VertexCount / 4) * 6
                        );
#else
                    device.DrawIndexedPrimitives(
                        PrimitiveType.TriangleList, 0,
                        swb.HardwareVertexOffset + nb.LocalVertexOffset,
                        nb.VertexCount,
                        swb.HardwareIndexOffset + nb.LocalIndexOffset,
                        nb.VertexCount / 2
                        );
#endif
                }

                if (previousHardwareBuffer != null)
                {
                    previousHardwareBuffer.SetInactive(device);
                }
            }

            _BufferGenerator = null;

            base.Issue(manager);
        }