Commit b4fd0c96 by Jamie Madill

Replace usages of std::vector::data in most cases.

In some parts of ANGLE code, we were using std::vector::data to get a pointer to the first element. Sadly, this is c++11 only, which isn't currently supported on Chromium. This was causing a breakage on Android. We should probably refrain from using data except on D3D-only code, which we know will be Visual Studio. BUG=angle:767 Change-Id: Ibc10577368435a13f62d74d77c95076482cd8f82 Reviewed-on: https://chromium-review.googlesource.com/220920Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 18b931d5
......@@ -24,7 +24,7 @@ std::string FormatString(const char *fmt, va_list vararg)
vsnprintf(&buffer[0], buffer.size(), fmt, vararg);
}
return std::string(buffer.data(), len);
return std::string(&buffer[0], len);
}
std::string FormatString(const char *fmt, ...)
......
......@@ -44,7 +44,7 @@ class VertexArray
void setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, bool pureInteger, GLsizei stride, const void *pointer);
const VertexAttribute* getVertexAttributes() const { return mVertexAttributes.data(); }
const VertexAttribute* getVertexAttributes() const { return &mVertexAttributes[0]; }
Buffer *getElementArrayBuffer() const { return mElementArrayBuffer.get(); }
void setElementArrayBuffer(Buffer *buffer);
GLuint getElementArrayBufferId() const { return mElementArrayBuffer.id(); }
......
......@@ -104,9 +104,9 @@ GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<GLchar> infoLog(infoLogLength);
glGetShaderInfoLog(shader, infoLog.size(), NULL, infoLog.data());
glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);
std::cerr << "shader compilation failed: " << infoLog.data();
std::cerr << "shader compilation failed: " << &infoLog[0];
glDeleteShader(shader);
shader = 0;
......
......@@ -96,7 +96,7 @@ TYPED_TEST(IncompleteTextureTest, IncompleteTexture2D)
std::vector<GLubyte> textureData(textureWidth * textureHeight * 4);
fillTextureData(textureData, 255, 0, 0, 255);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData.data());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
drawQuad(mProgram, "position", 0.5f);
......@@ -107,7 +107,7 @@ TYPED_TEST(IncompleteTextureTest, IncompleteTexture2D)
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 255);
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, textureWidth >> 1, textureHeight >> 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData.data());
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, textureWidth >> 1, textureHeight >> 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
......@@ -132,7 +132,7 @@ TYPED_TEST(IncompleteTextureTest, UpdateTexture)
for (size_t i = 0; i < 7; i++)
{
glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, redTextureWidth >> i, redTextureHeight >> i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
redTextureData.data());
&redTextureData[0]);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
......@@ -150,7 +150,7 @@ TYPED_TEST(IncompleteTextureTest, UpdateTexture)
{
glTexSubImage2D(GL_TEXTURE_2D, i, greenTextureWidth >> i, greenTextureHeight >> i,
greenTextureWidth >> i, greenTextureHeight >> i, GL_RGBA, GL_UNSIGNED_BYTE,
greenTextureData.data());
&greenTextureData[0]);
}
drawQuad(mProgram, "position", 0.5f);
......
......@@ -67,12 +67,12 @@ protected:
};
glGenBuffers(1, &mVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), vertices.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), &vertices[0], GL_STATIC_DRAW);
std::array<IndexType, mPointCount> indices = { 0, 1, 2, 3 };
glGenBuffers(1, &mIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(IndexType), indices.data(), GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(IndexType), &indices[0], GL_STATIC_DRAW);
}
virtual void TearDown()
......
......@@ -111,13 +111,13 @@ protected:
glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices);
std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
for (int y = 0; y < getWindowHeight(); y++)
{
for (int x = 0; x < getWindowWidth(); x++)
{
const GLubyte* pixel = pixels.data() + ((y * getWindowWidth() + x) * 4);
const GLubyte* pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
EXPECT_EQ(pixel[0], 0);
EXPECT_EQ(pixel[1], pixel[2]);
......
......@@ -110,7 +110,7 @@ TYPED_TEST(MaxTextureSizeTest, SpecificationTexImage)
{
for (int x = 0; x < textureWidth; x++)
{
GLubyte* pixel = data.data() + ((y * textureWidth + x) * 4);
GLubyte* pixel = &data[0] + ((y * textureWidth + x) * 4);
// Draw a gradient, red in direction, green in y direction
pixel[0] = static_cast<GLubyte>((float(x) / textureWidth) * 255);
......@@ -120,7 +120,7 @@ TYPED_TEST(MaxTextureSizeTest, SpecificationTexImage)
}
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
EXPECT_GL_NO_ERROR();
glUseProgram(mTextureProgram);
......@@ -129,14 +129,14 @@ TYPED_TEST(MaxTextureSizeTest, SpecificationTexImage)
drawQuad(mTextureProgram, "position", 0.5f);
std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
for (int y = 1; y < getWindowHeight(); y++)
{
for (int x = 1; x < getWindowWidth(); x++)
{
const GLubyte* prevPixel = pixels.data() + (((y - 1) * getWindowWidth() + (x - 1)) * 4);
const GLubyte* curPixel = pixels.data() + ((y * getWindowWidth() + x) * 4);
const GLubyte* prevPixel = &pixels[0] + (((y - 1) * getWindowWidth() + (x - 1)) * 4);
const GLubyte* curPixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
EXPECT_GE(curPixel[0], prevPixel[0]);
EXPECT_GE(curPixel[1], prevPixel[1]);
......@@ -170,7 +170,7 @@ TYPED_TEST(MaxTextureSizeTest, SpecificationTexStorage)
{
for (int x = 0; x < textureWidth; x++)
{
GLubyte* pixel = data.data() + ((y * textureWidth + x) * 4);
GLubyte* pixel = &data[0] + ((y * textureWidth + x) * 4);
// Draw a gradient, red in direction, green in y direction
pixel[0] = static_cast<GLubyte>((float(x) / textureWidth) * 255);
......@@ -190,7 +190,7 @@ TYPED_TEST(MaxTextureSizeTest, SpecificationTexStorage)
}
EXPECT_GL_NO_ERROR();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
EXPECT_GL_NO_ERROR();
glUseProgram(mTextureProgram);
......@@ -199,14 +199,14 @@ TYPED_TEST(MaxTextureSizeTest, SpecificationTexStorage)
drawQuad(mTextureProgram, "position", 0.5f);
std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
for (int y = 1; y < getWindowHeight(); y++)
{
for (int x = 1; x < getWindowWidth(); x++)
{
const GLubyte* prevPixel = pixels.data() + (((y - 1) * getWindowWidth() + (x - 1)) * 4);
const GLubyte* curPixel = pixels.data() + ((y * getWindowWidth() + x) * 4);
const GLubyte* prevPixel = &pixels[0] + (((y - 1) * getWindowWidth() + (x - 1)) * 4);
const GLubyte* curPixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
EXPECT_GE(curPixel[0], prevPixel[0]);
EXPECT_GE(curPixel[1], prevPixel[1]);
......
......@@ -99,14 +99,14 @@ TYPED_TEST(ReadPixelsTest, OutOfBounds)
GLint offset = 16;
std::vector<GLubyte> pixels((pixelsWidth + offset) * (pixelsHeight + offset) * 4);
glReadPixels(-offset, -offset, pixelsWidth + offset, pixelsHeight + offset, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glReadPixels(-offset, -offset, pixelsWidth + offset, pixelsHeight + offset, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
EXPECT_GL_NO_ERROR();
for (int y = pixelsHeight / 2; y < pixelsHeight; y++)
{
for (int x = pixelsWidth / 2; x < pixelsWidth; x++)
{
const GLubyte* pixel = pixels.data() + ((y * (pixelsWidth + offset) + x) * 4);
const GLubyte* pixel = &pixels[0] + ((y * (pixelsWidth + offset) + x) * 4);
unsigned int r = static_cast<unsigned int>(pixel[0]);
unsigned int g = static_cast<unsigned int>(pixel[1]);
unsigned int b = static_cast<unsigned int>(pixel[2]);
......
......@@ -207,11 +207,11 @@ bool BufferSubDataBenchmark::initializeBenchmark()
std::vector<uint8_t> zeroData(mParams.bufferSize);
memset(zeroData.data(), 0, zeroData.size());
memset(&zeroData[0], 0, zeroData.size());
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ARRAY_BUFFER, mParams.bufferSize, zeroData.data(), GL_DYNAMIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, mParams.bufferSize, &zeroData[0], GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, mParams.vertexComponentCount, mParams.vertexType,
mParams.vertexNormalized, 0, 0);
......@@ -230,14 +230,14 @@ bool BufferSubDataBenchmark::initializeBenchmark()
mNumTris = mParams.updateSize / triDataSize;
for (int i = 0, offset = 0; i < mNumTris; ++i)
{
memcpy(mUpdateData + offset, data.data(), triDataSize);
memcpy(mUpdateData + offset, &data[0], triDataSize);
offset += triDataSize;
}
if (mParams.updateSize == 0)
{
mNumTris = 1;
glBufferSubData(GL_ARRAY_BUFFER, 0, data.size(), data.data());
glBufferSubData(GL_ARRAY_BUFFER, 0, data.size(), &data[0]);
}
// Set the viewport
......
......@@ -107,7 +107,7 @@ bool PointSpritesBenchmark::initializeBenchmark()
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ARRAY_BUFFER, vertexPositions.size() * sizeof(float), vertexPositions.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vertexPositions.size() * sizeof(float), &vertexPositions[0], GL_STATIC_DRAW);
int positionLocation = glGetAttribLocation(mProgram, "vPosition");
if (positionLocation == -1)
......
......@@ -47,9 +47,9 @@ GLuint CompileShader(GLenum type, const std::string &source)
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<GLchar> infoLog(infoLogLength);
glGetShaderInfoLog(shader, infoLog.size(), NULL, infoLog.data());
glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);
std::cerr << "shader compilation failed: " << infoLog.data();
std::cerr << "shader compilation failed: " << &infoLog[0];
glDeleteShader(shader);
shader = 0;
......@@ -101,9 +101,9 @@ GLuint CompileProgram(const std::string &vsSource, const std::string &fsSource)
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<GLchar> infoLog(infoLogLength);
glGetProgramInfoLog(program, infoLog.size(), NULL, infoLog.data());
glGetProgramInfoLog(program, infoLog.size(), NULL, &infoLog[0]);
std::cerr << "program link failed: " << infoLog.data();
std::cerr << "program link failed: " << &infoLog[0];
glDeleteProgram(program);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment