From: Gerardo H. <ma...@us...> - 2007-03-06 18:43:00
|
Update of /cvsroot/jrman/drafts/src/org/jrman/parser/keywords In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28800/src/org/jrman/parser/keywords Modified Files: AbstractKeywordParser.java Log Message: Started working on new internal representation for primitive parameters (to handle dicing and splitting for all vertex parameters). Index: AbstractKeywordParser.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/parser/keywords/AbstractKeywordParser.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** AbstractKeywordParser.java 1 Mar 2007 00:50:29 -0000 1.17 --- AbstractKeywordParser.java 6 Mar 2007 18:42:46 -0000 1.18 *************** *** 34,37 **** --- 34,39 ---- import org.jrman.parameters.Declaration; import org.jrman.parameters.ParameterList; + import org.jrman.parameters.Parameters; + import org.jrman.parameters.ParamInfo; import org.jrman.parser.Global; import org.jrman.parser.Parser; *************** *** 62,65 **** --- 64,85 ---- protected static int arraySize; + private static int floatCount; + + private static int integerCount; + + private static int stringCount; + + private static List<ParamInfo> constantParams = + new ArrayList<ParamInfo>(); + + private static List<ParamInfo> uniformParams = + new ArrayList<ParamInfo>(); + + private static List<ParamInfo> varyingParams = + new ArrayList<ParamInfo>(); + + private static List<ParamInfo> vertexParams = + new ArrayList<ParamInfo>(); + protected Parser parser; *************** *** 367,369 **** --- 387,677 ---- } + private void addFloat(float f) { + if (floatCount == floats.length) { + float[] tmp = new float[floats.length * 2]; + System.arraycopy(floats, 0, tmp, 0, floats.length); + floats = tmp; + } + floats[floatCount++] = f; + } + + private void readFloats(Tokenizer st) throws Exception { + int token = st.nextToken(); + if (token == TK_LBRACE) { + while (st.nextToken() == TK_NUMBER) + addFloat(st.nval); + st.pushBack(); + match(st, TK_RBRACE); + } else { + st.pushBack(); + match(st, TK_NUMBER); + addFloat(st.nval); + } + } + + private void addInteger(int i) { + if (integerCount == integers.length) { + int[] tmp = new int[integers.length * 2]; + System.arraycopy(integers, 0, tmp, 0, integers.length); + integers = tmp; + } + integers[integerCount++] = i; + } + + private void readIntegers(Tokenizer st) throws Exception { + int token = st.nextToken(); + if (token == TK_LBRACE) { + while (st.nextToken() == TK_NUMBER) + addInteger((int) st.nval); + st.pushBack(); + match(st, TK_RBRACE); + } else { + st.pushBack(); + match(st, TK_NUMBER); + addInteger((int) st.nval); + } + } + + private void addString(String s) { + if (stringCount == strings.length) { + String[] tmp = new String[strings.length * 2]; + System.arraycopy(strings, 0, tmp, 0, strings.length); + strings = tmp; + } + strings[stringCount++] = s; + } + + private void readStrings(Tokenizer st) throws Exception { + int token = st.nextToken(); + if (token == TK_LBRACE) { + while (st.nextToken() == TK_NUMBER) + addString(st.sval); + st.pushBack(); + match(st, TK_RBRACE); + } else { + st.pushBack(); + match(st, TK_NUMBER); + addString(st.sval); + } + } + + protected Parameters parseParameters(Tokenizer st) throws Exception { + floatCount = 0; + integerCount = 0; + stringCount = 0; + constantParams.clear(); + uniformParams.clear(); + varyingParams.clear(); + vertexParams.clear(); + // Expect list of key & value pairs + while (st.nextToken() == TK_STRING) { + Declaration declaration = null; + try { + declaration = getDeclaration(st.sval); + } catch (IllegalArgumentException e) { + System.err.println("Unknown type for parameter: " + st.sval); + } + Declaration.Type elementType = declaration.getElementType(); + int offset, count; + if (elementType == Declaration.Type.FLOAT) { + offset = floatCount; + readFloats(st); + count = floatCount - offset; + } else if (elementType == Declaration.Type.INTEGER) { + offset = integerCount; + readIntegers(st); + count = integerCount - offset; + } else { + offset = stringCount; + readStrings(st); + count = stringCount - offset; + } + ParamInfo paramInfo = new ParamInfo(declaration, offset, count); + Declaration.StorageClass storageClass = + declaration.getStorageClass(); + if (storageClass == Declaration.StorageClass.CONSTANT) + constantParams.add(paramInfo); + else if (storageClass == Declaration.StorageClass.UNIFORM) + uniformParams.add(paramInfo); + else if (storageClass == Declaration.StorageClass.VARYING) + varyingParams.add(paramInfo); + else + vertexParams.add(paramInfo); + } + int floatParamsCount = 0; + int integerParamsCount = 0; + int stringParamsCount = 0; + for (ParamInfo paramInfo: constantParams) { + Declaration.Type elementType = + paramInfo.getDeclaration().getElementType(); + if (elementType == Declaration.Type.FLOAT) + floatParamsCount++; + else if (elementType == Declaration.Type.INTEGER) + integerParamsCount++; + else + stringParamsCount++; + } + ParamInfo[] constantParamsInfo = null; + float[] constantFloats = null; + int[] constantIntegers = null; + String[] constantStrings = null; + int floatsOffset = 0; + int integersOffset = 0; + int stringsOffset = 0; + if (constantParams.size() > 0) { + constantParamsInfo = new ParamInfo[constantParams.size()]; + if (floatParamsCount > 0) + constantFloats = new float[floatParamsCount]; + if (integerParamsCount > 0) + constantIntegers = new int[integerParamsCount]; + if (stringParamsCount > 0) + constantStrings = new String[stringParamsCount]; + int index = 0; + for (ParamInfo paramInfo: constantParams) { + Declaration.Type elementType = + paramInfo.getDeclaration().getElementType(); + int count = paramInfo.getDeclaration().getElementCount(); + if (elementType == Declaration.Type.FLOAT) { + System.arraycopy(floats, paramInfo.getOffset(), + constantFloats, floatsOffset, + paramInfo.getCount()); + paramInfo.adjust(floatsOffset); + floatsOffset += paramInfo.getCount(); + } else if (elementType == Declaration.Type.INTEGER) { + System.arraycopy(integers, paramInfo.getOffset(), + constantIntegers, integersOffset, + paramInfo.getCount()); + paramInfo.adjust(integersOffset); + integersOffset += paramInfo.getCount(); + } else { + System.arraycopy(strings, paramInfo.getOffset(), + constantStrings, stringsOffset, + paramInfo.getCount()); + paramInfo.adjust(stringsOffset); + stringsOffset += paramInfo.getCount(); + } + constantParamsInfo[index++] = paramInfo; + } + } + floatParamsCount = 0; + integerParamsCount = 0; + floatParamsCount = 0; + for (ParamInfo paramInfo: uniformParams) { + Declaration.Type elementType = + paramInfo.getDeclaration().getElementType(); + if (elementType == Declaration.Type.FLOAT) + floatParamsCount++; + else if (elementType == Declaration.Type.INTEGER) + integerParamsCount++; + else + stringParamsCount++; + } + ParamInfo[] uniformParamsInfo = null; + float[] uniformFloats = null; + int[] uniformIntegers = null; + String[] uniformStrings = null; + floatsOffset = 0; + integersOffset = 0; + stringsOffset = 0; + if (uniformParams.size() > 0) { + uniformParamsInfo = new ParamInfo[uniformParams.size()]; + if (floatParamsCount > 0) + uniformFloats = new float[floatParamsCount]; + if (integerParamsCount > 0) + uniformIntegers = new int[integerParamsCount]; + if (stringParamsCount > 0) + uniformStrings = new String[stringParamsCount]; + int index = 0; + for (ParamInfo paramInfo: uniformParams) { + Declaration.Type elementType = + paramInfo.getDeclaration().getElementType(); + int count = paramInfo.getDeclaration().getElementCount(); + if (elementType == Declaration.Type.FLOAT) { + System.arraycopy(floats, paramInfo.getOffset(), + uniformFloats, floatsOffset, + paramInfo.getCount()); + paramInfo.adjust(floatsOffset); + floatsOffset += paramInfo.getCount(); + } else if (elementType == Declaration.Type.INTEGER) { + System.arraycopy(integers, paramInfo.getOffset(), + uniformIntegers, integersOffset, + paramInfo.getCount()); + paramInfo.adjust(integersOffset); + integersOffset += paramInfo.getCount(); + } else { + System.arraycopy(strings, paramInfo.getOffset(), + uniformStrings, stringsOffset, + paramInfo.getCount()); + paramInfo.adjust(stringsOffset); + stringsOffset += paramInfo.getCount(); + } + uniformParamsInfo[index++] = paramInfo; + } + } + ParamInfo[] varyingParamsInfo = null; + float[][] varyingFloats = null; + floatsOffset = 0; + if (varyingParams.size() > 0) { + varyingParamsInfo = new ParamInfo[varyingParams.size()]; + ParamInfo pi = varyingParams.get(0); + int numArrays = + pi.getCount() / pi.getDeclaration().getElementCount(); + varyingFloats = new float[numArrays][]; + floatParamsCount = 0; + for (ParamInfo paramInfo: varyingParams) + floatParamsCount += paramInfo.getCount() / numArrays; + for (int i = 0; i < numArrays; i++) + varyingFloats[i] = new float[floatParamsCount]; + int index = 0; + for (ParamInfo paramInfo: varyingParams) { + int offset = paramInfo.getOffset(); + int count = paramInfo.getCount() / numArrays; + for (int i = 0; i < numArrays; i++) { + System.arraycopy(floats, offset, + varyingFloats[i], floatsOffset, + count); + offset += count; + } + paramInfo.adjust(floatsOffset, count); + varyingParamsInfo[index++] = paramInfo; + floatsOffset += count; + } + } + ParamInfo[] vertexParamsInfo = null; + float[][] vertexFloats = null; + floatsOffset = 0; + if (vertexParams.size() > 0) { + vertexParamsInfo = new ParamInfo[vertexParams.size()]; + ParamInfo pi = vertexParams.get(0); + int numArrays = + pi.getCount() / pi.getDeclaration().getElementCount(); + vertexFloats = new float[numArrays][]; + floatParamsCount = 0; + for (ParamInfo paramInfo: vertexParams) + floatParamsCount += paramInfo.getCount() / numArrays; + for (int i = 0; i < numArrays; i++) + vertexFloats[i] = new float[floatParamsCount]; + int index = 0; + for (ParamInfo paramInfo: vertexParams) { + int offset = paramInfo.getOffset(); + int count = paramInfo.getCount() / numArrays; + for (int i = 0; i < numArrays; i++) { + System.arraycopy(floats, offset, + vertexFloats[i], floatsOffset, + count); + offset += count; + } + paramInfo.adjust(floatsOffset, count); + vertexParamsInfo[index++] = paramInfo; + floatsOffset += count; + } + } + return new Parameters(constantParamsInfo, constantFloats, + constantIntegers, constantStrings, + uniformParamsInfo, uniformFloats, + uniformIntegers, uniformStrings, + varyingParamsInfo, varyingFloats, + vertexParamsInfo, vertexFloats); + } + } |