Ejemplo n.º 1
0
void Entity::setMaterial(const std::string &name)
{
	//setMaterial(name, 0);
	IMaterialMgr *pMatMgr = gEngModule->pMaterialMgr;
	MaterialHandle handle = pMatMgr->getHandle(name);
	IMaterial *pMat = 0;
	if (handle.isNull() == true)
	{
		IMaterial *pCreateMat = pMatMgr->create(name);
		if (pCreateMat != 0)
		{
			mMaterialHandle = pMatMgr->getHandle(name);
			pMat = pCreateMat;
		}
	}

	for (int i = 0; i < mSubRenderableVec.size(); ++i)
	{
		if (i == 0)
		{
			mSubRenderableVec[i]->setMaterial(mMaterialHandle);
		}
		else
		{
			SubMaterialVec subMaterialVec = pMat->getSubMaterialVec();
			IMaterial *pSubMat = subMaterialVec[i - 1];
			mSubRenderableVec[i]->setMaterial(pSubMat->getName());
		}
	}
}
Ejemplo n.º 2
0
DebugDrawer::DebugDrawer()
	: lines(nullptr)
	, triangles(nullptr)
{
	Allocator* alloc = AllocatorGetThis();
	
	MaterialHandle debug = MaterialCreate(alloc, "Debug");
	
	Material* mat = debug.Resolve();
	mat->setBackfaceCulling(false);
	mat->setBlending(BlendSource::SourceAlpha, BlendDestination::InverseSourceAlpha);
	mat->setDepthCompare( DepthCompare::LessOrEqual );
	mat->setDepthOffset(Vector2(-1.0f, 1.0f));

	//mat->setDepthRange( Vector2(0.1f, 0.9f) );
	//mat->setDepthWrite(false);

	// Lines
	GeometryBuffer* linesVB = AllocateThis(GeometryBuffer);
	linesVB->setBufferAccess(BufferAccess::Write);
	linesVB->setBufferUsage(BufferUsage::Dynamic);
	SetupDebugVertexFormat(linesVB);

	lines = RenderBatchCreate(alloc);
	lines->setGeometryBuffer(linesVB);
	lines->setPrimitiveType(PrimitiveType::Lines);
	lines->setMaterial(debug);
	lines->setRenderLayer(RenderLayer::PostTransparency);
	renderables.push_back(lines.get());

	// Triangles
	GeometryBufferPtr trianglesVB = AllocateThis(GeometryBuffer);
	trianglesVB->setBufferAccess(BufferAccess::Write);
	trianglesVB->setBufferUsage(BufferUsage::Dynamic);
	SetupDebugVertexFormat(trianglesVB.get());

	triangles = RenderBatchCreate(alloc);
	triangles->setGeometryBuffer(trianglesVB);
	triangles->setPrimitiveType(PrimitiveType::Triangles);
	triangles->setMaterial(debug);
	triangles->setRenderLayer(RenderLayer::PostTransparency);
	renderables.push_back(triangles.get());

	// Quads
	GeometryBufferPtr quadsVB = AllocateThis(GeometryBuffer);
	quadsVB->setBufferAccess(BufferAccess::Write);
	quadsVB->setBufferUsage(BufferUsage::Dynamic);
	SetupDebugVertexFormat(quadsVB.get());

	quads = RenderBatchCreate(alloc);
	quads->setGeometryBuffer(quadsVB);
	quads->setPrimitiveType(PrimitiveType::Quads);
	quads->setMaterial(debug);
	quads->setRenderLayer(RenderLayer::PostTransparency);
	renderables.push_back(quads.get());

	reset();
}
Ejemplo n.º 3
0
// From ReferenceTarget
RefTargetHandle MaterialHandle::Clone(RemapDir& remap) 
{
	MaterialHandle* newob = new MaterialHandle();	
	// Make a copy all the data and also clone all the references
	newob->ReplaceReference(0,remap.CloneRef(pblock2));
	newob->ivalid.SetEmpty();
	BaseClone(this, newob, remap);
	return(newob);
}
Ejemplo n.º 4
0
void Overlay::setOpacity( float opacity )
{
    this->opacity = opacity;

    if( renderables.Empty() ) return;

    MaterialHandle materialHandle = renderables[0]->getMaterial();

    Material* material = materialHandle.Resolve();
    if( !material ) return;

    material->setBlending(BlendSource::SourceAlpha, BlendDestination::InverseSourceAlpha);
}
Ejemplo n.º 5
0
RenderBatchPtr Model::createDebugRenderable() const
{
	MaterialHandle handleMaterial = MaterialCreate(AllocatorGetHeap(), "SkeletonDebug");

	Material* material = handleMaterial.Resolve();
	material->setDepthTest(false);

	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);
	
	RenderBatch* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Lines);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(handleMaterial);

	return renderable;
}
Ejemplo n.º 6
0
RenderablePtr DebugBuildFrustum( const Frustum& box )
{
	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);

	MaterialHandle materialHandle = MaterialCreate(AllocatorGetHeap(), "FrustumDebug");
	Material* material = materialHandle.Resolve();
	material->setBackfaceCulling( false );

	Renderable* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Quads);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(materialHandle);
	renderable->setPrimitiveRasterMode( PrimitiveRasterMode::Wireframe );

	DebugUpdateFrustum(renderable, box);
	return renderable;
}
Ejemplo n.º 7
0
void Entity::setMaterial(const std::string &name, const int index)
{
	if (index >= mSubRenderableVec.size())
	{
		Log::getInstance().logMsg("Material index error !");
		return;
	}

	IMaterialMgr *pMatMgr = gEngModule->pMaterialMgr;
	MaterialHandle handle = pMatMgr->getHandle(name);
	if (handle.isNull() == true)
	{
		IMaterial *pCreateMat = pMatMgr->create(name);
		if (pCreateMat != 0)
		{
			mMaterialHandle = pMatMgr->getHandle(name);
		}
	}
	mSubRenderableVec[index]->setMaterial(name);
}
Ejemplo n.º 8
0
RenderablePtr DebugBuildBoundingBox( const BoundingBox& box )
{
	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);

	MaterialHandle materialHandle = MaterialCreate(AllocatorGetHeap(), "BoundingBoxDebug");
	
	Material* mat = materialHandle.Resolve();
	mat->setDepthCompare( DepthCompare::LessOrEqual );
	mat->setBackfaceCulling( false );
	//mat->setDepthRange( Vector2(0.1f, 0.9f) );

	Renderable* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Quads);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(materialHandle);
	renderable->setPrimitiveRasterMode( PrimitiveRasterMode::Wireframe );

	DebugUpdateBoudingBox(gb, box, Color::White);

	return renderable;
}