Instead of repeating this function in all these tests, let's add a common helper function instead.
Signed-off-by: Erik Faye-Lund <erik.faye-l...@collabora.com> --- .../nv_conditional_render/CMakeLists.gl.txt | 8 ++-- .../nv_conditional_render/blitframebuffer.c | 18 +------- tests/spec/nv_conditional_render/common.c | 44 +++++++++++++++++++ tests/spec/nv_conditional_render/common.h | 31 +++++++++++++ .../spec/nv_conditional_render/copyteximage.c | 19 +------- .../nv_conditional_render/copytexsubimage.c | 19 +------- .../nv_conditional_render/generatemipmap.c | 25 +++-------- 7 files changed, 87 insertions(+), 77 deletions(-) create mode 100644 tests/spec/nv_conditional_render/common.c create mode 100644 tests/spec/nv_conditional_render/common.h diff --git a/tests/spec/nv_conditional_render/CMakeLists.gl.txt b/tests/spec/nv_conditional_render/CMakeLists.gl.txt index a4cf2f5f6..0f24564d4 100644 --- a/tests/spec/nv_conditional_render/CMakeLists.gl.txt +++ b/tests/spec/nv_conditional_render/CMakeLists.gl.txt @@ -11,12 +11,12 @@ link_libraries ( piglit_add_executable (nv_conditional_render-begin-while-active begin-while-active.c) piglit_add_executable (nv_conditional_render-begin-zero begin-zero.c) piglit_add_executable (nv_conditional_render-bitmap bitmap.c) -piglit_add_executable (nv_conditional_render-blitframebuffer blitframebuffer.c) +piglit_add_executable (nv_conditional_render-blitframebuffer blitframebuffer.c common.c) piglit_add_executable (nv_conditional_render-clear clear.c) piglit_add_executable (nv_conditional_render-copypixels copypixels.c) -piglit_add_executable (nv_conditional_render-copyteximage copyteximage.c) -piglit_add_executable (nv_conditional_render-copytexsubimage copytexsubimage.c) +piglit_add_executable (nv_conditional_render-copyteximage copyteximage.c common.c) +piglit_add_executable (nv_conditional_render-copytexsubimage copytexsubimage.c common.c) piglit_add_executable (nv_conditional_render-dlist dlist.c) piglit_add_executable (nv_conditional_render-drawpixels drawpixels.c) -piglit_add_executable (nv_conditional_render-generatemipmap generatemipmap.c) +piglit_add_executable (nv_conditional_render-generatemipmap generatemipmap.c common.c) piglit_add_executable (nv_conditional_render-vertex_array vertex_array.c) diff --git a/tests/spec/nv_conditional_render/blitframebuffer.c b/tests/spec/nv_conditional_render/blitframebuffer.c index 06e5c7d81..c8c2f4b87 100644 --- a/tests/spec/nv_conditional_render/blitframebuffer.c +++ b/tests/spec/nv_conditional_render/blitframebuffer.c @@ -23,6 +23,7 @@ */ #include "piglit-util-gl.h" +#include "common.h" /** * @file blitframebuffer.c @@ -42,23 +43,6 @@ PIGLIT_GL_TEST_CONFIG_BEGIN PIGLIT_GL_TEST_CONFIG_END -static void fill_tex(int level, int w, int h, const GLfloat *color) -{ - GLfloat *data; - int i; - - data = malloc(w * h * 4 * sizeof(GLfloat)); - for (i = 0; i < 4 * w * h; i += 4) { - data[i + 0] = color[0]; - data[i + 1] = color[1]; - data[i + 2] = color[2]; - data[i + 3] = color[3]; - } - glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, - GL_RGBA, GL_FLOAT, data); - free(data); -} - static void blit_window_to_tex(GLuint tex, int w, int h) { GLuint fb; diff --git a/tests/spec/nv_conditional_render/common.c b/tests/spec/nv_conditional_render/common.c new file mode 100644 index 000000000..4d6c03198 --- /dev/null +++ b/tests/spec/nv_conditional_render/common.c @@ -0,0 +1,44 @@ +/* + * Copyright © 2011 Intel Corporation + * Copyright © 2011 Marek Olšák <mar...@gmail.com> + * + * 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 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#include "common.h" +#include "piglit-util-gl.h" + +void +fill_tex(int level, int w, int h, const float *color) +{ + GLfloat *data; + int i; + + data = malloc(w * h * 4 * sizeof(GLfloat)); + for (i = 0; i < 4 * w * h; i += 4) { + data[i + 0] = color[0]; + data[i + 1] = color[1]; + data[i + 2] = color[2]; + data[i + 3] = color[3]; + } + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, + GL_RGBA, GL_FLOAT, data); + free(data); +} diff --git a/tests/spec/nv_conditional_render/common.h b/tests/spec/nv_conditional_render/common.h new file mode 100644 index 000000000..fea961d6e --- /dev/null +++ b/tests/spec/nv_conditional_render/common.h @@ -0,0 +1,31 @@ +/* + * Copyright © 2011 Intel Corporation + * Copyright © 2011 Marek Olšák <mar...@gmail.com> + * + * 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 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifndef COMMON_H +#define COMMON_H + +void +fill_tex(int level, int w, int h, const float *color); + +#endif /* COMMON_H */ diff --git a/tests/spec/nv_conditional_render/copyteximage.c b/tests/spec/nv_conditional_render/copyteximage.c index 2a00c0293..6e2e5ffc6 100644 --- a/tests/spec/nv_conditional_render/copyteximage.c +++ b/tests/spec/nv_conditional_render/copyteximage.c @@ -23,6 +23,7 @@ */ #include "piglit-util-gl.h" +#include "common.h" /** * @file copyteximage.c @@ -42,24 +43,6 @@ PIGLIT_GL_TEST_CONFIG_BEGIN PIGLIT_GL_TEST_CONFIG_END -static void -fill_tex(int level, int w, int h, const GLfloat *color) -{ - GLfloat *data; - int i; - - data = malloc(w * h * 4 * sizeof(GLfloat)); - for (i = 0; i < 4 * w * h; i += 4) { - data[i + 0] = color[0]; - data[i + 1] = color[1]; - data[i + 2] = color[2]; - data[i + 3] = color[3]; - } - glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, - GL_RGBA, GL_FLOAT, data); - free(data); -} - enum piglit_result piglit_display(void) { diff --git a/tests/spec/nv_conditional_render/copytexsubimage.c b/tests/spec/nv_conditional_render/copytexsubimage.c index da8fc3ca9..36bde4ad4 100644 --- a/tests/spec/nv_conditional_render/copytexsubimage.c +++ b/tests/spec/nv_conditional_render/copytexsubimage.c @@ -23,6 +23,7 @@ */ #include "piglit-util-gl.h" +#include "common.h" /** * @file copytexsubimage.c @@ -42,24 +43,6 @@ PIGLIT_GL_TEST_CONFIG_BEGIN PIGLIT_GL_TEST_CONFIG_END -static void -fill_tex(int level, int w, int h, const GLfloat *color) -{ - GLfloat *data; - int i; - - data = malloc(w * h * 4 * sizeof(GLfloat)); - for (i = 0; i < 4 * w * h; i += 4) { - data[i + 0] = color[0]; - data[i + 1] = color[1]; - data[i + 2] = color[2]; - data[i + 3] = color[3]; - } - glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, - GL_RGBA, GL_FLOAT, data); - free(data); -} - enum piglit_result piglit_display(void) { diff --git a/tests/spec/nv_conditional_render/generatemipmap.c b/tests/spec/nv_conditional_render/generatemipmap.c index 1953e3dbf..d3e1e3a47 100644 --- a/tests/spec/nv_conditional_render/generatemipmap.c +++ b/tests/spec/nv_conditional_render/generatemipmap.c @@ -22,6 +22,7 @@ */ #include "piglit-util-gl.h" +#include "common.h" /** * @file generatemipmap.c @@ -46,24 +47,6 @@ PIGLIT_GL_TEST_CONFIG_BEGIN PIGLIT_GL_TEST_CONFIG_END -static void -fill_level(int level, int size, const GLfloat *color) -{ - GLfloat *data; - int i; - - data = malloc(size * size * 4 * sizeof(GLfloat)); - for (i = 0; i < 4 * size * size; i += 4) { - data[i + 0] = color[0]; - data[i + 1] = color[1]; - data[i + 2] = color[2]; - data[i + 3] = color[3]; - } - glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, - GL_RGBA, GL_FLOAT, data); - free(data); -} - enum piglit_result piglit_display(void) { @@ -88,8 +71,10 @@ piglit_display(void) GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - for (i = 0; tex_size / (1 << i) > 0; i++) - fill_level(i, tex_size / (1 << i), i == 0 ? green : red); + for (i = 0; tex_size / (1 << i) > 0; i++) { + int level_size = tex_size / (1 << i); + fill_tex(i, level_size, level_size, i == 0 ? green : red); + } glGenQueries(1, &q); -- 2.19.1 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/piglit