[PATCH] Add back support for GL_ARB_texture_rectangle



Revert most of:

    2008-06-06  Matthew Allum  <mallum openedhand com>

            Bug #948 - Remove texture rectangle support

GL_EXT_texture_for_pixmap only works with GL_ARGB_texture_rectangle on
many systems, either because of HW limitations (General NPOT textures
are not supported on older ATI cards), or because of driver bugs.

Changes to clutter_texture_new_from_actor() are not reverted; setting
disable-slicing there is pretty much orthogonal to texture_rectangle
and works fine with the rest of the revert.
---
 clutter/clutter-feature.c                |    3 +
 clutter/clutter-feature.h                |    1 +
 clutter/cogl/gl/cogl-texture.c           |   69 ++++++++++++++++++++++++++----
 clutter/cogl/gl/cogl.c                   |   15 ++++++-
 clutter/glx/clutter-glx-texture-pixmap.c |   13 +++---
 5 files changed, 85 insertions(+), 16 deletions(-)

diff --git a/clutter/clutter-feature.c b/clutter/clutter-feature.c
index 54ac41e..10edfe9 100644
--- a/clutter/clutter-feature.c
+++ b/clutter/clutter-feature.c
@@ -58,6 +58,9 @@ _clutter_features_from_cogl (guint cogl_flags)
 {
   ClutterFeatureFlags clutter_flags = 0;
   
+  if (cogl_flags & COGL_FEATURE_TEXTURE_RECTANGLE)
+    clutter_flags |= CLUTTER_FEATURE_TEXTURE_RECTANGLE;
+  
   if (cogl_flags & COGL_FEATURE_TEXTURE_NPOT)
     clutter_flags |= CLUTTER_FEATURE_TEXTURE_NPOT;
 
diff --git a/clutter/clutter-feature.h b/clutter/clutter-feature.h
index 89be737..0276fcf 100644
--- a/clutter/clutter-feature.h
+++ b/clutter/clutter-feature.h
@@ -57,6 +57,7 @@ G_BEGIN_DECLS
  */
 typedef enum 
 {
+  CLUTTER_FEATURE_TEXTURE_RECTANGLE      = (1 << 1),
   CLUTTER_FEATURE_TEXTURE_NPOT           = (1 << 2),
   CLUTTER_FEATURE_SYNC_TO_VBLANK         = (1 << 3),
   CLUTTER_FEATURE_TEXTURE_YUV            = (1 << 4),
diff --git a/clutter/cogl/gl/cogl-texture.c b/clutter/cogl/gl/cogl-texture.c
index 3bdf3bd..7cae747 100644
--- a/clutter/cogl/gl/cogl-texture.c
+++ b/clutter/cogl/gl/cogl-texture.c
@@ -752,7 +752,20 @@ _cogl_texture_size_supported (GLenum gl_target,
 			      int    width,
 			      int    height)
 {
-if (gl_target ==  GL_TEXTURE_2D)
+  if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
+    {
+      /* There is no proxy rectangle texture target so best we can
+       * do is to check against the safest value (although depending
+       * on our specific format and type the size could be supported
+       * when it seems it is not) */
+      
+      GLint max_size = 0;
+
+      GE( glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &max_size) );
+
+      return (max_size && width <= max_size && height <= max_size);
+    }
+  else if (gl_target ==  GL_TEXTURE_2D)
     {
       /* Proxy texture allows for a quick check for supported size */
       
@@ -801,6 +814,13 @@ _cogl_texture_slices_create (CoglTexture *tex)
       tex->gl_target  = GL_TEXTURE_2D;
       slices_for_size = _cogl_rect_slices_for_size;
     }
+  else if (cogl_features_available (COGL_FEATURE_TEXTURE_RECTANGLE))
+    {
+      max_width = tex->bitmap.width;
+      max_height = tex->bitmap.height;
+      tex->gl_target = GL_TEXTURE_RECTANGLE_ARB;
+      slices_for_size = _cogl_rect_slices_for_size;
+    }
   else
     {
       max_width = cogl_util_next_p2 (tex->bitmap.width);
@@ -1423,7 +1443,8 @@ cogl_texture_new_from_foreign (GLuint           gl_handle,
   CoglTexSliceSpan y_span;
   
   /* Allow 2-dimensional textures only */
-  if (gl_target != GL_TEXTURE_2D)
+  if (gl_target != GL_TEXTURE_2D &&
+      gl_target != GL_TEXTURE_RECTANGLE_ARB)
     return COGL_INVALID_HANDLE;
   
   /* Make sure it is a valid GL texture object */
@@ -1942,7 +1963,10 @@ _cogl_texture_quad_sw (CoglTexture *tex,
 #endif
   
   /* Prepare GL state */
-  enable_flags |= COGL_ENABLE_TEXTURE_2D;
+  if (tex->gl_target == GL_TEXTURE_RECTANGLE_ARB)
+    enable_flags |= COGL_ENABLE_TEXTURE_RECT;
+  else
+    enable_flags |= COGL_ENABLE_TEXTURE_2D;
   
   if (ctx->color_alpha < 255
       || tex->bitmap.format & COGL_A_BIT)
@@ -1998,8 +2022,11 @@ _cogl_texture_quad_sw (CoglTexture *tex,
       
       /* Normalize texture coordinates to current slice
          (rectangle texture targets take denormalized) */
-      slice_ty1 /= iter_y.span->size;
-      slice_ty2 /= iter_y.span->size;
+      if (tex->gl_target != GL_TEXTURE_RECTANGLE_ARB)
+	{
+	  slice_ty1 /= iter_y.span->size;
+	  slice_ty2 /= iter_y.span->size;
+	}
       
       
       /* Iterate until whole quad width covered */
@@ -2024,8 +2051,11 @@ _cogl_texture_quad_sw (CoglTexture *tex,
 	  
 	  /* Normalize texture coordinates to current slice
              (rectangle texture targets take denormalized) */
-          slice_tx1 /= iter_x.span->size;
-          slice_tx2 /= iter_x.span->size;
+	  if (tex->gl_target != GL_TEXTURE_RECTANGLE_ARB)
+	    {
+	      slice_tx1 /= iter_x.span->size;
+	      slice_tx2 /= iter_x.span->size;
+	    }
 	  
 #if COGL_DEBUG
 	  printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index);
@@ -2093,7 +2123,10 @@ _cogl_texture_quad_hw (CoglTexture *tex,
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
   
   /* Prepare GL state */
-  enable_flags |= COGL_ENABLE_TEXTURE_2D;
+  if (tex->gl_target == GL_TEXTURE_RECTANGLE_ARB)
+    enable_flags |= COGL_ENABLE_TEXTURE_RECT;
+  else
+    enable_flags |= COGL_ENABLE_TEXTURE_2D;
   
   if (ctx->color_alpha < 255
       || tex->bitmap.format & COGL_A_BIT)
@@ -2116,6 +2149,15 @@ _cogl_texture_quad_hw (CoglTexture *tex,
   ty1 = ty1 * (y_span->size - y_span->waste) / y_span->size;
   ty2 = ty2 * (y_span->size - y_span->waste) / y_span->size;
 
+  /* Denormalize texture coordinates for rectangle textures */
+  if (tex->gl_target == GL_TEXTURE_RECTANGLE_ARB)
+    {
+      tx1 *= x_span->size;
+      tx2 *= x_span->size;
+      ty1 *= y_span->size;
+      ty2 *= y_span->size;
+    }
+  
 #define CFX_F(x) CLUTTER_FIXED_TO_FLOAT(x)
   
   /* Draw textured quad */
@@ -2261,7 +2303,10 @@ cogl_texture_polygon (CoglHandle         handle,
   tex = _cogl_texture_pointer_from_handle (handle);
   
   /* Prepare GL state */
-  cogl_enable (COGL_ENABLE_TEXTURE_2D | COGL_ENABLE_BLEND);
+  if (tex->gl_target == GL_TEXTURE_RECTANGLE_ARB)
+    cogl_enable (COGL_ENABLE_TEXTURE_RECT | COGL_ENABLE_BLEND);
+  else
+    cogl_enable (COGL_ENABLE_TEXTURE_2D | COGL_ENABLE_BLEND);
 
   /* Temporarily change the wrapping mode on all of the slices to use
      a transparent border */
@@ -2310,6 +2355,12 @@ cogl_texture_polygon (CoglHandle         handle,
 		    - y_span->start / (GLfloat) tex->bitmap.height)
 		* tex->bitmap.height / y_span->size;
 
+	      if (tex->gl_target == GL_TEXTURE_RECTANGLE_ARB)
+		{
+		  tx *= x_span->size;
+		  ty *= y_span->size;
+		}
+
 	      glTexCoord2f (tx, ty);
 
 	      glVertex3f (CLUTTER_FIXED_TO_FLOAT (vertices[vnum].x),
diff --git a/clutter/cogl/gl/cogl.c b/clutter/cogl/gl/cogl.c
index 6906927..d56c306 100644
--- a/clutter/cogl/gl/cogl.c
+++ b/clutter/cogl/gl/cogl.c
@@ -323,6 +323,11 @@ cogl_enable (gulong flags)
 			   COGL_ENABLE_TEXCOORD_ARRAY,
 			   GL_TEXTURE_COORD_ARRAY);
   
+#ifdef GL_TEXTURE_RECTANGLE_ARB
+  cogl_toggle_flag (ctx, flags,
+		    COGL_ENABLE_TEXTURE_RECT,
+		    GL_TEXTURE_RECTANGLE_ARB);
+#endif
 }
 
 gulong
@@ -934,7 +939,15 @@ _cogl_features_init ()
 
   gl_extensions = (const gchar*) glGetString (GL_EXTENSIONS);
 
-  if (cogl_check_extension ("GL_ARB_texture_non_power_of_two", gl_extensions))
+#if defined(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB) && defined(GL_TEXTURE_RECTANGLE_ARB)
+  if (cogl_check_extension ("GL_ARB_texture_rectangle", gl_extensions) ||
+      cogl_check_extension ("GL_EXT_texture_rectangle", gl_extensions))
+    {
+      flags |= COGL_FEATURE_TEXTURE_RECTANGLE;
+    }
+#endif
+  
+  if (0 && cogl_check_extension ("GL_ARB_texture_non_power_of_two", gl_extensions))
     {
 #ifdef HAVE_CLUTTER_OSX
       if (really_enable_npot ())
diff --git a/clutter/glx/clutter-glx-texture-pixmap.c b/clutter/glx/clutter-glx-texture-pixmap.c
index 3ae6f54..0083fbf 100644
--- a/clutter/glx/clutter-glx-texture-pixmap.c
+++ b/clutter/glx/clutter-glx-texture-pixmap.c
@@ -548,7 +548,10 @@ clutter_glx_texture_pixmap_create_glx_pixmap (ClutterGLXTexturePixmap *texture)
 
   attribs[i++] = GLX_TEXTURE_TARGET_EXT;
 
-  attribs[i++] = GLX_TEXTURE_2D_EXT;
+  if (clutter_feature_available (COGL_FEATURE_TEXTURE_NPOT))
+    attribs[i++] = GLX_TEXTURE_2D_EXT;
+  else
+    attribs[i++] = GLX_TEXTURE_RECTANGLE_EXT;
 
   attribs[i++] = None;
 
@@ -715,11 +718,9 @@ clutter_glx_texture_pixmap_using_extension (ClutterGLXTexturePixmap *texture)
 
   priv = CLUTTER_GLX_TEXTURE_PIXMAP (texture)->priv;
 
-  return (_have_tex_from_pixmap_ext); 
-  /* Assume NPOT TFP's are supported even if regular NPOT isn't advertised 
-   * but tfp is. Seemingly some Intel drivers do this ?
-  */
-  /* && clutter_feature_available (COGL_FEATURE_TEXTURE_NPOT)); */
+  return (_have_tex_from_pixmap_ext
+	  && (clutter_feature_available (COGL_FEATURE_TEXTURE_NPOT)
+	      || clutter_feature_available (COGL_FEATURE_TEXTURE_RECTANGLE)));
 }
 
 /**
-- 
1.6.0.3


--=-1gOaMbTF0IoDctbcw5Ip
Content-Disposition: attachment; filename*0=0001-Support-GL_ARB_texture_rectangle-in-MutterShapedText.pat; filename*1=ch
Content-Type: text/x-patch; name="0001-Support-GL_ARB_texture_rectangle-in-MutterShapedText.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit



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