Esempio n. 1
0
void SSpineWidget::Flush(int32 LayerId, FSlateWindowElementList& OutDrawElements, const FGeometry& AllottedGeometry, int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector>& Colors2, UMaterialInstanceDynamic* Material) {
	if (Vertices.Num() == 0) return;
	SSpineWidget* self = (SSpineWidget*)this;

	self->renderData.IndexData.SetNumUninitialized(Indices.Num());
	uint32* indexData = (uint32*)renderData.IndexData.GetData();
	memcpy(indexData, Indices.GetData(), sizeof(uint32) * Indices.Num());

	self->renderData.VertexData.SetNumUninitialized(Vertices.Num());
	FSlateVertex* vertexData = (FSlateVertex*)renderData.VertexData.GetData();
	FVector2D offset = AllottedGeometry.AbsolutePosition;
	FColor white = FColor(0xffffffff);

	float width = AllottedGeometry.GetAbsoluteSize().X;
	float height = AllottedGeometry.GetAbsoluteSize().Y;

	for (size_t i = 0; i < (size_t)Vertices.Num(); i++) {
		setVertex(&vertexData[i], Vertices[i].X, Vertices[i].Y, Uvs[i].X, Uvs[i].Y, Colors[i], offset);
	}

	/*FSlateBrush brush;
	brush.SetResourceObject(Material);
	brush = widget->Brush;

	FSlateShaderResourceProxy* shaderResource = FSlateDataPayload::ResourceManager->GetShaderResource(brush);
	if (shaderResource) {
		FSlateResourceHandle resourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(brush);
		FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, resourceHandle, renderData.VertexData, renderData.IndexData, nullptr, 0, 0);
	}*/

	Vertices.SetNum(0);
	Indices.SetNum(0);
	Uvs.SetNum(0);
	Colors.SetNum(0);
	Colors2.SetNum(0);
	Idx++;
}
Esempio n. 2
0
int32 SSpineWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements,
							   int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const {

	SSpineWidget* self = (SSpineWidget*)this;

	if (widget && widget->skeleton && widget->Atlas) {
		widget->skeleton->getColor().set(widget->Color.R, widget->Color.G, widget->Color.B, widget->Color.A);

		if (widget->atlasNormalBlendMaterials.Num() != widget->Atlas->atlasPages.Num()) {
			widget->atlasNormalBlendMaterials.SetNum(0);
			widget->pageToNormalBlendMaterial.Empty();
			widget->atlasAdditiveBlendMaterials.SetNum(0);
			widget->pageToAdditiveBlendMaterial.Empty();
			widget->atlasMultiplyBlendMaterials.SetNum(0);
			widget->pageToMultiplyBlendMaterial.Empty();
			widget->atlasScreenBlendMaterials.SetNum(0);
			widget->pageToScreenBlendMaterial.Empty();

			for (int i = 0; i < widget->Atlas->atlasPages.Num(); i++) {
				AtlasPage* currPage = widget->Atlas->GetAtlas()->getPages()[i];

				UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->NormalBlendMaterial, widget);
				material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]);
				widget->atlasNormalBlendMaterials.Add(material);
				widget->pageToNormalBlendMaterial.Add(currPage, material);

				material = UMaterialInstanceDynamic::Create(widget->AdditiveBlendMaterial, widget);
				material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]);
				widget->atlasAdditiveBlendMaterials.Add(material);
				widget->pageToAdditiveBlendMaterial.Add(currPage, material);

				material = UMaterialInstanceDynamic::Create(widget->MultiplyBlendMaterial, widget);
				material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]);
				widget->atlasMultiplyBlendMaterials.Add(material);
				widget->pageToMultiplyBlendMaterial.Add(currPage, material);

				material = UMaterialInstanceDynamic::Create(widget->ScreenBlendMaterial, widget);
				material->SetTextureParameterValue(widget->TextureParameterName, widget->Atlas->atlasPages[i]);
				widget->atlasScreenBlendMaterials.Add(material);
				widget->pageToScreenBlendMaterial.Add(currPage, material);
			}
		} else {
			widget->pageToNormalBlendMaterial.Empty();
			widget->pageToAdditiveBlendMaterial.Empty();
			widget->pageToMultiplyBlendMaterial.Empty();
			widget->pageToScreenBlendMaterial.Empty();

			for (int i = 0; i < widget->Atlas->atlasPages.Num(); i++) {
				AtlasPage* currPage = widget->Atlas->GetAtlas()->getPages()[i];

				UTexture2D* texture = widget->Atlas->atlasPages[i];
				UTexture* oldTexture = nullptr;

				UMaterialInstanceDynamic* current = widget->atlasNormalBlendMaterials[i];
				if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) {
					UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->NormalBlendMaterial, widget);
					material->SetTextureParameterValue(widget->TextureParameterName, texture);
					widget->atlasNormalBlendMaterials[i] = material;
				}
				widget->pageToNormalBlendMaterial.Add(currPage, widget->atlasNormalBlendMaterials[i]);

				current = widget->atlasAdditiveBlendMaterials[i];
				if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) {
					UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->AdditiveBlendMaterial, widget);
					material->SetTextureParameterValue(widget->TextureParameterName, texture);
					widget->atlasAdditiveBlendMaterials[i] = material;
				}
				widget->pageToAdditiveBlendMaterial.Add(currPage, widget->atlasAdditiveBlendMaterials[i]);

				current = widget->atlasMultiplyBlendMaterials[i];
				if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) {
					UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->MultiplyBlendMaterial, widget);
					material->SetTextureParameterValue(widget->TextureParameterName, texture);
					widget->atlasMultiplyBlendMaterials[i] = material;
				}
				widget->pageToMultiplyBlendMaterial.Add(currPage, widget->atlasMultiplyBlendMaterials[i]);

				current = widget->atlasScreenBlendMaterials[i];
				if (!current || !current->GetTextureParameterValue(widget->TextureParameterName, oldTexture) || oldTexture != texture) {
					UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(widget->ScreenBlendMaterial, widget);
					material->SetTextureParameterValue(widget->TextureParameterName, texture);
					widget->atlasScreenBlendMaterials[i] = material;
				}
				widget->pageToScreenBlendMaterial.Add(currPage, widget->atlasScreenBlendMaterials[i]);
			}
		}
		// self->UpdateMesh(LayerId, OutDrawElements, AllottedGeometry, widget->skeleton);
	}
	//return LayerId;

	self->renderData.IndexData.SetNumUninitialized(6);
	uint32* indexData = (uint32*)renderData.IndexData.GetData();
	indexData[0] = 0;
	indexData[1] = 1;
	indexData[2] = 2;
	indexData[3] = 2;
	indexData[4] = 3;
	indexData[5] = 0;

	self->renderData.VertexData.SetNumUninitialized(4);
	FSlateVertex* vertexData = (FSlateVertex*)renderData.VertexData.GetData();
	FVector2D offset = AllottedGeometry.AbsolutePosition;
	FColor white = FColor(0xffffffff);

	float width = AllottedGeometry.GetAbsoluteSize().X;
	float height = AllottedGeometry.GetAbsoluteSize().Y;

	setVertex(&vertexData[0], 0, 0, 0, 0, white, offset);
	setVertex(&vertexData[1], width, 0, 1, 0, white, offset);
	setVertex(&vertexData[2], width, height, 1, 1, white, offset);
	setVertex(&vertexData[3], 0, height, 0, 1, white, offset);

	if (brush && renderData.VertexData.Num() > 0 && renderData.IndexData.Num() > 0) {
		FSlateShaderResourceProxy* shaderResource = FSlateDataPayload::ResourceManager->GetShaderResource(widget->Brush);
		FSlateResourceHandle resourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(widget->Brush);
		if (shaderResource)
			FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, resourceHandle, renderData.VertexData,
											   renderData.IndexData, nullptr, 0, 0);
	}

	return LayerId;
}