[cairo-commit] libglc/src glc.c,1.9,1.10 glc_glx_context.c,1.4,1.5 glc_glx_format.c,1.3,1.4 glc_glx_info.c,1.4,1.5 glc_glx_surface.c,1.5,1.6 glc_surface.c,1.5,1.6 glc_texture.c,1.3,1.4 glc_util.c,1.3,1.4 glcint.h,1.7,1.8

David Reveman commit at pdx.freedesktop.org
Mon Dec 8 13:03:35 PST 2003


Committed by: davidr

Update of /cvs/cairo/libglc/src
In directory pdx:/tmp/cvs-serv23597/src

Modified Files:
	glc.c glc_glx_context.c glc_glx_format.c glc_glx_info.c 
	glc_glx_surface.c glc_surface.c glc_texture.c glc_util.c 
	glcint.h 
Log Message:
Texture format fixes

Index: glc.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** glc.c	7 Dec 2003 02:42:29 -0000	1.9
--- glc.c	8 Dec 2003 21:03:33 -0000	1.10
***************
*** 203,206 ****
--- 203,207 ----
    } else {
      texture = glc_texture_create (src->width, src->height,
+                                   glc_surface_get_texture_format (src),
                                    &texture_width,
                                    &texture_height);
***************
*** 223,226 ****
--- 224,228 ----
    glEnable (GL_TEXTURE_2D);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ 
    switch (src->filter) {
    case GLC_FILTER_FAST:
***************
*** 244,248 ****
    glScissor (clip.x1, dst->height - (clip.y1 + height),
               clip.x2 - clip.x1, clip.y2 - clip.y1);
!   glColorMask (src->red, src->green, src->blue, src->alpha);
  
    glc_set_operator (op);
--- 246,254 ----
    glScissor (clip.x1, dst->height - (clip.y1 + height),
               clip.x2 - clip.x1, clip.y2 - clip.y1);
!   
!   glColorMask (src->red? GL_TRUE: GL_FALSE,
!                src->green? GL_TRUE: GL_FALSE,
!                src->blue? GL_TRUE: GL_FALSE,
!                src->alpha? GL_TRUE: GL_FALSE);
  
    glc_set_operator (op);
***************
*** 365,369 ****
                       intersect_clip.y2 - intersect_clip.y1);
          }
! 
          glBegin (GL_QUADS);
          glTexCoord2d (0.0, height_factor);
--- 371,375 ----
                       intersect_clip.y2 - intersect_clip.y1);
          }
!         
          glBegin (GL_QUADS);
          glTexCoord2d (0.0, height_factor);
***************
*** 398,404 ****
               (tl.y < (y_dst + height)));  
    }
!   
    glDisable (GL_TEXTURE_2D);
  
    if (texture)
      glc_texture_destroy (texture);
--- 404,412 ----
               (tl.y < (y_dst + height)));  
    }
! 
    glDisable (GL_TEXTURE_2D);
  
+   glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ 
    if (texture)
      glc_texture_destroy (texture);

Index: glc_glx_context.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_glx_context.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** glc_glx_context.c	7 Dec 2003 02:42:29 -0000	1.4
--- glc_glx_context.c	8 Dec 2003 21:03:33 -0000	1.5
***************
*** 251,255 ****
      new_context_info->display = context->screen_info->display_info->display;
      new_context_info->drawable = drawable;
!     new_context_info->context = context->context;
    } else {
      new_context_info->display = screen_info->display_info->display;
--- 251,255 ----
      new_context_info->display = context->screen_info->display_info->display;
      new_context_info->drawable = drawable;
!     new_context_info->context = context->context;    
    } else {
      new_context_info->display = screen_info->display_info->display;
***************
*** 268,272 ****
        glXMakeCurrent (screen_info->context_stack->display,
                        screen_info->context_stack->drawable,
!                       screen_info->context_stack->context);
        screen_info->current_drawable = screen_info->context_stack->drawable;
        screen_info->current_context = screen_info->context_stack->context;
--- 268,272 ----
        glXMakeCurrent (screen_info->context_stack->display,
                        screen_info->context_stack->drawable,
!                       screen_info->context_stack->context);      
        screen_info->current_drawable = screen_info->context_stack->drawable;
        screen_info->current_context = screen_info->context_stack->context;

Index: glc_glx_format.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_glx_format.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** glc_glx_format.c	5 Dec 2003 01:55:31 -0000	1.3
--- glc_glx_format.c	8 Dec 2003 21:03:33 -0000	1.4
***************
*** 350,367 ****
  glc_glx_format_get_pixelsize (glc_glx_format_t *format)
  {
-   int size = 0;
- 
    if (format->type != GLC_GLX_FORMAT_TYPE_DIRECT)
      return 4;
!   
!   if (format->direct.red &&
!       format->direct.green &&
!       format->direct.blue)
!     size += 3;
!     
!   if (format->direct.alpha)
!     size += 1;
!   
!   return size;
  }
  
--- 350,360 ----
  glc_glx_format_get_pixelsize (glc_glx_format_t *format)
  {
    if (format->type != GLC_GLX_FORMAT_TYPE_DIRECT)
      return 4;
! 
!   return glc_get_pixelsize_from_components (format->direct.red,
!                                             format->direct.green,
!                                             format->direct.blue,
!                                             format->direct.alpha);
  }
  

Index: glc_glx_info.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_glx_info.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** glc_glx_info.c	5 Dec 2003 01:55:31 -0000	1.4
--- glc_glx_info.c	8 Dec 2003 21:03:33 -0000	1.5
***************
*** 121,129 ****
    Window window;
    XVisualInfo *vinfo;
!   static int attrib[] = { GLX_RGBA,
!                           GLX_RED_SIZE, 1,
!                           GLX_GREEN_SIZE, 1,
!                           GLX_BLUE_SIZE, 1,
!                           None };
    XSetWindowAttributes win_attrib;
    glc_glx_screen_info_t *screen_info;
--- 121,133 ----
    Window window;
    XVisualInfo *vinfo;
!   int attrib[] = {
!     GLX_RGBA,
!     GLX_RED_SIZE, 1,
!     GLX_GREEN_SIZE, 1,
!     GLX_BLUE_SIZE, 1,
!     GLX_DOUBLEBUFFER,
!     None
!   };
!   
    XSetWindowAttributes win_attrib;
    glc_glx_screen_info_t *screen_info;
***************
*** 147,151 ****
  
    vinfo = glXChooseVisual (display, screen, attrib);
!   /* XXX: Check if vinfo != NULL */
    
    win_attrib.colormap =
--- 151,159 ----
  
    vinfo = glXChooseVisual (display, screen, attrib);
!   if (! vinfo) {
!     attrib[7] = None;
!     vinfo = glXChooseVisual (display, screen, attrib);
!     /* XXX: Check if vinfo != NULL */
!   }
    
    win_attrib.colormap =

Index: glc_glx_surface.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_glx_surface.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** glc_glx_surface.c	7 Dec 2003 02:42:29 -0000	1.5
--- glc_glx_surface.c	8 Dec 2003 21:03:33 -0000	1.6
***************
*** 138,141 ****
--- 138,142 ----
      glc_texture_create (surface->base.width,
                          surface->base.height,
+                         glc_surface_get_texture_format (&surface->base),
                          &surface->base.real_width,
                          &surface->base.real_height);
***************
*** 385,427 ****
  }
  
- static GLenum
- _glc_glx_surface_get_glformat_from_pixelsize (int pixelsize)
- {
-   switch (pixelsize) {
-   case 1:
-     return GL_ALPHA;
-     break;
-   case 3:
-     return GL_RGB8;
-     break;
-   default:
-     return GL_RGBA8;
-     break;
-   }
- }
- 
- static GLenum
- _glc_glx_surface_get_inverted_glformat_from_pixelsize (int pixelsize)
- {
-   switch (pixelsize) {
-   case 1:
-     return GL_ALPHA;
-     break;
-   case 3:
-     return GL_BGR;
-     break;
-   default:
-     return GL_BGRA;
-     break;
-   }
- }
- 
- GLenum
- glc_glx_surface_get_glformat (glc_glx_surface_t *surface)
- {
-   int pixelsize = glc_glx_format_get_pixelsize (surface->format);
-   return _glc_glx_surface_get_glformat_from_pixelsize (pixelsize);
- }
- 
  void
  glc_glx_surface_read_pixels (glc_surface_t *surface,
--- 386,389 ----
***************
*** 433,438 ****
  {
    unsigned char *pixel_buf;
!   int i, rowstride, area_rowstride, pixelsize;
!   GLenum format;
    glc_glx_surface_t *glx_surface = (glc_glx_surface_t *) surface;
  
--- 395,401 ----
  {
    unsigned char *pixel_buf;
!   int rowstride, area_rowstride, pixelsize;
!   unsigned int i;
!   GLenum format, type;
    glc_glx_surface_t *glx_surface = (glc_glx_surface_t *) surface;
  
***************
*** 444,453 ****
  
    pixelsize = glc_glx_format_get_pixelsize (glx_surface->format);
!   format = _glc_glx_surface_get_inverted_glformat_from_pixelsize (pixelsize);
  
    /* We currently read the whole image to a temporary buffer and then
       copy the part we want, not very efficient. We only want to read the
!      area requested. I think it can be fixed with glPixelStore parameters.
!   */
    rowstride = surface->real_width * pixelsize;
    rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
--- 407,416 ----
  
    pixelsize = glc_glx_format_get_pixelsize (glx_surface->format);
!   format = glc_get_texture_format_from_pixelsize (pixelsize);
!   type = glc_get_texture_data_type_from_pixelsize (pixelsize);
  
    /* We currently read the whole image to a temporary buffer and then
       copy the part we want, not very efficient. We only want to read the
!      area requested. I think it can be fixed with glPixelStore parameters. */
    rowstride = surface->real_width * pixelsize;
    rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
***************
*** 459,469 ****
    if (surface->type != GLC_SURFACE_TEXTURE_TYPE) {
      glReadPixels (0, 0, surface->real_width, surface->real_height,
!                   format, GL_UNSIGNED_BYTE, pixel_buf);
    } else {
      glEnable (GL_TEXTURE_2D);
      glBindTexture (GL_TEXTURE_2D, surface->texture);
      glGetTexImage (GL_TEXTURE_2D, 0,
                     format,
!                    GL_UNSIGNED_BYTE,
                     pixel_buf);
    }
--- 422,437 ----
    if (surface->type != GLC_SURFACE_TEXTURE_TYPE) {
      glReadPixels (0, 0, surface->real_width, surface->real_height,
!                   format, type, pixel_buf);
    } else {
      glEnable (GL_TEXTURE_2D);
      glBindTexture (GL_TEXTURE_2D, surface->texture);
+ 
+     glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
+     glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
+     glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
+     
      glGetTexImage (GL_TEXTURE_2D, 0,
                     format,
!                    type,
                     pixel_buf);
    }
***************
*** 479,483 ****
              area_rowstride);
    
-   glc_surface_pop_current (surface);
    free (pixel_buf);
  }
--- 447,450 ----
***************
*** 495,499 ****
    glc_surface_t *dst, *offscreen = NULL;
    glc_glx_surface_t *glx_surface = (glc_glx_surface_t *) surface;
!   GLenum format;
    
    if (x < 0 || x > (glx_surface->base.width - (int) width) ||
--- 462,466 ----
    glc_surface_t *dst, *offscreen = NULL;
    glc_glx_surface_t *glx_surface = (glc_glx_surface_t *) surface;
!   GLenum format, type;
    
    if (x < 0 || x > (glx_surface->base.width - (int) width) ||
***************
*** 504,508 ****
   
    pixelsize = glc_glx_format_get_pixelsize (glx_surface->format);
!   format = _glc_glx_surface_get_inverted_glformat_from_pixelsize (pixelsize);
  
    rowstride = width * pixelsize;
--- 471,476 ----
   
    pixelsize = glc_glx_format_get_pixelsize (glx_surface->format);
!   format = glc_get_texture_format_from_pixelsize (pixelsize);
!   type = glc_get_texture_data_type_from_pixelsize (pixelsize);
  
    rowstride = width * pixelsize;
***************
*** 511,516 ****
    /* TODO: This is very ugly and I like to remove it as soon as possible.
       Needs some changes to texture handling, as images will become upside
!      down without it.
!   */
    pixel_buf = (unsigned char *) malloc (rowstride * height);
    for (i = 0; i < (int) height; i++)
--- 479,483 ----
    /* TODO: This is very ugly and I like to remove it as soon as possible.
       Needs some changes to texture handling, as images will become upside
!      down without it. */
    pixel_buf = (unsigned char *) malloc (rowstride * height);
    for (i = 0; i < (int) height; i++)
***************
*** 518,522 ****
              &pixels[(height - i - 1) * rowstride], rowstride);
  
!   /* TODO: use glDrawPixels instead of temporary texture surface. */
    if (glx_surface->base.type != GLC_SURFACE_TEXTURE_TYPE) {
      Display *display = glx_surface->screen_info->display_info->display;
--- 485,491 ----
              &pixels[(height - i - 1) * rowstride], rowstride);
  
!   /* TODO: use glDrawPixels instead of temporary texture surface.
!      glc_glx_surface_draw_pixels and glc_glx_surface_read_pixels can then
!      be move from the GLX backend into glc_surface.c */
    if (glx_surface->base.type != GLC_SURFACE_TEXTURE_TYPE) {
      Display *display = glx_surface->screen_info->display_info->display;
***************
*** 527,548 ****
                                                    glx_surface->base.width,
                                                    glx_surface->base.height);
-     
-     glc_surface_push_current (offscreen);
      dst = offscreen;
    } else
      dst = surface;
    
    glEnable (GL_TEXTURE_2D);
    glBindTexture (GL_TEXTURE_2D, dst->texture);
  
    glTexSubImage2D (GL_TEXTURE_2D, 0,
                     x, dst->height - y - height,
                     width, height,
!                    format,
!                    GL_UNSIGNED_BYTE,
                     pixel_buf);
    glFlush ();
  
    glDisable (GL_TEXTURE_2D);
    
    if (offscreen) {
--- 496,523 ----
                                                    glx_surface->base.width,
                                                    glx_surface->base.height);
      dst = offscreen;
    } else
      dst = surface;
+ 
+   glc_surface_push_current (dst);
    
    glEnable (GL_TEXTURE_2D);
    glBindTexture (GL_TEXTURE_2D, dst->texture);
  
+   glPixelStorei (GL_PACK_ROW_LENGTH, 0);
+   glPixelStorei (GL_PACK_SKIP_ROWS, 0);
+   glPixelStorei (GL_PACK_SKIP_PIXELS, 0);
+ 
    glTexSubImage2D (GL_TEXTURE_2D, 0,
                     x, dst->height - y - height,
                     width, height,
!                    format, type,
                     pixel_buf);
+ 
    glFlush ();
  
    glDisable (GL_TEXTURE_2D);
+ 
+   glc_surface_pop_current (dst);
    
    if (offscreen) {
***************
*** 557,561 ****
                     height);
  
-     glc_surface_pop_current (surface);
      glc_surface_destroy (offscreen);
    }
--- 532,535 ----

Index: glc_surface.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_surface.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** glc_surface.c	7 Dec 2003 02:42:29 -0000	1.5
--- glc_surface.c	8 Dec 2003 21:03:33 -0000	1.6
***************
*** 202,206 ****
    glDisable (GL_DEPTH_TEST); 
    glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
-   glDisable (GL_LINE_SMOOTH);
    glDisable (GL_CULL_FACE);
    glDepthMask (GL_FALSE);
--- 202,205 ----
***************
*** 209,210 ****
--- 208,221 ----
    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  }
+ 
+ GLenum
+ glc_surface_get_texture_format (glc_surface_t *surface)
+ {
+   int pixelsize =
+     glc_get_pixelsize_from_components (surface->red,
+                                        surface->green,
+                                        surface->blue,
+                                        surface->alpha);
+   
+   return glc_get_texture_format_from_pixelsize (pixelsize);
+ }

Index: glc_texture.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_texture.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** glc_texture.c	4 Dec 2003 12:55:29 -0000	1.3
--- glc_texture.c	8 Dec 2003 21:03:33 -0000	1.4
***************
*** 48,51 ****
--- 48,52 ----
  _glc_texture_find_best_size (int width,
                               int height,
+                              GLenum texture_format,
                               int *real_width,
                               int *real_height)
***************
*** 62,66 ****
      glTexImage2D (GL_PROXY_TEXTURE_2D, 0, GL_RGBA,
                    test_width, test_height,
!                   0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
        
      w_ok = h_ok = 0;
--- 63,67 ----
      glTexImage2D (GL_PROXY_TEXTURE_2D, 0, GL_RGBA,
                    test_width, test_height,
!                   0, texture_format, GL_UNSIGNED_BYTE, NULL);
        
      w_ok = h_ok = 0;
***************
*** 92,95 ****
--- 93,97 ----
  glc_texture_create (int width,
                      int height,
+                     GLenum texture_format,
                      int *texture_width,
                      int *texture_height)
***************
*** 97,109 ****
    GLuint texture;
    
!   if (_glc_texture_find_best_size (width, height,
                                     texture_width, texture_height)) {
      
      glGenTextures (1, &texture);
      glBindTexture (GL_TEXTURE_2D, texture);
!     
      glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
                    *texture_width, *texture_height,
!                   0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
      
      return texture;
--- 99,111 ----
    GLuint texture;
    
!   if (_glc_texture_find_best_size (width, height, texture_format,
                                     texture_width, texture_height)) {
      
      glGenTextures (1, &texture);
      glBindTexture (GL_TEXTURE_2D, texture);
! 
      glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
                    *texture_width, *texture_height,
!                   0, texture_format, GL_UNSIGNED_BYTE, NULL);
      
      return texture;

Index: glc_util.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** glc_util.c	5 Dec 2003 15:22:16 -0000	1.3
--- glc_util.c	8 Dec 2003 21:03:33 -0000	1.4
***************
*** 79,81 ****
      return_box->y1 = return_box->y2 = 0;
  }
!                          
--- 79,138 ----
      return_box->y1 = return_box->y2 = 0;
  }
! 
! int
! glc_get_pixelsize_from_components (int red,
!                                    int green,
!                                    int blue,
!                                    int alpha)
! {
!   int size = 0;
!   
!   if (red && green && blue)
!     size += 3;
!     
!   if (alpha)
!     size += 1;
!   
!   return size;
! }
! 
! static int
! big_endian (void)
! {
!   int a = 1;
!   char *c;
!   
!   c = (char *) &a;
!   if (c[0])
!     return 0;
!   else
!     return 1;
! }
! 
! GLenum
! glc_get_texture_format_from_pixelsize (int pixelsize)
! {
!   switch (pixelsize) {
!   case 1:
!     return GL_ALPHA;
!     break;
!   case 3:
!     if (big_endian ())
!       return GL_RGB;
!     else
!       return GL_BGR;
!     break;
!   default:
!     return GL_BGRA;
!     break;
!   }
! }
! 
! GLenum
! glc_get_texture_data_type_from_pixelsize (int pixelsize)
! {
!   if (pixelsize == 4 && big_endian ())
!     return GL_UNSIGNED_INT_8_8_8_8_REV;
!   else
!     return GL_UNSIGNED_BYTE;
! }

Index: glcint.h
===================================================================
RCS file: /cvs/cairo/libglc/src/glcint.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** glcint.h	5 Dec 2003 15:22:16 -0000	1.7
--- glcint.h	8 Dec 2003 21:03:33 -0000	1.8
***************
*** 117,123 ****
--- 117,135 ----
                        glc_region_box_t *return_box);
  
+ extern int __internal_linkage
+ glc_get_pixelsize_from_components (int red,
+                                    int green,
+                                    int blue,
+                                    int alpha);
+ extern GLenum __internal_linkage
+ glc_get_texture_format_from_pixelsize (int pixelsize);
+ 
+ extern GLenum __internal_linkage
+ glc_get_texture_data_type_from_pixelsize (int pixelsize);
+ 
  extern GLuint __internal_linkage
  glc_texture_create (int width,
                      int height,
+                     GLenum texture_format,
                      int *texture_width,
                      int *texture_height);
***************
*** 159,162 ****
--- 171,177 ----
  glc_surface_setup_environment (glc_surface_t *surface);
  
+ extern GLenum __internal_linkage
+ glc_surface_get_texture_format (glc_surface_t *surface);
+ 
  extern glc_status_t __internal_linkage
  glc_status_pop_from_mask (long int *mask);
***************
*** 317,323 ****
  glc_glx_query_formats (glc_glx_screen_info_t *screen_info);
  
- extern GLenum __internal_linkage
- glc_glx_surface_get_glformat (glc_glx_surface_t *surface);
- 
  extern GLXPbuffer __internal_linkage
  glc_glx_pbuffer_create (Display *display,
--- 332,335 ----





More information about the cairo-commit mailing list