コード例 #1
0
    int UpdateBuffers(int renderIndex)
    {
        SpriteSheetManager.ReleaseBuffer(renderIndex);

        RenderInformation renderInformation = SpriteSheetManager.renderInformation[renderIndex];
        int instanceCount = EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Length;

        if (instanceCount > 0)
        {
            //TODO: deve moltiplicare il numero di sprites per questa animazione

            int stride = instanceCount >= 16 ? 16 : 16 * SpriteSheetCache.GetLenght(renderInformation.material);
            renderInformation.uvBuffer = new ComputeBuffer(instanceCount, stride);
            renderInformation.uvBuffer.SetData(EntityManager.GetBuffer <UvBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("uvBuffer", renderInformation.uvBuffer);


            renderInformation.indexBuffer = new ComputeBuffer(instanceCount, sizeof(int));
            renderInformation.indexBuffer.SetData(EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Reinterpret <int>().AsNativeArray());
            renderInformation.material.SetBuffer("indexBuffer", renderInformation.indexBuffer);

            renderInformation.matrixBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.matrixBuffer.SetData(EntityManager.GetBuffer <MatrixBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("matrixBuffer", renderInformation.matrixBuffer);

            renderInformation.args[1] = (uint)instanceCount;
            renderInformation.argsBuffer.SetData(renderInformation.args);

            renderInformation.colorsBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.colorsBuffer.SetData(EntityManager.GetBuffer <SpriteColorBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("colorsBuffer", renderInformation.colorsBuffer);
        }
        return(instanceCount);
    }
コード例 #2
0
 public RenderInformation(Material material, Entity bufferEntity)
 {
     this.material     = material;
     spriteCount       = SpriteSheetCache.GetLenght(material);
     this.bufferEntity = bufferEntity;
     args = new uint[5] {
         0, 0, 0, 0, 0
     };
     argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
     //thoose args are always the same since we always use the same mesh
     args[0] = (uint)6;
     args[2] = args[3] = (uint)0;
 }
コード例 #3
0
 public RenderInformation(Material mat, Entity bufEntity)
 {
     material = mat;
     material.enableInstancing = true;
     spriteCount  = SpriteSheetCache.GetLenght(material);
     bufferEntity = bufEntity;
     // Arguments for drawing mesh
     args = new uint[5] {
         0, 0, 0, 0, 0
     };
     argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
     // 0 == number of triangle indices, 1 == population, others are only relevant if drawing submeshes
     args[0]   = (uint)6;
     args[2]   = args[3] = (uint)0;
     updateUvs = true;
 }
コード例 #4
0
    //we should only update the index of the changed datas for index buffer,matrixbuffer and color buffer inside a burst job to avoid overhead
    int UpdateBuffers(int renderIndex)
    {
        SpriteSheetManager.ReleaseBuffer(renderIndex);

        RenderInformation renderInformation = SpriteSheetManager.renderInformation[renderIndex];
        int instanceCount = EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Length;

        if (instanceCount > 0)
        {
            int stride = instanceCount >= 16 ? 16 : 16 * SpriteSheetCache.GetLenght(renderInformation.material);
            if (renderInformation.updateUvs)
            {
                SpriteSheetManager.ReleaseUvBuffer(renderIndex);
                renderInformation.uvBuffer = new ComputeBuffer(instanceCount, stride);
                renderInformation.uvBuffer.SetData(EntityManager.GetBuffer <UvBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
                renderInformation.material.SetBuffer("uvBuffer", renderInformation.uvBuffer);
                renderInformation.updateUvs = false;
            }

            renderInformation.indexBuffer = new ComputeBuffer(instanceCount, sizeof(int));
            renderInformation.indexBuffer.SetData(EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Reinterpret <int>().AsNativeArray());
            renderInformation.material.SetBuffer("indexBuffer", renderInformation.indexBuffer);

            renderInformation.layerBuffer = new ComputeBuffer(instanceCount, sizeof(int));
            renderInformation.layerBuffer.SetData(EntityManager.GetBuffer <SpriteLayerBuffer>(renderInformation.bufferEntity).Reinterpret <int>().AsNativeArray());
            renderInformation.material.SetBuffer("layerBuffer", renderInformation.layerBuffer);

            renderInformation.matrixBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.matrixBuffer.SetData(EntityManager.GetBuffer <MatrixBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("matrixBuffer", renderInformation.matrixBuffer);

            renderInformation.args[1] = (uint)instanceCount;
            renderInformation.argsBuffer.SetData(renderInformation.args);

            renderInformation.colorsBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.colorsBuffer.SetData(EntityManager.GetBuffer <SpriteColorBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("colorsBuffer", renderInformation.colorsBuffer);
        }
        return(instanceCount);
    }