The previous glxsimple program was too simple as each frame was
entirely self-contained, (textures were created, initialized, and
referenced only within single frames).
For more realistic trimming, we create and initialize a texture in one
frame, then reference that texture in a later frame. This is a better
test to ensure that when trimming the first frame the texture creation
and initialization is not discarded.
-static void
-paint_rgb_using_texture (double r, double g, double b)
+static GLuint
+create_rgb_texture (double r, double g, double b)
data[0] = (uint8_t) (255.0 * r);
data[1] = (uint8_t) (255.0 * g);
data[0] = (uint8_t) (255.0 * r);
data[1] = (uint8_t) (255.0 * g);
1, 1, 0,
GL_RGB, GL_UNSIGNED_BYTE, data);
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 ();
glEnable (GL_TEXTURE_2D);
draw_fullscreen_textured_quad ();
static void
draw (Display *dpy, Window window, int width, int height)
{
static void
draw (Display *dpy, Window window, int width, int height)
{
+ GLuint texture[PASSES];
int visual_attr[] = {
GLX_RGBA,
int visual_attr[] = {
GLX_RGBA,
#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
int frame = 0;
#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
int frame = 0;
- for (i = 0; i < 2; i++) {
- /* Frame: Draw a solid (magenta) frame using glClear. */
+ for (i = 0; i < PASSES; i++) {
+
+ /* Frame: Draw a solid frame using glClear. */
paint_rgb_using_clear (RGB(frame));
glXSwapBuffers (dpy, window);
frame++;
paint_rgb_using_clear (RGB(frame));
glXSwapBuffers (dpy, window);
frame++;
- /* Frame: Draw a solid (yellow) frame using GLSL. */
+ /* Frame: Draw a solid frame using GLSL. */
paint_rgb_using_glsl (RGB(frame));
glXSwapBuffers (dpy, window);
frame++;
paint_rgb_using_glsl (RGB(frame));
glXSwapBuffers (dpy, window);
frame++;
- /* Frame: Draw a solid (cyan) frame using a texture. */
- paint_rgb_using_texture (RGB(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++;
}
glXSwapBuffers (dpy, window);
frame++;
}
+ /* Draw another frame with a re-used texture. */
+ paint_using_texture (texture[0]);
+ glXSwapBuffers (dpy, window);
+ frame++;
+
/* Cleanup */
glXDestroyContext (dpy, ctx);
}
/* Cleanup */
glXDestroyContext (dpy, ctx);
}