diff options
author | Brian Paul <[email protected]> | 2008-04-24 16:01:18 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2008-04-24 16:01:18 -0600 |
commit | ef683014dd72612e6eb245e89e754b033acb3a49 (patch) | |
tree | 58cec0c2fb9da0f56a5dac119026c8b03a3a3ed8 | |
parent | 98165318621cd3e01919b2b9ff140ce7a4e12beb (diff) |
gallium: initial edgeflags code
-rw-r--r-- | src/mesa/state_tracker/st_draw.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index befcb96bd89..097166f4446 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -190,6 +190,57 @@ pipe_vertex_format(GLenum type, GLuint size, GLboolean normalized) } +/* + * If edge flags are needed, setup an bitvector of flags and call + * pipe->set_edgeflags(). + * XXX memleak: need to free the returned pointer at some point + */ +static void * +setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count, + const struct gl_client_array *array) +{ + struct pipe_context *pipe = ctx->st->pipe; + + if ((primMode == GL_TRIANGLES || + primMode == GL_QUADS || + primMode == GL_POLYGON) && + (ctx->Polygon.FrontMode != GL_FILL || + ctx->Polygon.BackMode != GL_FILL)) { + /* need edge flags */ + GLuint i; + unsigned *vec = (unsigned *) calloc(sizeof(unsigned), (count + 31) / 32); + struct st_buffer_object *stobj = st_buffer_object(array->BufferObj); + ubyte *map; + + if (!vec) + return NULL; + + map = pipe->winsys->buffer_map(pipe->winsys, stobj->buffer, + PIPE_BUFFER_USAGE_CPU_READ); + map = ADD_POINTERS(map, array->Ptr); + + for (i = 0; i < count; i++) { + if (*((float *) map)) + vec[i/32] |= 1 << (i % 32); + + map += array->StrideB; + } + + pipe->winsys->buffer_unmap(pipe->winsys, stobj->buffer); + + pipe->set_edgeflags(pipe, vec); + + return vec; + } + else { + /* edge flags not needed */ + pipe->set_edgeflags(pipe, NULL); + return NULL; + } +} + + + /** * This function gets plugged into the VBO module and is called when * we have something to render. @@ -277,7 +328,6 @@ st_draw_vbo(GLcontext *ctx, pipe->set_vertex_buffers(pipe, vp->num_inputs, vbuffer); pipe->set_vertex_elements(pipe, vp->num_inputs, velements); - /* do actual drawing */ if (ib) { /* indexed primitive */ @@ -317,6 +367,10 @@ st_draw_vbo(GLcontext *ctx, /* draw */ for (i = 0; i < nr_prims; i++) { + setup_edgeflags(ctx, prims[i].mode, + prims[i].start + indexOffset, prims[i].count, + arrays[VERT_ATTRIB_EDGEFLAG]); + pipe->draw_elements(pipe, indexBuf, indexSize, prims[i].mode, prims[i].start + indexOffset, prims[i].count); @@ -328,6 +382,10 @@ st_draw_vbo(GLcontext *ctx, /* non-indexed */ GLuint i; for (i = 0; i < nr_prims; i++) { + setup_edgeflags(ctx, prims[i].mode, + prims[i].start, prims[i].count, + arrays[VERT_ATTRIB_EDGEFLAG]); + pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count); } } |