13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 2.0 Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Framebuffer Object Tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Notes:
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *   + Like in API tests, tcu::sgl2s::Context class is used.
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *   + ReferenceContext is used to generate reference images.
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *   + API calls can be logged \todo [pyry] Implement.
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fFboRenderTest.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrContextUtil.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrGLContext.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrReferenceContext.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.h"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::RGBA;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Surface;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glw; // GL types
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Shaders.
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FlatColorShader : public sglr::ShaderProgram
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlatColorShader (void)
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::Uniform("u_color", glu::TYPE_FLOAT_VEC4)
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexSource(
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"attribute highp vec4 a_position;\n"
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"void main (void)\n"
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"{\n"
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	gl_Position = a_position;\n"
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"}\n")
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::FragmentSource(
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"uniform mediump vec4 u_color;\n"
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"void main (void)\n"
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"{\n"
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	gl_FragColor = u_color;\n"
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"}\n"))
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void setColor (sglr::Context& gl, deUint32 program, const tcu::Vec4& color)
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.useProgram(program);
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform4fv(gl.getUniformLocation(program, "u_color"), 1, color.getPtr());
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			packets[packetNdx]->position = rr::readVertexAttribFloat(inputs[0], packets[packetNdx]->instanceNdx, packets[packetNdx]->vertexNdx);
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::Vec4 color(m_uniforms[0].value.f4);
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(packets);
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SingleTex2DShader : public sglr::ShaderProgram
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader (void)
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::Uniform("u_sampler0", glu::TYPE_SAMPLER_2D)
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexSource(
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"attribute highp vec4 a_position;\n"
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"attribute mediump vec2 a_coord;\n"
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"varying mediump vec2 v_coord;\n"
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"void main (void)\n"
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"{\n"
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	gl_Position = a_position;\n"
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	v_coord = a_coord;\n"
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"}\n")
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::FragmentSource(
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"uniform sampler2D u_sampler0;\n"
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"varying mediump vec2 v_coord;\n"
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"void main (void)\n"
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"{\n"
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	gl_FragColor = texture2D(u_sampler0, v_coord);\n"
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"}\n"))
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void setUnit (sglr::Context& gl, deUint32 program, int unitNdx)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.useProgram(program);
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform1i(gl.getUniformLocation(program, "u_sampler0"), unitNdx);
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::VertexPacket& packet = *packets[packetNdx];
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			packet.position		= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			packet.outputs[0]	= rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4 v_coord = rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx);
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float		lod		= 0.0f;
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, this->m_uniforms[0].sampler.tex2D->sample(v_coord.x(), v_coord.y(), lod));
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MixTexturesShader : public sglr::ShaderProgram
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MixTexturesShader (void)
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexAttribute("a_coord", rr::GENERICVECTYPE_FLOAT)
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::Uniform("u_sampler0", glu::TYPE_SAMPLER_2D)
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::Uniform("u_sampler1", glu::TYPE_SAMPLER_2D)
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::VertexSource(
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"attribute highp vec4 a_position;\n"
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"attribute mediump vec2 a_coord;\n"
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"varying mediump vec2 v_coord;\n"
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"void main (void)\n"
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"{\n"
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	gl_Position = a_position;\n"
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	v_coord = a_coord;\n"
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"}\n")
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								<< sglr::pdec::FragmentSource(
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"uniform sampler2D u_sampler0;\n"
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"uniform sampler2D u_sampler1;\n"
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"varying mediump vec2 v_coord;\n"
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"void main (void)\n"
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"{\n"
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"	gl_FragColor = texture2D(u_sampler0, v_coord)*0.5 + texture2D(u_sampler1, v_coord)*0.5;\n"
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										"}\n"))
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void setUnits (sglr::Context& gl, deUint32 program, int unit0, int unit1)
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.useProgram(program);
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform1i(gl.getUniformLocation(program, "u_sampler0"), unit0);
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform1i(gl.getUniformLocation(program, "u_sampler1"), unit1);
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::VertexPacket& packet = *packets[packetNdx];
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			packet.position		= rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			packet.outputs[0]	= rr::readVertexAttribFloat(inputs[1], packet.instanceNdx, packet.vertexNdx);
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::Vec4 v_coord = rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx);
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float		lod		= 0.0f;
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			rr::writeFragmentOutput(context, packetNdx, fragNdx, 0,   this->m_uniforms[0].sampler.tex2D->sample(v_coord.x(), v_coord.y(), lod) * 0.5f
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			                                                        + this->m_uniforms[1].sampler.tex2D->sample(v_coord.x(), v_coord.y(), lod) * 0.5f);
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Framebuffer config.
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FboConfig
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FboConfig (void)
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: colorbufferType		(GL_NONE)
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, colorbufferFormat		(GL_NONE)
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthbufferType		(GL_NONE)
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, depthbufferFormat		(GL_NONE)
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencilbufferType		(GL_NONE)
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, stencilbufferFormat	(GL_NONE)
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string				getName			(void) const;
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum					colorbufferType;		//!< GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, GL_RENDERBUFFER
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum					colorbufferFormat;		//!< Internal format for color buffer texture or renderbuffer
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum					depthbufferType;		//!< GL_RENDERBUFFER
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum					depthbufferFormat;
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum					stencilbufferType;		//!< GL_RENDERBUFFER
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum					stencilbufferFormat;
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char*		getFormatName	(GLenum format);
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst char* FboConfig::getFormatName (GLenum format)
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (format)
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB:				return "rgb";
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA:				return "rgba";
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_ALPHA:				return "alpha";
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_LUMINANCE:			return "luminance";
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_LUMINANCE_ALPHA:	return "luminance_alpha";
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB565:				return "rgb565";
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB5_A1:			return "rgb5_a1";
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA4:				return "rgba4";
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA16F:			return "rgba16f";
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB16F:				return "rgb16f";
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_DEPTH_COMPONENT16:	return "depth_component16";
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_STENCIL_INDEX8:		return "stencil_index8";
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:					DE_ASSERT(false); return DE_NULL;
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string FboConfig::getName (void) const
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string name = "";
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (colorbufferType != GL_NONE)
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (colorbufferType)
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_TEXTURE_2D:			name += "tex2d_";	break;
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_TEXTURE_CUBE_MAP:	name += "texcube_";	break;
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_RENDERBUFFER:		name += "rbo_";		break;
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:					DE_ASSERT(false);	break;
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		name += getFormatName(colorbufferFormat);
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (depthbufferType != GL_NONE)
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(depthbufferType == GL_RENDERBUFFER);
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (name.length() > 0)
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			name += "_";
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		name += getFormatName(depthbufferFormat);
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencilbufferType != GL_NONE)
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(stencilbufferType == GL_RENDERBUFFER);
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (name.length() > 0)
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			name += "_";
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		name += getFormatName(stencilbufferFormat);
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return name;
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FboIncompleteException : public tcu::TestError
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						FboIncompleteException		(const FboConfig& config, GLenum reason, const char* file, int line);
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual				~FboIncompleteException		(void) throw() {}
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const FboConfig&	getConfig					(void) const { return m_config; }
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum				getReason					(void) const { return m_reason; }
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FboConfig			m_config;
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum				m_reason;
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* getFboIncompleteReasonName (GLenum reason)
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (reason)
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:			return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:	return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:			return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_UNSUPPORTED:					return "GL_FRAMEBUFFER_UNSUPPORTED";
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_FRAMEBUFFER_COMPLETE:						return "GL_FRAMEBUFFER_COMPLETE";
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:											return "UNKNOWN";
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFboIncompleteException::FboIncompleteException (const FboConfig& config, GLenum reason, const char* file, int line)
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestError("Framebuffer is not complete", getFboIncompleteReasonName(reason), file, line)
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_config(config)
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_reason(reason)
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Framebuffer
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						Framebuffer			(sglr::Context& context, const FboConfig& config, int width, int height, deUint32 fbo = 0, deUint32 colorbuffer = 0, deUint32 depthbuffer = 0, deUint32 stencilbuffer = 0);
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						~Framebuffer		(void);
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const FboConfig&	getConfig			(void) const { return m_config; }
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			getFramebuffer		(void) const { return m_framebuffer; }
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			getColorbuffer		(void) const { return m_colorbuffer; }
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			getDepthbuffer		(void) const { return m_depthbuffer; }
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			getStencilbuffer	(void) const { return m_stencilbuffer; }
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				checkCompleteness	(void);
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				createRbo			(deUint32& name, GLenum format, int width, int height);
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				destroyBuffer		(deUint32 name, GLenum type);
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FboConfig			m_config;
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::Context&		m_context;
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			m_framebuffer;
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			m_colorbuffer;
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			m_depthbuffer;
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			m_stencilbuffer;
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic bool isExtensionSupported (sglr::Context& context, const char* name)
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::istringstream extensions(context.getString(GL_EXTENSIONS));
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string extension;
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	while (std::getline(extensions, extension, ' '))
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (extension == name)
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return true;
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void checkColorFormatSupport (sglr::Context& context, deUint32 sizedFormat)
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (sizedFormat)
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGBA16F:
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RGB16F:
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RG16F:
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_R16F:
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!isExtensionSupported(context, "GL_EXT_color_buffer_half_float"))
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::NotSupportedError("GL_EXT_color_buffer_half_float is not supported");
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4093c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFramebuffer::Framebuffer (sglr::Context& context, const FboConfig& config, int width, int height, deUint32 fbo, deUint32 colorbuffer, deUint32 depthbuffer, deUint32 stencilbuffer)
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_config			(config)
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_context			(context)
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_framebuffer		(fbo)
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_colorbuffer		(colorbuffer)
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_depthbuffer		(depthbuffer)
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_stencilbuffer	(stencilbuffer)
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Verify that color format is supported
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	checkColorFormatSupport(context, config.colorbufferFormat);
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_framebuffer == 0)
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.genFramebuffers(1, &m_framebuffer);
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_config.colorbufferType)
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_TEXTURE_2D:
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_colorbuffer == 0)
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				context.genTextures(1, &m_colorbuffer);
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.bindTexture(GL_TEXTURE_2D, m_colorbuffer);
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.texImage2D(GL_TEXTURE_2D, 0, m_config.colorbufferFormat, width, height);
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!deIsPowerOfTwo32(width) || !deIsPowerOfTwo32(height))
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Set wrap mode to clamp for NPOT FBOs
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorbuffer, 0);
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_TEXTURE_CUBE_MAP:
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(!"TODO");
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RENDERBUFFER:
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			createRbo(m_colorbuffer, m_config.colorbufferFormat, width, height);
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorbuffer);
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(m_config.colorbufferType == GL_NONE);
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_config.depthbufferType == GL_RENDERBUFFER)
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createRbo(m_depthbuffer, m_config.depthbufferFormat, width, height);
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthbuffer);
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_config.depthbufferType == GL_NONE);
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_config.stencilbufferType == GL_RENDERBUFFER)
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createRbo(m_stencilbuffer, m_config.stencilbufferFormat, width, height);
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilbuffer);
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_config.stencilbufferType == GL_NONE);
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 0);
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFramebuffer::~Framebuffer (void)
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context.deleteFramebuffers(1, &m_framebuffer);
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	destroyBuffer(m_colorbuffer, m_config.colorbufferType);
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	destroyBuffer(m_depthbuffer, m_config.depthbufferType);
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	destroyBuffer(m_stencilbuffer, m_config.stencilbufferType);
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Framebuffer::checkCompleteness (void)
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context.bindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum status = m_context.checkFramebufferStatus(GL_FRAMEBUFFER);
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context.bindFramebuffer(GL_FRAMEBUFFER, 0);
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (status != GL_FRAMEBUFFER_COMPLETE)
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw FboIncompleteException(m_config, status, __FILE__, __LINE__);
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Framebuffer::createRbo (deUint32& name, GLenum format, int width, int height)
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (name == 0)
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.genRenderbuffers(1, &name);
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context.bindRenderbuffer(GL_RENDERBUFFER, name);
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_context.renderbufferStorage(GL_RENDERBUFFER, format, width, height);
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Framebuffer::destroyBuffer (deUint32 name, GLenum type)
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (type == GL_TEXTURE_2D || type == GL_TEXTURE_CUBE_MAP)
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.deleteTextures(1, &name);
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (type == GL_RENDERBUFFER)
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.deleteRenderbuffers(1, &name);
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(type == GL_NONE);
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void createMetaballsTex2D (sglr::Context& context, deUint32 name, GLenum format, GLenum dataType, int width, int height)
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormat	texFormat	= glu::mapGLTransferFormat(format, dataType);
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel	level		(texFormat, width, height);
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::fillWithMetaballs(level.getAccess(), 5, name ^ width ^ height);
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, name);
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, dataType, level.getAccess().getDataPtr());
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void createQuadsTex2D (sglr::Context& context, deUint32 name, GLenum format, GLenum dataType, int width, int height)
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureFormat	texFormat	= glu::mapGLTransferFormat(format, dataType);
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel	level		(texFormat, width, height);
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::fillWithRGBAQuads(level.getAccess());
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, name);
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, dataType, level.getAccess().getDataPtr());
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FboRenderCase : public TestCase
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								FboRenderCase			(Context& context, const char* name, const char* description, const FboConfig& config);
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual						~FboRenderCase			(void) {}
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual IterateResult		iterate					(void);
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void				render					(sglr::Context& fboContext, Surface& dst) = DE_NULL;
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const FboConfig&			getConfig				(void) const { return m_config; }
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool					isConfigSupported		(const FboConfig& config) { DE_UNREF(config); return true; }
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FboConfig					m_config;
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5523c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFboRenderCase::FboRenderCase (Context& context, const char* name, const char* description, const FboConfig& config)
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase(context, name, description)
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_config(config)
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCase::IterateResult FboRenderCase::iterate (void)
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vec4						clearColor				(0.125f, 0.25f, 0.5f, 1.0f);
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::RenderContext&			renderCtx				= m_context.getRenderContext();
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::RenderTarget&	renderTarget			= m_context.getRenderTarget();
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestLog&				log						= m_testCtx.getLog();
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*					failReason				= DE_NULL;
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Position & size for context
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom rnd;
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom_init(&rnd, deStringHash(getName()));
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		width	= deMin32(renderTarget.getWidth(), 128);
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		height	= deMin32(renderTarget.getHeight(), 128);
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		xMax	= renderTarget.getWidth()-width+1;
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		yMax	= renderTarget.getHeight()-height+1;
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		x		= deRandom_getUint32(&rnd) % xMax;
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		y		= deRandom_getUint32(&rnd) % yMax;
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface	gles2Frame	(width, height);
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface	refFrame	(width, height);
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum			gles2Error;
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum			refError;
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render using GLES2
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::GLContext context(renderCtx, log, sglr::GLCONTEXT_LOG_CALLS, tcu::IVec4(x, y, width, height));
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		render(context, gles2Frame); // Call actual render func
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gles2Error = context.getError();
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (const FboIncompleteException& e)
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (e.getReason() == GL_FRAMEBUFFER_UNSUPPORTED)
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Mark test case as unsupported
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << e;
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not supported");
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return STOP;
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw; // Propagate error
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference image
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::ReferenceContextBuffers	buffers	(tcu::PixelFormat(8,8,8,renderTarget.getPixelFormat().alphaBits?8:0), renderTarget.getDepthBits(), renderTarget.getStencilBits(), width, height);
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::ReferenceContext			context	(sglr::ReferenceContextLimits(renderCtx), buffers.getColorbuffer(), buffers.getDepthbuffer(), buffers.getStencilbuffer());
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		render(context, refFrame);
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		refError = context.getError();
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare error codes
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool errorCodesOk = (gles2Error == refError);
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!errorCodesOk)
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << tcu::TestLog::Message << "Error code mismatch: got " << glu::getErrorStr(gles2Error) << ", expected " << glu::getErrorStr(refError) << tcu::TestLog::EndMessage;
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		failReason = "Got unexpected error";
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare images
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float		threshold	= 0.02f;
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			imagesOk	= tcu::fuzzyCompare(log, "ComparisonResult", "Image comparison result", refFrame, gles2Frame, threshold, tcu::COMPARE_LOG_RESULT);
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!imagesOk && !failReason)
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		failReason = "Image comparison failed";
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Store test result
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool isOk = errorCodesOk && imagesOk;
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							isOk ? "Pass"				: failReason);
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace FboCases
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ColorClearsTest : public FboRenderCase
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						ColorClearsTest				(Context& context, const FboConfig& config);
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						~ColorClearsTest			(void) {}
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				render						(sglr::Context& context, Surface& dst);
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6543c827367444ee418f129b2c238299f49d3264554Jarkko PoyryColorClearsTest::ColorClearsTest (Context& context, const FboConfig& config)
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, config.getName().c_str(), "Color buffer clears", config)
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ColorClearsTest::render (sglr::Context& context, Surface& dst)
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			width	= 128;
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			height	= 128;
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom	rnd;
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deRandom_init(&rnd, 0);
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create framebuffer
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fbo(context, getConfig(), width, height);
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fbo.checkCompleteness();
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Clear fbo
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, width, height);
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Enable scissor test.
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_SCISSOR_TEST);
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Do 10 random color clears
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < 15; i++)
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int		cX		= (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % width;
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int		cY		= (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % height;
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int		cWidth	= (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % (width-cX);
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int		cHeight	= (int)(deRandom_getUint32(&rnd) & 0x7fffffff) % (height-cY);
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Vec4	color	= RGBA(deRandom_getUint32(&rnd)).toVec();
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.scissor(cX, cY, cWidth, cHeight);
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clearColor(color.x(), color.y(), color.z(), color.w());
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clear(GL_COLOR_BUFFER_BIT);
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Disable scissor.
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_SCISSOR_TEST);
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Unbind fbo
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Draw to screen
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SingleTex2DShader	shader;
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32			shaderID = context.createProgram(&shader);
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		shader.setUnit(context, shaderID, 0);
7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Read from screen
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Read from fbo
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, width, height);
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass IntersectingQuadsTest : public FboRenderCase
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					IntersectingQuadsTest			(Context& context, const FboConfig& config, bool npot = false);
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~IntersectingQuadsTest			(void) {}
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void	render							(sglr::Context& context, Surface& dst);
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isConfigSupported				(const FboConfig& config);
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_fboWidth;
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_fboHeight;
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass IntersectingQuadsNpotTest : public IntersectingQuadsTest
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IntersectingQuadsNpotTest (Context& context, const FboConfig& config)
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: IntersectingQuadsTest(context, config, true)
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIntersectingQuadsTest::IntersectingQuadsTest (Context& context, const FboConfig& config, bool npot)
7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase	(context, (string(npot ? "npot_" : "") + config.getName()).c_str(), "Intersecting textured quads", config)
7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboWidth	(npot ? 127 : 128)
7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboHeight	(npot ?  95 : 128)
7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool IntersectingQuadsTest::isConfigSupported (const FboConfig& config)
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note Disabled for stencil configurations since doesn't exercise stencil buffer
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.depthbufferType	!= GL_NONE &&
7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.stencilbufferType	== GL_NONE;
7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid IntersectingQuadsTest::render (sglr::Context& ctx, Surface& dst)
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	texShader;
7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			texShaderID = ctx.createProgram(&texShader);
7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 metaballsTex	= 1;
7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 quadsTex		= 2;
7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(ctx, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createQuadsTex2D(ctx, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int width	= m_fboWidth;
7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int height	= m_fboHeight;
7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fbo(ctx, getConfig(), width, height);
7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fbo.checkCompleteness();
7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup shaders
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	texShader.setUnit(ctx, texShaderID, 0);
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw scene
7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.viewport(0, 0, width, height);
7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.enable(GL_DEPTH_TEST);
7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindTexture(GL_TEXTURE_2D, metaballsTex);
7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindTexture(GL_TEXTURE_2D, quadsTex);
7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 1.0f), Vec3(1.0f, 1.0f, -1.0f));
7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.disable(GL_DEPTH_TEST);
7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Unbind fbo
7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Draw to screen
8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.viewport(0, 0, ctx.getWidth(), ctx.getHeight());
8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Read from screen
8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.readPixels(dst, 0, 0, ctx.getWidth(), ctx.getHeight());
8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Read from fbo
8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.readPixels(dst, 0, 0, width, height);
8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MixTest : public FboRenderCase
8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						MixTest				(Context& context, const FboConfig& config, bool npot = false);
8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual				~MixTest			(void) {}
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				render				(sglr::Context& context, Surface& dst);
8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool			isConfigSupported	(const FboConfig& config);
8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboAWidth;
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboAHeight;
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboBWidth;
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboBHeight;
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MixNpotTest : public MixTest
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MixNpotTest (Context& context, const FboConfig& config)
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: MixTest(context, config, true)
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8413c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMixTest::MixTest (Context& context, const FboConfig& config, bool npot)
8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase	(context, (string(npot ? "mix_npot_" : "mix_") + config.getName()).c_str(), "Use two fbos as sources in draw operation", config)
8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboAWidth	(npot ? 127 : 128)
8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboAHeight	(npot ?  95 : 128)
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboBWidth	(npot ?  55 :  64)
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboBHeight	(npot ?  63 :  64)
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool MixTest::isConfigSupported (const FboConfig& config)
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note Disabled for stencil configurations since doesn't exercise stencil buffer
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.colorbufferType	== GL_TEXTURE_2D &&
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.stencilbufferType	== GL_NONE;
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MixTest::render (sglr::Context& context, Surface& dst)
8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	singleTexShader;
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MixTexturesShader	mixShader;
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			singleTexShaderID	= context.createProgram(&singleTexShader);
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			mixShaderID			= context.createProgram(&mixShader);
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Texture with metaballs
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 metaballsTex = 1;
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.pixelStorei(GL_UNPACK_ALIGNMENT, 1);
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup shaders
8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	singleTexShader.setUnit(context, singleTexShaderID, 0);
8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	mixShader.setUnits(context, mixShaderID, 0, 1);
8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fbo, quad with metaballs texture
8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fboA(context, getConfig(), m_fboAWidth, m_fboAHeight);
8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fboA.checkCompleteness();
8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, m_fboAWidth, m_fboAHeight);
8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, singleTexShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fbo, color clears
8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fboB(context, getConfig(), m_fboBWidth, m_fboBHeight);
8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fboB.checkCompleteness();
8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, m_fboBWidth, m_fboBHeight);
8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_SCISSOR_TEST);
8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(0, 0, 32, 64);
8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT);
8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(32, 0, 32, 64);
8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 1.0f, 0.0f, 1.0f);
8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT);
8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_SCISSOR_TEST);
8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Final mix op
8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.activeTexture(GL_TEXTURE0);
9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fboA.getColorbuffer());
9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.activeTexture(GL_TEXTURE1);
9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fboB.getColorbuffer());
9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 0);
9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, context.getWidth(), context.getHeight());
9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, mixShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BlendTest : public FboRenderCase
9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						BlendTest			(Context& context, const FboConfig& config, bool npot = false);
9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual				~BlendTest			(void) {}
9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				render				(sglr::Context& context, Surface& dst);
9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool			isConfigSupported	(const FboConfig& config);
9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboWidth;
9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboHeight;
9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BlendNpotTest : public BlendTest
9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BlendNpotTest (Context& context, const FboConfig& config)
9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: BlendTest(context, config, true)
9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBlendTest::BlendTest (Context& context, const FboConfig& config, bool npot)
9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase	(context, (string(npot ? "blend_npot_" : "blend_") + config.getName()).c_str(), "Blend to fbo", config)
9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboWidth	(npot ? 111 : 128)
9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboHeight	(npot ? 122 : 128)
9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool BlendTest::isConfigSupported (const FboConfig& config)
9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note Disabled for stencil configurations since doesn't exercise stencil buffer
9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.stencilbufferType	== GL_NONE;
9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BlendTest::render (sglr::Context& context, Surface& dst)
9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	shader;
9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			shaderID		= context.createProgram(&shader);
9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					width			= m_fboWidth;
9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					height			= m_fboHeight;
9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			metaballsTex	= 1;
9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, 64, 64);
9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fbo(context, getConfig(), width, height);
9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fbo.checkCompleteness();
9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	shader.setUnit(context, shaderID, 0);
9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, width, height);
9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.6f, 0.0f, 0.6f, 1.0f);
9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_BLEND);
9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.blendEquation(GL_FUNC_ADD);
9703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_BLEND);
9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, width, height);
9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass StencilClearsTest : public FboRenderCase
9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						StencilClearsTest		(Context& context, const FboConfig& config);
9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual				~StencilClearsTest		(void) {};
9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				render					(sglr::Context& context, Surface& dst);
9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool			isConfigSupported		(const FboConfig& config);
9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9973c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStencilClearsTest::StencilClearsTest (Context& context, const FboConfig& config)
9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, config.getName().c_str(), "Stencil clears", config)
9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid StencilClearsTest::render (sglr::Context& context, Surface& dst)
10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	shader;
10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			shaderID		= context.createProgram(&shader);
10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					width			= 128;
10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					height			= 128;
10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			quadsTex		= 1;
10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			metaballsTex	= 2;
10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createQuadsTex2D(context, quadsTex, GL_RGBA, GL_UNSIGNED_BYTE, width, height);
10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, width, height);
10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fbo(context, getConfig(), width, height);
10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fbo.checkCompleteness();
10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bind framebuffer and clear
10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, width, height);
10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Do stencil clears
10243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_SCISSOR_TEST);
10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(10, 16, 32, 120);
10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearStencil(1);
10273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_STENCIL_BUFFER_BIT);
10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(16, 32, 100, 64);
10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearStencil(2);
10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_STENCIL_BUFFER_BIT);
10313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_SCISSOR_TEST);
10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw 2 textures with stecil tests
10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.activeTexture(GL_TEXTURE0);
10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, quadsTex);
10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.activeTexture(GL_TEXTURE1);
10373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_STENCIL_TEST);
10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.stencilFunc(GL_EQUAL, 1, 0xffffffffu);
10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	shader.setUnit(context, shaderID, 0);
10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.stencilFunc(GL_EQUAL, 2, 0xffffffffu);
10453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	shader.setUnit(context, shaderID, 1);
10463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
10473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_STENCIL_TEST);
10493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
10513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
10533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.activeTexture(GL_TEXTURE0);
10543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
10553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
10563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		shader.setUnit(context, shaderID, 0);
10573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
10583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
10593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
10613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, width, height);
10623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool StencilClearsTest::isConfigSupported (const FboConfig& config)
10653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.stencilbufferType != GL_NONE;
10673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass StencilTest : public FboRenderCase
10703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
10723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						StencilTest				(Context& context, const FboConfig& config, bool npot = false);
10733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual				~StencilTest			(void) {};
10743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				render					(sglr::Context& context, Surface& dst);
10763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool			isConfigSupported		(const FboConfig& config);
10783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
10803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboWidth;
10813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_fboHeight;
10823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
10833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass StencilNpotTest : public StencilTest
10853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
10873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	StencilNpotTest (Context& context, const FboConfig& config)
10883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: StencilTest(context, config, true)
10893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
10923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10933c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStencilTest::StencilTest (Context& context, const FboConfig& config, bool npot)
10943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase	(context, (string(npot ? "npot_" : "") + config.getName()).c_str(), "Stencil ops", config)
10953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboWidth	(npot ?  99 : 128)
10963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fboHeight	(npot ? 110 : 128)
10973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool StencilTest::isConfigSupported (const FboConfig& config)
11013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.stencilbufferType != GL_NONE;
11033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid StencilTest::render (sglr::Context& ctx, Surface& dst)
11063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlatColorShader		colorShader;
11083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	texShader;
11093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			colorShaderID	= ctx.createProgram(&colorShader);
11103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			texShaderID		= ctx.createProgram(&texShader);
11113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					width			= m_fboWidth;
11123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					height			= m_fboHeight;
11133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					texWidth		= 64;
11143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					texHeight		= 64;
11153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			quadsTex		= 1;
11163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			metaballsTex	= 2;
11173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				depth			= getConfig().depthbufferType != GL_NONE;
11183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createQuadsTex2D(ctx, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, texWidth, texHeight);
11203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(ctx, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, texWidth, texHeight);
11213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fbo(ctx, getConfig(), width, height);
11233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fbo.checkCompleteness();
11243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bind framebuffer and clear
11263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
11273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.viewport(0, 0, width, height);
11283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
11293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
11303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render intersecting quads - increment stencil on depth pass
11323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.enable(GL_DEPTH_TEST);
11333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.enable(GL_STENCIL_TEST);
11343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.stencilFunc(GL_ALWAYS, 0, 0xffu);
11353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.stencilOp(GL_KEEP, GL_KEEP, GL_INCR);
11363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	colorShader.setColor(ctx, colorShaderID, Vec4(0.0f, 0.0f, 1.0f, 1.0f));
11383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, colorShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
11393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindTexture(GL_TEXTURE_2D, quadsTex);
11413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	texShader.setUnit(ctx, texShaderID, 0);
11423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(+1.0f, +1.0f, +1.0f));
11433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw quad with stencil test (stencil == 1 or 2 depending on depth) - decrement on stencil failure
11453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.disable(GL_DEPTH_TEST);
11463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.stencilFunc(GL_EQUAL, depth ? 2 : 1, 0xffu);
11473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.stencilOp(GL_DECR, GL_KEEP, GL_KEEP);
11483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	colorShader.setColor(ctx, colorShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
11493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, colorShaderID, Vec3(-0.5f, -0.5f, 0.0f), Vec3(+0.5f, +0.5f, 0.0f));
11503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw metaballs with stencil test where stencil > 1 or 2 depending on depth buffer
11523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindTexture(GL_TEXTURE_2D, metaballsTex);
11533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.stencilFunc(GL_GREATER, depth ? 1 : 2, 0xffu);
11543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
11553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
11563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.disable(GL_STENCIL_TEST);
11583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
11603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
11613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
11623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.activeTexture(GL_TEXTURE0);
11633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
11643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.viewport(0, 0, ctx.getWidth(), ctx.getHeight());
11653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
11663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.readPixels(dst, 0, 0, ctx.getWidth(), ctx.getHeight());
11673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
11693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.readPixels(dst, 0, 0, width, height);
11703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11723c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SharedColorbufferTest : public FboRenderCase
11733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
11753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						SharedColorbufferTest			(Context& context, const FboConfig& config);
11763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual				~SharedColorbufferTest			(void) {};
11773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				render							(sglr::Context& context, Surface& dst);
11793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
11803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11813c827367444ee418f129b2c238299f49d3264554Jarkko PoyrySharedColorbufferTest::SharedColorbufferTest (Context& context, const FboConfig& config)
11823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, config.getName().c_str(), "Shared colorbuffer", config)
11833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid SharedColorbufferTest::render (sglr::Context& context, Surface& dst)
11873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	shader;
11893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			shaderID		= context.createProgram(&shader);
11903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					width			= 128;
11913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					height			= 128;
11923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//	bool				depth			= getConfig().depthbufferFormat		!= GL_NONE;
11933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				stencil			= getConfig().stencilbufferFormat	!= GL_NONE;
11943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Textures
11963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	quadsTex		= 1;
11973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	metaballsTex	= 2;
11983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
11993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(context, metaballsTex, GL_RGBA, GL_UNSIGNED_BYTE, 64, 64);
12003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, width, height);
12023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	shader.setUnit(context, shaderID, 0);
12043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fbo A
12063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fboA(context, getConfig(), width, height);
12073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fboA.checkCompleteness();
12083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fbo B - don't create colorbuffer
12103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FboConfig cfg = getConfig();
12113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	cfg.colorbufferType		= GL_NONE;
12123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	cfg.colorbufferFormat	= GL_NONE;
12133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fboB(context, cfg, width, height);
12143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Attach color buffer from fbo A
12163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
12173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (getConfig().colorbufferType)
12183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
12193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_TEXTURE_2D:
12203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboA.getColorbuffer(), 0);
12213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RENDERBUFFER:
12243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fboA.getColorbuffer());
12253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
12263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
12283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
12293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
12303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Clear depth and stencil in fbo B
12323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
12333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render quads to fbo 1, with depth 0.0
12353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
12363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, quadsTex);
12373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
12383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
12393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
12413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
12423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Stencil to 1 in fbo A
12433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clearStencil(1);
12443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clear(GL_STENCIL_BUFFER_BIT);
12453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
12463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_DEPTH_TEST);
12483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
12493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_DEPTH_TEST);
12503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Blend metaballs to fbo 2
12523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
12533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
12543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_BLEND);
12553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
12563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
12573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render small quad that is only visible if depth buffer is not shared with fbo A - or there is no depth bits
12593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, quadsTex);
12603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_DEPTH_TEST);
12613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(0.5f, 0.5f, 0.5f), Vec3(1.0f, 1.0f, 0.5f));
12623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_DEPTH_TEST);
12633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
12653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
12663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FlatColorShader flatShader;
12673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		flatShaderID = context.createProgram(&flatShader);
12683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		flatShader.setColor(context, flatShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
12703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Clear subset of stencil buffer to 1
12723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.enable(GL_SCISSOR_TEST);
12733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.scissor(10, 10, 12, 25);
12743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clearStencil(1);
12753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clear(GL_STENCIL_BUFFER_BIT);
12763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.disable(GL_SCISSOR_TEST);
12773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render quad with stencil mask == 1
12793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.enable(GL_STENCIL_TEST);
12803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.stencilFunc(GL_EQUAL, 1, 0xffu);
12813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, flatShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
12823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.disable(GL_STENCIL_TEST);
12833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
12843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Get results
12863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fboA.getConfig().colorbufferType == GL_TEXTURE_2D)
12873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
12883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
12893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fboA.getColorbuffer());
12903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
12913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
12923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
12933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
12943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
12953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, width, height);
12963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SharedColorbufferClearsTest : public FboRenderCase
12993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
13013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					SharedColorbufferClearsTest		(Context& context, const FboConfig& config);
13023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~SharedColorbufferClearsTest	(void) {}
13033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isConfigSupported				(const FboConfig& config);
13053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render							(sglr::Context& context, Surface& dst);
13063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
13073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13083c827367444ee418f129b2c238299f49d3264554Jarkko PoyrySharedColorbufferClearsTest::SharedColorbufferClearsTest (Context& context, const FboConfig& config)
13093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, config.getName().c_str(), "Shared colorbuffer clears", config)
13103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool SharedColorbufferClearsTest::isConfigSupported (const FboConfig& config)
13143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.colorbufferType	!= GL_NONE &&
13163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.depthbufferType	== GL_NONE &&
13173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.stencilbufferType	== GL_NONE;
13183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid SharedColorbufferClearsTest::render (sglr::Context& context, Surface& dst)
13213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			width			= 128;
13233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			height			= 128;
13243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	colorbuffer		= 1;
13253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	checkColorFormatSupport(context, getConfig().colorbufferFormat);
13273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Single colorbuffer
13293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (getConfig().colorbufferType == GL_TEXTURE_2D)
13303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
13313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, colorbuffer);
13323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.texImage2D(GL_TEXTURE_2D, 0, getConfig().colorbufferFormat, width, height);
13333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
13343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
13353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
13363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
13373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(getConfig().colorbufferType == GL_RENDERBUFFER);
13383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindRenderbuffer(GL_RENDERBUFFER, colorbuffer);
13393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.renderbufferStorage(GL_RENDERBUFFER, getConfig().colorbufferFormat, width, height);
13403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
13413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Multiple framebuffers sharing the colorbuffer
13433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int fbo = 1; fbo <= 3; fbo++)
13443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
13453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, fbo);
13463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (getConfig().colorbufferType == GL_TEXTURE_2D)
13483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
13493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
13503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer);
13513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
13523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 1);
13543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Check completeness
13563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
13573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLenum status = context.checkFramebufferStatus(GL_FRAMEBUFFER);
13583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (status != GL_FRAMEBUFFER_COMPLETE)
13593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw FboIncompleteException(getConfig(), status, __FILE__, __LINE__);
13603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
13613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render to them
13633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, width, height);
13643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 1.0f, 1.0f);
13653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT);
13663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_SCISSOR_TEST);
13683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 2);
13703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.6f, 0.0f, 0.0f, 1.0f);
13713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(10, 10, 64, 64);
13723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT);
13733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.6f, 0.0f, 1.0f);
13743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(60, 60, 40, 20);
13753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT);
13763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 3);
13783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 0.6f, 1.0f);
13793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(20, 20, 100, 10);
13803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT);
13813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 1);
13833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.6f, 0.0f, 0.6f, 1.0f);
13843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.scissor(20, 20, 5, 100);
13853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT);
13863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_SCISSOR_TEST);
13883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (getConfig().colorbufferType == GL_TEXTURE_2D)
13903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
13913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SingleTex2DShader	shader;
13923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32			shaderID = context.createProgram(&shader);
13933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		shader.setUnit(context, shaderID, 0);
13953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
13973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
13983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, shaderID, Vec3(-0.9f, -0.9f, 0.0f), Vec3(0.9f, 0.9f, 0.0f));
13993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
14003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
14023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, width, height);
14033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SharedDepthbufferTest : public FboRenderCase
14063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
14083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					SharedDepthbufferTest		(Context& context, const FboConfig& config);
14093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~SharedDepthbufferTest		(void) {};
14103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isConfigSupported			(const FboConfig& config);
14123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render						(sglr::Context& context, Surface& dst);
14133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
14143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14153c827367444ee418f129b2c238299f49d3264554Jarkko PoyrySharedDepthbufferTest::SharedDepthbufferTest (Context& context, const FboConfig& config)
14163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, config.getName().c_str(), "Shared depthbuffer", config)
14173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool SharedDepthbufferTest::isConfigSupported (const FboConfig& config)
14213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.depthbufferType == GL_RENDERBUFFER;
14233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid SharedDepthbufferTest::render (sglr::Context& context, Surface& dst)
14263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	texShader;
14283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlatColorShader		colorShader;
14293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			texShaderID		= context.createProgram(&texShader);
14303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			colorShaderID	= context.createProgram(&colorShader);
14313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					width			= 128;
14323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					height			= 128;
14333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				stencil			= getConfig().stencilbufferType != GL_NONE;
14343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup shaders
14363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	texShader.setUnit(context, texShaderID, 0);
14373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	colorShader.setColor(context, colorShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
14383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Textures
14403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 metaballsTex	= 5;
14413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 quadsTex		= 6;
14423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
14433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
14443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, width, height);
14463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fbo A
14483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fboA(context, getConfig(), width, height);
14493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fboA.checkCompleteness();
14503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Fbo B
14523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FboConfig cfg = getConfig();
14533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	cfg.depthbufferType		= GL_NONE;
14543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	cfg.depthbufferFormat	= GL_NONE;
14553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fboB(context, cfg, width, height);
14563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Bind depth buffer from fbo A to fbo B
14583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(fboA.getConfig().depthbufferType == GL_RENDERBUFFER);
14593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
14603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fboA.getDepthbuffer());
14613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Clear fbo B color to red and stencil to 1
14633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
14643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearStencil(1);
14653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
14663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Enable depth test.
14683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_DEPTH_TEST);
14693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render quad to fbo A
14713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboA.getFramebuffer());
14723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, quadsTex);
14733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
14743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
14753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
14763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render metaballs to fbo B
14783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fboB.getFramebuffer());
14793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
14803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f));
14813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_DEPTH_TEST);
14833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
14853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
14863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Clear subset of stencil buffer to 0
14873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.enable(GL_SCISSOR_TEST);
14883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.scissor(10, 10, 12, 25);
14893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clearStencil(0);
14903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clear(GL_STENCIL_BUFFER_BIT);
14913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.disable(GL_SCISSOR_TEST);
14923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render quad with stencil mask == 0
14943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.enable(GL_STENCIL_TEST);
14953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.stencilFunc(GL_EQUAL, 0, 0xffu);
14963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, colorShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
14973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.disable(GL_STENCIL_TEST);
14983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (getConfig().colorbufferType == GL_TEXTURE_2D)
15013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render both to screen
15033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
15043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
15053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fboA.getColorbuffer());
15063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
15073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fboB.getColorbuffer());
15083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, texShaderID, Vec3(0.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
15093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
15113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
15123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
15133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Read results from fbo B
15153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, width, height);
15163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
15173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TexSubImageAfterRenderTest : public FboRenderCase
15203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
15223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TexSubImageAfterRenderTest		(Context& context, const FboConfig& config);
15233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~TexSubImageAfterRenderTest		(void) {}
15243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isConfigSupported				(const FboConfig& config);
15263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render							(sglr::Context& context, Surface& dst);
15273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
15283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15293c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexSubImageAfterRenderTest::TexSubImageAfterRenderTest (Context& context, const FboConfig& config)
15303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, (string("after_render_") + config.getName()).c_str(), "TexSubImage after rendering to texture", config)
15313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool TexSubImageAfterRenderTest::isConfigSupported (const FboConfig& config)
15353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.colorbufferType == GL_TEXTURE_2D &&
15373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   (config.colorbufferFormat == GL_RGB || config.colorbufferFormat == GL_RGBA) &&
15383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.depthbufferType == GL_NONE &&
15393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.stencilbufferType == GL_NONE;
15403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TexSubImageAfterRenderTest::render (sglr::Context& context, Surface& dst)
15433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	shader;
15453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			shaderID	= context.createProgram(&shader);
15463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				isRGBA		= getConfig().colorbufferFormat == GL_RGBA;
15473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel fourQuads(tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8), 64, 64);
15493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::fillWithRGBAQuads(fourQuads.getAccess());
15503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel metaballs(tcu::TextureFormat(isRGBA ? tcu::TextureFormat::RGBA : tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8), 64, 64);
15523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::fillWithMetaballs(metaballs.getAccess(), 5, 3);
15533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	shader.setUnit(context, shaderID, 0);
15553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 fourQuadsTex = 1;
15573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
15583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
15593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, fourQuads.getAccess().getDataPtr());
15603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 1);
15623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 fboTex = 2;
15643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fboTex);
15653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texImage2D(GL_TEXTURE_2D, 0, isRGBA ? GL_RGBA : GL_RGB, 128, 128);
15663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
15673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
15683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render to fbo
15703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, 128, 128);
15713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
15723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
15733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Update texture using TexSubImage2D
15753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fboTex);
15763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texSubImage2D(GL_TEXTURE_2D, 0, 32, 32, 64, 64, isRGBA ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, metaballs.getAccess().getDataPtr());
15773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw to screen
15793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 0);
15803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, context.getWidth(), context.getHeight());
15813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
15823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
15833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TexSubImageBetweenRenderTest : public FboRenderCase
15863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
15883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TexSubImageBetweenRenderTest		(Context& context, const FboConfig& config);
15893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~TexSubImageBetweenRenderTest		(void) {}
15903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isConfigSupported					(const FboConfig& config);
15923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render								(sglr::Context& context, Surface& dst);
15933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
15943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexSubImageBetweenRenderTest::TexSubImageBetweenRenderTest (Context& context, const FboConfig& config)
15963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, (string("between_render_") + config.getName()).c_str(), "TexSubImage between rendering calls", config)
15973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool TexSubImageBetweenRenderTest::isConfigSupported (const FboConfig& config)
16013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return config.colorbufferType == GL_TEXTURE_2D &&
16033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   (config.colorbufferFormat == GL_RGB || config.colorbufferFormat == GL_RGBA) &&
16043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.depthbufferType == GL_NONE &&
16053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   config.stencilbufferType == GL_NONE;
16063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
16073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TexSubImageBetweenRenderTest::render (sglr::Context& context, Surface& dst)
16093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	shader;
16113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			shaderID	= context.createProgram(&shader);
16123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				isRGBA		= getConfig().colorbufferFormat == GL_RGBA;
16133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel fourQuads(tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8), 64, 64);
16153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::fillWithRGBAQuads(fourQuads.getAccess());
16163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel metaballs(tcu::TextureFormat(isRGBA ? tcu::TextureFormat::RGBA : tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8), 64, 64);
16183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::fillWithMetaballs(metaballs.getAccess(), 5, 3);
16193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TextureLevel metaballs2(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 64, 64);
16213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::fillWithMetaballs(metaballs2.getAccess(), 5, 4);
16223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 metaballsTex = 3;
16243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
16253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
16263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, metaballs2.getAccess().getDataPtr());
16273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 fourQuadsTex = 1;
16293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
16303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
16313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, fourQuads.getAccess().getDataPtr());
16323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 1);
16343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 fboTex = 2;
16363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fboTex);
16373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texImage2D(GL_TEXTURE_2D, 0, isRGBA ? GL_RGBA : GL_RGB, 128, 128);
16383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
16393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
16403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	shader.setUnit(context, shaderID, 0);
16423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render to fbo
16443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, 128, 128);
16453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fourQuadsTex);
16463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
16473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Update texture using TexSubImage2D
16493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fboTex);
16503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.texSubImage2D(GL_TEXTURE_2D, 0, 32, 32, 64, 64, isRGBA ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, metaballs.getAccess().getDataPtr());
16513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render again to fbo
16533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
16543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_BLEND);
16553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
16563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
16573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_BLEND);
16583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw to screen
16603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, 0);
16613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, context.getWidth(), context.getHeight());
16623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, fboTex);
16633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
16643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
16663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
16673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ResizeTest : public FboRenderCase
16693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16703c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
16713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ResizeTest				(Context& context, const FboConfig& config);
16723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~ResizeTest				(void) {}
16733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render					(sglr::Context& context, Surface& dst);
16753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
16763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16773c827367444ee418f129b2c238299f49d3264554Jarkko PoyryResizeTest::ResizeTest (Context& context, const FboConfig& config)
16783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase(context, config.getName().c_str(), "Resize framebuffer", config)
16793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
16813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ResizeTest::render (sglr::Context& context, Surface& dst)
16833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	texShader;
16853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlatColorShader		colorShader;
16863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			texShaderID		= context.createProgram(&texShader);
16873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			colorShaderID	= context.createProgram(&colorShader);
16883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			quadsTex		= 1;
16893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			metaballsTex	= 2;
16903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				depth			= getConfig().depthbufferType	 != GL_NONE;
16913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				stencil			= getConfig().stencilbufferType	 != GL_NONE;
16923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createQuadsTex2D(context, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
16943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(context, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 32, 32);
16953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fbo(context, getConfig(), 128, 128);
16973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fbo.checkCompleteness();
16983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup shaders
17003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	texShader.setUnit(context, texShaderID, 0);
17013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	colorShader.setColor(context, colorShaderID, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
17023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render quads
17043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
17053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, 128, 128);
17063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
17073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
17083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, quadsTex);
17093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
17103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
17123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render fbo to screen
17143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
17153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
17163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
17173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
17183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Restore binding
17203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
17213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int newWidth	= 64;
17243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int newHeight	= 32;
17253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Resize buffers
17273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (fbo.getConfig().colorbufferType)
17283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_TEXTURE_2D:
17303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
17313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.texImage2D(GL_TEXTURE_2D, 0, fbo.getConfig().colorbufferFormat, newWidth, newHeight);
17323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case GL_RENDERBUFFER:
17353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getColorbuffer());
17363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().colorbufferFormat, newWidth, newHeight);
17373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
17383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
17403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
17413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (depth)
17443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(fbo.getConfig().depthbufferType == GL_RENDERBUFFER);
17463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getDepthbuffer());
17473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().depthbufferFormat, newWidth, newHeight);
17483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
17513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(fbo.getConfig().stencilbufferType == GL_RENDERBUFFER);
17533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindRenderbuffer(GL_RENDERBUFFER, fbo.getStencilbuffer());
17543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().stencilbufferFormat, newWidth, newHeight);
17553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render to resized fbo
17583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.viewport(0, 0, newWidth, newHeight);
17593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
17603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
17613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.enable(GL_DEPTH_TEST);
17633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, metaballsTex);
17653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
17663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.bindTexture(GL_TEXTURE_2D, quadsTex);
17683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(context, texShaderID, Vec3(0.0f, 0.0f, -1.0f), Vec3(+1.0f, +1.0f, 1.0f));
17693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	context.disable(GL_DEPTH_TEST);
17713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
17733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.enable(GL_SCISSOR_TEST);
17753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.scissor(10, 10, 5, 15);
17763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clearStencil(1);
17773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.clear(GL_STENCIL_BUFFER_BIT);
17783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.disable(GL_SCISSOR_TEST);
17793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.enable(GL_STENCIL_TEST);
17813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.stencilFunc(GL_EQUAL, 1, 0xffu);
17823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, colorShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
17833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.disable(GL_STENCIL_TEST);
17843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (getConfig().colorbufferType == GL_TEXTURE_2D)
17873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindFramebuffer(GL_FRAMEBUFFER, 0);
17893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.viewport(0, 0, context.getWidth(), context.getHeight());
17903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
17913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(context, texShaderID, Vec3(-0.5f, -0.5f, 0.0f), Vec3(0.5f, 0.5f, 0.0f));
17923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, context.getWidth(), context.getHeight());
17933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
17953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		context.readPixels(dst, 0, 0, newWidth, newHeight);
17963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
17973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17983c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <GLenum Buffers>
17993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RecreateBuffersTest : public FboRenderCase
18003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
18023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					RecreateBuffersTest			(Context& context, const FboConfig& config, bool rebind);
18033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~RecreateBuffersTest		(void) {}
18043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isConfigSupported			(const FboConfig& config);
18063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			render						(sglr::Context& context, Surface& dst);
18073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
18093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			m_rebind;
18103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
18113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <GLenum Buffers>
18133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RecreateBuffersNoRebindTest : public RecreateBuffersTest<Buffers>
18143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
18163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RecreateBuffersNoRebindTest (Context& context, const FboConfig& config)
18173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: RecreateBuffersTest<Buffers>(context, config, false)
18183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
18213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <GLenum Buffers>
18233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RecreateBuffersRebindTest : public RecreateBuffersTest<Buffers>
18243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
18263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RecreateBuffersRebindTest (Context& context, const FboConfig& config)
18273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: RecreateBuffersTest<Buffers>(context, config, true)
18283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
18313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <GLenum Buffers>
18333c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRecreateBuffersTest<Buffers>::RecreateBuffersTest (Context& context, const FboConfig& config, bool rebind)
18343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: FboRenderCase		(context, (string(rebind ? "rebind_" : "no_rebind_") + config.getName()).c_str(), "Recreate buffers", config)
18353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_rebind			(rebind)
18363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
18383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <GLenum Buffers>
18403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool RecreateBuffersTest<Buffers>::isConfigSupported (const FboConfig& config)
18413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((Buffers & GL_COLOR_BUFFER_BIT) && config.colorbufferType == GL_NONE)
18433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
18443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((Buffers & GL_DEPTH_BUFFER_BIT) && config.depthbufferType == GL_NONE)
18453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
18463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((Buffers & GL_STENCIL_BUFFER_BIT) && config.stencilbufferType == GL_NONE)
18473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
18483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return true;
18493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
18503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <GLenum Buffers>
18523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RecreateBuffersTest<Buffers>::render (sglr::Context& ctx, Surface& dst)
18533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleTex2DShader	texShader;
18553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			texShaderID		= ctx.createProgram(&texShader);
18563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					width			= 128;
18573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					height			= 128;
18583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			metaballsTex	= 1;
18593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			quadsTex		= 2;
18603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				stencil			= getConfig().stencilbufferType != GL_NONE;
18613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createQuadsTex2D(ctx, quadsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
18633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createMetaballsTex2D(ctx, metaballsTex, GL_RGB, GL_UNSIGNED_BYTE, 64, 64);
18643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Framebuffer fbo(ctx, getConfig(), width, height);
18663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fbo.checkCompleteness();
18673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup shader
18693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	texShader.setUnit(ctx, texShaderID, 0);
18703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw scene
18723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
18733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.viewport(0, 0, width, height);
18743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
18753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
18763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.enable(GL_DEPTH_TEST);
18783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindTexture(GL_TEXTURE_2D, quadsTex);
18803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
18813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
18833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.enable(GL_SCISSOR_TEST);
18853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.scissor(width/4, height/4, width/2, height/2);
18863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.clearStencil(1);
18873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.clear(GL_STENCIL_BUFFER_BIT);
18883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.disable(GL_SCISSOR_TEST);
18893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Recreate buffers
18923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_rebind)
18933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
18943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (Buffers & GL_COLOR_BUFFER_BIT)
18963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32 colorbuf = fbo.getColorbuffer();
18983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (fbo.getConfig().colorbufferType)
18993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
19003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_TEXTURE_2D:
19013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.deleteTextures(1, &colorbuf);
19023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.bindTexture(GL_TEXTURE_2D, colorbuf);
19033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.texImage2D(GL_TEXTURE_2D, 0, fbo.getConfig().colorbufferFormat, width, height);
19043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
19053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_rebind)
19073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ctx.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuf, 0);
19083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
19093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case GL_RENDERBUFFER:
19113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.deleteRenderbuffers(1, &colorbuf);
19123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.bindRenderbuffer(GL_RENDERBUFFER, colorbuf);
19133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().colorbufferFormat, width, height);
19143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (m_rebind)
19163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ctx.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuf);
19173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
19183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
19203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(false);
19213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
19223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (Buffers & GL_DEPTH_BUFFER_BIT)
19253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32 depthbuf = fbo.getDepthbuffer();
19273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(fbo.getConfig().depthbufferType == GL_RENDERBUFFER);
19283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.deleteRenderbuffers(1, &depthbuf);
19303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindRenderbuffer(GL_RENDERBUFFER, depthbuf);
19313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().depthbufferFormat, width, height);
19323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_rebind)
19343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ctx.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuf);
19353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (Buffers & GL_STENCIL_BUFFER_BIT)
19383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32 stencilbuf = fbo.getStencilbuffer();
19403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(fbo.getConfig().stencilbufferType == GL_RENDERBUFFER);
19413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.deleteRenderbuffers(1, &stencilbuf);
19433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindRenderbuffer(GL_RENDERBUFFER, stencilbuf);
19443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.renderbufferStorage(GL_RENDERBUFFER, fbo.getConfig().stencilbufferFormat, width, height);
19453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_rebind)
19473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ctx.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilbuf);
19483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_rebind)
19513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindFramebuffer(GL_FRAMEBUFFER, fbo.getFramebuffer());
19523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clearColor(0.0f, 0.0f, 1.0f, 0.0f);
19543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clearStencil(0);
19553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.clear(Buffers); // \note Clear only buffers that were re-created
19563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
19583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// \note Stencil test enabled only if we have stencil buffer
19603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.enable(GL_STENCIL_TEST);
19613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.stencilFunc(GL_EQUAL, 0, 0xffu);
19623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.bindTexture(GL_TEXTURE_2D, metaballsTex);
19643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 1.0f), Vec3(1.0f, 1.0f, -1.0f));
19653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (stencil)
19663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.disable(GL_STENCIL_TEST);
19673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ctx.disable(GL_DEPTH_TEST);
19693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (fbo.getConfig().colorbufferType == GL_TEXTURE_2D)
19713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Unbind fbo
19733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindFramebuffer(GL_FRAMEBUFFER, 0);
19743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Draw to screen
19763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.bindTexture(GL_TEXTURE_2D, fbo.getColorbuffer());
19773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.viewport(0, 0, ctx.getWidth(), ctx.getHeight());
19783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sglr::drawQuad(ctx, texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f));
19793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Read from screen
19813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.readPixels(dst, 0, 0, ctx.getWidth(), ctx.getHeight());
19823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
19843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Read from fbo
19863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.readPixels(dst, 0, 0, width, height);
19873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
19893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // FboCases
19913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19923c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFboRenderTestGroup::FboRenderTestGroup (Context& context)
19933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "render", "Rendering Tests")
19943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
19963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19973c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFboRenderTestGroup::~FboRenderTestGroup (void)
19983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
20023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TypeFormatPair
20053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum		type;
20073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLenum		format;
20083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
20093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20103c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename CaseType>
20113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid addChildVariants (deqp::gles2::TestCaseGroup* group)
20123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TypeFormatPair colorbufferConfigs[] =
20143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		{ GL_TEXTURE_2D,	GL_ALPHA },
20163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		{ GL_TEXTURE_2D,	GL_LUMINANCE },
20173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		{ GL_TEXTURE_2D,	GL_LUMINANCE_ALPHA },
20183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_TEXTURE_2D,	GL_RGB },
20193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_TEXTURE_2D,	GL_RGBA },
20203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_RENDERBUFFER,	GL_RGB565 },
20213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_RENDERBUFFER,	GL_RGB5_A1 },
20223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_RENDERBUFFER,	GL_RGBA4 },
20233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		{ GL_RENDERBUFFER,	GL_RGBA16F },
20243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//		{ GL_RENDERBUFFER,	GL_RGB16F }
20253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
20263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TypeFormatPair depthbufferConfigs[] =
20273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_NONE,			GL_NONE },
20293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_RENDERBUFFER,	GL_DEPTH_COMPONENT16 }
20303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
20313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TypeFormatPair stencilbufferConfigs[] =
20323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_NONE,			GL_NONE },
20343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_RENDERBUFFER,	GL_STENCIL_INDEX8 }
20353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
20363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int colorbufferNdx = 0; colorbufferNdx < DE_LENGTH_OF_ARRAY(colorbufferConfigs); colorbufferNdx++)
20383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int depthbufferNdx = 0; depthbufferNdx < DE_LENGTH_OF_ARRAY(depthbufferConfigs); depthbufferNdx++)
20393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int stencilbufferNdx = 0; stencilbufferNdx < DE_LENGTH_OF_ARRAY(stencilbufferConfigs); stencilbufferNdx++)
20403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FboConfig config;
20423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config.colorbufferType		= colorbufferConfigs[colorbufferNdx].type;
20433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config.colorbufferFormat	= colorbufferConfigs[colorbufferNdx].format;
20443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config.depthbufferType		= depthbufferConfigs[depthbufferNdx].type;
20453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config.depthbufferFormat	= depthbufferConfigs[depthbufferNdx].format;
20463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config.stencilbufferType	= stencilbufferConfigs[stencilbufferNdx].type;
20473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config.stencilbufferFormat	= stencilbufferConfigs[stencilbufferNdx].format;
20483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (CaseType::isConfigSupported(config))
20503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			group->addChild(new CaseType(group->getContext(), config));
20513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
20523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename CaseType>
20553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid createChildGroup (deqp::gles2::TestCaseGroup* parent, const char* name, const char* description)
20563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deqp::gles2::TestCaseGroup* tmpGroup = new deqp::gles2::TestCaseGroup(parent->getContext(), name, description);
20583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	parent->addChild(tmpGroup);
20593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<CaseType>(tmpGroup);
20603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <GLbitfield Buffers>
20633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid createRecreateBuffersGroup (deqp::gles2::TestCaseGroup* parent, const char* name, const char* description)
20643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deqp::gles2::TestCaseGroup* tmpGroup = new deqp::gles2::TestCaseGroup(parent->getContext(), name, description);
20663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	parent->addChild(tmpGroup);
20673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::RecreateBuffersRebindTest<Buffers> >		(tmpGroup);
20683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::RecreateBuffersNoRebindTest<Buffers> >	(tmpGroup);
20693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
20723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20733c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FboRenderTestGroup::init (void)
20743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createChildGroup<FboCases::ColorClearsTest>					(this, "color_clear",		"Color buffer clears");
20763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createChildGroup<FboCases::StencilClearsTest>				(this, "stencil_clear",		"Stencil buffer clears");
20773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deqp::gles2::TestCaseGroup* colorGroup = new deqp::gles2::TestCaseGroup(m_context, "color", "Color buffer tests");
20793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(colorGroup);
20803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::MixTest>			(colorGroup);
20813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::MixNpotTest>		(colorGroup);
20823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::BlendTest>		(colorGroup);
20833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::BlendNpotTest>	(colorGroup);
20843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deqp::gles2::TestCaseGroup* depthGroup = new deqp::gles2::TestCaseGroup(m_context, "depth", "Depth bufer tests");
20863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(depthGroup);
20873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::IntersectingQuadsTest>		(depthGroup);
20883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::IntersectingQuadsNpotTest>	(depthGroup);
20893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deqp::gles2::TestCaseGroup* stencilGroup = new deqp::gles2::TestCaseGroup(m_context, "stencil", "Stencil buffer tests");
20913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(stencilGroup);
20923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::StencilTest>		(stencilGroup);
20933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::StencilNpotTest>	(stencilGroup);
20943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createChildGroup<FboCases::SharedColorbufferClearsTest>		(this, "shared_colorbuffer_clear",	"Shared colorbuffer clears");
20963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createChildGroup<FboCases::SharedColorbufferTest>			(this, "shared_colorbuffer",		"Shared colorbuffer tests");
20973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createChildGroup<FboCases::SharedDepthbufferTest>			(this, "shared_depthbuffer",		"Shared depthbuffer tests");
20983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createChildGroup<FboCases::ResizeTest>						(this, "resize",					"FBO resize tests");
20993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createRecreateBuffersGroup<GL_COLOR_BUFFER_BIT>				(this, "recreate_colorbuffer",		"Recreate colorbuffer tests");
21013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createRecreateBuffersGroup<GL_DEPTH_BUFFER_BIT>				(this, "recreate_depthbuffer",		"Recreate depthbuffer tests");
21023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	createRecreateBuffersGroup<GL_STENCIL_BUFFER_BIT>			(this, "recreate_stencilbuffer",	"Recreate stencilbuffer tests");
21033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deqp::gles2::TestCaseGroup* texSubImageGroup = new deqp::gles2::TestCaseGroup(m_context, "texsubimage", "TexSubImage interop with FBO colorbuffer texture");
21053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(texSubImageGroup);
21063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::TexSubImageAfterRenderTest>		(texSubImageGroup);
21073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChildVariants<FboCases::TexSubImageBetweenRenderTest>	(texSubImageGroup);
21083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
21093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
21113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
21123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
2113