void VertexShaderData::PreDraw(ID3D11Device1& device, ID3D11DeviceContext1& context) {
		ASSERT(mInputLayout);
		ASSERT(mShader);
		ASSERT(mVertexBuffer);
		ASSERT(mVertexCount > 0);

		context.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

		context.IASetInputLayout(mInputLayout);

		context.VSSetShader(mShader, nullptr, 0);

		const unsigned int stride = sizeof(VertexData);
		const unsigned int offset = 0;
		context.IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &offset);

		// Set constant buffers
		ID3D11Buffer* const cBuffers[] = { mCBuffer.mBuffer };
		mCBuffer.CopyDataToBuffer(device);
		context.VSSetConstantBuffers(0, ARRAYSIZE(cBuffers), cBuffers);
	}
void DeviceGraphicsDX11Geometry::draw (void)
{
    DeviceGraphicsDX11Renderer *renderer = checkedCast<DeviceGraphicsDX11Renderer*>(System::getRenderer());

    ID3D11DeviceContext1 *context = renderer->getD3D11Context();


    ID3D11Buffer* buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {NULL};
    UINT strides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {0};
    UINT offsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {0};

	// If there are VBO's
	if (_normal_stream) {
        buffers[ShaderResource::ATTRIB_NORMAL] = _normal_stream->getBuffer();
        		
		if (_normal_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT)		strides[ShaderResource::ATTRIB_NORMAL] = sizeof(DTfloat) * 3;
		else if (_normal_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_2_FLOAT)	strides[ShaderResource::ATTRIB_NORMAL] = sizeof(DTfloat) * 2;
		else if (_normal_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT)	strides[ShaderResource::ATTRIB_NORMAL] = sizeof(DTfloat) * 4;
    }	
	
	if (_color_stream) {
        buffers[ShaderResource::ATTRIB_COLOR] = _color_stream->getBuffer();

		if (_color_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT)	    strides[ShaderResource::ATTRIB_COLOR] = sizeof(DTfloat) * 4;
		else if (_color_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT)   strides[ShaderResource::ATTRIB_COLOR] = sizeof(DTfloat) * 3;
		else if (_color_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_BYTE)	strides[ShaderResource::ATTRIB_COLOR] = sizeof(DTubyte) * 4;
	}
        
	if (_weights_strength_stream) {
        buffers[ShaderResource::ATTRIB_WEIGHTS_STRENGTH] = _weights_strength_stream->getBuffer();

		if (_weights_strength_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT)	    strides[ShaderResource::ATTRIB_WEIGHTS_STRENGTH] = sizeof(DTfloat) * 4;
	}

	if (_weights_index_stream) {
        buffers[ShaderResource::ATTRIB_WEIGHTS_INDEX] = _weights_index_stream->getBuffer();
		
        if (_weights_index_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_USHORT)	    strides[ShaderResource::ATTRIB_WEIGHTS_INDEX] = sizeof(DTushort) * 4;
	}

	DTint num_units = min2(4,System::getRenderer()->getNumTextureUnits());
	for (DTint unit = 0; unit < num_units; ++unit) {
			
		if (_texcoord_stream[unit]) {
            buffers[ShaderResource::ATTRIB_TEXCOORD0+unit] = _texcoord_stream[unit]->getBuffer();
						
			if (_texcoord_stream[unit]->getFormat() == DeviceGraphicsDX11DataStream::FMT_2_FLOAT)		strides[ShaderResource::ATTRIB_TEXCOORD0+unit] = sizeof(DTfloat) * 2;
			else if (_texcoord_stream[unit]->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT)	strides[ShaderResource::ATTRIB_TEXCOORD0+unit] = sizeof(DTfloat) * 3;
			else if (_texcoord_stream[unit]->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT)	strides[ShaderResource::ATTRIB_TEXCOORD0+unit] = sizeof(DTfloat) * 4;
		}
	}


	if (_vertex_stream) {
        buffers[ShaderResource::ATTRIB_POSITION] = _vertex_stream->getBuffer();
		
		if (_vertex_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT)		strides[ShaderResource::ATTRIB_POSITION] = sizeof(DTfloat) * 3;
		else if (_vertex_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_2_FLOAT)	strides[ShaderResource::ATTRIB_POSITION] = sizeof(DTfloat) * 2;
		else if (_vertex_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT)	strides[ShaderResource::ATTRIB_POSITION] = sizeof(DTfloat) * 4;
	}
	
    // Bind the streams
    context->IASetVertexBuffers(0,ShaderResource::NUM_ATTRIBS,buffers,strides,offsets);
    context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);


	// draw if there is an index stream
	if (_index_stream) {
        context->IASetIndexBuffer(_index_stream->getBuffer(), DXGI_FORMAT_R16_UINT, 0);
        context->DrawIndexed(_num_faces*3,0,0);
	}
}