/* * Copyright (c) The Piglit project 2008 * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * on the rights to use, copy, modify, merge, publish, distribute, sub * license, and/or sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * @file * Test the GL_EXT_texture_lod_bias extension. * * Only test LOD bias with a granularity of 1.0 with a nearest mip filter. * This leaves room for somewhat inaccurate hardware implementations. * The point of this test is that the implementation has to get the big * picture issues right: * * 1. LOD bias is per texture stage, not per texture object. * 2. LOD bias is applied *before* clamping. * 3. The supported bias range must be reported correctly. * * @todo * Check per-texture object LOD bias (support for this was added in OpenGL 1.4). * In particular, check interaction of per-texture and per-TexUnit bias. * Check clamping behaviour. */ #include "piglit-util-gl.h" #define SquareSize 50 PIGLIT_GL_TEST_CONFIG_BEGIN config.supports_gl_compat_version = 10; config.window_width = 3*SquareSize; config.window_height = 3*SquareSize; config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; config.khr_no_error_support = PIGLIT_NO_ERRORS; PIGLIT_GL_TEST_CONFIG_END static int CurrentTest = 0; static int CurrentBias = 0; static int CurrentBias2 = 0; static int MaxTextureLodBias; static GLuint Textures[2]; #define NrTests 2 /** * The test uses two 4x4 clamped, mipmapped textures (i.e. 3 mip levels) * with the following RGB colors on each level. * * Note: Black is used as a background color, so don't use black for the textures. */ static GLfloat TextureData[2][3][3] = { { { 0.5, 0.5, 0.5 }, { 0.5, 0.0, 0.0 }, { 0.0, 0.5, 0.0 } }, { { 0.0, 0.0, 0.5 }, { 0.5, 0.5, 0.0 }, { 0.0, 0.5, 0.5 } } }; static GLboolean probe_cell(const char* testname, int cellx, int celly, const float* expected) { int x, y; for(y = 0; y < 4; ++y) { for(x = 0; x < 4; ++x) { int pixx = (5*cellx+x+1)*SquareSize/5; int pixy = (5*celly+y+1)*SquareSize/5; if (!piglit_probe_pixel_rgb(pixx, pixy, expected)) { fprintf(stderr, "%s: %i,%i failed\n", testname, cellx, celly); return GL_FALSE; } } } return GL_TRUE; } static float scale_for_miplevel(int bias, int level) { float base = SquareSize/(4>>level); if (bias >= 0) return base/(float)(1<= NrTests) CurrentTest = 0; printf("Test: %s\n", CurrentTest ? "multitexturing" : "simple"); break; case 'b': CurrentBias--; if (CurrentBias < -MaxTextureLodBias) CurrentBias = -MaxTextureLodBias; break; case 'B': CurrentBias++; if (CurrentBias > MaxTextureLodBias) CurrentBias = MaxTextureLodBias; break; case 'n': CurrentBias2--; if (CurrentBias2 < -MaxTextureLodBias) CurrentBias2 = -MaxTextureLodBias; break; case 'N': CurrentBias2++; if (CurrentBias2 > MaxTextureLodBias) CurrentBias2 = MaxTextureLodBias; break; case 27: exit(0); break; } printf("Current LOD bias: 1st tex: %i 2nd tex: %i\n", CurrentBias, CurrentBias2); piglit_post_redisplay(); } void piglit_init(int argc, char **argv) { int i; piglit_require_gl_version(13); piglit_require_extension("GL_EXT_texture_lod_bias"); glGetIntegerv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLodBias); if (!piglit_automatic) printf("MAX_TEXTURE_LOD_BIAS_EXT = %i\n", MaxTextureLodBias); if (!piglit_automatic) { printf( "Press 't' to switch tests\n" "Press 'b'/'B' to change primary LOD bias\n" "Press 'n'/'N' to change secondary LOD bias\n" "Press 'Escape' to quit\n"); piglit_set_keyboard_func(Key); } glGenTextures(2, Textures); for(i = 0; i < 2; ++i) { int level; glBindTexture(GL_TEXTURE_2D, Textures[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); for(level = 0; level < 3; ++level) { GLfloat texdata[16][3]; int dim = 4 >> level; int j; for(j = 0; j < dim*dim; ++j) { texdata[j][0] = TextureData[i][level][0]; texdata[j][1] = TextureData[i][level][1]; texdata[j][2] = TextureData[i][level][2]; } glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, dim, dim, 0, GL_RGB, GL_FLOAT, texdata); } } glReadBuffer(GL_BACK); }