Difference for arch/ogl/ogl.c from version 1.37 to 1.38


version 1.37 version 1.38
Line 3
 
Line 3
 #include <windows.h>  #include <windows.h>
 #include <stddef.h>  #include <stddef.h>
 #endif  #endif
 #include <GL/gl.h>  #include "ogl_init.h"
 #include <GL/glu.h>  #include <GL/glu.h>
 #include <string.h>  #include <string.h>
 #include <math.h>  #include <math.h>
 #include "ogl_init.h"  
 #include "3d.h"  #include "3d.h"
 #include "piggy.h"  #include "piggy.h"
 #include "../../3d/globvars.h"  #include "../../3d/globvars.h"
Line 71
 
Line 70
 #endif  #endif
 int ogl_nv_texture_env_combine4_ok=0;  int ogl_nv_texture_env_combine4_ok=0;
 int ogl_ext_texture_filter_anisotropic_ok=0;  int ogl_ext_texture_filter_anisotropic_ok=0;
   #ifdef GL_EXT_paletted_texture
   int ogl_shared_palette_ok=0;
   int ogl_paletted_texture_ok=0;
   #endif
   
 int sphereh=0;  int sphereh=0;
 int cross_lh[2]={0,0};  int cross_lh[2]={0,0};
Line 1068
 
Line 1071
    
 // oldpal=ogl_pal;  // oldpal=ogl_pal;
  ogl_pal=gr_current_pal;   ogl_pal=gr_current_pal;
  ogl_loadtexture(src->bm_data,sx,sy,&tex);   ogl_loadtexture(src->bm_data,sx,sy,&tex,src->bm_flags);
 // ogl_pal=oldpal;  // ogl_pal=oldpal;
  ogl_pal=gr_palette;   ogl_pal=gr_palette;
  OGL_BINDTEXTURE(tex.handle);   OGL_BINDTEXTURE(tex.handle);
Line 1276
 
Line 1279
  glClear(GL_COLOR_BUFFER_BIT);   glClear(GL_COLOR_BUFFER_BIT);
 }  }
   
   void ogl_init_shared_palette(void) {
   #ifdef GL_EXT_paletted_texture
    if (ogl_shared_palette_ok) {
    int i;
    glEnable(GL_SHARED_TEXTURE_PALETTE_EXT);
    //glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, ogl_pal);
   
    for (i=0;i<256;i++){
    if (i==255) {
    texbuf[i*4]=0;
    texbuf[i*4+1]=0;
    texbuf[i*4+2]=0;
    texbuf[i*4+3]=0;
    } else {
    texbuf[i*4]=gr_current_pal[i*3]*4;
    texbuf[i*4+1]=gr_current_pal[i*3+1]*4;
    texbuf[i*4+2]=gr_current_pal[i*3+2]*4;
    texbuf[i*4+3]=255;
    }
    }
    glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, texbuf);
    }
   #endif
   }
   
 int tex_format_supported(int iformat,int format){  int tex_format_supported(int iformat,int format){
  switch (iformat){   switch (iformat){
  case GL_INTENSITY4:   case GL_INTENSITY4:
Line 1337
 
Line 1365
  (*(texp++))=0;   (*(texp++))=0;
  (*(texp++))=0;//transparent pixel   (*(texp++))=0;//transparent pixel
  break;   break;
    case GL_COLOR_INDEX:
    (*(texp++))=c;
    break;
    default:
    Error("ogl_filltexbuf unknown texformat\n");
    break;
  }   }
 // (*(tex++))=0;  // (*(tex++))=0;
  }else{   }else{
Line 1358
 
Line 1392
  (*(texp++))=255;//not transparent   (*(texp++))=255;//not transparent
  // (*(tex++))=(ogl_pal[c*3]>>1) + ((ogl_pal[c*3+1]>>1)<<5) + ((ogl_pal[c*3+2]>>1)<<10) + (1<<15);   // (*(tex++))=(ogl_pal[c*3]>>1) + ((ogl_pal[c*3+1]>>1)<<5) + ((ogl_pal[c*3+2]>>1)<<10) + (1<<15);
  break;   break;
    case GL_COLOR_INDEX:
    (*(texp++))=c;
    break;
    default:
    Error("ogl_filltexbuf unknown texformat\n");
    break;
  }   }
  }   }
  }   }
Line 1419
 
Line 1459
  glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_GREEN_SIZE,&t);a+=t;   glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_GREEN_SIZE,&t);a+=t;
  glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_BLUE_SIZE,&t);a+=t;   glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_BLUE_SIZE,&t);a+=t;
  glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_ALPHA_SIZE,&t);a+=t;   glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_ALPHA_SIZE,&t);a+=t;
   #ifdef GL_EXT_paletted_texture
    if (ogl_paletted_texture_ok) {
    glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_INDEX_SIZE_EXT,&t);a+=t;
    }
   #endif
  }else{   }else{
  w=tex->tw;   w=tex->tw;
  h=tex->th;   h=tex->th;
Line 1433
 
Line 1478
  case GL_RGBA:   case GL_RGBA:
  bi=16;   bi=16;
  break;   break;
    case GL_COLOR_INDEX:
    bi=8;
    break;
  default:   default:
  Error("tex_set_size unknown texformat\n");   Error("tex_set_size unknown texformat\n");
  break;   break;
Line 1444
 
Line 1492
 //In theory this could be a problem for repeating textures, but all real  //In theory this could be a problem for repeating textures, but all real
 //textures (not sprites, etc) in descent are 64x64, so we are ok.  //textures (not sprites, etc) in descent are 64x64, so we are ok.
 //stores OpenGL textured id in *texid and u/v values required to get only the real data in *u/*v  //stores OpenGL textured id in *texid and u/v values required to get only the real data in *u/*v
 void ogl_loadtexture(unsigned char * data, int dxo,int dyo, ogl_texture *tex){  void ogl_loadtexture(unsigned char * data, int dxo,int dyo, ogl_texture *tex, int bm_flags){
 //void ogl_loadtexture(unsigned char * data, int width, int height,int dxo,int dyo, int *texid,float *u,float *v,char domipmap,float prio){  //void ogl_loadtexture(unsigned char * data, int width, int height,int dxo,int dyo, int *texid,float *u,float *v,char domipmap,float prio){
 // int internalformat=GL_RGBA;  // int internalformat=GL_RGBA;
 // int format=GL_RGBA;  // int format=GL_RGBA;
Line 1461
 
Line 1509
  tex->u=(float)tex->w/(float)tex->tw;   tex->u=(float)tex->w/(float)tex->tw;
  tex->v=(float)tex->h/(float)tex->th;   tex->v=(float)tex->h/(float)tex->th;
   
   #ifdef GL_EXT_paletted_texture
    if (ogl_shared_palette_ok && tex->format==GL_RGBA) {
    //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;
    if (!(bm_flags & BM_FLAG_TRANSPARENT)) {
    int i;
    for (i=0; i < tex->w*tex->h; ++i)
    if (data[i]==255)
    usesthetransparentindexcolor+=1;
    }
    if (!usesthetransparentindexcolor) {
    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);
    }
   #endif
   
  // if (width!=twidth || height!=theight)   // if (width!=twidth || height!=theight)
  // glmprintf((0,"sizing %ix%i texture up to %ix%i\n",width,height,twidth,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);
Line 1539
 
Line 1608
  }   }
  buf=decodebuf;   buf=decodebuf;
  }   }
  ogl_loadtexture(buf,0,0,bm->gltexture);   ogl_loadtexture(buf,0,0,bm->gltexture,bm->bm_flags);
 }  }
 void ogl_loadbmtexture(grs_bitmap *bm){  void ogl_loadbmtexture(grs_bitmap *bm){
  ogl_loadbmtexture_m(bm,1);   ogl_loadbmtexture_m(bm,1);

Legend:
line(s) removed in v.1.37 
line(s) changed
 line(s) added in v.1.38