Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 8 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | using namespace angle; |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 10 | |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 11 | class FramebufferRenderMipmapTest : public ANGLETest |
| 12 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | protected: |
| 14 | FramebufferRenderMipmapTest() |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 15 | { |
| 16 | setWindowWidth(256); |
| 17 | setWindowHeight(256); |
| 18 | setConfigRedBits(8); |
| 19 | setConfigGreenBits(8); |
| 20 | setConfigBlueBits(8); |
| 21 | setConfigAlphaBits(8); |
| 22 | } |
| 23 | |
| 24 | virtual void SetUp() |
| 25 | { |
| 26 | ANGLETest::SetUp(); |
| 27 | |
| 28 | const std::string vsSource = SHADER_SOURCE |
| 29 | ( |
| 30 | attribute highp vec4 position; |
| 31 | void main(void) |
| 32 | { |
| 33 | gl_Position = position; |
| 34 | } |
| 35 | ); |
| 36 | |
| 37 | const std::string fsSource = SHADER_SOURCE |
| 38 | ( |
| 39 | uniform highp vec4 color; |
| 40 | void main(void) |
| 41 | { |
| 42 | gl_FragColor = color; |
| 43 | } |
| 44 | ); |
| 45 | |
| 46 | mProgram = CompileProgram(vsSource, fsSource); |
| 47 | if (mProgram == 0) |
| 48 | { |
| 49 | FAIL() << "shader compilation failed."; |
| 50 | } |
| 51 | |
| 52 | mColorLocation = glGetUniformLocation(mProgram, "color"); |
| 53 | |
| 54 | glUseProgram(mProgram); |
| 55 | |
| 56 | glClearColor(0, 0, 0, 0); |
| 57 | glClearDepthf(0.0); |
| 58 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 59 | |
| 60 | glEnable(GL_BLEND); |
| 61 | glDisable(GL_DEPTH_TEST); |
| 62 | |
| 63 | ASSERT_GL_NO_ERROR(); |
| 64 | } |
| 65 | |
| 66 | virtual void TearDown() |
| 67 | { |
| 68 | glDeleteProgram(mProgram); |
| 69 | |
| 70 | ANGLETest::TearDown(); |
| 71 | } |
| 72 | |
| 73 | GLuint mProgram; |
| 74 | GLint mColorLocation; |
| 75 | }; |
| 76 | |
| 77 | // Validate that if we are in ES3 or GL_OES_fbo_render_mipmap exists, there are no validation errors |
| 78 | // when using a non-zero level in glFramebufferTexture2D. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 79 | TEST_P(FramebufferRenderMipmapTest, Validation) |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 80 | { |
| 81 | bool renderToMipmapSupported = extensionEnabled("GL_OES_fbo_render_mipmap") || getClientVersion() > 2; |
| 82 | |
| 83 | GLuint tex = 0; |
| 84 | glGenTextures(1, &tex); |
| 85 | glBindTexture(GL_TEXTURE_2D, tex); |
| 86 | |
| 87 | const size_t levels = 5; |
| 88 | for (size_t i = 0; i < levels; i++) |
| 89 | { |
| 90 | size_t size = 1 << ((levels - 1) - i); |
| 91 | glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 92 | } |
| 93 | |
| 94 | EXPECT_GL_NO_ERROR(); |
| 95 | |
| 96 | GLuint fbo = 0; |
| 97 | glGenFramebuffers(1, &fbo); |
| 98 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 99 | EXPECT_GL_NO_ERROR(); |
| 100 | |
| 101 | for (size_t i = 0; i < levels; i++) |
| 102 | { |
| 103 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, i); |
| 104 | |
| 105 | if (i > 0 && !renderToMipmapSupported) |
| 106 | { |
| 107 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | EXPECT_GL_NO_ERROR(); |
| 112 | EXPECT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum(GL_FRAMEBUFFER_COMPLETE)); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | glDeleteFramebuffers(1, &fbo); |
| 117 | glDeleteTextures(1, &tex); |
| 118 | } |
| 119 | |
| 120 | // Render to various levels of a texture and check that they have the correct color data via ReadPixels |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 121 | TEST_P(FramebufferRenderMipmapTest, RenderToMipmap) |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 122 | { |
Geoff Lang | 1a0847c | 2015-04-08 13:49:31 -0400 | [diff] [blame] | 123 | // TODO(geofflang): Figure out why this is broken on Intel OpenGL |
| 124 | if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
| 125 | { |
| 126 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 127 | return; |
| 128 | } |
| 129 | |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 130 | bool renderToMipmapSupported = extensionEnabled("GL_OES_fbo_render_mipmap") || getClientVersion() > 2; |
| 131 | if (!renderToMipmapSupported) |
| 132 | { |
| 133 | std::cout << "Test skipped because GL_OES_fbo_render_mipmap or ES3 is not available." << std::endl; |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | const GLfloat levelColors[] = |
| 138 | { |
| 139 | 1.0f, 0.0f, 0.0f, 1.0f, |
| 140 | 0.0f, 1.0f, 0.0f, 1.0f, |
| 141 | 0.0f, 0.0f, 1.0f, 1.0f, |
| 142 | 1.0f, 1.0f, 0.0f, 1.0f, |
| 143 | 1.0f, 0.0f, 1.0f, 1.0f, |
| 144 | 0.0f, 1.0f, 1.0f, 1.0f, |
| 145 | }; |
| 146 | const size_t testLevels = ArraySize(levelColors) / 4; |
| 147 | |
| 148 | GLuint tex = 0; |
| 149 | glGenTextures(1, &tex); |
| 150 | glBindTexture(GL_TEXTURE_2D, tex); |
| 151 | |
| 152 | for (size_t i = 0; i < testLevels; i++) |
| 153 | { |
| 154 | size_t size = 1 << ((testLevels - 1) - i); |
| 155 | glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 156 | } |
| 157 | |
| 158 | EXPECT_GL_NO_ERROR(); |
| 159 | |
| 160 | GLuint fbo = 0; |
| 161 | glGenFramebuffers(1, &fbo); |
| 162 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 163 | EXPECT_GL_NO_ERROR(); |
| 164 | |
| 165 | // Render to the levels of the texture with different colors |
| 166 | for (size_t i = 0; i < testLevels; i++) |
| 167 | { |
| 168 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, i); |
| 169 | EXPECT_GL_NO_ERROR(); |
| 170 | |
| 171 | glUseProgram(mProgram); |
| 172 | glUniform4fv(mColorLocation, 1, levelColors + (i * 4)); |
| 173 | |
| 174 | drawQuad(mProgram, "position", 0.5f); |
| 175 | EXPECT_GL_NO_ERROR(); |
| 176 | } |
| 177 | |
| 178 | // Test that the levels of the texture are correct |
| 179 | for (size_t i = 0; i < testLevels; i++) |
| 180 | { |
| 181 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, i); |
| 182 | EXPECT_GL_NO_ERROR(); |
| 183 | |
| 184 | const GLfloat *color = levelColors + (i * 4); |
| 185 | EXPECT_PIXEL_EQ(0, 0, color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255); |
| 186 | } |
| 187 | |
| 188 | glDeleteFramebuffers(1, &fbo); |
| 189 | glDeleteTextures(1, &tex); |
| 190 | |
| 191 | EXPECT_GL_NO_ERROR(); |
| 192 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 193 | |
| 194 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 195 | ANGLE_INSTANTIATE_TEST(FramebufferRenderMipmapTest, ES2_D3D9(), ES2_D3D11(), ES3_D3D11(), ES2_OPENGL(), ES3_OPENGL()); |