/* * Direct Rendering Support for SMedia Glamo 336x/337x * * (c) 2009 Thomas White * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * * Based on intel_tris.c, to which the following notice applies: * * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include #include #include #include "main/mtypes.h" #include "swrast/swrast.h" #include "tnl/t_context.h" #include "tnl/t_vertex.h" #include "tnl/t_pipeline.h" #include "glamo_tris.h" #include "glamo_context.h" static void glamoRunPipeline(GLcontext *ctx) { printf("glamoRunPipeline\n"); /* TODO: Emit state */ _tnl_run_pipeline(ctx); } static void glamoRenderStart(GLcontext *ctx) { 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); } static void glamoRenderFinish(GLcontext *ctx) { printf("glamoRenderFinish\n"); } static void glamoPrimitiveNotify(GLcontext *ctx, GLenum prim) { printf("glamoPrimitiveNotify\n"); } uint32_t *glamoGetPrimSpace(struct glamo_context *gCtx, unsigned int count) { uint32_t *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" #define IND (0) #define TAG(x) x##_offset #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside_offset #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_unfilled #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_offset_unfilled #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside_unfilled #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside_offset_unfilled #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_fallback #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_offset_fallback #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside_fallback #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside_offset_fallback #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_unfilled_fallback #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_offset_unfilled_fallback #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside_unfilled_fallback #include "tnl_dd/t_dd_tritmp.h" #define IND (0) #define TAG(x) x##_twoside_offset_unfilled_fallback #include "tnl_dd/t_dd_tritmp.h" static void init_rast_tab() { init(); init_offset(); init_twoside(); init_twoside_offset(); init_unfilled(); init_offset_unfilled(); init_twoside_unfilled(); init_twoside_offset_unfilled(); init_fallback(); init_offset_fallback(); init_twoside_fallback(); init_twoside_offset_fallback(); init_unfilled_fallback(); init_offset_unfilled_fallback(); init_twoside_unfilled_fallback(); init_twoside_offset_unfilled_fallback(); } void glamoInitTriFuncs(GLcontext *ctx) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); static int firsttime = 1; if (firsttime) { init_rast_tab(); 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; tnl->Driver.Render.PrimitiveNotify = glamoPrimitiveNotify; tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple; tnl->Driver.Render.BuildVertices = _tnl_build_vertices; tnl->Driver.Render.CopyPV = _tnl_copy_pv; tnl->Driver.Render.Interp = _tnl_interp; }