version 1.40 | | version 1.41 |
---|
| | |
int ogl_sgis_multitexture_ok=0; | | int ogl_sgis_multitexture_ok=0; |
#endif | | #endif |
int ogl_nv_texture_env_combine4_ok=0; | | 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; | | int ogl_ext_texture_filter_anisotropic_ok=0; |
#ifdef GL_EXT_paletted_texture | | #ifdef GL_EXT_paletted_texture |
int ogl_shared_palette_ok=0; | | int ogl_shared_palette_ok=0; |
| | |
if (tmap2 != 0){ | | if (tmap2 != 0){ |
PIGGY_PAGE_IN(Textures[tmap2&0x3FFF]); | | PIGGY_PAGE_IN(Textures[tmap2&0x3FFF]); |
bm2 = &GameBitmaps[Textures[tmap2&0x3FFF].index]; | | 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 ); | | bm = texmerge_get_cached_bitmap( tmap1, tmap2 ); |
else { | | else { |
ogl_loadbmtexture(bm2); | | ogl_loadbmtexture(bm2); |
| | |
} | | } |
bool g3_draw_tmap_2(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bmbot,grs_bitmap *bm,int orient) | | 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 ((defined(GL_NV_register_combiners) || 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 ((ogl_nv_register_combiners_ok || ogl_nv_texture_env_combine4_ok) && (ogl_arb_multitexture_ok || ogl_sgis_multitexture_ok)){ |
int c; | | int c; |
float l,u1,v1; | | float l,u1,v1; |
| | |
| | |
ogl_bindbmtex(bm); | | ogl_bindbmtex(bm); |
ogl_texwrap(bm->gltexture,GL_REPEAT); | | ogl_texwrap(bm->gltexture,GL_REPEAT); |
| | |
//GL_DECAL works sorta ok but the top texture is fullbright. | | if (ogl_nv_register_combiners_ok) { |
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | | 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 { |
//http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_env_combine4.txt | | //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: | | //only GL_NV_texture_env_combine4 lets us do what we need: |
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV); | | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV); |
| | |
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_ONE_MINUS_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_OPERAND2_ALPHA_EXT, GL_SRC_ALPHA); |
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_ALPHA_NV, GL_ONE_MINUS_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); |
| | |
//GL_ARB_texture_env_combine comes close, but doesn't quite make it. | | //GL_ARB_texture_env_combine comes close, but doesn't quite make it. |
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); | | //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); |
| | |
//glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); | | //glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); |
//glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB); | | //glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB); |
| | |
| | |
glBegin(GL_TRIANGLE_FAN); | | glBegin(GL_TRIANGLE_FAN); |
for (c=0;c<nv;c++){ | | for (c=0;c<nv;c++){ |
switch(orient){ | | switch(orient){ |
| | |
} | | } |
glEnd(); | | glEnd(); |
//ogl_setActiveTexture(1);//still the active texture | | //ogl_setActiveTexture(1);//still the active texture |
| | if (ogl_nv_register_combiners_ok) { |
| | glDisable(GL_REGISTER_COMBINERS_NV); |
| | } else { |
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| | } |
glDisable(GL_TEXTURE_2D); | | glDisable(GL_TEXTURE_2D); |
ogl_setActiveTexture(0); | | ogl_setActiveTexture(0); |
}else | | }else |
| | |
//glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, ogl_pal); | | //glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, ogl_pal); |
| | |
for (i=0;i<256;i++){ | | 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]=0; |
texbuf[i*4+1]=0; | | texbuf[i*4+1]=0; |
texbuf[i*4+2]=0; | | texbuf[i*4+2]=0; |
| | |
if (x<width && y<height) | | if (x<width && y<height) |
c=data[i++]; | | c=data[i++]; |
else | | else |
c=256;//fill the pad space with transparancy | | c=256;//fill the pad space with transparancy (or blackness) |
if ((c==255 && (bm_flags&BM_FLAG_TRANSPARENT)) || c==256){ | | 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){ | | switch (type){ |
case GL_LUMINANCE: | | case GL_LUMINANCE: |
(*(texp++))=0; | | (*(texp++))=0; |
| | |
Error("ogl_filltexbuf unknown texformat\n"); | | Error("ogl_filltexbuf unknown texformat\n"); |
break; | | break; |
} | | } |
// (*(tex++))=0; | | |
}else{ | | }else{ |
switch (type){ | | 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. :) | | 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. :) |
| | |
//descent makes palette entries 254 and 255 both do double duty, depending upon the setting of BM_FLAG_SUPER_TRANSPARENT and BM_FLAG_TRANSPARENT. | | //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.) | | // 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. | | // 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)) { | | if (!(bm_flags & BM_FLAG_TRANSPARENT)) { |
int i; | | int i; |
for (i=0; i < tex->w*tex->h; ++i) | | for (i=0; i < tex->w*tex->h; ++i) |
if (data[i]==255) | | if (data[i]==255) |
usesthetransparentindexcolor+=1; | | usesthetransparentindexcolor+=1; |
} | | } |
if (!usesthetransparentindexcolor) { | | if (!usesthetransparentindexcolor && !usesthesupertransparentindexcolor) { |
tex->internalformat = GL_COLOR_INDEX8_EXT; | | tex->internalformat = GL_COLOR_INDEX8_EXT; |
tex->format = GL_COLOR_INDEX; | | tex->format = GL_COLOR_INDEX; |
} | | } |
//else | | //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 | | #endif |
| | |