summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2008-04-25 15:23:21 -0600
committerBrian Paul <[email protected]>2008-04-25 15:24:07 -0600
commit332b77b852905224741084c5a4f5d2f4625dd119 (patch)
treed0a9c8b79656068e85c2b3666eb1ceb2756e08f4
parent4c50969334844bc9aa622176c3ebcbc733394f78 (diff)
gallium: use simple color pass-through fragment shader if textures don't exist
If we run out of texture memory we may not have the texture needed by the fragment shader. If this happens, plug in a color passthrough shader. So instead of crashing, we just don't see the texture. GL_OUT_OF_MEMORY is raised, of course.
-rw-r--r--src/mesa/state_tracker/st_atom_texture.c30
-rw-r--r--src/mesa/state_tracker/st_context.h2
2 files changed, 30 insertions, 2 deletions
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index 01c07dc26d3..d15da5895ab 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -38,6 +38,23 @@
#include "st_cb_texture.h"
#include "pipe/p_context.h"
#include "pipe/p_inlines.h"
+#include "cso_cache/cso_context.h"
+#include "util/u_simple_shaders.h"
+
+
+static void *
+get_passthrough_fs(struct st_context *st)
+{
+ struct pipe_shader_state shader;
+
+ if (!st->passthrough_fs) {
+ st->passthrough_fs =
+ util_make_fragment_passthrough_shader(st->pipe, &shader);
+ free((void *) shader.tokens);
+ }
+
+ return st->passthrough_fs;
+}
/**
@@ -49,6 +66,7 @@ update_textures(struct st_context *st)
{
struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current;
GLuint su;
+ GLboolean missing_textures = GL_FALSE;
st->state.num_textures = 0;
@@ -67,6 +85,7 @@ update_textures(struct st_context *st)
retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush);
if (!retval) {
/* out of mem */
+ missing_textures = GL_TRUE;
continue;
}
@@ -79,8 +98,15 @@ update_textures(struct st_context *st)
pipe_texture_reference(&st->state.sampler_texture[su], pt);
}
- st->pipe->set_sampler_textures(st->pipe, st->state.num_textures,
- st->state.sampler_texture);
+ cso_set_sampler_textures(st->cso_context,
+ st->state.num_textures,
+ st->state.sampler_texture);
+
+ if (missing_textures) {
+ /* use a pass-through frag shader that uses no textures */
+ void *fs = get_passthrough_fs(st);
+ cso_set_fragment_shader_handle(st->cso_context, fs);
+ }
}
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 2851770d4ca..7e933a2b109 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -165,6 +165,8 @@ struct st_context
struct pipe_buffer *vbuf;
} clear;
+ void *passthrough_fs; /**< simple pass-through frag shader */
+
struct gen_mipmap_state *gen_mipmap;
struct blit_state *blit;