Beispiel #1
0
        public UIRenderer(Spritebatch2D texture)
        {
            Texture = texture;

            Window.Changed += () => {
                matrix = new Matrix(Window.ProjectionSize, MIN_DEPTH, MAX_DEPTH);
            };
            matrix = new Matrix(Window.ProjectionSize, MIN_DEPTH, MAX_DEPTH);

            preVertexBuffer  = new CachedGPUBuffer(3, MAX_QUADS_PER_BUFFER, PrimitiveType.Quad);
            preTextureBuffer = new CachedGPUBuffer(2, MAX_QUADS_PER_BUFFER, PrimitiveType.Quad);
            preColorBuffer   = new CachedGPUBuffer(4, MAX_QUADS_PER_BUFFER, PrimitiveType.Quad);

            postVertexBuffer  = new CachedGPUBuffer(3, MAX_QUADS_PER_BUFFER, PrimitiveType.Quad);
            postTextureBuffer = new CachedGPUBuffer(2, MAX_QUADS_PER_BUFFER, PrimitiveType.Quad);
            postColorBuffer   = new CachedGPUBuffer(4, MAX_QUADS_PER_BUFFER, PrimitiveType.Quad);

            IndexBuffer sharedIndexBuffer = new IndexBuffer(MAX_QUADS_PER_BUFFER);

            preBuffer  = new BufferBatch(sharedIndexBuffer, preVertexBuffer, preColorBuffer, preTextureBuffer);
            postBuffer = new BufferBatch(sharedIndexBuffer, postVertexBuffer, postColorBuffer, postTextureBuffer);

            preBufferLength   = postBufferLength = 0;
            preRenderCount    = postRenderCount = 0;
            preBufferChanged  = postBufferChanged = false;
            preBufferEntries  = new Dictionary <Element, BufferEntry>( );
            postBufferEntries = new Dictionary <Element, BufferEntry>( );

            updateQueue = new Queue <Element>( );
        }
Beispiel #2
0
        public static void Init( )
        {
            vertexBuffer  = new ClientBuffer(2, MAX_VERTEX_COUNT, PrimitiveType.Quad);
            textureBuffer = new ClientBuffer(2, MAX_VERTEX_COUNT, PrimitiveType.Quad);
            colorBuffer   = new ClientBuffer(4, MAX_VERTEX_COUNT, PrimitiveType.Quad);
            buffer        = new BufferBatch(new IndexBuffer(MAX_VERTEX_COUNT), vertexBuffer, colorBuffer, textureBuffer);

            entityTextures[(int)MobType.OCTOPUS] = Assets.GetSprite("mobs/octopus");
            entityTextures[(int)MobType.CHEST]   = Assets.GetSprite("mobs/chest");
        }
Beispiel #3
0
        public static void Init()
        {
            startPositions = new int[] { 0, 0, 0 };
            renderCount    = 0;
            vertexCount    = 0;
            updateQueue    = new Queue <UIItem>();

            IndexBuffer sharedIndexBuffer = new IndexBuffer(MAX_QUADS);

            vertexBuffer  = new CachedGPUBuffer(2, MAX_QUADS, BufferPrimitiveType.Quad);
            textureBuffer = new CachedGPUBuffer(2, MAX_QUADS, BufferPrimitiveType.Quad);
            colorBuffer   = new CachedGPUBuffer(4, MAX_QUADS, BufferPrimitiveType.Quad);
            buffer        = new BufferBatch(sharedIndexBuffer, vertexBuffer, colorBuffer, textureBuffer);

            uiItems       = new Dictionary <Layer, List <UIItem> >();
            uiItemsOffset = new Dictionary <Layer, int>();
            indexUsage    = new List <Tuple <UIItem, int> >[] { new List <Tuple <UIItem, int> >(), new List <Tuple <UIItem, int> >(), new List <Tuple <UIItem, int> >() };
        }
Beispiel #4
0
        private void Window_Changed()
        {
            matrix.UpdateProjection(Window.ProjectionSize);
            matrix.CalculateMVP();

            if (2 * Window.Ratio / DRAW_WIDTH != VertexSize)
            {
                VertexSize    = 2 * Window.Ratio / DRAW_WIDTH;
                DrawSize      = new Size(DRAW_WIDTH + 2, Mathi.Ceil(DRAW_WIDTH / Window.Ratio + 1));
                drawThreshold = new Vector2(DrawSize.Width / 2f, DrawSize.Height / 2f);

                mainBuffer?.Dispose();
                mainTextureBuffer = new CachedGPUBuffer(2, DrawSize.Area * 2, BufferPrimitiveType.Quad);
                mainBuffer        = new BufferBatch(new IndexBuffer(DrawSize.Area * 2), new GPUBuffer(2, DrawSize.Area * 2, BufferPrimitiveType.Quad, GenerateMainVerticies()), mainTextureBuffer);

                foregroundBuffer?.Dispose();
                foregroundTextureBuffer = new CachedGPUBuffer(2, DrawSize.Area, BufferPrimitiveType.Quad);
                foregroundBuffer        = new BufferBatch(new IndexBuffer(DrawSize.Area), new GPUBuffer(2, DrawSize.Area, BufferPrimitiveType.Quad, GenerateForegroundVerticies()), foregroundTextureBuffer);

                UpdateTextureBuffer();
            }
        }
Beispiel #5
0
 public void Draw(BufferBatch buffer, Texture2D texture, Matrix matrix, int count, int offset, bool alphaBlending = true)
 {
     Draw(buffer.IndexBuffer, buffer.VertexBuffer, buffer.TextureBuffer, buffer.ColorBuffer, texture, matrix, count, offset, alphaBlending);
 }
Beispiel #6
0
 public void Draw(BufferBatch buffer, Texture2D texture, Matrix matrix, bool alphaBlending = true)
 {
     Draw(buffer, texture, matrix, buffer.IndexBuffer.Length, 0, alphaBlending);
 }
Beispiel #7
0
 public void Draw(BufferBatch batch, int count, bool alphablending = true)
 {
     Draw(batch.VertexBuffer, batch.SizeBuffer, batch.ColorBuffer, count, alphablending);
 }
Beispiel #8
0
 public void Draw(BufferBatch batch, bool alphablending = true)
 {
     Draw(batch.VertexBuffer, batch.SizeBuffer, batch.ColorBuffer, batch.SizeBuffer.Length, alphablending);
 }