| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.renderscript; |
| 18 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 19 | import java.lang.reflect.Field; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * @hide |
| 23 | * |
| 24 | **/ |
| 25 | public class Element extends BaseObj { |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 26 | int mSize; |
| 27 | Entry[] mEntries; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 28 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 29 | static class Entry { |
| 30 | Element mElement; |
| 31 | Element.DataType mType; |
| 32 | Element.DataKind mKind; |
| 33 | boolean mIsNormalized; |
| 34 | int mBits; |
| 35 | String mName; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 36 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 37 | Entry(Element e, int bits) { |
| 38 | mElement = e; |
| 39 | int mBits = bits; |
| 40 | } |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 41 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 42 | Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) { |
| 43 | mType = dt; |
| 44 | mKind = dk; |
| 45 | mIsNormalized = isNorm; |
| 46 | mBits = bits; |
| 47 | mName = name; |
| 48 | } |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 51 | public static final Element USER_U8 = new Element(); |
| 52 | public static final Element USER_I8 = new Element(); |
| 53 | public static final Element USER_U16 = new Element(); |
| 54 | public static final Element USER_I16 = new Element(); |
| 55 | public static final Element USER_U32 = new Element(); |
| 56 | public static final Element USER_I32 = new Element(); |
| 57 | public static final Element USER_FLOAT = new Element(); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 58 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 59 | public static final Element A_8 = new Element(); |
| 60 | public static final Element RGB_565 = new Element(); |
| 61 | public static final Element RGB_888 = new Element(); |
| 62 | public static final Element RGBA_5551 = new Element(); |
| 63 | public static final Element RGBA_4444 = new Element(); |
| 64 | public static final Element RGBA_8888 = new Element(); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 65 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 66 | public static final Element INDEX_16 = new Element(); |
| 67 | public static final Element XY_F32 = new Element(); |
| 68 | public static final Element XYZ_F32 = new Element(); |
| 69 | public static final Element ST_XY_F32 = new Element(); |
| 70 | public static final Element ST_XYZ_F32 = new Element(); |
| 71 | public static final Element NORM_XYZ_F32 = new Element(); |
| 72 | public static final Element NORM_ST_XYZ_F32 = new Element(); |
| 73 | |
| 74 | static void initPredefined(RenderScript rs) { |
| 75 | USER_U8.mEntries = new Entry[1]; |
| 76 | USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null); |
| 77 | USER_U8.init(rs); |
| 78 | |
| 79 | USER_I8.mEntries = new Entry[1]; |
| 80 | USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null); |
| 81 | USER_I8.init(rs); |
| 82 | |
| 83 | USER_U16.mEntries = new Entry[1]; |
| 84 | USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null); |
| 85 | USER_U16.init(rs); |
| 86 | |
| 87 | USER_I16.mEntries = new Entry[1]; |
| 88 | USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null); |
| 89 | USER_I16.init(rs); |
| 90 | |
| 91 | USER_U32.mEntries = new Entry[1]; |
| 92 | USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null); |
| 93 | USER_U32.init(rs); |
| 94 | |
| 95 | USER_I32.mEntries = new Entry[1]; |
| 96 | USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null); |
| 97 | USER_I32.init(rs); |
| 98 | |
| 99 | USER_FLOAT.mEntries = new Entry[1]; |
| 100 | USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null); |
| 101 | USER_FLOAT.init(rs); |
| 102 | |
| 103 | A_8.mEntries = new Entry[1]; |
| 104 | A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a"); |
| 105 | A_8.init(rs); |
| 106 | |
| 107 | RGB_565.mEntries = new Entry[3]; |
| 108 | RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r"); |
| 109 | RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g"); |
| 110 | RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b"); |
| 111 | RGB_565.init(rs); |
| 112 | |
| 113 | RGB_888.mEntries = new Entry[3]; |
| 114 | RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r"); |
| 115 | RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g"); |
| 116 | RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b"); |
| 117 | RGB_888.init(rs); |
| 118 | |
| 119 | RGBA_5551.mEntries = new Entry[4]; |
| 120 | RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r"); |
| 121 | RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g"); |
| 122 | RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b"); |
| 123 | RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a"); |
| 124 | RGBA_5551.init(rs); |
| 125 | |
| 126 | RGBA_4444.mEntries = new Entry[4]; |
| 127 | RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r"); |
| 128 | RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g"); |
| 129 | RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b"); |
| 130 | RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a"); |
| 131 | RGBA_4444.init(rs); |
| 132 | |
| 133 | RGBA_8888.mEntries = new Entry[4]; |
| 134 | RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r"); |
| 135 | RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g"); |
| 136 | RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b"); |
| 137 | RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a"); |
| 138 | RGBA_8888.init(rs); |
| 139 | |
| 140 | INDEX_16.mEntries = new Entry[1]; |
| 141 | INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index"); |
| 142 | INDEX_16.init(rs); |
| 143 | |
| 144 | XY_F32.mEntries = new Entry[2]; |
| 145 | XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x"); |
| 146 | XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y"); |
| 147 | XY_F32.init(rs); |
| 148 | |
| 149 | XYZ_F32.mEntries = new Entry[3]; |
| 150 | XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x"); |
| 151 | XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y"); |
| 152 | XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z"); |
| 153 | XYZ_F32.init(rs); |
| 154 | |
| 155 | ST_XY_F32.mEntries = new Entry[4]; |
| 156 | ST_XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s"); |
| 157 | ST_XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t"); |
| 158 | ST_XY_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x"); |
| 159 | ST_XY_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y"); |
| 160 | ST_XY_F32.init(rs); |
| 161 | |
| 162 | ST_XYZ_F32.mEntries = new Entry[5]; |
| 163 | ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s"); |
| 164 | ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t"); |
| 165 | ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x"); |
| 166 | ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y"); |
| 167 | ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z"); |
| 168 | ST_XYZ_F32.init(rs); |
| 169 | |
| 170 | NORM_XYZ_F32.mEntries = new Entry[6]; |
| 171 | NORM_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx"); |
| 172 | NORM_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny"); |
| 173 | NORM_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz"); |
| 174 | NORM_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x"); |
| 175 | NORM_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y"); |
| 176 | NORM_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z"); |
| 177 | NORM_XYZ_F32.init(rs); |
| 178 | |
| 179 | NORM_ST_XYZ_F32.mEntries = new Entry[8]; |
| 180 | NORM_ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx"); |
| 181 | NORM_ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny"); |
| 182 | NORM_ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz"); |
| 183 | NORM_ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s"); |
| 184 | NORM_ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t"); |
| 185 | NORM_ST_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x"); |
| 186 | NORM_ST_XYZ_F32.mEntries[6] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y"); |
| 187 | NORM_ST_XYZ_F32.mEntries[7] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z"); |
| 188 | NORM_ST_XYZ_F32.init(rs); |
| 189 | |
| 190 | rs.nInitElements(A_8.mID, RGBA_4444.mID, RGBA_8888.mID, RGB_565.mID); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
| 194 | public enum DataType { |
| 195 | FLOAT (0), |
| 196 | UNSIGNED (1), |
| 197 | SIGNED (2); |
| 198 | |
| 199 | int mID; |
| 200 | DataType(int id) { |
| 201 | mID = id; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | public enum DataKind { |
| 206 | USER (0), |
| 207 | RED (1), |
| 208 | GREEN (2), |
| 209 | BLUE (3), |
| 210 | ALPHA (4), |
| 211 | LUMINANCE (5), |
| 212 | INTENSITY (6), |
| 213 | X (7), |
| 214 | Y (8), |
| 215 | Z (9), |
| 216 | W (10), |
| 217 | S (11), |
| 218 | T (12), |
| 219 | Q (13), |
| 220 | R (14), |
| 221 | NX (15), |
| 222 | NY (16), |
| 223 | NZ (17), |
| Jason Sams | 25ffcdc | 2009-08-20 16:10:36 -0700 | [diff] [blame] | 224 | INDEX (18), |
| 225 | POINT_SIZE(19); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 226 | |
| 227 | int mID; |
| 228 | DataKind(int id) { |
| 229 | mID = id; |
| 230 | } |
| 231 | } |
| 232 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 233 | Element() { |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 234 | super(null); |
| 235 | mID = 0; |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 236 | mSize = 0; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | public void destroy() throws IllegalStateException { |
| Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 240 | super.destroy(); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 243 | public static Element createFromClass(RenderScript rs, Class c) { |
| 244 | Field[] fields = c.getFields(); |
| 245 | Builder b = new Builder(rs); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 246 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 247 | for(Field f: fields) { |
| 248 | Class fc = f.getType(); |
| 249 | if(fc == int.class) { |
| 250 | b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName()); |
| 251 | } else if(fc == short.class) { |
| 252 | b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName()); |
| 253 | } else if(fc == byte.class) { |
| 254 | b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName()); |
| 255 | } else if(fc == float.class) { |
| 256 | b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName()); |
| 257 | } else { |
| 258 | throw new IllegalArgumentException("Unkown field type"); |
| 259 | } |
| 260 | } |
| 261 | return b.create(); |
| 262 | } |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 263 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 264 | static synchronized void internalCreate(RenderScript rs, Element e) { |
| 265 | rs.nElementBegin(); |
| 266 | int bits = 0; |
| 267 | for (int ct=0; ct < e.mEntries.length; ct++) { |
| 268 | Entry en = e.mEntries[ct]; |
| 269 | if(en.mElement != null) { |
| 270 | //rs.nElementAdd(en.mElement.mID); |
| 271 | } else { |
| 272 | int norm = 0; |
| 273 | if (en.mIsNormalized) { |
| 274 | norm = 1; |
| 275 | } |
| 276 | rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName); |
| 277 | bits += en.mBits; |
| 278 | } |
| 279 | } |
| 280 | e.mID = rs.nElementCreate(); |
| 281 | e.mSize = (bits + 7) >> 3; |
| 282 | } |
| 283 | |
| 284 | void init(RenderScript rs) { |
| 285 | mRS = rs; |
| 286 | internalCreate(mRS, this); |
| 287 | } |
| 288 | |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 289 | |
| 290 | public static class Builder { |
| 291 | RenderScript mRS; |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 292 | Entry[] mEntries; |
| 293 | int mEntryCount; |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 294 | |
| 295 | public Builder(RenderScript rs) { |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 296 | mRS = rs; |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 297 | mEntryCount = 0; |
| 298 | mEntries = new Entry[8]; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 301 | void addEntry(Entry e) { |
| 302 | if(mEntries.length >= mEntryCount) { |
| 303 | Entry[] en = new Entry[mEntryCount + 8]; |
| Romain Guy | 81e4640 | 2009-08-14 18:58:33 -0700 | [diff] [blame] | 304 | System.arraycopy(mEntries, 0, en, 0, mEntries.length); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 305 | mEntries = en; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 306 | } |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 307 | mEntries[mEntryCount] = e; |
| 308 | mEntryCount++; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 311 | public Builder add(Element e) throws IllegalArgumentException { |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 312 | Entry en = new Entry(e, e.mSize * 8); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 313 | addEntry(en); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 314 | return this; |
| 315 | } |
| 316 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 317 | public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) { |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 318 | Entry en = new Entry(dt, dk, isNormalized, bits, name); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 319 | addEntry(en); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 320 | return this; |
| 321 | } |
| 322 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 323 | public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) { |
| 324 | add(dt, dk, isNormalized, bits, null); |
| 325 | return this; |
| 326 | } |
| 327 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 328 | public Builder addFloat(Element.DataKind dk) { |
| 329 | add(DataType.FLOAT, dk, false, 32, null); |
| 330 | return this; |
| 331 | } |
| 332 | |
| 333 | public Builder addFloat(Element.DataKind dk, String name) { |
| 334 | add(DataType.FLOAT, dk, false, 32, name); |
| 335 | return this; |
| 336 | } |
| 337 | |
| 338 | public Builder addFloatXY() { |
| 339 | add(DataType.FLOAT, DataKind.X, false, 32, null); |
| 340 | add(DataType.FLOAT, DataKind.Y, false, 32, null); |
| 341 | return this; |
| 342 | } |
| 343 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 344 | public Builder addFloatXY(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 345 | add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x"); |
| 346 | add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 347 | return this; |
| 348 | } |
| 349 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 350 | public Builder addFloatXYZ() { |
| 351 | add(DataType.FLOAT, DataKind.X, false, 32, null); |
| 352 | add(DataType.FLOAT, DataKind.Y, false, 32, null); |
| 353 | add(DataType.FLOAT, DataKind.Z, false, 32, null); |
| 354 | return this; |
| 355 | } |
| Jason Sams | 25ffcdc | 2009-08-20 16:10:36 -0700 | [diff] [blame] | 356 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 357 | public Builder addFloatXYZ(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 358 | add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x"); |
| 359 | add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y"); |
| 360 | add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "z"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 361 | return this; |
| 362 | } |
| 363 | |
| Romain Guy | 4f7136c | 2009-08-17 19:59:27 -0700 | [diff] [blame] | 364 | public Builder addFloatST() { |
| 365 | add(DataType.FLOAT, DataKind.S, false, 32, null); |
| 366 | add(DataType.FLOAT, DataKind.T, false, 32, null); |
| 367 | return this; |
| 368 | } |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 369 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 370 | public Builder addFloatST(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 371 | add(DataType.FLOAT, DataKind.S, false, 32, prefix + "s"); |
| 372 | add(DataType.FLOAT, DataKind.T, false, 32, prefix + "t"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 373 | return this; |
| 374 | } |
| 375 | |
| 376 | public Builder addFloatNorm() { |
| 377 | add(DataType.FLOAT, DataKind.NX, false, 32, null); |
| 378 | add(DataType.FLOAT, DataKind.NY, false, 32, null); |
| 379 | add(DataType.FLOAT, DataKind.NZ, false, 32, null); |
| 380 | return this; |
| 381 | } |
| 382 | |
| 383 | public Builder addFloatNorm(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 384 | add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "nx"); |
| 385 | add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "ny"); |
| 386 | add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "nz"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 387 | return this; |
| 388 | } |
| 389 | |
| Jason Sams | 25ffcdc | 2009-08-20 16:10:36 -0700 | [diff] [blame] | 390 | public Builder addFloatPointSize() { |
| 391 | add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, null); |
| 392 | return this; |
| 393 | } |
| 394 | |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 395 | public Builder addFloatPointSize(String prefix) { |
| 396 | add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 397 | return this; |
| 398 | } |
| 399 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 400 | public Builder addFloatRGB() { |
| 401 | add(DataType.FLOAT, DataKind.RED, false, 32, null); |
| 402 | add(DataType.FLOAT, DataKind.GREEN, false, 32, null); |
| 403 | add(DataType.FLOAT, DataKind.BLUE, false, 32, null); |
| 404 | return this; |
| 405 | } |
| 406 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 407 | public Builder addFloatRGB(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 408 | add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r"); |
| 409 | add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g"); |
| 410 | add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 411 | return this; |
| 412 | } |
| 413 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 414 | public Builder addFloatRGBA() { |
| 415 | add(DataType.FLOAT, DataKind.RED, false, 32, null); |
| 416 | add(DataType.FLOAT, DataKind.GREEN, false, 32, null); |
| 417 | add(DataType.FLOAT, DataKind.BLUE, false, 32, null); |
| 418 | add(DataType.FLOAT, DataKind.ALPHA, false, 32, null); |
| 419 | return this; |
| 420 | } |
| 421 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 422 | public Builder addFloatRGBA(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 423 | add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r"); |
| 424 | add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g"); |
| 425 | add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b"); |
| 426 | add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "a"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 427 | return this; |
| 428 | } |
| 429 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 430 | public Builder addUNorm8RGBA() { |
| 431 | add(DataType.UNSIGNED, DataKind.RED, true, 8, null); |
| 432 | add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null); |
| 433 | add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null); |
| 434 | add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null); |
| 435 | return this; |
| 436 | } |
| 437 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 438 | public Builder addUNorm8RGBA(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 439 | add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "r"); |
| 440 | add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "g"); |
| 441 | add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "b"); |
| 442 | add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "a"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 443 | return this; |
| 444 | } |
| 445 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 446 | public Element create() { |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 447 | Element e = new Element(); |
| 448 | e.mEntries = new Entry[mEntryCount]; |
| 449 | java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount); |
| 450 | e.init(mRS); |
| 451 | return e; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
| 455 | } |
| 456 | |