Example #1
0
        public int CreateMesh(ref BoundingBox bounds, ref MeshDrawParametersComponent drawArgs)
        {
            int idx = AllocateValidAndVisibleRenderable();

            cBounds[idx]         = bounds;
            cDrawParameters[idx] = drawArgs;
            return(idx);
        }
Example #2
0
            public void AddDraw(ref MeshDrawParametersComponent drawparams, Pipeline pipeline)
            {
                // Encode the draw
                if (_indirectDrawCount[_stagingSet] >= _indirectStagingBuffer.Length)
                {
                    throw new Exception("Indirect buffer not large enough for draw");
                }
                if (pipeline == null)
                {
                    throw new Exception("Pipeline is null");
                }
                if (drawparams._bufferIndex == -1)
                {
                    throw new Exception("Invalid buffer index");
                }
                _indirectStagingBuffer[_indirectDrawCount[_stagingSet]] = drawparams._indirectArgs;
                _indirectDrawCount[_stagingSet]++;

                // Determine if we need a new batch
                if (_batchCount[_stagingSet] == 0 ||
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet] - 1]._pipeline != pipeline ||
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet] - 1]._objectRS != drawparams._objectResourceSet ||
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet] - 1]._indexFormat != drawparams._indexFormat ||
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet] - 1]._bufferIndex != drawparams._bufferIndex)
                {
                    if (_batchCount[_stagingSet] >= MAX_BATCH)
                    {
                        //throw new Exception("Batch count is not large enough");
                        return; // Drop the batch for now
                    }
                    // Add a new batch
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet]]._bufferIndex = drawparams._bufferIndex;
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet]]._pipeline    = pipeline;
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet]]._objectRS    = drawparams._objectResourceSet;
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet]]._indexFormat = drawparams._indexFormat;
                    _batches[MAX_BATCH * _stagingSet + _batchCount[_stagingSet]]._batchStart  = _indirectDrawCount[_stagingSet] - 1;
                    _batchCount[_stagingSet]++;
                }
            }