All pastes #365174 Raw Edit

Untitled

public text v1 · immutable
#365174 ·published 2007-02-20 19:08 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
			];
	
			static 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.
			auto pD3DVertexBuffer = new LPDIRECT3DVERTEXBUFFER9;
			auto 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);
		}
	}
}