Set DrawBuffers for each fragment color output
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / gl / gl4cEnhancedLayoutsTests.cpp
index e3658a6..a9246c1 100644 (file)
@@ -520,15 +520,24 @@ GLuint Type::GetLocations() const
        return n_loc_per_column * m_n_columns;
 }
 
-/** Get size of the type in bytes. Note that this routine assumes tightly packing
+/** Get size of the type in bytes.
+ * Note that this routine doesn't consider arrays and assumes
+ * column_major matrices.
  *
- * @return Formula Number of columns * number of rows * sizeof(base_type)
+ * @return Formula:
+ *          - If std140 packaging and matrix; number of columns * base alignment
+ *          - Otherwise; number of elements * sizeof(base_type)
  **/
-GLuint Type::GetSize() const
+GLuint Type::GetSize(const bool is_std140) const
 {
        const GLuint basic_type_size = GetTypeSize(m_basic_type);
        const GLuint n_elements          = m_n_columns * m_n_rows;
 
+       if (is_std140 && m_n_columns > 1)
+       {
+               return m_n_columns * GetBaseAlignment(false);
+       }
+
        return basic_type_size * n_elements;
 }
 
@@ -9345,7 +9354,7 @@ void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
        {
                const Utils::Type& type           = getType(i);
                const GLuint       alignment  = type.GetBaseAlignment(false);
-               const GLuint       type_size  = type.GetSize();
+               const GLuint       type_size  = type.GetSize(true);
                const GLuint       sec_to_end = max_size - 2 * type_size;
 
                for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
@@ -19322,16 +19331,18 @@ void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebu
 
        /* Set up drawbuffers */
        const Functions& gl = m_context.getRenderContext().getFunctions();
-       //  1. There are only 4 outputs in fragment shader, so only need to do buffer mapping for 4 attachments,
-       //  2. another issue is each output variable has a location, it is the fragment color index, so the index of
-       //  GL_COLOR_ATTACHMENT in glDrawBuffers() should keep the same with the location, to make test correct,
-       //  we needt to change the above code of glDrawBuffers() as :
-       GLint  buffers_size = 4;
-       GLenum buffers[]        = { GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location),
-                                                GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location),
-                                                GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location),
-                                                GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location) };
-       gl.drawBuffers(buffers_size, buffers);
+       // The fragment shader can have more than 4 color outputs, but it only care about 4 (goku, gohan, goten, chichi).
+       // We will first initialize all draw buffers to NONE and then set the real value for the 4 outputs we care about
+       GLint maxDrawBuffers = 0;
+       gl.getIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
+
+       std::vector<GLenum> buffers(maxDrawBuffers, GL_NONE);
+       buffers[m_chichi_location] = GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location);
+       buffers[m_goten_location]  = GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location);
+       buffers[m_goku_location]   = GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location);
+       buffers[m_gohan_location]  = GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location);
+
+       gl.drawBuffers(maxDrawBuffers, buffers.data());
        GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
 }