Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (702)
Games in Android Showcase (203)
games submitted by our members
Games in WIP (774)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: BloodShura (posted 2014-05-01 18:38:47, viewed 245 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103  
package org.shura.rpg.graphics.defaults;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import org.shura.rpg.object.Ideable;
import org.shura.x.lang.annotation.Internal;

/**
 * @author BloodShura
 * @date 01/05/2014 - 02:14:49
 */
public class VertexObject extends Ideable {
  private Integer bufferSize;
  private ByteBuffer byteBuffer;
  private FloatBuffer floatBuffer;
  private IntBuffer intBuffer, vertexBuffer;
  private int[] rawBuffer;
  private Integer rawBufferIndex, vertexCount;
  private ShortBuffer shortBuffer;

  public VertexObject(Integer bufferSize) {
    this.bufferSize = bufferSize;
    this.byteBuffer = bufferer.createDirectByteBuffer(bufferSize * 4);
    this.floatBuffer = byteBuffer.asFloatBuffer();
    this.intBuffer = byteBuffer.asIntBuffer();
    this.rawBuffer = new int[bufferSize];
    this.rawBufferIndex = 0;
    this.shortBuffer = byteBuffer.asShortBuffer();
    this.vertexCount = 0;
  }

  public void addVertex(Double x, Double y, Double z, Integer normal, Integer color, Double textureX, Double textureY) {
    rawBuffer()[rawBufferIndex + 0] = Float.floatToRawIntBits(x.floatValue());
    rawBuffer()[rawBufferIndex + 1] = Float.floatToRawIntBits(y.floatValue());
    rawBuffer()[rawBufferIndex + 2] = Float.floatToRawIntBits(z.floatValue());

    if (textureX != null && textureY != null) {
      rawBuffer()[rawBufferIndex + 3] = Float.floatToRawIntBits(textureX.floatValue());
      rawBuffer()[rawBufferIndex + 4] = Float.floatToRawIntBits(textureY.floatValue());
    }

    if (color != null) {
      rawBuffer()[rawBufferIndex + 5] = color;
    }

    if (normal != null) {
      rawBuffer()[rawBufferIndex + 6] = normal;
    }

    this.rawBufferIndex += 8;
    this.vertexCount++;
  }

  public Integer bufferSize() {
    return bufferSize;
  }

  public ByteBuffer byteBuffer() {
    return byteBuffer;
  }

  public void clear() {
    this.rawBufferIndex = 0;
    this.vertexCount = 0;

    byteBuffer().clear();
  }

  public Integer countVertexes() {
    return vertexCount;
  }

  public FloatBuffer floatBuffer() {
    return floatBuffer;
  }

  public IntBuffer intBuffer() {
    return intBuffer;
  }

  public int[] rawBuffer() {
    return rawBuffer;
  }

  public Integer rawBufferIndex() {
    return rawBufferIndex;
  }

  @Internal
  public void setupVertexBuffer() {
    context.arbGenBuffers(this.vertexBuffer = bufferer.createDirectIntBuffer(DefaultTessellator.VBO_COUNT));
  }

  public ShortBuffer shortBuffer() {
    return shortBuffer;
  }

  public IntBuffer vertexBuffer() {
    return vertexBuffer;
  }
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
Lunch (44 views)
2016-12-06 16:01:40

ral0r2 (270 views)
2016-11-23 16:08:26

ClaasJG (403 views)
2016-11-10 17:36:32

CoffeeChemist (499 views)
2016-11-05 00:46:53

jay4842 (545 views)
2016-11-01 19:04:52

theagentd (570 views)
2016-10-24 17:51:53

theagentd (552 views)
2016-10-24 17:50:08

theagentd (503 views)
2016-10-24 17:43:15

CommanderKeith (498 views)
2016-10-22 15:22:05

Roquen (460 views)
2016-10-22 01:57:43
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!