Beispiel #1
0
void CVK::Node::load(std::string path)
{
	// load a scene with ASSIMP
	Assimp::Importer importer;
	const aiScene* scene = importer.ReadFile(path, aiProcess_GenSmoothNormals | aiProcess_Triangulate);
	if(scene)
		printf("SUCCESS: Loaded Model from Path: \"%s\"\n", path.c_str());
	else 
	{
		printf("ERROR: Loading failed from Path: \"%s\"\n", path.c_str());
		return;
	}

	std::vector<CVK::Material*> materials;
	
	// load all materials in this file
	for(unsigned int i=0; i < scene->mNumMaterials; i++)
	{
		aiMaterial* mat = scene->mMaterials[i];

		aiColor3D diffColor (0.f,0.f,0.f);
		mat->Get(AI_MATKEY_COLOR_DIFFUSE, diffColor);
		aiColor3D specColor (0.f,0.f,0.f);
		mat->Get(AI_MATKEY_COLOR_SPECULAR, specColor);
		float shininess = 0.0f;
		mat->Get(AI_MATKEY_SHININESS, shininess);
		glm::vec3 diffuseColor(diffColor.r, diffColor.g, diffColor.b);
		glm::vec3 specularColor(specColor.r, specColor.g, specColor.b);

		aiString fileName;  // filename
		mat->Get(AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0), fileName);
		std::string s = path.substr(0, path.rfind("/")) + "/";
		s += fileName.data;
		
		//materials.push_back(new CVK::Material(glm::vec3(0.0,1.0,0.0), glm::vec3(0.0,0.0,1.0), 10));
		if (fileName.length>0) 
			materials.push_back(new CVK::Material( const_cast<char*> ( s.c_str() ), 1.f, 1.f, specularColor, shininess));
			//should set kd and ks!!
		else 
			materials.push_back(new CVK::Material(diffuseColor, specularColor, shininess));
	}
	
	// load all meshes in this file
	for(unsigned int i=0; i < scene->mNumMeshes; i++)
	{
		aiMesh* mesh = scene->mMeshes[i];

		CVK::Geometry* geometry = new CVK::Geometry();
		
		// load geometry information of the current mesh
		for(unsigned int vCount = 0; vCount < mesh->mNumVertices; vCount++)
		{
			// vertices
			aiVector3D v = mesh->mVertices[vCount];
			geometry->getVertices()->push_back( glm::vec4(v.x, v.y, v.z, 1.0f));

			// normals
			if (mesh->HasNormals())
			{
				v = mesh->mNormals[vCount];
				geometry->getNormals()->push_back( glm::vec3(v.x, v.y, v.z));
			}

			// texture coordinates
			if (mesh->HasTextureCoords(0))
			{
				v = mesh->mTextureCoords[0][vCount];
				geometry->getUVs()->push_back( glm::vec2(v.x, v.y));
			}
		}

		for(unsigned int fCount = 0; fCount < mesh->mNumFaces; fCount++)
		{
			aiFace f = mesh->mFaces[fCount];
			// index numbers
			for(unsigned int iCount = 0; iCount < f.mNumIndices; iCount++)
			{
				geometry->getIndex()->push_back(f.mIndices[iCount]);
			}
		}

		geometry->createBuffers();
		
		// new child node with the geometry and a connection to material
		CVK::Node* child = new CVK::Node();
		child->setGeometry(geometry);
		child->setMaterial(materials[mesh->mMaterialIndex]);
		addChild(child);
	}
}
TestCase::IterateResult ReadPixelsCase::iterate (void)
{
	const tcu::RenderTarget&	renderTarget	= m_context.getRenderTarget();
	tcu::PixelFormat			pixelFormat		= renderTarget.getPixelFormat();
	int							targetWidth		= renderTarget.getWidth();
	int							targetHeight	= renderTarget.getHeight();
	int							x				= 0;
	int							y				= 0;
	int							imageWidth		= 0;
	int							imageHeight		= 0;

	deRandom rnd;
	deRandom_init(&rnd, deInt32Hash(m_curIter));

	switch (m_curIter)
	{
		case 0:
			// Fullscreen
			x = 0;
			y = 0;
			imageWidth  = targetWidth;
			imageHeight = targetHeight;
			break;
		case 1:
			// Upper left corner
			x = 0;
			y = 0;
			imageWidth = targetWidth / 2;
			imageHeight = targetHeight / 2;
			break;
		case 2:
			// Lower right corner
			x = targetWidth / 2;
			y = targetHeight / 2;
			imageWidth = targetWidth - x;
			imageHeight = targetHeight - y;
			break;
		default:
			x = deRandom_getUint32(&rnd) % (targetWidth - 1);
			y = deRandom_getUint32(&rnd) % (targetHeight - 1);
			imageWidth = 1 + (deRandom_getUint32(&rnd) % (targetWidth - x - 1));
			imageHeight = 1 + (deRandom_getUint32(&rnd) % (targetHeight - y - 1));
			break;
	}

	Surface	resImage(imageWidth, imageHeight);
	Surface	refImage(imageWidth, imageHeight);
	Surface	diffImage(imageWidth, imageHeight);

	int r = (int)(deRandom_getUint32(&rnd) & 0xFF);
	int g = (int)(deRandom_getUint32(&rnd) & 0xFF);
	int b = (int)(deRandom_getUint32(&rnd) & 0xFF);

	tcu::clear(refImage.getAccess(), tcu::IVec4(r, g, b, 255));
	glClearColor(r/255.0f, g/255.0f, b/255.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	glu::readPixels(m_context.getRenderContext(), x, y, resImage.getAccess());
	GLU_CHECK_MSG("glReadPixels() failed.");

	RGBA colorThreshold = pixelFormat.getColorThreshold();
	RGBA matchColor(0, 255, 0, 255);
	RGBA diffColor(255, 0, 0, 255);
	bool isImageOk = true;

	for (int j = 0; j < imageHeight; j++)
	{
		for (int i = 0; i < imageWidth; i++)
		{
			RGBA		resRGBA		= resImage.getPixel(i, j);
			RGBA		refRGBA		= refImage.getPixel(i, j);
			bool		isPixelOk	= compareThreshold(refRGBA, resRGBA, colorThreshold);
			diffImage.setPixel(i, j, isPixelOk ? matchColor : diffColor);

			isImageOk = isImageOk && isPixelOk;
		}
	}

	if (isImageOk)
		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
	else
	{
		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");

		TestLog& log = m_testCtx.getLog();
		log << TestLog::ImageSet("Result", "Resulting framebuffer")
			<< TestLog::Image("Result",		"Resulting framebuffer",	resImage)
			<< TestLog::Image("Reference",	"Reference image",			refImage)
			<< TestLog::Image("DiffMask",	"Failing pixels",			diffImage)
			<< TestLog::EndImageSet;
	}

	return (++m_curIter < m_numIters) ? CONTINUE : STOP;
}