[Piglit] [PATCH 3/4] piglit-fbo: Enable the tests to create FBO with multiple color attachments

Anuj Phogat anuj.phogat at gmail.com
Fri May 9 12:42:24 PDT 2014


and replace the usage of 'attach_texture' in piglit tests with new method
of specifying color attachments.

Old method:
config.attach_texture = true;

New method:
config.num_rb_attachments = 0;
config.num_tex_attachments = 1;

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 .../attachments-blit-scaled-linear.cpp             |  6 +--
 .../arb_framebuffer_object/blit-scaled-linear.cpp  | 12 ++---
 .../execution/builtin-gl-sample-id.cpp             |  7 +--
 .../execution/builtin-gl-sample-mask.cpp           |  8 +--
 .../execution/ignore-centroid-qualifier.cpp        |  3 +-
 .../execution/interpolate-at-sample-position.cpp   |  3 +-
 tests/spec/ext_framebuffer_multisample/common.cpp  |  5 +-
 .../sample-coverage.cpp                            |  2 +-
 .../blit-scaled.cpp                                | 12 ++---
 tests/util/piglit-fbo.cpp                          | 59 +++++++++++++---------
 tests/util/piglit-fbo.h                            | 31 ++++++------
 11 files changed, 81 insertions(+), 67 deletions(-)

diff --git a/tests/spec/arb_framebuffer_object/attachments-blit-scaled-linear.cpp b/tests/spec/arb_framebuffer_object/attachments-blit-scaled-linear.cpp
index 4dc43da..0772faa 100644
--- a/tests/spec/arb_framebuffer_object/attachments-blit-scaled-linear.cpp
+++ b/tests/spec/arb_framebuffer_object/attachments-blit-scaled-linear.cpp
@@ -61,10 +61,10 @@ piglit_init(int argc, char **argv)
 	 * different color attachment types.
 	 */
 	FboConfig Config(0, pattern_width, pattern_height);
-	Config.attach_texture = true;
-	fbo_tex.setup(Config);
-	Config.attach_texture = false;
 	fbo_rb.setup(Config);
+	Config.num_rb_attachments = 0;
+	Config.num_tex_attachments = 1;
+	fbo_tex.setup(Config);
 
 	test_pattern = new Triangles();
 	test_pattern->compile();
diff --git a/tests/spec/arb_framebuffer_object/blit-scaled-linear.cpp b/tests/spec/arb_framebuffer_object/blit-scaled-linear.cpp
index a656abe..7227c92 100644
--- a/tests/spec/arb_framebuffer_object/blit-scaled-linear.cpp
+++ b/tests/spec/arb_framebuffer_object/blit-scaled-linear.cpp
@@ -156,7 +156,7 @@ blit_scaled_linear_glsl(const Fbo *src_fbo, GLint samples)
 		{  1, -1, srcX1, srcY0 }};
 
 	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(GL_TEXTURE_RECTANGLE, src_fbo->color_tex);
+	glBindTexture(GL_TEXTURE_RECTANGLE, src_fbo->color_tex[0]);
 	glUseProgram(prog);
 	glBindVertexArray(vao);
 
@@ -189,10 +189,10 @@ piglit_init(int argc, char **argv)
 	 * different color attachment types.
 	 */
 	FboConfig Config(0, pattern_width / 2, pattern_height / 2);
-	Config.attach_texture = true;
-	fbo_tex.setup(Config);
-	Config.attach_texture = false;
 	fbo_rb.setup(Config);
+	Config.num_rb_attachments = 0;
+	Config.num_tex_attachments = 1;
+	fbo_tex.setup(Config);
 
 	test_pattern = new Triangles();
 	test_pattern->compile();
@@ -218,7 +218,7 @@ bool test_blit_scaled_linear(Fbo fbo_test)
 	glClear(GL_COLOR_BUFFER_BIT);
 	test_pattern->draw(TestPattern::no_projection);
 
-	if(!fbo_test.config.attach_texture) {
+	if(fbo_test.config.num_tex_attachments == 0) {
 		/* Blit the framebuffer with texture attachment into the
 		 * framebuffer with renderbuffer attachment.
 		 */
@@ -272,7 +272,7 @@ bool test_blit_scaled_linear(Fbo fbo_test)
 		pass = result && pass;
 		piglit_present_results();
 		printf("Attachment = %12s, scale = %f, result = %s\n",
-		       fbo_test.config.attach_texture ?
+		       fbo_test.config.num_tex_attachments  > 0 ?
 		       "TEXTURE" :
 		       "RENDERBUFFER",
 		       scale, result ? "pass" : "fail");
diff --git a/tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp
index 5f2e143..739c685 100644
--- a/tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp
+++ b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-id.cpp
@@ -147,7 +147,8 @@ piglit_init(int argc, char **argv)
 	msConfig.color_internalformat = GL_RGBA8UI;
 	multisampled_fbo.setup(msConfig);
 
-	msConfig.attach_texture = true;
+	msConfig.num_tex_attachments = 1;
+	msConfig.num_rb_attachments = 0; /* default value is 1 */
 	multisampled_tex.setup(msConfig);
 
 	compile_shader();
@@ -169,7 +170,7 @@ bool test_builtin_sample_id(Fbo ms_fbo)
 	glUniform1i(glGetUniformLocation(prog_0, "samples"), samples);
         piglit_draw_rect(-1, -1, 2, 2);
 
-	if(!ms_fbo.config.attach_texture) {
+	if(ms_fbo.config.num_tex_attachments == 0) {
 		/* Blit the framebuffer with multisample renderbuffer attachment
 		 * into the framebuffer with multisample texture attachment.
 		 */
@@ -200,7 +201,7 @@ bool test_builtin_sample_id(Fbo ms_fbo)
                && result;
 	piglit_present_results();
 	printf("FBO attachment = %s, result = %s\n",
-	       ms_fbo.config.attach_texture ?
+	       ms_fbo.config.num_tex_attachments > 0 ?
 	       "TEXTURE" :
 	       "RENDERBUFFER",
 	       result ? "pass" : "fail");
diff --git a/tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp
index 6585ab4..4f6667f 100644
--- a/tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp
+++ b/tests/spec/arb_sample_shading/execution/builtin-gl-sample-mask.cpp
@@ -157,8 +157,8 @@ piglit_init(int argc, char **argv)
 
 	FboConfig msConfig(num_samples, pattern_width, pattern_height);
 	multisampled_fbo.setup(msConfig);
-
-        msConfig.attach_texture = true;
+	msConfig.num_tex_attachments = 1;
+	msConfig.num_rb_attachments = 0;
 	multisampled_tex.setup(msConfig);
 
 	compile_shader();
@@ -181,7 +181,7 @@ test_builtin_sample_mask(Fbo ms_fbo)
 	glUniform1i(glGetUniformLocation(prog_0, "samples"), samples);
         piglit_draw_rect(-1, -1, 2, 2);
 
-	if(!ms_fbo.config.attach_texture) {
+	if(ms_fbo.config.num_tex_attachments == 0) {
 		/* Blit the framebuffer with multisample renderbuffer attachment
 		 * into the framebuffer with multisample texture attachment.
 		 */
@@ -212,7 +212,7 @@ test_builtin_sample_mask(Fbo ms_fbo)
 		 && result;
 	piglit_present_results();
 	printf("FBO attachment = %s, result = %s\n",
-	       ms_fbo.config.attach_texture ?
+	       ms_fbo.config.num_tex_attachments > 0 ?
 	       "TEXTURE" :
 	       "RENDERBUFFER",
 	       result ? "pass" : "fail");
diff --git a/tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp b/tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp
index cdcd9a0..caf4b2c 100644
--- a/tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp
+++ b/tests/spec/arb_sample_shading/execution/ignore-centroid-qualifier.cpp
@@ -127,7 +127,8 @@ piglit_init(int argc, char**argv)
 		piglit_report_result(PIGLIT_SKIP);
 
 	FboConfig msConfig(num_samples, piglit_width, piglit_height);
-        msConfig.attach_texture = true;
+	msConfig.num_rb_attachments = 0;
+	msConfig.num_tex_attachments = 1;
 	multisampled_fbo.setup(msConfig);
 
 	/* Reduced tolerence for stricter color matching */
diff --git a/tests/spec/arb_sample_shading/execution/interpolate-at-sample-position.cpp b/tests/spec/arb_sample_shading/execution/interpolate-at-sample-position.cpp
index 253606b..246e81b 100644
--- a/tests/spec/arb_sample_shading/execution/interpolate-at-sample-position.cpp
+++ b/tests/spec/arb_sample_shading/execution/interpolate-at-sample-position.cpp
@@ -126,7 +126,8 @@ piglit_init(int argc, char**argv)
 		piglit_report_result(PIGLIT_SKIP);
 
 	FboConfig msConfig(num_samples, piglit_width, piglit_height);
-        msConfig.attach_texture = true;
+	msConfig.num_rb_attachments = 0;
+	msConfig.num_tex_attachments = 1;
 	multisampled_fbo.setup(msConfig);
 
 	/* Reduced tolerence for stricter color matching */
diff --git a/tests/spec/ext_framebuffer_multisample/common.cpp b/tests/spec/ext_framebuffer_multisample/common.cpp
index 8bd4e4c..95f3c6f 100644
--- a/tests/spec/ext_framebuffer_multisample/common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/common.cpp
@@ -192,7 +192,7 @@ DownsampleProg::run(const Fbo *src_fbo, int dest_width, int dest_height,
 	float h = dest_height;
 
 	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(GL_TEXTURE_RECTANGLE, src_fbo->color_tex);
+	glBindTexture(GL_TEXTURE_RECTANGLE, src_fbo->color_tex[0]);
 
 	glUseProgram(prog);
 	glBindVertexArray(vao);
@@ -293,7 +293,8 @@ Test::init(int num_samples, bool small, bool combine_depth_stencil,
 	FboConfig supersample_fbo_config = test_fbo_config;
 	supersample_fbo_config.width = 1024;
 	supersample_fbo_config.height = 1024;
-	supersample_fbo_config.attach_texture = true;
+	supersample_fbo_config.num_tex_attachments = 1;
+	supersample_fbo_config.num_rb_attachments = 0;
 	supersample_fbo.setup(supersample_fbo_config);
 
 	FboConfig downsample_fbo_config = test_fbo_config;
diff --git a/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp b/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp
index 2209619..91e7a89 100644
--- a/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp
+++ b/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp
@@ -397,7 +397,7 @@ piglit_init(int argc, char **argv)
 	/* Query the number of samples used in ms_fbo. OpenGL implementation
 	 * may create FBO with more samples per pixel than what is requested.
 	 */
-	glBindRenderbuffer(GL_RENDERBUFFER, ms_fbo.color_rb);
+	glBindRenderbuffer(GL_RENDERBUFFER, ms_fbo.color_rb[0]);
 	glGetRenderbufferParameteriv(GL_RENDERBUFFER,
 				     GL_RENDERBUFFER_SAMPLES,
 				     &num_samples);
diff --git a/tests/spec/ext_framebuffer_multisample_blit_scaled/blit-scaled.cpp b/tests/spec/ext_framebuffer_multisample_blit_scaled/blit-scaled.cpp
index 6221e8c..d0ca1b4 100644
--- a/tests/spec/ext_framebuffer_multisample_blit_scaled/blit-scaled.cpp
+++ b/tests/spec/ext_framebuffer_multisample_blit_scaled/blit-scaled.cpp
@@ -215,7 +215,7 @@ ms_blit_scaled_glsl(const Fbo *src_fbo, GLint samples)
 		{  1, -1, srcX1, srcY0 }};
 
 	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, src_fbo->color_tex);
+	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, src_fbo->color_tex[0]);
 	glUseProgram(prog);
 	glBindVertexArray(vao);
 
@@ -267,10 +267,10 @@ piglit_init(int argc, char **argv)
 	 * but different color attachment types.
 	 */
 	FboConfig msConfig(num_samples, pattern_width, pattern_height);
-	msConfig.attach_texture = true;
-	multisampled_tex.setup(msConfig);
-	msConfig.attach_texture = false;
 	multisampled_fbo.setup(msConfig);
+	msConfig.num_tex_attachments = 1;
+	msConfig.num_rb_attachments = 0; /* default value is 1 */
+	multisampled_tex.setup(msConfig);
 
 	test_pattern = new Triangles();
 	test_pattern->compile();
@@ -296,7 +296,7 @@ bool test_ms_blit_scaled(Fbo ms_fbo)
 	glClear(GL_COLOR_BUFFER_BIT);
 	test_pattern->draw(TestPattern::no_projection);
 
-	if(!ms_fbo.config.attach_texture) {
+	if(ms_fbo.config.num_tex_attachments == 0) {
 		/* Blit the framebuffer with multisample texture attachment
 		 * into the framebuffer with multisample renderbuffer attachment.
 		 */
@@ -356,7 +356,7 @@ bool test_ms_blit_scaled(Fbo ms_fbo)
 				  GL_COLOR_BUFFER_BIT, GL_NEAREST);
 		piglit_present_results();
 		printf("MS attachment = %24s, scale = %f, result = %s\n",
-		       ms_fbo.config.attach_texture ?
+		       ms_fbo.config.num_tex_attachments > 0 ?
 		       "MULTISAMPLE_TEXTURE" :
 		       "MULTISAMPLE_RENDERBUFFER",
 		       scale, result ? "pass" : "fail");
diff --git a/tests/util/piglit-fbo.cpp b/tests/util/piglit-fbo.cpp
index 484c23f..49e9b26 100644
--- a/tests/util/piglit-fbo.cpp
+++ b/tests/util/piglit-fbo.cpp
@@ -38,7 +38,6 @@ FboConfig::FboConfig(int num_samples, int width, int height)
 	  width(width),
 	  height(height),
 	  combine_depth_stencil(true),
-	  attach_texture(false),
 	  color_format(GL_RGBA),
 	  color_internalformat(GL_RGBA),
 	  depth_internalformat(GL_DEPTH_COMPONENT24),
@@ -55,43 +54,45 @@ FboConfig::FboConfig(int num_samples, int width, int height)
 Fbo::Fbo()
 	: config(0, 0, 0), /* will be overwritten on first call to setup() */
 	  handle(0),
-	  color_tex(0),
-	  color_rb(0),
 	  depth_rb(0),
 	  stencil_rb(0),
 	  gl_objects_generated(false)
 {
+	memset(color_tex, 0, PIGLIT_MAX_COLOR_ATTACHMENTS * sizeof(GLuint));
+	memset(color_rb, 0, PIGLIT_MAX_COLOR_ATTACHMENTS * sizeof(GLuint));
 }
 
 void
 Fbo::generate_gl_objects(void)
 {
+	GLint max_color_attachments;
+	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments);
 	glGenFramebuffers(1, &handle);
-	glGenTextures(1, &color_tex);
-	glGenRenderbuffers(1, &color_rb);
+	glGenTextures(max_color_attachments, color_tex);
+	glGenRenderbuffers(max_color_attachments, color_rb);
 	glGenRenderbuffers(1, &depth_rb);
 	glGenRenderbuffers(1, &stencil_rb);
 	gl_objects_generated = true;
 }
 
 void
-Fbo::attach_color_renderbuffer(const FboConfig &config)
+Fbo::attach_color_renderbuffer(const FboConfig &config, int index)
 {
-	glBindRenderbuffer(GL_RENDERBUFFER, color_rb);
+	glBindRenderbuffer(GL_RENDERBUFFER, color_rb[index]);
 	glRenderbufferStorageMultisample(GL_RENDERBUFFER,
 					 config.num_samples,
 					 config.color_internalformat,
 					 config.width,
 					 config.height);
 	glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER,
-				  GL_COLOR_ATTACHMENT0,
-				  GL_RENDERBUFFER, color_rb);
+				  config.rb_attachment[index],
+				  GL_RENDERBUFFER, color_rb[index]);
 }
 
 void
-Fbo::attach_color_texture(const FboConfig &config)
+Fbo::attach_color_texture(const FboConfig &config, int index)
 {
-	glBindTexture(GL_TEXTURE_RECTANGLE, color_tex);
+	glBindTexture(GL_TEXTURE_RECTANGLE, color_tex[index]);
 	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER,
 			GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER,
@@ -106,16 +107,16 @@ Fbo::attach_color_texture(const FboConfig &config)
 		     GL_BYTE /* type */,
 		     NULL /* data */);
 	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
-			       GL_COLOR_ATTACHMENT0,
+			       config.tex_attachment[index],
 			       GL_TEXTURE_RECTANGLE,
-			       color_tex,
+			       color_tex[index],
 			       0 /* level */);
 }
 
 void
-Fbo::attach_multisample_color_texture(const FboConfig &config)
+Fbo::attach_multisample_color_texture(const FboConfig &config, int index)
 {
-	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, color_tex);
+	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, color_tex[index]);
 	glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,
 				config.num_samples,
 				config.color_internalformat,
@@ -124,9 +125,9 @@ Fbo::attach_multisample_color_texture(const FboConfig &config)
 				GL_TRUE /* fixed sample locations */);
 
 	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
-			       GL_COLOR_ATTACHMENT0,
+			       config.tex_attachment[index],
 			       GL_TEXTURE_2D_MULTISAMPLE,
-			       color_tex,
+			       color_tex[index],
 			       0 /* level */);
 }
 
@@ -182,14 +183,24 @@ Fbo::try_setup(const FboConfig &new_config)
 
 	/* Color buffer */
 	if (config.color_internalformat != GL_NONE) {
-		if (!config.attach_texture) {
-			attach_color_renderbuffer(new_config);
-		} else if (config.num_samples == 0) {
-			attach_color_texture(new_config);
-			piglit_require_extension("GL_ARB_texture_rectangle");
-		} else {
+
+		/* Attach renderbuffers as color attachments */
+		for (int i = 0; i < config.num_rb_attachments; i++)
+			attach_color_renderbuffer(new_config, i);
+
+		if (config.num_samples == 0) {
+
+			/* Attach textures as color attachments */
 			piglit_require_extension("GL_ARB_texture_multisample");
-			attach_multisample_color_texture(new_config);
+			for (int i = 0; i < config.num_tex_attachments; i++)
+				attach_color_texture(new_config, i);
+
+		} else {
+
+			/* Attach multisample textures as color attachments */
+			piglit_require_extension("GL_ARB_texture_rectangle");
+			for (int i = 0; i < config.num_tex_attachments; i++)
+				attach_multisample_color_texture(new_config, i);
 		}
 	}
 
diff --git a/tests/util/piglit-fbo.h b/tests/util/piglit-fbo.h
index 3be4f99..72fac72 100644
--- a/tests/util/piglit-fbo.h
+++ b/tests/util/piglit-fbo.h
@@ -58,18 +58,15 @@ namespace piglit_util_fbo {
 		bool combine_depth_stencil;
 
 		/**
-		 * True if a texture should be used as the backing store for
-		 * the color attachment point, false if a renderbuffer should
-		 * be used.  Defaults to false.
+		 * Set color attachment points for color_tex[i] or color_rb[i].
+		 * Default value for color_tex[0] and color_rb[0] is
+		 * GL_COLOR_ATTACHMENT0.
 		 */
-		bool attach_texture;
-
-		/* Set color attachments */
 		GLuint rb_attachment[PIGLIT_MAX_COLOR_ATTACHMENTS];
 		GLuint tex_attachment[PIGLIT_MAX_COLOR_ATTACHMENTS];
 
 		/**
-		 * Useful if attach_texture is true and color buffer is
+		 * Useful if num_tex_attachments > 0 and color buffer is
 		 * non-multisample. Specifies the format that should be used
 		 * for the color buffer, or GL_NONE if no color buffer should
 		 * be used. Defaults to GL_RGBA.
@@ -123,16 +120,16 @@ namespace piglit_util_fbo {
 		GLuint handle;
 
 		/**
-		 * If config.attach_texture is true, the backing store for the
-		 * color buffer.
+		 * If config.num_tex_attachments > 0, the backing store for the
+		 * color buffers.
 		 */
-		GLuint color_tex;
+		GLuint color_tex[PIGLIT_MAX_COLOR_ATTACHMENTS];
 
 		/**
-		 * If config.attach_texture is false, the backing store for
-		 * the color buffer.
+		 * If config.num_rb_attachments > 0, the backing store for the
+		 * color buffers.
 		 */
-		GLuint color_rb;
+		GLuint color_rb[PIGLIT_MAX_COLOR_ATTACHMENTS];
 
 		/**
 		 * If config.combine_depth_stencil is true, the backing store
@@ -150,9 +147,11 @@ namespace piglit_util_fbo {
 
 	private:
 		void generate_gl_objects();
-		void attach_color_renderbuffer(const FboConfig &config);
-		void attach_color_texture(const FboConfig &config);
-		void attach_multisample_color_texture(const FboConfig &config);
+		void attach_color_renderbuffer(const FboConfig &config,
+					       int index);
+		void attach_color_texture(const FboConfig &config, int index);
+		void attach_multisample_color_texture(const FboConfig &config,
+						      int index);
 
 		/**
 		 * True if generate_gl_objects has been called and color_tex,
-- 
1.8.3.1



More information about the Piglit mailing list