Mark __driCreateNewScreen PUBLIC
[mesa.git] / src / mesa / drivers / dri / sis / sis_tex.c
index 13c82652ea04782828fbd68f12f32d1407340ed6..5fa8256f1ba0550308f236869146d3ae39a185ef 100644 (file)
@@ -38,8 +38,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "texformat.h"
 #include "texstore.h"
 #include "teximage.h"
+#include "texobj.h"
 
-#define ALIGN(value, align) (char *)((long)(value + align - 1) & ~(align - 1))
+#define ALIGN(value, align) (GLubyte *)((long)(value + align - 1) & ~(align - 1))
 
 #define TEXTURE_HW_ALIGNMENT 4
 #define TEXTURE_HW_PLUS (4 + 4)
@@ -84,7 +85,7 @@ sisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level,
          t->hwformat = TEXEL_ARGB_0888_32;
          break;
       default:
-         assert(0);
+         sis_fatal_error("Bad texture format.\n");
       }
    }
    assert(t->format == image->Format);
@@ -95,10 +96,8 @@ sisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level,
    addr = sisAllocFB( smesa, size, &t->image[level].handle );
    if (addr == NULL) {
       addr = sisAllocAGP( smesa, size, &t->image[level].handle );
-      if (addr == NULL) {
-         fprintf (stderr, "SIS driver : out of video/agp memory\n");
-         sis_fatal_error();
-      }
+      if (addr == NULL)
+         sis_fatal_error("Failure to allocate texture memory.\n");
       t->image[level].memType = AGP_TYPE;
    }
    else
@@ -138,7 +137,7 @@ sisFreeTexImage( sisContextPtr smesa, sisTexObjPtr t, int level )
 }
 
 static void 
-sisDDTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param )
+sisTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param )
 {
   sisContextPtr smesa = SIS_CONTEXT(ctx);
 
@@ -146,9 +145,9 @@ sisDDTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param )
 }
 
 static void
-sisDDTexParameter( GLcontext *ctx, GLenum target,
-                  struct gl_texture_object *texObj, GLenum pname,
-                  const GLfloat *params )
+sisTexParameter( GLcontext *ctx, GLenum target,
+                 struct gl_texture_object *texObj, GLenum pname,
+                 const GLfloat *params )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
 
@@ -156,21 +155,20 @@ sisDDTexParameter( GLcontext *ctx, GLenum target,
 }
 
 static void
-sisDDBindTexture( GLcontext *ctx, GLenum target,
-                 struct gl_texture_object *texObj )
+sisBindTexture( GLcontext *ctx, GLenum target,
+                struct gl_texture_object *texObj )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    sisTexObjPtr t;
 
    if ( target == GL_TEXTURE_2D || target == GL_TEXTURE_1D ) {
       if ( texObj->DriverData == NULL ) {
-        sisAllocTexObj( texObj );
+         sisAllocTexObj( texObj );
       }
    }
 
    t = texObj->DriverData;
-
-   if (t == NULL)
+   if (!t)
       return;
 
    if (smesa->PrevTexFormat[ctx->Texture.CurrentUnit] != t->format) {
@@ -181,7 +179,7 @@ sisDDBindTexture( GLcontext *ctx, GLenum target,
 }
 
 static void
-sisDDDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj )
+sisDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    sisTexObjPtr t;
@@ -193,7 +191,7 @@ sisDDDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj )
    if (t == NULL) {
       /* 
        * this shows the texture is default object and never be a 
-       * argument of sisDDTexImage*
+       * argument of sisTexImage*
        */
       return;
    }
@@ -207,14 +205,14 @@ sisDDDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj )
    _mesa_delete_texture_object(ctx, texObj);
 }
 
-static GLboolean sisDDIsTextureResident( GLcontext * ctx,
+static GLboolean sisIsTextureResident( GLcontext * ctx,
                                         struct gl_texture_object *texObj )
 {
   return (texObj->DriverData != NULL);
 }
 
 static const struct gl_texture_format *
-sisDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
+sisChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
                          GLenum format, GLenum type )
 {
    /* XXX 16-bit internal texture formats? */
@@ -274,7 +272,7 @@ sisDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    }
 }
 
-static void sisDDTexImage1D( GLcontext *ctx, GLenum target, GLint level,
+static void sisTexImage1D( GLcontext *ctx, GLenum target, GLint level,
                             GLint internalFormat,
                             GLint width, GLint border,
                             GLenum format, GLenum type, const GLvoid *pixels,
@@ -289,7 +287,7 @@ static void sisDDTexImage1D( GLcontext *ctx, GLenum target, GLint level,
       sisAllocTexObj( texObj );
    t = texObj->DriverData;
 
-   /* Note, this will call sisDDChooseTextureFormat */
+   /* Note, this will call sisChooseTextureFormat */
    _mesa_store_teximage1d( ctx, target, level, internalFormat,
                           width, border, format, type,
                           pixels, packing, texObj, texImage );
@@ -310,7 +308,7 @@ static void sisDDTexImage1D( GLcontext *ctx, GLenum target, GLint level,
 }
 
 
-static void sisDDTexSubImage1D( GLcontext *ctx,
+static void sisTexSubImage1D( GLcontext *ctx,
                                GLenum target,
                                GLint level,
                                GLint xoffset,
@@ -325,7 +323,8 @@ static void sisDDTexSubImage1D( GLcontext *ctx,
    sisTexObjPtr t;
    GLuint copySize;
    GLint texelBytes;
-   char *src, *dst;
+   const char *src;
+   GLubyte *dst;
 
    if ( texObj->DriverData == NULL )
       sisAllocTexObj( texObj );
@@ -358,7 +357,7 @@ static void sisDDTexSubImage1D( GLcontext *ctx,
    smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING;
 }
 
-static void sisDDTexImage2D( GLcontext *ctx, GLenum target, GLint level,
+static void sisTexImage2D( GLcontext *ctx, GLenum target, GLint level,
                             GLint internalFormat,
                             GLint width, GLint height, GLint border,
                             GLenum format, GLenum type, const GLvoid *pixels,
@@ -373,7 +372,7 @@ static void sisDDTexImage2D( GLcontext *ctx, GLenum target, GLint level,
       sisAllocTexObj( texObj );
    t = texObj->DriverData;
 
-   /* Note, this will call sisDDChooseTextureFormat */
+   /* Note, this will call sisChooseTextureFormat */
    _mesa_store_teximage2d(ctx, target, level, internalFormat,
                           width, height, border, format, type, pixels,
                           &ctx->Unpack, texObj, texImage);
@@ -393,7 +392,7 @@ static void sisDDTexImage2D( GLcontext *ctx, GLenum target, GLint level,
    smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING;
 }
 
-static void sisDDTexSubImage2D( GLcontext *ctx,
+static void sisTexSubImage2D( GLcontext *ctx,
                                GLenum target,
                                GLint level,
                                GLint xoffset, GLint yoffset,
@@ -408,7 +407,8 @@ static void sisDDTexSubImage2D( GLcontext *ctx,
    sisTexObjPtr t;
    GLuint copySize;
    GLint texelBytes;
-   char *src, *dst;
+   const char *src;
+   GLubyte *dst;
    int j;
    GLuint soffset;
 
@@ -448,28 +448,37 @@ static void sisDDTexSubImage2D( GLcontext *ctx,
       smesa->PrevTexFormat[ctx->Texture.CurrentUnit] = t->format;
    }
    smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING;
+}
+
 
+/**
+ * Allocate a new texture object.
+ * Called via ctx->Driver.NewTextureObject.
+ * Note: this function will be called during context creation to
+ * allocate the default texture objects.
+ * Note: we could use containment here to 'derive' the driver-specific
+ * texture object from the core mesa gl_texture_object.  Not done at this time.
+ */
+static struct gl_texture_object *
+sisNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
+{
+   struct gl_texture_object *obj;
+   obj = _mesa_new_texture_object(ctx, name, target);
+   return obj;
 }
 
-void sisDDInitTextureFuncs( GLcontext *ctx )
+
+void sisInitTextureFuncs( struct dd_function_table *functions )
 {
-   ctx->Driver.TexEnv                  = sisDDTexEnv;
-   ctx->Driver.ChooseTextureFormat     = sisDDChooseTextureFormat;
-   ctx->Driver.TexImage1D              = sisDDTexImage1D;
-   ctx->Driver.TexSubImage1D           = sisDDTexSubImage1D;
-   ctx->Driver.TexImage2D              = sisDDTexImage2D;
-   ctx->Driver.TexSubImage2D           = sisDDTexSubImage2D;
-   ctx->Driver.TexImage3D               = _mesa_store_teximage3d;
-   ctx->Driver.TexSubImage3D            = _mesa_store_texsubimage3d;
-   ctx->Driver.CopyTexImage1D           = _swrast_copy_teximage1d;
-   ctx->Driver.CopyTexImage2D           = _swrast_copy_teximage2d;
-   ctx->Driver.CopyTexSubImage1D        = _swrast_copy_texsubimage1d;
-   ctx->Driver.CopyTexSubImage2D        = _swrast_copy_texsubimage2d;
-   ctx->Driver.CopyTexSubImage3D        = _swrast_copy_texsubimage3d;
-   ctx->Driver.TestProxyTexImage        = _mesa_test_proxy_teximage;
-   ctx->Driver.TexParameter            = sisDDTexParameter;
-   ctx->Driver.BindTexture             = sisDDBindTexture;
-   ctx->Driver.DeleteTexture           = sisDDDeleteTexture;
-   ctx->Driver.IsTextureResident       = sisDDIsTextureResident;
-   ctx->Driver.PrioritizeTexture       = NULL;
+   functions->TexEnv                   = sisTexEnv;
+   functions->ChooseTextureFormat      = sisChooseTextureFormat;
+   functions->TexImage1D               = sisTexImage1D;
+   functions->TexSubImage1D            = sisTexSubImage1D;
+   functions->TexImage2D               = sisTexImage2D;
+   functions->TexSubImage2D            = sisTexSubImage2D;
+   functions->TexParameter             = sisTexParameter;
+   functions->BindTexture              = sisBindTexture;
+   functions->NewTextureObject         = sisNewTextureObject;
+   functions->DeleteTexture            = sisDeleteTexture;
+   functions->IsTextureResident        = sisIsTextureResident;
 }