Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/mesa/teximage.c

    r2962 r3598  
    1 /* $Id: teximage.c,v 1.2 2000-03-01 18:49:36 jeroen Exp $ */
     1/* $Id: teximage.c,v 1.3 2000-05-23 20:40:55 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    2929#include "all.h"
    3030#else
    31 #ifndef XFree86Server
    32 #include <assert.h>
    33 #include <stdio.h>
    34 #include <stdlib.h>
    35 #include <string.h>
    36 #else
    37 #include "GL/xf86glx.h"
    38 #endif
     31#include "glheader.h"
    3932#include "types.h"
    4033#include "context.h"
    4134#include "image.h"
    42 #include "macros.h"
    4335#include "mmath.h"
    4436#include "span.h"
    4537#include "teximage.h"
    4638#include "texstate.h"
     39#include "mem.h"
    4740#endif
    4841
     
    5851
    5952
    60 
    61 static struct gl_pixelstore_attrib defaultPacking = {
    62    1,            /* Alignment */
    63    0,            /* RowLength */
    64    0,            /* SkipPixels */
    65    0,            /* SkipRows */
    66    0,            /* ImageHeight */
    67    0,            /* SkipImages */
    68    GL_FALSE,     /* SwapBytes */
    69    GL_FALSE      /* LsbFirst */
    70 };
    71 
    72 
    73 
    7453/*
    7554 * Compute log base 2 of n.
     
    7756 * If n<0 return -1.
    7857 */
    79 static int logbase2( int n )
     58static int
     59logbase2( int n )
    8060{
    8161   GLint i = 1;
     
    10686 * Return -1 if invalid enum.
    10787 */
    108 static GLint decode_internal_format( GLint format )
     88GLint
     89_mesa_base_tex_format( GLint format )
    10990{
    11091   switch (format) {
     
    178159 * number of components for the format.  Return -1 if invalid enum.
    179160 */
    180 static GLint components_in_intformat( GLint format )
     161static GLint
     162components_in_intformat( GLint format )
    181163{
    182164   switch (format) {
     
    244226
    245227
    246 struct gl_texture_image *gl_alloc_texture_image( void )
    247 {
    248    return CALLOC_STRUCT(gl_texture_image);
    249 }
    250 
    251 
    252 
    253 void gl_free_texture_image( struct gl_texture_image *teximage )
    254 {
    255    if (teximage->Data) {
    256       FREE( teximage->Data );
    257       teximage->Data = NULL;
    258    }
    259    FREE( teximage );
    260 }
    261 
    262 
    263 
    264228/*
    265229 * Examine the texImage->Format field and set the Red, Green, Blue, etc
     
    268232 * overwritting these fields to indicate true texel resolution.
    269233 */
    270 static void set_teximage_component_sizes( struct gl_texture_image *texImage )
     234static void
     235set_teximage_component_sizes( struct gl_texture_image *texImage )
    271236{
    272237   switch (texImage->Format) {
     
    370335
    371336
     337
     338/*
     339 * Return new gl_texture_image struct with all fields initialized to zero.
     340 */
     341struct gl_texture_image *
     342gl_alloc_texture_image( void )
     343{
     344   return CALLOC_STRUCT(gl_texture_image);
     345}
     346
     347
     348
     349/*
     350 * Initialize most fields of a gl_texture_image struct.
     351 */
     352static void
     353init_texture_image( struct gl_texture_image *img,
     354                    GLsizei width, GLsizei height, GLsizei depth,
     355                    GLint border, GLenum internalFormat )
     356{
     357   ASSERT(img);
     358   ASSERT(!img->Data);
     359   img->Format = (GLenum) _mesa_base_tex_format(internalFormat);
     360   set_teximage_component_sizes( img );
     361   img->IntFormat = (GLenum) internalFormat;
     362   img->Border = border;
     363   img->Width = width;
     364   img->Height = height;
     365   img->Depth = depth;
     366   img->WidthLog2 = logbase2(width - 2 * border);
     367   if (height == 1)  /* 1-D texture */
     368      img->HeightLog2 = 0;
     369   else
     370      img->HeightLog2 = logbase2(height - 2 * border);
     371   if (depth == 1)   /* 2-D texture */
     372      img->DepthLog2 = 0;
     373   else
     374      img->DepthLog2 = logbase2(depth - 2 * border);
     375   img->Width2 = 1 << img->WidthLog2;
     376   img->Height2 = 1 << img->HeightLog2;
     377   img->Depth2 = 1 << img->DepthLog2;
     378   img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
     379}
     380
     381
     382
     383void
     384gl_free_texture_image( struct gl_texture_image *teximage )
     385{
     386   if (teximage->Data) {
     387      FREE( teximage->Data );
     388      teximage->Data = NULL;
     389   }
     390   FREE( teximage );
     391}
     392
     393
     394
    372395/* Need this to prevent an out-of-bounds memory access when using
    373396 * X86 optimized code.
     
    382405
    383406/*
    384  * This is called by glTexImage[123]D in order to build a gl_texture_image
    385  * object given the client's parameters and image data.
    386  *
    387  * NOTES: Width, height and depth should include the border.
    388  *        All texture image parameters should have already been error checked.
     407 * Called by glTexImage[123]D.  Fill in a texture image with data given
     408 * by the client.  All pixel transfer and unpack modes are handled here.
     409 * NOTE: All texture image parameters should have already been error checked.
    389410 */
    390 static struct gl_texture_image *
    391 make_texture_image( GLcontext *ctx, GLint internalFormat,
    392                     GLint width, GLint height, GLint depth, GLint border,
     411static void
     412make_texture_image( GLcontext *ctx,
     413                    struct gl_texture_image *texImage,
    393414                    GLenum srcFormat, GLenum srcType, const GLvoid *pixels,
    394415                    const struct gl_pixelstore_attrib *unpacking)
    395416{
    396417   GLint components, numPixels;
    397    struct gl_texture_image *texImage;
    398 
    399    assert(width > 0);
    400    assert(height > 0);
    401    assert(depth > 0);
    402    assert(border == 0 || border == 1);
    403    assert(pixels);
    404    assert(unpacking);
    405 
    406 
    407    /*
    408     * Allocate and initialize the texture_image struct
    409     */
    410    texImage = gl_alloc_texture_image();
    411    if (!texImage)
    412       return NULL;
    413 
    414    texImage->Format = (GLenum) decode_internal_format(internalFormat);
    415    set_teximage_component_sizes( texImage );
    416    texImage->IntFormat = (GLenum) internalFormat;
    417    texImage->Border = border;
    418    texImage->Width = width;
    419    texImage->Height = height;
    420    texImage->Depth = depth;
    421    texImage->WidthLog2 = logbase2(width - 2 * border);
    422    if (height == 1)  /* 1-D texture */
    423       texImage->HeightLog2 = 0;
    424    else
    425       texImage->HeightLog2 = logbase2(height - 2 * border);
    426    if (depth == 1)   /* 2-D texture */
    427       texImage->DepthLog2 = 0;
    428    else
    429       texImage->DepthLog2 = logbase2(depth - 2 * border);
    430    texImage->Width2 = 1 << texImage->WidthLog2;
    431    texImage->Height2 = 1 << texImage->HeightLog2;
    432    texImage->Depth2 = 1 << texImage->DepthLog2;
    433    texImage->MaxLog2 = MAX2(texImage->WidthLog2, texImage->HeightLog2);
    434 
     418   GLint internalFormat, width, height, depth, border;
     419
     420   ASSERT(ctx);
     421   ASSERT(texImage);
     422   ASSERT(!texImage->Data);
     423   ASSERT(pixels);
     424   ASSERT(unpacking);
     425
     426   internalFormat = texImage->IntFormat;
     427   width = texImage->Width;
     428   height = texImage->Height;
     429   depth = texImage->Depth;
     430   border = texImage->Border;
    435431   components = components_in_intformat(internalFormat);
    436    numPixels = texImage->Width * texImage->Height * texImage->Depth;
     432
     433   ASSERT(width > 0);
     434   ASSERT(height > 0);
     435   ASSERT(depth > 0);
     436   ASSERT(border == 0 || border == 1);
     437   ASSERT(pixels);
     438   ASSERT(unpacking);
     439   ASSERT(components);
     440
     441   numPixels = width * height * depth;
    437442
    438443   texImage->Data = (GLubyte *) MALLOC(numPixels * components + EXTRA_BYTE);
    439 
    440    if (!texImage->Data) {
    441       /* out of memory */
    442       gl_free_texture_image(texImage);
    443       return NULL;
    444    }
    445 
     444   if (!texImage->Data)
     445      return;      /* out of memory */
    446446
    447447   /*
     
    457457       && srcType == GL_UNSIGNED_BYTE && depth == 1) {
    458458
    459       if (srcFormat == internalFormat) {
     459      if (srcFormat == internalFormat ||
     460          (srcFormat == GL_LUMINANCE && internalFormat == 1) ||
     461          (srcFormat == GL_LUMINANCE_ALPHA && internalFormat == 2) ||
     462          (srcFormat == GL_RGB && internalFormat == 3) ||
     463          (srcFormat == GL_RGBA && internalFormat == 4)) {
    460464         /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA,
    461465          * GL_LUMINANCE_ALPHA, etc. texture formats.
    462466          */
    463          const GLubyte *src = (GLubyte *)gl_pixel_addr_in_image(unpacking,
    464                 pixels, width, height, srcFormat, srcType, 0, 0, 0);
    465          const GLubyte *src1 = (GLubyte *)gl_pixel_addr_in_image(unpacking,
    466                 pixels, width, height, srcFormat, srcType, 0, 1, 0);
    467          const GLint srcStride = src1 - src;
     467         const GLubyte *src = (const GLubyte *) _mesa_image_address(
     468            unpacking, pixels, width, height, srcFormat, srcType, 0, 0, 0);
     469         const GLint srcStride = _mesa_image_row_stride(unpacking, width,
     470                                                        srcFormat, srcType);
    468471         GLubyte *dst = texImage->Data;
    469472         GLint dstBytesPerRow = width * components * sizeof(GLubyte);
     
    479482            }
    480483         }
    481          return texImage;  /* all done */
     484         return;  /* all done */
    482485      }
    483486      else if (srcFormat == GL_RGBA && internalFormat == GL_RGB) {
    484487         /* commonly used by Quake */
    485          const GLubyte *src = (GLubyte *)gl_pixel_addr_in_image(unpacking,
    486                 pixels, width, height, srcFormat, srcType, 0, 0, 0);
    487          const GLubyte *src1 = (GLubyte *)gl_pixel_addr_in_image(unpacking,
    488                 pixels, width, height, srcFormat, srcType, 0, 1, 0);
    489          const GLint srcStride = src1 - src;
     488         const GLubyte *src = (const GLubyte *) _mesa_image_address(
     489            unpacking, pixels, width, height, srcFormat, srcType, 0, 0, 0);
     490         const GLint srcStride = _mesa_image_row_stride(unpacking, width,
     491                                                        srcFormat, srcType);
    490492         GLubyte *dst = texImage->Data;
    491493         GLint i, j;
     
    500502            src += srcStride;
    501503         }
    502          return texImage;  /* all done */
     504         return;  /* all done */
    503505      }
    504506   }
     
    516518      for (img = 0; img < depth; img++) {
    517519         for (row = 0; row < height; row++) {
    518             const GLvoid *source = gl_pixel_addr_in_image(unpacking,
     520            const GLvoid *source = _mesa_image_address(unpacking,
    519521                pixels, width, height, srcFormat, srcType, img, row, 0);
    520522            _mesa_unpack_index_span(ctx, width, dstType, dest,
     
    532534      for (img = 0; img < depth; img++) {
    533535         for (row = 0; row < height; row++) {
    534             const GLvoid *source = gl_pixel_addr_in_image(unpacking,
     536            const GLvoid *source = _mesa_image_address(unpacking,
    535537                   pixels, width, height, srcFormat, srcType, img, row, 0);
    536538            _mesa_unpack_ubyte_color_span(ctx, width, dstFormat, dest,
     
    540542      }
    541543   }
    542 
    543    return texImage;   /* All done! */
    544544}
    545545
     
    549549 * glTexImage[123]D can accept a NULL image pointer.  In this case we
    550550 * create a texture image with unspecified image contents per the OpenGL
    551  * spec.
     551 * spec.  This function creates an empty image for the given texture image.
    552552 */
    553 static struct gl_texture_image *
    554 make_null_texture( GLcontext *ctx, GLenum internalFormat,
    555                    GLsizei width, GLsizei height, GLsizei depth, GLint border )
     553static void
     554make_null_texture( struct gl_texture_image *texImage )
    556555{
    557556   GLint components;
    558    struct gl_texture_image *texImage;
    559557   GLint numPixels;
    560    (void) ctx;
    561 
    562    /*internalFormat = decode_internal_format(internalFormat);*/
    563    components = components_in_intformat(internalFormat);
    564    numPixels = width * height * depth;
    565 
    566    texImage = gl_alloc_texture_image();
    567    if (!texImage)
    568       return NULL;
    569 
    570    texImage->Format = (GLenum) decode_internal_format(internalFormat);
    571    set_teximage_component_sizes( texImage );
    572    texImage->IntFormat = internalFormat;
    573    texImage->Border = border;
    574    texImage->Width = width;
    575    texImage->Height = height;
    576    texImage->Depth = depth;
    577    texImage->WidthLog2 = logbase2(width - 2*border);
    578    if (height==1)  /* 1-D texture */
    579       texImage->HeightLog2 = 0;
    580    else
    581       texImage->HeightLog2 = logbase2(height - 2*border);
    582    if (depth==1)   /* 2-D texture */
    583       texImage->DepthLog2 = 0;
    584    else
    585       texImage->DepthLog2 = logbase2(depth - 2*border);
    586    texImage->Width2 = 1 << texImage->WidthLog2;
    587    texImage->Height2 = 1 << texImage->HeightLog2;
    588    texImage->Depth2 = 1 << texImage->DepthLog2;
    589    texImage->MaxLog2 = MAX2( texImage->WidthLog2, texImage->HeightLog2 );
    590 
    591    /* XXX should we really allocate memory for the image or let it be NULL? */
    592    /*texImage->Data = NULL;*/
     558
     559   ASSERT(texImage);
     560   ASSERT(!texImage->Data);
     561
     562   components = components_in_intformat(texImage->IntFormat);
     563   numPixels = texImage->Width * texImage->Height * texImage->Depth;
    593564
    594565   texImage->Data = (GLubyte *) MALLOC( numPixels * components + EXTRA_BYTE );
     
    600571    */
    601572   if (texImage->Data) {
    602       char message[8][32] = {
     573      static const char message[8][32] = {
    603574         "   X   X  XXXXX   XXX     X    ",
    604575         "   XX XX  X      X   X   X X   ",
     
    613584      GLubyte *imgPtr = texImage->Data;
    614585      GLint i, j, k;
    615       for (i=0;i<height;i++) {
     586      for (i = 0; i < texImage->Height; i++) {
    616587         GLint srcRow = 7 - i % 8;
    617          for (j=0;j<width;j++) {
     588         for (j = 0; j < texImage->Width; j++) {
    618589            GLint srcCol = j % 32;
    619590            GLint texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
     
    624595      }
    625596   }
    626 
    627    return texImage;
    628597}
    629598
     
    674643
    675644   /* Border */
    676    if (border!=0 && border!=1) {
     645   if (border != 0 && border != 1) {
    677646      if (!isProxy) {
    678647         char message[100];
     
    719688
    720689   /* Level */
    721    if (level<0 || level>=ctx->Const.MaxTextureLevels) {
     690   if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
    722691      if (!isProxy) {
    723692         char message[100];
     
    728697   }
    729698
    730    iformat = decode_internal_format( internalFormat );
     699   iformat = _mesa_base_tex_format( internalFormat );
    731700   if (iformat < 0) {
    732701      if (!isProxy) {
     
    738707   }
    739708
    740    if (!gl_is_legal_format_and_type( format, type )) {
     709   if (!_mesa_is_legal_format_and_type( format, type )) {
    741710      /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
    742711       * is a type/format mismatch.  See 1.2 spec page 94, sec 3.6.4.
     
    763732 */
    764733static GLboolean
    765 subtexture_error_check( GLcontext *ctx, GLint dimensions,
     734subtexture_error_check( GLcontext *ctx, GLuint dimensions,
    766735                        GLenum target, GLint level,
    767736                        GLint xoffset, GLint yoffset, GLint zoffset,
     
    854823   }
    855824
    856    if (!gl_is_legal_format_and_type(format, type)) {
     825   if (!_mesa_is_legal_format_and_type(format, type)) {
    857826      char message[100];
    858827      sprintf(message, "glTexSubImage%dD(format or type)", dimensions);
     
    871840 */
    872841static GLboolean
    873 copytexture_error_check( GLcontext *ctx, GLint dimensions,
     842copytexture_error_check( GLcontext *ctx, GLuint dimensions,
    874843                         GLenum target, GLint level, GLint internalFormat,
    875844                         GLint width, GLint height, GLint border )
     
    927896   }
    928897
    929    iformat = decode_internal_format( internalFormat );
     898   iformat = _mesa_base_tex_format( internalFormat );
    930899   if (iformat < 0) {
    931900      char message[100];
     
    941910
    942911static GLboolean
    943 copytexsubimage_error_check( GLcontext *ctx, GLint dimensions,
     912copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
    944913                             GLenum target, GLint level,
    945914                             GLint xoffset, GLint yoffset, GLint zoffset,
     
    10431012 * Called from the API.  Note that width includes the border.
    10441013 */
    1045 void gl_TexImage1D( GLcontext *ctx, GLenum target, GLint level,
    1046                     GLint internalformat,
    1047                     GLsizei width, GLint border, GLenum format,
    1048                     GLenum type, const GLvoid *pixels )
    1049 {
    1050    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1014void
     1015_mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
     1016                  GLsizei width, GLint border, GLenum format,
     1017                  GLenum type, const GLvoid *pixels )
     1018{
     1019   GET_CURRENT_CONTEXT(ctx);
    10511020   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage1D");
    10521021
    10531022   if (target==GL_TEXTURE_1D) {
    1054       struct gl_texture_image *teximage;
    1055       if (texture_error_check( ctx, target, level, internalformat,
     1023      struct gl_texture_unit *texUnit;
     1024      struct gl_texture_object *texObj;
     1025      struct gl_texture_image *texImage;
     1026
     1027      if (texture_error_check( ctx, target, level, internalFormat,
    10561028                               format, type, 1, width, 1, 1, border )) {
    1057          /* error in texture image was detected */
    1058          return;
    1059       }
    1060 
    1061       /* free current texture image, if any */
    1062       if (texUnit->CurrentD[1]->Image[level]) {
    1063          gl_free_texture_image( texUnit->CurrentD[1]->Image[level] );
    1064       }
    1065 
    1066       /* make new texture from source image */
     1029         return;   /* error in texture image was detected */
     1030      }
     1031
     1032      texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1033      texObj = texUnit->CurrentD[1];
     1034      texImage = texObj->Image[level];
     1035
     1036      if (!texImage) {
     1037         texImage = gl_alloc_texture_image();
     1038         texObj->Image[level] = texImage;
     1039         if (!texImage) {
     1040            gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
     1041            return;
     1042         }
     1043      }
     1044      else if (texImage->Data) {
     1045         FREE(texImage->Data);
     1046         texImage->Data = NULL;
     1047      }
     1048
     1049      /* setup the teximage struct's fields */
     1050      init_texture_image(texImage, width, 1, 1, border, internalFormat);
     1051
     1052      /* process the texture image */
    10671053      if (pixels) {
    1068          teximage = make_texture_image(ctx, internalformat, width, 1, 1,
    1069                               border, format, type, pixels, &ctx->Unpack);
     1054         GLboolean retain = GL_TRUE;
     1055         GLboolean success = GL_FALSE;
     1056         if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA
     1057             && ctx->Driver.TexImage1D) {
     1058            /* let device driver try to use raw image */
     1059            success = (*ctx->Driver.TexImage1D)( ctx, target, level, format,
     1060                                                 type, pixels, &ctx->Unpack,
     1061                                                 texObj, texImage, &retain);
     1062         }
     1063         if (retain || !success) {
     1064            /* make internal copy of the texture image */
     1065            make_texture_image(ctx, texImage, format, type,
     1066                               pixels, &ctx->Unpack);
     1067            if (!success && ctx->Driver.TexImage1D) {
     1068               /* let device driver try to use unpacked image */
     1069               (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format,
     1070                                          GL_UNSIGNED_BYTE, texImage->Data,
     1071                                          &_mesa_native_packing,
     1072                                          texObj, texImage, &retain);
     1073            }
     1074         }
     1075         if (!retain && texImage->Data) {
     1076            FREE(texImage->Data);
     1077            texImage->Data = NULL;
     1078         }
    10701079      }
    10711080      else {
    1072          teximage = make_null_texture(ctx, (GLenum) internalformat,
    1073                                       width, 1, 1, border);
    1074       }
    1075 
    1076       /* install new texture image */
    1077       texUnit->CurrentD[1]->Image[level] = teximage;
    1078       gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] );
     1081         make_null_texture(texImage);
     1082         if (ctx->Driver.TexImage1D) {
     1083            GLboolean retain;
     1084            (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format,
     1085                                       GL_UNSIGNED_BYTE, texImage->Data,
     1086                                       &_mesa_native_packing,
     1087                                       texObj, texImage, &retain);
     1088         }
     1089      }
     1090
     1091      /* state update */
     1092      gl_put_texobj_on_dirty_list( ctx, texObj );
    10791093      ctx->NewState |= NEW_TEXTURING;
    1080 
    1081       /* tell driver about change */
    1082       if (ctx->Driver.TexImage) {
    1083          (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D,
    1084                                   texUnit->CurrentD[1],
    1085                                   level, internalformat, teximage );
    1086       }
    10871094   }
    10881095   else if (target==GL_PROXY_TEXTURE_1D) {
    10891096      /* Proxy texture: check for errors and update proxy state */
    1090       if (texture_error_check( ctx, target, level, internalformat,
     1097      if (texture_error_check( ctx, target, level, internalFormat,
    10911098                               format, type, 1, width, 1, 1, border )) {
    10921099         if (level>=0 && level<ctx->Const.MaxTextureLevels) {
     
    10981105         ctx->Texture.Proxy1D->Image[level]->Format = (GLenum) format;
    10991106         set_teximage_component_sizes( ctx->Texture.Proxy1D->Image[level] );
    1100          ctx->Texture.Proxy1D->Image[level]->IntFormat = (GLenum) internalformat;
     1107         ctx->Texture.Proxy1D->Image[level]->IntFormat = (GLenum) internalFormat;
    11011108         ctx->Texture.Proxy1D->Image[level]->Border = border;
    11021109         ctx->Texture.Proxy1D->Image[level]->Width = width;
     
    11121119
    11131120
    1114 void gl_TexImage2D( GLcontext *ctx, GLenum target, GLint level,
    1115                     GLint internalformat,
    1116                     GLsizei width, GLsizei height, GLint border,
    1117                     GLenum format, GLenum type,
    1118                     const GLvoid *pixels )
    1119 {
    1120    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1121void
     1122_mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
     1123                  GLsizei width, GLsizei height, GLint border,
     1124                  GLenum format, GLenum type,
     1125                  const GLvoid *pixels )
     1126{
     1127   GET_CURRENT_CONTEXT(ctx);
    11211128   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage2D");
    11221129
    11231130   if (target==GL_TEXTURE_2D) {
    1124       struct gl_texture_image *teximage;
    1125       if (texture_error_check( ctx, target, level, internalformat,
     1131      struct gl_texture_unit *texUnit;
     1132      struct gl_texture_object *texObj;
     1133      struct gl_texture_image *texImage;
     1134
     1135      if (texture_error_check( ctx, target, level, internalFormat,
    11261136                               format, type, 2, width, height, 1, border )) {
    1127          /* error in texture image was detected */
    1128          return;
    1129       }
    1130 
    1131       /* free current texture image, if any */
    1132       if (texUnit->CurrentD[2]->Image[level]) {
    1133          gl_free_texture_image( texUnit->CurrentD[2]->Image[level] );
    1134       }
    1135 
    1136       /* make new texture from source image */
     1137         return;   /* error in texture image was detected */
     1138      }
     1139
     1140      texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1141      texObj = texUnit->CurrentD[2];
     1142      texImage = texObj->Image[level];
     1143
     1144      if (!texImage) {
     1145         texImage = gl_alloc_texture_image();
     1146         texObj->Image[level] = texImage;
     1147         if (!texImage) {
     1148            gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
     1149            return;
     1150         }
     1151      }
     1152      else if (texImage->Data) {
     1153         FREE(texImage->Data);
     1154         texImage->Data = NULL;
     1155      }
     1156
     1157      /* setup the teximage struct's fields */
     1158      init_texture_image(texImage, width, height, 1, border, internalFormat);
     1159
     1160      /* process the texture image */
    11371161      if (pixels) {
    1138          teximage = make_texture_image(ctx, internalformat, width, height, 1,
    1139                                   border, format, type, pixels, &ctx->Unpack);
     1162         GLboolean retain = GL_TRUE;
     1163         GLboolean success = GL_FALSE;
     1164         if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA
     1165             && ctx->Driver.TexImage2D) {
     1166            /* let device driver try to use raw image */
     1167            success = (*ctx->Driver.TexImage2D)( ctx, target, level, format,
     1168                                                 type, pixels, &ctx->Unpack,
     1169                                                 texObj, texImage, &retain);
     1170         }
     1171         if (retain || !success) {
     1172            /* make internal copy of the texture image */
     1173            make_texture_image(ctx, texImage, format, type,
     1174                               pixels, &ctx->Unpack);
     1175            if (!success && ctx->Driver.TexImage2D) {
     1176               /* let device driver try to use unpacked image */
     1177               (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format,
     1178                                          GL_UNSIGNED_BYTE, texImage->Data,
     1179                                          &_mesa_native_packing,
     1180                                          texObj, texImage, &retain);
     1181            }
     1182         }
     1183         if (!retain && texImage->Data) {
     1184            FREE(texImage->Data);
     1185            texImage->Data = NULL;
     1186         }
    11401187      }
    11411188      else {
    1142          teximage = make_null_texture(ctx, (GLenum) internalformat,
    1143                                       width, height, 1, border);
    1144       }
    1145 
    1146       /* install new texture image */
    1147       texUnit->CurrentD[2]->Image[level] = teximage;
    1148       gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[2] );
     1189         make_null_texture(texImage);
     1190         if (ctx->Driver.TexImage2D) {
     1191            GLboolean retain;
     1192            (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format,
     1193                                       GL_UNSIGNED_BYTE, texImage->Data,
     1194                                       &_mesa_native_packing,
     1195                                       texObj, texImage, &retain);
     1196         }
     1197      }
     1198
     1199#define OLD_DD_TEXTURE
     1200#ifdef OLD_DD_TEXTURE
     1201      /* XXX this will be removed in the future */
     1202      if (ctx->Driver.TexImage) {
     1203         (*ctx->Driver.TexImage)( ctx, target, texObj, level, internalFormat,
     1204                                  texImage );
     1205      }
     1206#endif
     1207
     1208      /* state update */
     1209      gl_put_texobj_on_dirty_list( ctx, texObj );
    11491210      ctx->NewState |= NEW_TEXTURING;
    1150 
    1151       /* tell driver about change */
    1152       if (ctx->Driver.TexImage) {
    1153          (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D,
    1154                                   texUnit->CurrentD[2],
    1155                                   level, internalformat, teximage );
    1156       }
    11571211   }
    11581212   else if (target==GL_PROXY_TEXTURE_2D) {
    11591213      /* Proxy texture: check for errors and update proxy state */
    1160       if (texture_error_check( ctx, target, level, internalformat,
     1214      if (texture_error_check( ctx, target, level, internalFormat,
    11611215                               format, type, 2, width, height, 1, border )) {
    11621216         if (level>=0 && level<ctx->Const.MaxTextureLevels) {
     
    11681222         ctx->Texture.Proxy2D->Image[level]->Format = (GLenum) format;
    11691223         set_teximage_component_sizes( ctx->Texture.Proxy2D->Image[level] );
    1170          ctx->Texture.Proxy2D->Image[level]->IntFormat = (GLenum) internalformat;
     1224         ctx->Texture.Proxy2D->Image[level]->IntFormat = (GLenum) internalFormat;
    11711225         ctx->Texture.Proxy2D->Image[level]->Border = border;
    11721226         ctx->Texture.Proxy2D->Image[level]->Width = width;
     
    11871241 * Note that width and height include the border.
    11881242 */
    1189 void gl_TexImage3D( GLcontext *ctx, GLenum target, GLint level,
    1190                     GLint internalformat,
    1191                     GLsizei width, GLsizei height, GLsizei depth,
    1192                     GLint border, GLenum format, GLenum type,
    1193                     const GLvoid *pixels )
    1194 {
    1195    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1243void
     1244_mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
     1245                  GLsizei width, GLsizei height, GLsizei depth,
     1246                  GLint border, GLenum format, GLenum type,
     1247                  const GLvoid *pixels )
     1248{
     1249   GET_CURRENT_CONTEXT(ctx);
    11961250   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage3D");
    11971251
    1198    if (target==GL_TEXTURE_3D) {
    1199       struct gl_texture_image *teximage;
    1200       if (texture_error_check( ctx, target, level, internalformat,
     1252   if (target==GL_TEXTURE_3D_EXT) {
     1253      struct gl_texture_unit *texUnit;
     1254      struct gl_texture_object *texObj;
     1255      struct gl_texture_image *texImage;
     1256      if (texture_error_check( ctx, target, level, internalFormat,
    12011257                               format, type, 3, width, height, depth,
    12021258                               border )) {
    1203          /* error in texture image was detected */
    1204          return;
    1205       }
    1206 
    1207       /* free current texture image, if any */
    1208       if (texUnit->CurrentD[3]->Image[level]) {
    1209          gl_free_texture_image( texUnit->CurrentD[3]->Image[level] );
    1210       }
    1211 
    1212       /* make new texture from source image */
     1259         return;   /* error in texture image was detected */
     1260      }
     1261
     1262      texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1263      texObj = texUnit->CurrentD[3];
     1264      texImage = texObj->Image[level];
     1265
     1266      if (!texImage) {
     1267         texImage = gl_alloc_texture_image();
     1268         texObj->Image[level] = texImage;
     1269         if (!texImage) {
     1270            gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
     1271            return;
     1272         }
     1273      }
     1274      else if (texImage->Data) {
     1275         FREE(texImage->Data);
     1276         texImage->Data = NULL;
     1277      }
     1278
     1279      /* setup the teximage struct's fields */
     1280      init_texture_image(texImage, width, height, depth,
     1281                         border, internalFormat);
     1282
     1283      /* process the texture image */
    12131284      if (pixels) {
    1214          teximage = make_texture_image(ctx, internalformat, width, height,
    1215                        depth, border, format, type, pixels, &ctx->Unpack);
     1285         GLboolean retain = GL_TRUE;
     1286         GLboolean success = GL_FALSE;
     1287         if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA
     1288             && ctx->Driver.TexImage3D) {
     1289            /* let device driver try to use raw image */
     1290            success = (*ctx->Driver.TexImage3D)( ctx, target, level, format,
     1291                                                 type, pixels, &ctx->Unpack,
     1292                                                 texObj, texImage, &retain);
     1293         }
     1294         if (retain || !success) {
     1295            /* make internal copy of the texture image */
     1296            make_texture_image(ctx, texImage, format, type,
     1297                               pixels, &ctx->Unpack);
     1298            if (!success && ctx->Driver.TexImage3D) {
     1299               /* let device driver try to use unpacked image */
     1300               (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format,
     1301                                          GL_UNSIGNED_BYTE, texImage->Data,
     1302                                          &_mesa_native_packing,
     1303                                          texObj, texImage, &retain);
     1304            }
     1305         }
     1306         if (!retain && texImage->Data) {
     1307            FREE(texImage->Data);
     1308            texImage->Data = NULL;
     1309         }
    12161310      }
    12171311      else {
    1218          teximage = make_null_texture(ctx, (GLenum) internalformat,
    1219                                       width, height, depth, border);
    1220       }
    1221 
    1222       /* install new texture image */
    1223       texUnit->CurrentD[3]->Image[level] = teximage;
    1224       gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[3] );
     1312         make_null_texture(texImage);
     1313         if (ctx->Driver.TexImage3D) {
     1314            GLboolean retain;
     1315            (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format,
     1316                                       GL_UNSIGNED_BYTE, texImage->Data,
     1317                                       &_mesa_native_packing,
     1318                                       texObj, texImage, &retain);
     1319         }
     1320      }
     1321
     1322      /* state update */
     1323      gl_put_texobj_on_dirty_list( ctx, texObj );
    12251324      ctx->NewState |= NEW_TEXTURING;
    1226 
    1227       /* tell driver about change */
    1228       if (ctx->Driver.TexImage) {
    1229          (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_3D_EXT,
    1230                                   texUnit->CurrentD[3],
    1231                                   level, internalformat, teximage );
    1232       }
    12331325   }
    12341326   else if (target==GL_PROXY_TEXTURE_3D_EXT) {
    12351327      /* Proxy texture: check for errors and update proxy state */
    1236       if (texture_error_check( ctx, target, level, internalformat,
     1328      if (texture_error_check( ctx, target, level, internalFormat,
    12371329                               format, type, 3, width, height, depth,
    12381330                               border )) {
     
    12451337         ctx->Texture.Proxy3D->Image[level]->Format = (GLenum) format;
    12461338         set_teximage_component_sizes( ctx->Texture.Proxy3D->Image[level] );
    1247          ctx->Texture.Proxy3D->Image[level]->IntFormat = (GLenum) internalformat;
     1339         ctx->Texture.Proxy3D->Image[level]->IntFormat = (GLenum) internalFormat;
    12481340         ctx->Texture.Proxy3D->Image[level]->Border = border;
    12491341         ctx->Texture.Proxy3D->Image[level]->Width = width;
     
    12591351
    12601352
    1261 
    1262 void gl_GetTexImage( GLcontext *ctx, GLenum target, GLint level, GLenum format,
    1263                      GLenum type, GLvoid *pixels )
    1264 {
     1353void
     1354_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat,
     1355                     GLsizei width, GLsizei height, GLsizei depth,
     1356                     GLint border, GLenum format, GLenum type,
     1357                     const GLvoid *pixels )
     1358{
     1359   _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height,
     1360                    depth, border, format, type, pixels);
     1361}
     1362
     1363
     1364/*
     1365 * Fetch a texture image from the device driver.
     1366 * Store the results in the given texture object at the given mipmap level.
     1367 */
     1368static void
     1369get_teximage_from_driver( GLcontext *ctx, GLenum target, GLint level,
     1370                          const struct gl_texture_object *texObj )
     1371{
     1372   GLvoid *image;
     1373   GLenum imgFormat, imgType;
     1374   GLboolean freeImage;
     1375   struct gl_texture_image *texImage;
     1376   GLint destComponents, numPixels, srcBytesPerTexel;
     1377
     1378   if (!ctx->Driver.GetTexImage)
     1379      return;
     1380
     1381   image = (*ctx->Driver.GetTexImage)( ctx, target, level,
     1382                                       &imgFormat, &imgType, &freeImage);
     1383   if (!image)
     1384      return;
     1385
     1386   texImage = texObj->Image[level];
     1387   ASSERT(texImage);
     1388   if (!texImage)
     1389      return;
     1390
     1391   destComponents = components_in_intformat(texImage->Format);
     1392   ASSERT(destComponents > 0);
     1393   numPixels = texImage->Width * texImage->Height * texImage->Depth;
     1394   ASSERT(numPixels > 0);
     1395   srcBytesPerTexel = _mesa_bytes_per_pixel(imgFormat, imgType);
     1396   ASSERT(srcBytesPerTexel > 0);
     1397
     1398   if (!texImage->Data) {
     1399      /* Allocate memory for the texture image data */
     1400      texImage->Data = (GLubyte *) MALLOC(numPixels * destComponents + EXTRA_BYTE);
     1401   }
     1402
     1403   if (imgFormat == texImage->Format && imgType == GL_UNSIGNED_BYTE) {
     1404      /* We got lucky!  The driver's format and type match Mesa's format. */
     1405      if (texImage->Data) {
     1406         MEMCPY(texImage->Data, image, numPixels * destComponents);
     1407      }
     1408   }
     1409   else {
     1410      /* Convert the texture image from the driver's format to Mesa's
     1411       * internal format.
     1412       */
     1413      const GLint width = texImage->Width;
     1414      const GLint height = texImage->Height;
     1415      const GLint depth = texImage->Depth;
     1416      const GLint destBytesPerRow = width * destComponents * sizeof(GLchan);
     1417      const GLint srcBytesPerRow = width * srcBytesPerTexel;
     1418      const GLenum dstType = GL_UNSIGNED_BYTE;
     1419      const GLenum dstFormat = texImage->Format;
     1420      const GLubyte *srcPtr = (const GLubyte *) image;
     1421      GLubyte *destPtr = texImage->Data;
     1422
     1423      if (texImage->Format == GL_COLOR_INDEX) {
     1424         /* color index texture */
     1425         GLint img, row;
     1426         ASSERT(imgFormat == GL_COLOR_INDEX);
     1427         for (img = 0; img < depth; img++) {
     1428            for (row = 0; row < height; row++) {
     1429               _mesa_unpack_index_span(ctx, width, dstType, destPtr,
     1430                             imgType, srcPtr, &_mesa_native_packing, GL_FALSE);
     1431               destPtr += destBytesPerRow;
     1432               srcPtr += srcBytesPerRow;
     1433            }
     1434         }
     1435      }
     1436      else {
     1437         /* color texture */
     1438         GLint img, row;
     1439         for (img = 0; img < depth; img++) {
     1440            for (row = 0; row < height; row++) {
     1441               _mesa_unpack_ubyte_color_span(ctx, width, dstFormat, destPtr,
     1442                  imgFormat, imgType, srcPtr, &_mesa_native_packing, GL_FALSE);
     1443               destPtr += destBytesPerRow;
     1444               srcPtr += srcBytesPerRow;
     1445            }
     1446         }
     1447      }
     1448   }
     1449
     1450   if (freeImage)
     1451      FREE(image);
     1452}
     1453
     1454
     1455void
     1456_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
     1457                   GLenum type, GLvoid *pixels )
     1458{
     1459   GET_CURRENT_CONTEXT(ctx);
    12651460   const struct gl_texture_object *texObj;
     1461   struct gl_texture_image *texImage;
     1462   GLboolean discardImage;
    12661463
    12671464   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexImage");
     
    12721469   }
    12731470
    1274    if (gl_sizeof_type(type) <= 0) {
     1471   if (_mesa_sizeof_type(type) <= 0) {
    12751472      gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" );
    12761473      return;
    12771474   }
    12781475
    1279    if (gl_components_in_format(format) <= 0) {
     1476   if (_mesa_components_in_format(format) <= 0) {
    12801477      gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" );
    12811478      return;
     
    12831480
    12841481   if (!pixels)
    1285       return;  /* XXX generate an error??? */
     1482      return;
    12861483
    12871484   switch (target) {
     
    13001497   }
    13011498
    1302    if (texObj->Image[level] && texObj->Image[level]->Data) {
    1303       const struct gl_texture_image *texImage = texObj->Image[level];
     1499   texImage = texObj->Image[level];
     1500   if (!texImage) {
     1501      /* invalid mipmap level */
     1502      return;
     1503   }
     1504
     1505   if (!texImage->Data) {
     1506      /* try to get the texture image from the device driver */
     1507      get_teximage_from_driver(ctx, target, level, texObj);
     1508      discardImage = GL_TRUE;
     1509   }
     1510   else {
     1511      discardImage = GL_FALSE;
     1512   }
     1513
     1514   if (texImage->Data) {
    13041515      GLint width = texImage->Width;
    13051516      GLint height = texImage->Height;
     
    13081519      for (row = 0; row < height; row++) {
    13091520         /* compute destination address in client memory */
    1310          GLvoid *dest = gl_pixel_addr_in_image( &ctx->Unpack, pixels,
     1521         GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels,
    13111522                                                width, height,
    13121523                                                format, type, 0, row, 0);
    13131524
    1314          assert(dest);
     1525         ASSERT(dest);
    13151526         if (texImage->Format == GL_RGBA) {
    13161527            const GLubyte *src = texImage->Data + row * width * 4 * sizeof(GLubyte);
    1317             gl_pack_rgba_span( ctx, width,
    1318                                (const GLubyte (*)[4]) src,
    1319                                format, type, dest,
    1320                                &ctx->Pack, GL_TRUE );
     1528            _mesa_pack_rgba_span( ctx, width, (CONST GLubyte (*)[4]) src,
     1529                                  format, type, dest, &ctx->Pack, GL_TRUE );
    13211530         }
    13221531         else {
     
    13811590                  gl_problem( ctx, "bad format in gl_GetTexImage" );
    13821591            }
    1383             gl_pack_rgba_span( ctx, width, (const GLubyte (*)[4])rgba,
    1384                                format, type, dest, &ctx->Pack, GL_TRUE );
    1385          }
    1386       }
    1387    }
    1388 }
    1389 
    1390 
    1391 
    1392 void gl_TexSubImage1D( GLcontext *ctx, GLenum target, GLint level,
    1393                        GLint xoffset, GLsizei width,
    1394                        GLenum format, GLenum type,
    1395                        const GLvoid *pixels )
    1396 {
    1397    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    1398    struct gl_texture_image *destTex;
     1592            _mesa_pack_rgba_span( ctx, width, (const GLubyte (*)[4])rgba,
     1593                                  format, type, dest, &ctx->Pack, GL_TRUE );
     1594         }
     1595      }
     1596
     1597      /* if we got the teximage from the device driver we'll discard it now */
     1598      if (discardImage) {
     1599         FREE(texImage->Data);
     1600         texImage->Data = NULL;
     1601      }
     1602   }
     1603}
     1604
     1605
     1606
     1607void
     1608_mesa_TexSubImage1D( GLenum target, GLint level,
     1609                     GLint xoffset, GLsizei width,
     1610                     GLenum format, GLenum type,
     1611                     const GLvoid *pixels )
     1612{
     1613   GET_CURRENT_CONTEXT(ctx);
     1614   struct gl_texture_unit *texUnit;
     1615   struct gl_texture_object *texObj;
     1616   struct gl_texture_image *texImage;
     1617   GLboolean success = GL_FALSE;
    13991618
    14001619   if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0,
    14011620                              width, 1, 1, format, type)) {
    1402       /* error was detected */
    1403       return;
    1404    }
    1405 
    1406    destTex = texUnit->CurrentD[1]->Image[level];
    1407    assert(destTex);
     1621      return;   /* error was detected */
     1622   }
     1623
     1624   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1625   texObj = texUnit->CurrentD[1];
     1626   texImage = texObj->Image[level];
     1627   ASSERT(texImage);
    14081628
    14091629   if (width == 0 || !pixels)
     
    14111631
    14121632
    1413    /*
    1414     * Replace the texture subimage
    1415     */
    1416    {
    1417       const GLint texComponents = components_in_intformat(destTex->Format);
    1418       const GLenum texFormat = destTex->Format;
    1419       const GLint xoffsetb = xoffset + destTex->Border;
    1420       GLubyte *dst = destTex->Data + xoffsetb * texComponents;
     1633   if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA
     1634       && ctx->Driver.TexSubImage1D) {
     1635      success = (*ctx->Driver.TexSubImage1D)( ctx, target, level, xoffset,
     1636                                              width, format, type, pixels,
     1637                                              &ctx->Unpack, texObj, texImage );
     1638   }
     1639   if (!success) {
     1640      /* XXX if Driver.TexSubImage1D, unpack image and try again? */
     1641
     1642      const GLint texComponents = components_in_intformat(texImage->Format);
     1643      const GLenum texFormat = texImage->Format;
     1644      const GLint xoffsetb = xoffset + texImage->Border;
     1645      GLboolean retain = GL_TRUE;
     1646      if (!texImage->Data) {
     1647         get_teximage_from_driver( ctx, target, level, texObj );
     1648         if (!texImage->Data) {
     1649            make_null_texture(texImage);
     1650         }
     1651         if (!texImage->Data)
     1652            return;  /* we're really out of luck! */
     1653      }
     1654
    14211655      if (texFormat == GL_COLOR_INDEX) {
    14221656         /* color index texture */
    1423          const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,
    1424                                   width, 1, format, type, 0, 0, 0);
     1657         GLubyte *dst = texImage->Data + xoffsetb * texComponents;
     1658         const GLvoid *src = _mesa_image_address(&ctx->Unpack, pixels, width,
     1659                                                 1, format, type, 0, 0, 0);
    14251660         _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst,
    1426                                     type, src, &ctx->Unpack, GL_TRUE);
     1661                                 type, src, &ctx->Unpack, GL_TRUE);
    14271662      }
    14281663      else {
    14291664         /* color texture */
    1430          const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,
    1431                                   width, 1, format, type, 0, 0, 0);
    1432          _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst,
    1433                               format, type, src, &ctx->Unpack, GL_TRUE);
    1434       }
    1435    }
    1436 
    1437    gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] );
    1438 
    1439    /*
    1440     * Inform device driver of texture image change.
    1441     */
    1442    if (ctx->Driver.TexSubImage) {
    1443       (*ctx->Driver.TexSubImage)(ctx, GL_TEXTURE_1D, texUnit->CurrentD[1],
    1444                                  level, xoffset, 0, width, 1,
    1445                                  texUnit->CurrentD[1]->Image[level]->IntFormat,
    1446                                  destTex );
    1447    }
    1448    else {
    1449       if (ctx->Driver.TexImage) {
    1450          (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_1D, texUnit->CurrentD[1],
    1451                                  level,
    1452                                  texUnit->CurrentD[1]->Image[level]->IntFormat,
    1453                                  destTex );
    1454       }
    1455    }
    1456 }
    1457 
    1458 
    1459 void gl_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level,
    1460                        GLint xoffset, GLint yoffset,
    1461                        GLsizei width, GLsizei height,
    1462                        GLenum format, GLenum type,
    1463                        const GLvoid *pixels )
    1464 {
    1465    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    1466    struct gl_texture_image *destTex;
     1665         GLubyte *dst = texImage->Data + xoffsetb * texComponents;
     1666         const GLvoid *src = _mesa_image_address(&ctx->Unpack, pixels, width,
     1667                                                 1, format, type, 0, 0, 0);
     1668         _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst, format,
     1669                                       type, src, &ctx->Unpack, GL_TRUE);
     1670      }
     1671
     1672      if (ctx->Driver.TexImage1D) {
     1673         (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format,
     1674                                    GL_UNSIGNED_BYTE, texImage->Data,
     1675                                    &_mesa_native_packing, texObj, texImage,
     1676                                    &retain );
     1677      }
     1678
     1679      if (!retain && texImage->Data) {
     1680         FREE(texImage->Data);
     1681         texImage->Data = NULL;
     1682      }
     1683   }
     1684
     1685   /*gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] );*/
     1686}
     1687
     1688
     1689void
     1690_mesa_TexSubImage2D( GLenum target, GLint level,
     1691                     GLint xoffset, GLint yoffset,
     1692                     GLsizei width, GLsizei height,
     1693                     GLenum format, GLenum type,
     1694                     const GLvoid *pixels )
     1695{
     1696   GET_CURRENT_CONTEXT(ctx);
     1697   struct gl_texture_unit *texUnit;
     1698   struct gl_texture_object *texObj;
     1699   struct gl_texture_image *texImage;
     1700   GLboolean success = GL_FALSE;
    14671701
    14681702   if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
    14691703                              width, height, 1, format, type)) {
    1470       /* error was detected */
    1471       return;
    1472    }
    1473 
    1474    destTex = texUnit->CurrentD[2]->Image[level];
    1475    assert(destTex);
     1704      return;   /* error was detected */
     1705   }
     1706
     1707   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1708   texObj = texUnit->CurrentD[2];
     1709   texImage = texObj->Image[level];
     1710   ASSERT(texImage);
    14761711
    14771712   if (width == 0 || height == 0 || !pixels)
    14781713      return;  /* no-op, not an error */
    14791714
    1480 
    1481    /*
    1482     * Replace the texture subimage
    1483     */
    1484    {
    1485       const GLint texComponents = components_in_intformat(destTex->Format);
    1486       const GLenum texFormat = destTex->Format;
    1487       const GLint xoffsetb = xoffset + destTex->Border;
    1488       const GLint yoffsetb = yoffset + destTex->Border;
    1489       GLubyte *dst = destTex->Data
    1490                    + (yoffsetb * destTex->Width + xoffsetb) * texComponents;
     1715   if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA
     1716       && ctx->Driver.TexSubImage2D) {
     1717      success = (*ctx->Driver.TexSubImage2D)( ctx, target, level, xoffset,
     1718                                     yoffset, width, height, format, type,
     1719                                     pixels, &ctx->Unpack, texObj, texImage );
     1720   }
     1721   if (!success) {
     1722      /* XXX if Driver.TexSubImage2D, unpack image and try again? */
     1723
     1724      const GLint texComponents = components_in_intformat(texImage->Format);
     1725      const GLenum texFormat = texImage->Format;
     1726      const GLint xoffsetb = xoffset + texImage->Border;
     1727      const GLint yoffsetb = yoffset + texImage->Border;
     1728      const GLint srcStride = _mesa_image_row_stride(&ctx->Unpack, width,
     1729                                                     format, type);
     1730      const GLint dstStride = texImage->Width * texComponents *sizeof(GLubyte);
     1731      GLboolean retain = GL_TRUE;
     1732
     1733      if (!texImage->Data) {
     1734         get_teximage_from_driver( ctx, target, level, texObj );
     1735         if (!texImage->Data) {
     1736            make_null_texture(texImage);
     1737         }
     1738         if (!texImage->Data)
     1739            return;  /* we're really out of luck! */
     1740      }
     1741
    14911742      if (texFormat == GL_COLOR_INDEX) {
    14921743         /* color index texture */
    1493          const GLint stride = destTex->Width * sizeof(GLubyte);
     1744         GLubyte *dst = texImage->Data
     1745                    + (yoffsetb * texImage->Width + xoffsetb) * texComponents;
     1746         const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels,
     1747                                     width, height, format, type, 0, 0, 0);
    14941748         GLint row;
    14951749         for (row = 0; row < height; row++) {
    1496             const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,
    1497                                      width, height, format, type, 0, row, 0);
    1498             _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst,
    1499                                     type, src, &ctx->Unpack, GL_TRUE);
    1500             dst += stride;
     1750            _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst, type,
     1751                                 (const GLvoid *) src, &ctx->Unpack, GL_TRUE);
     1752            src += srcStride;
     1753            dst += dstStride;
    15011754         }
    15021755      }
    15031756      else {
    15041757         /* color texture */
    1505          const GLint stride = destTex->Width * texComponents * sizeof(GLubyte);
     1758         GLubyte *dst = texImage->Data
     1759                    + (yoffsetb * texImage->Width + xoffsetb) * texComponents;
     1760         const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels,
     1761                                     width, height, format, type, 0, 0, 0);
    15061762         GLint row;
    15071763         for (row = 0; row < height; row++) {
    1508             const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,
    1509                                      width, height, format, type, 0, row, 0);
    1510             _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst,
    1511                                  format, type, src, &ctx->Unpack, GL_TRUE);
    1512             dst += stride;
    1513          }
    1514       }
    1515    }
    1516 
    1517    gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[2] );
    1518 
    1519    /*
    1520     * Inform device driver of texture image change.
    1521     */
    1522    if (ctx->Driver.TexSubImage) {
    1523       (*ctx->Driver.TexSubImage)(ctx, GL_TEXTURE_2D, texUnit->CurrentD[2],
    1524                                  level, xoffset, yoffset, width, height,
    1525                                  texUnit->CurrentD[2]->Image[level]->IntFormat,
    1526                                  destTex );
    1527    }
    1528    else {
    1529       if (ctx->Driver.TexImage) {
    1530          (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_2D, texUnit->CurrentD[2],
    1531                                  level,
    1532                                  texUnit->CurrentD[2]->Image[level]->IntFormat,
    1533                                  destTex );
    1534       }
    1535    }
    1536 }
    1537 
    1538 
    1539 
    1540 void gl_TexSubImage3D( GLcontext *ctx, GLenum target, GLint level,
    1541                        GLint xoffset, GLint yoffset, GLint zoffset,
    1542                        GLsizei width, GLsizei height, GLsizei depth,
    1543                        GLenum format, GLenum type,
    1544                        const GLvoid *pixels )
    1545 {
    1546    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    1547    struct gl_texture_image *destTex;
     1764            _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst, format,
     1765                           type, (const GLvoid *) src, &ctx->Unpack, GL_TRUE);
     1766            src += srcStride;
     1767            dst += dstStride;
     1768         }
     1769      }
     1770
     1771      if (ctx->Driver.TexImage2D) {
     1772         (*ctx->Driver.TexImage2D)(ctx, target, level, texImage->Format,
     1773                                   GL_UNSIGNED_BYTE, texImage->Data,
     1774                                   &_mesa_native_packing, texObj, texImage,
     1775                                   &retain);
     1776      }
     1777
     1778      if (!retain && texImage->Data) {
     1779         FREE(texImage->Data);
     1780         texImage->Data = NULL;
     1781      }
     1782
     1783#ifdef OLD_DD_TEXTURE
     1784      /* XXX this will be removed in the future */
     1785      if (ctx->Driver.TexSubImage) {
     1786         (*ctx->Driver.TexSubImage)(ctx, target, texObj, level,
     1787                                    xoffset, yoffset, width, height,
     1788                                    texImage->IntFormat, texImage);
     1789      }
     1790      else if (ctx->Driver.TexImage) {
     1791         (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_2D, texObj,
     1792                                 level, texImage->IntFormat, texImage );
     1793      }
     1794#endif
     1795   }
     1796}
     1797
     1798
     1799
     1800void
     1801_mesa_TexSubImage3D( GLenum target, GLint level,
     1802                     GLint xoffset, GLint yoffset, GLint zoffset,
     1803                     GLsizei width, GLsizei height, GLsizei depth,
     1804                     GLenum format, GLenum type,
     1805                     const GLvoid *pixels )
     1806{
     1807   GET_CURRENT_CONTEXT(ctx);
     1808   struct gl_texture_unit *texUnit;
     1809   struct gl_texture_object *texObj;
     1810   struct gl_texture_image *texImage;
     1811   GLboolean success = GL_FALSE;
    15481812
    15491813   if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
    15501814                              width, height, depth, format, type)) {
    1551       /* error was detected */
    1552       return;
    1553    }
    1554 
    1555    destTex = texUnit->CurrentD[3]->Image[level];
    1556    assert(destTex);
     1815      return;   /* error was detected */
     1816   }
     1817
     1818   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
     1819   texObj = texUnit->CurrentD[3];
     1820   texImage = texObj->Image[level];
     1821   ASSERT(texImage);
    15571822
    15581823   if (width == 0 || height == 0 || height == 0 || !pixels)
    15591824      return;  /* no-op, not an error */
    15601825
    1561    /*
    1562     * Replace the texture subimage
    1563     */
    1564    {
    1565       const GLint texComponents = components_in_intformat(destTex->Format);
    1566       const GLenum texFormat = destTex->Format;
    1567       const GLint xoffsetb = xoffset + destTex->Border;
    1568       const GLint yoffsetb = yoffset + destTex->Border;
    1569       const GLint zoffsetb = zoffset + destTex->Border;
    1570       GLint dstRectArea = destTex->Width * destTex->Height;
    1571       GLubyte *dst = destTex->Data
    1572             + (zoffsetb * dstRectArea +  yoffsetb * destTex->Width + xoffsetb)
    1573             * texComponents;
     1826   if (!ctx->Pixel.MapColorFlag && !ctx->Pixel.ScaleOrBiasRGBA
     1827       && ctx->Driver.TexSubImage3D) {
     1828      success = (*ctx->Driver.TexSubImage3D)( ctx, target, level, xoffset,
     1829                                yoffset, zoffset, width, height, depth, format,
     1830                                type, pixels, &ctx->Unpack, texObj, texImage );
     1831   }
     1832   if (!success) {
     1833      /* XXX if Driver.TexSubImage3D, unpack image and try again? */
     1834
     1835      const GLint texComponents = components_in_intformat(texImage->Format);
     1836      const GLenum texFormat = texImage->Format;
     1837      const GLint xoffsetb = xoffset + texImage->Border;
     1838      const GLint yoffsetb = yoffset + texImage->Border;
     1839      const GLint zoffsetb = zoffset + texImage->Border;
     1840      const GLint texWidth = texImage->Width;
     1841      const GLint dstRectArea = texWidth * texImage->Height;
     1842      const GLint srcStride = _mesa_image_row_stride(&ctx->Unpack,
     1843                                                     width, format, type);
     1844      const GLint dstStride = texWidth * texComponents * sizeof(GLubyte);
     1845      GLboolean retain = GL_TRUE;
    15741846
    15751847      if (texFormat == GL_COLOR_INDEX) {
    15761848         /* color index texture */
    1577          const GLint stride = destTex->Width * sizeof(GLubyte);
    15781849         GLint img, row;
    15791850         for (img = 0; img < depth; img++) {
     1851            const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels,
     1852                                    width, height, format, type, img, 0, 0);
     1853            GLubyte *dst = texImage->Data + ((zoffsetb + img) * dstRectArea
     1854                     + yoffsetb * texWidth + xoffsetb) * texComponents;
    15801855            for (row = 0; row < height; row++) {
    1581                const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,
    1582                                     width, height, format, type, img, row, 0);
    15831856               _mesa_unpack_index_span(ctx, width, GL_UNSIGNED_BYTE, dst,
    1584                                        type, src, &ctx->Unpack, GL_TRUE);
    1585                dst += stride;
     1857                         type, (const GLvoid *) src, &ctx->Unpack, GL_TRUE);
     1858               src += srcStride;
     1859               dst += dstStride;
    15861860            }
    15871861         }
     
    15891863      else {
    15901864         /* color texture */
    1591          const GLint stride = destTex->Width * texComponents * sizeof(GLubyte);
    15921865         GLint img, row;
    15931866         for (img = 0; img < depth; img++) {
     1867            const GLubyte *src = (const GLubyte *)_mesa_image_address(&ctx->Unpack, pixels,
     1868                                     width, height, format, type, img, 0, 0);
     1869            GLubyte *dst = texImage->Data + ((zoffsetb + img) * dstRectArea
     1870                     + yoffsetb * texWidth + xoffsetb) * texComponents;
    15941871            for (row = 0; row < height; row++) {
    1595                const GLvoid *src = gl_pixel_addr_in_image(&ctx->Unpack, pixels,
    1596                                      width, height, format, type, img, row, 0);
    15971872               _mesa_unpack_ubyte_color_span(ctx, width, texFormat, dst,
    1598                                     format, type, src, &ctx->Unpack, GL_TRUE);
    1599                dst += stride;
     1873                   format, type, (const GLvoid *) src, &ctx->Unpack, GL_TRUE);
     1874               src += srcStride;
     1875               dst += dstStride;
    16001876            }
    16011877         }
    16021878      }
    1603    }
    1604 
    1605    gl_put_texobj_on_dirty_list( ctx, texUnit->CurrentD[1] );
    1606 
    1607    /*
    1608     * Inform device driver of texture image change.
    1609     */
    1610    /* XXX todo */
     1879
     1880      if (ctx->Driver.TexImage3D) {
     1881         (*ctx->Driver.TexImage3D)(ctx, target, level, texImage->Format,
     1882                                   GL_UNSIGNED_BYTE, texImage->Data,
     1883                                   &_mesa_native_packing, texObj, texImage,
     1884                                   &retain);
     1885      }
     1886
     1887      if (!retain && texImage->Data) {
     1888         FREE(texImage->Data);
     1889         texImage->Data = NULL;
     1890      }
     1891   }
    16111892}
    16121893
     
    16281909   GLubyte *image, *dst;
    16291910
    1630    image = (GLubyte *)MALLOC(width * height * 4 * sizeof(GLubyte));
     1911   image = (GLubyte *) MALLOC(width * height * 4 * sizeof(GLubyte));
    16311912   if (!image)
    16321913      return NULL;
    16331914
    16341915   /* Select buffer to read from */
    1635    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
     1916   (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
     1917                                 ctx->Pixel.DriverReadBuffer );
    16361918
    16371919   dst = image;
    16381920   stride = width * 4 * sizeof(GLubyte);
    16391921   for (i = 0; i < height; i++) {
    1640       gl_read_rgba_span( ctx, width, x, y + i, (GLubyte (*)[4]) dst );
     1922      gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i,
     1923                         (GLubyte (*)[4]) dst );
    16411924      dst += stride;
    16421925   }
    16431926
    1644    /* Restore drawing buffer */
    1645    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
     1927   /* Read from draw buffer (the default) */
     1928   (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
     1929                                 ctx->Color.DriverDrawBuffer );
    16461930
    16471931   return image;
     
    16501934
    16511935
    1652 void gl_CopyTexImage1D( GLcontext *ctx, GLenum target, GLint level,
    1653                         GLenum internalFormat,
    1654                         GLint x, GLint y,
    1655                         GLsizei width, GLint border )
    1656 {
     1936void
     1937_mesa_CopyTexImage1D( GLenum target, GLint level,
     1938                      GLenum internalFormat,
     1939                      GLint x, GLint y,
     1940                      GLsizei width, GLint border )
     1941{
     1942   GET_CURRENT_CONTEXT(ctx);
    16571943   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage1D");
    16581944
    1659    if (!copytexture_error_check(ctx, 1, target, level, internalFormat,
    1660                                width, 1, border)) {
     1945   if (copytexture_error_check(ctx, 1, target, level, internalFormat,
     1946                               width, 1, border))
     1947      return;
     1948
     1949   if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA
     1950       || !ctx->Driver.CopyTexImage1D
     1951       || !(*ctx->Driver.CopyTexImage1D)(ctx, target, level,
     1952                         internalFormat, x, y, width, border))
     1953   {
    16611954      GLubyte *image  = read_color_image( ctx, x, y, width, 1 );
    16621955      if (!image) {
     
    16641957         return;
    16651958      }
    1666       (*ctx->Exec.TexImage1D)( ctx, target, level, internalFormat, width,
    1667                                border, GL_RGBA, GL_UNSIGNED_BYTE, image );
     1959      (*ctx->Exec->TexImage1D)( target, level, internalFormat, width,
     1960                                border, GL_RGBA, GL_UNSIGNED_BYTE, image );
    16681961      FREE(image);
    16691962   }
     
    16721965
    16731966
    1674 void gl_CopyTexImage2D( GLcontext *ctx, GLenum target, GLint level,
    1675                         GLenum internalFormat,
    1676                         GLint x, GLint y, GLsizei width, GLsizei height,
    1677                         GLint border )
    1678 {
     1967void
     1968_mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
     1969                      GLint x, GLint y, GLsizei width, GLsizei height,
     1970                      GLint border )
     1971{
     1972   GET_CURRENT_CONTEXT(ctx);
    16791973   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage2D");
    16801974
    1681    if (!copytexture_error_check(ctx, 2, target, level, internalFormat,
    1682                                width, height, border)) {
     1975   if (copytexture_error_check(ctx, 2, target, level, internalFormat,
     1976                               width, height, border))
     1977      return;
     1978
     1979   if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA
     1980       || !ctx->Driver.CopyTexImage2D
     1981       || !(*ctx->Driver.CopyTexImage2D)(ctx, target, level,
     1982                         internalFormat, x, y, width, height, border))
     1983   {
    16831984      GLubyte *image  = read_color_image( ctx, x, y, width, height );
    16841985      if (!image) {
     
    16861987         return;
    16871988      }
    1688       {
    1689          struct gl_pixelstore_attrib save = ctx->Unpack;
    1690          ctx->Unpack = defaultPacking;
    1691          (ctx->Exec.TexImage2D)( ctx, target, level, internalFormat, width,
    1692                          height, border, GL_RGBA, GL_UNSIGNED_BYTE, image );
    1693          ctx->Unpack = save;  /* restore */
    1694       }
     1989      (ctx->Exec->TexImage2D)( target, level, internalFormat, width,
     1990                      height, border, GL_RGBA, GL_UNSIGNED_BYTE, image );
    16951991      FREE(image);
    16961992   }
     
    17082004                    GLint dstx, GLint dsty, GLint dstz )
    17092005{
    1710    static struct gl_pixelstore_attrib packing = {
    1711       1,            /* Alignment */
    1712       0,            /* RowLength */
    1713       0,            /* SkipPixels */
    1714       0,            /* SkipRows */
    1715       0,            /* ImageHeight */
    1716       0,            /* SkipImages */
    1717       GL_FALSE,     /* SwapBytes */
    1718       GL_FALSE      /* LsbFirst */
    1719    };
    1720 
    17212006   GLint i;
    17222007   GLint format, components, rectarea;
     
    17352020
    17362021   /* Select buffer to read from */
    1737    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
     2022   (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
     2023                                 ctx->Pixel.DriverReadBuffer );
    17382024
    17392025   for (i = 0;i < height; i++) {
    17402026      GLubyte rgba[MAX_WIDTH][4];
    17412027      GLubyte *dst;
    1742       gl_read_rgba_span( ctx, width, srcx, srcy + i, rgba );
     2028      gl_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, srcy + i, rgba );
    17432029      dst = dest->Data + ( zoffset + (dsty+i) * texwidth + dstx) * components;
    1744       _mesa_unpack_ubyte_color_span(ctx, width, (GLenum)format, dst,
     2030      _mesa_unpack_ubyte_color_span(ctx, width, format, dst,
    17452031                                    GL_RGBA, GL_UNSIGNED_BYTE, rgba,
    1746                                     &packing, GL_TRUE);
    1747    }
    1748 
    1749    /* Restore drawing buffer */
    1750    (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
    1751 }
    1752 
    1753 
    1754 
    1755 
    1756 void gl_CopyTexSubImage1D( GLcontext *ctx, GLenum target, GLint level,
    1757                            GLint xoffset, GLint x, GLint y, GLsizei width )
    1758 {
     2032                                    &_mesa_native_packing, GL_TRUE);
     2033   }
     2034
     2035   /* Read from draw buffer (the default) */
     2036   (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
     2037                                 ctx->Color.DriverDrawBuffer );
     2038}
     2039
     2040
     2041
     2042
     2043void
     2044_mesa_CopyTexSubImage1D( GLenum target, GLint level,
     2045                         GLint xoffset, GLint x, GLint y, GLsizei width )
     2046{
     2047   GET_CURRENT_CONTEXT(ctx);
    17592048   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage1D");
    17602049
    1761    if (!copytexsubimage_error_check(ctx, 1, target, level,
    1762                     xoffset, 0, 0, width, 1)) {
     2050   if (copytexsubimage_error_check(ctx, 1, target, level,
     2051                                   xoffset, 0, 0, width, 1))
     2052      return;
     2053
     2054   if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA
     2055       || !ctx->Driver.CopyTexSubImage1D
     2056       || !(*ctx->Driver.CopyTexSubImage1D)(ctx, target, level,
     2057                                            xoffset, x, y, width)) {
    17632058      struct gl_texture_unit *texUnit;
    17642059      struct gl_texture_image *teximage;
    17652060      texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    17662061      teximage = texUnit->CurrentD[1]->Image[level];
    1767       assert(teximage);
     2062      ASSERT(teximage);
    17682063      if (teximage->Data) {
    17692064         copy_tex_sub_image(ctx, teximage, width, 1, x, y, xoffset, 0, 0);
    1770          /* tell driver about the change */
    1771          if (ctx->Driver.TexImage) {
    1772            (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D,
    1773                                     texUnit->CurrentD[1],
    1774                                     level, teximage->IntFormat, teximage );
    1775          }
    1776       }
    1777    }
    1778 }
    1779 
    1780 
    1781 
    1782 void gl_CopyTexSubImage2D( GLcontext *ctx, GLenum target, GLint level,
    1783                            GLint xoffset, GLint yoffset,
    1784                            GLint x, GLint y, GLsizei width, GLsizei height )
    1785 {
     2065         /* tell driver about the change */
     2066         /* XXX this is obsolete */
     2067         if (ctx->Driver.TexImage) {
     2068            (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D,
     2069                                     texUnit->CurrentD[1],
     2070                                     level, teximage->IntFormat, teximage );
     2071         }
     2072      }
     2073   }
     2074}
     2075
     2076
     2077
     2078void
     2079_mesa_CopyTexSubImage2D( GLenum target, GLint level,
     2080                         GLint xoffset, GLint yoffset,
     2081                         GLint x, GLint y, GLsizei width, GLsizei height )
     2082{
     2083   GET_CURRENT_CONTEXT(ctx);
    17862084   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage2D");
    17872085
    1788    if (!copytexsubimage_error_check(ctx, 2, target, level,
    1789                     xoffset, yoffset, 0, width, height)) {
     2086   if (copytexsubimage_error_check(ctx, 2, target, level,
     2087                                   xoffset, yoffset, 0, width, height))
     2088      return;
     2089
     2090   if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA
     2091       || !ctx->Driver.CopyTexSubImage2D
     2092       || !(*ctx->Driver.CopyTexSubImage2D)(ctx, target, level,
     2093                                xoffset, yoffset, x, y, width, height )) {
    17902094      struct gl_texture_unit *texUnit;
    17912095      struct gl_texture_image *teximage;
    17922096      texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    17932097      teximage = texUnit->CurrentD[2]->Image[level];
    1794       assert(teximage);
     2098      ASSERT(teximage);
    17952099      if (teximage->Data) {
    17962100         copy_tex_sub_image(ctx, teximage, width, height,
    17972101                            x, y, xoffset, yoffset, 0);
    1798          /* tell driver about the change */
    1799          if (ctx->Driver.TexImage) {
    1800            (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D,
    1801                                     texUnit->CurrentD[2],
    1802                                     level, teximage->IntFormat, teximage );
    1803          }
    1804       }
    1805    }
    1806 }
    1807 
    1808 
    1809 
    1810 void gl_CopyTexSubImage3D( GLcontext *ctx, GLenum target, GLint level,
    1811                            GLint xoffset, GLint yoffset, GLint zoffset,
    1812                            GLint x, GLint y, GLsizei width, GLsizei height )
    1813 {
     2102         /* tell driver about the change */
     2103         /* XXX this is obsolete */
     2104         if (ctx->Driver.TexImage) {
     2105            (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D,
     2106                                     texUnit->CurrentD[2],
     2107                                     level, teximage->IntFormat, teximage );
     2108         }
     2109      }
     2110   }
     2111}
     2112
     2113
     2114
     2115void
     2116_mesa_CopyTexSubImage3D( GLenum target, GLint level,
     2117                         GLint xoffset, GLint yoffset, GLint zoffset,
     2118                         GLint x, GLint y, GLsizei width, GLsizei height )
     2119{
     2120   GET_CURRENT_CONTEXT(ctx);
    18142121   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage3D");
    18152122
    1816    if (!copytexsubimage_error_check(ctx, 3, target, level,
    1817                     xoffset, yoffset, zoffset, width, height)) {
     2123   if (copytexsubimage_error_check(ctx, 3, target, level,
     2124                    xoffset, yoffset, zoffset, width, height))
     2125      return;
     2126
     2127   if (ctx->Pixel.MapColorFlag || ctx->Pixel.ScaleOrBiasRGBA
     2128       || !ctx->Driver.CopyTexSubImage3D
     2129       || !(*ctx->Driver.CopyTexSubImage3D)(ctx, target, level,
     2130                     xoffset, yoffset, zoffset, x, y, width, height )) {
    18182131      struct gl_texture_unit *texUnit;
    18192132      struct gl_texture_image *teximage;
    18202133      texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    18212134      teximage = texUnit->CurrentD[3]->Image[level];
    1822       assert(teximage);
     2135      ASSERT(teximage);
    18232136      if (teximage->Data) {
    18242137         copy_tex_sub_image(ctx, teximage, width, height,
    18252138                            x, y, xoffset, yoffset, zoffset);
    1826         /* tell driver about the change */
    1827          if (ctx->Driver.TexImage) {
    1828            (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_3D,
    1829                                     texUnit->CurrentD[3],
    1830                                     level, teximage->IntFormat, teximage );
    1831          }
    1832       }
    1833    }
    1834 }
    1835 
     2139        /* tell driver about the change */
     2140         /* XXX this is obsolete */
     2141         if (ctx->Driver.TexImage) {
     2142            (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_3D,
     2143                                     texUnit->CurrentD[3],
     2144                                     level, teximage->IntFormat, teximage );
     2145         }
     2146      }
     2147   }
     2148}
Note: See TracChangeset for help on using the changeset viewer.