gallium: added support for fixed-point formats, drawing
authorBrian Paul <brian.paul@tungstengraphics.com>
Mon, 23 Jun 2008 23:13:14 +0000 (17:13 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Mon, 23 Jun 2008 23:13:14 +0000 (17:13 -0600)
src/gallium/auxiliary/translate/translate_generic.c
src/gallium/include/pipe/p_format.h
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_draw.c

index 3fec89b36e9798a2e7ead97ab0205495a1a4442a..17e37d17458b27708bb5021596a8542ec8bb93f7 100644 (file)
@@ -121,6 +121,8 @@ emit_##NAME(const float *attrib, void *ptr)         \
 #define FROM_16_SNORM(i)   ((float) ((short *) ptr)[i] / 32767.0f)
 #define FROM_32_SNORM(i)   ((float) ((int *) ptr)[i] / 2147483647.0f)
 
+#define FROM_32_FIXED(i)   (((int *) ptr)[i] / 65536.0)
+
 #define TO_64_FLOAT(x)   ((double) x)
 #define TO_32_FLOAT(x)   (x)
 
@@ -140,6 +142,8 @@ emit_##NAME(const float *attrib, void *ptr)         \
 #define TO_16_SNORM(x)   ((short) (x * 32767.0f))
 #define TO_32_SNORM(x)   ((int) (x * 2147483647.0f))
 
+#define TO_32_FIXED(x)   ((int) (x * 65536.0f))
+
 
 
 ATTRIB( R64G64B64A64_FLOAT,   4, double, FROM_64_FLOAT, TO_64_FLOAT )
@@ -215,6 +219,11 @@ ATTRIB( R8_SNORM,        1, char, FROM_8_SNORM, TO_8_SNORM )
 ATTRIB( A8R8G8B8_UNORM,       4, ubyte, FROM_8_UNORM, TO_8_UNORM )
 //ATTRIB( R8G8B8A8_UNORM,       4, ubyte, FROM_8_UNORM, TO_8_UNORM )
 
+ATTRIB( R32G32B32A32_FIXED,   4, int, FROM_32_FIXED, TO_32_FIXED )
+ATTRIB( R32G32B32_FIXED,      3, int, FROM_32_FIXED, TO_32_FIXED )
+ATTRIB( R32G32_FIXED,         2, int, FROM_32_FIXED, TO_32_FIXED )
+ATTRIB( R32_FIXED,            1, int, FROM_32_FIXED, TO_32_FIXED )
+
 
 
 static void
@@ -386,6 +395,15 @@ static fetch_func get_fetch_func( enum pipe_format format )
    case PIPE_FORMAT_B8G8R8A8_UNORM:
       return &fetch_B8G8R8A8_UNORM;
 
+   case PIPE_FORMAT_R32_FIXED:
+      return &fetch_R32_FIXED;
+   case PIPE_FORMAT_R32G32_FIXED:
+      return &fetch_R32G32_FIXED;
+   case PIPE_FORMAT_R32G32B32_FIXED:
+      return &fetch_R32G32B32_FIXED;
+   case PIPE_FORMAT_R32G32B32A32_FIXED:
+      return &fetch_R32G32B32A32_FIXED;
+
    default:
       assert(0); 
       return &fetch_NULL;
index 579fdb2957f5f247233ae5e223b5f84d3efa4179..00aa02311c4031eeb0131e68599b02312fbf0434 100644 (file)
@@ -83,6 +83,7 @@ static INLINE uint pf_layout(uint f)  /**< PIPE_FORMAT_LAYOUT_ */
 #define PIPE_FORMAT_TYPE_USCALED 4  /**< uints, not normalized */
 #define PIPE_FORMAT_TYPE_SSCALED 5  /**< ints, not normalized */
 #define PIPE_FORMAT_TYPE_SRGB    6  /**< sRGB colorspace */
+#define PIPE_FORMAT_TYPE_FIXED   7  /**< 16.16 fixed point */
 
 
 /**
@@ -353,6 +354,10 @@ enum pipe_format {
    PIPE_FORMAT_R8G8B8_SSCALED        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ),
    PIPE_FORMAT_R8G8B8A8_SSCALED      = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ),
    PIPE_FORMAT_R8G8B8X8_SSCALED      = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ),
+   PIPE_FORMAT_R32_FIXED             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FIXED ),
+   PIPE_FORMAT_R32G32_FIXED          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FIXED ),
+   PIPE_FORMAT_R32G32B32_FIXED       = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FIXED ),
+   PIPE_FORMAT_R32G32B32A32_FIXED    = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FIXED ),
    /* sRGB formats */
    PIPE_FORMAT_L8_SRGB               = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SRGB ),
    PIPE_FORMAT_A8_L8_SRGB            = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ),
index da45a5e32136469a2dabe2ac91572b797ff8844c..7d52d1da1b61436d998d55134467f108588b2cd8 100644 (file)
@@ -1161,7 +1161,8 @@ do_copy_texsubimage(GLcontext *ctx,
 
    (void) texImage;
 
-   /* XX need this?   st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);*/
+   /* XX need this?*/
+   st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
 
    /* determine if copying depth or color data */
    if (baseFormat == GL_DEPTH_COMPONENT) {
index 5300848ef6a3b0ad890ff0ca67a721079d1332d7..6867d50c87366e5f86de16319e35ff1310c40632 100644 (file)
@@ -147,6 +147,14 @@ static GLuint byte_types_scale[4] = {
    PIPE_FORMAT_R8G8B8A8_SSCALED
 };
 
+static GLuint fixed_types[4] = {
+   PIPE_FORMAT_R32_FIXED,
+   PIPE_FORMAT_R32G32_FIXED,
+   PIPE_FORMAT_R32G32B32_FIXED,
+   PIPE_FORMAT_R32G32B32A32_FIXED
+};
+
+
 
 /**
  * Return a PIPE_FORMAT_x for the given GL datatype and size.
@@ -154,8 +162,8 @@ static GLuint byte_types_scale[4] = {
 static GLuint
 pipe_vertex_format(GLenum type, GLuint size, GLboolean normalized)
 {
-   assert(type >= GL_BYTE);
-   assert(type <= GL_DOUBLE);
+   assert((type >= GL_BYTE && type <= GL_DOUBLE) ||
+          type == GL_FIXED);
    assert(size >= 1);
    assert(size <= 4);
 
@@ -169,6 +177,7 @@ pipe_vertex_format(GLenum type, GLuint size, GLboolean normalized)
       case GL_UNSIGNED_INT: return uint_types_norm[size-1];
       case GL_UNSIGNED_SHORT: return ushort_types_norm[size-1];
       case GL_UNSIGNED_BYTE: return ubyte_types_norm[size-1];
+      case GL_FIXED: return fixed_types[size-1];
       default: assert(0); return 0;
       }      
    }
@@ -182,6 +191,7 @@ pipe_vertex_format(GLenum type, GLuint size, GLboolean normalized)
       case GL_UNSIGNED_INT: return uint_types_scale[size-1];
       case GL_UNSIGNED_SHORT: return ushort_types_scale[size-1];
       case GL_UNSIGNED_BYTE: return ubyte_types_scale[size-1];
+      case GL_FIXED: return fixed_types[size-1];
       default: assert(0); return 0;
       }      
    }