summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2008-12-17 17:05:20 -0800
committerIan Romanick <ian.d.romanick@intel.com>2008-12-17 17:05:20 -0800
commit85e8a8a2006cbcabadfc52784c561a6b334ccaa5 (patch)
tree3c69309253f3bbc52b636043787d2592893ddd85 /tests
parent2dba2fde852af95a504e0ea62b41d4406be2037b (diff)
Test NPOT and rectangle textures
Diffstat (limited to 'tests')
-rw-r--r--tests/texturing/copytexsubimage.c151
1 files changed, 120 insertions, 31 deletions
diff --git a/tests/texturing/copytexsubimage.c b/tests/texturing/copytexsubimage.c
index 7daafca36..83d3b1645 100644
--- a/tests/texturing/copytexsubimage.c
+++ b/tests/texturing/copytexsubimage.c
@@ -25,7 +25,7 @@
*
*/
-#include "GL/glut.h"
+#include <GL/glut.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@@ -35,6 +35,12 @@
static GLboolean Automatic = GL_FALSE;
+/** Should GL_TEXTURE_RECTANGLE_ARB be tested? */
+int have_rect = 0;
+
+/** Should non-power-of-two textures be tested? */
+int have_NPOT = 0;
+
static void rect(int x1, int y1, int x2, int y2)
{
glBegin(GL_POLYGON);
@@ -98,16 +104,26 @@ check_results(int dstx, int dsty, int w, int h)
return pass;
}
-static void display()
+static GLboolean
+do_row(int srcy, int srcw, int srch, GLenum target)
{
- int srcx = 20, srcy = 20, srcw = 32, srch = 32;
- int dstx = 80, dsty = 20;
- int dstx2 = 140, dsty2 = 20;
- int texname, x, y;
+ int srcx = 20;
+ int dstx = 80, dsty = srcy;
+ int dstx2 = 140, dsty2 = srcy;
+ int remain_width;
+ int remain_height;
+ GLuint texname;
GLboolean pass = GL_TRUE;
- glClearColor(0.5, 0.5, 0.5, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
+ /* Rectangle textures use coordinates on the range [0..w]x[0..h],
+ * where as all other textures use coordinates on the range
+ * [0..1]x[0..1].
+ */
+ const GLfloat tex_s_max = (target == GL_TEXTURE_RECTANGLE_ARB)
+ ? (float)srcw : 1.0;
+ const GLfloat tex_t_max = (target == GL_TEXTURE_RECTANGLE_ARB)
+ ? (float)srch : 1.0;
+
/* Draw the object we're going to copy */
glColor3f(1.0, 0.0, 0.0);
@@ -119,59 +135,121 @@ static void display()
/* Create a texture image and copy it in */
glGenTextures(1, &texname);
- glBindTexture(GL_TEXTURE_2D, texname);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glBindTexture(target, texname);
+ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ /* The default mode is GL_REPEAT, and this mode is invalid for
+ * GL_TEXTURE_RECTANGLE_ARB textures.
+ */
+ glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glEnable(GL_TEXTURE_2D);
+ glEnable(target);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, srcw, srch, 0,
+ glTexImage2D(target, 0, GL_RGBA8, srcw, srch, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
+ glCopyTexSubImage2D(target, 0,
0, 0, /* offset in image */
srcx, srcy, /* offset in readbuffer */
srcw, srch);
/* Draw the texture image out */
glBegin(GL_POLYGON);
- glTexCoord2f(0.0, 0.0); glVertex2f(dstx, dsty);
- glTexCoord2f(0.0, 1.0); glVertex2f(dstx, dsty + srch);
- glTexCoord2f(1.0, 1.0); glVertex2f(dstx + srcw, dsty + srch);
- glTexCoord2f(1.0, 0.0); glVertex2f(dstx + srcw, dsty);
+ glTexCoord2f(0.0, 0.0);
+ glVertex2f(dstx, dsty);
+
+ glTexCoord2f(0.0, tex_t_max);
+ glVertex2f(dstx, dsty + srch);
+
+ glTexCoord2f(tex_s_max, tex_t_max);
+ glVertex2f(dstx + srcw, dsty + srch);
+
+ glTexCoord2f(tex_s_max, 0.0);
+ glVertex2f(dstx + srcw, dsty);
glEnd();
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, srcw, srch, 0,
+ glTexImage2D(target, 0, GL_RGBA8, srcw, srch, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
+
+ remain_width = srcw - (srcw / 2);
+ remain_height = srch - (srch / 2);
+ glCopyTexSubImage2D(target, 0,
0, 0, /* offset in image */
srcx, srcy, /* offset in readbuffer */
srcw / 2, srch / 2);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
+ glCopyTexSubImage2D(target, 0,
srcw / 2, 0, /* offset in image */
srcx + srcw / 2, srcy, /* offset in readbuffer */
- srcw / 2, srch / 2);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
+ remain_width, srch / 2);
+ glCopyTexSubImage2D(target, 0,
0, srch / 2, /* offset in image */
srcx, srcy + srch / 2, /* offset in readbuffer */
- srcw / 2, srch / 2);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
+ srcw / 2, remain_height);
+ glCopyTexSubImage2D(target, 0,
srcw / 2, srch / 2, /* offset in image */
srcx + srcw / 2, srcy + srch / 2, /* offset in readbuffer */
- srcw / 2, srch / 2);
+ remain_width, remain_height);
/* Draw the texture image out */
glBegin(GL_POLYGON);
- glTexCoord2f(0.0, 0.0); glVertex2f(dstx2, dsty2);
- glTexCoord2f(0.0, 1.0); glVertex2f(dstx2, dsty2 + srch);
- glTexCoord2f(1.0, 1.0); glVertex2f(dstx2 + srcw, dsty2 + srch);
- glTexCoord2f(1.0, 0.0); glVertex2f(dstx2 + srcw, dsty2);
+ glTexCoord2f(0.0, 0.0);
+ glVertex2f(dstx2, dsty2);
+
+ glTexCoord2f(0.0, tex_t_max);
+ glVertex2f(dstx2, dsty2 + srch);
+
+ glTexCoord2f(tex_s_max, tex_t_max);
+ glVertex2f(dstx2 + srcw, dsty2 + srch);
+
+ glTexCoord2f(tex_s_max, 0.0);
+ glVertex2f(dstx2 + srcw, dsty2);
glEnd();
- glDisable(GL_TEXTURE_2D);
+ glDisable(target);
glDeleteTextures(1, &texname);
pass &= check_results(dstx, dsty, srcw, srch);
pass &= check_results(dstx2, dsty2, srcw, srch);
+ return pass;
+}
+
+
+static void display()
+{
+ GLboolean pass;
+ int srcy = 5;
+
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+
+ /* Test plain old 2D textures.
+ */
+ pass = do_row(srcy, 32, 32, GL_TEXTURE_2D);
+ srcy += 33 + 5;
+
+
+ /* Test non-power-of-two 2D textures.
+ */
+ if (have_NPOT) {
+ pass &= do_row(srcy, 31, 13, GL_TEXTURE_2D);
+ srcy += 15;
+ pass &= do_row(srcy, 11, 34, GL_TEXTURE_2D);
+ srcy += 35 + 5;
+ }
+
+
+ /* Test non-power-of-two 2D textures.
+ */
+ if (have_rect) {
+ pass &= do_row(srcy, 31, 13, GL_TEXTURE_RECTANGLE_ARB);
+ srcy += 14;
+ pass &= do_row(srcy, 11, 34, GL_TEXTURE_RECTANGLE_ARB);
+ srcy += 35 + 5;
+ }
+
if (Automatic) {
printf("PIGLIT: {'result': '%s' }\n",
pass ? "pass" : "fail");
@@ -191,6 +269,15 @@ static void init()
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
+
+ glClearColor(0.5, 0.5, 0.5, 1.0);
+
+ have_NPOT = ((atof((const char *) glGetString(GL_VERSION)) >= 2.0)
+ || (glutExtensionSupported("GL_ARB_texture_non_power_of_two")));
+
+ have_rect = ((glutExtensionSupported("GL_ARB_texture_rectangle"))
+ || (glutExtensionSupported("GL_EXT_texture_rectangle"))
+ || (glutExtensionSupported("GL_NV_texture_rectangle")));
}
int main(int argc, char**argv)
@@ -205,4 +292,6 @@ int main(int argc, char**argv)
init();
glutDisplayFunc(display);
glutMainLoop();
+
+ return 0;
}