From 03aea2f5130b0392e37d7dfbb2d02e8e9c56fdd5 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 16 Oct 2009 10:41:46 +0200 Subject: Ready for vertex submission to hardware --- src/mesa/drivers/dri/glamo/glamo_tris.c | 146 ++++++++++++++++++++++++-------- 1 file changed, 111 insertions(+), 35 deletions(-) (limited to 'src/mesa/drivers/dri/glamo/glamo_tris.c') diff --git a/src/mesa/drivers/dri/glamo/glamo_tris.c b/src/mesa/drivers/dri/glamo/glamo_tris.c index 22c70004b4..6c6b5a6729 100644 --- a/src/mesa/drivers/dri/glamo/glamo_tris.c +++ b/src/mesa/drivers/dri/glamo/glamo_tris.c @@ -49,6 +49,10 @@ */ +#include +#include +#include + #include "main/mtypes.h" #include "swrast/swrast.h" #include "tnl/t_context.h" @@ -69,14 +73,19 @@ static void glamoRunPipeline(GLcontext *ctx) } -/* Unused */ static void glamoRenderStart(GLcontext *ctx) { - printf("glamoRenderStart\n"); + struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); + + /* Decide which attributes will be used */ + gCtx->vertex_attrs[0].attrib = _TNL_ATTRIB_POS; + gCtx->vertex_attrs[0].format = EMIT_4F; + + gCtx->vertex_size = _tnl_install_attrs(ctx, gCtx->vertex_attrs, 1, + NULL, 0); } -/* Unused */ static void glamoRenderFinish(GLcontext *ctx) { printf("glamoRenderFinish\n"); @@ -93,40 +102,100 @@ uint32_t *glamoGetPrimSpace(struct glamo_context *gCtx, unsigned int count) { uint32_t *addr; -#if 0 - if (intel->intelScreen->no_vbo) { - return intel_extend_inline(intel, count * intel->vertex_size); - } - - /* Check for space in the existing VB */ - if (intel->prim.vb_bo == NULL || - (intel->prim.current_offset + - count * intel->vertex_size * 4) > INTEL_VB_SIZE || - (intel->prim.count + count) >= (1 << 16)) { - /* Flush existing prim if any */ - INTEL_FIREVERTICES(intel); - - intel_finish_vb(intel); - - /* Start a new VB */ - if (intel->prim.vb == NULL) - intel->prim.vb = malloc(INTEL_VB_SIZE); - intel->prim.vb_bo = dri_bo_alloc(intel->bufmgr, "vb", - INTEL_VB_SIZE, 4); - intel->prim.start_offset = 0; - intel->prim.current_offset = 0; - } - - intel->prim.flush = intel_flush_prim; - - addr = (uint32_t *)(intel->prim.vb + intel->prim.current_offset); - intel->prim.current_offset += intel->vertex_size * 4 * count; - intel->prim.count += count; -#endif - - return addr; + printf("glamoGetPrimSpace\n"); + + /* Check for space in the existing VB */ + if (gCtx->prim.vb_bo == NULL || (gCtx->prim.current_offset + + count * gCtx->vertex_size) > GLAMO_VB_SIZE) { + + /* Not enough space, or no VB existing. Start a new one... */ + if (gCtx->prim.vb == NULL) { + printf("Allocated %i bytes\n", GLAMO_VB_SIZE); + gCtx->prim.vb = malloc(GLAMO_VB_SIZE); + } + gCtx->prim.vb_bo = glamo_bo_open(gCtx->glamoScreen->bom, 0, + GLAMO_VB_SIZE, 4, + GLAMO_GEM_DOMAIN_VRAM, 0); + gCtx->prim.start_offset = 0; + gCtx->prim.current_offset = 0; + } + + addr = (uint32_t *)(gCtx->prim.vb + gCtx->prim.current_offset); + gCtx->prim.current_offset += gCtx->vertex_size * count; + gCtx->prim.count += count; + + return addr; } + +#define COPY_DWORDS( j, vb, vertsize, v ) \ +do { \ + for ( j = 0 ; j < vertsize ; j++ ) { \ + vb[j] = ((GLuint *)v)[j]; \ + } \ + vb += vertsize; \ +} while (0) + + +static void glamo_draw_triangle(struct glamo_context *gCtx, + glamoVertexPtr v0, glamoVertexPtr v1, + glamoVertexPtr v2) +{ + GLuint *vb = glamoGetPrimSpace(gCtx, 3); + int j; + + COPY_DWORDS(j, vb, gCtx->vertex_size, v0); + COPY_DWORDS(j, vb, gCtx->vertex_size, v1); + COPY_DWORDS(j, vb, gCtx->vertex_size, v2); +} + + +static void glamo_draw_line(struct glamo_context *gCtx, + glamoVertexPtr v0, glamoVertexPtr v1) +{ + GLuint *vb = glamoGetPrimSpace(gCtx, 2); + int j; + + COPY_DWORDS(j, vb, gCtx->vertex_size, v0); + COPY_DWORDS(j, vb, gCtx->vertex_size, v1); +} + + +static void glamo_draw_point(struct glamo_context *gCtx, glamoVertexPtr v0) +{ + GLuint *vb = glamoGetPrimSpace(gCtx, 2); + int j; + + COPY_DWORDS(j, vb, gCtx->vertex_size, v0); +} + + +#define TRI( a, b, c ) \ +do { \ + glamo_draw_triangle(gCtx, a, b, c ); \ +} while (0) + + +#define QUAD( a, b, c, d ) \ +printf("Drawing a quad\n"); \ +do { \ + glamo_draw_triangle(gCtx, a, b, d); \ + glamo_draw_triangle(gCtx, b, c, d); \ +} while (0) + + +#define LINE(v0, v1) \ +do { \ + glamo_draw_line(gCtx, v0, v1); \ +} while (0) + + +#define POINT(v0) \ +do { \ + glamo_draw_point(gCtx, v0); \ +} while (0) + + #define IND (0) #define TAG(x) x #include "tnl_dd/t_dd_tritmp.h" @@ -216,6 +285,7 @@ static void init_rast_tab() void glamoInitTriFuncs(GLcontext *ctx) { TNLcontext *tnl = TNL_CONTEXT(ctx); + struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); static int firsttime = 1; if (firsttime) { @@ -223,6 +293,12 @@ void glamoInitTriFuncs(GLcontext *ctx) firsttime = 0; } + gCtx->prim.start_offset = 0; + gCtx->prim.current_offset = 0; + gCtx->prim.vb_bo = NULL; + gCtx->prim.vb = NULL; + gCtx->prim.count = 0; + tnl->Driver.RunPipeline = glamoRunPipeline; tnl->Driver.Render.Start = glamoRenderStart; tnl->Driver.Render.Finish = glamoRenderFinish; -- cgit v1.2.3