opengl hardware super-transparency support using GL_NV_register_combiners (d1x r1...
authorBradley Bell <btb@icculus.org>
Sat, 22 May 2004 21:48:48 +0000 (21:48 +0000)
committerBradley Bell <btb@icculus.org>
Sat, 22 May 2004 21:48:48 +0000 (21:48 +0000)
ChangeLog
arch/ogl/gr.c
arch/ogl/ogl.c
include/loadgl.h
include/ogl_init.h
main/render.c

index 3041ac5..e4d1b0b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-05-22  Matthew Mueller  <donut@dakotacom.net>
+
+       * arch/ogl/gr.c, arch/ogl/ogl.c, include/loadgl.h,
+       include/ogl_init.h, main/render.c: opengl hardware
+       super-transparency support using GL_NV_register_combiners (d1x
+       r1.38, r1.41, r1.6, r1.26, r1.7)
+
 2004-05-22  Bradley Bell  <btb@icculus.org>
 
        * arch/ogl/internal.h, include/gr.h, include/ogl_init.h: function
index ac40869..57f9db5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gr.c,v 1.28 2004-05-22 09:15:15 btb Exp $ */
+/* $Id: gr.c,v 1.29 2004-05-22 21:48:33 btb Exp $ */
 /*
  *
  * OGL video functions. - Added 9/15/99 Matthew Mueller
@@ -162,7 +162,7 @@ const char *gl_vendor,*gl_renderer,*gl_version,*gl_extensions;
 
 void ogl_get_verinfo(void)
 {
-       int t, arb_max_textures = -1, sgi_max_textures = -1;
+       int t, arb_max_textures = -1, sgi_max_textures = -1, nv_register_combiners = -1;
        float anisotropic_max = 0;
 
        gl_vendor=glGetString(GL_VENDOR);
@@ -184,6 +184,9 @@ void ogl_get_verinfo(void)
        dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
        dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
        dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
+       dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
+       dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
+       dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
 #endif
 
 #ifdef GL_ARB_multitexture
@@ -195,6 +198,9 @@ void ogl_get_verinfo(void)
        mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
 #endif
        ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
+#ifdef GL_NV_register_combiners
+       ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
+#endif
 
        ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
        if (ogl_ext_texture_filter_anisotropic_ok)
@@ -232,6 +238,14 @@ void ogl_get_verinfo(void)
        if (ogl_sgis_multitexture_ok)
                glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
 #endif
+#ifdef GL_NV_register_combiners
+       if ((t = FindArg("-gl_nv_register_combiners_ok")))
+       {
+               ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
+       }
+       if (ogl_nv_register_combiners_ok)
+               glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
+#endif
 #ifdef GL_EXT_paletted_texture
        if ((t = FindArg("-gl_paletted_texture_ok")))
        {
@@ -264,7 +278,7 @@ void ogl_get_verinfo(void)
                ogl_setgammaramp_ok = atoi(Args[t + 1]);
        }
 
-       con_printf(CON_VERBOSE, "gl_arb_multitexture:%i(%i units) gl_sgis_multitexture:%i(%i units) gl_nv_texture_env_combine4:%i\n", ogl_arb_multitexture_ok, arb_max_textures, ogl_sgis_multitexture_ok, sgi_max_textures, ogl_nv_texture_env_combine4_ok);
+       con_printf(CON_VERBOSE, "gl_arb_multitexture:%i(%i units) gl_sgis_multitexture:%i(%i units) gl_nv_texture_env_combine4:%i gl_nv_register_combiners:%i(%i stages)\n", ogl_arb_multitexture_ok, arb_max_textures, ogl_sgis_multitexture_ok, sgi_max_textures, ogl_nv_texture_env_combine4_ok, 0/*ogl_nv_register_combiners_ok*/, nv_register_combiners);
        con_printf(CON_VERBOSE, "gl_intensity4:%i gl_luminance4_alpha4:%i gl_rgba2:%i gl_readpixels:%i gl_gettexlevelparam:%i gl_setgammaramp_ok:%i gl_ext_texture_filter_anisotropic:%i(%f max)\n", ogl_intensity4_ok, ogl_luminance4_alpha4_ok, ogl_rgba2_ok, ogl_readpixels_ok, ogl_gettexlevelparam_ok, ogl_setgammaramp_ok, ogl_ext_texture_filter_anisotropic_ok, anisotropic_max);
 }
 
index 1d299e4..5047dae 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ogl.c,v 1.28 2004-05-22 09:15:26 btb Exp $ */
+/* $Id: ogl.c,v 1.29 2004-05-22 21:48:36 btb Exp $ */
 /*
  *
  * Graphics support functions for OpenGL.
@@ -91,6 +91,9 @@ int ogl_arb_multitexture_ok=0;
 int ogl_sgis_multitexture_ok=0;
 #endif
 int ogl_nv_texture_env_combine4_ok = 0;
+#ifdef GL_NV_register_combiners
+int ogl_nv_register_combiners_ok = 0;
+#endif
 int ogl_ext_texture_filter_anisotropic_ok = 0;
 #ifdef GL_EXT_paletted_texture
 int ogl_shared_palette_ok = 0;
@@ -446,7 +449,7 @@ void ogl_cache_level_textures(void)
                                if (tmap2 != 0){
                                        PIGGY_PAGE_IN(Textures[tmap2&0x3FFF]);
                                        bm2 = &GameBitmaps[Textures[tmap2&0x3FFF].index];
-                                       if (ogl_alttexmerge==0 || (bm2->bm_flags & BM_FLAG_SUPER_TRANSPARENT))
+                                       if (ogl_alttexmerge == 0 || (!OGL_SUPER_TRANSPARENT_OK && (bm2->bm_flags & BM_FLAG_SUPER_TRANSPARENT)))
                                                bm = texmerge_get_cached_bitmap( tmap1, tmap2 );
                                        else {
                                                ogl_loadbmtexture(bm2);
@@ -849,8 +852,8 @@ void ogl_MultiTexCoord2f(int t, float u, float v)
 
 bool g3_draw_tmap_2(int nv, g3s_point **pointlist, g3s_uvl *uvl_list, grs_bitmap *bmbot, grs_bitmap *bm, int orient)
 {
-#if (defined(GL_NV_texture_env_combine4) && (defined(GL_ARB_multitexture) || defined(GL_SGIS_multitexture)))
-       if (ogl_nv_texture_env_combine4_ok && (ogl_arb_multitexture_ok || ogl_sgis_multitexture_ok))
+#if ((defined(GL_NV_register_combiners) || defined(GL_NV_texture_env_combine4)) && (defined(GL_ARB_multitexture) || defined(GL_SGIS_multitexture)))
+       if ((/*ogl_nv_register_combiners_ok ||*/ ogl_nv_texture_env_combine4_ok) && (ogl_arb_multitexture_ok || ogl_sgis_multitexture_ok))
        {
                int c;
                float l, u1, v1;
@@ -871,39 +874,102 @@ bool g3_draw_tmap_2(int nv, g3s_point **pointlist, g3s_uvl *uvl_list, grs_bitmap
                ogl_bindbmtex(bm);
                ogl_texwrap(bm->gltexture,GL_REPEAT);
 
+#ifdef GL_NV_register_combiners
+               if (ogl_nv_register_combiners_ok)
+               {
+                       glEnable(GL_REGISTER_COMBINERS_NV);
+                       glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 1);
+                       // spare0 = tex0 * (1-alpha1) + tex1 * alpha1
+                       glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
+                       glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
+                       glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
+                       glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
+                       glCombinerOutputNV(
+                                          GL_COMBINER0_NV,   //GLenum stage
+                                          GL_RGB,            //GLenum portion,
+                                          GL_DISCARD_NV,     //GLenum abOutput,
+                                          GL_DISCARD_NV,     //GLenum cdOutput,
+                                          GL_SPARE0_NV,      //GLenum sumOutput,
+                                          GL_NONE,           //GLenum scale,
+                                          GL_NONE,           //GLenum bias,
+                                          GL_FALSE,          //GLboolean abDotProduct,
+                                          GL_FALSE,          //GLboolean cdDotProduct,
+                                          GL_FALSE           //GLboolean muxSum
+                                          );
+                       // out = spare0 * color
+                       // ( out = AB + (1-A)C + D )
+                       glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
+                       glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
+                       glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
+                       glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
+
+                       if (bm->bm_flags & BM_FLAG_SUPER_TRANSPARENT)
+                       {
+                               // out = alpha0*(1-tex1) + alpha1
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_INVERT_NV, GL_BLUE);
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
+                       }
+                       else
+                       {
+                               // out = alpha0 + alpha1
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
+                               glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
+                       }
+                       glCombinerOutputNV(
+                                          GL_COMBINER0_NV,   //GLenum stage
+                                          GL_ALPHA,          //GLenum portion,
+                                          GL_DISCARD_NV,     //GLenum abOutput,
+                                          GL_DISCARD_NV,     //GLenum cdOutput,
+                                          GL_SPARE0_NV,      //GLenum sumOutput,
+                                          GL_NONE,           //GLenum scale,
+                                          GL_NONE,           //GLenum bias,
+                                          GL_FALSE,          //GLboolean abDotProduct,
+                                          GL_FALSE,          //GLboolean cdDotProduct,
+                                          GL_FALSE           //GLboolean muxSum
+                                          );
+                       glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
+               }
+               else
+#endif
+               {
+                       //http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_env_combine4.txt
+                       //only GL_NV_texture_env_combine4 lets us do what we need:
+                       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
+
+                       //multiply top texture by color(vertex lighting) and add bottom texture(where alpha says to)
+                       glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);
+
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_TEXTURE);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_RGB_NV, GL_PREVIOUS_EXT);
+
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_ONE_MINUS_SRC_ALPHA);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_RGB_NV, GL_SRC_COLOR);
+
+                       //add up alpha channels
+                       glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_ADD);
+
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_ZERO);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, GL_PREVIOUS_EXT);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_ALPHA_NV, GL_ZERO);
+
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_ONE_MINUS_SRC_ALPHA);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, GL_SRC_ALPHA);
+                       glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_ALPHA_NV, GL_ONE_MINUS_SRC_ALPHA);
+               }
+
                // GL_DECAL works sorta ok but the top texture is fullbright.
                //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
 
-               // http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_env_combine4.txt
-               // only GL_NV_texture_env_combine4 lets us do what we need:
-               glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
-
-               // multiply top texture by color(vertex lighting) and add bottom texture(where alpha says to)
-               glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);
-
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_TEXTURE);
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_RGB_NV, GL_PREVIOUS_EXT);
-
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_ONE_MINUS_SRC_ALPHA);
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_RGB_NV, GL_SRC_COLOR);
-
-               // add up alpha channels
-               glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_ADD);
-
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_ZERO);
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, GL_PREVIOUS_EXT);
-               glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_ALPHA_NV, GL_ZERO);
-
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_ONE_MINUS_SRC_ALPHA);
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, GL_SRC_ALPHA);
-               glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_ALPHA_NV, GL_ONE_MINUS_SRC_ALPHA);
-
                // GL_ARB_texture_env_combine comes close, but doesn't quite make it.
                //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
 
@@ -925,7 +991,6 @@ bool g3_draw_tmap_2(int nv, g3s_point **pointlist, g3s_uvl *uvl_list, grs_bitmap
                //glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
                //glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB);
 
-
                glBegin(GL_TRIANGLE_FAN);
                for (c=0;c<nv;c++){
                        switch(orient){
@@ -960,7 +1025,16 @@ bool g3_draw_tmap_2(int nv, g3s_point **pointlist, g3s_uvl *uvl_list, grs_bitmap
                }
                glEnd();
                //ogl_setActiveTexture(1); // still the active texture
-               glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+#ifdef GL_NV_register_combiners
+               if (ogl_nv_register_combiners_ok)
+               {
+                       glDisable(GL_REGISTER_COMBINERS_NV);
+               }
+               else
+#endif
+               {
+                       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+               }
                glDisable(GL_TEXTURE_2D);
                ogl_setActiveTexture(0);
        }
@@ -1426,7 +1500,14 @@ void ogl_init_shared_palette(void)
 
                for (i = 0; i < 256; i++)
                {
-                       if (i == 255)
+                       if (i == 254)
+                       {
+                               texbuf[i * 4] = 255;
+                               texbuf[i * 4 + 1] = 255;
+                               texbuf[i * 4 + 2] = 255;
+                               texbuf[i * 4 + 3] = 0;
+                       }
+                       else if (i == 255)
                        {
                                texbuf[i * 4] = 0;
                                texbuf[i * 4 + 1] = 0;
@@ -1491,8 +1572,30 @@ void ogl_filltexbuf(unsigned char *data, GLubyte *texp, int truewidth, int width
                        if (x<width && y<height)
                                c=data[i++];
                        else
-                               c = 256; // fill the pad space with transparancy
-                       if ((c == 255 && (bm_flags & BM_FLAG_TRANSPARENT)) || c == 256)
+                               c = 256; // fill the pad space with transparency (or blackness)
+                       if (c == 254 && (bm_flags & BM_FLAG_SUPER_TRANSPARENT))
+                       {
+                               switch (type)
+                               {
+                               case GL_LUMINANCE_ALPHA:
+                                       (*(texp++)) = 255;
+                                       (*(texp++)) = 0;
+                                       break;
+                               case GL_RGBA:
+                                       (*(texp++)) = 255;
+                                       (*(texp++)) = 255;
+                                       (*(texp++)) = 255;
+                                       (*(texp++)) = 0; // transparent pixel
+                                       break;
+                               case GL_COLOR_INDEX:
+                                       (*(texp++)) = c;
+                                       break;
+                               default:
+                                       Error("ogl_filltexbuf unhandled super-transparent texformat\n");
+                                       break;
+                               }
+                       }
+                       else if ((c == 255 && (bm_flags & BM_FLAG_TRANSPARENT)) || c == 256)
                        {
                                switch (type){
                                        case GL_LUMINANCE:
@@ -1520,7 +1623,6 @@ void ogl_filltexbuf(unsigned char *data, GLubyte *texp, int truewidth, int width
                                                Error("ogl_filltexbuf unknown texformat\n");
                                                break;
                                }
-//                             (*(tex++))=0;
                        }else{
                                switch (type){
                                        case GL_LUMINANCE://these could prolly be done to make the intensity based upon the intensity of the resulting color, but its not needed for anything (yet?) so no point. :)
@@ -1678,7 +1780,16 @@ void ogl_loadtexture(unsigned char *data, int dxo, int dyo, ogl_texture *tex, in
                // descent makes palette entries 254 and 255 both do double duty, depending upon the setting of BM_FLAG_SUPER_TRANSPARENT and BM_FLAG_TRANSPARENT.
                // So if the texture doesn't have BM_FLAG_TRANSPARENT set, yet uses index 255, we cannot use the palette for it since that color would be incorrect. (this case is much less common than transparent textures, hence why we don't exclude those instead.)
                // We don't handle super transparent textures with ogl yet, so we don't bother checking that here.
-               int usesthetransparentindexcolor = 0;
+               int usesthetransparentindexcolor = 0, usesthesupertransparentindexcolor = 0;
+
+               if (!(bm_flags & BM_FLAG_SUPER_TRANSPARENT))
+               {
+                       int i;
+
+                       for (i = 0; i < tex->w * tex->h; ++i)
+                               if (data[i] == 254)
+                                       usesthesupertransparentindexcolor += 1;
+               }
                if (!(bm_flags & BM_FLAG_TRANSPARENT))
                {
                        int i;
@@ -1687,13 +1798,13 @@ void ogl_loadtexture(unsigned char *data, int dxo, int dyo, ogl_texture *tex, in
                                if (data[i] == 255)
                                        usesthetransparentindexcolor += 1;
                }
-               if (!usesthetransparentindexcolor)
+               if (!usesthetransparentindexcolor && !usesthesupertransparentindexcolor)
                {
                        tex->internalformat = GL_COLOR_INDEX8_EXT;
                        tex->format = GL_COLOR_INDEX;
                }
                //else
-               //      printf("bm data=%p w=%i h=%i used the transparent color %i times\n",data, tex->w, tex->h, usesthetransparentindexcolor);
+               //      printf("bm data=%p w=%i h=%i transparent:%i supertrans:%i\n", data, tex->w, tex->h, usesthetransparentindexcolor, usesthesupertransparentindexcolor);
        }
 #endif
 
index bf9c688..7d4e336 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: loadgl.h,v 1.8 2004-05-22 08:43:08 btb Exp $ */
+/* $Id: loadgl.h,v 1.9 2004-05-22 21:48:41 btb Exp $ */
 /*
  *
  * dynamic opengl loading - courtesy of Jeff Slutter
 #define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
 #endif
 
++ #ifndef GL_NV_register_combiners
+#define GL_NV_register_combiners 1
+#define GL_REGISTER_COMBINERS_NV          0x8522
+#define GL_VARIABLE_A_NV                  0x8523
+#define GL_VARIABLE_B_NV                  0x8524
+#define GL_VARIABLE_C_NV                  0x8525
+#define GL_VARIABLE_D_NV                  0x8526
+#define GL_VARIABLE_E_NV                  0x8527
+#define GL_VARIABLE_F_NV                  0x8528
+#define GL_VARIABLE_G_NV                  0x8529
+#define GL_CONSTANT_COLOR0_NV             0x852A
+#define GL_CONSTANT_COLOR1_NV             0x852B
+#define GL_PRIMARY_COLOR_NV               0x852C
+#define GL_SECONDARY_COLOR_NV             0x852D
+#define GL_SPARE0_NV                      0x852E
+#define GL_SPARE1_NV                      0x852F
+#define GL_DISCARD_NV                     0x8530
+#define GL_E_TIMES_F_NV                   0x8531
+#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532
+#define GL_UNSIGNED_IDENTITY_NV           0x8536
+#define GL_UNSIGNED_INVERT_NV             0x8537
+#define GL_EXPAND_NORMAL_NV               0x8538
+#define GL_EXPAND_NEGATE_NV               0x8539
+#define GL_HALF_BIAS_NORMAL_NV            0x853A
+#define GL_HALF_BIAS_NEGATE_NV            0x853B
+#define GL_SIGNED_IDENTITY_NV             0x853C
+#define GL_SIGNED_NEGATE_NV               0x853D
+#define GL_SCALE_BY_TWO_NV                0x853E
+#define GL_SCALE_BY_FOUR_NV               0x853F
+#define GL_SCALE_BY_ONE_HALF_NV           0x8540
+#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV   0x8541
+#define GL_COMBINER_INPUT_NV              0x8542
+#define GL_COMBINER_MAPPING_NV            0x8543
+#define GL_COMBINER_COMPONENT_USAGE_NV    0x8544
+#define GL_COMBINER_AB_DOT_PRODUCT_NV     0x8545
+#define GL_COMBINER_CD_DOT_PRODUCT_NV     0x8546
+#define GL_COMBINER_MUX_SUM_NV            0x8547
+#define GL_COMBINER_SCALE_NV              0x8548
+#define GL_COMBINER_BIAS_NV               0x8549
+#define GL_COMBINER_AB_OUTPUT_NV          0x854A
+#define GL_COMBINER_CD_OUTPUT_NV          0x854B
+#define GL_COMBINER_SUM_OUTPUT_NV         0x854C
+#define GL_MAX_GENERAL_COMBINERS_NV       0x854D
+#define GL_NUM_GENERAL_COMBINERS_NV       0x854E
+#define GL_COLOR_SUM_CLAMP_NV             0x854F
+#define GL_COMBINER0_NV                   0x8550
+#define GL_COMBINER1_NV                   0x8551
+#define GL_COMBINER2_NV                   0x8552
+#define GL_COMBINER3_NV                   0x8553
+#define GL_COMBINER4_NV                   0x8554
+#define GL_COMBINER5_NV                   0x8555
+#define GL_COMBINER6_NV                   0x8556
+#define GL_COMBINER7_NV                   0x8557
+#endif
+
 #ifdef _cplusplus
 #define OEXTERN        extern "C"
 #else
 
 #define glColorTableEXT dglColorTableEXT
 
+#define glCombinerParameteriNV dglCombinerParameteriNV
+#define glCombinerInputNV dglCombinerInputNV
+#define glCombinerOutputNV dglCombinerOutputNV
+
 #ifdef _WIN32
 #define wglCopyContext dwglCopyContext
 #define wglCreateContext dwglCreateContext
@@ -764,6 +823,9 @@ typedef void (OGLFUNCCALL *glActiveTextureARB_fp)(GLenum target);
 typedef void (OGLFUNCCALL *glMultiTexCoord2fSGIS_fp)(GLenum target, GLfloat s, GLfloat t);
 typedef void (OGLFUNCCALL *glSelectTextureSGIS_fp)(GLenum target);
 typedef void (OGLFUNCCALL *glColorTableEXT_fp)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table);
+typedef void (OGLFUNCCALL *glCombinerParameteriNV_fp)(GLenum, GLint);
+typedef void (OGLFUNCCALL *glCombinerInputNV_fp)(GLenum, GLenum, GLenum, GLenum, GLenum, GLenum);
+typedef void (OGLFUNCCALL *glCombinerOutputNV_fp)(GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLboolean, GLboolean, GLboolean);
 
 #ifdef _WIN32
 typedef BOOL  (OGLFUNCCALL *wglCopyContext_fp)(HGLRC, HGLRC, UINT);
@@ -1949,6 +2011,10 @@ void OpenGL_SetFuncsToNull(void)
        dglSelectTextureSGIS = NULL;
        dglColorTableEXT = NULL;
 
+       dglCombinerParameteriNV = NULL;
+       dglCombinerInputNV = NULL;
+       dglCombinerOutputNV = NULL;
+
 #ifdef _WIN32
        dwglCopyContext = NULL;
        dwglCreateContext = NULL;
index 147ef64..f760bbb 100644 (file)
@@ -101,6 +101,13 @@ extern int ogl_gettexlevelparam_ok;
 #endif
 extern int ogl_nv_texture_env_combine4_ok;
 
+#ifdef GL_NV_register_combiners
+extern int ogl_nv_register_combiners_ok;
+#define OGL_SUPER_TRANSPARENT_OK (ogl_nv_register_combiners_ok)
+#else
+#define OGL_SUPER_TRANSPARENT_OK (0)
+#endif
+
 #ifndef GL_EXT_texture_filter_anisotropic
 #define GL_EXT_texture_filter_anisotropic 1
 #define GL_TEXTURE_MAX_ANISOTROPY_EXT     0x84FE
index 90b5fd4..9ceefb1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: render.c,v 1.21 2004-05-22 01:06:27 btb Exp $ */
+/* $Id: render.c,v 1.22 2004-05-22 21:48:48 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -648,7 +648,8 @@ void render_face(int segnum, int sidenum, int nv, short *vp, int tmap1, int tmap
                        PIGGY_PAGE_IN(Textures[tmap2&0x3FFF]);
                        bm2 = &GameBitmaps[Textures[tmap2&0x3FFF].index];
                }
-               if (bm2 && (bm2->bm_flags&BM_FLAG_SUPER_TRANSPARENT)){
+               if (!OGL_SUPER_TRANSPARENT_OK && bm2 && (bm2->bm_flags & BM_FLAG_SUPER_TRANSPARENT))
+               {
                        bm = texmerge_get_cached_bitmap( tmap1, tmap2 );
                        bm2 = NULL;
                }