#include "via_tris.h"
#include "via_state.h"
#include "via_span.h"
-#include "via_vb.h"
#include "via_ioctl.h"
/***********************************************************************
* Emit primitives as inline vertices *
***********************************************************************/
-#if 0
+#if 1
#define COPY_DWORDS(vb, vertsize, v) \
do { \
int j; \
} while (0)
#endif
-static void __inline__ via_draw_triangle(viaContextPtr vmesa,
- viaVertexPtr v0,
- viaVertexPtr v1,
- viaVertexPtr v2)
+static void via_draw_triangle(viaContextPtr vmesa,
+ viaVertexPtr v0,
+ viaVertexPtr v1,
+ viaVertexPtr v2)
{
- GLuint vertsize = vmesa->vertexSize;
- GLuint *vb = viaExtendPrimitive(vmesa, 3 * 4 * vertsize);
-/* fprintf(stderr, "%s: %p %p %p\n", __FUNCTION__, v0, v1, v2); */
- COPY_DWORDS(vb, vertsize, v0);
- COPY_DWORDS(vb, vertsize, v1);
- COPY_DWORDS(vb, vertsize, v2);
+ GLuint vertsize = vmesa->vertexSize;
+ GLuint *vb = viaExtendPrimitive(vmesa, 3 * 4 * vertsize);
+
+ COPY_DWORDS(vb, vertsize, v0);
+ COPY_DWORDS(vb, vertsize, v1);
+ COPY_DWORDS(vb, vertsize, v2);
}
-static void __inline__ via_draw_quad(viaContextPtr vmesa,
- viaVertexPtr v0,
- viaVertexPtr v1,
- viaVertexPtr v2,
- viaVertexPtr v3)
+static void via_draw_quad(viaContextPtr vmesa,
+ viaVertexPtr v0,
+ viaVertexPtr v1,
+ viaVertexPtr v2,
+ viaVertexPtr v3)
{
- GLuint vertsize = vmesa->vertexSize;
- GLuint *vb = viaExtendPrimitive(vmesa, 6 * 4 * vertsize);
-
-/* fprintf(stderr, "%s: %p %p %p %p\n", __FUNCTION__, v0, v1, v2, v3); */
- COPY_DWORDS(vb, vertsize, v0);
- COPY_DWORDS(vb, vertsize, v1);
- COPY_DWORDS(vb, vertsize, v3);
- COPY_DWORDS(vb, vertsize, v1);
- COPY_DWORDS(vb, vertsize, v2);
- COPY_DWORDS(vb, vertsize, v3);
+ GLuint vertsize = vmesa->vertexSize;
+ GLuint *vb = viaExtendPrimitive(vmesa, 6 * 4 * vertsize);
+
+ COPY_DWORDS(vb, vertsize, v0);
+ COPY_DWORDS(vb, vertsize, v1);
+ COPY_DWORDS(vb, vertsize, v3);
+ COPY_DWORDS(vb, vertsize, v1);
+ COPY_DWORDS(vb, vertsize, v2);
+ COPY_DWORDS(vb, vertsize, v3);
}
-static __inline__ void via_draw_line(viaContextPtr vmesa,
- viaVertexPtr v0,
- viaVertexPtr v1)
+static void via_draw_line(viaContextPtr vmesa,
+ viaVertexPtr v0,
+ viaVertexPtr v1)
{
- GLuint vertsize = vmesa->vertexSize;
- GLuint *vb = viaExtendPrimitive(vmesa, 2 * 4 * vertsize);
- COPY_DWORDS(vb, vertsize, v0);
- COPY_DWORDS(vb, vertsize, v1);
+ GLuint vertsize = vmesa->vertexSize;
+ GLuint *vb = viaExtendPrimitive(vmesa, 2 * 4 * vertsize);
+ COPY_DWORDS(vb, vertsize, v0);
+ COPY_DWORDS(vb, vertsize, v1);
}
-static __inline__ void via_draw_point(viaContextPtr vmesa,
- viaVertexPtr v0)
+static void via_draw_point(viaContextPtr vmesa,
+ viaVertexPtr v0)
{
- GLuint vertsize = vmesa->vertexSize;
- GLuint *vb = viaExtendPrimitive(vmesa, 4 * vertsize);
- COPY_DWORDS(vb, vertsize, v0);
+ GLuint vertsize = vmesa->vertexSize;
+ GLuint *vb = viaExtendPrimitive(vmesa, 4 * vertsize);
+ COPY_DWORDS(vb, vertsize, v0);
}
+/* Fallback drawing functions for the ptex hack.
+ */
+#define PTEX_VERTEX( tmp, vertex_size, v) \
+do { \
+ GLuint j; \
+ GLfloat rhw = 1.0 / v->f[vertex_size]; \
+ for ( j = 0 ; j < vertex_size ; j++ ) \
+ tmp.f[j] = v->f[j]; \
+ tmp.f[3] *= v->f[vertex_size]; \
+ tmp.f[vertex_size-2] *= rhw; \
+ tmp.f[vertex_size-1] *= rhw; \
+} while (0)
+
+static void via_ptex_tri (viaContextPtr vmesa,
+ viaVertexPtr v0,
+ viaVertexPtr v1,
+ viaVertexPtr v2)
+{
+ GLuint vertsize = vmesa->hwVertexSize;
+ GLuint *vb = viaExtendPrimitive(vmesa, 3*4*vertsize);
+ viaVertex tmp;
+
+ PTEX_VERTEX(tmp, vertsize, v0); COPY_DWORDS(vb, vertsize, &tmp);
+ PTEX_VERTEX(tmp, vertsize, v1); COPY_DWORDS(vb, vertsize, &tmp);
+ PTEX_VERTEX(tmp, vertsize, v2); COPY_DWORDS(vb, vertsize, &tmp);
+}
+
+static void via_ptex_line (viaContextPtr vmesa,
+ viaVertexPtr v0,
+ viaVertexPtr v1)
+{
+ GLuint vertsize = vmesa->hwVertexSize;
+ GLuint *vb = viaExtendPrimitive(vmesa, 2*4*vertsize);
+ viaVertex tmp;
+
+ PTEX_VERTEX(tmp, vertsize, v0); COPY_DWORDS(vb, vertsize, &tmp);
+ PTEX_VERTEX(tmp, vertsize, v1); COPY_DWORDS(vb, vertsize, &tmp);
+}
+
+static void via_ptex_point (viaContextPtr vmesa,
+ viaVertexPtr v0)
+{
+ GLuint vertsize = vmesa->hwVertexSize;
+ GLuint *vb = viaExtendPrimitive(vmesa, 1*4*vertsize);
+ viaVertex tmp;
+
+ PTEX_VERTEX(tmp, vertsize, v0); COPY_DWORDS(vb, vertsize, &tmp);
+}
+
+
+
/***********************************************************************
#define TRI(a, b, c) \
do { \
- if (VIA_DEBUG) fprintf(stderr, "hw TRI\n"); \
if (DO_FALLBACK) \
vmesa->drawTri(vmesa, a, b, c); \
else \
#define QUAD(a, b, c, d) \
do { \
- if (VIA_DEBUG) fprintf(stderr, "hw QUAD\n");\
if (DO_FALLBACK) { \
vmesa->drawTri(vmesa, a, b, d); \
vmesa->drawTri(vmesa, b, c, d); \
#define LINE(v0, v1) \
do { \
- if(VIA_DEBUG) fprintf(stderr, "hw LINE\n");\
if (DO_FALLBACK) \
vmesa->drawLine(vmesa, v0, v1); \
else \
#define POINT(v0) \
do { \
- if (VIA_DEBUG) fprintf(stderr, "hw POINT\n");\
if (DO_FALLBACK) \
vmesa->drawPoint(vmesa, v0); \
else \
#define VERT_SET_SPEC( v0, c ) \
do { \
- if (havespec) { \
+ if (specoffset) { \
UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
} while (0)
#define VERT_COPY_SPEC( v0, v1 ) \
do { \
- if (havespec) { \
+ if (specoffset) { \
v0->v.specular.red = v1->v.specular.red; \
v0->v.specular.green = v1->v.specular.green; \
v0->v.specular.blue = v1->v.specular.blue; \
#define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
-#define VERT_SAVE_SPEC( idx ) if (havespec) spec[idx] = v[idx]->ui[5]
-#define VERT_RESTORE_SPEC( idx ) if (havespec) v[idx]->ui[5] = spec[idx]
+#define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
+#define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
#define LOCAL_VARS(n) \
viaContextPtr vmesa = VIA_CONTEXT(ctx); \
GLuint color[n], spec[n]; \
- GLuint coloroffset = (vmesa->vertexSize == 4 ? 3 : 4); \
- GLboolean havespec = (vmesa->vertexSize > 4); \
- (void)color; (void)spec; (void)coloroffset; (void)havespec;
+ GLuint coloroffset = vmesa->coloroffset; \
+ GLuint specoffset = vmesa->specoffset; \
+ (void)color; (void)spec; (void)coloroffset; (void)specoffset;
/***********************************************************************
{
GLcontext *ctx = vmesa->glCtx;
SWvertex v[3];
- via_translate_vertex(ctx, v0, &v[0]);
- via_translate_vertex(ctx, v1, &v[1]);
- via_translate_vertex(ctx, v2, &v[2]);
+ _swsetup_Translate(ctx, v0, &v[0]);
+ _swsetup_Translate(ctx, v1, &v[1]);
+ _swsetup_Translate(ctx, v2, &v[2]);
viaSpanRenderStart( ctx );
_swrast_Triangle(ctx, &v[0], &v[1], &v[2]);
viaSpanRenderFinish( ctx );
{
GLcontext *ctx = vmesa->glCtx;
SWvertex v[2];
- via_translate_vertex(ctx, v0, &v[0]);
- via_translate_vertex(ctx, v1, &v[1]);
+ _swsetup_Translate(ctx, v0, &v[0]);
+ _swsetup_Translate(ctx, v1, &v[1]);
viaSpanRenderStart( ctx );
_swrast_Line(ctx, &v[0], &v[1]);
viaSpanRenderFinish( ctx );
{
GLcontext *ctx = vmesa->glCtx;
SWvertex v[1];
- via_translate_vertex(ctx, v0, &v[0]);
+ _swsetup_Translate(ctx, v0, &v[0]);
viaSpanRenderStart( ctx );
_swrast_Point(ctx, &v[0]);
viaSpanRenderFinish( ctx );
+
+#define _VIA_NEW_VERTEX (_NEW_TEXTURE | \
+ _DD_NEW_SEPARATE_SPECULAR | \
+ _DD_NEW_TRI_UNFILLED | \
+ _DD_NEW_TRI_LIGHT_TWOSIDE | \
+ _NEW_FOG)
+
#define _VIA_NEW_RENDERSTATE (_DD_NEW_LINE_STIPPLE | \
_DD_NEW_TRI_UNFILLED | \
_DD_NEW_TRI_LIGHT_TWOSIDE | \
#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
-void viaChooseRenderState(GLcontext *ctx)
+static void viaChooseRenderState(GLcontext *ctx)
{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
- GLuint flags = ctx->_TriangleCaps;
- GLuint index = 0;
- if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
-
- if (VIA_DEBUG) fprintf(stderr, "_TriangleCaps = %x\n", flags);
- if (flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) {
- if (flags & ANY_RASTER_FLAGS) {
- if (flags & DD_TRI_LIGHT_TWOSIDE) index |= VIA_TWOSIDE_BIT;
- if (flags & DD_TRI_OFFSET) index |= VIA_OFFSET_BIT;
- if (flags & DD_TRI_UNFILLED) index |= VIA_UNFILLED_BIT;
- }
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ viaContextPtr vmesa = VIA_CONTEXT(ctx);
+ GLuint flags = ctx->_TriangleCaps;
+ GLuint index = 0;
+
+ if (vmesa->ptexHack) {
+ vmesa->drawPoint = via_ptex_point;
+ vmesa->drawLine = via_ptex_line;
+ vmesa->drawTri = via_ptex_tri;
+ index |= VIA_FALLBACK_BIT;
+ }
+ else {
+ vmesa->drawPoint = via_draw_point;
+ vmesa->drawLine = via_draw_line;
+ vmesa->drawTri = via_draw_triangle;
+ }
- vmesa->drawPoint = via_draw_point;
- vmesa->drawLine = via_draw_line;
- vmesa->drawTri = via_draw_triangle;
+ if (flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) {
+ if (flags & DD_TRI_LIGHT_TWOSIDE) index |= VIA_TWOSIDE_BIT;
+ if (flags & DD_TRI_OFFSET) index |= VIA_OFFSET_BIT;
+ if (flags & DD_TRI_UNFILLED) index |= VIA_UNFILLED_BIT;
+ if (flags & ANY_FALLBACK_FLAGS) index |= VIA_FALLBACK_BIT;
- /* Hook in fallbacks for specific primitives.
- */
- if (flags & ANY_FALLBACK_FLAGS) {
- if (flags & POINT_FALLBACK)
- vmesa->drawPoint = via_fallback_point;
+ /* Hook in fallbacks for specific primitives.
+ */
+ if (flags & POINT_FALLBACK)
+ vmesa->drawPoint = via_fallback_point;
+
+ if (flags & LINE_FALLBACK)
+ vmesa->drawLine = via_fallback_line;
+
+ if (flags & TRI_FALLBACK)
+ vmesa->drawTri = via_fallback_tri;
+ }
- if (flags & LINE_FALLBACK)
- vmesa->drawLine = via_fallback_line;
+ if (vmesa->renderIndex != index) {
+ vmesa->renderIndex = index;
- if (flags & TRI_FALLBACK)
- vmesa->drawTri = via_fallback_tri;
+ tnl->Driver.Render.Points = rast_tab[index].points;
+ tnl->Driver.Render.Line = rast_tab[index].line;
+ tnl->Driver.Render.Triangle = rast_tab[index].triangle;
+ tnl->Driver.Render.Quad = rast_tab[index].quad;
- index |= VIA_FALLBACK_BIT;
- }
- }
- if (VIA_DEBUG) {
- fprintf(stderr, "index = %x\n", index);
- fprintf(stderr, "renderIndex = %x\n", vmesa->renderIndex);
- }
- if (vmesa->renderIndex != index) {
- vmesa->renderIndex = index;
-
- tnl->Driver.Render.Points = rast_tab[index].points;
- tnl->Driver.Render.Line = rast_tab[index].line;
- tnl->Driver.Render.Triangle = rast_tab[index].triangle;
-
- tnl->Driver.Render.Quad = rast_tab[index].quad;
-
- if (index == 0) {
- tnl->Driver.Render.PrimTabVerts = via_fastrender_tab_verts;
- tnl->Driver.Render.PrimTabElts = via_fastrender_tab_elts;
- tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
- tnl->Driver.Render.ClippedPolygon = viaFastRenderClippedPoly;
- }
- else {
- tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
- tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
- tnl->Driver.Render.ClippedLine = viaRenderClippedLine;
- tnl->Driver.Render.ClippedPolygon = viaRenderClippedPoly;
- }
- }
- if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
+ if (index == 0) {
+ tnl->Driver.Render.PrimTabVerts = via_fastrender_tab_verts;
+ tnl->Driver.Render.PrimTabElts = via_fastrender_tab_elts;
+ tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
+ tnl->Driver.Render.ClippedPolygon = viaFastRenderClippedPoly;
+ }
+ else {
+ tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
+ tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
+ tnl->Driver.Render.ClippedLine = viaRenderClippedLine;
+ tnl->Driver.Render.ClippedPolygon = viaRenderClippedPoly;
+ }
+ }
}
+#define VIA_EMIT_TEX1 0x01
+#define VIA_EMIT_TEX0 0x02
+#define VIA_EMIT_PTEX0 0x04
+#define VIA_EMIT_RGBA 0x08
+#define VIA_EMIT_SPEC 0x10
+#define VIA_EMIT_FOG 0x20
+#define VIA_EMIT_W 0x40
+
+#define EMIT_ATTR( ATTR, STYLE, INDEX, REGB ) \
+do { \
+ vmesa->vertex_attrs[vmesa->vertex_attr_count].attrib = (ATTR); \
+ vmesa->vertex_attrs[vmesa->vertex_attr_count].format = (STYLE); \
+ vmesa->vertex_attr_count++; \
+ setupIndex |= (INDEX); \
+ regCmdB |= (REGB); \
+} while (0)
+#define EMIT_PAD( N ) \
+do { \
+ vmesa->vertex_attrs[vmesa->vertex_attr_count].attrib = 0; \
+ vmesa->vertex_attrs[vmesa->vertex_attr_count].format = EMIT_PAD; \
+ vmesa->vertex_attrs[vmesa->vertex_attr_count].offset = (N); \
+ vmesa->vertex_attr_count++; \
+} while (0)
-/**********************************************************************/
-/* High level hooks for t_vb_render.c */
-/**********************************************************************/
-static void viaRunPipeline(GLcontext *ctx)
+static void viaChooseVertexState( GLcontext *ctx )
{
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
-
- if (vmesa->newState) {
- viaValidateState( ctx );
- if (!vmesa->Fallback) {
- viaChooseVertexState(ctx);
- viaChooseRenderState(ctx);
- }
- }
+ viaContextPtr vmesa = VIA_CONTEXT(ctx);
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ GLuint index = tnl->render_inputs;
+ GLuint regCmdB = HC_HVPMSK_X | HC_HVPMSK_Y | HC_HVPMSK_Z;
+ GLuint setupIndex = 0;
+
+ vmesa->vertex_attr_count = 0;
+
+ /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
+ * build up a hardware vertex.
+ */
+ if (index & (_TNL_BITS_TEX_ANY|_TNL_BIT_FOG)) {
+ EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VIA_EMIT_W, HC_HVPMSK_W );
+ vmesa->coloroffset = 4;
+ }
+ else {
+ EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, 0, 0 );
+ vmesa->coloroffset = 3;
+ }
- _tnl_run_pipeline(ctx);
+ /* t_context.c always includes a diffuse color */
+ EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VIA_EMIT_RGBA, HC_HVPMSK_Cd );
+
+ vmesa->specoffset = 0;
+ if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) {
+ if ((index & _TNL_BIT_COLOR1)) {
+ vmesa->specoffset = vmesa->coloroffset + 1;
+ EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VIA_EMIT_SPEC, HC_HVPMSK_Cs );
+ }
+ else
+ EMIT_PAD( 3 );
+
+ if ((index & _TNL_BIT_FOG))
+ EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, VIA_EMIT_FOG, HC_HVPMSK_Cs );
+ else
+ EMIT_PAD( 1 );
+ }
+
+ if (index & _TNL_BIT_TEX(0)) {
+ if (vmesa->ptexHack)
+ EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_3F_XYW, VIA_EMIT_PTEX0, (HC_HVPMSK_S | HC_HVPMSK_T) );
+ else
+ EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_2F, VIA_EMIT_TEX0, (HC_HVPMSK_S | HC_HVPMSK_T) );
+ }
+
+ if (index & _TNL_BIT_TEX(1)) {
+ EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, VIA_EMIT_TEX1, 0 ); /* how does the hardware find out about this? */
+ }
+
+ if (setupIndex != vmesa->setupIndex) {
+ vmesa->vertexSize = _tnl_install_attrs( ctx,
+ vmesa->vertex_attrs,
+ vmesa->vertex_attr_count,
+ vmesa->ViewportMatrix.m, 0 );
+ vmesa->vertexSize >>= 2;
+ vmesa->setupIndex = setupIndex;
+ vmesa->regCmdB &= ~HC_HVPMSK_MASK;
+ vmesa->regCmdB |= regCmdB;
+
+ if (vmesa->ptexHack)
+ vmesa->hwVertexSize = vmesa->vertexSize - 1;
+ else
+ vmesa->hwVertexSize = vmesa->vertexSize;
+ }
}
+
+
+
+/* Check if projective texture coordinates are used and if we can fake
+ * them. Fallback to swrast we can't. Returns GL_TRUE if projective
+ * texture coordinates must be faked, GL_FALSE otherwise.
+ */
+static GLboolean viaCheckPTexHack( GLcontext *ctx )
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &tnl->vb;
+ GLuint index = tnl->render_inputs;
+ GLboolean fallback = GL_FALSE;
+ GLboolean ptexHack = GL_FALSE;
+
+ if (index & _TNL_BIT_TEX(0) && VB->TexCoordPtr[0]->size == 4) {
+ if ((index & _TNL_BITS_TEX_ANY) == _TNL_BIT_TEX(0))
+ ptexHack = GL_TRUE;
+ else
+ fallback = GL_TRUE;
+ }
+ if ((index & _TNL_BIT_TEX(1)) && VB->TexCoordPtr[1]->size == 4)
+ fallback = GL_TRUE;
+
+ FALLBACK(VIA_CONTEXT(ctx), VIA_FALLBACK_PROJ_TEXTURE, fallback);
+ return ptexHack;
+}
+
+
+
+
+/**********************************************************************/
+/* High level hooks for t_vb_render.c */
+/**********************************************************************/
+
+
static void viaRenderStart(GLcontext *ctx)
{
- /* Check for projective texturing. Make sure all texcoord
- * pointers point to something. (fix in mesa?)
- */
- viaCheckTexSizes(ctx);
+ viaContextPtr vmesa = VIA_CONTEXT(ctx);
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+
+ {
+ GLboolean ptexHack = viaCheckPTexHack( ctx );
+ if (ptexHack != vmesa->ptexHack) {
+ vmesa->ptexHack = ptexHack;
+ vmesa->newRenderState |= _VIA_NEW_RENDERSTATE;
+ }
+ }
+
+ if (vmesa->newState) {
+ vmesa->newRenderState |= vmesa->newState;
+ viaValidateState( ctx );
+ }
+
+ if (vmesa->Fallback) {
+ tnl->Driver.Render.Start(ctx);
+ return;
+ }
+
+ if (vmesa->newRenderState) {
+ viaChooseVertexState(ctx);
+ viaChooseRenderState(ctx);
+ vmesa->newRenderState = 0;
+ }
+
+ /* Important:
+ */
+ VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
}
static void viaRenderFinish(GLcontext *ctx)
/* assert((vmesa->dmaLow & 0x4) == 0); */
- if (vmesa->dmaCliprectAddr == 0) {
+ if (vmesa->dmaCliprectAddr == ~0) {
if (VIA_DEBUG) fprintf(stderr, "reserve cliprect space at %x\n", vmesa->dmaLow);
- assert(vmesa->dmaLow);
vmesa->dmaCliprectAddr = vmesa->dmaLow;
BEGIN_RING(8);
OUT_RING( HC_HEADER2 );
if (VIA_DEBUG)
fprintf(stderr, "%s\n", __FUNCTION__);
- if (!vmesa->dmaLastPrim || !vmesa->dmaCliprectAddr) {
+ if (!vmesa->dmaLastPrim || vmesa->dmaCliprectAddr == ~0) {
assert(0);
}
else if (vmesa->dmaLow != vmesa->dmaLastPrim) {
*/
if (vmesa->dmaCliprectAddr == vmesa->dmaLow - 8 * sizeof(GLuint)) {
vmesa->dmaLow -= 8 * sizeof(GLuint);
- vmesa->dmaCliprectAddr = 0;
+ vmesa->dmaCliprectAddr = ~0;
}
}
if (mode) {
vmesa->Fallback |= bit;
if (oldfallback == 0) {
- if (VIA_DEBUG) fprintf(stderr, "ENTER FALLBACK\n");
VIA_FLUSH_DMA(vmesa);
_swsetup_Wakeup(ctx);
vmesa->renderIndex = ~0;
else {
vmesa->Fallback &= ~bit;
if (oldfallback == bit) {
- if (VIA_DEBUG) fprintf(stderr, "LEAVE FALLBACK\n");
+ _swrast_flush( ctx );
+
tnl->Driver.Render.Start = viaRenderStart;
tnl->Driver.Render.PrimitiveNotify = viaRenderPrimitive;
tnl->Driver.Render.Finish = viaRenderFinish;
- tnl->Driver.Render.BuildVertices = viaBuildVertices;
+
+ tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
+ tnl->Driver.Render.CopyPV = _tnl_copy_pv;
+ tnl->Driver.Render.Interp = _tnl_interp;
+
+ _tnl_invalidate_vertex_state( ctx, ~0 );
+ _tnl_invalidate_vertices( ctx, ~0 );
+ _tnl_install_attrs( ctx,
+ vmesa->vertex_attrs,
+ vmesa->vertex_attr_count,
+ vmesa->ViewportMatrix.m, 0 );
+
vmesa->newState |= (_VIA_NEW_RENDERSTATE|_VIA_NEW_VERTEX);
}
- }
-
+ }
}
void viaInitTriFuncs(GLcontext *ctx)
{
+ viaContextPtr vmesa = VIA_CONTEXT(ctx);
TNLcontext *tnl = TNL_CONTEXT(ctx);
static int firsttime = 1;
firsttime = 0;
}
- tnl->Driver.RunPipeline = viaRunPipeline;
+ tnl->Driver.RunPipeline = _tnl_run_pipeline;
tnl->Driver.Render.Start = viaRenderStart;
tnl->Driver.Render.Finish = viaRenderFinish;
tnl->Driver.Render.PrimitiveNotify = viaRenderPrimitive;
tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
- tnl->Driver.Render.BuildVertices = viaBuildVertices;
+ tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
+ tnl->Driver.Render.CopyPV = _tnl_copy_pv;
+ tnl->Driver.Render.Interp = _tnl_interp;
+
+ _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
+ (6 + 2*ctx->Const.MaxTextureUnits) * sizeof(GLfloat) );
+
+ vmesa->verts = (char *)tnl->clipspace.vertex_buf;
+
}
+++ /dev/null
-/*
- * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
- * Copyright 2001-2003 S3 Graphics, Inc. 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
- * VIA, S3 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 "glheader.h"
-#include "mtypes.h"
-#include "imports.h"
-#include "macros.h"
-#include "colormac.h"
-
-#include "swrast_setup/swrast_setup.h"
-#include "tnl/t_context.h"
-
-#include "via_context.h"
-#include "via_vb.h"
-#include "via_ioctl.h"
-#include "via_tris.h"
-#include "via_state.h"
-
-static struct {
- void (*emit)(GLcontext *, GLuint, GLuint, void *, GLuint);
- tnl_interp_func interp;
- tnl_copy_pv_func copy_pv;
- GLboolean (*check_tex_sizes)(GLcontext *ctx);
- GLuint vertex_size;
- GLuint vertex_format;
-} setup_tab[VIA_MAX_SETUP];
-
-#define TINY_VERTEX_FORMAT 1
-#define NOTEX_VERTEX_FORMAT 2
-#define TEX0_VERTEX_FORMAT 3
-#define TEX1_VERTEX_FORMAT 4
-
-#define PROJ_TEX1_VERTEX_FORMAT 0
-#define TEX2_VERTEX_FORMAT 0
-#define TEX3_VERTEX_FORMAT 0
-#define PROJ_TEX3_VERTEX_FORMAT 0
-
-#define DO_XYZW (IND & VIA_XYZW_BIT)
-#define DO_RGBA (IND & VIA_RGBA_BIT)
-#define DO_SPEC (IND & VIA_SPEC_BIT)
-#define DO_FOG (IND & VIA_FOG_BIT)
-#define DO_TEX0 (IND & VIA_TEX0_BIT)
-#define DO_TEX1 (IND & VIA_TEX1_BIT)
-#define DO_TEX2 0
-#define DO_TEX3 0
-#define DO_PTEX (IND & VIA_PTEX_BIT)
-
-#define VERTEX viaVertex
-#define VERTEX_COLOR via_color_t
-#define GET_VIEWPORT_MAT() VIA_CONTEXT(ctx)->ViewportMatrix.m
-#define GET_TEXSOURCE(n) n
-#define GET_VERTEX_FORMAT() VIA_CONTEXT(ctx)->vertexFormat
-#define GET_VERTEX_SIZE() VIA_CONTEXT(ctx)->vertexSize * sizeof(GLuint)
-#define GET_VERTEX_STORE() VIA_CONTEXT(ctx)->verts
-#define INVALIDATE_STORED_VERTICES()
-
-#define HAVE_HW_VIEWPORT 0
-#define HAVE_HW_DIVIDE 0
-#define HAVE_RGBA_COLOR 0
-#define HAVE_TINY_VERTICES 1
-#define HAVE_NOTEX_VERTICES 1
-#define HAVE_TEX0_VERTICES 1
-#define HAVE_TEX1_VERTICES 1
-#define HAVE_TEX2_VERTICES 0
-#define HAVE_TEX3_VERTICES 0
-#define HAVE_PTEX_VERTICES 0
-
-#define UNVIEWPORT_VARS \
- viaContextPtr vmesa = VIA_CONTEXT(ctx); \
- GLfloat h = vmesa->driDrawable->h, depth_max = vmesa->depth_max, xoff = vmesa->drawXoff;
-
-#define UNVIEWPORT_X(x) x - (SUBPIXEL_X + xoff)
-#define UNVIEWPORT_Y(y) - y + h + SUBPIXEL_Y
-#define UNVIEWPORT_Z(z) z * (float)depth_max
-
-#define PTEX_FALLBACK() FALLBACK(VIA_CONTEXT(ctx), VIA_FALLBACK_TEXTURE, 1)
-
-#define INTERP_VERTEX setup_tab[VIA_CONTEXT(ctx)->setupIndex].interp
-#define COPY_PV_VERTEX setup_tab[VIA_CONTEXT(ctx)->setupIndex].copy_pv
-
-
-/***********************************************************************
- * Generate pv-copying and translation functions *
- ***********************************************************************/
-
-#define TAG(x) via_##x
-#include "tnl_dd/t_dd_vb.c"
-
-/***********************************************************************
- * Generate vertex emit and interp functions *
- ***********************************************************************/
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT)
-#define TAG(x) x##_wg
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_SPEC_BIT)
-#define TAG(x) x##_wgs
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_TEX0_BIT)
-#define TAG(x) x##_wgt0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_TEX0_BIT | VIA_TEX1_BIT)
-#define TAG(x) x##_wgt0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_TEX0_BIT | VIA_PTEX_BIT)
-#define TAG(x) x##_wgpt0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_TEX0_BIT | VIA_TEX1_BIT |\
- VIA_PTEX_BIT)
-#define TAG(x) x##_wgpt0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_SPEC_BIT | VIA_TEX0_BIT)
-#define TAG(x) x##_wgst0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_SPEC_BIT | VIA_TEX0_BIT |\
- VIA_TEX1_BIT)
-#define TAG(x) x##_wgst0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_SPEC_BIT | VIA_TEX0_BIT |\
- VIA_PTEX_BIT)
-#define TAG(x) x##_wgspt0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_SPEC_BIT | VIA_TEX0_BIT |\
- VIA_TEX1_BIT | VIA_PTEX_BIT)
-#define TAG(x) x##_wgspt0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT)
-#define TAG(x) x##_wgf
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_SPEC_BIT)
-#define TAG(x) x##_wgfs
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_TEX0_BIT)
-#define TAG(x) x##_wgft0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_TEX0_BIT |\
- VIA_TEX1_BIT)
-#define TAG(x) x##_wgft0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_TEX0_BIT |\
- VIA_PTEX_BIT)
-#define TAG(x) x##_wgfpt0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_TEX0_BIT |\
- VIA_TEX1_BIT | VIA_PTEX_BIT)
-#define TAG(x) x##_wgfpt0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_SPEC_BIT |\
- VIA_TEX0_BIT)
-#define TAG(x) x##_wgfst0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_SPEC_BIT |\
- VIA_TEX0_BIT | VIA_TEX1_BIT)
-#define TAG(x) x##_wgfst0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_SPEC_BIT |\
- VIA_TEX0_BIT | VIA_PTEX_BIT)
-#define TAG(x) x##_wgfspt0
-#include "tnl_dd/t_dd_vbtmp.h"
-
-#define IND (VIA_XYZW_BIT | VIA_RGBA_BIT | VIA_FOG_BIT | VIA_SPEC_BIT |\
- VIA_TEX0_BIT | VIA_TEX1_BIT | VIA_PTEX_BIT)
-#define TAG(x) x##_wgfspt0t1
-#include "tnl_dd/t_dd_vbtmp.h"
-
-static void init_setup_tab(void) {
-
- init_wg();
- init_wgs();
- init_wgt0();
- init_wgt0t1();
- init_wgpt0();
- init_wgpt0t1();
- init_wgst0();
- init_wgst0t1();
- init_wgspt0();
- init_wgspt0t1();
- init_wgf();
- init_wgfs();
- init_wgft0();
- init_wgft0t1();
- init_wgfpt0();
- init_wgfpt0t1();
- init_wgfst0();
- init_wgfst0t1();
- init_wgfspt0();
- init_wgfspt0t1();
-}
-
-void viaPrintSetupFlags(char *msg, GLuint flags) {
- if (VIA_DEBUG) fprintf(stderr, "%s(%x): %s%s%s%s%s%s\n",
- msg,
- (int)flags,
- (flags & VIA_XYZW_BIT) ? " xyzw," : "",
- (flags & VIA_RGBA_BIT) ? " rgba," : "",
- (flags & VIA_SPEC_BIT) ? " spec," : "",
- (flags & VIA_FOG_BIT) ? " fog," : "",
- (flags & VIA_TEX0_BIT) ? " tex-0," : "",
- (flags & VIA_TEX1_BIT) ? " tex-1," : "");
-}
-
-void viaCheckTexSizes(GLcontext *ctx)
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
-
- if (!setup_tab[vmesa->setupIndex].check_tex_sizes(ctx)) {
- /* Invalidate stored verts
- */
- vmesa->setupNewInputs = ~0;
- vmesa->setupIndex |= VIA_PTEX_BIT;
-
- if (!vmesa->Fallback &&
- !(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
- tnl->Driver.Render.Interp = setup_tab[vmesa->setupIndex].interp;
- tnl->Driver.Render.CopyPV = setup_tab[vmesa->setupIndex].copy_pv;
- }
-
- if (vmesa->Fallback)
- tnl->Driver.Render.Start(ctx);
- }
- if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
-}
-
-void viaBuildVertices(GLcontext *ctx,
- GLuint start,
- GLuint count,
- GLuint newinputs)
-{
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
- GLuint stride = vmesa->vertexSize * sizeof(GLuint);
- GLubyte *v = (GLubyte *)vmesa->verts + start * stride;
-
- newinputs |= vmesa->setupNewInputs;
- vmesa->setupNewInputs = 0;
-
- if (!newinputs)
- return;
-
- if (newinputs & VERT_BIT_POS) {
- setup_tab[vmesa->setupIndex].emit(ctx, start, count, v, stride);
- }
- else {
- GLuint ind = 0;
-
- if (newinputs & VERT_BIT_COLOR0)
- ind |= VIA_RGBA_BIT;
-
- if (newinputs & VERT_BIT_COLOR1)
- ind |= VIA_SPEC_BIT;
-
- if (newinputs & VERT_BIT_TEX0)
- ind |= VIA_TEX0_BIT;
-
- if (newinputs & VERT_BIT_TEX1)
- ind |= VIA_TEX1_BIT;
-
- if (newinputs & VERT_BIT_FOG)
- ind |= VIA_FOG_BIT;
-
- if (vmesa->setupIndex & VIA_PTEX_BIT)
- ind = ~0;
-
- ind &= vmesa->setupIndex;
- ind |= VIA_XYZW_BIT;
-
- if (ind) {
- setup_tab[ind].emit(ctx, start, count, v, stride);
- }
- }
-}
-
-void viaChooseVertexState(GLcontext *ctx) {
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
- GLuint ind = VIA_XYZW_BIT | VIA_RGBA_BIT;
-
- if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
- ind |= VIA_SPEC_BIT;
-
- if (ctx->Fog.Enabled)
- ind |= VIA_FOG_BIT;
-
- if (ctx->Texture._EnabledUnits > 1)
- ind |= VIA_TEX1_BIT | VIA_TEX0_BIT;
- else if (ctx->Texture._EnabledUnits == 1)
- ind |= VIA_TEX0_BIT;
-
- vmesa->setupIndex = ind;
- viaPrintSetupFlags(__FUNCTION__, ind);
-
- if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
- tnl->Driver.Render.Interp = via_interp_extras;
- tnl->Driver.Render.CopyPV = via_copy_pv_extras;
- }
- else {
- tnl->Driver.Render.Interp = setup_tab[ind].interp;
- tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv;
- }
-
- vmesa->vertexSize = setup_tab[ind].vertex_size;
- vmesa->vertexFormat = setup_tab[ind].vertex_format;
-
- if (VIA_DEBUG) fprintf(stderr, "%s, size %d\n", __FUNCTION__, vmesa->vertexSize);
-}
-
-void *via_emit_contiguous_verts(GLcontext *ctx,
- GLuint start,
- GLuint count,
- void *dest)
-{
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
- GLuint stride = vmesa->vertexSize * 4;
- setup_tab[vmesa->setupIndex].emit(ctx, start, count, dest, stride);
- return (void *)((char *)dest + (count - start) * stride);
-}
-
-
-void viaInitVB(GLcontext *ctx)
-{
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
- GLuint size = TNL_CONTEXT(ctx)->vb.Size;
-
- vmesa->verts = ALIGN_MALLOC(size * 4 * 16, 32);
-
- {
- static int firsttime = 1;
- if (firsttime) {
- init_setup_tab();
- firsttime = 0;
- }
- }
-}
-
-void viaFreeVB(GLcontext *ctx) {
- viaContextPtr vmesa = VIA_CONTEXT(ctx);
-
- if (vmesa->verts) {
- ALIGN_FREE(vmesa->verts);
- vmesa->verts = 0;
- }
-}