From e2a8de33cc383f05c350a4b36b7c164e337e3a71 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 26 Dec 2011 18:34:51 +0900 Subject: [PATCH] First real texture support function for glsl. --- include/QF/GLSL/qf_textures.h | 23 +-------- libs/video/renderer/glsl/Makefile.am | 6 +-- libs/video/renderer/glsl/glsl_draw.c | 13 +---- libs/video/renderer/glsl/glsl_textures.c | 64 ++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 libs/video/renderer/glsl/glsl_textures.c diff --git a/include/QF/GLSL/qf_textures.h b/include/QF/GLSL/qf_textures.h index 917996975..a713ec122 100644 --- a/include/QF/GLSL/qf_textures.h +++ b/include/QF/GLSL/qf_textures.h @@ -31,28 +31,9 @@ #include "QF/qtypes.h" -#define MAX_GLTEXTURES 2048 - -extern int gl_alpha_format; -extern int gl_solid_format; -extern int gl_lightmap_format; -extern int gl_filter_min; -extern int gl_filter_max; -extern qboolean Anisotropy; -extern float aniso; -extern int part_tex; -/* -extern int part_tex_dot; -extern int part_tex_smoke; -extern int part_tex_spark; -*/ - -void GL_Upload8 (byte *data, int width, int height, qboolean mipmap, qboolean alpha); -void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboolean alpha); +int GL_LoadQuakeTexture (const char *identifier, int width, int height, + byte *data); int GL_LoadTexture (const char *identifier, int width, int height, byte *data, qboolean mipmap, qboolean alpha, int bytesperpixel); -int GL_FindTexture (const char *identifier); - -void GL_TextureMode_f (void); void GDT_Init (void); diff --git a/libs/video/renderer/glsl/Makefile.am b/libs/video/renderer/glsl/Makefile.am index 40cdc9b51..7bfbf1e77 100644 --- a/libs/video/renderer/glsl/Makefile.am +++ b/libs/video/renderer/glsl/Makefile.am @@ -5,6 +5,9 @@ INCLUDES= -I$(top_srcdir)/include $(GLX_CFLAGS) shader_src= quake2d.frag quaketxt.vert shader_gen= quake2d.fc quaketxt.vc +glsl_src = \ + glsl_draw.c glsl_main.c glsl_particles.c glsl_screen.c glsl_textures.c + if BUILD_GL noinst_LTLIBRARIES= libglsl.la BUILT_SOURCES= $(shader_gen) @@ -19,9 +22,6 @@ SUFFICES=.frag .vert .fc .vc .vert.vc: sed -e 's/^/"/' -e 's/$$/\\n"/' $< > $@ -glsl_src = \ - glsl_draw.c glsl_main.c glsl_particles.c glsl_screen.c - libglsl_la_SOURCES= $(glsl_src) EXTRA_DIST = $(glsl_src) $(shader_src) diff --git a/libs/video/renderer/glsl/glsl_draw.c b/libs/video/renderer/glsl/glsl_draw.c index 9585b948e..049504e59 100644 --- a/libs/video/renderer/glsl/glsl_draw.c +++ b/libs/video/renderer/glsl/glsl_draw.c @@ -40,6 +40,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "QF/GLSL/defines.h" #include "QF/GLSL/funcs.h" +#include "QF/GLSL/qf_textures.h" #include "QF/GLSL/qf_vid.h" #include "gl_draw.h" @@ -95,7 +96,6 @@ Draw_TextBox (int x, int y, int width, int lines, byte alpha) VISIBLE void Draw_Init (void) { - GLuint tnum; int i; int frag, vert; @@ -114,16 +114,7 @@ Draw_Init (void) if (draw_chars[i] == 0) draw_chars[i] = 255; // proper transparent color - qfglGenTextures (1, &tnum); - char_texture = tnum; - qfglBindTexture (GL_TEXTURE_2D, char_texture); - qfglTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, - 128, 128, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, draw_chars); - qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - qfglGenerateMipmap (GL_TEXTURE_2D); + char_texture = GL_LoadQuakeTexture ("conchars", 128, 128, draw_chars); } static inline void diff --git a/libs/video/renderer/glsl/glsl_textures.c b/libs/video/renderer/glsl/glsl_textures.c new file mode 100644 index 000000000..f734e87c7 --- /dev/null +++ b/libs/video/renderer/glsl/glsl_textures.c @@ -0,0 +1,64 @@ +/* + glsl_textures.c + + Texture format setup. + + Copyright (C) 1996-1997 Id Software, Inc. + Copyright (C) 2001 Ragnvald Maartmann-Moe IV + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +static __attribute__ ((used)) const char rcsid[] = + "$Id$"; + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif + +#include + +#include "QF/GLSL/defines.h" +#include "QF/GLSL/funcs.h" +#include "QF/GLSL/qf_textures.h" + +int +GL_LoadQuakeTexture (const char *identifier, int width, int height, byte *data) +{ + GLuint tnum; + + qfglGenTextures (1, &tnum); + qfglBindTexture (GL_TEXTURE_2D, tnum); + qfglTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, + width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + qfglGenerateMipmap (GL_TEXTURE_2D); + + return tnum; +}