From 017e4064fdd099f9506e7bb6e723cfbcf579497e Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 10 Jul 2018 10:48:21 -0700 Subject: [PATCH] tfp: Also test with GL_TEXTURE_RECTANGLE --- tests/glx/glx-tfp.c | 102 +++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 40 deletions(-) diff --git a/tests/glx/glx-tfp.c b/tests/glx/glx-tfp.c index 26408741a..46e317adc 100644 --- a/tests/glx/glx-tfp.c +++ b/tests/glx/glx-tfp.c @@ -48,9 +48,12 @@ GLfloat tex_data[4][4] = { }; #define WIN_WIDTH 256 -#define WIN_HEIGHT 128 +#define WIN_HEIGHT 256 +#define PIXMAP_WIDTH 2 +#define PIXMAP_HEIGHT 2 -static GLXPixmap rgb_pixmap, rgba_pixmap; +static GLXPixmap rgb_2d_pixmap, rgba_2d_pixmap; +static GLXPixmap rgb_rect_pixmap, rgba_rect_pixmap; static Display *dpy; static Window win; int piglit_width = WIN_WIDTH; @@ -95,7 +98,7 @@ check_results(GLboolean has_alpha, int x, int y, int w, int h) } static void -draw_pixmap(GLXPixmap pixmap, int x, int y, int w, int h) +draw_pixmap(GLXPixmap pixmap, GLenum target, int x, int y, int w, int h) { GLuint texname; GLfloat tex_coords[] = { @@ -106,6 +109,13 @@ draw_pixmap(GLXPixmap pixmap, int x, int y, int w, int h) }; GLfloat vertex_coords[4][2]; + if (target == GL_TEXTURE_RECTANGLE) { + for (int i = 0; i < 4; i++) { + tex_coords[i * 2 + 0] *= PIXMAP_WIDTH; + tex_coords[i * 2 + 1] *= PIXMAP_HEIGHT; + } + } + vertex_coords[0][0] = x; vertex_coords[0][1] = y; vertex_coords[1][0] = x + w; @@ -117,13 +127,13 @@ draw_pixmap(GLXPixmap pixmap, int x, int y, int w, int h) /* Create the texture. */ glGenTextures(1, &texname); - glBindTexture(GL_TEXTURE_2D, texname); - glEnable(GL_TEXTURE_2D); + glBindTexture(target, texname); + glEnable(target); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP); /* Set the texture combiner to give {r*a, g*a, b*a, a} so we can see * the effect of the alpha channel in terms of color. @@ -154,29 +164,35 @@ draw_pixmap(GLXPixmap pixmap, int x, int y, int w, int h) glDeleteTextures(1, &texname); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable(GL_TEXTURE_2D); + glDisable(target); } static enum piglit_result draw(Display *dpy) { GLboolean pass = GL_TRUE; - int draw_w = piglit_width / 4; - int draw_h = piglit_height / 2; - int rgb_x = piglit_width / 8; - int rgb_y = piglit_height / 4; - int rgba_x = piglit_width * 5 / 8; - int rgba_y = piglit_height / 4; + int unit_x = piglit_width / 8; + int unit_y = piglit_width / 8; + int draw_w = 2 * unit_x; + int draw_h = 2 * unit_y; /* Clear background to gray */ glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT); - draw_pixmap(rgb_pixmap, rgb_x, rgb_y, draw_w, draw_h); - draw_pixmap(rgba_pixmap, rgba_x, rgba_y, draw_w, draw_h); + draw_pixmap(rgb_2d_pixmap, GL_TEXTURE_2D, + unit_x, unit_y, draw_w, draw_h); + draw_pixmap(rgba_2d_pixmap, GL_TEXTURE_2D, + 5 * unit_x, unit_y, draw_w, draw_h); + draw_pixmap(rgb_rect_pixmap, GL_TEXTURE_RECTANGLE, + unit_x, 5 * unit_y, draw_w, draw_h); + draw_pixmap(rgba_rect_pixmap, GL_TEXTURE_RECTANGLE, + 5 * unit_x, 5 * unit_y, draw_w, draw_h); - pass &= check_results(GL_FALSE, rgb_x, rgb_y, draw_w, draw_h); - pass &= check_results(GL_TRUE, rgba_x, rgba_y, draw_w, draw_h); + pass &= check_results(GL_FALSE, unit_x, unit_y, draw_w, draw_h); + pass &= check_results(GL_TRUE, 5 * unit_x, unit_y, draw_w, draw_h); + pass &= check_results(GL_FALSE, unit_x, 5 * unit_y, draw_w, draw_h); + pass &= check_results(GL_TRUE, 5 * unit_x, 5 * unit_y, draw_w, draw_h); glXSwapBuffers(dpy, win); @@ -201,7 +217,7 @@ set_pixel(Display *dpy, Picture picture, int x, int y, GLfloat *color) * Creates a Pixmap and GLXPixmap with tex_data as the contents. */ static GLXPixmap -create_pixmap(GLenum format) +create_pixmap(GLenum format, GLenum target) { static const int rgb_fb_config_attribs[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, @@ -223,17 +239,7 @@ create_pixmap(GLenum format) GLX_BIND_TO_TEXTURE_RGBA_EXT, 1, None }; - static const int rgb_pixmap_attribs[] = { - GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, - GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, - None - }; - static const int rgba_pixmap_attribs[] = { - GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, - GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT, - None - }; - static const int *fb_config_attribs, *pixmap_attribs; + const int *fb_config_attribs; GLXFBConfig *fb_configs; GLXFBConfig fb_config; int n_fb_configs; @@ -243,14 +249,25 @@ create_pixmap(GLenum format) XRenderPictFormat *render_format; Picture picture; + int pixmap_attribs[] = { + GLX_TEXTURE_TARGET_EXT, None, + GLX_TEXTURE_FORMAT_EXT, None, + None + }; + + if (target == GL_TEXTURE_2D) + pixmap_attribs[1] = GLX_TEXTURE_2D_EXT; + else + pixmap_attribs[1] = GLX_TEXTURE_RECTANGLE_EXT; + if (format == GL_RGBA) { fb_config_attribs = rgba_fb_config_attribs; - pixmap_attribs = rgba_pixmap_attribs; + pixmap_attribs[3] = GLX_TEXTURE_FORMAT_RGBA_EXT; render_format = XRenderFindStandardFormat(dpy, PictStandardARGB32); } else { fb_config_attribs = rgb_fb_config_attribs; - pixmap_attribs = rgb_pixmap_attribs; + pixmap_attribs[3] = GLX_TEXTURE_FORMAT_RGB_EXT; render_format = XRenderFindStandardFormat(dpy, PictStandardRGB24); } @@ -268,7 +285,7 @@ create_pixmap(GLenum format) fb_config = fb_configs[n_fb_configs - 1]; pixmap = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), - 2, 2, render_format->depth); + PIXMAP_WIDTH, PIXMAP_HEIGHT, render_format->depth); picture = XRenderCreatePicture(dpy, pixmap, render_format, 0, NULL); glx_pixmap = glXCreatePixmap(dpy, fb_config, pixmap, pixmap_attribs); @@ -290,8 +307,10 @@ static void init(void) { piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); - rgb_pixmap = create_pixmap(GL_RGB); - rgba_pixmap = create_pixmap(GL_RGBA); + rgb_2d_pixmap = create_pixmap(GL_RGB, GL_TEXTURE_2D); + rgba_2d_pixmap = create_pixmap(GL_RGBA, GL_TEXTURE_2D); + rgb_rect_pixmap = create_pixmap(GL_RGB, GL_TEXTURE_RECTANGLE); + rgba_rect_pixmap = create_pixmap(GL_RGBA, GL_TEXTURE_RECTANGLE); } int main(int argc, char**argv) @@ -346,9 +365,12 @@ int main(int argc, char**argv) init(); if (!piglit_automatic) { - printf("Left rectangle (RGB) should be green on the top and\n" - "red on the bottom. The right rectangle (RGBA) should\n" - "be the same, but darker on the right half.\n"); + printf("Left rectangles (RGB) should be green on the top and\n" + "red on the bottom. The right rectangles (RGBA) should\n" + "be the same, but darker on the right half. The top\n" + "rectangles are rendered with GL_TEXTURE_RECTANGLE while\n" + "the bottom are rendered with GL_TEXTURE_2D; they should\n" + "render the same\n"); printf("Press Escape to quit\n"); } -- 2.17.1