当前位置: 首页>>代码示例>>C++>>正文


C++ Batch::GetPS方法代码示例

本文整理汇总了C++中Batch::GetPS方法的典型用法代码示例。如果您正苦于以下问题:C++ Batch::GetPS方法的具体用法?C++ Batch::GetPS怎么用?C++ Batch::GetPS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Batch的用法示例。


在下文中一共展示了Batch::GetPS方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Init

bool Trans_Mesh::Init(){
	XAxis_Color=vec3(1, 0, 0);
	YAxis_Color=vec3(0, 1,0);
	ZAxis_Color=vec3(0, 0, 1);
	Hit_Axis_Color = vec3(1, 1, 1);
	HitAxis = vec3(0,0,0);
	Vertices.push_back(vec3(1.0f, 0.0f, 0.0f));
	const float split=16.0f;
	//note: all of these shapes will have to be scaled to correctly in the draw function, but its not something the user will do. that will be done in the draw function below
	// first create the cone pointer
	uint16_t index=1;
	for(float i=0.0f; i<2*Pi; i+=Pi/split){
		vec3 p;
		p.x=-1.0f;
		p.y=sinf(i);
		p.z=cosf(i);
		Vertices.push_back(p);
	}

	index=0;
	for(float i=0.0f; i<2*Pi; i+=Pi/split){
		Indices.push_back(0);
		Indices.push_back(index+2);
		Indices.push_back(index+1);
		index+=1;
	}
	Indices[Indices.size()-2]=Vertices.size()-1;
	Indices.push_back(0);
	Indices.push_back(1);
	Indices.push_back(Vertices.size()-1);

	FormatDesc layers[1] = { FormatDesc(TYPE_VERTEX, FORMAT_FLOAT, 4, 0) };
	Batch* b = new Batch();
	b->GetVS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_VS);
	b->GetVS()->CreateInputLayout(layers, 1);
	b->GetPS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_PS);
	b->NumIndices = Indices.size();
	b->StartIndex =0;
	b->NumVerts = Vertices.size();
	Batches.push_back(b);

	index=Vertices.size();

	// now create the rod to connect to it 
	// a long triangle looks the same as a rod
	Vertices.push_back(vec3(1.0f, 1.0f, 0.0f));//0
	Vertices.push_back(vec3(1.0f, -1.0f, 1.0f));//1
	Vertices.push_back(vec3(1.0f, -1.0f, -1.0f));//2

	Vertices.push_back(vec3(-1.0f, 1.0f, 0.0f));//3
	Vertices.push_back(vec3(-1.0f, -1.0f, 1.0f));//4
	Vertices.push_back(vec3(-1.0f, -1.0f, -1.0f));//5

	Vertices.push_back(vec3(-1.0f, -1.0f, -1.0f));//extra vert is needed for alignment reasons.. .  i guess

	Batch* b1 = new Batch();
	b1->GetVS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_VS);
	b1->GetVS()->CreateInputLayout(layers, 1);
	b1->GetPS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_PS);
	b1->StartIndex =Indices.size();
	b1->NumVerts = 6;
	Batches.push_back(b1);

	Indices.push_back(index+0);
	Indices.push_back(index+4);
	Indices.push_back(index+3);

	Indices.push_back(index+1);
	Indices.push_back(index+4);
	Indices.push_back(index+0);

	Indices.push_back(index+1);
	Indices.push_back(index+4);
	Indices.push_back(index+2);

	Indices.push_back(index+2);
	Indices.push_back(index+4);
	Indices.push_back(index+5);

	Indices.push_back(index+5);
	Indices.push_back(index+2);
	Indices.push_back(index+3);

	Indices.push_back(index+3);
	Indices.push_back(index+2);
	Indices.push_back(index+0);

	b1->NumIndices = Indices.size()-b->NumIndices;


	CBuffer0.Create(1, sizeof(mat4) + sizeof(vec4), CONSTANT_BUFFER);
	VB[0].Create(Vertices.size(), sizeof(vec3), BufferType::VERTEX_BUFFER, DEFAULT, CPU_NONE, &Vertices[0]);
	IB.Create(Indices.size(), sizeof(uint16_t), BufferType::INDEX_BUFFER, DEFAULT, CPU_NONE, &Indices[0]);

	return true;
}
开发者ID:LazyNarwhal,项目名称:Destination_Toolkit,代码行数:96,代码来源:Trans_Mesh.cpp

示例2: Load_Assimp


//.........这里部分代码省略.........
			if(bonein ==-1){//  did not find the bone, this is a new one push back
				bonein = bonenames.size();// get the index before insertion
				bonenames.push_back(bone->mName.data);
			}
			// there should only be 4 per vertex here because assimp guaranteees it, but if there are more, we are ok
			for( unsigned int b = 0; b < bone->mNumWeights; b++){
				if(			tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.x <= 0.f) {
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[0] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.x = bone->mWeights[b].mWeight;
				} else if(	tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.y <= 0.f){
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[1] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.y = bone->mWeights[b].mWeight;
				} else if(	tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.z <= 0.f){
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[2] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.z = bone->mWeights[b].mWeight;
				} else if(	tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.w <= 0.f){
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[3] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.w = bone->mWeights[b].mWeight;
				}
			}
			
		}
		for (unsigned int x = 0; x < mesh->mNumVertices;++x){
			Vertices[x + currentvertex] = tempverts[x + currentvertex].Pos = *reinterpret_cast<vec3*>(&mesh->mVertices[x]);
			tempverts[x + currentvertex].Tex =  *reinterpret_cast<vec2*>(&mesh->mTextureCoords[0][x]);
			tempverts[x + currentvertex].Norm = *reinterpret_cast<vec3*>(&mesh->mNormals[x]);
			tempverts[x + currentvertex].Tang = *reinterpret_cast<vec3*>(&mesh->mTangents[x]);
		}
		// check whether we can use 16 bit indices for our format... the ASSIMPOBLARBLA uses 32 bit indices for all theirs..
		if (IB.Stride == 4){
			uint32_t* pbData = reinterpret_cast<uint32_t*>(&Indices[currentindex]);
			for (unsigned int x = 0; x < mesh->mNumFaces;++x){
				for (unsigned int a = 0; a < 3 ;++a) {
					*pbData++ = static_cast<uint32_t>(mesh->mFaces[x].mIndices[a]+ currentvertex);
				}
			}
		} else {
			uint16_t* pbData = reinterpret_cast<uint16_t*>(&Indices[currentindex]);
			for (unsigned int x = 0; x < mesh->mNumFaces;++x){
				for (unsigned int a = 0; a < 3 ;++a) {
					*pbData++ = static_cast<uint16_t>(mesh->mFaces[x].mIndices[a]+ currentvertex);
				}
			}
		}
		//load the textures
		std::string pathtomodel(GetPath(file));
		Batch *batch = new Batch();

		LoadMaterials(mesh, load->mMaterials, batch, pathtomodel, Asset_Dir);
		batch->NumIndices=mesh->mNumFaces*3;
		batch->StartIndex = static_cast<uint32_t>(currentindex);
		batch->NumVerts= mesh->mNumVertices;
		// make sure to increment the ref count for thesse so they are properly destroyed

		currentvertex+=mesh->mNumVertices;
		currentindex+=mesh->mNumFaces*3;

		//For now, there will be a new shader for each material. I will create a shader cache where the graphics lib will cache the shaders and issue out already created shaders like it does with textures.
		Graphics::Shader_Macro macro1[] = {
			{"NORMALMAP", "1" }, 
			{"MATRIX_PALETTE_SIZE_DEFAULT", "60" }, 
			{NULL, NULL}
		};
		Graphics::Shader_Macro macro0[] = {
			{"NORMALMAP", "0" }, 
			{"MATRIX_PALETTE_SIZE_DEFAULT", "60" }, 
			{NULL, NULL}
		};

		Graphics::Shader_Macro* ptr = nullptr;
		if(batch->Has_NormalMap()) ptr = macro1;
		else ptr = macro0;

		batch->GetVS()->CompileShaderFromFile("Animated_Mesh.fx", "VS", "vs_4_0", ptr);

		FormatDesc lay[] = {
			FormatDesc(),
			FormatDesc(TYPE_TEXCOORD, FORMAT_FLOAT, 2),
			FormatDesc(TYPE_NORMAL, FORMAT_FLOAT, 3),
			FormatDesc(TYPE_TANGENT, FORMAT_FLOAT, 3),
			FormatDesc(TYPE_BONE, FORMAT_FLOAT, 4),
			FormatDesc(TYPE_WEIGHT, FORMAT_FLOAT, 4)
		};
		batch->GetVS()->CreateInputLayout(lay, sizeof(lay)/sizeof(FormatDesc));
		batch->GetPS()->CompileShaderFromFile("Animated_Mesh.fx", "PS", "ps_4_0", ptr);

		Batches.push_back(batch);
	}
	Animatior.Init(load);
	aiReleaseImport(load);// free the resrouces
	if(currentvertex==0) {// this could happen, if so GET OUTOF HERE
		OUTPUT_DEBUG_MSG("Problem loading the mesh, there were no vertices loaded. Failed to load the mesh");
		return false;
	}
	VB[0].Create(currentvertex, sizeof(Vertex_Types::Pos_Tex_Norm_Tang_Bone_Weight), VERTEX_BUFFER, IMMUTABLE, CPU_NONE, &tempverts[0] );
	IB.Create(currentindex, IB.Stride, INDEX_BUFFER, IMMUTABLE, CPU_NONE, &Indices[0]); // create index buffer!
	OUTPUT_DEBUG_MSG("Finished Loading the Mesh");
	Name=FileName =file;
	return true;
}
开发者ID:LazyNarwhal,项目名称:Destination_Toolkit,代码行数:101,代码来源:Animated_Mesh.cpp


注:本文中的Batch::GetPS方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。