packer.py revision 66c14dd42d5cc3f7cc1a06db62c37e87602bcac0
# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.
# This script generates the packer.c file from the gl_header.parsed file.
import apiutil
"""Return a string to write a variable to the packing buffer."""
retval = 9
else:
if is_swapped:
else:
else:
if retval == 9:
assert 0
return retval
def UpdateCurrentPointer( func_name ):
if m :
k = m.group(1)
return
if m :
k = m.group(1)
name = 'secondaryColor'
return
if m :
k = m.group(1)
name = 'texCoord'
return
if m :
k = m.group(1)
name = 'texCoord'
return
if m :
k = m.group(1)
name = 'index'
return
if m :
k = m.group(1)
name = 'edgeFlag'
type = "l1"
return
if m :
k = m.group(1)
name = 'fogCoord'
return
if m :
k = m.group(1)
name = 'vertexAttrib'
# Add 12 to skip the packet length, opcode and index fields
print "\tpc->current.attribsUsedMask |= (1 << index);"
print "\tpc->current.changedVertexAttrib |= (1 << index);"
return
"""Emit a packer function."""
if is_swapped:
print 'void PACK_APIENTRY crPack%sSWAP( %s )' % (func_name, apiutil.MakeDeclarationStringWithContext('CR_PACKER_CONTEXT', params))
else:
print 'void PACK_APIENTRY crPack%s( %s )' % (func_name, apiutil.MakeDeclarationStringWithContext('CR_PACKER_CONTEXT', params))
print '{'
print '\tCR_GET_PACKER_CONTEXT(pc);'
# Save original function name
# Convert to a non-vector version of the function if possible
if not func_name:
# Check if there are any pointer parameters.
# That's usually a problem so we'll emit an error function.
bail_out = 0
bail_out = 1
if bail_out:
print '\t(void)%s;' % (name)
print '\tcrError ( "%s needs to be special cased %d %d!");' % (func_name, vecSize, can_have_pointers)
print '\t(void) pc;'
print '}'
# XXX we should really abort here
return
is_extended = 1
else:
is_extended = 0
print "\tunsigned char *data_ptr;"
print '\t(void) pc;'
#if func_name == "Enable" or func_name == "Disable":
# print "\tCRASSERT(!pc->buffer.geometry_only); /* sanity check */"
print " if (!%s) {" % name
# Know the reason for this one, so avoid the spam.
if orig_func_name != "SecondaryColor3fvEXT":
print " return;"
print " }"
print "\tCR_GET_BUFFERED_POINTER_NO_ARGS( pc );"
# XXX WTF is the purpose of this?
if is_extended:
packet_length += 8
print "\tCR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, %d, GL_TRUE );" % packet_length
else:
if is_extended:
packet_length += 8
print "\tCR_GET_BUFFERED_POINTER( pc, %d );" % packet_length
if is_extended:
counter = 8
else:
counter = 0
# Now emit the WRITE_() macros for all parameters
# if we're converting a vector-valued function to a non-vector func:
# XXX increment counter here?
else:
else:
# finish up
if is_extended:
print "\tWRITE_OPCODE( pc, CR_EXTEND_OPCODE );"
else:
print '\tCR_CMDBLOCK_CHECK_FLUSH(pc);'
print '\tCR_UNLOCK_PACKER_CONTEXT(pc);'
print '}\n'
print """
/* DO NOT EDIT - THIS FILE GENERATED BY THE packer.py SCRIPT */
/* For each of the OpenGL functions we have a packer function which
* packs the function's opcode and arguments into a buffer.
*/
#include "packer.h"
#include "cr_opcodes.h"
"""
continue
continue
pointers_ok = 0
if return_type != 'void':
# Yet another gross hack for glGetString
pointers_ok = 1
if func_name == 'Writeback':
pointers_ok = 1
print '#ifndef IN_RING0'
print '#endif'