gallium: use a default texture in update_textures(), update_samplers() when needed

The default texture is used when the current fragment shader has texture
sample instructions but the user has not provided/bound a texture.
This commit is contained in:
Brian Paul
2008-08-14 15:38:09 -06:00
parent 6c46b49d12
commit 8f6d9e12be
6 changed files with 83 additions and 16 deletions

View File

@@ -35,6 +35,7 @@
#include "main/macros.h" #include "main/macros.h"
#include "st_context.h" #include "st_context.h"
#include "st_cb_texture.h"
#include "st_atom.h" #include "st_atom.h"
#include "st_program.h" #include "st_program.h"
#include "pipe/p_context.h" #include "pipe/p_context.h"
@@ -125,6 +126,8 @@ update_samplers(struct st_context *st)
st->state.num_samplers = 0; st->state.num_samplers = 0;
/*printf("%s samplers used = 0x%x\n", __FUNCTION__, fs->Base.Base.SamplersUsed);*/
/* loop over sampler units (aka tex image units) */ /* loop over sampler units (aka tex image units) */
for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
struct pipe_sampler_state *sampler = st->state.samplers + su; struct pipe_sampler_state *sampler = st->state.samplers + su;
@@ -136,8 +139,9 @@ update_samplers(struct st_context *st)
const struct gl_texture_object *texobj const struct gl_texture_object *texobj
= st->ctx->Texture.Unit[texUnit]._Current; = st->ctx->Texture.Unit[texUnit]._Current;
if (!texobj) if (!texobj) {
continue; texobj = st_get_default_texture(st);
}
sampler->wrap_s = gl_wrap_to_sp(texobj->WrapS); sampler->wrap_s = gl_wrap_to_sp(texobj->WrapS);
sampler->wrap_t = gl_wrap_to_sp(texobj->WrapT); sampler->wrap_t = gl_wrap_to_sp(texobj->WrapT);
@@ -184,11 +188,11 @@ update_samplers(struct st_context *st)
st->state.num_samplers = su + 1; st->state.num_samplers = su + 1;
/* XXX more sampler state here */ /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/
cso_single_sampler(st->cso_context, su, sampler); cso_single_sampler(st->cso_context, su, sampler);
} }
else { else {
/*printf("%s su=%u null\n", __FUNCTION__, su);*/
cso_single_sampler(st->cso_context, su, NULL); cso_single_sampler(st->cso_context, su, NULL);
} }
} }

View File

@@ -49,6 +49,8 @@ update_textures(struct st_context *st)
st->state.num_textures = 0; st->state.num_textures = 0;
/*printf("%s samplers used = 0x%x\n", __FUNCTION__, fprog->Base.SamplersUsed);*/
for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) { for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) {
struct pipe_texture *pt = NULL; struct pipe_texture *pt = NULL;
@@ -56,24 +58,34 @@ update_textures(struct st_context *st)
const GLuint texUnit = fprog->Base.SamplerUnits[su]; const GLuint texUnit = fprog->Base.SamplerUnits[su];
struct gl_texture_object *texObj struct gl_texture_object *texObj
= st->ctx->Texture.Unit[texUnit]._Current; = st->ctx->Texture.Unit[texUnit]._Current;
struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_object *stObj;
GLboolean flush, retval;
if (texObj) { if (!texObj) {
GLboolean flush, retval; texObj = st_get_default_texture(st);
retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush);
if (!retval) {
/* out of mem */
/* missing texture */
continue;
}
st->state.num_textures = su + 1;
} }
stObj = st_texture_object(texObj);
retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush);
if (!retval) {
/* out of mem */
continue;
}
st->state.num_textures = su + 1;
pt = st_get_stobj_texture(stObj); pt = st_get_stobj_texture(stObj);
} }
/*
if (pt) {
printf("%s su=%u non-null\n", __FUNCTION__, su);
}
else {
printf("%s su=%u null\n", __FUNCTION__, su);
}
*/
pipe_texture_reference(&st->state.sampler_texture[su], pt); pipe_texture_reference(&st->state.sampler_texture[su], pt);
} }

View File

@@ -1461,6 +1461,46 @@ st_finalize_texture(GLcontext *ctx,
} }
/**
* Returns pointer to a default/dummy texture.
* This is typically used when the current shader has tex/sample instructions
* but the user has not provided a (any) texture(s).
*/
struct gl_texture_object *
st_get_default_texture(struct st_context *st)
{
if (!st->default_texture) {
static const GLenum target = GL_TEXTURE_2D;
GLubyte pixels[16][16][4];
struct gl_texture_object *texObj;
struct gl_texture_image *texImg;
texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
_mesa_init_teximage_fields(st->ctx, target, texImg,
16, 16, 1, 0, /* w, h, d, border */
GL_RGBA);
st_TexImage(st->ctx, 2, target,
0, GL_RGBA, /* level, intformat */
16, 16, 1, 0, /* w, h, d, border */
GL_RGBA, GL_UNSIGNED_BYTE, pixels,
&st->ctx->DefaultPacking,
texObj, texImg,
0, 0);
texObj->MinFilter = GL_NEAREST;
texObj->MagFilter = GL_NEAREST;
texObj->_Complete = GL_TRUE;
st->default_texture = texObj;
}
return st->default_texture;
}
void void
st_init_texture_functions(struct dd_function_table *functions) st_init_texture_functions(struct dd_function_table *functions)
{ {

View File

@@ -37,6 +37,10 @@ st_finalize_texture(GLcontext *ctx,
GLboolean *needFlush); GLboolean *needFlush);
extern struct gl_texture_object *
st_get_default_texture(struct st_context *st);
extern void extern void
st_init_texture_functions(struct dd_function_table *functions); st_init_texture_functions(struct dd_function_table *functions);

View File

@@ -199,6 +199,11 @@ static void st_destroy_context_priv( struct st_context *st )
} }
} }
if (st->default_texture) {
st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture);
st->default_texture = NULL;
}
free( st ); free( st );
} }

View File

@@ -132,6 +132,8 @@ struct st_context
struct st_vertex_program *vp; /**< Currently bound vertex program */ struct st_vertex_program *vp; /**< Currently bound vertex program */
struct st_fragment_program *fp; /**< Currently bound fragment program */ struct st_fragment_program *fp; /**< Currently bound fragment program */
struct gl_texture_object *default_texture;
struct { struct {
struct gl_program_cache *cache; struct gl_program_cache *cache;
struct st_fragment_program *program; /**< cur pixel transfer prog */ struct st_fragment_program *program; /**< cur pixel transfer prog */