Ejemplo n.º 1
0
//==============================================================================
Error GlPipelineHandle::commonConstructor(
	GlCommandBufferHandle& commands,
	const GlShaderHandle* progsBegin, const GlShaderHandle* progsEnd)
{
	class Command: public GlCommand
	{
	public:
		GlPipelineHandle m_ppline;
		Array<GlShaderHandle, 6> m_progs;
		U8 m_progsCount;

		Command(GlPipelineHandle& ppline, 
			const GlShaderHandle* progsBegin, const GlShaderHandle* progsEnd)
		:	m_ppline(ppline)
		{
			m_progsCount = 0;
			const GlShaderHandle* prog = progsBegin;
			do
			{
				m_progs[m_progsCount++] = *prog;
			} while(++prog != progsEnd);
		}

		Error operator()(GlCommandBuffer* cmdb)
		{
			Error err = m_ppline._get().create(
				&m_progs[0], &m_progs[0] + m_progsCount,
				cmdb->getGlobalAllocator());

			GlHandleState oldState = m_ppline._setState(
				err ? GlHandleState::ERROR : GlHandleState::CREATED);
			ANKI_ASSERT(oldState == GlHandleState::TO_BE_CREATED);
			(void)oldState;

			return err;
		}
	};

	using Alloc = GlAllocator<GlPipeline>;
	using DeleteCommand = GlDeleteObjectCommand<GlPipeline, Alloc>;
	using Deleter = 
		GlHandleDeferredDeleter<GlPipeline, Alloc, DeleteCommand>;

	Error err = _createAdvanced(
		&commands._get().getQueue().getDevice(),
		commands._get().getGlobalAllocator(), 
		Deleter());

	if(!err)
	{
		_setState(GlHandleState::TO_BE_CREATED);

		commands._pushBackNewCommand<Command>(*this, progsBegin, progsEnd);
	}

	return err;
}
//==============================================================================
void GlCommandBufferHandle::pushBackOtherCommandBuffer(
	GlCommandBufferHandle& commands)
{
	class Command: public GlCommand
	{
	public:
		GlCommandBufferHandle m_commands;

		Command(GlCommandBufferHandle& commands)
		:	m_commands(commands)
		{}

		Error operator()(GlCommandBuffer*)
		{
			return m_commands._executeAllCommands();
		}
	};

	commands._get().makeImmutable();
	_pushBackNewCommand<Command>(commands);
}