Пример #1
0
        public SpriteBatcher(int poolSize, Shader shader)
        {
            _poolSize = poolSize;
            _bufferSize = _poolSize * 4; // 4 vertices per sprite
            _indexSize = _poolSize * 6; // 6 elements per sprite

            _items = new List<SpriteBatchItem>(_poolSize);
            _itemPool = new Queue<SpriteBatchItem>(_poolSize);

            _vertices = new Vertex[_bufferSize];
            _bufferHandle = GlHelper.CreateBuffer(_vertices, BufferTarget.ArrayBuffer, BufferUsageHint.StreamDraw);

            _indices = new ushort[_indexSize];

            // generate a massive index array for quads (2 triangles)
            for (var i = 0; i < _poolSize; i++)
            {
                _indices[i * 6 + 0] = (ushort)(i * 4);
                _indices[i * 6 + 1] = (ushort)(i * 4 + 1);
                _indices[i * 6 + 2] = (ushort)(i * 4 + 2);
                _indices[i * 6 + 3] = (ushort)(i * 4 + 2);
                _indices[i * 6 + 4] = (ushort)(i * 4 + 1);
                _indices[i * 6 + 5] = (ushort)(i * 4 + 3);
            }

            _indexHandle = GlHelper.CreateBuffer(_indices, BufferTarget.ElementArrayBuffer, BufferUsageHint.DynamicDraw);

            var attributes = shader.GetAttributes(_bufferHandle);
            _vertexHandle = GlHelper.CreateVertexArray(attributes);
        }
Пример #2
0
 public SpriteBatch(int poolSize, Shader shader)
 {
     PoolSize = poolSize;
     _shader = shader;
     _batcher = new SpriteBatcher(PoolSize, shader);
 }