| 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) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 287 | rs.validate(); |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 288 | Field[] fields = c.getFields(); |
| 289 | Builder b = new Builder(rs); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 290 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 291 | for(Field f: fields) { |
| 292 | Class fc = f.getType(); |
| 293 | if(fc == int.class) { |
| 294 | b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName()); |
| 295 | } else if(fc == short.class) { |
| 296 | b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName()); |
| 297 | } else if(fc == byte.class) { |
| 298 | b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName()); |
| 299 | } else if(fc == float.class) { |
| 300 | b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName()); |
| 301 | } else { |
| 302 | throw new IllegalArgumentException("Unkown field type"); |
| 303 | } |
| 304 | } |
| 305 | return b.create(); |
| 306 | } |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 307 | |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 308 | static synchronized void internalCreate(RenderScript rs, Element e) { |
| 309 | rs.nElementBegin(); |
| 310 | int bits = 0; |
| 311 | for (int ct=0; ct < e.mEntries.length; ct++) { |
| 312 | Entry en = e.mEntries[ct]; |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 313 | //if(en.mElement != null) { |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 314 | //rs.nElementAdd(en.mElement.mID); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 315 | //} else |
| 316 | { |
| 317 | 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] | 318 | bits += en.mBits; |
| 319 | } |
| 320 | } |
| 321 | e.mID = rs.nElementCreate(); |
| 322 | e.mSize = (bits + 7) >> 3; |
| 323 | } |
| 324 | |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 325 | void init() { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 326 | mRS.validate(); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 327 | internalCreate(mRS, this); |
| 328 | } |
| 329 | |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 330 | |
| 331 | public static class Builder { |
| 332 | RenderScript mRS; |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 333 | Entry[] mEntries; |
| 334 | int mEntryCount; |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 335 | |
| 336 | public Builder(RenderScript rs) { |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 337 | mRS = rs; |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 338 | mEntryCount = 0; |
| 339 | mEntries = new Entry[8]; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 342 | void addEntry(Entry e) { |
| 343 | if(mEntries.length >= mEntryCount) { |
| 344 | Entry[] en = new Entry[mEntryCount + 8]; |
| Romain Guy | 81e4640 | 2009-08-14 18:58:33 -0700 | [diff] [blame] | 345 | System.arraycopy(mEntries, 0, en, 0, mEntries.length); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 346 | mEntries = en; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 347 | } |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 348 | mEntries[mEntryCount] = e; |
| 349 | mEntryCount++; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 352 | //public Builder add(Element e) throws IllegalArgumentException { |
| 353 | //Entry en = new Entry(e, e.mSize * 8); |
| 354 | //addEntry(en); |
| 355 | //return this; |
| 356 | //} |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 357 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 358 | 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] | 359 | Entry en = new Entry(dt, dk, isNormalized, bits, name); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 360 | addEntry(en); |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 361 | return this; |
| 362 | } |
| 363 | |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 364 | public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) { |
| 365 | add(dt, dk, isNormalized, bits, null); |
| 366 | return this; |
| 367 | } |
| 368 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 369 | public Builder addFloat(Element.DataKind dk) { |
| 370 | add(DataType.FLOAT, dk, false, 32, null); |
| 371 | return this; |
| 372 | } |
| 373 | |
| 374 | public Builder addFloat(Element.DataKind dk, String name) { |
| 375 | add(DataType.FLOAT, dk, false, 32, name); |
| 376 | return this; |
| 377 | } |
| 378 | |
| 379 | public Builder addFloatXY() { |
| 380 | add(DataType.FLOAT, DataKind.X, false, 32, null); |
| 381 | add(DataType.FLOAT, DataKind.Y, false, 32, null); |
| 382 | return this; |
| 383 | } |
| 384 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 385 | public Builder addFloatXY(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 386 | add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x"); |
| 387 | add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 388 | return this; |
| 389 | } |
| 390 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 391 | public Builder addFloatXYZ() { |
| 392 | add(DataType.FLOAT, DataKind.X, false, 32, null); |
| 393 | add(DataType.FLOAT, DataKind.Y, false, 32, null); |
| 394 | add(DataType.FLOAT, DataKind.Z, false, 32, null); |
| 395 | return this; |
| 396 | } |
| Jason Sams | 25ffcdc | 2009-08-20 16:10:36 -0700 | [diff] [blame] | 397 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 398 | public Builder addFloatXYZ(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 399 | add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x"); |
| 400 | add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y"); |
| 401 | add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "z"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 402 | return this; |
| 403 | } |
| 404 | |
| Romain Guy | 4f7136c | 2009-08-17 19:59:27 -0700 | [diff] [blame] | 405 | public Builder addFloatST() { |
| 406 | add(DataType.FLOAT, DataKind.S, false, 32, null); |
| 407 | add(DataType.FLOAT, DataKind.T, false, 32, null); |
| 408 | return this; |
| 409 | } |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 410 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 411 | public Builder addFloatST(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 412 | add(DataType.FLOAT, DataKind.S, false, 32, prefix + "s"); |
| 413 | add(DataType.FLOAT, DataKind.T, false, 32, prefix + "t"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 414 | return this; |
| 415 | } |
| 416 | |
| 417 | public Builder addFloatNorm() { |
| 418 | add(DataType.FLOAT, DataKind.NX, false, 32, null); |
| 419 | add(DataType.FLOAT, DataKind.NY, false, 32, null); |
| 420 | add(DataType.FLOAT, DataKind.NZ, false, 32, null); |
| 421 | return this; |
| 422 | } |
| 423 | |
| 424 | public Builder addFloatNorm(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 425 | add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "nx"); |
| 426 | add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "ny"); |
| 427 | add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "nz"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 428 | return this; |
| 429 | } |
| 430 | |
| Jason Sams | 25ffcdc | 2009-08-20 16:10:36 -0700 | [diff] [blame] | 431 | public Builder addFloatPointSize() { |
| 432 | add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, null); |
| 433 | return this; |
| 434 | } |
| 435 | |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 436 | public Builder addFloatPointSize(String prefix) { |
| 437 | add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 438 | return this; |
| 439 | } |
| 440 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 441 | public Builder addFloatRGB() { |
| 442 | add(DataType.FLOAT, DataKind.RED, false, 32, null); |
| 443 | add(DataType.FLOAT, DataKind.GREEN, false, 32, null); |
| 444 | add(DataType.FLOAT, DataKind.BLUE, false, 32, null); |
| 445 | return this; |
| 446 | } |
| 447 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 448 | public Builder addFloatRGB(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 449 | add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r"); |
| 450 | add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g"); |
| 451 | add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 452 | return this; |
| 453 | } |
| 454 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 455 | public Builder addFloatRGBA() { |
| 456 | add(DataType.FLOAT, DataKind.RED, false, 32, null); |
| 457 | add(DataType.FLOAT, DataKind.GREEN, false, 32, null); |
| 458 | add(DataType.FLOAT, DataKind.BLUE, false, 32, null); |
| 459 | add(DataType.FLOAT, DataKind.ALPHA, false, 32, null); |
| 460 | return this; |
| 461 | } |
| 462 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 463 | public Builder addFloatRGBA(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 464 | add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r"); |
| 465 | add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g"); |
| 466 | add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b"); |
| 467 | add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "a"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 468 | return this; |
| 469 | } |
| 470 | |
| Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 471 | public Builder addUNorm8RGBA() { |
| 472 | add(DataType.UNSIGNED, DataKind.RED, true, 8, null); |
| 473 | add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null); |
| 474 | add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null); |
| 475 | add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null); |
| 476 | return this; |
| 477 | } |
| 478 | |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 479 | public Builder addUNorm8RGBA(String prefix) { |
| Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 480 | add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "r"); |
| 481 | add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "g"); |
| 482 | add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "b"); |
| 483 | add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "a"); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 484 | return this; |
| 485 | } |
| 486 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 487 | public Element create() { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 488 | mRS.validate(); |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 489 | Element e = new Element(mRS, mEntryCount); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 490 | java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount); |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 491 | e.init(); |
| Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 492 | return e; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | } |
| 497 | |