Home | History | Annotate | Download | only in functional
      1 /*-------------------------------------------------------------------------
      2  * drawElements Quality Program OpenGL ES 2.0 Module
      3  * -------------------------------------------------
      4  *
      5  * Copyright 2018 The Android Open Source Project
      6  *
      7  * Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *      http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  *
     19  */ /*!
     20  * \file
     21  * \brief GL_EXT_multisample_render_to_texture tests.
     22  */ /*--------------------------------------------------------------------*/
     23 
     24 #include "es2fMultisampledRenderToTextureTests.hpp"
     25 
     26 #include "deString.h"
     27 #include "deStringUtil.hpp"
     28 #include "gluContextInfo.hpp"
     29 #include "gluPixelTransfer.hpp"
     30 #include "gluShaderProgram.hpp"
     31 #include "glw.h"
     32 #include "glwEnums.hpp"
     33 #include "glwFunctions.hpp"
     34 #include "tcuRenderTarget.hpp"
     35 #include "tcuSurface.hpp"
     36 #include "tcuTestLog.hpp"
     37 #include "tcuVector.hpp"
     38 
     39 using tcu::TestLog;
     40 using tcu::Vec4;
     41 
     42 namespace deqp
     43 {
     44 namespace gles2
     45 {
     46 namespace Functional
     47 {
     48 
     49 class MultisampledRenderToTextureReadPixelsCase : public TestCase
     50 {
     51 public:
     52 	MultisampledRenderToTextureReadPixelsCase(Context& context, const char* name, const char* description);
     53 	~MultisampledRenderToTextureReadPixelsCase();
     54 	void init();
     55 	IterateResult iterate();
     56 
     57 private:
     58 	MultisampledRenderToTextureReadPixelsCase(const MultisampledRenderToTextureReadPixelsCase& other);
     59 	MultisampledRenderToTextureReadPixelsCase& operator=(const MultisampledRenderToTextureReadPixelsCase& other);
     60 };
     61 
     62 MultisampledRenderToTextureReadPixelsCase::MultisampledRenderToTextureReadPixelsCase(Context& context, const char* name, const char* description)
     63 	: TestCase(context, name, description)
     64 {
     65 }
     66 
     67 MultisampledRenderToTextureReadPixelsCase::~MultisampledRenderToTextureReadPixelsCase()
     68 {
     69 }
     70 
     71 void MultisampledRenderToTextureReadPixelsCase::init()
     72 {
     73 	const glu::ContextInfo& contextInfo = m_context.getContextInfo();
     74 	if (!contextInfo.isExtensionSupported("GL_EXT_multisampled_render_to_texture"))
     75 	{
     76 		TCU_THROW(NotSupportedError, "EXT_multisampled_render_to_texture is not supported");
     77 	}
     78 }
     79 
     80 MultisampledRenderToTextureReadPixelsCase::IterateResult MultisampledRenderToTextureReadPixelsCase::iterate()
     81 {
     82 	// Test for a bug where ReadPixels fails on multisampled textures.
     83 	// See http://crbug.com/890002
     84 	// Note that this does not test whether multisampling is working properly,
     85 	// only that ReadPixels is able to read from the texture.
     86 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
     87 	// Create a framebuffer with a multisampled texture and a depth-stencil
     88 	// renderbuffer.
     89 	GLuint framebuffer = 0;
     90 	GLuint texture = 0;
     91 	gl.genFramebuffers(1, &framebuffer);
     92 	gl.genTextures(1, &texture);
     93 	gl.bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
     94 	gl.bindTexture(GL_TEXTURE_2D, texture);
     95 	gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
     96 	GLint max_samples = 0;
     97 	gl.getIntegerv(GL_MAX_SAMPLES_EXT, &max_samples);
     98 	gl.framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0, max_samples);
     99 	GLuint depthStencil = 0;
    100 	gl.genRenderbuffers(1, &depthStencil);
    101 	gl.bindRenderbuffer(GL_RENDERBUFFER, depthStencil);
    102 	gl.renderbufferStorageMultisampleEXT(GL_RENDERBUFFER, max_samples, GL_DEPTH24_STENCIL8, 1, 1);
    103 	gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencil);
    104 	gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencil);
    105 	if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
    106 		TCU_THROW(NotSupportedError, "Framebuffer format not supported.");
    107 	}
    108 	gl.clearColor(1, 0, 1, 0);
    109 	gl.clear(GL_COLOR_BUFFER_BIT);
    110 	GLU_EXPECT_NO_ERROR(gl.getError(), "init");
    111 
    112 	// ReadPixels should implicitly resolve the multisampled buffer.
    113 	GLubyte pixel[4] = { 0, 1, 0, 1 };
    114 	gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
    115 	GLU_EXPECT_NO_ERROR(gl.getError(), "ReadPixels");
    116 
    117 	if (pixel[0] != 255 || pixel[1] != 0 || pixel[2] != 255 || pixel[3] != 0)
    118 	{
    119 		std::ostringstream msg;
    120 		msg << "ReadPixels read incorrect values: [" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ", " << (int)pixel[3] << "]";
    121 		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg.str().c_str());
    122 	}
    123 	else
    124 	{
    125 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
    126 	}
    127 
    128 	gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
    129 	gl.bindTexture(GL_TEXTURE_2D, 0);
    130 	gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
    131 	gl.deleteFramebuffers(1, &framebuffer);
    132 	gl.deleteRenderbuffers(1, &depthStencil);
    133 	gl.deleteTextures(1, &texture);
    134 	return STOP;
    135 }
    136 
    137 MultisampledRenderToTextureTests::MultisampledRenderToTextureTests(Context& context) : TestCaseGroup(context, "multisampled_render_to_texture", "EXT_multisampled_render_to_texture tests")
    138 {
    139 }
    140 
    141 MultisampledRenderToTextureTests::~MultisampledRenderToTextureTests()
    142 {
    143 }
    144 
    145 void MultisampledRenderToTextureTests::init()
    146 {
    147 	addChild(new MultisampledRenderToTextureReadPixelsCase(m_context, "readpixels", "Test ReadPixels with EXT_multisampled_render_to_texture"));
    148 }
    149 
    150 } // namespace Functional
    151 } // namespace gles2
    152 } // namespace deqp
    153