4293
* Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4294
* XXX this is somewhat temporary.
4296
static const struct {
4298
StoreTexImageFunc Store;
4300
texstore_funcs[MESA_FORMAT_COUNT] =
4302
{ MESA_FORMAT_NONE, NULL },
4303
{ MESA_FORMAT_RGBA8888, _mesa_texstore_rgba8888 },
4304
{ MESA_FORMAT_RGBA8888_REV, _mesa_texstore_rgba8888 },
4305
{ MESA_FORMAT_ARGB8888, _mesa_texstore_argb8888 },
4306
{ MESA_FORMAT_ARGB8888_REV, _mesa_texstore_argb8888 },
4307
{ MESA_FORMAT_XRGB8888, _mesa_texstore_argb8888 },
4308
{ MESA_FORMAT_XRGB8888_REV, _mesa_texstore_argb8888 },
4309
{ MESA_FORMAT_RGB888, _mesa_texstore_rgb888 },
4310
{ MESA_FORMAT_BGR888, _mesa_texstore_bgr888 },
4311
{ MESA_FORMAT_RGB565, _mesa_texstore_rgb565 },
4312
{ MESA_FORMAT_RGB565_REV, _mesa_texstore_rgb565 },
4313
{ MESA_FORMAT_ARGB4444, _mesa_texstore_argb4444 },
4314
{ MESA_FORMAT_ARGB4444_REV, _mesa_texstore_argb4444 },
4315
{ MESA_FORMAT_RGBA5551, _mesa_texstore_rgba5551 },
4316
{ MESA_FORMAT_ARGB1555, _mesa_texstore_argb1555 },
4317
{ MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
4318
{ MESA_FORMAT_AL44, _mesa_texstore_unorm44 },
4319
{ MESA_FORMAT_AL88, _mesa_texstore_unorm88 },
4320
{ MESA_FORMAT_AL88_REV, _mesa_texstore_unorm88 },
4321
{ MESA_FORMAT_AL1616, _mesa_texstore_unorm1616 },
4322
{ MESA_FORMAT_AL1616_REV, _mesa_texstore_unorm1616 },
4323
{ MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },
4324
{ MESA_FORMAT_A8, _mesa_texstore_unorm8 },
4325
{ MESA_FORMAT_A16, _mesa_texstore_unorm16 },
4326
{ MESA_FORMAT_L8, _mesa_texstore_unorm8 },
4327
{ MESA_FORMAT_L16, _mesa_texstore_unorm16 },
4328
{ MESA_FORMAT_I8, _mesa_texstore_unorm8 },
4329
{ MESA_FORMAT_I16, _mesa_texstore_unorm16 },
4330
{ MESA_FORMAT_CI8, _mesa_texstore_ci8 },
4331
{ MESA_FORMAT_YCBCR, _mesa_texstore_ycbcr },
4332
{ MESA_FORMAT_YCBCR_REV, _mesa_texstore_ycbcr },
4333
{ MESA_FORMAT_R8, _mesa_texstore_unorm8 },
4334
{ MESA_FORMAT_RG88, _mesa_texstore_unorm88 },
4335
{ MESA_FORMAT_RG88_REV, _mesa_texstore_unorm88 },
4336
{ MESA_FORMAT_R16, _mesa_texstore_unorm16 },
4337
{ MESA_FORMAT_RG1616, _mesa_texstore_unorm1616 },
4338
{ MESA_FORMAT_RG1616_REV, _mesa_texstore_unorm1616 },
4339
{ MESA_FORMAT_ARGB2101010, _mesa_texstore_argb2101010 },
4340
{ MESA_FORMAT_Z24_S8, _mesa_texstore_z24_s8 },
4341
{ MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
4342
{ MESA_FORMAT_Z16, _mesa_texstore_z16 },
4343
{ MESA_FORMAT_X8_Z24, _mesa_texstore_x8_z24 },
4344
{ MESA_FORMAT_Z24_X8, _mesa_texstore_z24_x8 },
4345
{ MESA_FORMAT_Z32, _mesa_texstore_z32 },
4346
{ MESA_FORMAT_S8, _mesa_texstore_s8 },
4347
{ MESA_FORMAT_SRGB8, _mesa_texstore_srgb8 },
4348
{ MESA_FORMAT_SRGBA8, _mesa_texstore_srgba8 },
4349
{ MESA_FORMAT_SARGB8, _mesa_texstore_sargb8 },
4350
{ MESA_FORMAT_SL8, _mesa_texstore_sl8 },
4351
{ MESA_FORMAT_SLA8, _mesa_texstore_sla8 },
4352
{ MESA_FORMAT_SRGB_DXT1, _mesa_texstore_rgb_dxt1 },
4353
{ MESA_FORMAT_SRGBA_DXT1, _mesa_texstore_rgba_dxt1 },
4354
{ MESA_FORMAT_SRGBA_DXT3, _mesa_texstore_rgba_dxt3 },
4355
{ MESA_FORMAT_SRGBA_DXT5, _mesa_texstore_rgba_dxt5 },
4356
{ MESA_FORMAT_RGB_FXT1, _mesa_texstore_rgb_fxt1 },
4357
{ MESA_FORMAT_RGBA_FXT1, _mesa_texstore_rgba_fxt1 },
4358
{ MESA_FORMAT_RGB_DXT1, _mesa_texstore_rgb_dxt1 },
4359
{ MESA_FORMAT_RGBA_DXT1, _mesa_texstore_rgba_dxt1 },
4360
{ MESA_FORMAT_RGBA_DXT3, _mesa_texstore_rgba_dxt3 },
4361
{ MESA_FORMAT_RGBA_DXT5, _mesa_texstore_rgba_dxt5 },
4362
{ MESA_FORMAT_RGBA_FLOAT32, _mesa_texstore_rgba_float32 },
4363
{ MESA_FORMAT_RGBA_FLOAT16, _mesa_texstore_rgba_float16 },
4364
{ MESA_FORMAT_RGB_FLOAT32, _mesa_texstore_rgba_float32 },
4365
{ MESA_FORMAT_RGB_FLOAT16, _mesa_texstore_rgba_float16 },
4366
{ MESA_FORMAT_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
4367
{ MESA_FORMAT_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
4368
{ MESA_FORMAT_LUMINANCE_FLOAT32, _mesa_texstore_rgba_float32 },
4369
{ MESA_FORMAT_LUMINANCE_FLOAT16, _mesa_texstore_rgba_float16 },
4370
{ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
4371
{ MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
4372
{ MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 },
4373
{ MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 },
4374
{ MESA_FORMAT_R_FLOAT32, _mesa_texstore_rgba_float32 },
4375
{ MESA_FORMAT_R_FLOAT16, _mesa_texstore_rgba_float16 },
4376
{ MESA_FORMAT_RG_FLOAT32, _mesa_texstore_rgba_float32 },
4377
{ MESA_FORMAT_RG_FLOAT16, _mesa_texstore_rgba_float16 },
4379
{ MESA_FORMAT_RGBA_INT8, _mesa_texstore_rgba_int8 },
4380
{ MESA_FORMAT_RGBA_INT16, _mesa_texstore_rgba_int16 },
4381
{ MESA_FORMAT_RGBA_INT32, _mesa_texstore_rgba_int32 },
4382
{ MESA_FORMAT_RGBA_UINT8, _mesa_texstore_rgba_uint8 },
4383
{ MESA_FORMAT_RGBA_UINT16, _mesa_texstore_rgba_uint16 },
4384
{ MESA_FORMAT_RGBA_UINT32, _mesa_texstore_rgba_uint32 },
4386
{ MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 },
4388
{ MESA_FORMAT_SIGNED_R8, _mesa_texstore_snorm8 },
4389
{ MESA_FORMAT_SIGNED_RG88_REV, _mesa_texstore_snorm88 },
4390
{ MESA_FORMAT_SIGNED_RGBX8888, _mesa_texstore_signed_rgbx8888 },
4392
{ MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 },
4393
{ MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 },
4395
{ MESA_FORMAT_SIGNED_R16, _mesa_texstore_snorm16 },
4396
{ MESA_FORMAT_SIGNED_GR1616, _mesa_texstore_snorm1616 },
4397
{ MESA_FORMAT_SIGNED_RGB_16, _mesa_texstore_signed_rgba_16 },
4398
{ MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 },
4399
{ MESA_FORMAT_RGBA_16, _mesa_texstore_rgba_16 },
4401
{ MESA_FORMAT_RED_RGTC1, _mesa_texstore_red_rgtc1 },
4402
{ MESA_FORMAT_SIGNED_RED_RGTC1, _mesa_texstore_signed_red_rgtc1 },
4403
{ MESA_FORMAT_RG_RGTC2, _mesa_texstore_rg_rgtc2 },
4404
{ MESA_FORMAT_SIGNED_RG_RGTC2, _mesa_texstore_signed_rg_rgtc2 },
4406
/* Re-use the R/RG texstore functions.
4407
* The code is generic enough to handle LATC too. */
4408
{ MESA_FORMAT_L_LATC1, _mesa_texstore_red_rgtc1 },
4409
{ MESA_FORMAT_SIGNED_L_LATC1, _mesa_texstore_signed_red_rgtc1 },
4410
{ MESA_FORMAT_LA_LATC2, _mesa_texstore_rg_rgtc2 },
4411
{ MESA_FORMAT_SIGNED_LA_LATC2, _mesa_texstore_signed_rg_rgtc2 },
4413
{ MESA_FORMAT_SIGNED_A8, _mesa_texstore_snorm8 },
4414
{ MESA_FORMAT_SIGNED_L8, _mesa_texstore_snorm8 },
4415
{ MESA_FORMAT_SIGNED_AL88, _mesa_texstore_snorm88 },
4416
{ MESA_FORMAT_SIGNED_I8, _mesa_texstore_snorm8 },
4418
{ MESA_FORMAT_SIGNED_A16, _mesa_texstore_snorm16 },
4419
{ MESA_FORMAT_SIGNED_L16, _mesa_texstore_snorm16 },
4420
{ MESA_FORMAT_SIGNED_AL1616, _mesa_texstore_snorm1616 },
4421
{ MESA_FORMAT_SIGNED_I16, _mesa_texstore_snorm16 },
4423
{ MESA_FORMAT_RGB9_E5_FLOAT, _mesa_texstore_rgb9_e5 },
4424
{ MESA_FORMAT_R11_G11_B10_FLOAT, _mesa_texstore_r11_g11_b10f },
4053
_mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS)
4055
ASSERT(dstFormat == MESA_FORMAT_Z32_FLOAT_X24S8);
4056
ASSERT(srcFormat == GL_DEPTH_STENCIL ||
4057
srcFormat == GL_DEPTH_COMPONENT ||
4058
srcFormat == GL_STENCIL_INDEX);
4059
ASSERT(srcFormat != GL_DEPTH_STENCIL ||
4060
srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
4062
if (srcFormat == GL_DEPTH_STENCIL &&
4063
ctx->Pixel.DepthScale == 1.0f &&
4064
ctx->Pixel.DepthBias == 0.0f &&
4065
!srcPacking->SwapBytes) {
4067
memcpy_texture(ctx, dims,
4069
dstRowStride, dstSlices,
4070
srcWidth, srcHeight, srcDepth, srcFormat, srcType,
4071
srcAddr, srcPacking);
4073
else if (srcFormat == GL_DEPTH_COMPONENT ||
4074
srcFormat == GL_STENCIL_INDEX) {
4076
const GLint srcRowStride
4077
= _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
4080
/* In case we only upload depth we need to preserve the stencil */
4081
for (img = 0; img < srcDepth; img++) {
4082
uint64_t *dstRow = (uint64_t *) dstSlices[img];
4084
= (const uint64_t *) _mesa_image_address(dims, srcPacking, srcAddr,
4085
srcWidth, srcHeight,
4088
for (row = 0; row < srcHeight; row++) {
4089
/* The unpack functions with:
4090
* dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
4091
* only write their own dword, so the other dword (stencil
4092
* or depth) is preserved. */
4093
if (srcFormat != GL_STENCIL_INDEX)
4094
_mesa_unpack_depth_span(ctx, srcWidth,
4095
GL_FLOAT_32_UNSIGNED_INT_24_8_REV, /* dst type */
4096
dstRow, /* dst addr */
4097
~0U, srcType, src, srcPacking);
4099
if (srcFormat != GL_DEPTH_COMPONENT)
4100
_mesa_unpack_stencil_span(ctx, srcWidth,
4101
GL_FLOAT_32_UNSIGNED_INT_24_8_REV, /* dst type */
4102
dstRow, /* dst addr */
4103
srcType, src, srcPacking,
4104
ctx->_ImageTransferState);
4106
src += srcRowStride;
4107
dstRow += dstRowStride / sizeof(uint64_t);
4115
_mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS)
4117
const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
4119
ASSERT(dstFormat == MESA_FORMAT_ARGB2101010_UINT);
4120
ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
4122
if (!srcPacking->SwapBytes &&
4123
dstFormat == MESA_FORMAT_ARGB2101010_UINT &&
4124
srcFormat == GL_BGRA_INTEGER_EXT &&
4125
srcType == GL_UNSIGNED_INT_2_10_10_10_REV &&
4126
baseInternalFormat == GL_RGBA) {
4127
/* simple memcpy path */
4128
memcpy_texture(ctx, dims,
4130
dstRowStride, dstSlices,
4131
srcWidth, srcHeight, srcDepth, srcFormat, srcType,
4132
srcAddr, srcPacking);
4136
const GLuint *tempImage = make_temp_uint_image(ctx, dims,
4139
srcWidth, srcHeight,
4140
srcDepth, srcFormat,
4143
const GLuint *src = tempImage;
4144
GLint img, row, col;
4147
for (img = 0; img < srcDepth; img++) {
4148
GLubyte *dstRow = dstSlices[img];
4150
for (row = 0; row < srcHeight; row++) {
4151
GLuint *dstUI = (GLuint *) dstRow;
4152
for (col = 0; col < srcWidth; col++) {
4158
dstUI[col] = (a << 30) | (r << 20) | (g << 10) | (b);
4161
dstRow += dstRowStride;
4164
free((void *) tempImage);
4428
4169
static GLboolean
4429
4170
_mesa_texstore_null(TEXSTORE_PARAMS)
4451
4190
static StoreTexImageFunc
4452
4191
_mesa_get_texstore_func(gl_format format)
4456
for (i = 0; i < MESA_FORMAT_COUNT; i++) {
4457
ASSERT(texstore_funcs[i].Name == i);
4193
static StoreTexImageFunc table[MESA_FORMAT_COUNT];
4194
static GLboolean initialized = GL_FALSE;
4197
table[MESA_FORMAT_NONE] = _mesa_texstore_null;
4199
table[MESA_FORMAT_RGBA8888] = _mesa_texstore_rgba8888;
4200
table[MESA_FORMAT_RGBA8888_REV] = _mesa_texstore_rgba8888;
4201
table[MESA_FORMAT_ARGB8888] = _mesa_texstore_argb8888;
4202
table[MESA_FORMAT_ARGB8888_REV] = _mesa_texstore_argb8888;
4203
table[MESA_FORMAT_RGBX8888] = _mesa_texstore_rgba8888;
4204
table[MESA_FORMAT_RGBX8888_REV] = _mesa_texstore_rgba8888;
4205
table[MESA_FORMAT_XRGB8888] = _mesa_texstore_argb8888;
4206
table[MESA_FORMAT_XRGB8888_REV] = _mesa_texstore_argb8888;
4207
table[MESA_FORMAT_RGB888] = _mesa_texstore_rgb888;
4208
table[MESA_FORMAT_BGR888] = _mesa_texstore_bgr888;
4209
table[MESA_FORMAT_RGB565] = _mesa_texstore_rgb565;
4210
table[MESA_FORMAT_RGB565_REV] = _mesa_texstore_rgb565;
4211
table[MESA_FORMAT_ARGB4444] = _mesa_texstore_argb4444;
4212
table[MESA_FORMAT_ARGB4444_REV] = _mesa_texstore_argb4444;
4213
table[MESA_FORMAT_RGBA5551] = _mesa_texstore_rgba5551;
4214
table[MESA_FORMAT_ARGB1555] = _mesa_texstore_argb1555;
4215
table[MESA_FORMAT_ARGB1555_REV] = _mesa_texstore_argb1555;
4216
table[MESA_FORMAT_AL44] = _mesa_texstore_unorm44;
4217
table[MESA_FORMAT_AL88] = _mesa_texstore_unorm88;
4218
table[MESA_FORMAT_AL88_REV] = _mesa_texstore_unorm88;
4219
table[MESA_FORMAT_AL1616] = _mesa_texstore_unorm1616;
4220
table[MESA_FORMAT_AL1616_REV] = _mesa_texstore_unorm1616;
4221
table[MESA_FORMAT_RGB332] = _mesa_texstore_rgb332;
4222
table[MESA_FORMAT_A8] = _mesa_texstore_unorm8;
4223
table[MESA_FORMAT_A16] = _mesa_texstore_unorm16;
4224
table[MESA_FORMAT_L8] = _mesa_texstore_unorm8;
4225
table[MESA_FORMAT_L16] = _mesa_texstore_unorm16;
4226
table[MESA_FORMAT_I8] = _mesa_texstore_unorm8;
4227
table[MESA_FORMAT_I16] = _mesa_texstore_unorm16;
4228
table[MESA_FORMAT_YCBCR] = _mesa_texstore_ycbcr;
4229
table[MESA_FORMAT_YCBCR_REV] = _mesa_texstore_ycbcr;
4230
table[MESA_FORMAT_R8] = _mesa_texstore_unorm8;
4231
table[MESA_FORMAT_GR88] = _mesa_texstore_unorm88;
4232
table[MESA_FORMAT_RG88] = _mesa_texstore_unorm88;
4233
table[MESA_FORMAT_R16] = _mesa_texstore_unorm16;
4234
table[MESA_FORMAT_RG1616] = _mesa_texstore_unorm1616;
4235
table[MESA_FORMAT_RG1616_REV] = _mesa_texstore_unorm1616;
4236
table[MESA_FORMAT_ARGB2101010] = _mesa_texstore_argb2101010;
4237
table[MESA_FORMAT_Z24_S8] = _mesa_texstore_z24_s8;
4238
table[MESA_FORMAT_S8_Z24] = _mesa_texstore_s8_z24;
4239
table[MESA_FORMAT_Z16] = _mesa_texstore_z16;
4240
table[MESA_FORMAT_X8_Z24] = _mesa_texstore_x8_z24;
4241
table[MESA_FORMAT_Z24_X8] = _mesa_texstore_z24_x8;
4242
table[MESA_FORMAT_Z32] = _mesa_texstore_z32;
4243
table[MESA_FORMAT_S8] = _mesa_texstore_s8;
4244
table[MESA_FORMAT_SRGB8] = _mesa_texstore_srgb8;
4245
table[MESA_FORMAT_SRGBA8] = _mesa_texstore_srgba8;
4246
table[MESA_FORMAT_SARGB8] = _mesa_texstore_sargb8;
4247
table[MESA_FORMAT_SL8] = _mesa_texstore_sl8;
4248
table[MESA_FORMAT_SLA8] = _mesa_texstore_sla8;
4249
table[MESA_FORMAT_SRGB_DXT1] = _mesa_texstore_rgb_dxt1;
4250
table[MESA_FORMAT_SRGBA_DXT1] = _mesa_texstore_rgba_dxt1;
4251
table[MESA_FORMAT_SRGBA_DXT3] = _mesa_texstore_rgba_dxt3;
4252
table[MESA_FORMAT_SRGBA_DXT5] = _mesa_texstore_rgba_dxt5;
4253
table[MESA_FORMAT_RGB_FXT1] = _mesa_texstore_rgb_fxt1;
4254
table[MESA_FORMAT_RGBA_FXT1] = _mesa_texstore_rgba_fxt1;
4255
table[MESA_FORMAT_RGB_DXT1] = _mesa_texstore_rgb_dxt1;
4256
table[MESA_FORMAT_RGBA_DXT1] = _mesa_texstore_rgba_dxt1;
4257
table[MESA_FORMAT_RGBA_DXT3] = _mesa_texstore_rgba_dxt3;
4258
table[MESA_FORMAT_RGBA_DXT5] = _mesa_texstore_rgba_dxt5;
4259
table[MESA_FORMAT_RGBA_FLOAT32] = _mesa_texstore_rgba_float32;
4260
table[MESA_FORMAT_RGBA_FLOAT16] = _mesa_texstore_rgba_float16;
4261
table[MESA_FORMAT_RGB_FLOAT32] = _mesa_texstore_rgba_float32;
4262
table[MESA_FORMAT_RGB_FLOAT16] = _mesa_texstore_rgba_float16;
4263
table[MESA_FORMAT_ALPHA_FLOAT32] = _mesa_texstore_rgba_float32;
4264
table[MESA_FORMAT_ALPHA_FLOAT16] = _mesa_texstore_rgba_float16;
4265
table[MESA_FORMAT_LUMINANCE_FLOAT32] = _mesa_texstore_rgba_float32;
4266
table[MESA_FORMAT_LUMINANCE_FLOAT16] = _mesa_texstore_rgba_float16;
4267
table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = _mesa_texstore_rgba_float32;
4268
table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = _mesa_texstore_rgba_float16;
4269
table[MESA_FORMAT_INTENSITY_FLOAT32] = _mesa_texstore_rgba_float32;
4270
table[MESA_FORMAT_INTENSITY_FLOAT16] = _mesa_texstore_rgba_float16;
4271
table[MESA_FORMAT_R_FLOAT32] = _mesa_texstore_rgba_float32;
4272
table[MESA_FORMAT_R_FLOAT16] = _mesa_texstore_rgba_float16;
4273
table[MESA_FORMAT_RG_FLOAT32] = _mesa_texstore_rgba_float32;
4274
table[MESA_FORMAT_RG_FLOAT16] = _mesa_texstore_rgba_float16;
4275
table[MESA_FORMAT_DUDV8] = _mesa_texstore_dudv8;
4276
table[MESA_FORMAT_SIGNED_R8] = _mesa_texstore_snorm8;
4277
table[MESA_FORMAT_SIGNED_RG88_REV] = _mesa_texstore_snorm88;
4278
table[MESA_FORMAT_SIGNED_RGBX8888] = _mesa_texstore_signed_rgbx8888;
4279
table[MESA_FORMAT_SIGNED_RGBA8888] = _mesa_texstore_signed_rgba8888;
4280
table[MESA_FORMAT_SIGNED_RGBA8888_REV] = _mesa_texstore_signed_rgba8888;
4281
table[MESA_FORMAT_SIGNED_R16] = _mesa_texstore_snorm16;
4282
table[MESA_FORMAT_SIGNED_GR1616] = _mesa_texstore_snorm1616;
4283
table[MESA_FORMAT_SIGNED_RGB_16] = _mesa_texstore_signed_rgba_16;
4284
table[MESA_FORMAT_SIGNED_RGBA_16] = _mesa_texstore_signed_rgba_16;
4285
table[MESA_FORMAT_RGBA_16] = _mesa_texstore_rgba_16;
4286
table[MESA_FORMAT_RED_RGTC1] = _mesa_texstore_red_rgtc1;
4287
table[MESA_FORMAT_SIGNED_RED_RGTC1] = _mesa_texstore_signed_red_rgtc1;
4288
table[MESA_FORMAT_RG_RGTC2] = _mesa_texstore_rg_rgtc2;
4289
table[MESA_FORMAT_SIGNED_RG_RGTC2] = _mesa_texstore_signed_rg_rgtc2;
4290
table[MESA_FORMAT_L_LATC1] = _mesa_texstore_red_rgtc1;
4291
table[MESA_FORMAT_SIGNED_L_LATC1] = _mesa_texstore_signed_red_rgtc1;
4292
table[MESA_FORMAT_LA_LATC2] = _mesa_texstore_rg_rgtc2;
4293
table[MESA_FORMAT_SIGNED_LA_LATC2] = _mesa_texstore_signed_rg_rgtc2;
4294
table[MESA_FORMAT_ETC1_RGB8] = _mesa_texstore_etc1_rgb8;
4295
table[MESA_FORMAT_SIGNED_A8] = _mesa_texstore_snorm8;
4296
table[MESA_FORMAT_SIGNED_L8] = _mesa_texstore_snorm8;
4297
table[MESA_FORMAT_SIGNED_AL88] = _mesa_texstore_snorm88;
4298
table[MESA_FORMAT_SIGNED_I8] = _mesa_texstore_snorm8;
4299
table[MESA_FORMAT_SIGNED_A16] = _mesa_texstore_snorm16;
4300
table[MESA_FORMAT_SIGNED_L16] = _mesa_texstore_snorm16;
4301
table[MESA_FORMAT_SIGNED_AL1616] = _mesa_texstore_snorm1616;
4302
table[MESA_FORMAT_SIGNED_I16] = _mesa_texstore_snorm16;
4303
table[MESA_FORMAT_RGB9_E5_FLOAT] = _mesa_texstore_rgb9_e5;
4304
table[MESA_FORMAT_R11_G11_B10_FLOAT] = _mesa_texstore_r11_g11_b10f;
4305
table[MESA_FORMAT_Z32_FLOAT] = _mesa_texstore_z32;
4306
table[MESA_FORMAT_Z32_FLOAT_X24S8] = _mesa_texstore_z32f_x24s8;
4308
table[MESA_FORMAT_ALPHA_UINT8] = _mesa_texstore_rgba_uint8;
4309
table[MESA_FORMAT_ALPHA_UINT16] = _mesa_texstore_rgba_uint16;
4310
table[MESA_FORMAT_ALPHA_UINT32] = _mesa_texstore_rgba_uint32;
4311
table[MESA_FORMAT_ALPHA_INT8] = _mesa_texstore_rgba_int8;
4312
table[MESA_FORMAT_ALPHA_INT16] = _mesa_texstore_rgba_int16;
4313
table[MESA_FORMAT_ALPHA_INT32] = _mesa_texstore_rgba_int32;
4315
table[MESA_FORMAT_INTENSITY_UINT8] = _mesa_texstore_rgba_uint8;
4316
table[MESA_FORMAT_INTENSITY_UINT16] = _mesa_texstore_rgba_uint16;
4317
table[MESA_FORMAT_INTENSITY_UINT32] = _mesa_texstore_rgba_uint32;
4318
table[MESA_FORMAT_INTENSITY_INT8] = _mesa_texstore_rgba_int8;
4319
table[MESA_FORMAT_INTENSITY_INT16] = _mesa_texstore_rgba_int16;
4320
table[MESA_FORMAT_INTENSITY_INT32] = _mesa_texstore_rgba_int32;
4322
table[MESA_FORMAT_LUMINANCE_UINT8] = _mesa_texstore_rgba_uint8;
4323
table[MESA_FORMAT_LUMINANCE_UINT16] = _mesa_texstore_rgba_uint16;
4324
table[MESA_FORMAT_LUMINANCE_UINT32] = _mesa_texstore_rgba_uint32;
4325
table[MESA_FORMAT_LUMINANCE_INT8] = _mesa_texstore_rgba_int8;
4326
table[MESA_FORMAT_LUMINANCE_INT16] = _mesa_texstore_rgba_int16;
4327
table[MESA_FORMAT_LUMINANCE_INT32] = _mesa_texstore_rgba_int32;
4329
table[MESA_FORMAT_LUMINANCE_ALPHA_UINT8] = _mesa_texstore_rgba_uint8;
4330
table[MESA_FORMAT_LUMINANCE_ALPHA_UINT16] = _mesa_texstore_rgba_uint16;
4331
table[MESA_FORMAT_LUMINANCE_ALPHA_UINT32] = _mesa_texstore_rgba_uint32;
4332
table[MESA_FORMAT_LUMINANCE_ALPHA_INT8] = _mesa_texstore_rgba_int8;
4333
table[MESA_FORMAT_LUMINANCE_ALPHA_INT16] = _mesa_texstore_rgba_int16;
4334
table[MESA_FORMAT_LUMINANCE_ALPHA_INT32] = _mesa_texstore_rgba_int32;
4336
table[MESA_FORMAT_R_INT8] = _mesa_texstore_rgba_int8;
4337
table[MESA_FORMAT_RG_INT8] = _mesa_texstore_rgba_int8;
4338
table[MESA_FORMAT_RGB_INT8] = _mesa_texstore_rgba_int8;
4339
table[MESA_FORMAT_RGBA_INT8] = _mesa_texstore_rgba_int8;
4340
table[MESA_FORMAT_R_INT16] = _mesa_texstore_rgba_int16;
4341
table[MESA_FORMAT_RG_INT16] = _mesa_texstore_rgba_int16;
4342
table[MESA_FORMAT_RGB_INT16] = _mesa_texstore_rgba_int16;
4343
table[MESA_FORMAT_RGBA_INT16] = _mesa_texstore_rgba_int16;
4344
table[MESA_FORMAT_R_INT32] = _mesa_texstore_rgba_int32;
4345
table[MESA_FORMAT_RG_INT32] = _mesa_texstore_rgba_int32;
4346
table[MESA_FORMAT_RGB_INT32] = _mesa_texstore_rgba_int32;
4347
table[MESA_FORMAT_RGBA_INT32] = _mesa_texstore_rgba_int32;
4349
table[MESA_FORMAT_R_UINT8] = _mesa_texstore_rgba_uint8;
4350
table[MESA_FORMAT_RG_UINT8] = _mesa_texstore_rgba_uint8;
4351
table[MESA_FORMAT_RGB_UINT8] = _mesa_texstore_rgba_uint8;
4352
table[MESA_FORMAT_RGBA_UINT8] = _mesa_texstore_rgba_uint8;
4353
table[MESA_FORMAT_R_UINT16] = _mesa_texstore_rgba_uint16;
4354
table[MESA_FORMAT_RG_UINT16] = _mesa_texstore_rgba_uint16;
4355
table[MESA_FORMAT_RGB_UINT16] = _mesa_texstore_rgba_uint16;
4356
table[MESA_FORMAT_RGBA_UINT16] = _mesa_texstore_rgba_uint16;
4357
table[MESA_FORMAT_R_UINT32] = _mesa_texstore_rgba_uint32;
4358
table[MESA_FORMAT_RG_UINT32] = _mesa_texstore_rgba_uint32;
4359
table[MESA_FORMAT_RGB_UINT32] = _mesa_texstore_rgba_uint32;
4360
table[MESA_FORMAT_RGBA_UINT32] = _mesa_texstore_rgba_uint32;
4362
table[MESA_FORMAT_ARGB2101010_UINT] = _mesa_texstore_argb2101010_uint;
4363
initialized = GL_TRUE;
4460
ASSERT(texstore_funcs[format].Name == format);
4462
if (texstore_funcs[format].Store)
4463
return texstore_funcs[format].Store;
4465
return _mesa_texstore_null;
4366
ASSERT(table[format]);
4367
return table[format];
4479
4381
storeImage = _mesa_get_texstore_func(dstFormat);
4481
4383
success = storeImage(ctx, dims, baseInternalFormat,
4482
dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
4483
dstRowStride, dstImageOffsets,
4385
dstRowStride, dstSlices,
4484
4386
srcWidth, srcHeight, srcDepth,
4485
4387
srcFormat, srcType, srcAddr, srcPacking);
4486
4388
return success;
4490
/** Return texture size in bytes */
4492
texture_size(const struct gl_texture_image *texImage)
4494
GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
4495
texImage->Height, texImage->Depth);
4500
/** Return row stride in bytes */
4502
texture_row_stride(const struct gl_texture_image *texImage)
4504
GLuint stride = _mesa_format_row_stride(texImage->TexFormat,
4512
* This is the software fallback for Driver.TexImage1D()
4513
* and Driver.CopyTexImage1D().
4514
* \sa _mesa_store_teximage2d()
4393
* Normally, we'll only _write_ texel data to a texture when we map it.
4394
* But if the user is providing depth or stencil values and the texture
4395
* image is a combined depth/stencil format, we'll actually read from
4396
* the texture buffer too (in order to insert the depth or stencil values.
4397
* \param userFormat the user-provided image format
4398
* \param texFormat the destination texture format
4401
get_read_write_mode(GLenum userFormat, gl_format texFormat)
4403
if ((userFormat == GL_STENCIL_INDEX || userFormat == GL_DEPTH_COMPONENT)
4404
&& _mesa_get_format_base_format(texFormat) == GL_DEPTH_STENCIL)
4405
return GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
4407
return GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT;
4412
* Helper function for storing 1D, 2D, 3D whole and subimages into texture
4414
* The source of the image data may be user memory or a PBO. In the later
4415
* case, we'll map the PBO, copy from it, then unmap it.
4418
store_texsubimage(struct gl_context *ctx,
4419
struct gl_texture_image *texImage,
4420
GLint xoffset, GLint yoffset, GLint zoffset,
4421
GLint width, GLint height, GLint depth,
4422
GLenum format, GLenum type, const GLvoid *pixels,
4423
const struct gl_pixelstore_attrib *packing,
4427
const GLbitfield mapMode = get_read_write_mode(format, texImage->TexFormat);
4428
const GLenum target = texImage->TexObject->Target;
4429
GLboolean success = GL_FALSE;
4430
GLuint dims, slice, numSlices = 1, sliceOffset = 0;
4431
GLint srcImageStride = 0;
4434
assert(xoffset + width <= texImage->Width);
4435
assert(yoffset + height <= texImage->Height);
4436
assert(zoffset + depth <= texImage->Depth);
4442
case GL_TEXTURE_2D_ARRAY:
4450
/* get pointer to src pixels (may be in a pbo which we'll map here) */
4451
src = (const GLubyte *)
4452
_mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
4453
format, type, pixels, packing, caller);
4457
/* compute slice info (and do some sanity checks) */
4460
case GL_TEXTURE_RECTANGLE:
4461
case GL_TEXTURE_CUBE_MAP:
4462
/* one image slice, nothing special needs to be done */
4465
assert(height == 1);
4467
assert(yoffset == 0);
4468
assert(zoffset == 0);
4470
case GL_TEXTURE_1D_ARRAY:
4472
assert(zoffset == 0);
4474
sliceOffset = yoffset;
4477
srcImageStride = _mesa_image_row_stride(packing, width, format, type);
4479
case GL_TEXTURE_2D_ARRAY:
4481
sliceOffset = zoffset;
4484
srcImageStride = _mesa_image_image_stride(packing, width, height,
4488
/* we'll store 3D images as a series of slices */
4490
sliceOffset = zoffset;
4491
srcImageStride = _mesa_image_image_stride(packing, width, height,
4495
_mesa_warning(ctx, "Unexpected target 0x%x in store_texsubimage()", target);
4499
assert(numSlices == 1 || srcImageStride != 0);
4501
for (slice = 0; slice < numSlices; slice++) {
4505
ctx->Driver.MapTextureImage(ctx, texImage,
4506
slice + sliceOffset,
4507
xoffset, yoffset, width, height,
4508
mapMode, &dstMap, &dstRowStride);
4510
/* Note: we're only storing a 2D (or 1D) slice at a time but we need
4511
* to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4512
* used for 3D images.
4514
success = _mesa_texstore(ctx, dims, texImage->_BaseFormat,
4515
texImage->TexFormat,
4518
width, height, 1, /* w, h, d */
4519
format, type, src, packing);
4521
ctx->Driver.UnmapTextureImage(ctx, texImage, slice + sliceOffset);
4524
src += srcImageStride;
4531
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
4533
_mesa_unmap_teximage_pbo(ctx, packing);
4539
* This is the fallback for Driver.TexImage1D().
4517
_mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
4542
_mesa_store_teximage1d(struct gl_context *ctx,
4543
struct gl_texture_image *texImage,
4518
4544
GLint internalFormat,
4519
4545
GLint width, GLint border,
4520
4546
GLenum format, GLenum type, const GLvoid *pixels,
4521
const struct gl_pixelstore_attrib *packing,
4522
struct gl_texture_object *texObj,
4523
struct gl_texture_image *texImage)
4547
const struct gl_pixelstore_attrib *packing)
4528
/* allocate memory */
4529
sizeInBytes = texture_size(texImage);
4530
texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4531
if (!texImage->Data) {
4552
/* allocate storage for texture data */
4553
if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
4532
4555
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
4536
pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
4537
pixels, packing, "glTexImage1D");
4539
/* Note: we check for a NULL image pointer here, _after_ we allocated
4540
* memory for the texture. That's what the GL spec calls for.
4545
const GLint dstRowStride = 0;
4546
GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
4547
texImage->TexFormat,
4549
0, 0, 0, /* dstX/Y/Zoffset */
4551
texImage->ImageOffsets,
4553
format, type, pixels, packing);
4555
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
4559
_mesa_unmap_teximage_pbo(ctx, packing);
4559
store_texsubimage(ctx, texImage,
4560
0, 0, 0, width, 1, 1,
4561
format, type, pixels, packing, "glTexImage1D");
4564
* This is the software fallback for Driver.TexImage2D()
4565
* and Driver.CopyTexImage2D().
4567
* This function is oriented toward storing images in main memory, rather
4568
* than VRAM. Device driver's can easily plug in their own replacement.
4566
* This is the fallback for Driver.TexImage2D().
4571
_mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
4569
_mesa_store_teximage2d(struct gl_context *ctx,
4570
struct gl_texture_image *texImage,
4572
4571
GLint internalFormat,
4573
4572
GLint width, GLint height, GLint border,
4574
4573
GLenum format, GLenum type, const void *pixels,
4575
const struct gl_pixelstore_attrib *packing,
4576
struct gl_texture_object *texObj,
4577
struct gl_texture_image *texImage)
4574
const struct gl_pixelstore_attrib *packing)
4576
if (width == 0 || height == 0)
4582
/* allocate memory */
4583
sizeInBytes = texture_size(texImage);
4584
texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4585
if (!texImage->Data) {
4579
/* allocate storage for texture data */
4580
if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
4581
width, height, 1)) {
4586
4582
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
4590
pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
4591
pixels, packing, "glTexImage2D");
4593
/* Note: we check for a NULL image pointer here, _after_ we allocated
4594
* memory for the texture. That's what the GL spec calls for.
4599
GLint dstRowStride = texture_row_stride(texImage);
4600
GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
4601
texImage->TexFormat,
4603
0, 0, 0, /* dstX/Y/Zoffset */
4605
texImage->ImageOffsets,
4607
format, type, pixels, packing);
4609
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
4613
_mesa_unmap_teximage_pbo(ctx, packing);
4586
store_texsubimage(ctx, texImage,
4587
0, 0, 0, width, height, 1,
4588
format, type, pixels, packing, "glTexImage2D");
4619
* This is the software fallback for Driver.TexImage3D()
4620
* and Driver.CopyTexImage3D().
4621
* \sa _mesa_store_teximage2d()
4594
* This is the fallback for Driver.TexImage3D().
4624
_mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
4597
_mesa_store_teximage3d(struct gl_context *ctx,
4598
struct gl_texture_image *texImage,
4625
4599
GLint internalFormat,
4626
4600
GLint width, GLint height, GLint depth, GLint border,
4627
4601
GLenum format, GLenum type, const void *pixels,
4628
const struct gl_pixelstore_attrib *packing,
4629
struct gl_texture_object *texObj,
4630
struct gl_texture_image *texImage)
4602
const struct gl_pixelstore_attrib *packing)
4604
if (width == 0 || height == 0 || depth == 0)
4635
/* allocate memory */
4636
sizeInBytes = texture_size(texImage);
4637
texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4638
if (!texImage->Data) {
4607
/* allocate storage for texture data */
4608
if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
4609
width, height, depth)) {
4639
4610
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
4643
pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
4644
type, pixels, packing, "glTexImage3D");
4646
/* Note: we check for a NULL image pointer here, _after_ we allocated
4647
* memory for the texture. That's what the GL spec calls for.
4652
GLint dstRowStride = texture_row_stride(texImage);
4653
GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
4654
texImage->TexFormat,
4656
0, 0, 0, /* dstX/Y/Zoffset */
4658
texImage->ImageOffsets,
4659
width, height, depth,
4660
format, type, pixels, packing);
4662
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
4666
_mesa_unmap_teximage_pbo(ctx, packing);
4614
store_texsubimage(ctx, texImage,
4615
0, 0, 0, width, height, depth,
4616
format, type, pixels, packing, "glTexImage3D");
4673
* This is the software fallback for Driver.TexSubImage1D()
4674
* and Driver.CopyTexSubImage1D().
4623
* This is the fallback for Driver.TexSubImage1D().
4677
_mesa_store_texsubimage1d(struct gl_context *ctx, GLenum target, GLint level,
4626
_mesa_store_texsubimage1d(struct gl_context *ctx,
4627
struct gl_texture_image *texImage,
4678
4628
GLint xoffset, GLint width,
4679
4629
GLenum format, GLenum type, const void *pixels,
4680
const struct gl_pixelstore_attrib *packing,
4681
struct gl_texture_object *texObj,
4682
struct gl_texture_image *texImage)
4630
const struct gl_pixelstore_attrib *packing)
4684
/* get pointer to src pixels (may be in a pbo which we'll map here) */
4685
pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
4686
pixels, packing, "glTexSubImage1D");
4691
const GLint dstRowStride = 0;
4692
GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
4693
texImage->TexFormat,
4695
xoffset, 0, 0, /* offsets */
4697
texImage->ImageOffsets,
4699
format, type, pixels, packing);
4701
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D");
4705
_mesa_unmap_teximage_pbo(ctx, packing);
4632
store_texsubimage(ctx, texImage,
4633
xoffset, 0, 0, width, 1, 1,
4634
format, type, pixels, packing, "glTexSubImage1D");
4711
* This is the software fallback for Driver.TexSubImage2D()
4712
* and Driver.CopyTexSubImage2D().
4640
* This is the fallback for Driver.TexSubImage2D().
4715
_mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level,
4643
_mesa_store_texsubimage2d(struct gl_context *ctx,
4644
struct gl_texture_image *texImage,
4716
4645
GLint xoffset, GLint yoffset,
4717
4646
GLint width, GLint height,
4718
4647
GLenum format, GLenum type, const void *pixels,
4719
const struct gl_pixelstore_attrib *packing,
4720
struct gl_texture_object *texObj,
4721
struct gl_texture_image *texImage)
4648
const struct gl_pixelstore_attrib *packing)
4723
/* get pointer to src pixels (may be in a pbo which we'll map here) */
4724
pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
4725
pixels, packing, "glTexSubImage2D");
4730
GLint dstRowStride = texture_row_stride(texImage);
4731
GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
4732
texImage->TexFormat,
4734
xoffset, yoffset, 0,
4736
texImage->ImageOffsets,
4738
format, type, pixels, packing);
4740
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
4744
_mesa_unmap_teximage_pbo(ctx, packing);
4650
store_texsubimage(ctx, texImage,
4651
xoffset, yoffset, 0, width, height, 1,
4652
format, type, pixels, packing, "glTexSubImage2D");
4749
* This is the software fallback for Driver.TexSubImage3D().
4750
* and Driver.CopyTexSubImage3D().
4657
* This is the fallback for Driver.TexSubImage3D().
4753
_mesa_store_texsubimage3d(struct gl_context *ctx, GLenum target, GLint level,
4660
_mesa_store_texsubimage3d(struct gl_context *ctx,
4661
struct gl_texture_image *texImage,
4754
4662
GLint xoffset, GLint yoffset, GLint zoffset,
4755
4663
GLint width, GLint height, GLint depth,
4756
4664
GLenum format, GLenum type, const void *pixels,
4757
const struct gl_pixelstore_attrib *packing,
4758
struct gl_texture_object *texObj,
4759
struct gl_texture_image *texImage)
4665
const struct gl_pixelstore_attrib *packing)
4761
/* get pointer to src pixels (may be in a pbo which we'll map here) */
4762
pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
4763
type, pixels, packing,
4769
GLint dstRowStride = texture_row_stride(texImage);
4770
GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
4771
texImage->TexFormat,
4773
xoffset, yoffset, zoffset,
4775
texImage->ImageOffsets,
4776
width, height, depth,
4777
format, type, pixels, packing);
4779
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage3D");
4783
_mesa_unmap_teximage_pbo(ctx, packing);
4667
store_texsubimage(ctx, texImage,
4668
xoffset, yoffset, zoffset, width, height, depth,
4669
format, type, pixels, packing, "glTexSubImage3D");