コード例 #1
0
/// Pre-wrap function getMainRenderer.
static inline int pwrapgetMainRenderer(lua_State* l)
{
	UserData* ud;
	(void)ud;
	void* voidp;
	(void)voidp;
	PtrSize size;
	(void)size;

	LuaBinder::checkArgsCount(l, 0);

	// Call the function
	MainRenderer* ret = getMainRenderer(l);

	// Push return value
	if(ANKI_UNLIKELY(ret == nullptr))
	{
		lua_pushstring(l, "Glue code returned nullptr");
		return -1;
	}

	voidp = lua_newuserdata(l, sizeof(UserData));
	ud = static_cast<UserData*>(voidp);
	luaL_setmetatable(l, "MainRenderer");
	ud->initPointed(919289102518575326, const_cast<MainRenderer*>(ret));

	return 1;
}
コード例 #2
0
ファイル: Material.cpp プロジェクト: swq0553/anki-3d-engine
//==============================================================================
Error Material::getProgramPipeline(
	const RenderingKey& key, GlPipelineHandle& out)
{
	ANKI_ASSERT(enumToType(key.m_pass) < m_passesCount);
	ANKI_ASSERT(key.m_lod < m_lodsCount);

	Error err = ErrorCode::NONE;

	U tessCount = 1;
	if(m_tessellation)
	{
		tessCount = 2;
	}
	else
	{
		ANKI_ASSERT(!key.m_tessellation);
	}

	U idx = enumToType(key.m_pass) * m_lodsCount * tessCount
		+ key.m_lod * tessCount + key.m_tessellation;

	GlPipelineHandle& ppline = m_pplines[idx];

	// Lazily create it
	if(ANKI_UNLIKELY(!ppline.isCreated()))
	{
		Array<GlShaderHandle, 5> progs;
		U progCount = 0;

		progs[progCount++] = 
			getProgram(key, ShaderType::VERTEX)->getGlProgram();

		if(key.m_tessellation)
		{
			progs[progCount++] = getProgram(
				key, ShaderType::TESSELLATION_CONTROL)->getGlProgram();
			progs[progCount++] = getProgram(
				key, ShaderType::TESSELLATION_EVALUATION)->getGlProgram();
		}

		progs[progCount++] = 
			getProgram(key, ShaderType::FRAGMENT)->getGlProgram();

		GlDevice& gl = m_resources->_getGlDevice();
		GlCommandBufferHandle cmdBuff;
		ANKI_CHECK(cmdBuff.create(&gl));

		ANKI_CHECK(ppline.create(cmdBuff, &progs[0], &progs[0] + progCount));

		cmdBuff.flush();
	}

	out = ppline;

	return err;
}
コード例 #3
0
ファイル: Material.cpp プロジェクト: ezhangle/anki-3d-engine
//==============================================================================
GlProgramPipelineHandle Material::getProgramPipeline(
	const RenderingKey& key)
{
	ANKI_ASSERT((U)key.m_pass < m_passesCount);
	ANKI_ASSERT(key.m_lod < m_lodsCount);

	U tessCount = 1;
	if(key.m_tessellation)
	{
		ANKI_ASSERT(m_tessellation);
		tessCount = 2;
	}

	U idx = (U)key.m_pass * m_lodsCount * tessCount
		+ key.m_lod * tessCount + key.m_tessellation;

	ANKI_ASSERT(idx < m_pplines.size());
	GlProgramPipelineHandle& ppline = m_pplines[idx];

	// Lazily create it
	if(ANKI_UNLIKELY(!ppline.isCreated()))
	{
		Array<GlProgramHandle, 5> progs;
		U progCount = 0;

		progs[progCount++] = getProgram(key, 0)->getGlProgram();

		if(key.m_tessellation)
		{
			progs[progCount++] = getProgram(key, 1)->getGlProgram();
			progs[progCount++] = getProgram(key, 2)->getGlProgram();
		}

		progs[progCount++] = getProgram(key, 4)->getGlProgram();

		GlDevice& gl = m_resources->_getGlDevice();
		GlCommandBufferHandle cmdBuff(&gl);

		ppline = GlProgramPipelineHandle(
			cmdBuff, &progs[0], &progs[0] + progCount);

		cmdBuff.flush();
	}

	return ppline;
}
コード例 #4
0
VkCommandBuffer GrManagerImpl::newCommandBuffer(ThreadId tid, CommandBufferFlag cmdbFlags)
{
	// Get the per thread cache
	PerThread& thread = getPerThreadCache(tid);

	// Try initialize the recycler
	if(ANKI_UNLIKELY(!thread.m_cmdbs.isCreated()))
	{
		Error err = thread.m_cmdbs.init(getAllocator(), m_device, m_queueIdx);
		if(err)
		{
			ANKI_LOGF("Cannot recover");
		}
	}

	return thread.m_cmdbs.newCommandBuffer(cmdbFlags);
}
コード例 #5
0
//==============================================================================
void CommandBufferImpl::drawcallCommon()
{
	// Preconditions
	commandCommon();
	ANKI_ASSERT(insideRenderPass());
	ANKI_ASSERT(m_subpassContents == VK_SUBPASS_CONTENTS_MAX_ENUM
		|| m_subpassContents == VK_SUBPASS_CONTENTS_INLINE);
#if ANKI_ASSERTIONS
	m_subpassContents = VK_SUBPASS_CONTENTS_INLINE;
#endif

	if(ANKI_UNLIKELY(m_rpDrawcallCount == 0))
	{
		beginRenderPassInternal();
	}

	++m_rpDrawcallCount;
}
コード例 #6
0
void SectorGroup::findVisibleNodes(
	const FrustumComponent& frc, U testId, const SoftwareRasterizer* r, SectorGroupVisibilityTestsContext& ctx) const
{
	auto alloc = m_scene->getFrameAllocator();

	// Find visible sectors
	ListAuto<const Sector*> visSectors(alloc);
	U spatialsCount = 0;
	findVisibleSectors(frc, r, visSectors, spatialsCount);

	if(ANKI_UNLIKELY(spatialsCount == 0))
	{
		return;
	}

	// Initiate storage of nodes
	SceneNode** visibleNodesMem = reinterpret_cast<SceneNode**>(alloc.allocate(spatialsCount * sizeof(void*)));

	WeakArray<SceneNode*> visibleNodes(visibleNodesMem, spatialsCount);

	// Iterate visible sectors and get the scene nodes. The array will contain
	// duplicates
	U nodesCount = 0;
	auto it = visSectors.getBegin();
	auto end = visSectors.getEnd();
	for(; it != end; ++it)
	{
		const Sector& s = *(*it);
		for(auto itsp : s.m_spatials)
		{
			const SpatialComponent& spc = *itsp;
			SceneNode& node = const_cast<SceneNode&>(spc.getSceneNode());

			// Check if alrady visited
			if(!node.fetchSetSectorVisited(testId, true))
			{
				visibleNodes[nodesCount++] = &node;
			}
		}
	}

	// Update the context
	ctx.m_visibleNodes = WeakArray<SceneNode*>(visibleNodesMem, nodesCount);
}
コード例 #7
0
//==============================================================================
F32 ConvexHullShape::testPlane(const Plane& p) const
{
	// Compute the invert transformation of the plane instead
	Plane pa = (m_trfIdentity) ? p : p.getTransformed(m_invTrf);

	F32 minDist = MAX_F32;
	F32 maxDist = MIN_F32;

	const Vec4* point = m_points;
	const Vec4* end = m_points + m_pointsCount;
	for(; point != end; ++point)
	{
		F32 test = pa.test(*point);
		if(ANKI_UNLIKELY(test == 0.0))
		{
			// Early exit
			return 0.0; 	
		}

		minDist = min(minDist, test);
		maxDist = max(maxDist, test);
	}

	if(minDist > 0.0 && maxDist > 0.0)
	{
		return minDist;
	}
	else if(minDist < 0.0 && maxDist < 0.0)
	{
		return maxDist;
	}
	else
	{
		return 0.0;
	}
}