All pastes #365173 Raw Edit

Unnamed

public text v1 · immutable
#365173 ·published 2007-02-20 19:05 UTC
rendered paste body

enum Usage {
	Flags!(DONOTCLIP, DYNAMIC, POINTS, SOFTWAREPROCESSING, WRITEONLY)
}

version(Direct3D) {

	class AlkeellinenLuokka {
	
		VertexBuffer CreateVertexBuffer(uint size, uint usage) {
			// Find combination of Direct3D usage flags.
			uint d3dUsage;
		
			auto systemFlags = [
				DONOTCLIP => D3DUSAGE_DONOTCLIP,
				DYNAMIC => D3DUSAGE_DYNAMIC,
				POINTS => D3DUSAGE_POINTS,
				SOFTWAREPROCESSING => D3DUSAGE_SOFTWAREPROCESSING,
				WRITEONLY => D3DUSAGE_WRITEONLY
			];
	
			foreach(flag, systemFlag; systemFlags) {
				if (usage & flag) d3dUsage |= systemFlag;
			}
	
			// Find Direct3D memory pool.
			auto d3dPool = usage & RV_SYSTEMMEMORY ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
		
			// Create Direct3D vertex buffer.
			LPDIRECT3DVERTEXBUFFER9 pD3DVertexBuffer;
			HRESULT d3dResult = pD3DDevice.CreateVertexBuffer(
				size, d3dUsage, 0, d3dPool, &pD3DVertexBuffer, NULL);
	
			if(d3dResult != D3D_OK)	{
				throw new Exception("CreateVertexBuffer failed: " ~ toString(d3dResult));
			}
	
			// Create and return vertex buffer.
			return new CRVVertexBuffer(pD3DVertexBuffer, size, usage);
		}
	}
}