aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/texobj.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-02-22 09:17:57 +0100
committermarha <marha@users.sourceforge.net>2012-02-22 09:17:57 +0100
commit6baac61e6ca9cd314e689dfe7f84771aad08c66e (patch)
tree2a8a059fc83d3f7acc1034071ed3a9f7ff3c0027 /mesalib/src/mesa/main/texobj.c
parent0ae7710db53515dab4a35c33ba9a030bbfc2ac5b (diff)
downloadvcxsrv-6baac61e6ca9cd314e689dfe7f84771aad08c66e.tar.gz
vcxsrv-6baac61e6ca9cd314e689dfe7f84771aad08c66e.tar.bz2
vcxsrv-6baac61e6ca9cd314e689dfe7f84771aad08c66e.zip
fontconfig libX11 libxcb mesa pixman xserver git update 22 Feb 2012
Diffstat (limited to 'mesalib/src/mesa/main/texobj.c')
-rw-r--r--mesalib/src/mesa/main/texobj.c126
1 files changed, 97 insertions, 29 deletions
diff --git a/mesalib/src/mesa/main/texobj.c b/mesalib/src/mesa/main/texobj.c
index 1b61d3a63..590594826 100644
--- a/mesalib/src/mesa/main/texobj.c
+++ b/mesalib/src/mesa/main/texobj.c
@@ -759,59 +759,127 @@ _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj,
/**
- * Return pointer to a default/fallback texture.
- * The texture is a 2D 8x8 RGBA texture with all texels = (0,0,0,1).
- * That's the value a sampler should get when sampling from an
+ * Return pointer to a default/fallback texture of the given type/target.
+ * The texture is an RGBA texture with all texels = (0,0,0,1).
+ * That's the value a GLSL sampler should get when sampling from an
* incomplete texture.
*/
struct gl_texture_object *
-_mesa_get_fallback_texture(struct gl_context *ctx)
+_mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex)
{
- if (!ctx->Shared->FallbackTex) {
+ if (!ctx->Shared->FallbackTex[tex]) {
/* create fallback texture now */
- static GLubyte texels[8 * 8][4];
+ const GLsizei width = 1, height = 1, depth = 1;
+ GLubyte texel[4];
struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
gl_format texFormat;
- GLuint i;
-
- for (i = 0; i < 8 * 8; i++) {
- texels[i][0] =
- texels[i][1] =
- texels[i][2] = 0x0;
- texels[i][3] = 0xff;
+ GLuint dims, face, numFaces = 1;
+ GLenum target;
+
+ texel[0] =
+ texel[1] =
+ texel[2] = 0x0;
+ texel[3] = 0xff;
+
+ switch (tex) {
+ case TEXTURE_2D_ARRAY_INDEX:
+ dims = 3;
+ target = GL_TEXTURE_2D_ARRAY;
+ break;
+ case TEXTURE_1D_ARRAY_INDEX:
+ dims = 2;
+ target = GL_TEXTURE_1D_ARRAY;
+ break;
+ case TEXTURE_CUBE_INDEX:
+ dims = 2;
+ target = GL_TEXTURE_CUBE_MAP;
+ numFaces = 6;
+ break;
+ case TEXTURE_3D_INDEX:
+ dims = 3;
+ target = GL_TEXTURE_3D;
+ break;
+ case TEXTURE_RECT_INDEX:
+ dims = 2;
+ target = GL_TEXTURE_RECTANGLE;
+ break;
+ case TEXTURE_2D_INDEX:
+ dims = 2;
+ target = GL_TEXTURE_2D;
+ break;
+ case TEXTURE_1D_INDEX:
+ dims = 1;
+ target = GL_TEXTURE_1D;
+ break;
+ case TEXTURE_BUFFER_INDEX:
+ case TEXTURE_EXTERNAL_INDEX:
+ default:
+ /* no-op */
+ return NULL;
}
/* create texture object */
- texObj = ctx->Driver.NewTextureObject(ctx, 0, GL_TEXTURE_2D);
+ texObj = ctx->Driver.NewTextureObject(ctx, 0, target);
+ if (!texObj)
+ return NULL;
+
assert(texObj->RefCount == 1);
texObj->Sampler.MinFilter = GL_NEAREST;
texObj->Sampler.MagFilter = GL_NEAREST;
- /* create level[0] texture image */
- texImage = _mesa_get_tex_image(ctx, texObj, GL_TEXTURE_2D, 0);
-
texFormat = ctx->Driver.ChooseTextureFormat(ctx, GL_RGBA, GL_RGBA,
GL_UNSIGNED_BYTE);
- /* init the image fields */
- _mesa_init_teximage_fields(ctx, texImage,
- 8, 8, 1, 0, GL_RGBA, texFormat);
+ /* need a loop here just for cube maps */
+ for (face = 0; face < numFaces; face++) {
+ GLenum faceTarget;
- ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
-
- /* set image data */
- ctx->Driver.TexImage2D(ctx, texImage, GL_RGBA,
- 8, 8, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, texels,
- &ctx->DefaultPacking);
+ if (target == GL_TEXTURE_CUBE_MAP)
+ faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
+ else
+ faceTarget = target;
+
+ /* initialize level[0] texture image */
+ texImage = _mesa_get_tex_image(ctx, texObj, faceTarget, 0);
+
+ _mesa_init_teximage_fields(ctx, texImage,
+ width,
+ (dims > 1) ? height : 1,
+ (dims > 2) ? depth : 1,
+ 0, /* border */
+ GL_RGBA, texFormat);
+
+ switch (dims) {
+ case 1:
+ ctx->Driver.TexImage1D(ctx, texImage, GL_RGBA,
+ width, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, texel,
+ &ctx->DefaultPacking);
+ break;
+ case 2:
+ ctx->Driver.TexImage2D(ctx, texImage, GL_RGBA,
+ width, height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, texel,
+ &ctx->DefaultPacking);
+ break;
+ case 3:
+ ctx->Driver.TexImage3D(ctx, texImage, GL_RGBA,
+ width, height, depth, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, texel,
+ &ctx->DefaultPacking);
+ break;
+ default:
+ _mesa_problem(ctx, "bad dims in _mesa_get_fallback_texture()");
+ }
+ }
_mesa_test_texobj_completeness(ctx, texObj);
assert(texObj->_Complete);
- ctx->Shared->FallbackTex = texObj;
+ ctx->Shared->FallbackTex[tex] = texObj;
}
- return ctx->Shared->FallbackTex;
+ return ctx->Shared->FallbackTex[tex];
}