Exemplo n.º 1
0
        public void Initialize()
        {
            var device  = _renderer.Device;
            var factory = device.ResourceFactory;

            BufferDescription vbDescription = new BufferDescription(
                4 * VertexPositionTextureColor.SizeInBytes,
                BufferUsage.VertexBuffer);

            vertexBuffer = AddDisposable(factory.CreateBuffer(vbDescription));

            BufferDescription ibDescription = new BufferDescription(
                4 * sizeof(ushort),
                BufferUsage.IndexBuffer);

            indexBuffer = AddDisposable(factory.CreateBuffer(ibDescription));

            var topLeft     = new Vector2(0, 0);
            var topRight    = new Vector2(0 + Size.X, 0);
            var bottomLeft  = new Vector2(0, 0 + Size.Y);
            var bottomRight = new Vector2(0 + Size.X, 0 + Size.Y);

            VertexPositionTextureColor[] quadVertices =
            {
                new VertexPositionTextureColor(topLeft,     new Vector2(0f, 0f), RgbaFloat.White),
                new VertexPositionTextureColor(topRight,    new Vector2(1f, 0f), RgbaFloat.White),
                new VertexPositionTextureColor(bottomLeft,  new Vector2(0f, 1f), RgbaFloat.White),
                new VertexPositionTextureColor(bottomRight, new Vector2(1f, 1f), RgbaFloat.White)
            };
            ushort[] quadIndices = { 0, 1, 2, 3 };

            device.UpdateBuffer(vertexBuffer, 0, quadVertices);
            device.UpdateBuffer(indexBuffer, 0, quadIndices);

            textCache   = AddDisposable(new TextCache(device));
            Font        = SystemFonts.CreateFont(FontName, FontSize, FontStyle);
            texture     = AddDisposable(textCache.GetTextTexture(Content, Font, TextAlignment, Color, Size));
            textureView = AddDisposable(device.ResourceFactory.CreateTextureView(texture));

            textureSet = AddDisposable(device.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                                    _renderer.Shader.TextureLayout,
                                                                                    textureView,
                                                                                    device.Aniso4xSampler)));
        }
Exemplo n.º 2
0
        public void Recreate()
        {
            var device = _renderer.Device;

            if (texture != null)
            {
                RemoveAndDispose(ref textureView);
                RemoveAndDispose(ref texture);
                RemoveAndDispose(ref textCache);
            }

            textCache   = AddDisposable(new TextCache(device));
            Font        = SystemFonts.CreateFont(FontName, FontSize, FontStyle);
            texture     = AddDisposable(textCache.GetTextTexture(Content, Font, TextAlignment, Color, Size));
            textureView = AddDisposable(device.ResourceFactory.CreateTextureView(texture));

            textureSet = AddDisposable(device.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                                    _renderer.Shader.TextureLayout,
                                                                                    textureView,
                                                                                    device.Aniso4xSampler)));
        }