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