示例#1
0
tcu::PixelBufferAccess getMultisampleAccess(const tcu::PixelBufferAccess& original)
{
	return tcu::PixelBufferAccess(original.getFormat(),
								  1,
								  original.getWidth(),
								  original.getHeight(),
								  original.getFormat().getPixelSize(),
								  original.getRowPitch(),
								  original.getDataPtr());
}
void resolveMultisampleColorBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
{
	DE_ASSERT(dst.getWidth() == src.raw().getHeight());
	DE_ASSERT(dst.getHeight() == src.raw().getDepth());

	float numSamplesInv = 1.0f / (float)src.getNumSamples();

	for (int y = 0; y < dst.getHeight(); y++)
	{
		for (int x = 0; x < dst.getWidth(); x++)
		{
			tcu::Vec4 sum;
			for (int s = 0; s < src.raw().getWidth(); s++)
				sum += src.raw().getPixel(s, x, y);

			dst.setPixel(sum*numSamplesInv, x, y);
		}
	}
}
void ShaderMetamorphicVariant::render (const tcu::PixelBufferAccess& img, const std::string& vertexSrc, const std::string& fragmentSrc)
{
	TestLog&				log		= m_testCtx.getLog();
	const glw::Functions&	gl		= m_context.getRenderContext().getFunctions();

	// Positions, shared between shaders
	const float positions[] =
	{
		-1.0f,  1.0f,	// top-left
		-1.0f, -1.0f,	// bottom-left
		 1.0f, -1.0f,	// bottom-right
		 1.0f,  1.0f,	// top-right
	};

	const deUint16 indices[] =
	{
		0, 1, 2,	// bottom-left triangle
		0, 3, 2,	// top-right triangle
	};

	glu::VertexArrayBinding posBinding = glu::va::Float("coord2d", 2, 6, 0, &positions[0]);

	const glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexSrc, fragmentSrc));
	log << program;

	if (!program.isOk())
		throw tcu::TestError("Compile failed");

	// Set uniforms expected in GraphicsFuzz generated programs
	gl.useProgram(program.getProgram());
	// Uniform: injectionSwitch
	int uniformLoc = gl.getUniformLocation(program.getProgram(), "injectionSwitch");
	if (uniformLoc != -1)
		gl.uniform2f(uniformLoc, 0.0f, 1.0f);
	// Uniform: resolution
	uniformLoc = gl.getUniformLocation(program.getProgram(), "resolution");
	if (uniformLoc != -1)
		gl.uniform2f(uniformLoc, glw::GLfloat(img.getWidth()), glw::GLfloat(img.getHeight()));
	// Uniform: mouse
	uniformLoc = gl.getUniformLocation(program.getProgram(), "mouse");
	if (uniformLoc != -1)
		gl.uniform2f(uniformLoc, 0.0f, 0.0f);
	// Uniform: time
	uniformLoc = gl.getUniformLocation(program.getProgram(), "time");
	if (uniformLoc != -1)
		gl.uniform1f(uniformLoc, 0.0f);

	// Render two times to check nondeterministic renderings
	glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding, glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indices), &indices[0]));
	glu::readPixels(m_context.getRenderContext(), 0, 0, img);
	GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
}