Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2574)

Unified Diff: client/deps/glbench/src/utils.cc

Issue 2123013: Split tests into individual files. Got rid of globals by converting them to classes. (Closed) Base URL: ssh://git@chromiumos-git//autotest.git
Patch Set: addressed comments Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/deps/glbench/src/utils.h ('k') | client/deps/glbench/src/varyingsandddxytest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/deps/glbench/src/utils.cc
diff --git a/client/deps/glbench/src/utils.cc b/client/deps/glbench/src/utils.cc
index ea0d6e0f444307e89ce86493d0f37a59f496ac0d..4d2aca4a908da3db65cb680a453c19692cbf7d33 100644
--- a/client/deps/glbench/src/utils.cc
+++ b/client/deps/glbench/src/utils.cc
@@ -47,6 +47,103 @@ void *MmapFile(const char* name, size_t* length) {
}
+namespace glbench {
+
+GLuint SetupTexture(GLsizei size_log2) {
+ GLsizei size = 1 << size_log2;
+ GLuint name = ~0;
+ glGenTextures(1, &name);
+ glBindTexture(GL_TEXTURE_2D, name);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ unsigned char *pixels = new unsigned char[size * size * 4];
+ if (!pixels)
+ return 0;
+
+ for (GLint level = 0; size > 0; level++, size /= 2) {
+ unsigned char *p = pixels;
+ for (int i = 0; i < size; i++) {
+ for (int j = 0; j < size; j++) {
+ *p++ = level %3 != 0 ? (i ^ j) << level : 0;
+ *p++ = level %3 != 1 ? (i ^ j) << level : 0;
+ *p++ = level %3 != 2 ? (i ^ j) << level : 0;
+ *p++ = 255;
+ }
+ }
+ if (size == 1) {
+ unsigned char *p = pixels;
+ *p++ = 255;
+ *p++ = 255;
+ *p++ = 255;
+ *p++ = 255;
+ }
+ glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+ }
+ delete[] pixels;
+ return name;
+}
+
+GLuint SetupVBO(GLenum target, GLsizeiptr size, const GLvoid *data) {
+ GLuint buf = ~0;
+ glGenBuffers(1, &buf);
+ glBindBuffer(target, buf);
+ glBufferData(target, size, data, GL_STATIC_DRAW);
+ CHECK(!glGetError());
+ return buf;
+}
+
+// Generates a tautological lattice.
+void CreateLattice(GLfloat **vertices, GLsizeiptr *size,
+ GLfloat size_x, GLfloat size_y, int width, int height)
+{
+ GLfloat *vptr = *vertices = new GLfloat[2 * (width + 1) * (height + 1)];
+ for (int j = 0; j <= height; j++) {
+ for (int i = 0; i <= width; i++) {
+ *vptr++ = i * size_x;
+ *vptr++ = j * size_y;
+ }
+ }
+ *size = (vptr - *vertices) * sizeof(GLfloat);
+}
+
+// Generates a mesh of 2*width*height triangles. The ratio of front facing to
+// back facing triangles is culled_ratio/RAND_MAX. Returns the number of
+// vertices in the mesh.
+int CreateMesh(GLuint **indices, GLsizeiptr *size,
+ int width, int height, int culled_ratio) {
+ srand(0);
+
+ GLuint *iptr = *indices = new GLuint[2 * 3 * (width * height)];
+ const int swath_height = 4;
+
+ CHECK(width % swath_height == 0 && height % swath_height == 0);
+
+ for (int j = 0; j < height; j += swath_height) {
+ for (int i = 0; i < width; i++) {
+ for (int j2 = 0; j2 < swath_height; j2++) {
+ GLuint first = (j + j2) * (width + 1) + i;
+ GLuint second = first + 1;
+ GLuint third = first + (width + 1);
+ GLuint fourth = third + 1;
+
+ bool flag = rand() < culled_ratio;
+ *iptr++ = first;
+ *iptr++ = flag ? second : third;
+ *iptr++ = flag ? third : second;
+
+ *iptr++ = fourth;
+ *iptr++ = flag ? third : second;
+ *iptr++ = flag ? second : third;
+ }
+ }
+ }
+ *size = (iptr - *indices) * sizeof(GLuint);
+
+ return iptr - *indices;
+}
+
static void print_info_log(int obj)
{
char info_log[4096];
@@ -67,7 +164,6 @@ static void print_info_log(int obj)
}
}
-
GLuint InitShaderProgram(const char *vertex_src, const char *fragment_src) {
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
@@ -92,3 +188,5 @@ GLuint InitShaderProgram(const char *vertex_src, const char *fragment_src) {
return program;
}
+
+} // namespace glbench
« no previous file with comments | « client/deps/glbench/src/utils.h ('k') | client/deps/glbench/src/varyingsandddxytest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698