|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright (c) 2009-2019 jMonkeyEngine |
|
|
|
* Copyright (c) 2009-2020 jMonkeyEngine |
|
|
|
* All rights reserved. |
|
|
|
* All rights reserved. |
|
|
|
* |
|
|
|
* |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
@ -54,7 +54,6 @@ import java.nio.*; |
|
|
|
* </ul> |
|
|
|
* </ul> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Type of buffer. Specifies the actual attribute it defines. |
|
|
|
* Type of buffer. Specifies the actual attribute it defines. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -63,27 +62,22 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* Position of the vertex (3 floats) |
|
|
|
* Position of the vertex (3 floats) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Position, |
|
|
|
Position, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The size of the point when using point buffers (float). |
|
|
|
* The size of the point when using point buffers (float). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Size, |
|
|
|
Size, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Normal vector, normalized (3 floats). |
|
|
|
* Normal vector, normalized (3 floats). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Normal, |
|
|
|
Normal, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate (2 float) |
|
|
|
* Texture coordinate (2 float) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord, |
|
|
|
TexCoord, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Color and Alpha (4 floats) |
|
|
|
* Color and Alpha (4 floats) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Color, |
|
|
|
Color, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Tangent vector, normalized (4 floats) (x,y,z,w). The w component is |
|
|
|
* Tangent vector, normalized (4 floats) (x,y,z,w). The w component is |
|
|
|
* called the binormal parity, is not normalized, and is either 1f or |
|
|
|
* called the binormal parity, is not normalized, and is either 1f or |
|
|
@ -91,19 +85,16 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* GPU at render time. |
|
|
|
* GPU at render time. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Tangent, |
|
|
|
Tangent, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Binormal vector, normalized (3 floats, optional) |
|
|
|
* Binormal vector, normalized (3 floats, optional) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Binormal, |
|
|
|
Binormal, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Specifies the source data for various vertex buffers |
|
|
|
* Specifies the source data for various vertex buffers |
|
|
|
* when interleaving is used. By default the format is |
|
|
|
* when interleaving is used. By default the format is |
|
|
|
* byte. |
|
|
|
* byte. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
InterleavedData, |
|
|
|
InterleavedData, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Do not use. |
|
|
|
* Do not use. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -114,7 +105,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* (ubyte, ushort, or uint). |
|
|
|
* (ubyte, ushort, or uint). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Index, |
|
|
|
Index, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initial vertex position, used with animation. |
|
|
|
* Initial vertex position, used with animation. |
|
|
|
* Should have the same format and size as {@link Type#Position}. |
|
|
|
* Should have the same format and size as {@link Type#Position}. |
|
|
@ -123,7 +113,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* on the heap. |
|
|
|
* on the heap. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BindPosePosition, |
|
|
|
BindPosePosition, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initial vertex normals, used with animation. |
|
|
|
* Initial vertex normals, used with animation. |
|
|
|
* Should have the same format and size as {@link Type#Normal}. |
|
|
|
* Should have the same format and size as {@link Type#Normal}. |
|
|
@ -132,7 +121,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* on the heap. |
|
|
|
* on the heap. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BindPoseNormal, |
|
|
|
BindPoseNormal, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Bone weights, used with animation (4 floats). |
|
|
|
* Bone weights, used with animation (4 floats). |
|
|
|
* Only used for software skinning, the usage should be |
|
|
|
* Only used for software skinning, the usage should be |
|
|
@ -140,7 +128,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* on the heap. |
|
|
|
* on the heap. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BoneWeight, |
|
|
|
BoneWeight, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Bone indices, used with animation (4 ubytes). |
|
|
|
* Bone indices, used with animation (4 ubytes). |
|
|
|
* Only used for software skinning, the usage should be |
|
|
|
* Only used for software skinning, the usage should be |
|
|
@ -148,42 +135,34 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* on the heap as a ubytes buffer. |
|
|
|
* on the heap as a ubytes buffer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BoneIndex, |
|
|
|
BoneIndex, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate #2 |
|
|
|
* Texture coordinate #2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord2, |
|
|
|
TexCoord2, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate #3 |
|
|
|
* Texture coordinate #3 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord3, |
|
|
|
TexCoord3, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate #4 |
|
|
|
* Texture coordinate #4 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord4, |
|
|
|
TexCoord4, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate #5 |
|
|
|
* Texture coordinate #5 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord5, |
|
|
|
TexCoord5, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate #6 |
|
|
|
* Texture coordinate #6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord6, |
|
|
|
TexCoord6, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate #7 |
|
|
|
* Texture coordinate #7 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord7, |
|
|
|
TexCoord7, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Texture coordinate #8 |
|
|
|
* Texture coordinate #8 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
TexCoord8, |
|
|
|
TexCoord8, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initial vertex tangents, used with animation. |
|
|
|
* Initial vertex tangents, used with animation. |
|
|
|
* Should have the same format and size as {@link Type#Tangent}. |
|
|
|
* Should have the same format and size as {@link Type#Tangent}. |
|
|
@ -192,20 +171,17 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* on the heap. |
|
|
|
* on the heap. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BindPoseTangent, |
|
|
|
BindPoseTangent, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Bone weights, used with animation (4 floats). |
|
|
|
* Bone weights, used with animation (4 floats). |
|
|
|
* for Hardware Skinning only |
|
|
|
* for Hardware Skinning only |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
HWBoneWeight, |
|
|
|
HWBoneWeight, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Bone indices, used with animation (4 ubytes). |
|
|
|
* Bone indices, used with animation (4 ubytes). |
|
|
|
* for Hardware Skinning only |
|
|
|
* for Hardware Skinning only |
|
|
|
* either an int or float buffer due to shader attribute types restrictions. |
|
|
|
* either an int or float buffer due to shader attribute types restrictions. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
HWBoneIndex, |
|
|
|
HWBoneIndex, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Information about this instance. |
|
|
|
* Information about this instance. |
|
|
|
* |
|
|
|
* |
|
|
@ -213,7 +189,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* should be 16. |
|
|
|
* should be 16. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
InstanceData, |
|
|
|
InstanceData, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Morph animations targets. |
|
|
|
* Morph animations targets. |
|
|
|
* Supports up tp 14 morph target buffers at the same time |
|
|
|
* Supports up tp 14 morph target buffers at the same time |
|
|
@ -225,11 +200,15 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* 7 simultaneous POSITION and NORMAL targets |
|
|
|
* 7 simultaneous POSITION and NORMAL targets |
|
|
|
* 4 simultaneous POSTION, NORMAL and TANGENT targets. |
|
|
|
* 4 simultaneous POSTION, NORMAL and TANGENT targets. |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* Note that the MorphControl will find how many buffers can be supported for each mesh/material combination. |
|
|
|
* Note that the MorphControl will find how many buffers |
|
|
|
* Note that all buffers have 3 components (Vector3f) even the Tangent buffer that |
|
|
|
* can be supported for each mesh/material combination. |
|
|
|
* does not contain the w (handedness) component that will not be interpolated for morph animation. |
|
|
|
* Note that all buffers have 3 components (Vector3f) |
|
|
|
|
|
|
|
* even the Tangent buffer that |
|
|
|
|
|
|
|
* does not contain the w (handedness) component |
|
|
|
|
|
|
|
* that will not be interpolated for morph animation. |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* Note that those buffers contain the difference between the base buffer (POSITION, NORMAL or TANGENT) and the target value |
|
|
|
* Note that those buffers contain the difference between |
|
|
|
|
|
|
|
* the base buffer (POSITION, NORMAL or TANGENT) and the target value |
|
|
|
* So that you can interpolate with a MADD operation in the vertex shader |
|
|
|
* So that you can interpolate with a MADD operation in the vertex shader |
|
|
|
* position = weight * diffPosition + basePosition; |
|
|
|
* position = weight * diffPosition + basePosition; |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -247,7 +226,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
MorphTarget11, |
|
|
|
MorphTarget11, |
|
|
|
MorphTarget12, |
|
|
|
MorphTarget12, |
|
|
|
MorphTarget13, |
|
|
|
MorphTarget13, |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -256,22 +234,18 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* or held in video memory, but no guarantees are made- it's only a hint. |
|
|
|
* or held in video memory, but no guarantees are made- it's only a hint. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static enum Usage { |
|
|
|
public static enum Usage { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Mesh data is sent once and very rarely updated. |
|
|
|
* Mesh data is sent once and very rarely updated. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Static, |
|
|
|
Static, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Mesh data is updated occasionally (once per frame or less). |
|
|
|
* Mesh data is updated occasionally (once per frame or less). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Dynamic, |
|
|
|
Dynamic, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Mesh data is updated every frame. |
|
|
|
* Mesh data is updated every frame. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Stream, |
|
|
|
Stream, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Mesh data is <em>not</em> sent to GPU at all. It is only |
|
|
|
* Mesh data is <em>not</em> sent to GPU at all. It is only |
|
|
|
* used by the CPU. |
|
|
|
* used by the CPU. |
|
|
@ -289,49 +263,38 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static enum Format { |
|
|
|
public static enum Format { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Half precision floating point. |
|
|
|
* Half precision floating point. 2 bytes, signed. |
|
|
|
* 2 bytes, signed. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Half(2), |
|
|
|
Half(2), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Single precision floating point. |
|
|
|
* Single precision floating point. 4 bytes, signed |
|
|
|
* 4 bytes, signed |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Float(4), |
|
|
|
Float(4), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Double precision floating point. |
|
|
|
* Double precision floating point. 8 bytes, signed. May not be |
|
|
|
* 8 bytes, signed. May not |
|
|
|
* supported by all GPUs. |
|
|
|
* be supported by all GPUs. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Double(8), |
|
|
|
Double(8), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 1 byte integer, signed. |
|
|
|
* 1 byte integer, signed. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Byte(1), |
|
|
|
Byte(1), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 1 byte integer, unsigned. |
|
|
|
* 1 byte integer, unsigned. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
UnsignedByte(1), |
|
|
|
UnsignedByte(1), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 2 byte integer, signed. |
|
|
|
* 2 byte integer, signed. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Short(2), |
|
|
|
Short(2), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 2 byte integer, unsigned. |
|
|
|
* 2 byte integer, unsigned. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
UnsignedShort(2), |
|
|
|
UnsignedShort(2), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 4 byte integer, signed. |
|
|
|
* 4 byte integer, signed. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Int(4), |
|
|
|
Int(4), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 4 byte integer, unsigned. |
|
|
|
* 4 byte integer, unsigned. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -507,7 +470,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
* that is safe to read from a separate thread from other readers. |
|
|
|
* that is safe to read from a separate thread from other readers. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Buffer getDataReadOnly() { |
|
|
|
public Buffer getDataReadOnly() { |
|
|
|
|
|
|
|
|
|
|
|
if (data == null) { |
|
|
|
if (data == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
@ -515,7 +477,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
// Create a read-only duplicate(). Note: this does not copy
|
|
|
|
// Create a read-only duplicate(). Note: this does not copy
|
|
|
|
// the underlying memory, it just creates a new read-only wrapper
|
|
|
|
// the underlying memory, it just creates a new read-only wrapper
|
|
|
|
// with its own buffer position state.
|
|
|
|
// with its own buffer position state.
|
|
|
|
|
|
|
|
|
|
|
|
// Unfortunately, this is not 100% straight forward since Buffer
|
|
|
|
// Unfortunately, this is not 100% straight forward since Buffer
|
|
|
|
// does not have an asReadOnlyBuffer() method.
|
|
|
|
// does not have an asReadOnlyBuffer() method.
|
|
|
|
Buffer result; |
|
|
|
Buffer result; |
|
|
@ -707,7 +668,8 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Called to update the data in the buffer with new data. Can only |
|
|
|
* Called to update the data in the buffer with new data. Can only |
|
|
|
* be called after {@link VertexBuffer#setupData(com.jme3.scene.VertexBuffer.Usage, int, com.jme3.scene.VertexBuffer.Format, java.nio.Buffer) } |
|
|
|
* be called after {@link VertexBuffer#setupData( |
|
|
|
|
|
|
|
* com.jme3.scene.VertexBuffer.Usage, int, com.jme3.scene.VertexBuffer.Format, java.nio.Buffer) } |
|
|
|
* has been called. Note that it is fine to call this method on the |
|
|
|
* has been called. Note that it is fine to call this method on the |
|
|
|
* data already set, e.g. vb.updateData(vb.getData()), this will just |
|
|
|
* data already set, e.g. vb.updateData(vb.getData()), this will just |
|
|
|
* set the proper update flag indicating the data should be sent to the GPU |
|
|
|
* set the proper update flag indicating the data should be sent to the GPU |
|
|
@ -743,6 +705,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns true if the data size of the VertexBuffer has changed. |
|
|
|
* Returns true if the data size of the VertexBuffer has changed. |
|
|
|
* Internal use only. |
|
|
|
* Internal use only. |
|
|
|
|
|
|
|
* |
|
|
|
* @return true if the data size has changed |
|
|
|
* @return true if the data size has changed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hasDataSizeChanged() { |
|
|
|
public boolean hasDataSizeChanged() { |
|
|
@ -1145,7 +1108,6 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void write(JmeExporter ex) throws IOException { |
|
|
|
public void write(JmeExporter ex) throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
OutputCapsule oc = ex.getCapsule(this); |
|
|
|
OutputCapsule oc = ex.getCapsule(this); |
|
|
|
oc.write(components, "components", 0); |
|
|
|
oc.write(components, "components", 0); |
|
|
|
oc.write(usage, "usage", Usage.Dynamic); |
|
|
|
oc.write(usage, "usage", Usage.Dynamic); |
|
|
@ -1215,5 +1177,4 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { |
|
|
|
throw new IOException("Unsupported import buffer format: " + format); |
|
|
|
throw new IOException("Unsupported import buffer format: " + format); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|