// Test mapping with the OES extension. TEST_P(BufferDataTest, MapBufferOES) { if (!IsGLExtensionEnabled("GL_EXT_map_buffer_range")) { // Needed for test validation. return; } std::vector<uint8_t> data(1024); FillVectorWithRandomUBytes(&data); GLBuffer buffer; glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); glBufferData(GL_ARRAY_BUFFER, data.size(), nullptr, GL_STATIC_DRAW); // Validate that other map flags don't work. void *badMapPtr = glMapBufferOES(GL_ARRAY_BUFFER, GL_MAP_READ_BIT); EXPECT_EQ(nullptr, badMapPtr); EXPECT_GL_ERROR(GL_INVALID_ENUM); // Map and write. void *mapPtr = glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES); ASSERT_NE(nullptr, mapPtr); ASSERT_GL_NO_ERROR(); memcpy(mapPtr, data.data(), data.size()); glUnmapBufferOES(GL_ARRAY_BUFFER); // Validate data with EXT_map_buffer_range void *readMapPtr = glMapBufferRangeEXT(GL_ARRAY_BUFFER, 0, data.size(), GL_MAP_READ_BIT_EXT); ASSERT_NE(nullptr, readMapPtr); ASSERT_GL_NO_ERROR(); std::vector<uint8_t> actualData(data.size()); memcpy(actualData.data(), readMapPtr, data.size()); glUnmapBufferOES(GL_ARRAY_BUFFER); EXPECT_EQ(data, actualData); }
// Checks gl_PointCoord and gl_PointSize // https://www.khronos.org/registry/webgl/sdk/tests/conformance/glsl/variables/gl-pointcoord.html TEST_P(PointSpritesTest, PointCoordAndPointSizeCompliance) { // TODO(jmadill): figure out why this fails if (IsIntel() && GetParam() == ES2_D3D9()) { std::cout << "Test skipped on Intel due to failures." << std::endl; return; } // TODO(jmadill): Investigate potential AMD driver bug. // http://anglebug.com/1643 if (IsAMD() && IsDesktopOpenGL() && IsWindows()) { std::cout << "Test skipped on desktop GL AMD Windows." << std::endl; return; } const std::string fs = R"(precision mediump float; void main() { gl_FragColor = vec4(gl_PointCoord.x, gl_PointCoord.y, 0, 1); })"; const std::string vs = R"(attribute vec4 vPosition; uniform float uPointSize; void main() { gl_PointSize = uPointSize; gl_Position = vPosition; })"; ANGLE_GL_PROGRAM(program, vs, fs); glUseProgram(program); GLfloat pointSizeRange[2] = {}; glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange); GLfloat maxPointSize = pointSizeRange[1]; ASSERT_TRUE(maxPointSize >= 1); maxPointSize = floorf(maxPointSize); ASSERT_TRUE((int)maxPointSize % 1 == 0); maxPointSize = std::min(maxPointSize, 64.0f); GLfloat pointWidth = maxPointSize / windowWidth; GLint step = static_cast<GLint>(floorf(maxPointSize / 4)); GLint pointStep = std::max<GLint>(1, step); GLint pointSizeLoc = glGetUniformLocation(program, "uPointSize"); ASSERT_GL_NO_ERROR(); glUniform1f(pointSizeLoc, maxPointSize); ASSERT_GL_NO_ERROR(); GLfloat pixelOffset = ((int)maxPointSize % 2) ? (1.0f / (GLfloat)windowWidth) : 0; GLBuffer vertexObject; glBindBuffer(GL_ARRAY_BUFFER, vertexObject.get()); ASSERT_GL_NO_ERROR(); GLfloat thePoints[] = {-0.5f + pixelOffset, -0.5f + pixelOffset, 0.5f + pixelOffset, -0.5f + pixelOffset, -0.5f + pixelOffset, 0.5f + pixelOffset, 0.5f + pixelOffset, 0.5f + pixelOffset}; glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW); ASSERT_GL_NO_ERROR(); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDrawArrays(GL_POINTS, 0, 4); ASSERT_GL_NO_ERROR(); std::string debugText; for (float py = 0; py < 2; ++py) { for (float px = 0; px < 2; ++px) { float pointX = -0.5f + px + pixelOffset; float pointY = -0.5f + py + pixelOffset; for (int yy = 0; yy < maxPointSize; yy += pointStep) { for (int xx = 0; xx < maxPointSize; xx += pointStep) { // formula for s and t from OpenGL ES 2.0 spec section 3.3 float xw = s2p(pointX); float yw = s2p(pointY); float u = xx / maxPointSize * 2 - 1; float v = yy / maxPointSize * 2 - 1; int xf = static_cast<int>(floorf(s2p(pointX + u * pointWidth))); int yf = static_cast<int>(floorf(s2p(pointY + v * pointWidth))); float s = 0.5f + (xf + 0.5f - xw) / maxPointSize; float t = 0.5f + (yf + 0.5f - yw) / maxPointSize; GLubyte color[4] = {static_cast<GLubyte>(floorf(s * 255)), static_cast<GLubyte>(floorf((1 - t) * 255)), 0, 255}; EXPECT_PIXEL_NEAR(xf, yf, color[0], color[1], color[2], color[3], 4); } } } } }
glClearColor(0, 0, 0, 1); glDisable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT); GLint pointSizeLoc = glGetUniformLocation(program, "u_pointSize"); ASSERT_GL_NO_ERROR(); GLfloat pointSize = std::min<GLfloat>(20.0f, maxPointSize); glUniform1f(pointSizeLoc, pointSize); ASSERT_GL_NO_ERROR(); GLBuffer vertexObject; ASSERT_GL_NO_ERROR(); glBindBuffer(GL_ARRAY_BUFFER, vertexObject.get()); ASSERT_GL_NO_ERROR(); GLfloat thePoints[] = {0.0f, 0.0f}; glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW); ASSERT_GL_NO_ERROR(); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); glDrawArrays(GL_POINTS, 0, 1); ASSERT_GL_NO_ERROR(); // expect the center pixel to be green EXPECT_PIXEL_EQ((windowWidth - 1) / 2, (windowHeight - 1) / 2, 0, 255, 0, 255);