summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-08-20 10:23:28 -0600
committerBrian <[email protected]>2007-08-20 10:23:28 -0600
commitdf1df82f1660996d09fa272e6129c194afde3ece (patch)
treea28e21bb697f637707ca95cdf20e09a8d3a94b9a /src/mesa/state_tracker
parent8339ca7d1e9a3fe90f46e6e81f7ec8574d121072 (diff)
parent14327705fd53e984b74f8e9adb053df03fba7aff (diff)
Merge branch 'softpipe_0_1_branch' of git+ssh://[email protected]/git/mesa/mesa into softpipe_0_1_branch
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_atom.c1
-rw-r--r--src/mesa/state_tracker/st_atom.h1
-rw-r--r--src/mesa/state_tracker/st_atom_fs.c3
-rw-r--r--src/mesa/state_tracker/st_atom_vs.c31
-rw-r--r--src/mesa/state_tracker/st_context.c6
-rw-r--r--src/mesa/state_tracker/st_context.h2
-rw-r--r--src/mesa/state_tracker/st_draw.c113
7 files changed, 128 insertions, 29 deletions
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index 32b8b8f277b..d67291e50bb 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -46,6 +46,7 @@ static const struct st_tracked_state *atoms[] =
&st_update_clear_color,
&st_update_depth,
&st_update_clip,
+ &st_update_tnl,
&st_update_vs,
&st_update_fs,
&st_update_setup,
diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
index 2f628206cae..51da489f6db 100644
--- a/src/mesa/state_tracker/st_atom.h
+++ b/src/mesa/state_tracker/st_atom.h
@@ -48,6 +48,7 @@ const struct st_tracked_state st_update_framebuffer;
const struct st_tracked_state st_update_clip;
const struct st_tracked_state st_update_clear_color;
const struct st_tracked_state st_update_depth;
+const struct st_tracked_state st_update_tnl;
const struct st_tracked_state st_update_fs;
const struct st_tracked_state st_update_vs;
const struct st_tracked_state st_update_setup;
diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c
index 41ad49b317a..9aba9aaa565 100644
--- a/src/mesa/state_tracker/st_atom_fs.c
+++ b/src/mesa/state_tracker/st_atom_fs.c
@@ -74,6 +74,9 @@ static void update_fs( struct st_context *st )
if (fp && params) {
/* load program's constants array */
+
+ _mesa_load_state_parameters(st->ctx, params);
+
fp->constants.nr_constants = params->NumParameters;
memcpy(fp->constants.constant,
params->ParameterValues,
diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c
index cef6e38d566..c8bd805e022 100644
--- a/src/mesa/state_tracker/st_atom_vs.c
+++ b/src/mesa/state_tracker/st_atom_vs.c
@@ -1,6 +1,6 @@
/**************************************************************************
*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -27,9 +27,11 @@
/*
* Authors:
* Keith Whitwell <[email protected]>
+ * Brian Paul
*/
#include "shader/prog_parameter.h"
+#include "tnl/t_vp_build.h"
#include "pipe/p_context.h"
#include "pipe/tgsi/mesa/mesa_to_tgsi.h"
@@ -39,6 +41,7 @@
#include "st_atom.h"
#include "st_program.h"
+
#define TGSI_DEBUG 0
static void compile_vs( struct st_context *st,
@@ -59,8 +62,10 @@ static void update_vs( struct st_context *st )
struct st_vertex_program *vp = NULL;
struct gl_program_parameter_list *params = NULL;
+#if 0
if (st->ctx->VertexProgram._MaintainTnlProgram)
_tnl_UpdateFixedFunctionProgram( st->ctx );
+#endif
if (st->ctx->Shader.CurrentProgram &&
st->ctx->Shader.CurrentProgram->LinkStatus &&
@@ -83,6 +88,7 @@ static void update_vs( struct st_context *st )
if (vp && params) {
/* load program's constants array */
+ /* XXX this should probably be done elsewhere/separately */
_mesa_load_state_parameters(st->ctx, params);
vp->constants.nr_constants = params->NumParameters;
@@ -117,3 +123,26 @@ const struct st_tracked_state st_update_vs = {
},
.update = update_vs
};
+
+
+
+
+
+/**
+ * When TnL state has changed, need to generate new vertex program.
+ * This should be done before updating the vertes shader (vs) state.
+ */
+static void update_tnl( struct st_context *st )
+{
+ if (st->ctx->VertexProgram._MaintainTnlProgram)
+ _tnl_UpdateFixedFunctionProgram( st->ctx );
+}
+
+
+const struct st_tracked_state st_update_tnl = {
+ .dirty = {
+ .mesa = _NEW_PROGRAM | _NEW_LIGHT | _NEW_TEXTURE, /* XXX more? */
+ .st = ST_NEW_MESA, /* XXX correct? */
+ },
+ .update = update_tnl
+};
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 35a262ab5b5..9e89ece52e1 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -25,7 +25,8 @@
*
**************************************************************************/
-#include "imports.h"
+#include "main/imports.h"
+#include "vbo/vbo.h"
#include "st_public.h"
#include "st_context.h"
#include "st_cb_bufferobjects.h"
@@ -68,6 +69,9 @@ struct st_context *st_create_context( GLcontext *ctx,
st_init_atoms( st );
st_init_draw( st );
+ /* we want all vertex data to be placed in buffer objects */
+ vbo_use_buffer_objects(ctx);
+
/* Need these flags:
*/
st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 25ed20a5f84..35774a790e2 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -104,6 +104,8 @@ struct st_context
struct st_state_flags dirty;
GLfloat polygon_offset_scale; /* ?? */
+
+ struct pipe_buffer_handle *default_attrib_buffer;
};
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 425076d6537..db24b24fa7e 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -44,6 +44,7 @@
#include "st_cb_bufferobjects.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
+#include "pipe/p_winsys.h"
#include "vbo/vbo_context.h"
@@ -52,7 +53,7 @@
* bypassing the T&L module. This only works with VBO-based demos,
* such as progs/test/bufferobj.c
*/
-#define USE_NEW_DRAW 0
+#define USE_NEW_DRAW 01
/*
@@ -135,6 +136,38 @@ pipe_vertex_format(GLenum format, GLuint size)
/**
+ * The default attribute buffer is basically a copy of the
+ * ctx->Current.Attrib[] array. It's used when the vertex program
+ * references an attribute for which we don't have a VBO/array.
+ */
+static void
+create_default_attribs_buffer(struct st_context *st)
+{
+ struct pipe_context *pipe = st->pipe;
+ st->default_attrib_buffer = pipe->winsys->buffer_create( pipe->winsys, 32 );
+}
+
+
+static void
+destroy_default_attribs_buffer(struct st_context *st)
+{
+ struct pipe_context *pipe = st->pipe;
+ pipe->winsys->buffer_unreference(pipe->winsys, &st->default_attrib_buffer);
+}
+
+
+static void
+update_default_attribs_buffer(GLcontext *ctx)
+{
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct pipe_buffer_handle *buf = ctx->st->default_attrib_buffer;
+ const unsigned size = sizeof(ctx->Current.Attrib);
+ const void *data = ctx->Current.Attrib;
+ pipe->winsys->buffer_data(pipe->winsys, buf, size, data);
+}
+
+
+/**
* This function gets plugged into the VBO module and is called when
* we have something to render.
* Basically, translate the information into the format expected by pipe.
@@ -150,41 +183,66 @@ draw_vbo(GLcontext *ctx,
{
struct pipe_context *pipe = ctx->st->pipe;
GLuint attr, i;
+ GLbitfield attrsNeeded;
+ const unsigned attr0_offset = (unsigned) arrays[0]->Ptr;
st_validate_state(ctx->st);
+ update_default_attribs_buffer(ctx);
+ /* this must be after state validation */
+ attrsNeeded = ctx->st->state.vs.inputs_read;
/* tell pipe about the vertex array element/attributes */
for (attr = 0; attr < 16; attr++) {
- struct gl_buffer_object *bufobj = arrays[attr]->BufferObj;
struct pipe_vertex_buffer vbuffer;
struct pipe_vertex_element velement;
- if (bufobj && bufobj->Name) {
- struct st_buffer_object *stobj = st_buffer_object(bufobj);
-
- assert(stobj->buffer);
-
- vbuffer.pitch = arrays[attr]->StrideB; /* in bytes */
- vbuffer.max_index = 0;
- vbuffer.buffer = stobj->buffer;
- vbuffer.buffer_offset = 0;
-
- /* Recall that for VBOs, the gl_client_array->Ptr field is
- * really an offset from the start of the VBO, not a pointer.
- */
- velement.src_offset = (unsigned) arrays[attr]->Ptr;
- velement.vertex_buffer_index = attr;
- velement.dst_offset = 0;
- velement.src_format = pipe_vertex_format(arrays[attr]->Type,
- arrays[attr]->Size);
+ vbuffer.buffer = NULL;
+ vbuffer.pitch = 0;
+ velement.src_offset = 0;
+ velement.vertex_buffer_index = 0;
+ velement.src_format = 0;
+
+ if (attrsNeeded & (1 << attr)) {
+ struct gl_buffer_object *bufobj = arrays[attr]->BufferObj;
+
+ if (bufobj && bufobj->Name) {
+ struct st_buffer_object *stobj = st_buffer_object(bufobj);
+ /* Recall that for VBOs, the gl_client_array->Ptr field is
+ * really an offset from the start of the VBO, not a pointer.
+ */
+ unsigned offset = (unsigned) arrays[attr]->Ptr;
+
+ assert(stobj->buffer);
+
+ vbuffer.buffer = stobj->buffer;
+ vbuffer.buffer_offset = attr0_offset; /* in bytes */
+ vbuffer.pitch = arrays[attr]->StrideB; /* in bytes */
+ vbuffer.max_index = 0; /* need this? */
+
+ velement.src_offset = offset - attr0_offset; /* bytes */
+ velement.vertex_buffer_index = attr;
+ velement.dst_offset = 0; /* need this? */
+ velement.src_format = pipe_vertex_format(arrays[attr]->Type,
+ arrays[attr]->Size);
+ assert(velement.src_format);
+ }
+ else {
+ /* use the default attribute buffer */
+ vbuffer.buffer = ctx->st->default_attrib_buffer;
+ vbuffer.buffer_offset = 0;
+ vbuffer.pitch = 0; /* must be zero! */
+ vbuffer.max_index = 1;
+
+ velement.src_offset = attr * 4 * sizeof(GLfloat);
+ velement.vertex_buffer_index = attr;
+ velement.dst_offset = 0;
+ velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ }
}
- else {
- /* vertex attribute data is not an a real buffer! */
- /* XXX we'll want to handle that someday... */
- vbuffer.buffer = NULL;
- }
+ if (attr == 0)
+ assert(vbuffer.buffer);
pipe->set_vertex_buffer(pipe, attr, &vbuffer);
pipe->set_vertex_element(pipe, attr, &velement);
@@ -209,6 +267,8 @@ void st_init_draw( struct st_context *st )
#if USE_NEW_DRAW
struct vbo_context *vbo = (struct vbo_context *) ctx->swtnl_im;
+ create_default_attribs_buffer(st);
+
assert(vbo);
assert(vbo->draw_prims);
vbo->draw_prims = draw_vbo;
@@ -224,8 +284,7 @@ void st_init_draw( struct st_context *st )
void st_destroy_draw( struct st_context *st )
{
- /* Nothing to do.
- */
+ destroy_default_attribs_buffer(st);
}