Merge remote branch 'upstream/gallium-0.1' into gallium-0.1
[mesa.git] / src / gallium / drivers / nv10 / nv10_state.c
index 12722709f6baae03f674c62b5e6cdd41efcbe398..11664fae2afa51ede43f7bd9024d3a7ef3b9770b 100644 (file)
@@ -1,3 +1,4 @@
+#include "draw/draw_context.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_util.h"
@@ -7,38 +8,6 @@
 #include "nv10_context.h"
 #include "nv10_state.h"
 
-static void nv10_vertex_layout(struct pipe_context* pipe)
-{
-       struct nv10_context *nv10 = nv10_context(pipe);
-       struct nv10_fragment_program *fp = nv10->fragprog.current;
-       uint32_t src = 0;
-       int i;
-       struct vertex_info vinfo;
-
-       memset(&vinfo, 0, sizeof(vinfo));
-
-       for (i = 0; i < fp->info.num_inputs; i++) {
-               switch (fp->info.input_semantic_name[i]) {
-                       case TGSI_SEMANTIC_POSITION:
-                               draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src++);
-                               break;
-                       case TGSI_SEMANTIC_COLOR:
-                               draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src++);
-                               break;
-                       default:
-                       case TGSI_SEMANTIC_GENERIC:
-                               draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src++);
-                               break;
-                       case TGSI_SEMANTIC_FOG:
-                               draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src++);
-                               break;
-               }
-       }
-       draw_compute_vertex_size(&vinfo);
-
-       nv10->dirty |= NV10_NEW_VTXFMT;
-}
-
 static void *
 nv10_blend_state_create(struct pipe_context *pipe,
                        const struct pipe_blend_state *cso)
@@ -282,6 +251,8 @@ nv10_rasterizer_state_create(struct pipe_context *pipe,
         */
        rs = malloc(sizeof(struct nv10_rasterizer_state));
 
+       rs->templ = cso;
+       
        rs->shade_model = cso->flatshade ? 0x1d00 : 0x1d01;
 
        rs->line_width = (unsigned char)(cso->line_width * 8.0) & 0xff;
@@ -347,6 +318,8 @@ nv10_rasterizer_state_bind(struct pipe_context *pipe, void *rast)
 
        nv10->rast = (struct nv10_rasterizer_state*)rast;
 
+       draw_set_rasterizer_state(nv10->draw, (nv10->rast ? nv10->rast->templ : NULL));
+
        nv10->dirty |= NV10_NEW_RAST;
 }
 
@@ -402,34 +375,29 @@ nv10_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
 
 static void *
 nv10_vp_state_create(struct pipe_context *pipe,
-                    const struct pipe_shader_state *cso)
+                    const struct pipe_shader_state *templ)
 {
-       struct nv10_vertex_program *vp;
-
-       vp = CALLOC(1, sizeof(struct nv10_vertex_program));
-       vp->pipe = cso;
+       struct nv10_context *nv10 = nv10_context(pipe);
 
-       return (void *)vp;
+       return draw_create_vertex_shader(nv10->draw, templ);
 }
 
 static void
-nv10_vp_state_bind(struct pipe_context *pipe, void *hwcso)
+nv10_vp_state_bind(struct pipe_context *pipe, void *shader)
 {
        struct nv10_context *nv10 = nv10_context(pipe);
-       struct nv10_vertex_program *vp = hwcso;
 
-       nv10->vertprog.current = vp;
+       draw_bind_vertex_shader(nv10->draw, (struct draw_vertex_shader *) shader);
+
        nv10->dirty |= NV10_NEW_VERTPROG;
 }
 
 static void
-nv10_vp_state_delete(struct pipe_context *pipe, void *hwcso)
+nv10_vp_state_delete(struct pipe_context *pipe, void *shader)
 {
-       //struct nv10_context *nv10 = nv10_context(pipe);
-       struct nv10_vertex_program *vp = hwcso;
+       struct nv10_context *nv10 = nv10_context(pipe);
 
-       //nv10_vertprog_destroy(nv10, vp);
-       FREE(vp);
+       draw_delete_vertex_shader(nv10->draw, (struct draw_vertex_shader *) shader);
 }
 
 static void *
@@ -481,6 +449,9 @@ static void
 nv10_set_clip_state(struct pipe_context *pipe,
                    const struct pipe_clip_state *clip)
 {
+       struct nv10_context *nv10 = nv10_context(pipe);
+
+       draw_set_clip_state(nv10->draw, clip);
 }
 
 static void
@@ -488,14 +459,20 @@ nv10_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
                         const struct pipe_constant_buffer *buf )
 {
        struct nv10_context *nv10 = nv10_context(pipe);
-
-       if (shader == PIPE_SHADER_VERTEX) {
-               nv10->vertprog.constant_buf = buf->buffer;
-               nv10->dirty |= NV10_NEW_VERTPROG;
-       } else
-       if (shader == PIPE_SHADER_FRAGMENT) {
-               nv10->fragprog.constant_buf = buf->buffer;
-               nv10->dirty |= NV10_NEW_FRAGPROG;
+       struct pipe_winsys *ws = pipe->winsys;
+
+       assert(shader < PIPE_SHADER_TYPES);
+       assert(index == 0);
+
+       if (buf) {
+               void *mapped;
+               if (buf->size && (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_USAGE_CPU_READ)))
+               {
+                       memcpy(nv10->constbuf[shader], mapped, buf->size);
+                       nv10->constbuf_nr[shader] =
+                               buf->size / (4 * sizeof(float));
+                       ws->buffer_unmap(ws, buf->buffer);
+               }
        }
 }
 
@@ -536,6 +513,8 @@ nv10_set_viewport_state(struct pipe_context *pipe,
 
        nv10->viewport = (struct pipe_viewport_state*)vpt;
 
+       draw_set_viewport_state(nv10->draw, nv10->viewport);
+
        nv10->dirty |= NV10_NEW_VIEWPORT;
 }
 
@@ -546,7 +525,9 @@ nv10_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
        struct nv10_context *nv10 = nv10_context(pipe);
 
        memcpy(nv10->vtxbuf, vb, sizeof(*vb) * count);
-       nv10->dirty |= NV10_NEW_ARRAYS;
+       nv10->dirty |= NV10_NEW_VTXARRAYS;
+
+       draw_set_vertex_buffers(nv10->draw, count, vb);
 }
 
 static void
@@ -556,7 +537,9 @@ nv10_set_vertex_elements(struct pipe_context *pipe, unsigned count,
        struct nv10_context *nv10 = nv10_context(pipe);
 
        memcpy(nv10->vtxelt, ve, sizeof(*ve) * count);
-       nv10->dirty |= NV10_NEW_ARRAYS;
+       nv10->dirty |= NV10_NEW_VTXARRAYS;
+
+       draw_set_vertex_elements(nv10->draw, count, ve);
 }
 
 void