# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.
# This script generates the packer_bbox.c file from gl_header.parsed
import sys
import cPickle
import string
import apiutil
print """
/* DO NOT EDIT - THIS FILE GENERATED BY THE packer_bbox.py SCRIPT */
/* These functions pack glVertex functions and also update the bounding box
* if the cr_packer_globals.updateBBOX variable is non-zero.
*/
#include "packer.h"
#include "cr_opcodes.h"
#include "pack_bbox.h"
#include <float.h>
/**
* Reset packer bounding box to empty state.
*/
void crPackResetBoundingBox( CRPackContext *pc )
{
pc->bounds_min.x = FLT_MAX;
pc->bounds_min.y = FLT_MAX;
pc->bounds_min.z = FLT_MAX;
pc->bounds_max.x = -FLT_MAX;
pc->bounds_max.y = -FLT_MAX;
pc->bounds_max.z = -FLT_MAX;
pc->updateBBOX = 1;
}
/**
* Query current bounding box.
* \return GL_TRUE if non-empty box, GL_FALSE if empty box.
*/
GLboolean crPackGetBoundingBox( CRPackContext *pc,
GLfloat *xmin, GLfloat *ymin, GLfloat *zmin,
GLfloat *xmax, GLfloat *ymax, GLfloat *zmax)
{
if (pc->bounds_min.x != FLT_MAX) {
*xmin = pc->bounds_min.x;
*ymin = pc->bounds_min.y;
*zmin = pc->bounds_min.z;
*xmax = pc->bounds_max.x;
*ymax = pc->bounds_max.y;
*zmax = pc->bounds_max.z;
return GL_TRUE;
}
else {
return GL_FALSE;
}
}
"""
else:
if is_swapped:
else:
else:
return retval
"""
Generate all the functions named crPackVertex[234][dfis][v]BBOX() and
crPackVertex[234][dfis][v]BBOX_COUNT().
We also handle glVertexAttrib*ARB.
Note: func_name should not have an ARB suffix.
"""
if do_count:
countSuffix = "_COUNT"
else:
countSuffix = ""
if do_swapped:
swapSuffix = "SWAP"
else:
swapSuffix = ""
isVertexAttrib = 1
else:
isVertexAttrib = 0
normalized = 1
else:
normalized = 0;
vector_type = "GLbyte"
vector_type = "GLubyte"
vector_type = "GLshort"
vector_type = "GLushort"
vector_type = "GLint"
vector_type = "GLuint"
elif argtype == "f":
vector_type = "GLfloat"
elif argtype == "d":
vector_type = "GLdouble"
else:
print "type is %s" % argtype
abort()
if do_vector:
if isVertexAttrib:
else:
print '{'
if do_vector:
# vector version
if isVertexAttrib:
packet_length += 2
else:
# non-vector
if isVertexAttrib:
packet_length += 2
print "\tCR_GET_PACKER_CONTEXT(pc);"
print "\tunsigned char *data_ptr;"
if normalized:
if argtype == "Nb":
t = "B"
elif argtype == "Ni":
t = "I"
elif argtype == "Nui":
t = "UI"
elif argtype == "Nub":
t = "UB"
elif argtype == "Ns":
t = "S"
elif argtype == "Nus":
t = "US"
else:
abort()
if do_vector:
print "\tCREATE_%dD_VFLOATS_%s_NORMALIZED();" % (num_coords, t)
else:
print "\tCREATE_%dD_FLOATS_%s_NORMALIZED();" % (num_coords, t)
else:
if do_vector:
print "\tCREATE_%dD_VFLOATS();" % num_coords
else:
print "\tCREATE_%dD_FLOATS();" % num_coords
# Bounding box code
if isVertexAttrib:
print "\tif (pc->updateBBOX && index == 0)"
else:
print "\tif (pc->updateBBOX)"
print "\t{"
if num_coords < 4:
print "\t\tUPDATE_%dD_BBOX();" % num_coords
else:
print "\t\tUPDATE_3D_BBOX();"
print "\t}"
if isVertexAttrib:
print "\tif (index > 0) {"
t = argtype
print "\t\tpc->current.c.vertexAttrib.%s%d[index] = data_ptr + 4;" % (t, num_coords)
print "\t\tpc->current.attribsUsedMask |= (1 << index);"
if do_count:
print "\t\tpc->current.vtx_count--;"
print "\t}"
if do_vector:
# use non-vector opcode
else:
counter = 0
if do_vector:
if isVertexAttrib:
if do_swapped:
print "\tWRITE_DATA( 0, GLuint, SWAP32(index) );"
else:
print "\tWRITE_DATA( 0, GLuint, index );"
counter += 4
else:
if isVertexAttrib:
if do_vector == 2:
# this is a bit of a hack
else:
else:
else:
if isVertexAttrib:
else:
print "\tCR_UNLOCK_PACKER_CONTEXT(pc);"
print '}\n'
#end PrintFunction()
# Special vector functions
[ "VertexAttrib4usv", "us" ],
[ "VertexAttrib4uiv", "ui" ],
[ "VertexAttrib4bv", "b" ],
[ "VertexAttrib4iv", "i" ],
[ "VertexAttrib4Nbv", "Nb" ],
[ "VertexAttrib4Nsv", "Ns" ],
[ "VertexAttrib4Niv", "Ni" ],
[ "VertexAttrib4Nubv", "Nub" ],
[ "VertexAttrib4Nusv", "Nus" ],
[ "VertexAttrib4Nuiv", "Nui" ]
]
# Special non-vector functions