prevent buffer flip on position of 0
This commit is contained in:
parent
bd41085afa
commit
035a13ae7b
@ -199,7 +199,9 @@ public class AudioBuffer {
|
|||||||
ByteBuffer buffer = MemoryUtil.memAlloc(dataRaw.length);
|
ByteBuffer buffer = MemoryUtil.memAlloc(dataRaw.length);
|
||||||
buffer.order(isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
buffer.order(isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||||
buffer.put(dataRaw);
|
buffer.put(dataRaw);
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
|
|
||||||
//sanity check
|
//sanity check
|
||||||
if(this.length > 10 * 60 * 60 * 1000){
|
if(this.length > 10 * 60 * 60 * 1000){
|
||||||
@ -269,7 +271,9 @@ public class AudioBuffer {
|
|||||||
while(fc.read(buffer) != -1){
|
while(fc.read(buffer) != -1){
|
||||||
|
|
||||||
}
|
}
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LoggerInterface.loggerFileIO.ERROR("Failed to create audio, file is not readable: " + filepath, new IOException("File access error!"));
|
LoggerInterface.loggerFileIO.ERROR("Failed to create audio, file is not readable: " + filepath, new IOException("File access error!"));
|
||||||
|
|||||||
@ -40,28 +40,28 @@ public class RenderUtils {
|
|||||||
int rVal = glGenVertexArrays();
|
int rVal = glGenVertexArrays();
|
||||||
glBindVertexArray(rVal);
|
glBindVertexArray(rVal);
|
||||||
//vertices
|
//vertices
|
||||||
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(12);
|
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(12);
|
||||||
VertexArrayBufferData.put(-1.0f);
|
vertexArrayBufferData.put(-1.0f);
|
||||||
VertexArrayBufferData.put( 1.0f);
|
vertexArrayBufferData.put( 1.0f);
|
||||||
|
|
||||||
VertexArrayBufferData.put(-1.0f);
|
vertexArrayBufferData.put(-1.0f);
|
||||||
VertexArrayBufferData.put(-1.0f);
|
vertexArrayBufferData.put(-1.0f);
|
||||||
|
|
||||||
VertexArrayBufferData.put( 1.0f);
|
vertexArrayBufferData.put( 1.0f);
|
||||||
VertexArrayBufferData.put(-1.0f);
|
vertexArrayBufferData.put(-1.0f);
|
||||||
|
|
||||||
VertexArrayBufferData.put(-1.0f);
|
vertexArrayBufferData.put(-1.0f);
|
||||||
VertexArrayBufferData.put( 1.0f);
|
vertexArrayBufferData.put( 1.0f);
|
||||||
|
|
||||||
VertexArrayBufferData.put( 1.0f);
|
vertexArrayBufferData.put( 1.0f);
|
||||||
VertexArrayBufferData.put(-1.0f);
|
vertexArrayBufferData.put(-1.0f);
|
||||||
|
|
||||||
VertexArrayBufferData.put( 1.0f);
|
vertexArrayBufferData.put( 1.0f);
|
||||||
VertexArrayBufferData.put( 1.0f);
|
vertexArrayBufferData.put( 1.0f);
|
||||||
VertexArrayBufferData.flip();
|
vertexArrayBufferData.flip();
|
||||||
int vertexBuffer = glGenBuffers();
|
int vertexBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, VertexArrayBufferData, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, vertexArrayBufferData, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
@ -70,28 +70,28 @@ public class RenderUtils {
|
|||||||
|
|
||||||
|
|
||||||
//texture coords
|
//texture coords
|
||||||
FloatBuffer TextureArrayBufferData = BufferUtils.createFloatBuffer(12);
|
FloatBuffer textureArrayBufferData = BufferUtils.createFloatBuffer(12);
|
||||||
TextureArrayBufferData.put(0.0f);
|
textureArrayBufferData.put(0.0f);
|
||||||
TextureArrayBufferData.put(1.0f);
|
textureArrayBufferData.put(1.0f);
|
||||||
|
|
||||||
TextureArrayBufferData.put(0.0f);
|
textureArrayBufferData.put(0.0f);
|
||||||
TextureArrayBufferData.put(0.0f);
|
textureArrayBufferData.put(0.0f);
|
||||||
|
|
||||||
TextureArrayBufferData.put(1.0f);
|
textureArrayBufferData.put(1.0f);
|
||||||
TextureArrayBufferData.put(0.0f);
|
textureArrayBufferData.put(0.0f);
|
||||||
|
|
||||||
TextureArrayBufferData.put(0.0f);
|
textureArrayBufferData.put(0.0f);
|
||||||
TextureArrayBufferData.put(1.0f);
|
textureArrayBufferData.put(1.0f);
|
||||||
|
|
||||||
TextureArrayBufferData.put(1.0f);
|
textureArrayBufferData.put(1.0f);
|
||||||
TextureArrayBufferData.put(0.0f);
|
textureArrayBufferData.put(0.0f);
|
||||||
|
|
||||||
TextureArrayBufferData.put(1.0f);
|
textureArrayBufferData.put(1.0f);
|
||||||
TextureArrayBufferData.put(1.0f);
|
textureArrayBufferData.put(1.0f);
|
||||||
TextureArrayBufferData.flip();
|
textureArrayBufferData.flip();
|
||||||
int textureCoordBuffer = glGenBuffers();
|
int textureCoordBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, textureCoordBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, textureCoordBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, TextureArrayBufferData, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, textureArrayBufferData, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
@ -158,16 +158,16 @@ public class RenderUtils {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
int vertexCount = vertexcoords.length / 3;
|
int vertexCount = vertexcoords.length / 3;
|
||||||
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(vertexCount * 3);
|
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(vertexCount * 3);
|
||||||
float[] temp = new float[3];
|
float[] temp = new float[3];
|
||||||
for (int i = 0; i < vertexCount; i++) {
|
for (int i = 0; i < vertexCount; i++) {
|
||||||
temp[0] = vertexcoords[i * 3 + 0];
|
temp[0] = vertexcoords[i * 3 + 0];
|
||||||
temp[1] = vertexcoords[i * 3 + 1];
|
temp[1] = vertexcoords[i * 3 + 1];
|
||||||
temp[2] = vertexcoords[i * 3 + 2];
|
temp[2] = vertexcoords[i * 3 + 2];
|
||||||
VertexArrayBufferData.put(temp);
|
vertexArrayBufferData.put(temp);
|
||||||
}
|
}
|
||||||
VertexArrayBufferData.flip();
|
vertexArrayBufferData.flip();
|
||||||
particleMesh.bufferVertices(VertexArrayBufferData, 3);
|
particleMesh.bufferVertices(vertexArrayBufferData, 3);
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -291,39 +291,57 @@ public class InstanceData {
|
|||||||
switch(attributeGlBufferMap.get(attribute).getType()){
|
switch(attributeGlBufferMap.get(attribute).getType()){
|
||||||
case VEC3F: {
|
case VEC3F: {
|
||||||
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case VEC3D: {
|
case VEC3D: {
|
||||||
DoubleBuffer buffer = ((DoubleBuffer)attributeCpuBufferMap.get(attribute));
|
DoubleBuffer buffer = ((DoubleBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case VEC4F: {
|
case VEC4F: {
|
||||||
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case VEC4D: {
|
case VEC4D: {
|
||||||
DoubleBuffer buffer = ((DoubleBuffer)attributeCpuBufferMap.get(attribute));
|
DoubleBuffer buffer = ((DoubleBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case MAT4F: {
|
case MAT4F: {
|
||||||
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case MAT4D: {
|
case MAT4D: {
|
||||||
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case DOUBLE: {
|
case DOUBLE: {
|
||||||
DoubleBuffer buffer = ((DoubleBuffer)attributeCpuBufferMap.get(attribute));
|
DoubleBuffer buffer = ((DoubleBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case FLOAT: {
|
case FLOAT: {
|
||||||
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
FloatBuffer buffer = ((FloatBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case INT: {
|
case INT: {
|
||||||
IntBuffer buffer = ((IntBuffer)attributeCpuBufferMap.get(attribute));
|
IntBuffer buffer = ((IntBuffer)attributeCpuBufferMap.get(attribute));
|
||||||
buffer.flip();
|
if(buffer.position() > 0){
|
||||||
|
buffer.flip();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -291,7 +291,9 @@ public class LightManager {
|
|||||||
dataBuffer.putFloat(0);
|
dataBuffer.putFloat(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataBuffer.flip();
|
if(dataBuffer.position() > 0){
|
||||||
|
dataBuffer.flip();
|
||||||
|
}
|
||||||
|
|
||||||
// dataBuffer.position(0);
|
// dataBuffer.position(0);
|
||||||
|
|
||||||
|
|||||||
@ -582,8 +582,6 @@ public class FluidChunkModelGeneration {
|
|||||||
List<Vector3f> normals = new LinkedList<Vector3f>();
|
List<Vector3f> normals = new LinkedList<Vector3f>();
|
||||||
//the list of number of triangles that share a vert
|
//the list of number of triangles that share a vert
|
||||||
List<Integer> trianglesSharingVert = new LinkedList<Integer>();
|
List<Integer> trianglesSharingVert = new LinkedList<Integer>();
|
||||||
//List of elements in order
|
|
||||||
List<Integer> faceElements = new LinkedList<Integer>();
|
|
||||||
//List of UVs
|
//List of UVs
|
||||||
List<Float> UVs = new LinkedList<Float>();
|
List<Float> UVs = new LinkedList<Float>();
|
||||||
|
|
||||||
@ -696,13 +694,14 @@ public class FluidChunkModelGeneration {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
int vertexCount = data.getVertices().size() / 3;
|
int vertexCount = data.getVertices().size() / 3;
|
||||||
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(vertexCount * 3);
|
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(vertexCount * 3);
|
||||||
float[] temp = new float[3];
|
|
||||||
for(float vertValue : data.getVertices()){
|
for(float vertValue : data.getVertices()){
|
||||||
VertexArrayBufferData.put(vertValue);
|
vertexArrayBufferData.put(vertValue);
|
||||||
|
}
|
||||||
|
if(vertexArrayBufferData.position() > 0){
|
||||||
|
vertexArrayBufferData.flip();
|
||||||
|
mesh.bufferVertices(vertexArrayBufferData, 3);
|
||||||
}
|
}
|
||||||
VertexArrayBufferData.flip();
|
|
||||||
mesh.bufferVertices(VertexArrayBufferData, 3);
|
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -712,16 +711,16 @@ public class FluidChunkModelGeneration {
|
|||||||
//
|
//
|
||||||
// FACES
|
// FACES
|
||||||
//
|
//
|
||||||
int faceCount = data.getFaceElements().size() / 3;
|
|
||||||
int elementCount = data.getFaceElements().size();
|
int elementCount = data.getFaceElements().size();
|
||||||
try {
|
try {
|
||||||
IntBuffer elementArrayBufferData = BufferUtils.createIntBuffer(elementCount);
|
IntBuffer elementArrayBufferData = BufferUtils.createIntBuffer(elementCount);
|
||||||
int[] temp = new int[3];
|
|
||||||
for(int element : data.getFaceElements()){
|
for(int element : data.getFaceElements()){
|
||||||
elementArrayBufferData.put(element);
|
elementArrayBufferData.put(element);
|
||||||
}
|
}
|
||||||
elementArrayBufferData.flip();
|
if(elementArrayBufferData.position() > 0){
|
||||||
mesh.bufferFaces(elementArrayBufferData,elementCount);
|
elementArrayBufferData.flip();
|
||||||
|
mesh.bufferFaces(elementArrayBufferData,elementCount);
|
||||||
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -734,15 +733,16 @@ public class FluidChunkModelGeneration {
|
|||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
int normalCount = data.getNormals().size() / 3;
|
int normalCount = data.getNormals().size() / 3;
|
||||||
FloatBuffer NormalArrayBufferData;
|
FloatBuffer normalArrayBufferData;
|
||||||
if(normalCount > 0){
|
if(normalCount > 0){
|
||||||
NormalArrayBufferData = BufferUtils.createFloatBuffer(normalCount * 3);
|
normalArrayBufferData = BufferUtils.createFloatBuffer(normalCount * 3);
|
||||||
float[] temp = new float[3];
|
|
||||||
for(float normalValue : data.getNormals()){
|
for(float normalValue : data.getNormals()){
|
||||||
NormalArrayBufferData.put(normalValue);
|
normalArrayBufferData.put(normalValue);
|
||||||
|
}
|
||||||
|
if(normalArrayBufferData.position() > 0){
|
||||||
|
normalArrayBufferData.flip();
|
||||||
|
mesh.bufferNormals(normalArrayBufferData, 3);
|
||||||
}
|
}
|
||||||
NormalArrayBufferData.flip();
|
|
||||||
mesh.bufferNormals(NormalArrayBufferData, 3);
|
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -753,15 +753,16 @@ public class FluidChunkModelGeneration {
|
|||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
int textureCoordCount = data.getUVs().size() / 2;
|
int textureCoordCount = data.getUVs().size() / 2;
|
||||||
FloatBuffer TextureArrayBufferData;
|
FloatBuffer textureArrayBufferData;
|
||||||
if(textureCoordCount > 0){
|
if(textureCoordCount > 0){
|
||||||
TextureArrayBufferData = BufferUtils.createFloatBuffer(textureCoordCount * 2);
|
textureArrayBufferData = BufferUtils.createFloatBuffer(textureCoordCount * 2);
|
||||||
float[] temp = new float[2];
|
|
||||||
for(float uvValue : data.getUVs()){
|
for(float uvValue : data.getUVs()){
|
||||||
TextureArrayBufferData.put(uvValue);
|
textureArrayBufferData.put(uvValue);
|
||||||
|
}
|
||||||
|
if(textureArrayBufferData.position() > 0){
|
||||||
|
textureArrayBufferData.flip();
|
||||||
|
mesh.bufferTextureCoords(textureArrayBufferData, 2);
|
||||||
}
|
}
|
||||||
TextureArrayBufferData.flip();
|
|
||||||
mesh.bufferTextureCoords(TextureArrayBufferData, 2);
|
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|||||||
@ -86,7 +86,7 @@ public class MeshLoader {
|
|||||||
int vertexCount = 0;
|
int vertexCount = 0;
|
||||||
try {
|
try {
|
||||||
vertexCount = mesh.mNumVertices();
|
vertexCount = mesh.mNumVertices();
|
||||||
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(vertexCount * 3);
|
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(vertexCount * 3);
|
||||||
float[] temp = new float[3];
|
float[] temp = new float[3];
|
||||||
boolean definedDimensions = false;
|
boolean definedDimensions = false;
|
||||||
float minX = 0, maxX = 0, minY = 0, maxY = 0, minZ = 0, maxZ = 0;
|
float minX = 0, maxX = 0, minY = 0, maxY = 0, minZ = 0, maxZ = 0;
|
||||||
@ -120,11 +120,12 @@ public class MeshLoader {
|
|||||||
temp[0] = (float)transformedVertex.x;
|
temp[0] = (float)transformedVertex.x;
|
||||||
temp[1] = (float)transformedVertex.y;
|
temp[1] = (float)transformedVertex.y;
|
||||||
temp[2] = (float)transformedVertex.z;
|
temp[2] = (float)transformedVertex.z;
|
||||||
VertexArrayBufferData.put(temp);
|
vertexArrayBufferData.put(temp);
|
||||||
|
}
|
||||||
|
if(vertexArrayBufferData.position() > 0){
|
||||||
|
vertexArrayBufferData.flip();
|
||||||
|
rVal.bufferVertices(vertexArrayBufferData, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexArrayBufferData.flip();
|
|
||||||
rVal.bufferVertices(VertexArrayBufferData, 3);
|
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -134,9 +135,9 @@ public class MeshLoader {
|
|||||||
AIVector3D.Buffer normals = mesh.mNormals();
|
AIVector3D.Buffer normals = mesh.mNormals();
|
||||||
try {
|
try {
|
||||||
int normalCount = mesh.mNumVertices();
|
int normalCount = mesh.mNumVertices();
|
||||||
FloatBuffer NormalArrayBufferData;
|
FloatBuffer normalArrayBufferData;
|
||||||
if(normalCount > 0){
|
if(normalCount > 0){
|
||||||
NormalArrayBufferData = BufferUtils.createFloatBuffer(normalCount * 3);
|
normalArrayBufferData = BufferUtils.createFloatBuffer(normalCount * 3);
|
||||||
float[] temp = new float[3];
|
float[] temp = new float[3];
|
||||||
for (int i = 0; i < normalCount; i++) {
|
for (int i = 0; i < normalCount; i++) {
|
||||||
AIVector3D normal = normals.get(i);
|
AIVector3D normal = normals.get(i);
|
||||||
@ -144,10 +145,12 @@ public class MeshLoader {
|
|||||||
temp[0] = (float)transformedNormal.x();
|
temp[0] = (float)transformedNormal.x();
|
||||||
temp[1] = (float)transformedNormal.y();
|
temp[1] = (float)transformedNormal.y();
|
||||||
temp[2] = (float)transformedNormal.z();
|
temp[2] = (float)transformedNormal.z();
|
||||||
NormalArrayBufferData.put(temp);
|
normalArrayBufferData.put(temp);
|
||||||
|
}
|
||||||
|
if(normalArrayBufferData.position() > 0){
|
||||||
|
normalArrayBufferData.flip();
|
||||||
|
rVal.bufferNormals(normalArrayBufferData, 3);
|
||||||
}
|
}
|
||||||
NormalArrayBufferData.flip();
|
|
||||||
rVal.bufferNormals(NormalArrayBufferData, 3);
|
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -166,8 +169,10 @@ public class MeshLoader {
|
|||||||
}
|
}
|
||||||
elementArrayBufferData.put(face.mIndices());
|
elementArrayBufferData.put(face.mIndices());
|
||||||
}
|
}
|
||||||
elementArrayBufferData.flip();
|
if(elementArrayBufferData.position() > 0){
|
||||||
rVal.bufferFaces(elementArrayBufferData,elementCount);
|
elementArrayBufferData.flip();
|
||||||
|
rVal.bufferFaces(elementArrayBufferData,elementCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -181,19 +186,21 @@ public class MeshLoader {
|
|||||||
try {
|
try {
|
||||||
if(texturecoords != null){
|
if(texturecoords != null){
|
||||||
int textureCoordCount = texturecoords.capacity();
|
int textureCoordCount = texturecoords.capacity();
|
||||||
FloatBuffer TextureArrayBufferData;
|
FloatBuffer textureArrayBufferData;
|
||||||
if(textureCoordCount > 0){
|
if(textureCoordCount > 0){
|
||||||
TextureArrayBufferData = BufferUtils.createFloatBuffer(textureCoordCount * 2);
|
textureArrayBufferData = BufferUtils.createFloatBuffer(textureCoordCount * 2);
|
||||||
float[] temp = new float[2];
|
float[] temp = new float[2];
|
||||||
for (int i = 0; i < textureCoordCount; i++) {
|
for (int i = 0; i < textureCoordCount; i++) {
|
||||||
AIVector3D normal = texturecoords.get(i);
|
AIVector3D normal = texturecoords.get(i);
|
||||||
temp[0] = normal.x();
|
temp[0] = normal.x();
|
||||||
temp[1] = normal.y();
|
temp[1] = normal.y();
|
||||||
// temp[2] = normal.z();
|
// temp[2] = normal.z();
|
||||||
TextureArrayBufferData.put(temp);
|
textureArrayBufferData.put(temp);
|
||||||
|
}
|
||||||
|
if(textureArrayBufferData.position() > 0){
|
||||||
|
textureArrayBufferData.flip();
|
||||||
|
rVal.bufferTextureCoords(textureArrayBufferData, 2);
|
||||||
}
|
}
|
||||||
TextureArrayBufferData.flip();
|
|
||||||
rVal.bufferTextureCoords(TextureArrayBufferData, 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
@ -299,8 +306,12 @@ public class MeshLoader {
|
|||||||
boneIndexDataBuffer.put(index);
|
boneIndexDataBuffer.put(index);
|
||||||
boneWeightDataBuffer.put(weight);
|
boneWeightDataBuffer.put(weight);
|
||||||
}
|
}
|
||||||
boneIndexDataBuffer.flip();
|
if(boneIndexDataBuffer.position() > 0){
|
||||||
boneWeightDataBuffer.flip();
|
boneIndexDataBuffer.flip();
|
||||||
|
}
|
||||||
|
if(boneWeightDataBuffer.position() > 0){
|
||||||
|
boneWeightDataBuffer.flip();
|
||||||
|
}
|
||||||
|
|
||||||
if(!Globals.HEADLESS){
|
if(!Globals.HEADLESS){
|
||||||
rVal.bufferBoneIndices(boneIndexDataBuffer);
|
rVal.bufferBoneIndices(boneIndexDataBuffer);
|
||||||
|
|||||||
@ -789,38 +789,44 @@ public class TerrainChunkModelGeneration {
|
|||||||
//
|
//
|
||||||
int elementCount = data.getFaceElements().size();
|
int elementCount = data.getFaceElements().size();
|
||||||
try {
|
try {
|
||||||
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
||||||
FloatBuffer NormalArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
FloatBuffer normalArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
||||||
FloatBuffer TextureArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 2);
|
FloatBuffer textureArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 2);
|
||||||
for(int element : data.getFaceElements()){
|
for(int element : data.getFaceElements()){
|
||||||
//for each element, need to push vert, normal, etc
|
//for each element, need to push vert, normal, etc
|
||||||
|
|
||||||
//push current vertex
|
//push current vertex
|
||||||
VertexArrayBufferData.put(data.getVertices().get(element*3+0));
|
vertexArrayBufferData.put(data.getVertices().get(element*3+0));
|
||||||
VertexArrayBufferData.put(data.getVertices().get(element*3+1));
|
vertexArrayBufferData.put(data.getVertices().get(element*3+1));
|
||||||
VertexArrayBufferData.put(data.getVertices().get(element*3+2));
|
vertexArrayBufferData.put(data.getVertices().get(element*3+2));
|
||||||
|
|
||||||
//push current normals
|
//push current normals
|
||||||
NormalArrayBufferData.put(data.getNormals().get(element*3+0));
|
normalArrayBufferData.put(data.getNormals().get(element*3+0));
|
||||||
NormalArrayBufferData.put(data.getNormals().get(element*3+1));
|
normalArrayBufferData.put(data.getNormals().get(element*3+1));
|
||||||
NormalArrayBufferData.put(data.getNormals().get(element*3+2));
|
normalArrayBufferData.put(data.getNormals().get(element*3+2));
|
||||||
|
|
||||||
//push current uvs
|
//push current uvs
|
||||||
TextureArrayBufferData.put(data.getUVs().get(element*2+0));
|
textureArrayBufferData.put(data.getUVs().get(element*2+0));
|
||||||
TextureArrayBufferData.put(data.getUVs().get(element*2+1));
|
textureArrayBufferData.put(data.getUVs().get(element*2+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
//actually buffer vertices
|
//actually buffer vertices
|
||||||
VertexArrayBufferData.flip();
|
if(vertexArrayBufferData.position() > 0){
|
||||||
mesh.bufferVertices(VertexArrayBufferData, 3);
|
vertexArrayBufferData.flip();
|
||||||
|
mesh.bufferVertices(vertexArrayBufferData, 3);
|
||||||
|
}
|
||||||
|
|
||||||
//actually buffer normals
|
//actually buffer normals
|
||||||
NormalArrayBufferData.flip();
|
if(normalArrayBufferData.position() > 0){
|
||||||
mesh.bufferNormals(NormalArrayBufferData, 3);
|
normalArrayBufferData.flip();
|
||||||
|
mesh.bufferNormals(normalArrayBufferData, 3);
|
||||||
|
}
|
||||||
|
|
||||||
//actually buffer UVs
|
//actually buffer UVs
|
||||||
TextureArrayBufferData.flip();
|
if(textureArrayBufferData.position() > 0){
|
||||||
mesh.bufferTextureCoords(TextureArrayBufferData, 2);
|
textureArrayBufferData.flip();
|
||||||
|
mesh.bufferTextureCoords(textureArrayBufferData, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
@ -841,8 +847,10 @@ public class TerrainChunkModelGeneration {
|
|||||||
for(float samplerVec : data.getTextureSamplers()){
|
for(float samplerVec : data.getTextureSamplers()){
|
||||||
samplerBuffer.put(samplerVec);
|
samplerBuffer.put(samplerVec);
|
||||||
}
|
}
|
||||||
samplerBuffer.flip();
|
if(samplerBuffer.position() > 0){
|
||||||
mesh.bufferCustomFloatAttribArray(samplerBuffer, 3, SAMPLER_INDEX_ATTRIB_LOC);
|
samplerBuffer.flip();
|
||||||
|
mesh.bufferCustomFloatAttribArray(samplerBuffer, 3, SAMPLER_INDEX_ATTRIB_LOC);
|
||||||
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -856,8 +864,10 @@ public class TerrainChunkModelGeneration {
|
|||||||
for(float samplerVec : data.getTextureRatioVectors()){
|
for(float samplerVec : data.getTextureRatioVectors()){
|
||||||
samplerBuffer.put(samplerVec);
|
samplerBuffer.put(samplerVec);
|
||||||
}
|
}
|
||||||
samplerBuffer.flip();
|
if(samplerBuffer.position() > 0){
|
||||||
mesh.bufferCustomFloatAttribArray(samplerBuffer, 3, SAMPLER_RATIO_ATTRIB_LOC);
|
samplerBuffer.flip();
|
||||||
|
mesh.bufferCustomFloatAttribArray(samplerBuffer, 3, SAMPLER_RATIO_ATTRIB_LOC);
|
||||||
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,7 +118,9 @@ public class Texture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.flip();
|
if(data.position() > 0){
|
||||||
|
data.flip();
|
||||||
|
}
|
||||||
//call if width != height so opengl figures out how to unpack it properly
|
//call if width != height so opengl figures out how to unpack it properly
|
||||||
if(width != height){
|
if(width != height){
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|||||||
@ -105,7 +105,9 @@ public class ServerFluidManager {
|
|||||||
for(int x = 0; x < model.getElevation().length; x++){
|
for(int x = 0; x < model.getElevation().length; x++){
|
||||||
floatView.put(model.getElevation()[x]);
|
floatView.put(model.getElevation()[x]);
|
||||||
}
|
}
|
||||||
floatView.flip();
|
if(floatView.position() > 0){
|
||||||
|
floatView.flip();
|
||||||
|
}
|
||||||
FileUtils.saveBinaryToSavePath(saveName, "./fluid.dat", buffer.array());
|
FileUtils.saveBinaryToSavePath(saveName, "./fluid.dat", buffer.array());
|
||||||
FileUtils.serializeObjectToSavePath(saveName, "./fluid.json", model);
|
FileUtils.serializeObjectToSavePath(saveName, "./fluid.json", model);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,7 +110,9 @@ public class ServerTerrainManager {
|
|||||||
for(int x = 0; x < model.getElevation().length; x++){
|
for(int x = 0; x < model.getElevation().length; x++){
|
||||||
floatView.put(model.getElevation()[x]);
|
floatView.put(model.getElevation()[x]);
|
||||||
}
|
}
|
||||||
floatView.flip();
|
if(floatView.position() > 0){
|
||||||
|
floatView.flip();
|
||||||
|
}
|
||||||
FileUtils.serializeObjectToSavePath(saveName, "./terrain.json", model);
|
FileUtils.serializeObjectToSavePath(saveName, "./terrain.json", model);
|
||||||
FileUtils.saveBinaryToSavePath(saveName, "./terrain.dat", buffer.array());
|
FileUtils.saveBinaryToSavePath(saveName, "./terrain.dat", buffer.array());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user