Exemplo n.º 1
0
//==============================================================================
Error XmlElement::getFloats(DynamicArrayAuto<F64>& out) const
{
	Error err = check();

	const char* txt;
	if(!err)
	{
		txt = m_el->GetText();
		if(txt == nullptr)
		{
			err = ErrorCode::USER_DATA;
		}
	}

	StringList list;
	if(!err)
	{
		list.splitString(m_alloc, txt, ' ');
	}

	out = DynamicArrayAuto<F64>(m_alloc);

	if(!err)
	{
		out.create(list.getSize());
	}

	auto it = list.getBegin();
	for(U i = 0; i < out.getSize() && !err; i++)
	{
		err = it->toF64(out[i]);
		++it;
	}

	if(err)
	{
		ANKI_LOGE("Failed to return floats. Element: %s", m_el->Value());
	}

	list.destroy(m_alloc);

	return err;
}
Exemplo n.º 2
0
MaterialVariableTemplate<T>* MaterialVariableTemplate<T>::_newInstance(
	const MaterialProgramCreator::Input& in,
	ResourceAllocator<U8> alloc, TempResourceAllocator<U8> talloc)
{
	Error err = ErrorCode::NONE;
	MaterialVariableTemplate<T>* out = nullptr;

	TempResourceDArray<F32> floats;
	TempResourceDArray<F32>::ScopeDestroyer floatsd(&floats, talloc);

	// Get the float values
	if(in.m_value.getSize() > 0)
	{
		// Has values

		U floatsNeeded = in.m_arraySize * (sizeof(T) / sizeof(F32));

		if(in.m_value.getSize() != floatsNeeded)
		{
			ANKI_LOGE("Incorrect number of values. Variable %s", 
				&in.m_name[0]);

			return nullptr;
		}

		err = floats.create(talloc, floatsNeeded);
		if(err) return nullptr;

		auto it = in.m_value.getBegin();
		for(U i = 0; i < floatsNeeded; ++i)
		{
			F64 d;
			err = it->toF64(d);
			if(err)	return nullptr;

			floats[i] = d;
			++it;
		}
	}

	// Create new instance
	out = alloc.newInstance<MaterialVariableTemplate<T>>();
	if(!out) return nullptr;

	if(floats.getSize() > 0)
	{
		err = out->create(alloc, in.m_name.toCString(), 
			(T*)&floats[0], in.m_arraySize);
	}
	else
	{
		// Buildin
		err = out->create(alloc, in.m_name.toCString(), nullptr, 0);
	}

	if(err && out)
	{
		alloc.deleteInstance(out);
		return nullptr;
	}

	// Set some values
	out->m_instanced = in.m_instanced;
	out->m_varType = in.m_type;
	out->m_textureUnit = in.m_binding;
	out->m_varBlkInfo.m_arraySize = in.m_arraySize;

	// Set UBO data
	if(out && in.m_inBlock)
	{
		out->m_varBlkInfo.m_offset = in.m_offset;
		ANKI_ASSERT(out->m_varBlkInfo.m_offset >= 0);
		out->m_varBlkInfo.m_arrayStride = in.m_arrayStride;
		out->m_varBlkInfo.m_matrixStride = in.m_matrixStride;
	}

	return out;
}