From 9288fa432d4884a825ad538ead465481b7a6ee33 Mon Sep 17 00:00:00 2001 From: Oliver McFadden Date: Sun, 23 Sep 2007 23:18:25 +0000 Subject: Added a GL_TEXTURE_MIN_FILTER test. --- src/Makefile.am | 2 + src/Makefile.in | 8 +++- src/gl_texture.c | 2 +- src/gl_texture_min_filter.c | 110 ++++++++++++++++++++++++++++++++++++++++++++ src/gl_texture_min_filter.h | 28 +++++++++++ src/test.c | 2 + 6 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 src/gl_texture_min_filter.c create mode 100644 src/gl_texture_min_filter.h diff --git a/src/Makefile.am b/src/Makefile.am index 93a0bd2..4f1a6e9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,8 @@ revenge_SOURCES = \ gl_shade_model.h \ gl_texture.c \ gl_texture.h \ + gl_texture_min_filter.c \ + gl_texture_min_filter.h \ main.c \ main.h \ memory.c \ diff --git a/src/Makefile.in b/src/Makefile.in index 632d54f..a9db4f3 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -53,8 +53,9 @@ am_revenge_OBJECTS = detect.$(OBJEXT) dump.$(OBJEXT) \ gl_null.$(OBJEXT) gl_point_size.$(OBJEXT) \ gl_primitives.$(OBJEXT) gl_render_mode.$(OBJEXT) \ gl_scissor_test.$(OBJEXT) gl_shade_model.$(OBJEXT) \ - gl_texture.$(OBJEXT) main.$(OBJEXT) memory.$(OBJEXT) \ - register.$(OBJEXT) test.$(OBJEXT) + gl_texture.$(OBJEXT) gl_texture_min_filter.$(OBJEXT) \ + main.$(OBJEXT) memory.$(OBJEXT) register.$(OBJEXT) \ + test.$(OBJEXT) revenge_OBJECTS = $(am_revenge_OBJECTS) revenge_LDADD = $(LDADD) DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@ @@ -199,6 +200,8 @@ revenge_SOURCES = \ gl_shade_model.h \ gl_texture.c \ gl_texture.h \ + gl_texture_min_filter.c \ + gl_texture_min_filter.h \ main.c \ main.h \ memory.c \ @@ -296,6 +299,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_scissor_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_shade_model.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_texture.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_texture_min_filter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/register.Po@am__quote@ diff --git a/src/gl_texture.c b/src/gl_texture.c index 62a4f3d..8296f72 100644 --- a/src/gl_texture.c +++ b/src/gl_texture.c @@ -30,7 +30,7 @@ #define TEXTURE_WIDTH 16 #define TEXTURE_HEIGHT 16 -GLuint * +static GLuint * random_texture (int width, int height) { GLuint *texture = NULL; diff --git a/src/gl_texture_min_filter.c b/src/gl_texture_min_filter.c new file mode 100644 index 0000000..4b13a49 --- /dev/null +++ b/src/gl_texture_min_filter.c @@ -0,0 +1,110 @@ +/* + * $Id$ + * Copyright (C) 2007 Oliver McFadden + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef struct +{ + unsigned int id; + char *name; +} data_store; + +#define N_(name) name, # name + +#define TEXTURE_WIDTH 16 +#define TEXTURE_HEIGHT 16 + +static GLuint * +random_texture (int width, int height) +{ + GLuint *texture = NULL; + int i; + + if (!(texture = (GLuint *) malloc (width * height * sizeof (GLuint)))) + { + fprintf (stderr, "%s: %s\n", program_invocation_short_name, + strerror (errno)); + return NULL; + } + + for (i = 0; i < width * height; i++) + { + texture[i] = random (); + } + + return texture; +} + +void +gl_texture_min_filter (void) +{ + data_store texture_min_filter[] = { + {N_(GL_NEAREST)}, + {N_(GL_LINEAR)}, + {N_(GL_NEAREST_MIPMAP_NEAREST)}, + {N_(GL_LINEAR_MIPMAP_NEAREST)}, + {N_(GL_NEAREST_MIPMAP_LINEAR)}, + {N_(GL_LINEAR_MIPMAP_LINEAR)}, + }; + + GLuint *texture = NULL;; + GLuint texName; + int i; + + if (!(texture = random_texture (TEXTURE_WIDTH, TEXTURE_HEIGHT))) + { + return; + } + + for (i = 0; + i < sizeof (texture_min_filter) / sizeof (texture_min_filter[0]); i++) + { + test_prologue (texture_min_filter[i].name); + + glEnable (GL_TEXTURE_2D); + + glGenTextures (1, &texName); + glBindTexture (GL_TEXTURE_2D, texName); + + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + texture_min_filter[i].id); + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, TEXTURE_WIDTH, TEXTURE_HEIGHT, + 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); + + tex_tri (); + + glDisable (GL_TEXTURE_2D); + + test_epilogue (true); + } + + free (texture); +} diff --git a/src/gl_texture_min_filter.h b/src/gl_texture_min_filter.h new file mode 100644 index 0000000..ece68fb --- /dev/null +++ b/src/gl_texture_min_filter.h @@ -0,0 +1,28 @@ +/* + * $Id$ + * Copyright (C) 2007 Oliver McFadden + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __GL_TEXTURE_MIN_FILTER_H__ +#define __GL_TEXTURE_MIN_FILTER_H__ + +#include +#include + +void gl_texture_min_filter (void); + +#endif diff --git a/src/test.c b/src/test.c index 40c3a37..a58b788 100644 --- a/src/test.c +++ b/src/test.c @@ -53,6 +53,7 @@ #include #include #include +#include void tri (void) @@ -161,6 +162,7 @@ static struct test_t tests[] = { {_(gl_scissor_test)}, {_(gl_shade_model)}, {_(gl_texture)}, + {_(gl_texture_min_filter)}, }; #undef _ -- cgit v1.2.3