paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/draw/opengl pgglcore.cpp,1.1.2.5,1.1.2.6


From: Teunis Peters <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/draw/opengl pgglcore.cpp,1.1.2.5,1.1.2.6 pgglmem.cpp,1.1.2.3,1.1.2.4 pggloper.cpp,1.1.2.6,1.1.2.7 pgglroot.cpp,1.1.2.6,1.1.2.7 pgglsurf.cpp,1.1.2.8,1.1.2.9
Date: Sat, 09 Nov 2002 07:00:38 -0500

Update of /cvsroot/paragui/paragui/src/draw/opengl
In directory subversions:/tmp/cvs-serv20544/src/draw/opengl

Modified Files:
      Tag: devel-opengl
        pgglcore.cpp pgglmem.cpp pggloper.cpp pgglroot.cpp 
        pgglsurf.cpp 
Log Message:
Working OpenGL
still needs additional repairs to get textures looking right, but so far so 
good :)


Index: pgglcore.cpp
===================================================================
RCS file: /cvsroot/paragui/paragui/src/draw/opengl/Attic/pgglcore.cpp,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -C2 -r1.1.2.5 -r1.1.2.6
*** pgglcore.cpp        8 Nov 2002 11:22:01 -0000       1.1.2.5
--- pgglcore.cpp        9 Nov 2002 12:00:35 -0000       1.1.2.6
***************
*** 55,71 ****
  namespace PG_Draw {
  
- /* inline */
- #if 0
- bool PG_GLDraw::is_GL() {
-   bool rv = false;
-   if (realscreen != NULL) {
-     rv = (GetTexInfo(realscreen->SDL()) != NULL);
-   } else {
-     rv = (GetTexInfo(screen->SDL()) != NULL);
-   };
-   return rv;
- };
- #endif
- 
  PG_GLDraw::PG_GLDraw()
    : PG_Draw(), maxtexsize(256), update_screen(0) {
--- 55,58 ----
***************
*** 87,92 ****
  void PG_GLDraw::quit() {
    if (SDL_WasInit(SDL_INIT_VIDEO)) {
!     SDL_Surface *screen = SDL_GetVideoSurface();
!     FreeTexInfo(screen);
      SDL_QuitSubSystem(SDL_INIT_VIDEO);
    }
--- 74,79 ----
  void PG_GLDraw::quit() {
    if (SDL_WasInit(SDL_INIT_VIDEO)) {
!     /* SDL_Surface *screen = SDL_GetVideoSurface(); */
!     /* FreeTexInfo(screen); */
      SDL_QuitSubSystem(SDL_INIT_VIDEO);
    }
***************
*** 118,128 ****
      // PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x amask %x", 
__FUNCTION__, __FILE__, __LINE__, pf->BytesPerPixel, pf->Rmask, pf->Gmask, 
pf->Bmask, pf->Amask);
    };
-   
-   switch (AddTexInfo(s)) {
-   case 0: break;
-   case -1: PG_LogERR("AddTexInfo returned: no screen"); break;
-   case -2: PG_LogERR("AddTexInfo returned: no texinfo"); break;
-   case -3: PG_LogERR("AddTexInfo returned: calc chop fail"); break;
-   };
    return s;
  }
--- 105,108 ----
***************
*** 152,162 ****
      // PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x amask %x", 
__FUNCTION__, __FILE__, __LINE__, pf->BytesPerPixel, pf->Rmask, pf->Gmask, 
pf->Bmask, pf->Amask);
    };
-   
-   switch (AddTexInfo(s)) {
-   case 0: break;
-   case -1: PG_LogERR("AddTexInfo returned: no screen"); break;
-   case -2: PG_LogERR("AddTexInfo returned: no texinfo"); break;
-   case -3: PG_LogERR("AddTexInfo returned: calc chop fail"); break;
-   };
    return s;
  }
--- 132,135 ----
***************
*** 200,205 ****
  
   fail:
-   PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x amask %x", 
__FUNCTION__, __FILE__, __LINE__, _RGBAfmt.BytesPerPixel, _RGBAfmt.Rmask, 
_RGBAfmt.Gmask, _RGBAfmt.Bmask, _RGBAfmt.Amask);
    PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x amask %x", 
__FUNCTION__, __FILE__, __LINE__, pf->BytesPerPixel, pf->Rmask, pf->Gmask, 
pf->Bmask, pf->Amask);
    return 0;
  }
--- 173,179 ----
  
   fail:
    PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x amask %x", 
__FUNCTION__, __FILE__, __LINE__, pf->BytesPerPixel, pf->Rmask, pf->Gmask, 
pf->Bmask, pf->Amask);
+   PG_LogMSG("%s[%s:%i]: RGBA format bpp %i rmask %x gmask %x bmask %x amask 
%x", __FUNCTION__, __FILE__, __LINE__, _RGBAfmt.BytesPerPixel, _RGBAfmt.Rmask, 
_RGBAfmt.Gmask, _RGBAfmt.Bmask, _RGBAfmt.Amask);
+   PG_LogMSG("%s[%s:%i]: RGB format bpp %i rmask %x gmask %x bmask %x amask 
%x", __FUNCTION__, __FILE__, __LINE__, _RGBAfmt.BytesPerPixel, _RGBfmt.Rmask, 
_RGBfmt.Gmask, _RGBfmt.Bmask, _RGBfmt.Amask);
    return 0;
  }
***************
*** 346,373 ****
    DBG(PG_LogERR("ParaGUI GLcore: Max texture size: %d", maxtexsize));
  
- #if 0
-   if (AddTexInfo(sdlroot) < 0) {
-     DBG(PG_LogERR("ParaGUI GLcore: Failed to add info to screen surface!"));
-     SDL_QuitSubSystem(SDL_INIT_VIDEO);
-     return NULL;
-   }
- #endif
-   {
-     int ativ = AddTexInfo(sdlroot);
-     if (ativ < 0) {
-       switch (ativ) {
-       /* Q - if root has no "pixel" data, what should it return? */
-       case -1: PG_LogERR("AddTexInfo returned: no screen"); break;
-       case -2: PG_LogERR("AddTexInfo returned: no texinfo"); break;
-       case -3: PG_LogERR("AddTexInfo returned: calc chop fail"); break;
-       case -4: PG_LogERR("root image - no pixel data"); goto bypass;
-       };
-       DBG(PG_LogERR("ParaGUI GLcore: Failed to add info to screen surface!"));
-       SDL_QuitSubSystem(SDL_INIT_VIDEO);
-       return NULL;
-     };
-   };
-  bypass:
- 
    _init_formats();
  
--- 320,323 ----
***************
*** 425,429 ****
      if (!s) {
        PG_LogERR("SDL: %s", SDL_GetError());
!       _FreeSurface(tmp);
        exit(-1);
        return NULL;
--- 375,379 ----
      if (!s) {
        PG_LogERR("SDL: %s", SDL_GetError());
!       SDL_FreeSurface(tmp); // _FreeSurface(tmp);
        exit(-1);
        return NULL;
***************
*** 438,442 ****
      // DBG5(DBGLINE());
      surf->BlitSurface(tmp, PG_Rect(), PG_Rect());
!     _FreeSurface(tmp);
      
      if (src->flags & SDL_SRCALPHA)
--- 388,392 ----
      // DBG5(DBGLINE());
      surf->BlitSurface(tmp, PG_Rect(), PG_Rect());
!     SDL_FreeSurface(tmp); // _FreeSurface(tmp);
      
      if (src->flags & SDL_SRCALPHA)
***************
*** 449,469 ****
    }
    /* if !is_GL */
- #if 0
- else {
-     if (hasalpha) {
-       s = SDL_DisplayFormatAlpha(src);
-     } else {
-       s = SDL_DisplayFormat(src);
-     };
-     if (s == NULL) { PG_LogERR("SDL: %s", SDL_GetError()); exit(-1); }
-     GLSDL_FIX_SURFACE(s);
-     surf = new PG_GLDrawableSurface(this,s);
-     attach(surf);
-     if (surf == NULL) { PG_LogERR("failed to create window"); exit(-1); }
-     // PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x", 
__FUNCTION__, __FILE__, __LINE__, surf->GetFormat()->BytesPerPixel, 
surf->GetFormat()->Rmask, surf->GetFormat()->Gmask, surf->GetFormat()->Bmask);
-     DBG5(DBGFUNCEND());
-     return surf;
-   }
- #endif
  };
  
--- 399,402 ----
***************
*** 484,495 ****
    if (s == NULL) { PG_LogERR("invalid SDL surface!"); return NULL; }
    surf = new PG_GLDrawableSurface(this, s);
- #if 0
-   {
-     SDL_PixelFormat *pf;
-     pf = s->format;
-     PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x amask %x", 
__FUNCTION__, __FILE__, __LINE__, pf->BytesPerPixel, pf->Rmask, pf->Gmask, 
pf->Bmask, pf->Amask);
-   };
- #endif
  
    PG_GLDrawableSurface *ts;
    bool talph = true;
--- 417,428 ----
    if (s == NULL) { PG_LogERR("invalid SDL surface!"); return NULL; }
    surf = new PG_GLDrawableSurface(this, s);
  
+   /* bypass autoconvert */
+   if (_FormatIsOk(s)) {
+     attach(surf);
+     // PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x", 
__FUNCTION__, __FILE__, __LINE__, surf->GetFormat()->BytesPerPixel, 
surf->GetFormat()->Rmask, surf->GetFormat()->Gmask, surf->GetFormat()->Bmask);
+     return surf;
+   };
+   // PG_LogDBG("ParaGUI[%s]: %s:%i accelerated surface %p", __FILE__, 
__FUNCTION__, __LINE__, surf->SDL());
    PG_GLDrawableSurface *ts;
    bool talph = true;
***************
*** 500,504 ****
    // PG_LogMSG("create accelerated surface from SDL(alpha=%s)", 
talph?"true":"false");
  #endif
!   ts = (PG_GLDrawableSurface*)AccelerateSurface(surf, talph);
    if (ts != NULL) {
      delete surf;
--- 433,437 ----
    // PG_LogMSG("create accelerated surface from SDL(alpha=%s)", 
talph?"true":"false");
  #endif
!   ts = dynamic_cast<PG_GLDrawableSurface*>(AccelerateSurface(surf, talph));
    if (ts != NULL) {
      delete surf;
***************
*** 509,512 ****
--- 442,446 ----
    attach(surf);
    if (surf == NULL) { PG_LogERR("failed to create window"); exit(-1); }
+   // PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x", __FUNCTION__, 
__FILE__, __LINE__, surf->GetFormat()->BytesPerPixel, surf->GetFormat()->Rmask, 
surf->GetFormat()->Gmask, surf->GetFormat()->Bmask);
    return surf;
  };
***************
*** 515,518 ****
--- 449,453 ----
                                                     int width, int height, int 
depth,
                                                     Uint32 Rmask, Uint32 
Gmask, Uint32 Bmask, Uint32 Amask) {
+   // PG_LogMSG("%s[%s:%i]: (%ix%i) bpp %i rmask %x gmask %x bmask %x amask 
%x", __FUNCTION__, __FILE__, __LINE__, width,height,depth, 
Rmask,Gmask,Bmask,Amask);
    // depth = Rmask = Gmask = Bmask = Amask = 0;
    if (depth == 0) depth = _RGBfmt.BitsPerPixel;
***************
*** 521,535 ****
    t = SDL_CreateRGBSurface(flags,width,height,depth,Rmask,Gmask,Bmask,Amask);
    if (t == NULL) { PG_LogERR("SDL: %s", SDL_GetError()); exit(-1); }
- #if 0
-   {
-     SDL_PixelFormat *pf;
-     pf = t->format;
-     PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x amask %x", 
__FUNCTION__, __FILE__, __LINE__, pf->BytesPerPixel, pf->Rmask, pf->Gmask, 
pf->Bmask, pf->Amask);
-   };
- #endif
    /* GLSDL_FIX_SURFACE(t); */
    surf = new PG_GLDrawableSurface(this, t);
    attach(surf);
    if (surf == NULL) { PG_LogERR("failed to create window"); exit(-1); }
    // PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x", __FUNCTION__, 
__FILE__, __LINE__, surf->GetFormat()->BytesPerPixel, surf->GetFormat()->Rmask, 
surf->GetFormat()->Gmask, surf->GetFormat()->Bmask);
    return surf;
--- 456,464 ----
    t = SDL_CreateRGBSurface(flags,width,height,depth,Rmask,Gmask,Bmask,Amask);
    if (t == NULL) { PG_LogERR("SDL: %s", SDL_GetError()); exit(-1); }
    /* GLSDL_FIX_SURFACE(t); */
    surf = new PG_GLDrawableSurface(this, t);
    attach(surf);
    if (surf == NULL) { PG_LogERR("failed to create window"); exit(-1); }
+   // PG_LogMSG("%s[%s:%i]: (%ix%i) bpp %i rmask %x gmask %x bmask %x amask 
%x", __FUNCTION__, __FILE__, __LINE__, width,height,depth, 
Rmask,Gmask,Bmask,Amask);
    // PG_LogMSG("%s[%s:%i]: bpp %i rmask %x gmask %x bmask %x", __FUNCTION__, 
__FILE__, __LINE__, surf->GetFormat()->BytesPerPixel, surf->GetFormat()->Rmask, 
surf->GetFormat()->Gmask, surf->GetFormat()->Bmask);
    return surf;
***************
*** 539,547 ****
    PG_GLDrawableSurface* surf;
    SDL_Surface* t;
- #if 0
-   t = SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,
-                          _RGBfmt.BitsPerPixel,
-                          
_RGBfmt.Rmask,_RGBfmt.Gmask,_RGBfmt.Bmask,_RGBfmt.Amask);
- #endif
    t = _CreateRGBSurface(width, height);
    if (t == NULL) { PG_LogERR("SDL: %s", SDL_GetError()); exit(-1); }
--- 468,471 ----
***************
*** 588,599 ****
      GLSDL_FIX_SURFACE(t);
    };
-   
-   switch (AddTexInfo(t)) {
-   case 0: break;
-   case -1: PG_LogERR("AddTexInfo returned: no screen"); break;
-   case -2: PG_LogERR("AddTexInfo returned: no texinfo"); break;
-   case -3: PG_LogERR("AddTexInfo returned: calc chop fail"); break;
-   };
- 
    surf = new PG_GLDrawableSurface(this, t);
    attach(surf);
--- 512,515 ----
***************
*** 611,621 ****
      GLSDL_FIX_SURFACE(t);
    };
-   
-   switch (AddTexInfo(t)) {
-   case 0: break;
-   case -1: PG_LogERR("AddTexInfo returned: no screen"); break;
-   case -2: PG_LogERR("AddTexInfo returned: no texinfo"); break;
-   case -3: PG_LogERR("AddTexInfo returned: calc chop fail"); break;
-   };
  
    surf = new PG_GLDrawableSurface(this, t);
--- 527,530 ----
***************
*** 650,660 ****
    if (t) {
      GLSDL_FIX_SURFACE(t);
-   };
-   
-   switch (AddTexInfo(t)) {
-   case 0: break;
-   case -1: PG_LogERR("AddTexInfo returned: no screen"); break;
-   case -2: PG_LogERR("AddTexInfo returned: no texinfo"); break;
-   case -3: PG_LogERR("AddTexInfo returned: calc chop fail"); break;
    };
  
--- 559,562 ----

Index: pgglmem.cpp
===================================================================
RCS file: /cvsroot/paragui/paragui/src/draw/opengl/Attic/pgglmem.cpp,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -r1.1.2.3 -r1.1.2.4
*** pgglmem.cpp 4 Nov 2002 10:58:32 -0000       1.1.2.3
--- pgglmem.cpp 9 Nov 2002 12:00:35 -0000       1.1.2.4
***************
*** 81,101 ****
  
  /* Get texinfo for a surface. */
! glSDL_TexInfo *PG_GLDraw::GetTexInfo(SDL_Surface *surface) {
    DBG2(PG_LogMSG("GetTexInfo 1:handle %p", surface));
!   if(!surface)
!     return NULL;      
    DBG2(PG_LogMSG("GetTexInfo 2:handle %p -- not null", surface));
!   if(!texinfotab)
!     return NULL;
    DBG2(PG_LogMSG("GetTexInfo 3:handle %p -- texinfotab exists", surface));
!   DBG2(PG_LogMSG("GetTexInfo 4:handle %p -- ref %i/%i", surface, 
surface->unused1, MAX_TEXINFOS));
!   if(surface->unused1 >= MAX_TEXINFOS)
!     return NULL;
    // DBG2(PG_LogMSG("%s:%s:%i %p %u\n", __FILE__, __FUNCTION__, __LINE__, 
surface, surface->unused1));
    /* DBG2(PG_LogMSG("GetTexInfo 4:handle %p %u %p", surface, 
surface->unused1, texinfotab[surface->unused1])); */
!   DBG2(PG_LogMSG("GetTexInfo 4:handle %p %u", surface, surface->unused1));
!   DBG2(PG_LogMSG("GetTexInfo 5:handle %p %p", surface, 
texinfotab[surface->unused1]));
    
!   return texinfotab[surface->unused1];
  }
  
--- 81,100 ----
  
  /* Get texinfo for a surface. */
! glSDL_TexInfo *PG_GLDraw::GetTexInfo(PG_GLDrawableSurface* surface) {
    DBG2(PG_LogMSG("GetTexInfo 1:handle %p", surface));
!   if(!surface) return NULL;   
    DBG2(PG_LogMSG("GetTexInfo 2:handle %p -- not null", surface));
!   if(!texinfotab) return NULL;
    DBG2(PG_LogMSG("GetTexInfo 3:handle %p -- texinfotab exists", surface));
!   // DBG2(PG_LogMSG("GetTexInfo 4:handle %p -- ref %i/%i", surface, 
surface->unused1, MAX_TEXINFOS));
!   if ((surface->texi<=0) || (surface->texi >= MAX_TEXINFOS)) return NULL;
!   // if(surface->unused1 >= MAX_TEXINFOS) return NULL;
    // DBG2(PG_LogMSG("%s:%s:%i %p %u\n", __FILE__, __FUNCTION__, __LINE__, 
surface, surface->unused1));
    /* DBG2(PG_LogMSG("GetTexInfo 4:handle %p %u %p", surface, 
surface->unused1, texinfotab[surface->unused1])); */
!   // DBG2(PG_LogMSG("GetTexInfo 4:handle %p %u", surface, surface->unused1));
!   // DBG2(PG_LogMSG("GetTexInfo 5:handle %p %p", surface, 
texinfotab[surface->unused1]));
    
!   // return texinfotab[surface->unused1];
!   return texinfotab[(surface->texi)-1];
  }
  
***************
*** 103,107 ****
  
  /* Allocate a "blank" texinfo for a suface. */
! glSDL_TexInfo *PG_GLDraw::AllocTexInfo(SDL_Surface *surface) {
    int handle, i;
    glSDL_TexInfo *txi;
--- 102,106 ----
  
  /* Allocate a "blank" texinfo for a suface. */
! glSDL_TexInfo *PG_GLDraw::AllocTexInfo(PG_GLDrawableSurface* surface) {
    int handle, i;
    glSDL_TexInfo *txi;
***************
*** 161,166 ****
    
    /* Connect the surface to the new TexInfo. */
!   surface->unused1 = (Uint32)handle;
!   DBG2(PG_LogMSG("AllocTexInfo 1:handle %p (%i) -- ref %i/%i", surface, 
handle, surface->unused1, MAX_TEXINFOS));
    
    /* DBG2(fprintf(stderr, "ParaGUI GLcore: Allocated TexInfo %d.\n", 
handle)); */
--- 160,167 ----
    
    /* Connect the surface to the new TexInfo. */
!   // surface->unused1 = (Uint32)handle;
!   surface->texi = (Uint32)handle + 1;
!   // DBG2(PG_LogMSG("AllocTexInfo 1:handle %p (%i) -- ref %i/%i", surface, 
handle, surface->unused1, MAX_TEXINFOS));
!   // PG_LogMSG("AllocTexInfo 1:handle %p (%i) -- ref %i/%i", surface, handle, 
surface->texi, MAX_TEXINFOS);
    
    /* DBG2(fprintf(stderr, "ParaGUI GLcore: Allocated TexInfo %d.\n", 
handle)); */
***************
*** 185,193 ****
  
  /* Detach and free the texinfo of a surface. */
! void PG_GLDraw::FreeTexInfo(SDL_Surface *surface) {
    if (!GetTexInfo(surface)) return;
!   DBG2(PG_LogMSG("FreeTexInfo 1:handle %p -- ref %i/%i", surface, 
surface->unused1, MAX_TEXINFOS));
!   _FreeTexInfo(surface->unused1);
!   GLSDL_FIX_SURFACE(surface);
  }
  
--- 186,194 ----
  
  /* Detach and free the texinfo of a surface. */
! void PG_GLDraw::FreeTexInfo(PG_GLDrawableSurface* surface) {
    if (!GetTexInfo(surface)) return;
!   // DBG2(PG_LogMSG("FreeTexInfo 1:handle %p -- ref %i/%i", surface, 
surface->unused1, MAX_TEXINFOS));
!   _FreeTexInfo((surface->texi)-1);
!   // GLSDL_FIX_SURFACE(surface);
  }
  
***************
*** 298,302 ****
    
  /* Add a glSDL_TexInfo struct to an SDL_Surface */
! int PG_GLDraw::AddTexInfo(SDL_Surface *surface) {
    glSDL_TexInfo *txi;
    DBG5(DBGFUNC());
--- 299,303 ----
    
  /* Add a glSDL_TexInfo struct to an SDL_Surface */
! int PG_GLDraw::AddTexInfo(PG_GLDrawableSurface* surface) {
    glSDL_TexInfo *txi;
    DBG5(DBGFUNC());
***************
*** 305,310 ****
    if (!surface) return -1;
    /* Q - if root has no "pixel" data, what should it return? */
!   if (surface->pixels == NULL) return -4;
!   if (IS_GLSDL_SURFACE(surface)) return 0;    /* Do nothing */
    
    AllocTexInfo(surface);
--- 306,311 ----
    if (!surface) return -1;
    /* Q - if root has no "pixel" data, what should it return? */
!   if (surface->GetPixels() == NULL) return -4;
!   // if (IS_GLSDL_SURFACE(surface)) return 0; /* Do nothing */
    
    AllocTexInfo(surface);
***************
*** 312,326 ****
    if (!txi) return -2;        /* Oops! Didn't get a texinfo... --> */
    
!   txi->virt.w = txi->lw = surface->w;
!   txi->virt.h = txi->lh = surface->h;
    
!   DBG5(dumpimg(surface));
    if (_CalcChop(txi) < 0) return -3;
    
!   SDL_SetClipRect(surface, &txi->virt);
    DBG5(DBGFUNCEND());
    return 0;
  }
  
  void PG_GLDraw::_FreeSurface(SDL_Surface *surface) {
    if (surface == NULL) return;
--- 313,328 ----
    if (!txi) return -2;        /* Oops! Didn't get a texinfo... --> */
    
!   txi->virt.w = txi->lw = surface->GetWidth();
!   txi->virt.h = txi->lh = surface->GetHeight();
    
!   DBG5(dumpimg(surface->SDL()));
    if (_CalcChop(txi) < 0) return -3;
    
!   SDL_SetClipRect(surface->SDL(), &txi->virt);
    DBG5(DBGFUNCEND());
    return 0;
  }
  
+ #if 0
  void PG_GLDraw::_FreeSurface(SDL_Surface *surface) {
    if (surface == NULL) return;
***************
*** 328,331 ****
--- 330,334 ----
    SDL_FreeSurface(surface);
  }
+ #endif
  
  void PG_GLDraw::_init_formats(void) {
***************
*** 333,342 ****
    if (!s) return;
    _RGBfmt = *(s->format);
!   _FreeSurface(s);
    
    s = _CreateRGBASurface(1, 1);
    if (!s) return;
    _RGBAfmt = *(s->format);
!   _FreeSurface(s);
  }
  
--- 336,345 ----
    if (!s) return;
    _RGBfmt = *(s->format);
!   SDL_FreeSurface(s); // _FreeSurface(s);
    
    s = _CreateRGBASurface(1, 1);
    if (!s) return;
    _RGBAfmt = *(s->format);
!   SDL_FreeSurface(s); // _FreeSurface(s);
  }
  

Index: pggloper.cpp
===================================================================
RCS file: /cvsroot/paragui/paragui/src/draw/opengl/Attic/pggloper.cpp,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -r1.1.2.6 -r1.1.2.7
*** pggloper.cpp        8 Nov 2002 11:22:01 -0000       1.1.2.6
--- pggloper.cpp        9 Nov 2002 12:00:35 -0000       1.1.2.7
***************
*** 89,120 ****
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return; // DEBUG
- #if 0
-   if (!update_screen && dynamic_cast<PG_GLDrawableSurface*>(screen)->is_GL())
-     Flip();
-   else
-     screen->UpdateRects(numrects, rects);
- #endif
- #if 0
-   if (!update_screen && is_GL())
-     Flip();
-   else
-     screen->UpdateRects(numrects, rects);
- #else
-   //  Flip();
    SDL_GL_SwapBuffers();
- #endif
    update_screen = 0;
  }
  
  int PG_GLDraw::Flip() {
- #if 0
-   if (!dynamic_cast<PG_GLDrawableSurface*>(screen)->is_GL())
-     return PG_Draw::Flip();
- #endif
-   // DBG5(DBGLINE());
- #if 0
-   if (!is_GL())
-     return PG_Draw::Flip();
- #endif
  /*
  TODO: Perform all rendering here, after globally reordering/optimizing
--- 89,97 ----
***************
*** 348,353 ****
  }
  
! int PG_GLDraw::_BlitGL(SDL_Surface *src, SDL_Rect *srcrect,
!                      SDL_Surface *dst, SDL_Rect *dstrect) {
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return 0; // DEBUG
--- 325,330 ----
  }
  
! int PG_GLDraw::_BlitGL(PG_GLDrawableSurface* src, SDL_Rect *srcrect,
!                      PG_DrawableSurface* dst, SDL_Rect *dstrect) {
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return 0; // DEBUG
***************
*** 362,373 ****
    /* Cull off-screen blits. */
    if (dstrect) {
!     if (dstrect->x > dst->w) return 0;
!     if (dstrect->y > dst->h) return 0;
      if (srcrect) {
        if (dstrect->x + srcrect->w < 0) return 0;
        if (dstrect->y + srcrect->h < 0) return 0;
      } else {
!       if (dstrect->x + src->w < 0) return 0;
!       if (dstrect->y + src->h < 0) return 0;
      }
    }
--- 339,350 ----
    /* Cull off-screen blits. */
    if (dstrect) {
!     if ((Uint32)dstrect->x > dst->GetWidth()) return 0;
!     if ((Uint32)dstrect->y > dst->GetHeight()) return 0;
      if (srcrect) {
        if (dstrect->x + srcrect->w < 0) return 0;
        if (dstrect->y + srcrect->h < 0) return 0;
      } else {
!       if (dstrect->x + src->GetWidth() < 0) return 0;
!       if (dstrect->y + src->GetHeight() < 0) return 0;
      }
    }
***************
*** 377,383 ****
    DownloadSurface(src);
    txi = GetTexInfo(src);
  
    /* Set up blending */
!   if (src->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY)) {
      gl_blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      gl_do_blend(1);
--- 354,365 ----
    DownloadSurface(src);
    txi = GetTexInfo(src);
+   // PG_LogDBG("ParaGUI[%s]: %s:%i %p", __FILE__, __FUNCTION__, __LINE__, 
txi);
+   if (txi == NULL) {
+     exit(-1);
+     return 0;
+   };
  
    /* Set up blending */
!   if (src->GetSDLFlags() & (SDL_SRCALPHA | SDL_SRCCOLORKEY)) {
      gl_blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      gl_do_blend(1);
***************
*** 417,423 ****
     * and alpha channel in combination - to stay SDL 2D compatible.
     */
!   if ((src->flags & SDL_SRCALPHA) &&
!       (!src->format->Amask || (src->flags & SDL_SRCCOLORKEY)))
!     alpha = src->format->alpha;
    else
      alpha = 255;
--- 399,405 ----
     * and alpha channel in combination - to stay SDL 2D compatible.
     */
!   if ((src->GetSDLFlags() & SDL_SRCALPHA) &&
!       (!src->GetFormat()->Amask || (src->GetSDLFlags() & SDL_SRCCOLORKEY)))
!     alpha = src->GetFormat()->alpha;
    else
      alpha = 255;
***************
*** 450,478 ****
  
  /* Download a single texture. */
! int PG_GLDraw::_DownloadTexture(SDL_Surface *datasurf,
                                glSDL_TexInfo *txi, int tex) {
    enum { _None=0, _Bitmap=1, _Pal=2, _GreyAlpha=3, _RGBx=4 } surftype = _None;
    int bpp;
!   Uint32 rowlength;
!   bpp = datasurf->format->BytesPerPixel;
!   if (datasurf->pixels == NULL) {
      DBG5(PG_LogMSG("%s:%i debug: NULL surface? issit sdlroot?", __FUNCTION__, 
__LINE__));
      return 0; /* only the root surface has this BUT... */
    };
    // DBG5(DBGFUNC());
!   // DBG5(PG_LogMSG("%s:%i %p: %i x %i x %i : tile (%i,%i)", __FUNCTION__, 
__LINE__, datasurf->pixels, datasurf->w, datasurf->h, bpp, txi->tilew, 
txi->tileh));
    // return 0; // DEBUG
  
    // DBG5(PG_LogMSG("%s:%i %p:%p[%i]", __FUNCTION__, __LINE__, txi, 
txi->texture, tex));
  
!   glGenTextures(1, &txi->texture[tex]);
    // DBG5(DBGLINE());
    glBindTexture(GL_TEXTURE_2D, txi->texture[tex]);
  
!   if (datasurf->format->BitsPerPixel == 1) {
      surftype = _Bitmap;
!   } else if(datasurf->format->BitsPerPixel == 8) {
      surftype = _Pal;
!   } else if((datasurf->format->BitsPerPixel == 16) && 
(datasurf->format->Amask) && (!datasurf->format->Bmask)) {
      surftype = _GreyAlpha;
    } else {
--- 432,477 ----
  
  /* Download a single texture. */
! int PG_GLDraw::_DownloadTexture(PG_GLDrawableSurface* datasurf,
                                glSDL_TexInfo *txi, int tex) {
+   SDL_Color refpal[256];
    enum { _None=0, _Bitmap=1, _Pal=2, _GreyAlpha=3, _RGBx=4 } surftype = _None;
    int bpp;
!   Uint32 rowlength, pitch, dw, dh;
!   SDL_PixelFormat *pf;
!   Uint8* pixels;
!   pf    = datasurf->GetFormat();
!   bpp   = pf->BytesPerPixel;
!   pitch = datasurf->GetPitch();
!   pixels = (Uint8*)(datasurf->GetPixels());
!   dw     = datasurf->GetWidth();
!   dh     = datasurf->GetHeight();
!   if ((pixels == NULL) || (!pitch)) {
      DBG5(PG_LogMSG("%s:%i debug: NULL surface? issit sdlroot?", __FUNCTION__, 
__LINE__));
      return 0; /* only the root surface has this BUT... */
    };
    // DBG5(DBGFUNC());
!   // DBG5(PG_LogMSG("%s:%i %p: %i x %i x %i : tile (%i,%i)", __FUNCTION__, 
__LINE__, pixels, dw, dh, bpp, txi->tilew, txi->tileh));
    // return 0; // DEBUG
  
+   // PG_LogMSG("%s:%i %p: %i x %i x %i : tile (%i,%i)", __FUNCTION__, 
__LINE__, pixels, dw, dh, bpp, txi->tilew, txi->tileh);
+ 
    // DBG5(PG_LogMSG("%s:%i %p:%p[%i]", __FUNCTION__, __LINE__, txi, 
txi->texture, tex));
  
!   // glGenTextures(1, &(txi->texture[tex]));
!   glGenTextures(1, txi->texture + tex);
!   // PG_LogMSG("%s:%i %p[%i]", __FUNCTION__, __LINE__, txi->texture, tex);
!   // PG_LogMSG("%s:%i %i", __FUNCTION__, __LINE__, txi->texture[tex]);
!   /* FIXME - just catch -this- bogus answer... 0 is not valid by spec but some
!    * OpenGL systems provide anyways.  Much safer not to IMHO */
!   // if (txi->texture[tex] == 0) glGenTextures(1, &txi->texture[tex]);
!   DBG(_print_glerror(1));
    // DBG5(DBGLINE());
    glBindTexture(GL_TEXTURE_2D, txi->texture[tex]);
  
!   if (pf->BitsPerPixel == 1) {
      surftype = _Bitmap;
!   } else if(pf->BitsPerPixel == 8) {
      surftype = _Pal;
!   } else if((pf->BitsPerPixel == 16) && (pf->Amask) && (!pf->Bmask)) {
      surftype = _GreyAlpha;
    } else {
***************
*** 483,491 ****
    if (surftype == _None) return -2;
    if (surftype == _Bitmap) {
!     rowlength = datasurf->pitch;
    } else {
!     rowlength = datasurf->pitch / bpp;
    };
!   // PG_LogDBG("ParaGUI[%s]: %s:%i pitch %i bpp %i", __FILE__, __FUNCTION__, 
__LINE__, datasurf->pitch, bpp);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
--- 482,490 ----
    if (surftype == _None) return -2;
    if (surftype == _Bitmap) {
!     rowlength = pitch;
    } else {
!     rowlength = pitch / bpp;
    };
!   // PG_LogDBG("ParaGUI[%s]: %s:%i pitch %i bpp %i", __FILE__, __FUNCTION__, 
__LINE__, pitch, bpp);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
***************
*** 496,527 ****
    case _Bitmap: {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, txi->texsize, txi->texsize, 
0, GL_LUMINANCE,
!                GL_UNSIGNED_BYTE, NULL);
!     DBG(_print_glerror(1));
      break;
    };
    case _Pal: {
  #ifdef GL_VERSION_1_2
!     if (datasurf->format->palette != NULL) {
!       glColorTable(GL_TEXTURE_2D,GL_RGBA,
!                  datasurf->format->palette->ncolors,
!                  GL_RGBA,GL_UNSIGNED_BYTE,
!                  datasurf->format->palette->colors);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
                   txi->texsize, txi->texsize, 0, GL_COLOR_INDEX,
                   GL_UNSIGNED_BYTE, NULL);
!       DBG(_print_glerror(1));
        break;
      };
  #else
  #ifdef GL_EXT_paletted_texture
!     if (datasurf->format->palette != NULL) {
!       glColorTableEXT(GL_TEXTURE_2D,GL_RGBA,
!                     datasurf->format->palette->ncolors,
!                     GL_RGBA,GL_UNSIGNED_BYTE,
!                     datasurf->format->palette->colors);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
                   txi->texsize, txi->texsize, 0, GL_COLOR_INDEX,
                   GL_UNSIGNED_BYTE, NULL);
!       DBG(_print_glerror(1));
        break;
      };
--- 495,534 ----
    case _Bitmap: {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, txi->texsize, txi->texsize, 
0, GL_LUMINANCE,
!                GL_BITMAP, NULL);
!     DBG(_print_glerror(2));
      break;
    };
    case _Pal: {
+     int       ncolors;
+     SDL_Color *colors;
+     ncolors = pf->palette->ncolors;
+     colors  = pf->palette->colors;
+     if (ncolors < 256) {
+       colors = refpal;
+       memcpy(colors, pf->palette->colors, pf->palette->ncolors);
+     };
  #ifdef GL_VERSION_1_2
!     if (pf->palette != NULL) {
!       // PG_LogDBG("ParaGUI[%s]: %s:%i pal[%i]:%p", __FILE__, __FUNCTION__, 
__LINE__, pf->palette->ncolors, pf->palette->colors);
!       glColorTable(GL_TEXTURE_2D,GL_RGBA8,   256,
!                  GL_RGBA,GL_UNSIGNED_BYTE, colors);
!       DBG(_print_glerror(301));
        glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
                   txi->texsize, txi->texsize, 0, GL_COLOR_INDEX,
                   GL_UNSIGNED_BYTE, NULL);
!       DBG(_print_glerror(302));
!       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
        break;
      };
  #else
  #ifdef GL_EXT_paletted_texture
!     if (pf->palette != NULL) {
!       glColorTableEXT(GL_TEXTURE_2D,GL_RGBA,    256,
!                     GL_RGBA,GL_UNSIGNED_BYTE, colors);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
                   txi->texsize, txi->texsize, 0, GL_COLOR_INDEX,
                   GL_UNSIGNED_BYTE, NULL);
!       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
!       DBG(_print_glerror(4));
        break;
      };
***************
*** 531,535 ****
                 txi->texsize, txi->texsize, 0, GL_LUMINANCE,
                 GL_UNSIGNED_BYTE, NULL);
!     DBG(_print_glerror(1));
      break;
    };
--- 538,542 ----
                 txi->texsize, txi->texsize, 0, GL_LUMINANCE,
                 GL_UNSIGNED_BYTE, NULL);
!     DBG(_print_glerror(5));
      break;
    };
***************
*** 538,557 ****
                 txi->texsize, txi->texsize, 0, GL_LUMINANCE_ALPHA,
                 GL_UNSIGNED_BYTE, NULL);
!     DBG(_print_glerror(1));
      break;
    };
    case _RGBx: {
- #if 0
-     DBG5(PG_LogMSG("amask %s size %ix%i form %s",
-                  datasurf->format->Amask ? "GL_RGBA8" : "GL_RGB8",
-                  txi->texsize, txi->texsize,
-                  datasurf->format->Amask ? "GL_RGBA" : "GL_RGB"));
- #endif
      glTexImage2D(GL_TEXTURE_2D, 0,
!                datasurf->format->Amask ? GL_RGBA8 : GL_RGB8,
                 txi->texsize, txi->texsize, 0,
!                datasurf->format->Amask ? GL_RGBA : GL_RGB,
                 GL_UNSIGNED_BYTE, NULL);
!     DBG(_print_glerror(1));
      break;
    };
--- 545,558 ----
                 txi->texsize, txi->texsize, 0, GL_LUMINANCE_ALPHA,
                 GL_UNSIGNED_BYTE, NULL);
!     DBG(_print_glerror(6));
      break;
    };
    case _RGBx: {
      glTexImage2D(GL_TEXTURE_2D, 0,
!                pf->Amask ? GL_RGBA8 : GL_RGB8,
                 txi->texsize, txi->texsize, 0,
!                pf->Amask ? GL_RGBA : GL_RGB,
                 GL_UNSIGNED_BYTE, NULL);
!     DBG(_print_glerror(7));
      break;
    };
***************
*** 565,580 ****
        int fromx = txi->tilew * tex * txi->tilespertex;
        int toy = 0;
!       // DBG5(PG_LogMSG("fromx %i yoff %i bpp %i on %p", fromx, toy, bpp, 
datasurf->pixels));
        while(toy + txi->tileh <= txi->texsize) {
          int thistw;
!         thistw = datasurf->w - fromx;
          if (thistw > txi->tilew) thistw = txi->tilew;
          else if (thistw <= 0)    break;
- #if 0
-         glBindTexture(GL_TEXTURE_2D, txi->texture[tex]);
-         glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
-         /* glPixelStorei(GL_UNPACK_SKIP_ROWS, toy ); */
-         /* glPixelStorei(GL_UNPACK_SKIP_PIXELS, textures[i].skip_pixels ); */
- #endif
          switch (surftype) {
          case _Bitmap: {
--- 566,575 ----
        int fromx = txi->tilew * tex * txi->tilespertex;
        int toy = 0;
!       // DBG5(PG_LogMSG("fromx %i yoff %i bpp %i on %p", fromx, toy, bpp, 
pixels));
        while(toy + txi->tileh <= txi->texsize) {
          int thistw;
!         thistw = dw - fromx;
          if (thistw > txi->tilew) thistw = txi->tilew;
          else if (thistw <= 0)    break;
          switch (surftype) {
          case _Bitmap: {
***************
*** 584,607 ****
                            GL_LUMINANCE,
                            GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + bpp * fromx);
!           DBG(_print_glerror(2));
            break;
          };
          case _Pal: {
  #ifdef GL_VERSION_1_2
!           if (datasurf->format->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D,0,0,toy,thistw,txi->tileh,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)datasurf->pixels + bpp * fromx);
!             DBG(_print_glerror(2));
              break;
            };
  #else
  #ifdef GL_EXT_paletted_texture
!           if (datasurf->format->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D,0,0,toy,thistw,txi->tileh,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)datasurf->pixels + bpp * fromx);
!             DBG(_print_glerror(2));
              break;
            };
--- 579,602 ----
                            GL_LUMINANCE,
                            GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + bpp * fromx);
!           DBG(_print_glerror(8));
            break;
          };
          case _Pal: {
  #ifdef GL_VERSION_1_2
!           if (pf->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D,0,0,toy,thistw,txi->tileh,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)pixels + bpp * fromx);
!             DBG(_print_glerror(9));
              break;
            };
  #else
  #ifdef GL_EXT_paletted_texture
!           if (pf->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D,0,0,toy,thistw,txi->tileh,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)pixels + bpp * fromx);
!             DBG(_print_glerror(10));
              break;
            };
***************
*** 610,615 ****
            glTexSubImage2D(GL_TEXTURE_2D, 0,0, toy,thistw, txi->tileh,
                            GL_LUMINANCE, GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + bpp * fromx);
!           DBG(_print_glerror(2));
            break;
          };
--- 605,610 ----
            glTexSubImage2D(GL_TEXTURE_2D, 0,0, toy,thistw, txi->tileh,
                            GL_LUMINANCE, GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + bpp * fromx);
!           DBG(_print_glerror(11));
            break;
          };
***************
*** 617,631 ****
            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, toy, thistw, txi->tileh,
                            GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + bpp * fromx);
!           DBG(_print_glerror(2));
            break;
          };
          case _RGBx: {
            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, toy, thistw, txi->tileh,
!                           datasurf->format->Amask ? GL_RGBA : GL_RGB,
                            GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + bpp * fromx);
!           /*             ((Uint8 *)datasurf->pixels) + (bpp * fromx)); */
!           DBG4(_print_glerror(2));
            break;
          };
--- 612,628 ----
            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, toy, thistw, txi->tileh,
                            GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + bpp * fromx);
!           DBG(_print_glerror(12));
            break;
          };
          case _RGBx: {
+ #if 1
            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, toy, thistw, txi->tileh,
!                           pf->Amask ? GL_RGBA : GL_RGB,
                            GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + bpp * fromx);
!           /*             ((Uint8 *)pixels) + (bpp * fromx)); */
!           DBG4(_print_glerror(13));
! #endif
            break;
          };
***************
*** 647,685 ****
        while (tox + txi->tilew <= txi->texsize) {
          int thisth;
!         thisth = datasurf->h - fromy;
          if (thisth > txi->tileh)
            thisth = txi->tileh;
          else if(thisth <= 0)
            break;
- #if 0
-         glBindTexture(GL_TEXTURE_2D, txi->texture[tex]);
-         glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
-         /* glPixelStorei(GL_UNPACK_SKIP_ROWS, toy ); */
-         /* glPixelStorei(GL_UNPACK_SKIP_PIXELS, textures[i].skip_pixels ); */
- #endif
          switch (surftype) {
          case _Bitmap: {
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                            GL_LUMINANCE, GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + (datasurf->pitch * 
fromy));
!           DBG(_print_glerror(3));
            break;
          };
          case _Pal: {
  #ifdef GL_VERSION_1_2
!           if (datasurf->format->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)datasurf->pixels + (datasurf->pitch * 
fromy));
!             DBG(_print_glerror(3));
              break;
            };
  #else
  #ifdef GL_EXT_paletted_texture
!           if (datasurf->format->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)datasurf->pixels + (datasurf->pitch * 
fromy));
!             DBG(_print_glerror(3));
              break;
            };
--- 644,676 ----
        while (tox + txi->tilew <= txi->texsize) {
          int thisth;
!         thisth = dh - fromy;
          if (thisth > txi->tileh)
            thisth = txi->tileh;
          else if(thisth <= 0)
            break;
          switch (surftype) {
          case _Bitmap: {
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                            GL_LUMINANCE, GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + (pitch * fromy));
!           DBG(_print_glerror(14));
            break;
          };
          case _Pal: {
  #ifdef GL_VERSION_1_2
!           if (pf->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)pixels + (pitch * fromy));
!             DBG(_print_glerror(15));
              break;
            };
  #else
  #ifdef GL_EXT_paletted_texture
!           if (pf->palette != NULL) {
              glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                              GL_COLOR_INDEX,GL_UNSIGNED_BYTE,
!                             (Uint8 *)pixels + (pitch * fromy));
!             DBG(_print_glerror(16));
              break;
            };
***************
*** 688,693 ****
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                            GL_LUMINANCE, GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + (datasurf->pitch * 
fromy));
!           DBG(_print_glerror(3));
            break;
          };
--- 679,684 ----
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                            GL_LUMINANCE, GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + (pitch * fromy));
!           DBG(_print_glerror(17));
            break;
          };
***************
*** 695,713 ****
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                            GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + (datasurf->pitch * 
fromy));
!           DBG(_print_glerror(3));
            break;
          };
          case _RGBx: {
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
!                           datasurf->format->Amask ? GL_RGBA : GL_RGB,
                            GL_UNSIGNED_BYTE,
!                           (Uint8 *)datasurf->pixels + (datasurf->pitch * 
fromy));
!           DBG4(_print_glerror(3));
            break;
          };
          case _None: return -2;
          };
!         DBG4(_print_glerror(3));
          fromy += txi->tileh;
          tox += txi->tilew;
--- 686,704 ----
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
                            GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + (pitch * fromy));
!           DBG(_print_glerror(18));
            break;
          };
          case _RGBx: {
            glTexSubImage2D(GL_TEXTURE_2D, 0, tox, 0, txi->tilew, thisth,
!                           pf->Amask ? GL_RGBA : GL_RGB,
                            GL_UNSIGNED_BYTE,
!                           (Uint8 *)pixels + (pitch * fromy));
!           DBG4(_print_glerror(19));
            break;
          };
          case _None: return -2;
          };
!         DBG4(_print_glerror(20));
          fromy += txi->tileh;
          tox += txi->tilew;
***************
*** 727,734 ****
  }
  
! int PG_GLDraw::DownloadSurface(SDL_Surface *surface) {
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return 0; // DEBUG
!   SDL_Surface *datasurf = surface;
    PG_DrawableSurface* tmp = NULL;
    glSDL_TexInfo *txi;
--- 718,725 ----
  }
  
! int PG_GLDraw::DownloadSurface(PG_GLDrawableSurface* surface) {
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return 0; // DEBUG
!   PG_GLDrawableSurface* datasurf = surface;
    PG_DrawableSurface* tmp = NULL;
    glSDL_TexInfo *txi;
***************
*** 750,753 ****
--- 741,746 ----
      /* AddTexInfo(surface); */
    };
+   // PG_LogDBG("ParaGUI[%s]: %s:%i downloading texture %i", __FILE__, 
__FUNCTION__, __LINE__, surface->unused1);
+   // PG_LogDBG("ParaGUI[%s]: %s:%i downloading texture %i", __FILE__, 
__FUNCTION__, __LINE__, surface->texi);
    txi = GetTexInfo(surface);
    if (txi == NULL) { PG_LogERR("GetTexInfo returned NULL!!!!"); return -1; };
***************
*** 783,787 ****
     *  preferably one that makes DMA w/o conversion possible.
     */
!   if (_FormatIsOk(surface))
      datasurf = surface;
    else {
--- 776,780 ----
     *  preferably one that makes DMA w/o conversion possible.
     */
!   if (_FormatIsOk(surface->SDL()))
      datasurf = surface;
    else {
***************
*** 795,802 ****
      */
      DBG(PG_LogWRN("ParaGUI GLcore: WARNING: On-the-fly conversion 
performed!"));
!     tmp = AccelDrawableSurface(surface, surface->format->Amask);
      // DBG5(DBGLINE());
      if (!tmp) return -2;
!     datasurf = tmp->SDL();
    }
    /* {
--- 788,795 ----
      */
      DBG(PG_LogWRN("ParaGUI GLcore: WARNING: On-the-fly conversion 
performed!"));
!     tmp = AccelerateSurface(surface, surface->GetFormat()->Amask);
      // DBG5(DBGLINE());
      if (!tmp) return -2;
!     datasurf = dynamic_cast<PG_GLDrawableSurface*>(tmp); // datasurf = 
tmp->SDL();
    }
    /* {
***************
*** 820,829 ****
    int i;
    for (i = 0; i < txi->textures; ++i)
!     if (txi->texture[i] != GLSDL_NOTEX)
        glDeleteTextures(1, &txi->texture[i]);
    memset(&txi->invalid_area, 0, sizeof(txi->invalid_area));
  }
  
! void PG_GLDraw::UnloadSurface(SDL_Surface *surface) {
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return; // DEBUG
--- 813,824 ----
    int i;
    for (i = 0; i < txi->textures; ++i)
!     if (txi->texture[i] != GLSDL_NOTEX) {
!       // PG_LogDBG("ParaGUI[%s]: %s:%i deleting[%i] %i", __FILE__, 
__FUNCTION__, __LINE__, i, txi->texture[i]);
        glDeleteTextures(1, &txi->texture[i]);
+     };
    memset(&txi->invalid_area, 0, sizeof(txi->invalid_area));
  }
  
! void PG_GLDraw::UnloadSurface(PG_GLDrawableSurface* surface) {
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return; // DEBUG

Index: pgglroot.cpp
===================================================================
RCS file: /cvsroot/paragui/paragui/src/draw/opengl/Attic/pgglroot.cpp,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -r1.1.2.6 -r1.1.2.7
*** pgglroot.cpp        4 Nov 2002 10:58:32 -0000       1.1.2.6
--- pgglroot.cpp        9 Nov 2002 12:00:35 -0000       1.1.2.7
***************
*** 137,141 ****
  void PG_GLRootDrawableSurface::SetLogicSize(int w, int h) {
    PG_Rect r;
!   DBGLINE();
  
    r.x = r.y = 0;
--- 137,141 ----
  void PG_GLRootDrawableSurface::SetLogicSize(int w, int h) {
    PG_Rect r;
!   // DBGLINE();
  
    r.x = r.y = 0;
***************
*** 143,147 ****
    r.h = h;
    SetClipRect(r);
!   DBGLINE();
  
    glMatrixMode(GL_MODELVIEW);
--- 143,147 ----
    r.h = h;
    SetClipRect(r);
!   // DBGLINE();
  
    glMatrixMode(GL_MODELVIEW);
***************
*** 152,158 ****
    glDisable(GL_CULL_FACE);
    
!   DBGLINE();
    host->gl_reset();
!   DBGLINE();
  }
  
--- 152,158 ----
    glDisable(GL_CULL_FACE);
    
!   // DBGLINE();
    host->gl_reset();
!   // DBGLINE();
  }
  
***************
*** 170,186 ****
  
    SDL_bool res;
-   SDL_Surface *screen;
    SDL_Rect* trect;
    if (ref == NULL) ref=SDL_GetVideoSurface();
    
!   screen = SDL_GetVideoSurface();
!   
!   res = SDL_SetClipRect(screen, (SDL_Rect*)&rect);
    if (!res) return SDL_FALSE;
!   trect = &screen->clip_rect;
    
    float xscale, yscale;
    glViewport( trect->x * scale,
!               screen->h - (trect->y + trect->h) * scale,
                trect->w * scale,
                trect->h * scale);
--- 170,183 ----
  
    SDL_bool res;
    SDL_Rect* trect;
    if (ref == NULL) ref=SDL_GetVideoSurface();
    
!   res = SDL_SetClipRect(ref, (SDL_Rect*)&rect);
    if (!res) return SDL_FALSE;
!   trect = &ref->clip_rect;
    
    float xscale, yscale;
    glViewport( trect->x * scale,
!               ref->h - (trect->y + trect->h) * scale,
                trect->w * scale,
                trect->h * scale);
***************
*** 306,313 ****
--- 303,312 ----
    // PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
    // return; // DEBUG
+ #if 0
    SDL_Rect* a;
    SDL_Rect* b;
    a = (rect_src.IsNull()) ? NULL : (PG_Rect*)&rect_src;
    b = (rect_dst.IsNull()) ? NULL : (PG_Rect*)&rect_dst;
+ #endif
  
    if (ref == NULL) ref=SDL_GetVideoSurface();
***************
*** 350,354 ****
      return;
    } else {
!     host->_BlitGL((SDL_Surface*)srf_src, a, ref, b);
    }
  };
--- 349,364 ----
      return;
    } else {
!     PG_DrawableSurface* tmp;
!     PG_GLDrawableSurface* datasurf;
!     tmp = host->AccelDrawableSurface((SDL_Surface*)srf_src, 
srf_src->format->Amask);
!     // DBG5(DBGLINE());
!     if (!tmp) return;
!     datasurf = dynamic_cast<PG_GLDrawableSurface*>(tmp); // datasurf = 
tmp->SDL();
!     BlitSurface(datasurf, rect_src, rect_dst);
!     // host->_BlitGL(datasurf, a, this, b);
!     datasurf = NULL;
!     delete tmp;
! 
!     // host->_BlitGL((SDL_Surface*)srf_src, a, ref, b);
    }
  };
***************
*** 383,388 ****
    if (ref == NULL) ref=SDL_GetVideoSurface();
    /* FIXME theres' a better way to do this... I'm just bored */
!   PG_GLDrawableSurface* p = (PG_GLDrawableSurface*)srf_src;
!   const SDL_Surface* src = p->SDL();
  
    SDL_Rect* a;
--- 393,398 ----
    if (ref == NULL) ref=SDL_GetVideoSurface();
    /* FIXME theres' a better way to do this... I'm just bored */
!   PG_GLDrawableSurface* p = (PG_GLDrawableSurface*)(dynamic_cast<const 
PG_GLDrawableSurface*>(srf_src));
!   // const SDL_Surface* src = p->SDL();
  
    SDL_Rect* a;
***************
*** 421,430 ****
     *      surface->surface:       SDL_BlitSurface()
     */
!   if (src == ref) {
      DBG(PG_LogERR("glSDL_BlitSurface(): screen->screen"
                  " blits not yet implemented!"));
      return;
    } else {
!     host->_BlitGL((SDL_Surface*)src, a, ref, b);
    }
  };
--- 431,440 ----
     *      surface->surface:       SDL_BlitSurface()
     */
!   if (srf_src == this) {
      DBG(PG_LogERR("glSDL_BlitSurface(): screen->screen"
                  " blits not yet implemented!"));
      return;
    } else {
!     host->_BlitGL(p, a, this, b);
    }
  };

Index: pgglsurf.cpp
===================================================================
RCS file: /cvsroot/paragui/paragui/src/draw/opengl/Attic/pgglsurf.cpp,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -C2 -r1.1.2.8 -r1.1.2.9
*** pgglsurf.cpp        8 Nov 2002 11:22:01 -0000       1.1.2.8
--- pgglsurf.cpp        9 Nov 2002 12:00:35 -0000       1.1.2.9
***************
*** 53,69 ****
   */
  
! PG_GLDrawableSurface::PG_GLDrawableSurface(PG_GLDraw* refhost) : 
PG_DrawableSurface(), scale(1), isgrey(false) { host=refhost; };
    /* PG_GLDrawableSurface::PG_GLDrawableSurface(SDL_Surface* s) : 
PG_DrawableSurface(s), scale(1) { host=NULL; }; */
  PG_GLDrawableSurface::PG_GLDrawableSurface(PG_GLDraw* refhost, SDL_Surface* s)
!   : PG_DrawableSurface(s), scale(1), isgrey(false) {
    ref = s;
    host = refhost;
  };
  
  PG_GLDrawableSurface::~PG_GLDrawableSurface() {
    if ((ref != NULL) && (host != NULL)) {
!     /* host->FreeTexInfo(ref); */
!     host->_FreeSurface(ref);
!     ref = NULL;
    };
  };
--- 53,79 ----
   */
  
! PG_GLDrawableSurface::PG_GLDrawableSurface(PG_GLDraw* refhost)
!   : PG_DrawableSurface(), scale(1), isgrey(false), texi(0) {
!   host=refhost;
! };
    /* PG_GLDrawableSurface::PG_GLDrawableSurface(SDL_Surface* s) : 
PG_DrawableSurface(s), scale(1) { host=NULL; }; */
  PG_GLDrawableSurface::PG_GLDrawableSurface(PG_GLDraw* refhost, SDL_Surface* s)
!   : PG_DrawableSurface(s), scale(1), isgrey(false), texi(0) {
    ref = s;
    host = refhost;
+ 
+   switch (host->AddTexInfo(this)) {
+   case 0: break;
+   case -1: PG_LogERR("AddTexInfo returned: no screen"); break;
+   case -2: PG_LogERR("AddTexInfo returned: no texinfo"); break;
+   case -3: PG_LogERR("AddTexInfo returned: calc chop fail"); break;
+   };
  };
  
  PG_GLDrawableSurface::~PG_GLDrawableSurface() {
    if ((ref != NULL) && (host != NULL)) {
!     host->FreeTexInfo(this);
!     /* host->_FreeSurface(ref); */
!     /* ref = NULL; */
    };
  };
***************
*** 208,212 ****
    if (!ref) return;
    SDL_UnlockSurface(ref);
!   host->DownloadSurface(ref);
  };
  
--- 218,222 ----
    if (!ref) return;
    SDL_UnlockSurface(ref);
!   host->DownloadSurface(this);
  };
  
***************
*** 237,241 ****
     * *unless* you keep modifying the surface.
     */
!   host->FreeTexInfo(ref);
    return res;
  };
--- 247,251 ----
     * *unless* you keep modifying the surface.
     */
!   host->FreeTexInfo(this);
    return res;
  };
***************
*** 289,293 ****
    glSDL_TexInfo *txi;
    if (!ref) return;
!   txi = host->GetTexInfo(ref);
    if (!txi) return;
    if (area.IsNull()) {
--- 299,303 ----
    glSDL_TexInfo *txi;
    if (!ref) return;
!   txi = GetTexInfo();
    if (!txi) return;
    if (area.IsNull()) {
***************
*** 304,308 ****
    PG_Rect r;
    glSDL_TexInfo *txi;
!   txi = host->GetTexInfo(surface);
    
    txi->lw = w;
--- 314,318 ----
    PG_Rect r;
    glSDL_TexInfo *txi;
!   txi = GetTexInfo();
    
    txi->lw = w;
***************
*** 312,316 ****
  glSDL_TexInfo *PG_GLDrawableSurface::GetTexInfo() {
    glSDL_TexInfo *rv;
!   rv = host->GetTexInfo(ref);
    return rv;
  };
--- 322,326 ----
  glSDL_TexInfo *PG_GLDrawableSurface::GetTexInfo() {
    glSDL_TexInfo *rv;
!   rv = host->GetTexInfo(this);
    return rv;
  };
***************
*** 426,429 ****
--- 436,440 ----
                                        PG_Rect *ClipRect) {
    int         x,y;
+   Uint32        pitch
    Uint32      *raw_pixels;
    PG_Rect     TargetPos;
***************
*** 482,487 ****
  #if 0
        host->my_charSurface = host->CreateDrawableSurface(SDL_SRCALPHA, 
BitmapRealWidth, Bitmap->rows, 32, 0xff0000, 0xff00, 0xff, 0xff000000);
! #endif
        host->my_charSurface = host->CreateDrawableSurfaceAlpha(hx, hy);
        if (host->my_charSurface == NULL) {
        PG_LogWRN("Can`t get char surface : %s",SDL_GetError());
--- 493,503 ----
  #if 0
        host->my_charSurface = host->CreateDrawableSurface(SDL_SRCALPHA, 
BitmapRealWidth, Bitmap->rows, 32, 0xff0000, 0xff00, 0xff, 0xff000000);
! #else
! #if 1
        host->my_charSurface = host->CreateDrawableSurfaceAlpha(hx, hy);
+ #else
+       host->my_charSurface = host->CreateDrawableSurface(hx, hy);
+ #endif
+ #endif
        if (host->my_charSurface == NULL) {
        PG_LogWRN("Can`t get char surface : %s",SDL_GetError());
***************
*** 523,527 ****
      SourcePos.y += delta;
    }
!   
    raw_pixels = (Uint32 *) host->my_charSurface->GetPixels();
    Uint32 pitch_diff = 0;
--- 539,544 ----
      SourcePos.y += delta;
    }
! 
!   pitch      = host->my_charSurface->GetPitch() / 4;
    raw_pixels = (Uint32 *) host->my_charSurface->GetPixels();
    Uint32 pitch_diff = 0;
***************
*** 544,553 ****
          //    a = (a * Param->GetAlpha()) / 255;
          
!         raw_pixels[int(ioffset) + x + 
(host->my_charSurface->GetPitch()/4)*(y)] = 
host->my_charSurface->MapRGBA(Param->GetColor().r, Param->GetColor().g, 
Param->GetColor().b, a);
        }
        SrcPix -= x;
        }
      } else
!       pitch_diff = (host->my_charSurface->GetPitch()/4);
      
      for (y = 0; y < Bitmap->rows; y++, SrcPix += Bitmap->pitch) {
--- 561,570 ----
          //    a = (a * Param->GetAlpha()) / 255;
          
!         raw_pixels[int(ioffset) + x + pitch*(y)] = 
host->my_charSurface->MapRGBA(Param->GetColor().r, Param->GetColor().g, 
Param->GetColor().b, a);
        }
        SrcPix -= x;
        }
      } else
!       pitch_diff = pitch;
      
      for (y = 0; y < Bitmap->rows; y++, SrcPix += Bitmap->pitch) {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]