#include "main/fbobject.h"
#include "main/teximage.h"
#include "main/texobj.h"
+#include "util/u_memory.h"
#include "swrast/swrast.h"
#include "swrast/s_context.h"
}
static unsigned int
-texture_slices(struct gl_texture_image *texImage)
+texture_slices(const struct gl_texture_image *texImage)
{
if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY)
return texImage->Height;
{
struct swrast_texture_image *swImg = swrast_texture_image(texImage);
- if ((texImage->Width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
- (texImage->Height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
- (texImage->Depth == 1 || _mesa_is_pow_two(texImage->Depth2)))
+ if ((texImage->Width == 1 || util_is_power_of_two_or_zero(texImage->Width2)) &&
+ (texImage->Height == 1 || util_is_power_of_two_or_zero(texImage->Height2)) &&
+ (texImage->Depth == 1 || util_is_power_of_two_or_zero(texImage->Depth2)))
swImg->_IsPowerOfTwo = GL_TRUE;
else
swImg->_IsPowerOfTwo = GL_FALSE;
struct gl_texture_image *texImage)
{
struct swrast_texture_image *swImage = swrast_texture_image(texImage);
- if (swImage->Buffer) {
- _mesa_align_free(swImage->Buffer);
- swImage->Buffer = NULL;
- }
+
+ _mesa_align_free(swImage->Buffer);
+ swImage->Buffer = NULL;
free(swImage->ImageSlices);
swImage->ImageSlices = NULL;
* Error checking for debugging only.
*/
static void
-_mesa_check_map_teximage(struct gl_texture_image *texImage,
- GLuint slice, GLuint x, GLuint y, GLuint w, GLuint h)
+check_map_teximage(const struct gl_texture_image *texImage,
+ GLuint slice, GLuint x, GLuint y, GLuint w, GLuint h)
{
if (texImage->TexObject->Target == GL_TEXTURE_1D)
assert(y < texImage->Height || texImage->Height == 0);
assert(x + w <= texImage->Width);
assert(y + h <= texImage->Height);
+ assert(slice < texture_slices(texImage));
}
/**
GLint stride, texelSize;
GLuint bw, bh;
- _mesa_check_map_teximage(texImage, slice, x, y, w, h);
+ check_map_teximage(texImage, slice, x, y, w, h);
+
+ if (!swImage->Buffer) {
+ /* Either glTexImage was called with a NULL <pixels> argument or
+ * we ran out of memory when allocating texture memory,
+ */
+ *mapOut = NULL;
+ *rowStrideOut = 0;
+ return;
+ }
texelSize = _mesa_get_format_bytes(texImage->TexFormat);
stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
assert(x % bw == 0);
assert(y % bh == 0);
- if (!swImage->Buffer) {
- /* probably ran out of memory when allocating tex mem */
- *mapOut = NULL;
- return;
- }
-
/* This function can only be used with a swrast-allocated buffer, in which
* case ImageSlices is populated with pointers into Buffer.
*/
assert(swImage->Buffer);
assert(swImage->Buffer == swImage->ImageSlices[0]);
- assert(slice < texture_slices(texImage));
map = swImage->ImageSlices[slice];
/* apply x/y offset to map address */
for (level = texObj->BaseLevel; level < MAX_TEXTURE_LEVELS; level++) {
struct gl_texture_image *texImage = texObj->Image[face][level];
struct swrast_texture_image *swImage = swrast_texture_image(texImage);
- unsigned int i;
+ unsigned int i, slices;
if (!texImage)
continue;
continue;
}
- for (i = 0; i < texture_slices(texImage); i++) {
+ if (!swImage->ImageSlices) {
+ swImage->ImageSlices =
+ calloc(texture_slices(texImage), sizeof(void *));
+ if (!swImage->ImageSlices)
+ continue;
+ }
+
+ slices = texture_slices(texImage);
+
+ for (i = 0; i < slices; i++) {
GLubyte *map;
GLint rowStride;
for (level = texObj->BaseLevel; level < MAX_TEXTURE_LEVELS; level++) {
struct gl_texture_image *texImage = texObj->Image[face][level];
struct swrast_texture_image *swImage = swrast_texture_image(texImage);
- unsigned int i;
+ unsigned int i, slices;
if (!texImage)
continue;
if (swImage->Buffer)
return;
- for (i = 0; i < texture_slices(texImage); i++) {
+ if (!swImage->ImageSlices)
+ continue;
+
+ slices = texture_slices(texImage);
+
+ for (i = 0; i < slices; i++) {
if (swImage->ImageSlices[i]) {
ctx->Driver.UnmapTextureImage(ctx, texImage, i);
swImage->ImageSlices[i] = NULL;
void
_swrast_map_textures(struct gl_context *ctx)
{
- GLbitfield enabledUnits = ctx->Texture._EnabledUnits;
+ int unit;
- /* loop over enabled texture units */
- while (enabledUnits) {
- GLuint unit = ffs(enabledUnits) - 1;
+ for (unit = 0; unit <= ctx->Texture._MaxEnabledTexImageUnit; unit++) {
struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
-
- _swrast_map_texture(ctx, texObj);
- enabledUnits &= ~(1 << unit);
+ if (texObj)
+ _swrast_map_texture(ctx, texObj);
}
}
void
_swrast_unmap_textures(struct gl_context *ctx)
{
- GLbitfield enabledUnits = ctx->Texture._EnabledUnits;
-
- /* loop over enabled texture units */
- while (enabledUnits) {
- GLuint unit = ffs(enabledUnits) - 1;
+ int unit;
+ for (unit = 0; unit <= ctx->Texture._MaxEnabledTexImageUnit; unit++) {
struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
-
- _swrast_unmap_texture(ctx, texObj);
- enabledUnits &= ~(1 << unit);
+ if (texObj)
+ _swrast_unmap_texture(ctx, texObj);
}
}