Fix EGLImage depth image test issues.

- Fix reversed depth compare in reference image generation.
- Set probe plane z coordinates in clip space.
- Use depth mask to avoid probe planes from altering the result.
- Clear fb color before rendering probe planes.
- Use proper threshold when reading a RGB4 fb.
- Initialize RBOs to a nice pattern instead of a single value.
- Don't render from images in multicontext cases before creating it.

Bug: 20637957
Change-Id: I158e51489ab8d562e74066b8549f5ee5a0d90cb7
diff --git a/modules/egl/teglImageFormatTests.cpp b/modules/egl/teglImageFormatTests.cpp
index 5eb4ac9..d40dc09 100644
--- a/modules/egl/teglImageFormatTests.cpp
+++ b/modules/egl/teglImageFormatTests.cpp
@@ -455,12 +455,14 @@
 	Framebuffer				framebuffer			(gl);
 	Renderbuffer			renderbufferColor	(gl);
 	Renderbuffer			renderbufferDepth	(gl);
-	log << tcu::TestLog::Message << "Rendering with depth buffer" << tcu::TestLog::EndMessage;
+	const tcu::RGBA			compareThreshold	(32, 32, 32, 32); // layer colors are far apart, large thresholds are ok
 
 	// Branch only taken in TryAll case
 	if (reference.getFormat().order != tcu::TextureFormat::DS && reference.getFormat().order != tcu::TextureFormat::D)
 		throw IllegalRendererException(); // Skip, interpreting non-depth data as depth data is not meaningful
 
+	log << tcu::TestLog::Message << "Rendering with depth buffer" << tcu::TestLog::EndMessage;
+
 	GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
 
 	GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbufferColor));
@@ -503,6 +505,9 @@
 	GLuint depthLoc = gl.getUniformLocation(glProgram, "u_depth");
 	TCU_CHECK_MSG((int)depthLoc != (int)-1, "Couldn't find uniform u_depth");
 
+	GLU_CHECK_GLW_CALL(gl, clearColor(0.5f, 1.0f, 0.5f, 1.0f));
+	GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
+
 	tcu::Vec4 depthLevelColors[] = {
 		tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
 		tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
@@ -522,12 +527,15 @@
 
 	GLU_CHECK_GLW_CALL(gl, enable(GL_DEPTH_TEST));
 	GLU_CHECK_GLW_CALL(gl, depthFunc(GL_LESS));
+	GLU_CHECK_GLW_CALL(gl, depthMask(GL_FALSE));
 
 	for (int level = 0; level < DE_LENGTH_OF_ARRAY(depthLevelColors); level++)
 	{
-		tcu::Vec4 color = depthLevelColors[level];
+		const tcu::Vec4	color		= depthLevelColors[level];
+		const float		clipDepth	= ((level + 1) * 0.1f) * 2.0f - 1.0f; // depth in clip coords
+
 		GLU_CHECK_GLW_CALL(gl, uniform4f(colorLoc, color.x(), color.y(), color.z(), color.w()));
-		GLU_CHECK_GLW_CALL(gl, uniform1f(depthLoc, (level + 1) * 0.1f));
+		GLU_CHECK_GLW_CALL(gl, uniform1f(depthLoc, clipDepth));
 		GLU_CHECK_GLW_CALL(gl, drawArrays(GL_TRIANGLES, 0, 6));
 	}
 
@@ -544,11 +552,11 @@
 	{
 		for (int x = 0; x < reference.getWidth(); x++)
 		{
-			tcu::Vec4 result;
+			tcu::Vec4 result = tcu::Vec4(0.5f, 1.0f, 0.5f, 1.0f);
 
 			for (int level = 0; level < DE_LENGTH_OF_ARRAY(depthLevelColors); level++)
 			{
-				if (refAccess.getPixDepth(x, y) < (level + 1) * 0.1f)
+				if ((level + 1) * 0.1f < refAccess.getPixDepth(x, y))
 					result = depthLevelColors[level];
 			}
 
@@ -556,10 +564,11 @@
 		}
 	}
 
+	GLU_CHECK_GLW_CALL(gl, depthMask(GL_TRUE));
 	GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, 0));
 	GLU_CHECK_GLW_CALL(gl, finish());
 
-	return tcu::pixelThresholdCompare(log, "Depth buffer rendering result", "Result from rendering with depth buffer", referenceScreen, screen, tcu::RGBA(1,1,1,1), tcu::COMPARE_LOG_RESULT);
+	return tcu::pixelThresholdCompare(log, "Depth buffer rendering result", "Result from rendering with depth buffer", referenceScreen, screen, compareThreshold, tcu::COMPARE_LOG_RESULT);
 }
 
 bool GLES2ImageApi::RenderReadPixelsRenderbuffer::invokeGLES2 (GLES2ImageApi& api, MovePtr<UniqueImage>& img, tcu::Texture2D& reference) const
@@ -574,14 +583,14 @@
 	tcu::Surface			screen			(reference.getWidth(), reference.getHeight());
 	tcu::Surface			refSurface		(reference.getWidth(), reference.getHeight());
 
-	log << tcu::TestLog::Message << "Reading with ReadPixels from renderbuffer" << tcu::TestLog::EndMessage;
-
 	// Branch only taken in TryAll case
 	if (reference.getFormat().order == tcu::TextureFormat::DS || reference.getFormat().order == tcu::TextureFormat::D)
 		throw IllegalRendererException(); // Skip, GLES2 does not support ReadPixels for depth attachments
 	if (reference.getFormat().order == tcu::TextureFormat::S)
 		throw IllegalRendererException(); // Skip, GLES2 does not support ReadPixels for stencil attachments
 
+	log << tcu::TestLog::Message << "Reading with ReadPixels from renderbuffer" << tcu::TestLog::EndMessage;
+
 	GLU_CHECK_GLW_CALL(gl, bindFramebuffer(GL_FRAMEBUFFER, *framebuffer));
 	GLU_CHECK_GLW_CALL(gl, bindRenderbuffer(GL_RENDERBUFFER, *renderbuffer));
 	imageTargetRenderbuffer(api.m_egl, gl, **img);
@@ -1150,89 +1159,6 @@
 	return new SimpleCreationTests(eglTestCtx, name, desc);
 }
 
-class MultiContextRenderTests : public RenderTests
-{
-public:
-			MultiContextRenderTests		(EglTestContext& eglTestCtx, const string& name, const string& desc);
-	void	init						(void);
-};
-
-MultiContextRenderTests::MultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
-	: RenderTests	(eglTestCtx, name, desc)
-{
-}
-
-void MultiContextRenderTests::init (void)
-{
-	addCreateTexture2DActions("texture_");
-	addCreateTextureCubemapActions("_rgba8", GL_RGBA, GL_UNSIGNED_BYTE);
-	addCreateTextureCubemapActions("_rgb8", GL_RGB, GL_UNSIGNED_BYTE);
-	addCreateRenderbufferActions();
-	addCreateAndroidNativeActions();
-	addRenderActions();
-
-	for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
-	{
-		const LabeledAction& createAction = m_createActions[createNdx];
-		for (int renderNdx = 0; renderNdx < m_renderActions.size(); renderNdx++)
-		{
-			const LabeledAction&	renderAction	= m_renderActions[renderNdx];
-			TestSpec				spec;
-
-			if (!isCompatibleCreateAndRenderActions(*createAction.action, *renderAction.action))
-				continue;
-
-			spec.name = std::string("gles2_") + createAction.label + "_" + renderAction.label;
-			spec.desc = spec.name;
-
-			spec.contexts.push_back(TestSpec::API_GLES2);
-			spec.contexts.push_back(TestSpec::API_GLES2);
-
-			spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
-			spec.operations.push_back(TestSpec::Operation(1, *renderAction.action));
-			spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
-			spec.operations.push_back(TestSpec::Operation(1, *createAction.action));
-			spec.operations.push_back(TestSpec::Operation(1, *renderAction.action));
-			spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
-
-			addChild(new ImageFormatCase(m_eglTestCtx, spec));
-		}
-	}
-}
-
-TestCaseGroup* createMultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
-{
-	return new MultiContextRenderTests(eglTestCtx, name, desc);
-}
-
-class ModifyTests : public ImageTests
-{
-public:
-								ModifyTests		(EglTestContext& eglTestCtx, const string& name, const string& desc)
-									: ImageTests(eglTestCtx, name, desc) {}
-
-	void						init			(void);
-
-protected:
-	void						addModifyActions(void);
-
-	LabeledActions				m_modifyActions;
-	GLES2ImageApi::RenderTryAll	m_renderAction;
-};
-
-void ModifyTests::addModifyActions (void)
-{
-	m_modifyActions.add("tex_subimage_rgb8",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB,	GL_UNSIGNED_BYTE)));
-	m_modifyActions.add("tex_subimage_rgb565",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB, 	GL_UNSIGNED_SHORT_5_6_5)));
-	m_modifyActions.add("tex_subimage_rgba8",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA,	GL_UNSIGNED_BYTE)));
-	m_modifyActions.add("tex_subimage_rgba5_a1",		MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA,	GL_UNSIGNED_SHORT_5_5_5_1)));
-	m_modifyActions.add("tex_subimage_rgba4",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA,	GL_UNSIGNED_SHORT_4_4_4_4)));
-
-	m_modifyActions.add("renderbuffer_clear_color",		MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearColor(tcu::Vec4(0.3f, 0.5f, 0.3f, 1.0f))));
-	m_modifyActions.add("renderbuffer_clear_depth",		MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearDepth(0.7f)));
-	m_modifyActions.add("renderbuffer_clear_stencil",	MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearStencil(78)));
-}
-
 bool isCompatibleFormats (GLenum createFormat, GLenum modifyFormat)
 {
 	switch (createFormat)
@@ -1311,6 +1237,102 @@
 	return false;
 }
 
+class MultiContextRenderTests : public RenderTests
+{
+public:
+					MultiContextRenderTests		(EglTestContext& eglTestCtx, const string& name, const string& desc);
+	void			init						(void);
+	void			addClearActions				(void);
+private:
+	LabeledActions	m_clearActions;
+};
+
+MultiContextRenderTests::MultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
+	: RenderTests	(eglTestCtx, name, desc)
+{
+}
+
+void MultiContextRenderTests::addClearActions (void)
+{
+	m_clearActions.add("renderbuffer_clear_color",		MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearColor(tcu::Vec4(0.8f, 0.2f, 0.9f, 1.0f))));
+	m_clearActions.add("renderbuffer_clear_depth",		MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearDepth(0.75f)));
+	m_clearActions.add("renderbuffer_clear_stencil",	MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearStencil(97)));
+}
+
+void MultiContextRenderTests::init (void)
+{
+	addCreateTexture2DActions("texture_");
+	addCreateTextureCubemapActions("_rgba8", GL_RGBA, GL_UNSIGNED_BYTE);
+	addCreateTextureCubemapActions("_rgb8", GL_RGB, GL_UNSIGNED_BYTE);
+	addCreateRenderbufferActions();
+	addCreateAndroidNativeActions();
+	addRenderActions();
+	addClearActions();
+
+	for (int createNdx = 0; createNdx < m_createActions.size(); createNdx++)
+	for (int renderNdx = 0; renderNdx < m_renderActions.size(); renderNdx++)
+	for (int clearNdx = 0; clearNdx < m_clearActions.size(); clearNdx++)
+	{
+		const LabeledAction&	createAction	= m_createActions[createNdx];
+		const LabeledAction&	renderAction	= m_renderActions[renderNdx];
+		const LabeledAction&	clearAction		= m_clearActions[clearNdx];
+		TestSpec				spec;
+
+		if (!isCompatibleCreateAndRenderActions(*createAction.action, *renderAction.action))
+			continue;
+		if (!isCompatibleCreateAndModifyActions(*createAction.action, *clearAction.action))
+			continue;
+
+		spec.name = std::string("gles2_") + createAction.label + "_" + renderAction.label;
+		spec.desc = spec.name;
+
+		spec.contexts.push_back(TestSpec::API_GLES2);
+		spec.contexts.push_back(TestSpec::API_GLES2);
+
+		spec.operations.push_back(TestSpec::Operation(0, *createAction.action));
+		spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
+		spec.operations.push_back(TestSpec::Operation(0, *clearAction.action));
+		spec.operations.push_back(TestSpec::Operation(1, *createAction.action));
+		spec.operations.push_back(TestSpec::Operation(0, *renderAction.action));
+		spec.operations.push_back(TestSpec::Operation(1, *renderAction.action));
+
+		addChild(new ImageFormatCase(m_eglTestCtx, spec));
+	}
+}
+
+TestCaseGroup* createMultiContextRenderTests (EglTestContext& eglTestCtx, const string& name, const string& desc)
+{
+	return new MultiContextRenderTests(eglTestCtx, name, desc);
+}
+
+class ModifyTests : public ImageTests
+{
+public:
+								ModifyTests		(EglTestContext& eglTestCtx, const string& name, const string& desc)
+									: ImageTests(eglTestCtx, name, desc) {}
+
+	void						init			(void);
+
+protected:
+	void						addModifyActions(void);
+
+	LabeledActions				m_modifyActions;
+	GLES2ImageApi::RenderTryAll	m_renderAction;
+};
+
+void ModifyTests::addModifyActions (void)
+{
+	m_modifyActions.add("tex_subimage_rgb8",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB,	GL_UNSIGNED_BYTE)));
+	m_modifyActions.add("tex_subimage_rgb565",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGB, 	GL_UNSIGNED_SHORT_5_6_5)));
+	m_modifyActions.add("tex_subimage_rgba8",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA,	GL_UNSIGNED_BYTE)));
+	m_modifyActions.add("tex_subimage_rgba5_a1",		MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA,	GL_UNSIGNED_SHORT_5_5_5_1)));
+	m_modifyActions.add("tex_subimage_rgba4",			MovePtr<Action>(new GLES2ImageApi::ModifyTexSubImage(GL_RGBA,	GL_UNSIGNED_SHORT_4_4_4_4)));
+
+	m_modifyActions.add("renderbuffer_clear_color",		MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearColor(tcu::Vec4(0.3f, 0.5f, 0.3f, 1.0f))));
+	m_modifyActions.add("renderbuffer_clear_depth",		MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearDepth(0.7f)));
+	m_modifyActions.add("renderbuffer_clear_stencil",	MovePtr<Action>(new GLES2ImageApi::ModifyRenderbufferClearStencil(78)));
+}
+
 void ModifyTests::init (void)
 {
 	addCreateTexture2DActions("tex_");
diff --git a/modules/egl/teglImageUtil.cpp b/modules/egl/teglImageUtil.cpp
index badb9ab..9f47f5a 100644
--- a/modules/egl/teglImageUtil.cpp
+++ b/modules/egl/teglImageUtil.cpp
@@ -314,40 +314,123 @@
 	GLenum					m_format;
 };
 
-void initializeStencilRbo(const glw::Functions& gl, GLuint rbo, GLint value, Texture2D& ref)
+void initializeStencilRbo(const glw::Functions& gl, GLuint rbo, Texture2D& ref)
 {
+	static const deUint32 stencilValues[] =
+	{
+		0xBF688C11u,
+		0xB43D2922u,
+		0x055D5FFBu,
+		0x9300655Eu,
+		0x63BE0DF2u,
+		0x0345C13Bu,
+		0x1C184832u,
+		0xD107040Fu,
+		0x9B91569Fu,
+		0x0F0CFDC7u,
+	};
+
 	GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
 												   GL_RENDERBUFFER, rbo));
-	GLU_CHECK_GLW_CALL(gl, clearStencil(value));
+	GLU_CHECK_GLW_CALL(gl, clearStencil(0));
 	GLU_CHECK_GLW_CALL(gl, clear(GL_STENCIL_BUFFER_BIT));
+	tcu::clearStencil(ref.getLevel(0), 0);
+
+	// create a pattern
+	GLU_CHECK_GLW_CALL(gl, enable(GL_SCISSOR_TEST));
+	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(stencilValues); ++ndx)
+	{
+		const tcu::IVec2	size	= tcu::IVec2((int)((DE_LENGTH_OF_ARRAY(stencilValues) - ndx) * (ref.getWidth() / float(DE_LENGTH_OF_ARRAY(stencilValues)))),
+												 (int)((DE_LENGTH_OF_ARRAY(stencilValues) - ndx) * (ref.getHeight() / float(DE_LENGTH_OF_ARRAY(stencilValues) + 4)))); // not symmetric
+
+		if (size.x() == 0 || size.y() == 0)
+			break;
+
+		GLU_CHECK_GLW_CALL(gl, scissor(0, 0, size.x(), size.y()));
+		GLU_CHECK_GLW_CALL(gl, clearStencil(stencilValues[ndx]));
+		GLU_CHECK_GLW_CALL(gl, clear(GL_STENCIL_BUFFER_BIT));
+
+		tcu::clearStencil(tcu::getSubregion(ref.getLevel(0), 0, 0, size.x(), size.y()), stencilValues[ndx]);
+	}
+
+	GLU_CHECK_GLW_CALL(gl, disable(GL_SCISSOR_TEST));
 	GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
 												   GL_RENDERBUFFER, 0));
-
-	tcu::clearStencil(ref.getLevel(0), value);
 }
 
-void initializeDepthRbo(const glw::Functions& gl, GLuint rbo, GLfloat value, Texture2D& ref)
+void initializeDepthRbo(const glw::Functions& gl, GLuint rbo, Texture2D& ref)
 {
+	const int NUM_STEPS = 13;
+
 	GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
 												   GL_RENDERBUFFER, rbo));
-	GLU_CHECK_GLW_CALL(gl, clearDepthf(value));
+
+	GLU_CHECK_GLW_CALL(gl, clearDepthf(0.0f));
 	GLU_CHECK_GLW_CALL(gl, clear(GL_DEPTH_BUFFER_BIT));
+	tcu::clearDepth(ref.getLevel(0), 0.0f);
+
+	// create a pattern
+	GLU_CHECK_GLW_CALL(gl, enable(GL_SCISSOR_TEST));
+	for (int ndx = 0; ndx < NUM_STEPS; ++ndx)
+	{
+		const float			depth	= ndx / float(NUM_STEPS);
+		const tcu::IVec2	size	= tcu::IVec2((int)((NUM_STEPS - ndx) * (ref.getWidth() / float(NUM_STEPS))),
+												 (int)((NUM_STEPS - ndx) * (ref.getHeight() / float(NUM_STEPS + 4)))); // not symmetric
+
+		if (size.x() == 0 || size.y() == 0)
+			break;
+
+		GLU_CHECK_GLW_CALL(gl, scissor(0, 0, size.x(), size.y()));
+		GLU_CHECK_GLW_CALL(gl, clearDepthf(depth));
+		GLU_CHECK_GLW_CALL(gl, clear(GL_DEPTH_BUFFER_BIT));
+
+		tcu::clearDepth(tcu::getSubregion(ref.getLevel(0), 0, 0, size.x(), size.y()), depth);
+	}
+
+	GLU_CHECK_GLW_CALL(gl, disable(GL_SCISSOR_TEST));
 	GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
 												   GL_RENDERBUFFER, 0));
 
-	tcu::clearDepth(ref.getLevel(0), value);
 }
 
-void initializeColorRbo(const glw::Functions& gl, GLuint rbo, GLfloat r, GLfloat g, GLfloat b, GLfloat a, Texture2D& ref)
+void initializeColorRbo(const glw::Functions& gl, GLuint rbo, Texture2D& ref)
 {
+	static const tcu::Vec4 colorValues[] =
+	{
+		tcu::Vec4(0.9f, 0.5f, 0.65f, 1.0f),
+		tcu::Vec4(0.5f, 0.7f, 0.65f, 1.0f),
+		tcu::Vec4(0.2f, 0.5f, 0.65f, 1.0f),
+		tcu::Vec4(0.3f, 0.1f, 0.5f, 1.0f),
+		tcu::Vec4(0.8f, 0.2f, 0.3f, 1.0f),
+		tcu::Vec4(0.9f, 0.4f, 0.8f, 1.0f),
+	};
+
 	GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
 												   GL_RENDERBUFFER, rbo));
-	GLU_CHECK_GLW_CALL(gl, clearColor(r, g, b, a));
+	GLU_CHECK_GLW_CALL(gl, clearColor(1.0f, 1.0f, 0.0f, 1.0f));
 	GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
+	tcu::clear(ref.getLevel(0), Vec4(1.0f, 1.0f, 0.0f, 1.0f));
+
+	// create a pattern
+	GLU_CHECK_GLW_CALL(gl, enable(GL_SCISSOR_TEST));
+	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(colorValues); ++ndx)
+	{
+		const tcu::IVec2	size	= tcu::IVec2((int)((DE_LENGTH_OF_ARRAY(colorValues) - ndx) * (ref.getWidth() / float(DE_LENGTH_OF_ARRAY(colorValues)))),
+												 (int)((DE_LENGTH_OF_ARRAY(colorValues) - ndx) * (ref.getHeight() / float(DE_LENGTH_OF_ARRAY(colorValues) + 4)))); // not symmetric
+
+		if (size.x() == 0 || size.y() == 0)
+			break;
+
+		GLU_CHECK_GLW_CALL(gl, scissor(0, 0, size.x(), size.y()));
+		GLU_CHECK_GLW_CALL(gl, clearColor(colorValues[ndx].x(), colorValues[ndx].y(), colorValues[ndx].z(), colorValues[ndx].w()));
+		GLU_CHECK_GLW_CALL(gl, clear(GL_COLOR_BUFFER_BIT));
+
+		tcu::clear(tcu::getSubregion(ref.getLevel(0), 0, 0, size.x(), size.y()), colorValues[ndx]);
+	}
+
+	GLU_CHECK_GLW_CALL(gl, disable(GL_SCISSOR_TEST));
 	GLU_CHECK_GLW_CALL(gl, framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
 												   GL_RENDERBUFFER, 0));
-
-	tcu::clear(ref.getLevel(0), Vec4(r, g, b, a));
 }
 
 MovePtr<ClientBuffer> RenderbufferImageSource::createBuffer (const glw::Functions& gl, Texture2D* ref) const
@@ -372,19 +455,19 @@
 		switch (m_format)
 		{
 			case GL_STENCIL_INDEX8:
-				initializeStencilRbo(gl, rbo, 235, *ref);
+				initializeStencilRbo(gl, rbo, *ref);
 				break;
 			case GL_DEPTH_COMPONENT16:
-				initializeDepthRbo(gl, rbo, 0.5f, *ref);
+				initializeDepthRbo(gl, rbo, *ref);
 				break;
 			case GL_RGBA4:
-				initializeColorRbo(gl, rbo, 0.9f, 0.5f, 0.65f, 1.0f, *ref);
+				initializeColorRbo(gl, rbo, *ref);
 				break;
 			case GL_RGB5_A1:
-				initializeColorRbo(gl, rbo, 0.5f, 0.7f, 0.65f, 1.0f, *ref);
+				initializeColorRbo(gl, rbo, *ref);
 				break;
 			case GL_RGB565:
-				initializeColorRbo(gl, rbo, 0.2f, 0.5f, 0.65f, 1.0f, *ref);
+				initializeColorRbo(gl, rbo, *ref);
 				break;
 			default:
 				DE_ASSERT(!"Impossible");