# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.
import sys
from pack_currenttypes import *
import apiutil
print '''
#include "state/cr_currentpointers.h"
#include "state.h"
#include <stdio.h>
#ifdef WINDOWS
#pragma warning( disable : 4127 )
#endif
typedef void (*convert_func) (GLfloat *, const unsigned char *);
'''
import convert
for k in current_fns.keys():
name = k
print '#define VPINCH_CONVERT_%s(op,data,dst) \\' % ucname
print '{\\'
print '\tGLfloat vdata[%d] = {' % num_members,
## Copy dst data into vdata
i = 0;
print '%d' % defaultvar,
if i != num_members:
print ',',
i += 1
print '};\\'
print '\tswitch (op) { \\'
else:
if ucname == 'EDGEFLAG':
print '\tcase CR_%s_OPCODE: \\' % ucname
else:
if (ucname == 'COLOR' or ucname == 'NORMAL' or ucname == 'SECONDARYCOLOR' or normalize) and type != 'f' and type != 'd':
else:
print '\t\tbreak; \\'
print '\tdefault: \\'
print '\t\tcrSimpleError ( "Unknown opcode in VPINCH_CONVERT_%s" ); \\' % ucname
print '\t}\\'
i = 0
print '\t(dst).%s = vdata[%d];\\' % (member,i)
i += 1
print '}\n'
print '''
void crStateCurrentRecover( void )
{
const unsigned char *v;
convert_func convert=NULL;
CRContext *g = GetCurrentContext();
CRCurrentState *c = &(g->current);
CRStateBits *sb = GetCurrentBits();
CRCurrentBits *cb = &(sb->current);
static const GLfloat color_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
static const GLfloat secondaryColor_default[4] = {0.0f, 0.0f, 0.0f, 0.0f};
static const GLfloat texCoord_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
static const GLfloat normal_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
static const GLfloat index_default = 0.0f;
static const GLboolean edgeFlag_default = GL_TRUE;
static const GLfloat vertexAttrib_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
static const GLfloat fogCoord_default = 0.0f;
GLnormal_p *normal = &(c->current->c.normal);
GLcolor_p *color = &(c->current->c.color);
GLsecondarycolor_p *secondaryColor = &(c->current->c.secondaryColor);
GLtexcoord_p *texCoord = &(c->current->c.texCoord);
GLindex_p *index = &(c->current->c.index);
GLedgeflag_p *edgeFlag = &(c->current->c.edgeFlag);
GLvertexattrib_p *vertexAttrib = &(c->current->c.vertexAttrib);
GLfogcoord_p *fogCoord = &(c->current->c.fogCoord);
unsigned int i;
CRbitvalue nbitID[CR_MAX_BITARRAY];
/*
* If the calling SPU hasn't called crStateSetCurrentPointers()
* we can't recover anything, so abort now. (i.e. we don't have
* a pincher, oh, and just emit the message once).
*/
if (!c->current) {
static int donewarning = 0;
if (!donewarning)
crWarning("No pincher, please call crStateSetCurrentPointers() in your SPU");
donewarning = 1;
return; /* never get here */
}
c->attribsUsedMask = c->current->attribsUsedMask;
/* silence warnings */
(void) __convert_b1;
(void) __convert_b2;
(void) __convert_b3;
(void) __convert_b4;
(void) __convert_ui1;
(void) __convert_ui2;
(void) __convert_ui3;
(void) __convert_ui4;
(void) __convert_l1;
(void) __convert_l2;
(void) __convert_l3;
(void) __convert_l4;
(void) __convert_us1;
(void) __convert_us2;
(void) __convert_us3;
(void) __convert_us4;
(void) __convert_ub1;
(void) __convert_ub2;
(void) __convert_ub3;
(void) __convert_ub4;
(void) __convert_rescale_s1;
(void) __convert_rescale_s2;
(void) __convert_rescale_b1;
(void) __convert_rescale_b2;
(void) __convert_rescale_ui1;
(void) __convert_rescale_ui2;
(void) __convert_rescale_i1;
(void) __convert_rescale_i2;
(void) __convert_rescale_us1;
(void) __convert_rescale_us2;
(void) __convert_rescale_ub1;
(void) __convert_rescale_ub2;
(void) __convert_Ni1;
(void) __convert_Ni2;
(void) __convert_Ni3;
(void) __convert_Ni4;
(void) __convert_Nb1;
(void) __convert_Nb2;
(void) __convert_Nb3;
(void) __convert_Nb4;
(void) __convert_Nus1;
(void) __convert_Nus2;
(void) __convert_Nus3;
(void) __convert_Nus4;
(void) __convert_Nui1;
(void) __convert_Nui2;
(void) __convert_Nui3;
(void) __convert_Nui4;
(void) __convert_Ns1;
(void) __convert_Ns2;
(void) __convert_Ns3;
(void) __convert_Ns4;
(void) __convert_Nub1;
(void) __convert_Nub2;
(void) __convert_Nub3;
(void) __convert_Nub4;
DIRTY(nbitID, g->neg_bitid);
/* Save pre state */
for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++) {
COPY_4V(c->vertexAttribPre[i] , c->vertexAttrib[i]);
}
c->edgeFlagPre = c->edgeFlag;
c->colorIndexPre = c->colorIndex;
'''
for k in current_fns.keys():
print '\t/* %s */' % k
print '\tv=NULL;'
print '\t{'
indent += "\t"
else:
ptr += "[i]"
print '%s\t{' % indent
if (k == 'Color' or k == 'Normal' or k == 'SecondaryColor' or normalized) and type != 'f' and type != 'd' and type != 'l':
else:
print '%s\t}' % indent
print ''
print '%s\tif (v != NULL) {' % indent
if k == 'TexCoord':
else:
else:
if k == 'Normal':
elif k == 'FogCoord':
elif k == 'Color':
elif k == 'SecondaryColor':
elif k == 'TexCoord':
elif k == 'Index':
elif k == 'EdgeFlag':
else:
if k == 'EdgeFlag':
print '%s\t\t__convert_boolean (&c->edgeFlag, v);' % (indent)
elif k == 'Normal':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_NORMAL][0]), v);' % (indent)
elif k == 'TexCoord':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_TEX0 + i][0]), v);' % (indent)
elif k == 'Color':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]), v);' % (indent)
elif k == 'Index':
print '%s\t\tconvert(&(c->colorIndex), v);' % (indent)
elif k == 'SecondaryColor':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR1][0]), v);' % (indent)
elif k == 'FogCoord':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_FOG][0]), v);' % (indent)
elif k == 'VertexAttrib':
print '%s\t\tconvert(&(c->vertexAttrib[i][0]), v);' % (indent)
else:
assert 0 # should never get here
# if current_fns[k].has_key( 'array' ):
# print '%s\t\tDIRTY(cb->%s[i], nbitID);' % (indent,name)
# else:
# print '%s\t\tDIRTY(cb->%s, nbitID);' % (indent,name)
print '%s\t\tDIRTY(cb->dirty, nbitID);' % indent
print '%s\t}' % indent
else:
print '\t}'
print '}'
print '''
void crStateCurrentRecoverNew(CRContext *g, CRCurrentStatePointers *current)
{
const unsigned char *v;
convert_func convert=NULL;
CRCurrentState *c = &(g->current);
CRStateBits *sb = GetCurrentBits();
CRCurrentBits *cb = &(sb->current);
static const GLfloat vertexAttrib_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
GLvertexattrib_p *vertexAttrib = &(current->c.vertexAttrib);
unsigned int i;
CRbitvalue nbitID[CR_MAX_BITARRAY];
/* silence warnings */
(void) __convert_b1;
(void) __convert_b2;
(void) __convert_b3;
(void) __convert_b4;
(void) __convert_ui1;
(void) __convert_ui2;
(void) __convert_ui3;
(void) __convert_ui4;
(void) __convert_l1;
(void) __convert_l2;
(void) __convert_l3;
(void) __convert_l4;
(void) __convert_us1;
(void) __convert_us2;
(void) __convert_us3;
(void) __convert_us4;
(void) __convert_ub1;
(void) __convert_ub2;
(void) __convert_ub3;
(void) __convert_ub4;
(void) __convert_rescale_s1;
(void) __convert_rescale_s2;
(void) __convert_rescale_b1;
(void) __convert_rescale_b2;
(void) __convert_rescale_ui1;
(void) __convert_rescale_ui2;
(void) __convert_rescale_i1;
(void) __convert_rescale_i2;
(void) __convert_rescale_us1;
(void) __convert_rescale_us2;
(void) __convert_rescale_ub1;
(void) __convert_rescale_ub2;
(void) __convert_Ni1;
(void) __convert_Ni2;
(void) __convert_Ni3;
(void) __convert_Ni4;
(void) __convert_Nb1;
(void) __convert_Nb2;
(void) __convert_Nb3;
(void) __convert_Nb4;
(void) __convert_Nus1;
(void) __convert_Nus2;
(void) __convert_Nus3;
(void) __convert_Nus4;
(void) __convert_Nui1;
(void) __convert_Nui2;
(void) __convert_Nui3;
(void) __convert_Nui4;
(void) __convert_Ns1;
(void) __convert_Ns2;
(void) __convert_Ns3;
(void) __convert_Ns4;
(void) __convert_Nub1;
(void) __convert_Nub2;
(void) __convert_Nub3;
(void) __convert_Nub4;
'''
for k in current_fns_new.keys():
print '\t/* %s */' % k
print '\tif (current->changed%s)' % k
print '\t{'
print '\t\tv=NULL;'
print '\t\t{'
indent += "\t\t"
print '\t\tif (!(current->changed%s & (1 << i))) continue;' % k
else:
ptr += "[i]"
print '#ifdef DEBUG_misha'
print '%s\t{' % (indent)
print '%s\t\t--pTst;' % (indent)
print '%s\t\tAssert((*pTst) == i);' % (indent)
print '%s\t}' % (indent)
print '#endif'
print '%s\t{' % indent
if (k == 'Color' or k == 'Normal' or k == 'SecondaryColor' or normalized) and type != 'f' and type != 'd' and type != 'l':
else:
print '%s\t}' % indent
print ''
print '%s\tif (v != NULL) {' % indent
if k == 'TexCoord':
else:
else:
if k == 'Normal':
elif k == 'FogCoord':
elif k == 'Color':
elif k == 'SecondaryColor':
elif k == 'TexCoord':
elif k == 'Index':
elif k == 'EdgeFlag':
else:
if k == 'EdgeFlag':
print '%s\t\t__convert_boolean (&c->edgeFlag, v);' % (indent)
elif k == 'Normal':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_NORMAL][0]), v);' % (indent)
elif k == 'TexCoord':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_TEX0 + i][0]), v);' % (indent)
elif k == 'Color':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]), v);' % (indent)
elif k == 'Index':
print '%s\t\tconvert(&(c->colorIndex), v);' % (indent)
elif k == 'SecondaryColor':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR1][0]), v);' % (indent)
elif k == 'FogCoord':
print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_FOG][0]), v);' % (indent)
elif k == 'VertexAttrib':
print '%s\t\tconvert(&(c->vertexAttrib[i][0]), v);' % (indent)
else:
assert 0 # should never get here
# if current_fns_new[k].has_key( 'array' ):
# print '%s\t\tDIRTY(cb->%s[i], nbitID);' % (indent,name)
# else:
# print '%s\t\tDIRTY(cb->%s, nbitID);' % (indent,name)
print '%s\t\tDIRTY(cb->dirty, nbitID);' % indent
print '%s\t}' % indent
else:
print '\t\t}'
print '\t\tcurrent->changed%s = 0;' % k
print '\t}'
print '\tcrStateResetCurrentPointers(current);'
print '}'