In order to test that MSAA works properly for integer framebuffers, we
will need to be able to output ivec4 and uvec4 types when rendering
the test image.  This patch makes that possible by adapting the
Sunburst GLSL program so that it can be compiled to output ivec4's,
uvec4's, or vec4's.
---
 tests/spec/ext_framebuffer_multisample/common.cpp  |   50 +++++++++++++++++++-
 tests/spec/ext_framebuffer_multisample/common.h    |   20 ++++++++
 tests/spec/ext_framebuffer_multisample/formats.cpp |    2 +-
 3 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/tests/spec/ext_framebuffer_multisample/common.cpp 
b/tests/spec/ext_framebuffer_multisample/common.cpp
index 982d991..ff1ca7f 100644
--- a/tests/spec/ext_framebuffer_multisample/common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/common.cpp
@@ -880,6 +880,36 @@ void Points::draw(const float (*proj)[4])
        }
 }
 
+Sunburst::Sunburst()
+       : out_type(GL_UNSIGNED_NORMALIZED)
+{
+}
+
+
+/**
+ * Determine the GLSL type that should be used for rendering, based on
+ * out_type.
+ */
+const char *
+Sunburst::get_out_type_glsl() const
+{
+       switch(out_type) {
+       case GL_INT:
+               return "ivec4";
+       case GL_UNSIGNED_INT:
+               return "uvec4";
+       case GL_UNSIGNED_NORMALIZED:
+       case GL_FLOAT:
+               return "vec4";
+       default:
+               printf("Unrecognized out_type: %s\n",
+                      piglit_get_gl_enum_name(out_type));
+               piglit_report_result(PIGLIT_FAIL);
+               return "UNKNOWN";
+       }
+}
+
+
 void Sunburst::compile()
 {
        static struct vertex_attributes {
@@ -912,24 +942,33 @@ void Sunburst::compile()
                "  barycentric_coords = in_barycentric_coords;\n"
                "}\n";
 
-       static const char *frag =
+       static const char *frag_template =
                "#version 130\n"
+               "#define OUT_TYPE %s\n"
                "in vec3 barycentric_coords;\n"
                "uniform mat3x4 draw_colors;\n"
+               "out OUT_TYPE frag_out;\n"
                "\n"
                "void main()\n"
                "{\n"
-               "  gl_FragColor = draw_colors * barycentric_coords;\n"
+               "  frag_out = OUT_TYPE(draw_colors * barycentric_coords);\n"
                "}\n";
 
        /* Compile program */
        prog = glCreateProgram();
        GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
        glAttachShader(prog, vs);
+       const char *out_type_glsl = get_out_type_glsl();
+       unsigned frag_alloc_len =
+               strlen(frag_template) + strlen(out_type_glsl) + 1;
+       char *frag = (char *) malloc(frag_alloc_len);
+       sprintf(frag, frag_template, out_type_glsl);
        GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);
+       free(frag);
        glAttachShader(prog, fs);
        glBindAttribLocation(prog, 0, "pos_within_tri");
        glBindAttribLocation(prog, 1, "in_barycentric_coords");
+       glBindFragDataLocation(prog, 0, "frag_out");
        glLinkProgram(prog);
        if (!piglit_link_check_status(prog)) {
                piglit_report_result(PIGLIT_FAIL);
@@ -963,6 +1002,13 @@ void Sunburst::compile()
                                                barycentric_coords));
 }
 
+
+ColorGradientSunburst::ColorGradientSunburst(GLenum out_type)
+{
+       this->out_type = out_type;
+}
+
+
 void
 ColorGradientSunburst::draw(const float (*proj)[4])
 {
diff --git a/tests/spec/ext_framebuffer_multisample/common.h 
b/tests/spec/ext_framebuffer_multisample/common.h
index 07d892d..b432f86 100644
--- a/tests/spec/ext_framebuffer_multisample/common.h
+++ b/tests/spec/ext_framebuffer_multisample/common.h
@@ -310,8 +310,19 @@ private:
 class Sunburst : public TestPattern
 {
 public:
+       Sunburst();
+
        virtual void compile();
 
+       /**
+        * Type of color buffer being rendered into.  Should be one of
+        * the following enum values: GL_FLOAT,
+        * GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_INT, or GL_INT.
+        *
+        * Defaults to GL_UNSIGNED_NORMALIZED.
+        */
+       GLenum out_type;
+
 protected:
        GLint prog;
        GLint rotation_loc;
@@ -322,6 +333,8 @@ protected:
        int num_tris;
 
 private:
+       const char *get_out_type_glsl() const;
+
        GLuint vertex_buf;
 };
 
@@ -330,10 +343,17 @@ private:
  *
  * This program draws triangles using a variety of colors and
  * gradients.
+ *
+ * This program is capable of drawing to floating point, integer, and
+ * unsigned integer framebuffers, controlled by the out_type
+ * constructor parameter, which should be GL_FLOAT,
+ * GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_INT, or GL_INT.
  */
 class ColorGradientSunburst : public Sunburst
 {
 public:
+       explicit ColorGradientSunburst(GLenum out_type);
+
        virtual void draw(const float (*proj)[4]);
 };
 
diff --git a/tests/spec/ext_framebuffer_multisample/formats.cpp 
b/tests/spec/ext_framebuffer_multisample/formats.cpp
index 220de79..907f3d1 100644
--- a/tests/spec/ext_framebuffer_multisample/formats.cpp
+++ b/tests/spec/ext_framebuffer_multisample/formats.cpp
@@ -427,7 +427,7 @@ piglit_init(int argc, char **argv)
 
        fbo_formats_init_test_set(0 /* core formats */,
                                  GL_TRUE /* print_options */);
-       test_pattern = new ColorGradientSunburst();
+       test_pattern = new ColorGradientSunburst(GL_UNSIGNED_NORMALIZED);
        test_pattern->compile();
 }
 
-- 
1.7.7.6

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to