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
MultisampledRenderToTextureReadPixelsCase(Context & context,const char * name,const char * description)62 MultisampledRenderToTextureReadPixelsCase::MultisampledRenderToTextureReadPixelsCase(Context &context, const char *name,
63 const char *description)
64 : TestCase(context, name, description)
65 {
66 }
67
~MultisampledRenderToTextureReadPixelsCase()68 MultisampledRenderToTextureReadPixelsCase::~MultisampledRenderToTextureReadPixelsCase()
69 {
70 }
71
init()72 void MultisampledRenderToTextureReadPixelsCase::init()
73 {
74 const glu::ContextInfo &contextInfo = m_context.getContextInfo();
75 if (!contextInfo.isExtensionSupported("GL_EXT_multisampled_render_to_texture"))
76 {
77 TCU_THROW(NotSupportedError, "EXT_multisampled_render_to_texture is not supported");
78 }
79 }
80
iterate()81 MultisampledRenderToTextureReadPixelsCase::IterateResult MultisampledRenderToTextureReadPixelsCase::iterate()
82 {
83 // Test for a bug where ReadPixels fails on multisampled textures.
84 // See http://crbug.com/890002
85 // Note that this does not test whether multisampling is working properly,
86 // only that ReadPixels is able to read from the texture.
87 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
88 // Create a framebuffer with a multisampled texture and a depth-stencil
89 // renderbuffer.
90 GLuint framebuffer = 0;
91 GLuint texture = 0;
92 gl.genFramebuffers(1, &framebuffer);
93 gl.genTextures(1, &texture);
94 gl.bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
95 gl.bindTexture(GL_TEXTURE_2D, texture);
96 gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
97 GLint max_samples = 0;
98 gl.getIntegerv(GL_MAX_SAMPLES_EXT, &max_samples);
99 gl.framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0, max_samples);
100 GLuint depthStencil = 0;
101 gl.genRenderbuffers(1, &depthStencil);
102 gl.bindRenderbuffer(GL_RENDERBUFFER, depthStencil);
103 gl.renderbufferStorageMultisampleEXT(GL_RENDERBUFFER, max_samples, GL_DEPTH24_STENCIL8, 1, 1);
104 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencil);
105 gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencil);
106 if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
107 {
108 TCU_THROW(NotSupportedError, "Framebuffer format not supported.");
109 }
110 gl.clearColor(1, 0, 1, 0);
111 gl.clear(GL_COLOR_BUFFER_BIT);
112 GLU_EXPECT_NO_ERROR(gl.getError(), "init");
113
114 // ReadPixels should implicitly resolve the multisampled buffer.
115 GLubyte pixel[4] = {0, 1, 0, 1};
116 gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
117 GLU_EXPECT_NO_ERROR(gl.getError(), "ReadPixels");
118
119 if (pixel[0] != 255 || pixel[1] != 0 || pixel[2] != 255 || pixel[3] != 0)
120 {
121 std::ostringstream msg;
122 msg << "ReadPixels read incorrect values: [" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2]
123 << ", " << (int)pixel[3] << "]";
124 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg.str().c_str());
125 }
126 else
127 {
128 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
129 }
130
131 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
132 gl.bindTexture(GL_TEXTURE_2D, 0);
133 gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
134 gl.deleteFramebuffers(1, &framebuffer);
135 gl.deleteRenderbuffers(1, &depthStencil);
136 gl.deleteTextures(1, &texture);
137 return STOP;
138 }
139
MultisampledRenderToTextureTests(Context & context)140 MultisampledRenderToTextureTests::MultisampledRenderToTextureTests(Context &context)
141 : TestCaseGroup(context, "multisampled_render_to_texture", "EXT_multisampled_render_to_texture tests")
142 {
143 }
144
~MultisampledRenderToTextureTests()145 MultisampledRenderToTextureTests::~MultisampledRenderToTextureTests()
146 {
147 }
148
init()149 void MultisampledRenderToTextureTests::init()
150 {
151 addChild(new MultisampledRenderToTextureReadPixelsCase(m_context, "readpixels",
152 "Test ReadPixels with EXT_multisampled_render_to_texture"));
153 }
154
155 } // namespace Functional
156 } // namespace gles2
157 } // namespace deqp
158