示例#1
0
void RenderingContext::RestoreBatch()
{
	if (mBatch!=nullptr)
	{
		mBatch->Restore();
	}
	ResetBatch();
}
	void CDX9Renderer::EndBatch()
	{
		if (batch.empty())
			return;

		if(begin_scene_nest == 0)
		{
			// Its better if this doesn't happen...but if it does...force direct x to have 
			// a begin scene otherwise it will crash. This messes up parallel processing, 
			// but its better than the runtime crashing! - Davo
			CRASSERT(d3d9_device != NULL);
			hr = d3d9_device->BeginScene();
		}

		batches_per_present++;

#ifdef CR_DEBUG
		if (debug_save_next_batch)
			DoBatchLog();
#endif

		// Lock exactly the right number of indices and vertices
		vertex* vertex_mem;
		unsigned short* index_mem;

		unsigned int vertex_bytes = vertices_vector.size() * sizeof(vertex);
		unsigned int index_bytes = indices_vector.size() * sizeof(unsigned short);

		// Update only when bytes are to be copied (D3D interprets 0 as 'lock entire buffer'!)
		if (vertex_bytes != 0) {

			batch_buffer->Lock(0, vertex_bytes, (void**)&vertex_mem, D3DLOCK_DISCARD);
			memcpy(vertex_mem, &(vertices_vector.front()), vertex_bytes);
			batch_buffer->Unlock();
		}
		if (index_bytes != 0) {

			index_buffer->Lock(0, index_bytes, (void**)&index_mem, D3DLOCK_DISCARD);
			memcpy(index_mem, &(indices_vector.front()), index_bytes);
			index_buffer->Unlock();
		}

		// Loop the batch doing every item
		BatchIterator i = batch.begin();
		BatchIterator batch_end = batch.end();

		for ( ; i != batch_end; ++i)
			(*i)->Do();

		if(begin_scene_nest == 0)
		{
			// Its better if this doesn't happen...but if it does...force direct x to have 
			// a begin scene otherwise it will crash. This messes up parallel processing, 
			// but its better than it crashing! - Davo
			CRASSERT(d3d9_device != NULL);
			hr = d3d9_device->EndScene();
		}

		// Put everything back
		ResetBatch();
	}