+
#define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace)
-static void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
+
+/*
+ * These functions take the NDC coordinates pointed to by 'in', apply the
+ * NDC->Viewport mapping and store the results at 'v'.
+ */
+
+static void
+insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
{
GLfloat *out = (GLfloat *)v;
const GLfloat * const vp = a->vp;
}
+/*
+ * These functions do the same as above, except for the viewport mapping.
+ */
+
static void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
{
GLfloat *out = (GLfloat *)(v);
{
UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
v[1] = 0;
- v[0]= 0;
+ v[0] = 0;
}
const GLfloat *in = (const GLfloat *)v;
const GLfloat * const vp = a->vp;
+ /* Although included for completeness, the position coordinate is
+ * usually handled differently during clipping.
+ */
out[0] = (in[0] - vp[12]) / vp[0];
out[1] = (in[1] - vp[13]) / vp[5];
out[2] = (in[2] - vp[14]) / vp[10];
out[0] = in[0];
out[1] = in[1];
- out[2] = in[3];
- out[3] = 1;
+ out[2] = 0;
+ out[3] = in[2];
}
const char *name;
extract_func extract;
insert_func insert[4];
- GLuint attrsize;
+ const GLuint attrsize;
} format_info[EMIT_MAX] = {
{ "1f",
extract_4chan_4f_rgba,
{ insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3,
insert_4chan_4f_rgba_4 },
- 4 * sizeof(GLchan) }
+ 4 * sizeof(GLchan) },
+
+ { "pad",
+ 0,
+ { 0, 0, 0, 0 },
+ 0 }
};
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
struct tnl_clipspace_attr *a = vtx->attr;
GLubyte *v = (GLubyte *)dest;
- int i, j;
- GLuint count = vtx->attr_count;
+ GLuint i, j;
+ const GLuint count = vtx->attr_count;
GLuint stride;
for (j = 0; j < count; j++) {
GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
a[j].inputstride = vptr->stride;
- a[j].inputptr = (GLubyte *)STRIDE_4F(vptr->data, start * vptr->stride);
+ a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
a[j].emit = a[j].insert[vptr->size - 1];
}
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct vertex_buffer *VB = &tnl->vb;
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
- GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
+ const GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
+ const GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
const struct tnl_clipspace_attr *a = vtx->attr;
- int attr_count = vtx->attr_count;
- int j;
+ const GLuint attr_count = vtx->attr_count;
+ GLuint j;
if (tnl->NeedNdcCoords) {
const GLfloat *dstclip = VB->ClipPtr->data[edst];
- const GLfloat w = 1.0 / dstclip[3];
- GLfloat pos[4];
+ if (dstclip[3] != 0.0) {
+ const GLfloat w = 1.0f / dstclip[3];
+ GLfloat pos[4];
- pos[0] = dstclip[0] * w;
- pos[1] = dstclip[1] * w;
- pos[2] = dstclip[2] * w;
- pos[3] = w;
+ pos[0] = dstclip[0] * w;
+ pos[1] = dstclip[1] * w;
+ pos[2] = dstclip[2] * w;
+ pos[3] = w;
- a[0].insert[4-1]( &a[0], vdst, pos );
+ a[0].insert[4-1]( &a[0], vdst, pos );
+ }
}
else {
a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] );
GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
const struct tnl_clipspace_attr *a = vtx->attr;
- int attr_count = vtx->attr_count;
- int j;
+ const GLuint attr_count = vtx->attr_count;
+ GLuint j;
for (j = 0; j < attr_count; j++) {
if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
a[j].attrib == VERT_ATTRIB_COLOR1) {
- memcpy( vdst + a[j].vertoffset,
- vsrc + a[j].vertoffset,
- a[j].vertattrsize );
+ _mesa_memcpy( vdst + a[j].vertoffset,
+ vsrc + a[j].vertoffset,
+ a[j].vertattrsize );
}
}
}
VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
}
- _tnl_copy_pv(ctx, dst, src);
+ generic_copy_pv(ctx, dst, src);
}
-
-
/***********************************************************************
* Build codegen functions or return generic ones:
*/
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
const struct tnl_clipspace_attr *a = vtx->attr;
- int attr_count = vtx->attr_count;
- int j;
+ const GLuint attr_count = vtx->attr_count;
+ GLuint j;
for (j = 0; j < attr_count; j++) {
- if (a[j].attrib == attr) {
- a[j].extract( &a[j], dest, vin );
+ if (a[j].attrib == (int)attr) {
+ a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset );
return;
}
}
- /* Else return the value from ctx->Current
+ /* Else return the value from ctx->Current -- dangerous???
*/
- memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
+ _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat));
}
+
+/* Complementary operation to the above.
+ */
+void _tnl_set_attr( GLcontext *ctx, void *vout,
+ GLenum attr, const GLfloat *src )
+{
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ const struct tnl_clipspace_attr *a = vtx->attr;
+ const GLuint attr_count = vtx->attr_count;
+ GLuint j;
+
+ for (j = 0; j < attr_count; j++) {
+ if (a[j].attrib == (int)attr) {
+ a[j].insert[4-1]( &a[j], (GLubyte *)vout + a[j].vertoffset, src );
+ return;
+ }
+ }
+}
+
+
void *_tnl_get_vertex( GLcontext *ctx, GLuint nr )
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
GLuint unpacked_size )
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- int offset = 0;
- int i;
+ GLuint offset = 0;
+ GLuint i, j;
assert(nr < _TNL_ATTRIB_MAX);
assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS);
- vtx->attr_count = nr;
vtx->emit = choose_emit_func;
vtx->interp = choose_interp_func;
vtx->copy_pv = choose_copy_pv_func;
vtx->new_inputs = ~0;
- for (i = 0; i < nr; i++) {
- GLuint format = map[i].format;
- vtx->attr[i].attrib = map[i].attrib;
- vtx->attr[i].vp = vp;
- vtx->attr[i].insert = format_info[format].insert;
- vtx->attr[i].extract = format_info[format].extract;
- vtx->attr[i].vertattrsize = format_info[format].attrsize;
+ for (j = 0, i = 0; i < nr; i++) {
+ const GLuint format = map[i].format;
+ if (format == EMIT_PAD) {
+ offset += map[i].offset;
- if (unpacked_size)
- vtx->attr[i].vertoffset = map[i].offset;
- else
- vtx->attr[i].vertoffset = offset;
+/* fprintf(stderr, "%d: pad %d, offset now %d\n", i, */
+/* map[i].offset, offset); */
- offset += format_info[format].attrsize;
+ }
+ else {
+ vtx->attr[j].attrib = map[i].attrib;
+ vtx->attr[j].vp = vp;
+ vtx->attr[j].insert = format_info[format].insert;
+ vtx->attr[j].extract = format_info[format].extract;
+ vtx->attr[j].vertattrsize = format_info[format].attrsize;
+
+ if (unpacked_size)
+ vtx->attr[j].vertoffset = map[i].offset;
+ else
+ vtx->attr[j].vertoffset = offset;
+
+/* fprintf(stderr, "%d: %s offset %d\n", i, */
+/* format_info[format].name, vtx->attr[j].vertoffset); */
+
+ offset += format_info[format].attrsize;
+ j++;
+ }
}
+ vtx->attr_count = j;
+
if (unpacked_size)
vtx->vertex_size = unpacked_size;
else
void _tnl_build_vertices( GLcontext *ctx,
- GLuint start,
- GLuint count,
- GLuint newinputs )
+ GLuint start,
+ GLuint end,
+ GLuint newinputs )
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- GLuint stride = vtx->vertex_size;
- GLubyte *v = ((GLubyte *)vtx->vertex_buf + (start*stride));
+ const GLuint stride = vtx->vertex_size;
+ GLubyte *vDest = ((GLubyte *)vtx->vertex_buf + (start*stride));
newinputs |= vtx->new_inputs;
vtx->new_inputs = 0;
if (newinputs)
- vtx->emit( ctx, start, count, v );
+ vtx->emit( ctx, start, end, vDest );
}
void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
- GLuint start,
- GLuint count,
- void *dest )
+ GLuint start,
+ GLuint end,
+ void *dest )
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- vtx->emit( ctx, start, count, dest );
- return (void *)((GLubyte *)dest + vtx->vertex_size * (count - start));
+ vtx->emit( ctx, start, end, dest );
+ return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start));
}
if (max_vertex_size > vtx->max_vertex_size) {
_tnl_free_vertices( ctx );
vtx->max_vertex_size = max_vertex_size;
- vtx->vertex_buf = (GLubyte *)ALIGN_MALLOC(vb_size * max_vertex_size, 32 );
+ vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 );
}
}