-/* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
+/* -*- mode: c; c-basic-offset: 3 -*- */
/*
* Copyright 2000 Gareth Hughes
* All Rights Reserved.
* José Fonseca <j_r_fonseca@yahoo.co.uk>
*/
-#include "glheader.h"
-#include "mtypes.h"
-#include "colormac.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/mtypes.h"
+#include "main/colormac.h"
+#include "main/macros.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#define COPY_VERTEX_OOA( vb, vertsize, v, n ) DO_COPY_VERTEX( vb, vertsize, v, n, 1 )
-static __inline void mach64_draw_quad( mach64ContextPtr mmesa,
+static INLINE void mach64_draw_quad( mach64ContextPtr mmesa,
mach64VertexPtr v0,
mach64VertexPtr v1,
mach64VertexPtr v2,
#endif
}
-static __inline void mach64_draw_triangle( mach64ContextPtr mmesa,
+static INLINE void mach64_draw_triangle( mach64ContextPtr mmesa,
mach64VertexPtr v0,
mach64VertexPtr v1,
mach64VertexPtr v2 )
#endif
}
-static __inline void mach64_draw_line( mach64ContextPtr mmesa,
+static INLINE void mach64_draw_line( mach64ContextPtr mmesa,
mach64VertexPtr v0,
mach64VertexPtr v1 )
{
#if MACH64_NATIVE_VTXFMT
GLcontext *ctx = mmesa->glCtx;
const GLuint vertsize = mmesa->vertex_size;
- GLint width = (GLint)(mmesa->glCtx->Line._Width * 2.0); /* 2 fractional bits for hardware */
+ /* 2 fractional bits for hardware: */
+ const int width = (int) (2.0 * CLAMP(mmesa->glCtx->Line.Width,
+ mmesa->glCtx->Const.MinLineWidth,
+ mmesa->glCtx->Const.MaxLineWidth));
GLfloat ooa;
GLuint *pxy0, *pxy1;
GLuint xy0old, xy0, xy1old, xy1;
mach64_print_vertex( ctx, v1 );
}
- if( !width )
- width = 1; /* round to the nearest supported width */
-
pxy0 = &v0->ui[xyoffset];
xy0old = *pxy0;
xy0 = LE32_IN( &xy0old );
#endif
}
-static __inline void mach64_draw_point( mach64ContextPtr mmesa,
+static INLINE void mach64_draw_point( mach64ContextPtr mmesa,
mach64VertexPtr v0 )
{
#if MACH64_NATIVE_VTXFMT
GLcontext *ctx = mmesa->glCtx;
const GLuint vertsize = mmesa->vertex_size;
- GLint sz = (GLint)(mmesa->glCtx->Point._Size * 2.0); /* 2 fractional bits for hardware */
+ /* 2 fractional bits for hardware: */
+ GLint sz = (GLint) (2.0 * CLAMP(mmesa->glCtx->Point.Size,
+ ctx->Const.MinPointSize,
+ ctx->Const.MaxPointSize));
GLfloat ooa;
GLuint *pxy;
GLuint xyold, xy;
#define MACH64_MAX_TRIFUNC 0x10
static struct {
- points_func points;
- line_func line;
- triangle_func triangle;
- quad_func quad;
+ tnl_points_func points;
+ tnl_line_func line;
+ tnl_triangle_func triangle;
+ tnl_quad_func quad;
} rast_tab[MACH64_MAX_TRIFUNC];
#define VERT_SET_Z(_v,val) LE32_OUT( &(_v)->ui[zoffset], (GLuint)(val) )
#define VERT_Z_ADD(_v,val) LE32_OUT( &(_v)->ui[zoffset], LE32_IN( &(_v)->ui[zoffset] ) + (GLuint)(val) )
#define AREA_IS_CCW( a ) ((a) < 0)
-#define GET_VERTEX(e) (mmesa->verts + ((e)<<mmesa->vertex_stride_shift))
+#define GET_VERTEX(e) (mmesa->verts + ((e) * mmesa->vertex_size * sizeof(int)))
#define MACH64_COLOR( dst, src ) \
do { \
- dst[0] = src[2]; \
- dst[1] = src[1]; \
- dst[2] = src[0]; \
- dst[3] = src[3]; \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[0], src[2]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[1], src[1]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[2], src[0]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[3], src[3]); \
} while (0)
#define MACH64_SPEC( dst, src ) \
do { \
- dst[0] = src[2]; \
- dst[1] = src[1]; \
- dst[2] = src[0]; \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[0], src[2]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[1], src[1]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[2], src[0]); \
} while (0)
#define VERT_SET_RGBA( v, c ) MACH64_COLOR( v->ub4[coloroffset], c )
#define LOCAL_VARS(n) \
mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
- GLuint color[n], spec[n]; \
+ GLuint color[n] = { 0 }; \
+ GLuint spec[n] = { 0 }; \
GLuint vertex_size = mmesa->vertex_size; \
const GLuint xyoffset = 9; \
const GLuint coloroffset = 8; \
#define VERT_Y(_v) _v->v.y
#define VERT_Z(_v) _v->v.z
#define AREA_IS_CCW( a ) (a > 0)
-#define GET_VERTEX(e) (mmesa->verts + (e<<mmesa->vertex_stride_shift))
+#define GET_VERTEX(e) (mmesa->verts + ((e) * mmesa->vertex_size * sizeof(int)))
#define MACH64_COLOR( dst, src ) \
do { \
- dst[0] = src[2]; \
- dst[1] = src[1]; \
- dst[2] = src[0]; \
- dst[3] = src[3]; \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[0], src[2]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[1], src[1]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[2], src[0]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[3], src[3]); \
} while (0)
#define MACH64_SPEC( dst, src ) \
do { \
- dst[0] = src[2]; \
- dst[1] = src[1]; \
- dst[2] = src[0]; \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[0], src[2]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[1], src[1]); \
+ UNCLAMPED_FLOAT_TO_UBYTE(dst[2], src[0]); \
} while (0)
#define VERT_SET_RGBA( v, c ) MACH64_COLOR( v->ub4[coloroffset], c )
/* Render unclipped begin/end objects */
/**********************************************************************/
-#define VERT(x) (mach64Vertex *)(mach64verts + ((x) << shift))
+#define VERT(x) (mach64Vertex *)(mach64verts + ((x) * vertsize * sizeof(int)))
#define RENDER_POINTS( start, count ) \
for ( ; start < count ; start++) \
mach64_draw_point( mmesa, VERT(start) )
#undef LOCAL_VARS
#define LOCAL_VARS \
mach64ContextPtr mmesa = MACH64_CONTEXT(ctx); \
- const GLuint shift = mmesa->vertex_stride_shift; \
+ const GLuint vertsize = mmesa->vertex_size; \
const char *mach64verts = (char *)mmesa->verts; \
const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
(void) elt;
mach64ContextPtr mmesa = MACH64_CONTEXT( ctx );
const GLuint vertsize = mmesa->vertex_size;
GLint a;
- GLfloat ooa;
+ union {
+ GLfloat f;
+ CARD32 u;
+ } ooa;
GLuint xy;
const GLuint xyoffset = 9;
GLint xx[3], yy[3]; /* 2 fractional bits for hardware */
unsigned vbsiz = (vertsize + (vertsize > 7 ? 2 : 1)) * n + (n-2);
CARD32 *vb, *vbchk;
GLubyte *mach64verts = (GLubyte *)mmesa->verts;
- const GLuint shift = mmesa->vertex_stride_shift;
mach64VertexPtr v0, v1, v2;
int i;
return;
}
- ooa = 16.0 / a;
+ ooa.f = 16.0 / a;
vb = (CARD32 *)mach64AllocDmaLow( mmesa, vbsiz * sizeof(CARD32) );
vbchk = vb + vbsiz;
COPY_VERTEX( vb, vertsize, v0, 1 );
COPY_VERTEX( vb, vertsize, v1, 2 );
COPY_VERTEX_OOA( vb, vertsize, v2, 3 );
- LE32_OUT( vb++, *(CARD32 *)&ooa );
+ LE32_OUT( vb++, ooa.u );
i = 3;
while (1) {
a = (xx[0] - xx[2]) * (yy[1] - yy[2]) -
(yy[0] - yy[2]) * (xx[1] - xx[2]);
- ooa = 16.0 / a;
+ ooa.f = 16.0 / a;
COPY_VERTEX_OOA( vb, vertsize, v0, 1 );
- LE32_OUT( vb++, *(CARD32 *)&ooa );
+ LE32_OUT( vb++, ooa.u );
if (i >= n)
break;
a = (xx[0] - xx[2]) * (yy[1] - yy[2]) -
(yy[0] - yy[2]) * (xx[1] - xx[2]);
- ooa = 16.0 / a;
+ ooa.f = 16.0 / a;
COPY_VERTEX_OOA( vb, vertsize, v1, 2 );
- LE32_OUT( vb++, *(CARD32 *)&ooa );
+ LE32_OUT( vb++, ooa.u );
}
assert( vb == vbchk );
GLuint n )
{
mach64ContextPtr mmesa = MACH64_CONTEXT( ctx );
+ const GLuint vertsize = mmesa->vertex_size;
GLubyte *mach64verts = (GLubyte *)mmesa->verts;
- const GLuint shift = mmesa->vertex_stride_shift;
const GLuint *start = (const GLuint *)VERT(elts[0]);
int i;
/* Transition to/from hardware rasterization. */
/**********************************************************************/
+static const char * const fallbackStrings[] = {
+ "Texture mode",
+ "glDrawBuffer(GL_FRONT_AND_BACK)",
+ "glReadBuffer",
+ "glEnable(GL_STENCIL) without hw stencil buffer",
+ "glRenderMode(selection or feedback)",
+ "glLogicOp (mode != GL_COPY)",
+ "GL_SEPARATE_SPECULAR_COLOR",
+ "glBlendEquation (mode != ADD)",
+ "glBlendFunc",
+ "Rasterization disable",
+};
+
+
+static const char *getFallbackString(GLuint bit)
+{
+ int i = 0;
+ while (bit > 1) {
+ i++;
+ bit >>= 1;
+ }
+ return fallbackStrings[i];
+}
+
void mach64Fallback( GLcontext *ctx, GLuint bit, GLboolean mode )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
GLuint oldfallback = mmesa->Fallback;
if (mode) {
- if (MACH64_DEBUG & DEBUG_VERBOSE_MSG)
- fprintf(stderr,"Set Fallback: %d\n", bit);
mmesa->Fallback |= bit;
if (oldfallback == 0) {
FLUSH_BATCH( mmesa );
_swsetup_Wakeup( ctx );
mmesa->RenderIndex = ~0;
+ if (MACH64_DEBUG & DEBUG_VERBOSE_FALLBACK) {
+ fprintf(stderr, "Mach64 begin rasterization fallback: 0x%x %s\n",
+ bit, getFallbackString(bit));
+ }
}
}
else {
- if (MACH64_DEBUG & DEBUG_VERBOSE_MSG)
- fprintf(stderr,"Clear Fallback: %d\n", bit);
mmesa->Fallback &= ~bit;
if (oldfallback == bit) {
_swrast_flush( ctx );
tnl->Driver.Render.BuildVertices = mach64BuildVertices;
mmesa->NewGLState |= (_MACH64_NEW_RENDER_STATE|
_MACH64_NEW_VERTEX_STATE);
+ if (MACH64_DEBUG & DEBUG_VERBOSE_FALLBACK) {
+ fprintf(stderr, "Mach64 end rasterization fallback: 0x%x %s\n",
+ bit, getFallbackString(bit));
+ }
}
}
}
tnl->Driver.Render.PrimitiveNotify = mach64RenderPrimitive;
tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
tnl->Driver.Render.BuildVertices = mach64BuildVertices;
-
-/* mach64Fallback( ctx, 0x100000, 1 ); */
}