void runTest(const TestData& test) { GLint viewportSize[4]; glGetIntegerv(GL_VIEWPORT, viewportSize); GLint midPixelX = (viewportSize[0] + viewportSize[2]) / 2; GLint midPixelY = (viewportSize[1] + viewportSize[3]) / 2; for (size_t i = 0; i < 4; i++) { glBindBuffer(GL_ARRAY_BUFFER, 0); glVertexAttribPointer(mTestAttrib, i + 1, test.type, test.normalized, 0, test.inputData); glVertexAttribPointer(mExpectedAttrib, i + 1, GL_FLOAT, GL_FALSE, 0, test.expectedData); glEnableVertexAttribArray(mTestAttrib); glEnableVertexAttribArray(mExpectedAttrib); drawQuad(mProgram, "position", 0.5f); glDisableVertexAttribArray(mTestAttrib); glDisableVertexAttribArray(mExpectedAttrib); // We need to offset our checks from triangle edges to ensure we don't fall on a single tri // Avoid making assumptions of drawQuad with four checks to check the four possible tri regions EXPECT_PIXEL_EQ((midPixelX + viewportSize[0]) / 2, midPixelY, 255, 255, 255, 255); EXPECT_PIXEL_EQ((midPixelX + viewportSize[2]) / 2, midPixelY, 255, 255, 255, 255); EXPECT_PIXEL_EQ(midPixelX, (midPixelY + viewportSize[1]) / 2, 255, 255, 255, 255); EXPECT_PIXEL_EQ(midPixelX, (midPixelY + viewportSize[3]) / 2, 255, 255, 255, 255); } }
// Test creating a pbuffer from a d3d surface and clearing it TEST_P(D3DTextureTest, Clear) { if (!valid()) { return; } EGLWindow *window = getEGLWindow(); EGLDisplay display = window->getDisplay(); const size_t bufferSize = 32; EGLSurface pbuffer = createPBuffer(bufferSize, bufferSize, EGL_NO_TEXTURE, EGL_NO_TEXTURE, 1, 0); ASSERT_EGL_SUCCESS(); ASSERT_NE(pbuffer, EGL_NO_SURFACE); // Apply the Pbuffer and clear it to purple and verify eglMakeCurrent(display, pbuffer, pbuffer, window->getContext()); ASSERT_EGL_SUCCESS(); glViewport(0, 0, static_cast<GLsizei>(bufferSize), static_cast<GLsizei>(bufferSize)); glClearColor(1.0f, 0.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); ASSERT_GL_NO_ERROR(); EXPECT_PIXEL_EQ(static_cast<GLint>(bufferSize) / 2, static_cast<GLint>(bufferSize) / 2, 255, 0, 255, 255); // Make current with fixture EGL to ensure the Surface can be released immediately. getEGLWindow()->makeCurrent(); eglDestroySurface(display, pbuffer); }
void checkPixel(GLint x, GLint y, GLboolean renderedRed) { // By default, expect the pixel to be black. GLint expectedRedChannel = 0; GLint expectedGreenChannel = 0; GLint scissorSize[4]; glGetIntegerv(GL_SCISSOR_BOX, scissorSize); EXPECT_GL_NO_ERROR(); if (scissorSize[0] <= x && x < scissorSize[0] + scissorSize[2] && scissorSize[1] <= y && y < scissorSize[1] + scissorSize[3]) { // If the pixel lies within the scissor rect, then it should have been cleared to green. // If we rendered a red square on top of it, then the pixel should be red (the green channel will have been reset to 0). expectedRedChannel = renderedRed ? 255 : 0; expectedGreenChannel = renderedRed ? 0 : 255; } // If the pixel is within the bounds of the window, then we check it. Otherwise we skip it. if (0 <= x && x < getWindowWidth() && 0 <= y && y < getWindowHeight()) { EXPECT_PIXEL_EQ(x, y, expectedRedChannel, expectedGreenChannel, 0, 255); } }
void runTest() { if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_blend_minmax")) { std::cout << "Test skipped because ES3 or GL_EXT_blend_minmax is not available." << std::endl; return; } const size_t colorCount = 1024; Color colors[colorCount]; for (size_t i = 0; i < colorCount; i++) { for (size_t j = 0; j < 4; j++) { colors[i].values[j] = (rand() % 255) / 255.0f; } } GLubyte prevColor[4]; for (size_t i = 0; i < colorCount; i++) { const Color &color = colors[i]; glUseProgram(mProgram); glUniform4f(mColorLocation, color.values[0], color.values[1], color.values[2], color.values[3]); bool blendMin = (rand() % 2 == 0); glBlendEquation(blendMin ? GL_MIN : GL_MAX); drawQuad(mProgram, "aPosition", 0.5f); if (i > 0) { EXPECT_PIXEL_EQ(0, 0, getExpected(blendMin, color.values[0], prevColor[0]), getExpected(blendMin, color.values[1], prevColor[1]), getExpected(blendMin, color.values[2], prevColor[2]), getExpected(blendMin, color.values[3], prevColor[3])); } glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, prevColor); } }
void runTest() { const size_t colorCount = 1024; Color colors[colorCount]; for (size_t i = 0; i < colorCount; i++) { for (size_t j = 0; j < 4; j++) { colors[i].values[j] = (rand() % 255) / 255.0f; } } GLubyte prevColor[4]; for (size_t i = 0; i < colorCount; i++) { const Color &color = colors[i]; glUseProgram(mProgram); glUniform4f(mColorLocation, color.values[0], color.values[1], color.values[2], color.values[3]); bool blendMin = (rand() % 2 == 0); glBlendEquation(blendMin ? GL_MIN : GL_MAX); drawQuad(mProgram, "aPosition", 0.5f); if (i > 0) { EXPECT_PIXEL_EQ(0, 0, getExpected(blendMin, color.values[0], prevColor[0]), getExpected(blendMin, color.values[1], prevColor[1]), getExpected(blendMin, color.values[2], prevColor[2]), getExpected(blendMin, color.values[3], prevColor[3])); } glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, prevColor); } }
// Test creating a pbuffer from a d3d surface and binding it to a texture TEST_P(D3DTextureTest, BindTexImage) { if (!valid()) { return; } EGLWindow *window = getEGLWindow(); EGLDisplay display = window->getDisplay(); const size_t bufferSize = 32; EGLSurface pbuffer = createPBuffer(bufferSize, bufferSize, EGL_TEXTURE_RGBA, EGL_TEXTURE_2D, 1, 0); ASSERT_EGL_SUCCESS(); ASSERT_NE(pbuffer, EGL_NO_SURFACE); // Apply the Pbuffer and clear it to purple eglMakeCurrent(display, pbuffer, pbuffer, window->getContext()); ASSERT_EGL_SUCCESS(); glViewport(0, 0, static_cast<GLsizei>(bufferSize), static_cast<GLsizei>(bufferSize)); glClearColor(1.0f, 0.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); ASSERT_GL_NO_ERROR(); EXPECT_PIXEL_EQ(static_cast<GLint>(bufferSize) / 2, static_cast<GLint>(bufferSize) / 2, 255, 0, 255, 255); // Apply the window surface eglMakeCurrent(display, window->getSurface(), window->getSurface(), window->getContext()); // Create a texture and bind the Pbuffer to it GLuint texture = 0; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); EXPECT_GL_NO_ERROR(); eglBindTexImage(display, pbuffer, EGL_BACK_BUFFER); glViewport(0, 0, getWindowWidth(), getWindowHeight()); ASSERT_EGL_SUCCESS(); // Draw a quad and verify that it is purple glUseProgram(mTextureProgram); glUniform1i(mTextureUniformLocation, 0); drawQuad(mTextureProgram, "position", 0.5f); EXPECT_GL_NO_ERROR(); // Unbind the texture eglReleaseTexImage(display, pbuffer, EGL_BACK_BUFFER); ASSERT_EGL_SUCCESS(); // Verify that purple was drawn EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 255, 0, 255, 255); glDeleteTextures(1, &texture); // Make current with fixture EGL to ensure the Surface can be released immediately. getEGLWindow()->makeCurrent(); eglDestroySurface(display, pbuffer); }