Move compiler.h and imports.h/c from src/mesa/main into src/util
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_tex.c
index c66e5d17b12379ba8ca2ea4dba53e7d0734b410f..3db6cbeb71ec7fde26d2bb8078887981dd260801 100644 (file)
@@ -32,13 +32,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #include "main/glheader.h"
-#include "main/imports.h"
-#include "main/colormac.h"
+#include "util/imports.h"
 #include "main/context.h"
 #include "main/enums.h"
 #include "main/image.h"
-#include "main/simple_list.h"
-#include "main/texstore.h"
 #include "main/teximage.h"
 #include "main/texobj.h"
 
@@ -47,7 +44,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "radeon_ioctl.h"
 #include "radeon_tex.h"
 
-#include "xmlpool.h"
+#include "util/xmlpool.h"
 
 
 
@@ -96,40 +93,42 @@ static void radeonSetTexWrap( radeonTexObjPtr t, GLenum swrap, GLenum twrap )
       is_clamp_to_border = GL_TRUE;
       break;
    default:
-      _mesa_problem(NULL, "bad S wrap mode in %s", __FUNCTION__);
+      _mesa_problem(NULL, "bad S wrap mode in %s", __func__);
    }
 
-   switch ( twrap ) {
-   case GL_REPEAT:
-      t->pp_txfilter |= RADEON_CLAMP_T_WRAP;
-      break;
-   case GL_CLAMP:
-      t->pp_txfilter |= RADEON_CLAMP_T_CLAMP_GL;
-      is_clamp = GL_TRUE;
-      break;
-   case GL_CLAMP_TO_EDGE:
-      t->pp_txfilter |= RADEON_CLAMP_T_CLAMP_LAST;
-      break;
-   case GL_CLAMP_TO_BORDER:
-      t->pp_txfilter |= RADEON_CLAMP_T_CLAMP_GL;
-      is_clamp_to_border = GL_TRUE;
-      break;
-   case GL_MIRRORED_REPEAT:
-      t->pp_txfilter |= RADEON_CLAMP_T_MIRROR;
-      break;
-   case GL_MIRROR_CLAMP_EXT:
-      t->pp_txfilter |= RADEON_CLAMP_T_MIRROR_CLAMP_GL;
-      is_clamp = GL_TRUE;
-      break;
-   case GL_MIRROR_CLAMP_TO_EDGE_EXT:
-      t->pp_txfilter |= RADEON_CLAMP_T_MIRROR_CLAMP_LAST;
-      break;
-   case GL_MIRROR_CLAMP_TO_BORDER_EXT:
-      t->pp_txfilter |= RADEON_CLAMP_T_MIRROR_CLAMP_GL;
-      is_clamp_to_border = GL_TRUE;
-      break;
-   default:
-      _mesa_problem(NULL, "bad T wrap mode in %s", __FUNCTION__);
+   if (t->base.Target != GL_TEXTURE_1D) {
+      switch ( twrap ) {
+      case GL_REPEAT:
+        t->pp_txfilter |= RADEON_CLAMP_T_WRAP;
+        break;
+      case GL_CLAMP:
+        t->pp_txfilter |= RADEON_CLAMP_T_CLAMP_GL;
+        is_clamp = GL_TRUE;
+        break;
+      case GL_CLAMP_TO_EDGE:
+        t->pp_txfilter |= RADEON_CLAMP_T_CLAMP_LAST;
+        break;
+      case GL_CLAMP_TO_BORDER:
+        t->pp_txfilter |= RADEON_CLAMP_T_CLAMP_GL;
+        is_clamp_to_border = GL_TRUE;
+        break;
+      case GL_MIRRORED_REPEAT:
+        t->pp_txfilter |= RADEON_CLAMP_T_MIRROR;
+        break;
+      case GL_MIRROR_CLAMP_EXT:
+        t->pp_txfilter |= RADEON_CLAMP_T_MIRROR_CLAMP_GL;
+        is_clamp = GL_TRUE;
+        break;
+      case GL_MIRROR_CLAMP_TO_EDGE_EXT:
+        t->pp_txfilter |= RADEON_CLAMP_T_MIRROR_CLAMP_LAST;
+        break;
+      case GL_MIRROR_CLAMP_TO_BORDER_EXT:
+        t->pp_txfilter |= RADEON_CLAMP_T_MIRROR_CLAMP_GL;
+        is_clamp_to_border = GL_TRUE;
+        break;
+      default:
+        _mesa_problem(NULL, "bad T wrap mode in %s", __func__);
+      }
    }
 
    if ( is_clamp_to_border ) {
@@ -253,23 +252,24 @@ static void radeonSetTexBorderColor( radeonTexObjPtr t, const GLfloat color[4] )
 #define SCALED_FLOAT_TO_BYTE( x, scale ) \
                (((GLuint)((255.0F / scale) * (x))) / 2)
 
-static void radeonTexEnv( GLcontext *ctx, GLenum target,
+static void radeonTexEnv( struct gl_context *ctx, GLenum target,
                          GLenum pname, const GLfloat *param )
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
    GLuint unit = ctx->Texture.CurrentUnit;
-   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+   struct gl_fixedfunc_texture_unit *texUnit =
+      &ctx->Texture.FixedFuncUnit[unit];
 
    if ( RADEON_DEBUG & RADEON_STATE ) {
       fprintf( stderr, "%s( %s )\n",
-              __FUNCTION__, _mesa_lookup_enum_by_nr( pname ) );
+              __func__, _mesa_enum_to_string( pname ) );
    }
 
    switch ( pname ) {
    case GL_TEXTURE_ENV_COLOR: {
       GLubyte c[4];
       GLuint envColor;
-      UNCLAMPED_FLOAT_TO_RGBA_CHAN( c, texUnit->EnvColor );
+      _mesa_unclamped_float_rgba_to_ubyte(c, texUnit->EnvColor);
       envColor = radeonPackColor( 4, c[0], c[1], c[2], c[3] );
       if ( rmesa->hw.tex[unit].cmd[TEX_PP_TFACTOR] != envColor ) {
         RADEON_STATECHANGE( rmesa, tex[unit] );
@@ -310,38 +310,33 @@ static void radeonTexEnv( GLcontext *ctx, GLenum target,
    }
 }
 
+void radeonTexUpdateParameters(struct gl_context *ctx, GLuint unit)
+{
+   struct gl_sampler_object *samp = _mesa_get_samplerobj(ctx, unit);
+   radeonTexObj* t = radeon_tex_obj(ctx->Texture.Unit[unit]._Current);
+
+   radeonSetTexMaxAnisotropy(t , samp->MaxAnisotropy);
+   radeonSetTexFilter(t, samp->MinFilter, samp->MagFilter);
+   radeonSetTexWrap(t, samp->WrapS, samp->WrapT);
+   radeonSetTexBorderColor(t, samp->BorderColor.f);
+}
+
 
 /**
  * Changes variables and flags for a state update, which will happen at the
  * next UpdateTextureState
  */
 
-static void radeonTexParameter( GLcontext *ctx, GLenum target,
+static void radeonTexParameter( struct gl_context *ctx,
                                struct gl_texture_object *texObj,
-                               GLenum pname, const GLfloat *params )
+                               GLenum pname )
 {
    radeonTexObj* t = radeon_tex_obj(texObj);
 
-   radeon_print(RADEON_TEXTURE, RADEON_VERBOSE, "%s( %s )\n", __FUNCTION__,
-              _mesa_lookup_enum_by_nr( pname ) );
+   radeon_print(RADEON_TEXTURE, RADEON_VERBOSE, "%s( %s )\n", __func__,
+              _mesa_enum_to_string( pname ) );
 
    switch ( pname ) {
-   case GL_TEXTURE_MIN_FILTER:
-   case GL_TEXTURE_MAG_FILTER:
-   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
-      radeonSetTexMaxAnisotropy( t, texObj->MaxAnisotropy );
-      radeonSetTexFilter( t, texObj->MinFilter, texObj->MagFilter );
-      break;
-
-   case GL_TEXTURE_WRAP_S:
-   case GL_TEXTURE_WRAP_T:
-      radeonSetTexWrap( t, texObj->WrapS, texObj->WrapT );
-      break;
-
-   case GL_TEXTURE_BORDER_COLOR:
-      radeonSetTexBorderColor( t, texObj->BorderColor.f );
-      break;
-
    case GL_TEXTURE_BASE_LEVEL:
    case GL_TEXTURE_MAX_LEVEL:
    case GL_TEXTURE_MIN_LOD:
@@ -354,7 +349,7 @@ static void radeonTexParameter( GLcontext *ctx, GLenum target,
    }
 }
 
-static void radeonDeleteTexture( GLcontext *ctx,
+static void radeonDeleteTexture( struct gl_context *ctx,
                                 struct gl_texture_object *texObj )
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
@@ -362,12 +357,12 @@ static void radeonDeleteTexture( GLcontext *ctx,
    int i;
 
    radeon_print(RADEON_TEXTURE, RADEON_NORMAL,
-        "%s( %p (target = %s) )\n", __FUNCTION__, (void *)texObj,
-              _mesa_lookup_enum_by_nr( texObj->Target ) );
+        "%s( %p (target = %s) )\n", __func__, (void *)texObj,
+              _mesa_enum_to_string( texObj->Target ) );
 
    if ( rmesa ) {
      radeon_firevertices(&rmesa->radeon);
-     for ( i = 0 ; i < rmesa->radeon.glCtx->Const.MaxTextureUnits ; i++ ) {
+     for ( i = 0 ; i < rmesa->radeon.glCtx.Const.MaxTextureUnits ; i++ ) {
        if ( t == rmesa->state.texture.unit[i].texobj ) {
         rmesa->state.texture.unit[i].texobj = NULL;
         rmesa->hw.tex[i].dirty = GL_FALSE;
@@ -392,7 +387,7 @@ static void radeonDeleteTexture( GLcontext *ctx,
  * Basically impossible to do this on the fly - just collect some
  * basic info & do the checks from ValidateState().
  */
-static void radeonTexGen( GLcontext *ctx,
+static void radeonTexGen( struct gl_context *ctx,
                          GLenum coord,
                          GLenum pname,
                          const GLfloat *params )
@@ -409,13 +404,13 @@ static void radeonTexGen( GLcontext *ctx,
  * texture object from the core mesa gl_texture_object.  Not done at this time.
  */
 static struct gl_texture_object *
-radeonNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
+radeonNewTextureObject( struct gl_context *ctx, GLuint name, GLenum target )
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
    radeonTexObj* t = CALLOC_STRUCT(radeon_tex_obj);
 
-   _mesa_initialize_texture_object(&t->base, name, target);
-   t->base.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
+   _mesa_initialize_texture_object(ctx, &t->base, name, target);
+   t->base.Sampler.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
 
    t->border_fallback = GL_FALSE;
 
@@ -423,24 +418,28 @@ radeonNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
    t->pp_txformat = (RADEON_TXFORMAT_ENDIAN_NO_SWAP |
                     RADEON_TXFORMAT_PERSPECTIVE_ENABLE);
    
-   radeonSetTexWrap( t, t->base.WrapS, t->base.WrapT );
-   radeonSetTexMaxAnisotropy( t, t->base.MaxAnisotropy );
-   radeonSetTexFilter( t, t->base.MinFilter, t->base.MagFilter );
-   radeonSetTexBorderColor( t, t->base.BorderColor.f );
+   radeonSetTexWrap( t, t->base.Sampler.WrapS, t->base.Sampler.WrapT );
+   radeonSetTexMaxAnisotropy( t, t->base.Sampler.MaxAnisotropy );
+   radeonSetTexFilter( t, t->base.Sampler.MinFilter, t->base.Sampler.MagFilter );
+   radeonSetTexBorderColor( t, t->base.Sampler.BorderColor.f );
    return &t->base;
 }
 
 
+static struct gl_sampler_object *
+radeonNewSamplerObject(struct gl_context *ctx, GLuint name)
+{
+   r100ContextPtr rmesa = R100_CONTEXT(ctx);
+   struct gl_sampler_object *samp = _mesa_new_sampler_object(ctx, name);
+   if (samp)
+      samp->MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
+   return samp;
+}
+
 
 void radeonInitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *functions )
 {
-   functions->ChooseTextureFormat      = radeonChooseTextureFormat_mesa;
-   functions->TexImage1D               = radeonTexImage1D;
-   functions->TexImage2D               = radeonTexImage2D;
-   functions->TexSubImage1D            = radeonTexSubImage1D;
-   functions->TexSubImage2D            = radeonTexSubImage2D;
-   functions->GetTexImage               = radeonGetTexImage;
-   functions->GetCompressedTexImage     = radeonGetCompressedTexImage;
+   radeon_init_common_texture_funcs(radeon, functions);
 
    functions->NewTextureObject         = radeonNewTextureObject;
    //   functions->BindTexture         = radeonBindTexture;
@@ -449,21 +448,5 @@ void radeonInitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *
    functions->TexEnv                   = radeonTexEnv;
    functions->TexParameter             = radeonTexParameter;
    functions->TexGen                   = radeonTexGen;
-
-   functions->CompressedTexImage2D     = radeonCompressedTexImage2D;
-   functions->CompressedTexSubImage2D  = radeonCompressedTexSubImage2D;
-
-   if (radeon->radeonScreen->kernel_mm) {
-      functions->CopyTexImage2D = radeonCopyTexImage2D;
-      functions->CopyTexSubImage2D = radeonCopyTexSubImage2D;
-   }
-
-   functions->GenerateMipmap = radeonGenerateMipmap;
-
-   functions->NewTextureImage = radeonNewTextureImage;
-   functions->FreeTexImageData = radeonFreeTexImageData;
-   functions->MapTexture = radeonMapTexture;
-   functions->UnmapTexture = radeonUnmapTexture;
-
-   driInitTextureFormats();
+   functions->NewSamplerObject         = radeonNewSamplerObject;
 }