示例#1
0
    public void DrawRectangle(Span <Vertex2d> corners,
                              ITexture texture,
                              ITexture mask             = null,
                              SamplerType2d samplerType = SamplerType2d.CLAMP,
                              bool blending             = true)
    {
        var samplerState = getSamplerState(samplerType);

        if (texture != null && mask != null)
        {
            Trace.Assert(blending);
            _device.SetMaterial(texturedWithMaskMaterial);
            _device.SetSamplerState(0, samplerState);
            _device.SetSamplerState(1, samplerState);
            _device.SetTexture(0, texture);
            _device.SetTexture(1, mask);
        }
        else if (texture != null)
        {
            if (blending)
            {
                _device.SetMaterial(texturedMaterial);
            }
            else
            {
                _device.SetMaterial(texturedWithoutBlendingMaterial);
            }

            _device.SetSamplerState(0, samplerState);
            _device.SetTexture(0, texture);
        }
        else
        {
            _device.SetMaterial(untexturedMaterial);
        }

        DrawRectangle(corners);

        if (texture != null)
        {
            _device.SetTexture(0, Textures.InvalidTexture);
        }

        if (mask != null)
        {
            _device.SetTexture(1, Textures.InvalidTexture);
        }
    }
示例#2
0
    public void Bind([MaybeNull] WorldCamera camera, RenderingDevice device, IList <Light3d> lights,
                     MdfRenderOverrides overrides = null)
    {
        device.SetMaterial(mDeviceMaterial);

        BindShader(camera, device, lights, overrides);
    }
示例#3
0
    private void BindLineMaterial(IGameViewport viewport, PackedLinearColorA color, bool occludedOnly = false)
    {
        if (occludedOnly)
        {
            _device.SetMaterial(_lineOccludedMaterial);
        }
        else
        {
            _device.SetMaterial(_lineMaterial);
        }

        Shape3dGlobals globals;

        globals.viewProj = viewport.Camera.GetViewProj();
        globals.colors   = color.ToRGBA();

        _device.SetVertexShaderConstants(0, ref globals);
    }
    private void RenderParticles(PartSysEmitter emitter)
    {
        var it         = emitter.NewIterator();
        var totalCount = emitter.GetActiveCount();

        if (totalCount == 0)
        {
            return;
        }

        // Lazily initialize render state
        if (!emitter.HasRenderState())
        {
            emitter.SetRenderState(
                new QuadEmitterRenderState(_device, emitter));
        }

        var renderState = (QuadEmitterRenderState)emitter.GetRenderState();

        using var spriteMemory = MemoryPool.Rent(4 * totalCount);
        var sUpdateBuffer = spriteMemory.Memory.Span.Slice(0, 4 * totalCount);

        var i = 0;

        while (it.HasNext())
        {
            var particleIdx = it.Next();
            FillVertex(emitter, particleIdx, sUpdateBuffer, i);
            i += 4;
        }

        renderState.vertexBuffer.Resource.Update <SpriteVertex>(sUpdateBuffer);

        _device.SetMaterial(renderState.material);
        renderState.bufferBinding.Resource.Bind();

        // Draw the batch
        _device.DrawIndexed(PrimitiveType.TriangleList, 4 * totalCount, 6 * totalCount);
    }
示例#5
0
    public void Render(IGameViewport viewport, TileRect tileRect)
    {
        _device.SetMaterial(_material.Resource);
        var viewProj = viewport.Camera.GetViewProj();

        _device.SetVertexShaderConstants(0, ref viewProj);

        using var sectorIt = new SectorIterator(tileRect);
        foreach (var sector in sectorIt.EnumerateSectors())
        {
            if (!sector.IsValid)
            {
                continue;
            }

            if (!_sectorDebugState.TryGetValue(sector.Loc, out var renderingState))
            {
                renderingState = BuildSubTileMesh(_device, _material.Resource.VertexShader, sector.Sector);
                _sectorDebugState.Add(sector.Loc, renderingState);
            }

            renderingState.Render(_device);
        }
    }