LilEngie/src/Core/Platform/Graphics/DirectX11/DX11Graphics.cpp
//Currently inilializes the buffer with useless memory for no reason. fix it

Currently inilializes the buffer with useless memory for no reason. fix it
Currently inilializes the buffer with useless memory for no reason . fix it
ICBuffer* DX11Graphics::CreateCBuffer(uint size, void* initData)
	{
		HRESULT hr = S_OK;
		size = 16 * ((size - 1) / 16 + 1);
		DX11CBuffer* cBuffer = new DX11CBuffer();
		cBuffer->data = new char[size];
		cBuffer->size = size;
		if (initData != nullptr)
			memcpy(cBuffer->data, initData, size);
		D3D11_BUFFER_DESC bd = {};
		bd.ByteWidth = size;
		bd.Usage = D3D11_USAGE_DYNAMIC;
		bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
		bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		bd.MiscFlags = NULL;
		bd.StructureByteStride = NULL;
		D3D11_SUBRESOURCE_DATA sd;
		sd.pSysMem = cBuffer->data;
		sd.SysMemPitch = 0;
		sd.SysMemSlicePitch = 0;
		hr = ctx->device->CreateBuffer(&bd, &sd, &cBuffer->buffer);
		if (FAILED(hr))
		{
			LIL_ERROR("Could not create constant buffer.");
			return nullptr;
		}
		return cBuffer;
	}
ICBuffer * DX11Graphics :: CreateCBuffer ( uint size , void * initData ) { HRESULT hr = S_OK ; size = 16 * ( ( size - 1 ) / 16 + 1 ) ; DX11CBuffer * cBuffer = new DX11CBuffer ( ) ; cBuffer -> data = new char [ size ] ; cBuffer -> size = size ; if ( initData != nullptr ) memcpy ( cBuffer -> data , initData , size ) ; D3D11_BUFFER_DESC bd = { } ; bd . ByteWidth = size ; bd . Usage = D3D11_USAGE_DYNAMIC ; bd . BindFlags = D3D11_BIND_CONSTANT_BUFFER ; bd . CPUAccessFlags = D3D11_CPU_ACCESS_WRITE ; bd . MiscFlags = NULL ; bd . StructureByteStride = NULL ; D3D11_SUBRESOURCE_DATA sd ; sd . pSysMem = cBuffer -> data ; sd . SysMemPitch = 0 ; sd . SysMemSlicePitch = 0 ; hr = ctx -> device -> CreateBuffer ( & bd , & sd , & cBuffer -> buffer ) ; if ( FAILED ( hr ) ) { LIL_ERROR ( " " ) ; return nullptr ; } return cBuffer ; }
Currently inilializes the buffer with useless memory for no reason.
Currently inilializes the buffer with useless memory for no reason .
//DX11 requires size in multiples of 16, allocate extra if needed
 //Setup cbuffer
 //Create buffer
