static GLboolean draw_at_size(int size, int x_offset, int y_offset, GLboolean mipmapped) { GLfloat row_y = PAD + y_offset; int dim, face; int color = 0, level = 0, maxlevel, baselevel = 3; GLuint texname; GLboolean pass = GL_TRUE; GLint loc; glUseProgram(program_cube); loc = glGetUniformLocation(program_cube, "tex"); glUniform1i(loc, 0); /* texture unit p */ /* Create the texture. */ glGenTextures(1, &texname); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, texname); /* For each face drawing, we want to only see that face's contents at * that mipmap level. */ if (mipmapped) { glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); } else { glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); /* Fill in faces on each level */ for (dim = size; dim > 0; dim /= 2) { if (test_state != STATE_PLAIN_SHADER) color = (level) % ARRAY_SIZE(colors); for (face = 0; face < 6; face++) { set_face_image(level, cube_face_targets[face], dim, color); if (test_state == STATE_PLAIN_SHADER) color = (color + 1) % ARRAY_SIZE(colors); } if (!mipmapped) break; level++; } maxlevel = level; if (maxlevel >= ARRAY_SIZE(colors)) maxlevel = ARRAY_SIZE(colors) - 1; glEnable(GL_TEXTURE_CUBE_MAP_ARB); color = 0; level = 0; if (test_state == STATE_LOD_BIAS_SHADER) level = baselevel; for (dim = size; dim > 0; dim /= 2) { GLfloat row_x = PAD + x_offset; if (test_state == STATE_LOD_SHADER) level = baselevel; for (face = 0; face < 6; face++) { GLfloat base_x = row_x + face * (max_size + PAD); GLfloat base_y = row_y; if (test_state != STATE_PLAIN_SHADER) { color = level; if (color >= ARRAY_SIZE(colors)) color = ARRAY_SIZE(colors) - 1; } glBegin(GL_QUADS); glTexCoord3fv(cube_face_texcoords[face][0]); glVertex2f(base_x, base_y); glTexCoord3fv(cube_face_texcoords[face][1]); glVertex2f(base_x + dim, base_y); glTexCoord3fv(cube_face_texcoords[face][2]); glVertex2f(base_x + dim, base_y + dim); glTexCoord3fv(cube_face_texcoords[face][3]); glVertex2f(base_x, base_y + dim); glEnd(); if (dim > 2) { pass = test_results(base_x, base_y, dim, level, face, mipmapped, color, maxlevel) && pass; } if (test_state == STATE_PLAIN_SHADER) color = (color + 1) % ARRAY_SIZE(colors); } if (!mipmapped) break; row_y += dim + PAD; level++; if (test_state != STATE_PLAIN_SHADER) if (level > maxlevel) level = maxlevel; } glUseProgram(0); glDeleteTextures(1, &texname); return pass; }
static GLboolean draw_at_size(int size, int x_offset, int y_offset, GLboolean mipmapped) { GLfloat row_y = PAD + y_offset; int dim, face; int color = 0, level = 0; GLuint texname; GLboolean pass = GL_TRUE; /* Create the texture. */ glGenTextures(1, &texname); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, texname); /* For each face drawing, we want to only see that face's contents at * that mipmap level. */ if (mipmapped) { glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); } else { glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); /* Fill in faces on each level */ for (dim = size; dim > 0; dim /= 2) { for (face = 0; face < 6; face++) { set_face_image(level, cube_face_targets[face], dim, color); color = (color + 1) % ARRAY_SIZE(colors); } if (!mipmapped) break; level++; } glEnable(GL_TEXTURE_CUBE_MAP_ARB); color = 0; level = 0; for (dim = size; dim > 0; dim /= 2) { GLfloat row_x = PAD + x_offset; for (face = 0; face < 6; face++) { GLfloat base_x = row_x + face * (max_size + PAD); GLfloat base_y = row_y; glBegin(GL_QUADS); glTexCoord3fv(cube_face_texcoords[face][0]); glVertex2f(base_x, base_y); glTexCoord3fv(cube_face_texcoords[face][1]); glVertex2f(base_x + dim, base_y); glTexCoord3fv(cube_face_texcoords[face][2]); glVertex2f(base_x + dim, base_y + dim); glTexCoord3fv(cube_face_texcoords[face][3]); glVertex2f(base_x, base_y + dim); glEnd(); if (dim > 2) { pass = test_results(base_x, base_y, dim, level, face, mipmapped, color) && pass; } color = (color + 1) % ARRAY_SIZE(colors); } if (!mipmapped) break; row_y += dim + PAD; level++; } glDeleteTextures(1, &texname); return pass; }