X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=cli%2Fsrc%2Fglxsimple.c;h=a4c9560dfb9e908b8d38ba8ca34486f08c67370c;hb=5efeef24814e1744e3c4f3109f82e700576439ab;hp=3c788c33ff132f0a4bea88e509d03028987ec88a;hpb=32cec36546fcd7899f6f92324e1f5166183bb058;p=apitrace-tests diff --git a/cli/src/glxsimple.c b/cli/src/glxsimple.c index 3c788c3..a4c9560 100644 --- a/cli/src/glxsimple.c +++ b/cli/src/glxsimple.c @@ -37,6 +37,37 @@ int width = 64; int height = 64; +static void +set_2d_projection (void) +{ + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + glOrtho (0, width, height, 0, 0, 1); + glMatrixMode (GL_MODELVIEW); +} + +static void +draw_fullscreen_quad (void) +{ + glBegin (GL_QUADS); + glVertex2f (0, 0); + glVertex2f (width, 0); + glVertex2f (width, height); + glVertex2f (0, height); + glEnd (); +} + +static void +draw_fullscreen_textured_quad (void) +{ + glBegin (GL_QUADS); + glTexCoord2f(0, 0); glVertex2f (0, 0); + glTexCoord2f(1, 0); glVertex2f (width, 0); + glTexCoord2f(1, 1); glVertex2f (width, height); + glTexCoord2f(0, 1); glVertex2f (0, height); + glEnd (); +} + static void paint_rgb_using_clear (double r, double g, double b) { @@ -82,25 +113,52 @@ paint_rgb_using_glsl (double r, double g, double b) glUniform4f (color, r, g, b, 1.0); - glMatrixMode (GL_PROJECTION); - glLoadIdentity (); - glOrtho (0, width, height, 0, 0, 1); - glMatrixMode (GL_MODELVIEW); - - glBegin (GL_QUADS); - glVertex2f (0, 0); - glVertex2f (width, 0); - glVertex2f (width, height); - glVertex2f (0, height); - glEnd (); + draw_fullscreen_quad (); glUseProgram (0); } +static GLuint +create_rgb_texture (double r, double g, double b) +{ + uint8_t data[3]; + GLuint texture = 0; + + data[0] = (uint8_t) (255.0 * r); + data[1] = (uint8_t) (255.0 * g); + data[2] = (uint8_t) (255.0 * b); + + glGenTextures (1, &texture); + + glBindTexture (GL_TEXTURE_2D, texture); + + glTexImage2D (GL_TEXTURE_2D, + 0, GL_COMPRESSED_RGBA, + 1, 1, 0, + GL_RGB, GL_UNSIGNED_BYTE, data); + + return texture; +} + +static void +paint_using_texture (GLuint texture) +{ + glBindTexture (GL_TEXTURE_2D, texture); + + glEnable (GL_TEXTURE_2D); + + draw_fullscreen_textured_quad (); + + glDisable (GL_TEXTURE_2D); +} + static void draw (Display *dpy, Window window, int width, int height) { +#define PASSES 2 + int i; GLenum glew_err; + GLuint texture[PASSES]; int visual_attr[] = { GLX_RGBA, @@ -130,13 +188,35 @@ draw (Display *dpy, Window window, int width, int height) glViewport(0, 0, width, height); - /* Frame 1: Draw a solid (magenta) frame using glClear. */ - paint_rgb_using_clear (1, 0, 1); - glXSwapBuffers (dpy, window); + set_2d_projection (); + +/* Simply count through some colors, frame by frame. */ +#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2) + + int frame = 0; + for (i = 0; i < PASSES; i++) { + + /* Frame: Draw a solid frame using glClear. */ + paint_rgb_using_clear (RGB(frame)); + glXSwapBuffers (dpy, window); + frame++; + + /* Frame: Draw a solid frame using GLSL. */ + paint_rgb_using_glsl (RGB(frame)); + glXSwapBuffers (dpy, window); + frame++; + + /* Frame: Draw a solid frame using a texture. */ + texture[i] = create_rgb_texture (RGB(frame)); + paint_using_texture (texture[i]); + glXSwapBuffers (dpy, window); + frame++; + } - /* Frame 2: Draw a solid (yellow) frame using GLSL. */ - paint_rgb_using_glsl (1, 1, 0); - glXSwapBuffers (dpy, window); + /* Draw another frame with a re-used texture. */ + paint_using_texture (texture[0]); + glXSwapBuffers (dpy, window); + frame++; /* Cleanup */ glXDestroyContext (dpy, ctx);