| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import com.google.common.primitives.Floats;
|
| 4 | import java.nio.ByteBuffer;
|
| 5 | import java.nio.ByteOrder;
|
| 6 | import java.nio.FloatBuffer;
|
| 7 | import java.nio.IntBuffer;
|
| 8 | import java.nio.ShortBuffer;
|
| 9 | import java.util.Arrays;
|
| 10 | import java.util.BitSet;
|
| 11 | import java.util.Comparator;
|
| 12 | import net.minecraft.client.renderer.vertex.VertexFormat;
|
| 13 | import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
| 14 | import net.minecraft.util.MathHelper;
|
| 15 | import org.apache.logging.log4j.LogManager;
|
| 16 |
|
| 17 | public class WorldRenderer
|
| 18 | {
|
| 19 | private ByteBuffer byteBuffer;
|
| 20 | private IntBuffer rawIntBuffer;
|
| 21 | private ShortBuffer rawShortBuffer;
|
| 22 | private FloatBuffer rawFloatBuffer;
|
| 23 | private int vertexCount;
|
| 24 | private VertexFormatElement vertexFormatElement;
|
| 25 | private int vertexFormatIndex;
|
| 26 |
|
| 27 | /** None */
|
| 28 | private boolean noColor;
|
| 29 | private int drawMode;
|
| 30 | private double xOffset;
|
| 31 | private double yOffset;
|
| 32 | private double zOffset;
|
| 33 | private VertexFormat vertexFormat;
|
| 34 | private boolean isDrawing;
|
| 35 |
|
| 36 | public WorldRenderer(int bufferSizeIn)
|
| 37 | {
|
| 38 | this.byteBuffer = GLAllocation.createDirectByteBuffer(bufferSizeIn * 4);
|
| 39 | this.rawIntBuffer = this.byteBuffer.asIntBuffer();
|
| 40 | this.rawShortBuffer = this.byteBuffer.asShortBuffer();
|
| 41 | this.rawFloatBuffer = this.byteBuffer.asFloatBuffer();
|
| 42 | }
|
| 43 |
|
| 44 | private void growBuffer(int p_181670_1_)
|
| 45 | {
|
| 46 | if (p_181670_1_ > this.rawIntBuffer.remaining())
|
| 47 | {
|
| 48 | int i = this.byteBuffer.capacity();
|
| 49 | int j = i % 2097152;
|
| 50 | int k = j + (((this.rawIntBuffer.position() + p_181670_1_) * 4 - j) / 2097152 + 1) * 2097152;
|
| 51 | LogManager.getLogger().warn("Needed to grow BufferBuilder buffer: Old size " + i + " bytes, new size " + k + " bytes.");
|
| 52 | int l = this.rawIntBuffer.position();
|
| 53 | ByteBuffer bytebuffer = GLAllocation.createDirectByteBuffer(k);
|
| 54 | this.byteBuffer.position(0);
|
| 55 | bytebuffer.put(this.byteBuffer);
|
| 56 | bytebuffer.rewind();
|
| 57 | this.byteBuffer = bytebuffer;
|
| 58 | this.rawFloatBuffer = this.byteBuffer.asFloatBuffer().asReadOnlyBuffer();
|
| 59 | this.rawIntBuffer = this.byteBuffer.asIntBuffer();
|
| 60 | this.rawIntBuffer.position(l);
|
| 61 | this.rawShortBuffer = this.byteBuffer.asShortBuffer();
|
| 62 | this.rawShortBuffer.position(l << 1);
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | public void sortVertexData(float p_181674_1_, float p_181674_2_, float p_181674_3_)
|
| 67 | {
|
| 68 | int i = this.vertexCount / 4;
|
| 69 | final float[] afloat = new float[i];
|
| 70 |
|
| 71 | for (int j = 0; j < i; ++j)
|
| 72 | {
|
| 73 | afloat[j] = getDistanceSq(this.rawFloatBuffer, (float)((double)p_181674_1_ + this.xOffset), (float)((double)p_181674_2_ + this.yOffset), (float)((double)p_181674_3_ + this.zOffset), this.vertexFormat.getIntegerSize(), j * this.vertexFormat.getNextOffset());
|
| 74 | }
|
| 75 |
|
| 76 | Integer[] ainteger = new Integer[i];
|
| 77 |
|
| 78 | for (int k = 0; k < ainteger.length; ++k)
|
| 79 | {
|
| 80 | ainteger[k] = Integer.valueOf(k);
|
| 81 | }
|
| 82 |
|
| 83 | Arrays.sort(ainteger, new Comparator<Integer>()
|
| 84 | {
|
| 85 | public int compare(Integer p_compare_1_, Integer p_compare_2_)
|
| 86 | {
|
| 87 | return Floats.compare(afloat[p_compare_2_.intValue()], afloat[p_compare_1_.intValue()]);
|
| 88 | }
|
| 89 | });
|
| 90 | BitSet bitset = new BitSet();
|
| 91 | int l = this.vertexFormat.getNextOffset();
|
| 92 | int[] aint = new int[l];
|
| 93 |
|
| 94 | for (int l1 = 0; (l1 = bitset.nextClearBit(l1)) < ainteger.length; ++l1)
|
| 95 | {
|
| 96 | int i1 = ainteger[l1].intValue();
|
| 97 |
|
| 98 | if (i1 != l1)
|
| 99 | {
|
| 100 | this.rawIntBuffer.limit(i1 * l + l);
|
| 101 | this.rawIntBuffer.position(i1 * l);
|
| 102 | this.rawIntBuffer.get(aint);
|
| 103 | int j1 = i1;
|
| 104 |
|
| 105 | for (int k1 = ainteger[i1].intValue(); j1 != l1; k1 = ainteger[k1].intValue())
|
| 106 | {
|
| 107 | this.rawIntBuffer.limit(k1 * l + l);
|
| 108 | this.rawIntBuffer.position(k1 * l);
|
| 109 | IntBuffer intbuffer = this.rawIntBuffer.slice();
|
| 110 | this.rawIntBuffer.limit(j1 * l + l);
|
| 111 | this.rawIntBuffer.position(j1 * l);
|
| 112 | this.rawIntBuffer.put(intbuffer);
|
| 113 | bitset.set(j1);
|
| 114 | j1 = k1;
|
| 115 | }
|
| 116 |
|
| 117 | this.rawIntBuffer.limit(l1 * l + l);
|
| 118 | this.rawIntBuffer.position(l1 * l);
|
| 119 | this.rawIntBuffer.put(aint);
|
| 120 | }
|
| 121 |
|
| 122 | bitset.set(l1);
|
| 123 | }
|
| 124 | }
|
| 125 |
|
| 126 | public WorldRenderer.State getVertexState()
|
| 127 | {
|
| 128 | this.rawIntBuffer.rewind();
|
| 129 | int i = this.getBufferSize();
|
| 130 | this.rawIntBuffer.limit(i);
|
| 131 | int[] aint = new int[i];
|
| 132 | this.rawIntBuffer.get(aint);
|
| 133 | this.rawIntBuffer.limit(this.rawIntBuffer.capacity());
|
| 134 | this.rawIntBuffer.position(i);
|
| 135 | return new WorldRenderer.State(aint, new VertexFormat(this.vertexFormat));
|
| 136 | }
|
| 137 |
|
| 138 | private int getBufferSize()
|
| 139 | {
|
| 140 | return this.vertexCount * this.vertexFormat.getIntegerSize();
|
| 141 | }
|
| 142 |
|
| 143 | private static float getDistanceSq(FloatBuffer p_181665_0_, float p_181665_1_, float p_181665_2_, float p_181665_3_, int p_181665_4_, int p_181665_5_)
|
| 144 | {
|
| 145 | float f = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 0 + 0);
|
| 146 | float f1 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 0 + 1);
|
| 147 | float f2 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 0 + 2);
|
| 148 | float f3 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 1 + 0);
|
| 149 | float f4 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 1 + 1);
|
| 150 | float f5 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 1 + 2);
|
| 151 | float f6 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 2 + 0);
|
| 152 | float f7 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 2 + 1);
|
| 153 | float f8 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 2 + 2);
|
| 154 | float f9 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 3 + 0);
|
| 155 | float f10 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 3 + 1);
|
| 156 | float f11 = p_181665_0_.get(p_181665_5_ + p_181665_4_ * 3 + 2);
|
| 157 | float f12 = (f + f3 + f6 + f9) * 0.25F - p_181665_1_;
|
| 158 | float f13 = (f1 + f4 + f7 + f10) * 0.25F - p_181665_2_;
|
| 159 | float f14 = (f2 + f5 + f8 + f11) * 0.25F - p_181665_3_;
|
| 160 | return f12 * f12 + f13 * f13 + f14 * f14;
|
| 161 | }
|
| 162 |
|
| 163 | public void setVertexState(WorldRenderer.State state)
|
| 164 | {
|
| 165 | this.rawIntBuffer.clear();
|
| 166 | this.growBuffer(state.getRawBuffer().length);
|
| 167 | this.rawIntBuffer.put(state.getRawBuffer());
|
| 168 | this.vertexCount = state.getVertexCount();
|
| 169 | this.vertexFormat = new VertexFormat(state.getVertexFormat());
|
| 170 | }
|
| 171 |
|
| 172 | public void reset()
|
| 173 | {
|
| 174 | this.vertexCount = 0;
|
| 175 | this.vertexFormatElement = null;
|
| 176 | this.vertexFormatIndex = 0;
|
| 177 | }
|
| 178 |
|
| 179 | public void begin(int glMode, VertexFormat format)
|
| 180 | {
|
| 181 | if (this.isDrawing)
|
| 182 | {
|
| 183 | throw new IllegalStateException("Already building!");
|
| 184 | }
|
| 185 | else
|
| 186 | {
|
| 187 | this.isDrawing = true;
|
| 188 | this.reset();
|
| 189 | this.drawMode = glMode;
|
| 190 | this.vertexFormat = format;
|
| 191 | this.vertexFormatElement = format.getElement(this.vertexFormatIndex);
|
| 192 | this.noColor = false;
|
| 193 | this.byteBuffer.limit(this.byteBuffer.capacity());
|
| 194 | }
|
| 195 | }
|
| 196 |
|
| 197 | public WorldRenderer tex(double u, double v)
|
| 198 | {
|
| 199 | int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
|
| 200 |
|
| 201 | switch (this.vertexFormatElement.getType())
|
| 202 | {
|
| 203 | case FLOAT:
|
| 204 | this.byteBuffer.putFloat(i, (float)u);
|
| 205 | this.byteBuffer.putFloat(i + 4, (float)v);
|
| 206 | break;
|
| 207 |
|
| 208 | case UINT:
|
| 209 | case INT:
|
| 210 | this.byteBuffer.putInt(i, (int)u);
|
| 211 | this.byteBuffer.putInt(i + 4, (int)v);
|
| 212 | break;
|
| 213 |
|
| 214 | case USHORT:
|
| 215 | case SHORT:
|
| 216 | this.byteBuffer.putShort(i, (short)((int)v));
|
| 217 | this.byteBuffer.putShort(i + 2, (short)((int)u));
|
| 218 | break;
|
| 219 |
|
| 220 | case UBYTE:
|
| 221 | case BYTE:
|
| 222 | this.byteBuffer.put(i, (byte)((int)v));
|
| 223 | this.byteBuffer.put(i + 1, (byte)((int)u));
|
| 224 | }
|
| 225 |
|
| 226 | this.nextVertexFormatIndex();
|
| 227 | return this;
|
| 228 | }
|
| 229 |
|
| 230 | public WorldRenderer lightmap(int p_181671_1_, int p_181671_2_)
|
| 231 | {
|
| 232 | int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
|
| 233 |
|
| 234 | switch (this.vertexFormatElement.getType())
|
| 235 | {
|
| 236 | case FLOAT:
|
| 237 | this.byteBuffer.putFloat(i, (float)p_181671_1_);
|
| 238 | this.byteBuffer.putFloat(i + 4, (float)p_181671_2_);
|
| 239 | break;
|
| 240 |
|
| 241 | case UINT:
|
| 242 | case INT:
|
| 243 | this.byteBuffer.putInt(i, p_181671_1_);
|
| 244 | this.byteBuffer.putInt(i + 4, p_181671_2_);
|
| 245 | break;
|
| 246 |
|
| 247 | case USHORT:
|
| 248 | case SHORT:
|
| 249 | this.byteBuffer.putShort(i, (short)p_181671_2_);
|
| 250 | this.byteBuffer.putShort(i + 2, (short)p_181671_1_);
|
| 251 | break;
|
| 252 |
|
| 253 | case UBYTE:
|
| 254 | case BYTE:
|
| 255 | this.byteBuffer.put(i, (byte)p_181671_2_);
|
| 256 | this.byteBuffer.put(i + 1, (byte)p_181671_1_);
|
| 257 | }
|
| 258 |
|
| 259 | this.nextVertexFormatIndex();
|
| 260 | return this;
|
| 261 | }
|
| 262 |
|
| 263 | public void putBrightness4(int p_178962_1_, int p_178962_2_, int p_178962_3_, int p_178962_4_)
|
| 264 | {
|
| 265 | int i = (this.vertexCount - 4) * this.vertexFormat.getIntegerSize() + this.vertexFormat.getUvOffsetById(1) / 4;
|
| 266 | int j = this.vertexFormat.getNextOffset() >> 2;
|
| 267 | this.rawIntBuffer.put(i, p_178962_1_);
|
| 268 | this.rawIntBuffer.put(i + j, p_178962_2_);
|
| 269 | this.rawIntBuffer.put(i + j * 2, p_178962_3_);
|
| 270 | this.rawIntBuffer.put(i + j * 3, p_178962_4_);
|
| 271 | }
|
| 272 |
|
| 273 | public void putPosition(double x, double y, double z)
|
| 274 | {
|
| 275 | int i = this.vertexFormat.getIntegerSize();
|
| 276 | int j = (this.vertexCount - 4) * i;
|
| 277 |
|
| 278 | for (int k = 0; k < 4; ++k)
|
| 279 | {
|
| 280 | int l = j + k * i;
|
| 281 | int i1 = l + 1;
|
| 282 | int j1 = i1 + 1;
|
| 283 | this.rawIntBuffer.put(l, Float.floatToRawIntBits((float)(x + this.xOffset) + Float.intBitsToFloat(this.rawIntBuffer.get(l))));
|
| 284 | this.rawIntBuffer.put(i1, Float.floatToRawIntBits((float)(y + this.yOffset) + Float.intBitsToFloat(this.rawIntBuffer.get(i1))));
|
| 285 | this.rawIntBuffer.put(j1, Float.floatToRawIntBits((float)(z + this.zOffset) + Float.intBitsToFloat(this.rawIntBuffer.get(j1))));
|
| 286 | }
|
| 287 | }
|
| 288 |
|
| 289 | /**
|
| 290 | * Takes in the pass the call list is being requested for. Args: renderPass
|
| 291 | */
|
| 292 | private int getColorIndex(int p_78909_1_)
|
| 293 | {
|
| 294 | return ((this.vertexCount - p_78909_1_) * this.vertexFormat.getNextOffset() + this.vertexFormat.getColorOffset()) / 4;
|
| 295 | }
|
| 296 |
|
| 297 | public void putColorMultiplier(float red, float green, float blue, int p_178978_4_)
|
| 298 | {
|
| 299 | int i = this.getColorIndex(p_178978_4_);
|
| 300 | int j = -1;
|
| 301 |
|
| 302 | if (!this.noColor)
|
| 303 | {
|
| 304 | j = this.rawIntBuffer.get(i);
|
| 305 |
|
| 306 | if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN)
|
| 307 | {
|
| 308 | int k = (int)((float)(j & 255) * red);
|
| 309 | int l = (int)((float)(j >> 8 & 255) * green);
|
| 310 | int i1 = (int)((float)(j >> 16 & 255) * blue);
|
| 311 | j = j & -16777216;
|
| 312 | j = j | i1 << 16 | l << 8 | k;
|
| 313 | }
|
| 314 | else
|
| 315 | {
|
| 316 | int j1 = (int)((float)(j >> 24 & 255) * red);
|
| 317 | int k1 = (int)((float)(j >> 16 & 255) * green);
|
| 318 | int l1 = (int)((float)(j >> 8 & 255) * blue);
|
| 319 | j = j & 255;
|
| 320 | j = j | j1 << 24 | k1 << 16 | l1 << 8;
|
| 321 | }
|
| 322 | }
|
| 323 |
|
| 324 | this.rawIntBuffer.put(i, j);
|
| 325 | }
|
| 326 |
|
| 327 | private void putColor(int argb, int p_178988_2_)
|
| 328 | {
|
| 329 | int i = this.getColorIndex(p_178988_2_);
|
| 330 | int j = argb >> 16 & 255;
|
| 331 | int k = argb >> 8 & 255;
|
| 332 | int l = argb & 255;
|
| 333 | int i1 = argb >> 24 & 255;
|
| 334 | this.putColorRGBA(i, j, k, l, i1);
|
| 335 | }
|
| 336 |
|
| 337 | public void putColorRGB_F(float red, float green, float blue, int p_178994_4_)
|
| 338 | {
|
| 339 | int i = this.getColorIndex(p_178994_4_);
|
| 340 | int j = MathHelper.clamp_int((int)(red * 255.0F), 0, 255);
|
| 341 | int k = MathHelper.clamp_int((int)(green * 255.0F), 0, 255);
|
| 342 | int l = MathHelper.clamp_int((int)(blue * 255.0F), 0, 255);
|
| 343 | this.putColorRGBA(i, j, k, l, 255);
|
| 344 | }
|
| 345 |
|
| 346 | private void putColorRGBA(int index, int red, int p_178972_3_, int p_178972_4_, int p_178972_5_)
|
| 347 | {
|
| 348 | if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN)
|
| 349 | {
|
| 350 | this.rawIntBuffer.put(index, p_178972_5_ << 24 | p_178972_4_ << 16 | p_178972_3_ << 8 | red);
|
| 351 | }
|
| 352 | else
|
| 353 | {
|
| 354 | this.rawIntBuffer.put(index, red << 24 | p_178972_3_ << 16 | p_178972_4_ << 8 | p_178972_5_);
|
| 355 | }
|
| 356 | }
|
| 357 |
|
| 358 | /**
|
| 359 | * Disabels color processing.
|
| 360 | */
|
| 361 | public void noColor()
|
| 362 | {
|
| 363 | this.noColor = true;
|
| 364 | }
|
| 365 |
|
| 366 | public WorldRenderer color(float red, float green, float blue, float alpha)
|
| 367 | {
|
| 368 | return this.color((int)(red * 255.0F), (int)(green * 255.0F), (int)(blue * 255.0F), (int)(alpha * 255.0F));
|
| 369 | }
|
| 370 |
|
| 371 | public WorldRenderer color(int red, int green, int blue, int alpha)
|
| 372 | {
|
| 373 | if (this.noColor)
|
| 374 | {
|
| 375 | return this;
|
| 376 | }
|
| 377 | else
|
| 378 | {
|
| 379 | int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
|
| 380 |
|
| 381 | switch (this.vertexFormatElement.getType())
|
| 382 | {
|
| 383 | case FLOAT:
|
| 384 | this.byteBuffer.putFloat(i, (float)red / 255.0F);
|
| 385 | this.byteBuffer.putFloat(i + 4, (float)green / 255.0F);
|
| 386 | this.byteBuffer.putFloat(i + 8, (float)blue / 255.0F);
|
| 387 | this.byteBuffer.putFloat(i + 12, (float)alpha / 255.0F);
|
| 388 | break;
|
| 389 |
|
| 390 | case UINT:
|
| 391 | case INT:
|
| 392 | this.byteBuffer.putFloat(i, (float)red);
|
| 393 | this.byteBuffer.putFloat(i + 4, (float)green);
|
| 394 | this.byteBuffer.putFloat(i + 8, (float)blue);
|
| 395 | this.byteBuffer.putFloat(i + 12, (float)alpha);
|
| 396 | break;
|
| 397 |
|
| 398 | case USHORT:
|
| 399 | case SHORT:
|
| 400 | this.byteBuffer.putShort(i, (short)red);
|
| 401 | this.byteBuffer.putShort(i + 2, (short)green);
|
| 402 | this.byteBuffer.putShort(i + 4, (short)blue);
|
| 403 | this.byteBuffer.putShort(i + 6, (short)alpha);
|
| 404 | break;
|
| 405 |
|
| 406 | case UBYTE:
|
| 407 | case BYTE:
|
| 408 | if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN)
|
| 409 | {
|
| 410 | this.byteBuffer.put(i, (byte)red);
|
| 411 | this.byteBuffer.put(i + 1, (byte)green);
|
| 412 | this.byteBuffer.put(i + 2, (byte)blue);
|
| 413 | this.byteBuffer.put(i + 3, (byte)alpha);
|
| 414 | }
|
| 415 | else
|
| 416 | {
|
| 417 | this.byteBuffer.put(i, (byte)alpha);
|
| 418 | this.byteBuffer.put(i + 1, (byte)blue);
|
| 419 | this.byteBuffer.put(i + 2, (byte)green);
|
| 420 | this.byteBuffer.put(i + 3, (byte)red);
|
| 421 | }
|
| 422 | }
|
| 423 |
|
| 424 | this.nextVertexFormatIndex();
|
| 425 | return this;
|
| 426 | }
|
| 427 | }
|
| 428 |
|
| 429 | public void addVertexData(int[] vertexData)
|
| 430 | {
|
| 431 | this.growBuffer(vertexData.length);
|
| 432 | this.rawIntBuffer.position(this.getBufferSize());
|
| 433 | this.rawIntBuffer.put(vertexData);
|
| 434 | this.vertexCount += vertexData.length / this.vertexFormat.getIntegerSize();
|
| 435 | }
|
| 436 |
|
| 437 | public void endVertex()
|
| 438 | {
|
| 439 | ++this.vertexCount;
|
| 440 | this.growBuffer(this.vertexFormat.getIntegerSize());
|
| 441 | }
|
| 442 |
|
| 443 | public WorldRenderer pos(double x, double y, double z)
|
| 444 | {
|
| 445 | int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
|
| 446 |
|
| 447 | switch (this.vertexFormatElement.getType())
|
| 448 | {
|
| 449 | case FLOAT:
|
| 450 | this.byteBuffer.putFloat(i, (float)(x + this.xOffset));
|
| 451 | this.byteBuffer.putFloat(i + 4, (float)(y + this.yOffset));
|
| 452 | this.byteBuffer.putFloat(i + 8, (float)(z + this.zOffset));
|
| 453 | break;
|
| 454 |
|
| 455 | case UINT:
|
| 456 | case INT:
|
| 457 | this.byteBuffer.putInt(i, Float.floatToRawIntBits((float)(x + this.xOffset)));
|
| 458 | this.byteBuffer.putInt(i + 4, Float.floatToRawIntBits((float)(y + this.yOffset)));
|
| 459 | this.byteBuffer.putInt(i + 8, Float.floatToRawIntBits((float)(z + this.zOffset)));
|
| 460 | break;
|
| 461 |
|
| 462 | case USHORT:
|
| 463 | case SHORT:
|
| 464 | this.byteBuffer.putShort(i, (short)((int)(x + this.xOffset)));
|
| 465 | this.byteBuffer.putShort(i + 2, (short)((int)(y + this.yOffset)));
|
| 466 | this.byteBuffer.putShort(i + 4, (short)((int)(z + this.zOffset)));
|
| 467 | break;
|
| 468 |
|
| 469 | case UBYTE:
|
| 470 | case BYTE:
|
| 471 | this.byteBuffer.put(i, (byte)((int)(x + this.xOffset)));
|
| 472 | this.byteBuffer.put(i + 1, (byte)((int)(y + this.yOffset)));
|
| 473 | this.byteBuffer.put(i + 2, (byte)((int)(z + this.zOffset)));
|
| 474 | }
|
| 475 |
|
| 476 | this.nextVertexFormatIndex();
|
| 477 | return this;
|
| 478 | }
|
| 479 |
|
| 480 | public void putNormal(float x, float y, float z)
|
| 481 | {
|
| 482 | int i = (byte)((int)(x * 127.0F)) & 255;
|
| 483 | int j = (byte)((int)(y * 127.0F)) & 255;
|
| 484 | int k = (byte)((int)(z * 127.0F)) & 255;
|
| 485 | int l = i | j << 8 | k << 16;
|
| 486 | int i1 = this.vertexFormat.getNextOffset() >> 2;
|
| 487 | int j1 = (this.vertexCount - 4) * i1 + this.vertexFormat.getNormalOffset() / 4;
|
| 488 | this.rawIntBuffer.put(j1, l);
|
| 489 | this.rawIntBuffer.put(j1 + i1, l);
|
| 490 | this.rawIntBuffer.put(j1 + i1 * 2, l);
|
| 491 | this.rawIntBuffer.put(j1 + i1 * 3, l);
|
| 492 | }
|
| 493 |
|
| 494 | private void nextVertexFormatIndex()
|
| 495 | {
|
| 496 | ++this.vertexFormatIndex;
|
| 497 | this.vertexFormatIndex %= this.vertexFormat.getElementCount();
|
| 498 | this.vertexFormatElement = this.vertexFormat.getElement(this.vertexFormatIndex);
|
| 499 |
|
| 500 | if (this.vertexFormatElement.getUsage() == VertexFormatElement.EnumUsage.PADDING)
|
| 501 | {
|
| 502 | this.nextVertexFormatIndex();
|
| 503 | }
|
| 504 | }
|
| 505 |
|
| 506 | public WorldRenderer normal(float p_181663_1_, float p_181663_2_, float p_181663_3_)
|
| 507 | {
|
| 508 | int i = this.vertexCount * this.vertexFormat.getNextOffset() + this.vertexFormat.getOffset(this.vertexFormatIndex);
|
| 509 |
|
| 510 | switch (this.vertexFormatElement.getType())
|
| 511 | {
|
| 512 | case FLOAT:
|
| 513 | this.byteBuffer.putFloat(i, p_181663_1_);
|
| 514 | this.byteBuffer.putFloat(i + 4, p_181663_2_);
|
| 515 | this.byteBuffer.putFloat(i + 8, p_181663_3_);
|
| 516 | break;
|
| 517 |
|
| 518 | case UINT:
|
| 519 | case INT:
|
| 520 | this.byteBuffer.putInt(i, (int)p_181663_1_);
|
| 521 | this.byteBuffer.putInt(i + 4, (int)p_181663_2_);
|
| 522 | this.byteBuffer.putInt(i + 8, (int)p_181663_3_);
|
| 523 | break;
|
| 524 |
|
| 525 | case USHORT:
|
| 526 | case SHORT:
|
| 527 | this.byteBuffer.putShort(i, (short)((int)p_181663_1_ * 32767 & 65535));
|
| 528 | this.byteBuffer.putShort(i + 2, (short)((int)p_181663_2_ * 32767 & 65535));
|
| 529 | this.byteBuffer.putShort(i + 4, (short)((int)p_181663_3_ * 32767 & 65535));
|
| 530 | break;
|
| 531 |
|
| 532 | case UBYTE:
|
| 533 | case BYTE:
|
| 534 | this.byteBuffer.put(i, (byte)((int)p_181663_1_ * 127 & 255));
|
| 535 | this.byteBuffer.put(i + 1, (byte)((int)p_181663_2_ * 127 & 255));
|
| 536 | this.byteBuffer.put(i + 2, (byte)((int)p_181663_3_ * 127 & 255));
|
| 537 | }
|
| 538 |
|
| 539 | this.nextVertexFormatIndex();
|
| 540 | return this;
|
| 541 | }
|
| 542 |
|
| 543 | public void setTranslation(double x, double y, double z)
|
| 544 | {
|
| 545 | this.xOffset = x;
|
| 546 | this.yOffset = y;
|
| 547 | this.zOffset = z;
|
| 548 | }
|
| 549 |
|
| 550 | public void finishDrawing()
|
| 551 | {
|
| 552 | if (!this.isDrawing)
|
| 553 | {
|
| 554 | throw new IllegalStateException("Not building!");
|
| 555 | }
|
| 556 | else
|
| 557 | {
|
| 558 | this.isDrawing = false;
|
| 559 | this.byteBuffer.position(0);
|
| 560 | this.byteBuffer.limit(this.getBufferSize() * 4);
|
| 561 | }
|
| 562 | }
|
| 563 |
|
| 564 | public ByteBuffer getByteBuffer()
|
| 565 | {
|
| 566 | return this.byteBuffer;
|
| 567 | }
|
| 568 |
|
| 569 | public VertexFormat getVertexFormat()
|
| 570 | {
|
| 571 | return this.vertexFormat;
|
| 572 | }
|
| 573 |
|
| 574 | public int getVertexCount()
|
| 575 | {
|
| 576 | return this.vertexCount;
|
| 577 | }
|
| 578 |
|
| 579 | public int getDrawMode()
|
| 580 | {
|
| 581 | return this.drawMode;
|
| 582 | }
|
| 583 |
|
| 584 | public void putColor4(int argb)
|
| 585 | {
|
| 586 | for (int i = 0; i < 4; ++i)
|
| 587 | {
|
| 588 | this.putColor(argb, i + 1);
|
| 589 | }
|
| 590 | }
|
| 591 |
|
| 592 | public void putColorRGB_F4(float red, float green, float blue)
|
| 593 | {
|
| 594 | for (int i = 0; i < 4; ++i)
|
| 595 | {
|
| 596 | this.putColorRGB_F(red, green, blue, i + 1);
|
| 597 | }
|
| 598 | }
|
| 599 |
|
| 600 | public class State
|
| 601 | {
|
| 602 | private final int[] stateRawBuffer;
|
| 603 | private final VertexFormat stateVertexFormat;
|
| 604 |
|
| 605 | public State(int[] buffer, VertexFormat format)
|
| 606 | {
|
| 607 | this.stateRawBuffer = buffer;
|
| 608 | this.stateVertexFormat = format;
|
| 609 | }
|
| 610 |
|
| 611 | public int[] getRawBuffer()
|
| 612 | {
|
| 613 | return this.stateRawBuffer;
|
| 614 | }
|
| 615 |
|
| 616 | public int getVertexCount()
|
| 617 | {
|
| 618 | return this.stateRawBuffer.length / this.stateVertexFormat.getIntegerSize();
|
| 619 | }
|
| 620 |
|
| 621 | public VertexFormat getVertexFormat()
|
| 622 | {
|
| 623 | return this.stateVertexFormat;
|
| 624 | }
|
| 625 | }
|
| 626 | }
|
| 627 |
|