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