From 2a095b8f8bdd7bd6c6b84189829cb2babc8fa2d1 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 22 May 2004 09:15:28 +0000 Subject: [PATCH] use GL_RGB for non-transparent textures, and fix fonts not having transparent flag set (wouldn't get paletted) (d1x r1.15, r1.37, r1.40, r1.25) --- 2d/font.c | 26 +++------ ChangeLog | 5 ++ arch/ogl/gr.c | 11 ++-- arch/ogl/internal.h | 2 +- arch/ogl/ogl.c | 125 ++++++++++++++++++++++++++++++++++---------- include/ogl_init.h | 9 +++- 6 files changed, 124 insertions(+), 54 deletions(-) diff --git a/2d/font.c b/2d/font.c index c9a74ab2..c1a2b8db 100644 --- a/2d/font.c +++ b/2d/font.c @@ -1,4 +1,4 @@ -/* $Id: font.c,v 1.28 2004-05-22 08:10:26 btb Exp $ */ +/* $Id: font.c,v 1.29 2004-05-22 09:15:12 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -1196,6 +1196,7 @@ void ogl_font_choose_size(grs_font * font,int gap,int *rw,int *rh){ } void ogl_init_font(grs_font * font){ + int oglflags = OGL_FLAG_ALPHA; int nchars = font->ft_maxchar-font->ft_minchar+1; int i,w,h,tw,th,x,y,curx=0,cury=0; char *fp; @@ -1207,8 +1208,11 @@ void ogl_init_font(grs_font * font){ data=d_malloc(tw*th); memset(data, 0, tw * th); gr_init_bitmap(&font->ft_parent_bitmap,BM_LINEAR,0,0,tw,th,tw,data); + gr_set_transparent(&font->ft_parent_bitmap, 1); - font->ft_parent_bitmap.gltexture=ogl_get_free_texture(); + if (!(font->ft_flags & FT_COLOR)) + oglflags |= OGL_FLAG_NOCOLOR; + ogl_init_texture(font->ft_parent_bitmap.gltexture = ogl_get_free_texture(), tw, th, oglflags); // have to init the gltexture here so the subbitmaps will find it. font->ft_bitmaps=(grs_bitmap*)d_malloc( nchars * sizeof(grs_bitmap)); mprintf((0,"ogl_init_font %s, %s, nchars=%i, (%ix%i tex)\n",(font->ft_flags & FT_PROPORTIONAL)?"proportional":"fixedwidth",(font->ft_flags & FT_COLOR)?"color":"mono",nchars,tw,th)); @@ -1273,23 +1277,7 @@ void ogl_init_font(grs_font * font){ curx+=w+gap; } - if (!(font->ft_flags & FT_COLOR)) { - //use GL_INTENSITY instead of GL_RGB - if (ogl_intensity4_ok){ - font->ft_parent_bitmap.gltexture->internalformat=GL_INTENSITY4; - font->ft_parent_bitmap.gltexture->format=GL_LUMINANCE; - }else if (ogl_luminance4_alpha4_ok){ - font->ft_parent_bitmap.gltexture->internalformat=GL_LUMINANCE4_ALPHA4; - font->ft_parent_bitmap.gltexture->format=GL_LUMINANCE_ALPHA; - }else if (ogl_rgba2_ok){ - font->ft_parent_bitmap.gltexture->internalformat=GL_RGBA2; - font->ft_parent_bitmap.gltexture->format=GL_RGBA; - }else{ - font->ft_parent_bitmap.gltexture->internalformat=ogl_rgba_format; - font->ft_parent_bitmap.gltexture->format=GL_RGBA; - } - } - ogl_loadbmtexture_m(&font->ft_parent_bitmap,0); + ogl_loadbmtexture_f(&font->ft_parent_bitmap, oglflags); } int ogl_internal_string(int x, int y, char *s ) diff --git a/ChangeLog b/ChangeLog index e94b8db2..61f846b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2004-05-22 Matthew Mueller + * 2d/font.c, arch/ogl/gr.c, arch/ogl/internal.h, arch/ogl/ogl.c, + include/ogl_init.h: use GL_RGB for non-transparent textures, and + fix fonts not having transparent flag set (wouldn't get paletted) + (d1x r1.15, r1.37, r1.40, r1.25) + * arch/ogl/ogl.c: don't try to use paletted textures with mipmapping since gluBuild2DMipmaps can't handle it (d1x r1.39) diff --git a/arch/ogl/gr.c b/arch/ogl/gr.c index a5e32e5f..ac40869b 100644 --- a/arch/ogl/gr.c +++ b/arch/ogl/gr.c @@ -1,4 +1,4 @@ -/* $Id: gr.c,v 1.27 2004-05-22 08:42:59 btb Exp $ */ +/* $Id: gr.c,v 1.28 2004-05-22 09:15:15 btb Exp $ */ /* * * OGL video functions. - Added 9/15/99 Matthew Mueller @@ -422,9 +422,12 @@ int gr_init() if ((t=FindArg("-gl_stdtexmerge"))) if (t>=glt)//allow overriding of earlier args ogl_alttexmerge=0; - - if ((glt=FindArg("-gl_16bittextures"))) - ogl_rgba_format=GL_RGB5_A1; + + if ((glt = FindArg("-gl_16bittextures"))) + { + ogl_rgba_internalformat = GL_RGB5_A1; + ogl_rgb_internalformat = GL_RGB5; + } if ((glt=FindArg("-gl_mipmap"))){ GL_texmagfilt=GL_LINEAR; diff --git a/arch/ogl/internal.h b/arch/ogl/internal.h index 02c5ad7e..91f9d221 100644 --- a/arch/ogl/internal.h +++ b/arch/ogl/internal.h @@ -12,7 +12,7 @@ extern ogl_texture ogl_texture_list[OGL_TEXTURE_LIST_SIZE]; extern int ogl_mem_target; -void ogl_init_texture(ogl_texture* t); +void ogl_init_texture(ogl_texture* t, int w, int h, int flags); void ogl_init_texture_list_internal(void); void ogl_smash_texture_list_internal(void); void ogl_vivify_texture_list_internal(void); diff --git a/arch/ogl/ogl.c b/arch/ogl/ogl.c index dff9ef22..1d299e4f 100644 --- a/arch/ogl/ogl.c +++ b/arch/ogl/ogl.c @@ -1,4 +1,4 @@ -/* $Id: ogl.c,v 1.27 2004-05-22 08:47:14 btb Exp $ */ +/* $Id: ogl.c,v 1.28 2004-05-22 09:15:26 btb Exp $ */ /* * * Graphics support functions for OpenGL. @@ -77,7 +77,8 @@ int GL_texclamp_enabled=-1; extern int gr_badtexture; int r_texcount = 0, r_cachedtexcount = 0; int ogl_alttexmerge=1;//merge textures by just printing the seperate textures? -int ogl_rgba_format=4; +int ogl_rgba_internalformat = GL_RGBA8; +int ogl_rgb_internalformat = GL_RGB8; int ogl_intensity4_ok=1; int ogl_luminance4_alpha4_ok=1; int ogl_rgba2_ok=1; @@ -117,7 +118,7 @@ int ogl_texture_list_cur; #define OGLTEXBUFSIZE (2048*2048*4) extern GLubyte texbuf[OGLTEXBUFSIZE]; //void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int width,int height,int twidth,int theight); -void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int truewidth,int width,int height,int dxo,int dyo,int twidth,int theight,int type); +void ogl_filltexbuf(unsigned char *data, GLubyte *texp, int truewidth, int width, int height, int dxo, int dyo, int twidth, int theight, int type, int bm_flags); void ogl_loadbmtexture(grs_bitmap *bm); //void ogl_loadtexture(unsigned char * data, int width, int height,int dxo,intdyo , int *texid,float *u,float *v,char domipmap,float prio); void ogl_loadtexture(unsigned char *data, int dxo, int dyo, ogl_texture *tex, int bm_flags); @@ -129,15 +130,67 @@ void ogl_init_texture_stats(ogl_texture* t){ t->lastrend=0; t->numrend=0; } -void ogl_init_texture(ogl_texture* t){ - t->handle=0; - t->internalformat=ogl_rgba_format; - t->format=GL_RGBA; +void ogl_init_texture(ogl_texture* t, int w, int h, int flags) +{ + t->handle = 0; + if (flags & OGL_FLAG_NOCOLOR) + { + // use GL_INTENSITY instead of GL_RGB + if (flags & OGL_FLAG_ALPHA) + { + if (ogl_intensity4_ok) + { + t->internalformat = GL_INTENSITY4; + t->format = GL_LUMINANCE; + } + else if (ogl_luminance4_alpha4_ok) + { + t->internalformat = GL_LUMINANCE4_ALPHA4; + t->format = GL_LUMINANCE_ALPHA; + } + else if (ogl_rgba2_ok) + { + t->internalformat = GL_RGBA2; + t->format = GL_RGBA; + } + else + { + t->internalformat = ogl_rgba_internalformat; + t->format = GL_RGBA; + } + } + else + { + // there are certainly smaller formats we could use here, but nothing needs it ATM. + t->internalformat = ogl_rgb_internalformat; + t->format = GL_RGB; + } + } + else + { + if (flags & OGL_FLAG_ALPHA) + { + t->internalformat = ogl_rgba_internalformat; + t->format = GL_RGBA; + } + else + { + t->internalformat = ogl_rgb_internalformat; + t->format = GL_RGB; + } + } t->wrapstate[0] = -1; t->wrapstate[1] = -1; - t->w=t->h=0; + t->lw = t->w = w; + t->h = h; ogl_init_texture_stats(t); } + +void ogl_reset_texture(ogl_texture* t) +{ + ogl_init_texture(t, 0, 0, 0); +} + void ogl_reset_texture_stats_internal(void){ int i; for (i=0;iprio<0.499)prio2++; else if (t->prio<0.599)prio3++; else prioh++; + if (t->format == GL_RGBA) + usedrgba++; + else if (t->format == GL_RGB) + usedrgb++; + else if (t->format == GL_COLOR_INDEX) + usedidx++; + else + usedother++; } // else if(t->w!=0) // grabbed++; @@ -226,7 +288,7 @@ int ogl_texture_stats(void){ glGetIntegerv(GL_DEPTH_BITS, &depth); colorsize = (idx * res * dbl) / 8; depthsize = res * depth / 8; - gr_printf(5, GAME_FONT->ft_h * 14 + 3 * 14, "%i(%i,%i) %iK(%iK wasted) (%i postcachedtex)", used, usedrgba, usedl4a4, truebytes / 1024, (truebytes - databytes) / 1024, r_texcount - r_cachedtexcount); + gr_printf(5, GAME_FONT->ft_h * 14 + 3 * 14, "%i(%i,%i,%i,%i) %iK(%iK wasted) (%i postcachedtex)", used, usedrgba, usedrgb, usedidx, usedother, truebytes / 1024, (truebytes - databytes) / 1024, r_texcount - r_cachedtexcount); gr_printf(5, GAME_FONT->ft_h * 15 + 3 * 15, "%ibpp(r%i,g%i,b%i,a%i)x%i=%iK depth%i=%iK", idx, r, g, b, a, dbl, colorsize / 1024, depth, depthsize / 1024); gr_printf(5, GAME_FONT->ft_h * 16 + 3 * 16, "total=%iK", (colorsize + depthsize + truebytes) / 1024); } @@ -1108,9 +1170,8 @@ bool ogl_ubitblt_i(int dw,int dh,int dx,int dy, int sw, int sh, int sx, int sy, // unsigned char *oldpal; r_ubitbltc++; - ogl_init_texture(&tex); - tex.w=sw;tex.h=sh; - tex.prio=0.0;tex.wantmip=0; + ogl_init_texture(&tex, sw, sh, OGL_FLAG_ALPHA); + tex.prio = 0.0; tex.lw=src->bm_rowsize; /* if (w==src->bm_w && sx==0){ @@ -1416,7 +1477,7 @@ int pow2ize(int x){ //GLubyte texbuf[512*512*4]; GLubyte texbuf[OGLTEXBUFSIZE]; -void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int truewidth,int width,int height,int dxo,int dyo,int twidth,int theight,int type) +void ogl_filltexbuf(unsigned char *data, GLubyte *texp, int truewidth, int width, int height, int dxo, int dyo, int twidth, int theight, int type, int bm_flags) { // GLushort *tex=(GLushort *)texp; int x,y,c,i; @@ -1430,8 +1491,9 @@ void ogl_filltexbuf(unsigned char *data,GLubyte *texp,int truewidth,int width,in if (xinternalformat=ogl_rgba_format; + tex->internalformat = ogl_rgba_internalformat; tex->format=GL_RGBA; break; default: @@ -1559,6 +1631,7 @@ void tex_set_size(ogl_texture *tex){ case GL_LUMINANCE_ALPHA: bi=8; break; + case GL_RGB: case GL_RGBA: bi=16; break; @@ -1598,7 +1671,7 @@ void ogl_loadtexture(unsigned char *data, int dxo, int dyo, ogl_texture *tex, in tex->v=(float)tex->h/(float)tex->th; #ifdef GL_EXT_paletted_texture - if (ogl_shared_palette_ok && tex->format == GL_RGBA && + if (ogl_shared_palette_ok && (tex->format == GL_RGBA || tex->format == GL_RGB) && !(tex->wantmip && GL_needmipmaps) // gluBuild2DMipmaps doesn't support paletted textures.. this could be worked around be generating our own mipmaps, but thats too much trouble at the moment. ) { @@ -1626,7 +1699,7 @@ void ogl_loadtexture(unsigned char *data, int dxo, int dyo, ogl_texture *tex, in // if (width!=twidth || height!=theight) // glmprintf((0,"sizing %ix%i texture up to %ix%i\n",width,height,twidth,theight)); - ogl_filltexbuf(data,texbuf,tex->lw,tex->w,tex->h,dxo,dyo,tex->tw,tex->th,tex->format); + ogl_filltexbuf(data, texbuf, tex->lw, tex->w, tex->h, dxo, dyo, tex->tw, tex->th, tex->format, bm_flags); // Generate OpenGL texture IDs. glGenTextures(1, &tex->handle); @@ -1671,18 +1744,14 @@ void ogl_loadtexture(unsigned char *data, int dxo, int dyo, ogl_texture *tex, in unsigned char decodebuf[512*512]; -void ogl_loadbmtexture_m(grs_bitmap *bm,int domipmap) +void ogl_loadbmtexture_f(grs_bitmap *bm, int flags) { unsigned char *buf; while (bm->bm_parent) bm=bm->bm_parent; buf=bm->bm_data; if (bm->gltexture==NULL){ - ogl_init_texture(bm->gltexture=ogl_get_free_texture()); - bm->gltexture->lw=bm->bm_w; - bm->gltexture->w=bm->bm_w; - bm->gltexture->h=bm->bm_h; - bm->gltexture->wantmip=domipmap; + ogl_init_texture(bm->gltexture = ogl_get_free_texture(), bm->bm_w, bm->bm_h, flags | ((bm->bm_flags & BM_FLAG_TRANSPARENT) ? OGL_FLAG_ALPHA : 0)); } else { if (bm->gltexture->handle>0) @@ -1720,7 +1789,7 @@ void ogl_loadbmtexture_m(grs_bitmap *bm,int domipmap) void ogl_loadbmtexture(grs_bitmap *bm) { - ogl_loadbmtexture_m(bm,1); + ogl_loadbmtexture_f(bm, OGL_FLAG_MIPMAP); } void ogl_freetexture(ogl_texture *gltexture) @@ -1730,7 +1799,7 @@ void ogl_freetexture(ogl_texture *gltexture) glmprintf((0,"ogl_freetexture(%p):%i (last rend %is) (%i left)\n",gltexture,gltexture->handle,(GameTime-gltexture->lastrend)/f1_0,r_texcount)); glDeleteTextures( 1, &gltexture->handle ); // gltexture->handle=0; - ogl_init_texture(gltexture); + ogl_reset_texture(gltexture); } } void ogl_freebmtexture(grs_bitmap *bm){ diff --git a/include/ogl_init.h b/include/ogl_init.h index 2d506e2e..c6b6fa17 100644 --- a/include/ogl_init.h +++ b/include/ogl_init.h @@ -61,7 +61,8 @@ typedef struct _ogl_texture { extern ogl_texture* ogl_get_free_texture(); extern int ogl_alttexmerge;//merge textures by just printing the seperate textures? -extern int ogl_rgba_format; +extern int ogl_rgba_internalformat; +extern int ogl_rgb_internalformat; extern int ogl_setgammaramp_ok; extern int ogl_intensity4_ok; extern int ogl_luminance4_alpha4_ok; @@ -131,7 +132,11 @@ void ogl_destroy_window(void);//destroy window/etc void ogl_init(void);//one time initialization void ogl_close(void);//one time shutdown -void ogl_loadbmtexture_m(grs_bitmap *bm,int domipmap); + +#define OGL_FLAG_MIPMAP (1 << 0) +#define OGL_FLAG_NOCOLOR (1 << 1) +#define OGL_FLAG_ALPHA (1 << 31) // not required for ogl_loadbmtexture, since it uses the BM_FLAG_TRANSPARENT, but is needed for ogl_init_texture. +void ogl_loadbmtexture_f(grs_bitmap *bm, int flags); void ogl_freebmtexture(grs_bitmap *bm); void ogl_start_offscreen_render(int x, int y, int w, int h); -- 2.39.2