Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for KHR_accessor_float64 support #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void setComponentType(Integer componentType) {
if (componentType == null) {
throw new NullPointerException((("Invalid value for componentType: "+ componentType)+", may not be null"));
}
if ((((((componentType!= 5120)&&(componentType!= 5121))&&(componentType!= 5122))&&(componentType!= 5123))&&(componentType!= 5125))&&(componentType!= 5126)) {
if ((((((componentType!= 5120)&&(componentType!= 5121))&&(componentType!= 5122))&&(componentType!= 5123))&&(componentType!= 5125))&&(componentType!= 5126)&&(componentType!= 5130)) {
throw new IllegalArgumentException((("Invalid value for componentType: "+ componentType)+", valid: [5120, 5121, 5122, 5123, 5125, 5126]"));
}
this.componentType = componentType;
Expand Down
79 changes: 79 additions & 0 deletions jgltf-model/src/main/java/de/javagl/jgltf/model/AccessorDatas.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public static AccessorData create(
{
return createFloat(accessorModel, byteBuffer);
}
if (accessorModel.getComponentDataType() == double.class)
{
return createDouble(accessorModel, byteBuffer);
}
// Should never happen
logger.severe("Invalid component data type: "
+ accessorModel.getComponentDataType());
Expand Down Expand Up @@ -138,6 +142,12 @@ public static AccessorData create(
componentType, bufferViewData, byteOffset, count,
elementType, byteStride);
}
if (isDoubleType(componentType))
{
return new AccessorDoubleData(
componentType, bufferViewData, byteOffset, count,
elementType, byteStride);
}
throw new IllegalArgumentException(
"Not a valid component type: " + componentType);
}
Expand Down Expand Up @@ -197,6 +207,17 @@ public static boolean isFloatType(int type)
return type == GltfConstants.GL_FLOAT;
}

/**
* Returns whether the given constant is <code>GL_DOUBLE</code>.
*
* @param type The type constant
* @return Whether the type is a <code>double</code> type
*/
public static boolean isDoubleType(int type)
{
return type == GltfConstants.GL_DOUBLE;
}

/**
* Returns whether the given constant is <code>GL_UNSIGNED_BYTE</code>,
* <code>GL_UNSIGNED_SHORT</code> or <code>GL_UNSIGNED_INT</code>.
Expand Down Expand Up @@ -288,6 +309,24 @@ static void validateFloatType(int type)
}
}

/**
* Make sure that the given type is <code>GL_DOUBLE</code>, and throw an
* <code>IllegalArgumentException</code> if this is not the case.
*
* @param type The type constant
* @throws IllegalArgumentException If the given type is not
* <code>GL_DOUBLE</code>
*/
static void validateDoubleType(int type)
{
if (!isDoubleType(type))
{
throw new IllegalArgumentException(
"The type is not GL_DOUBLE, but " +
GltfConstants.stringFor(type));
}
}



/**
Expand Down Expand Up @@ -432,6 +471,8 @@ public static AccessorFloatData createFloat(AccessorModel accessorModel)
* @return The {@link AccessorFloatData}
* @throws NullPointerException If any argument is <code>null</code>
* @throws IllegalArgumentException If the
* {@link AccessorModel#getComponentType() component type} of the given
* accessorModel is not <code>GL_FLOAT</code>
*/
private static AccessorFloatData createFloat(
AccessorModel accessorModel, ByteBuffer bufferViewByteBuffer)
Expand All @@ -444,6 +485,29 @@ private static AccessorFloatData createFloat(
accessorModel.getByteStride());
}

/**
* Creates an {@link AccessorDoubleData} for the given {@link AccessorModel}
*
* @param accessorModel The {@link AccessorModel}
* @param bufferViewByteBuffer The byte buffer of the
* {@link BufferViewModel} referenced by the {@link AccessorModel}
* @return The {@link AccessorDoubleData}
* @throws NullPointerException If any argument is <code>null</code>
* @throws IllegalArgumentException If the
* {@link AccessorModel#getComponentType() component type} of the given
* accessorModel is not <code>GL_DOUBLE</code>
*/
private static AccessorDoubleData createDouble(
AccessorModel accessorModel, ByteBuffer bufferViewByteBuffer)
{
return new AccessorDoubleData(accessorModel.getComponentType(),
bufferViewByteBuffer,
accessorModel.getByteOffset(),
accessorModel.getCount(),
accessorModel.getElementType(),
accessorModel.getByteStride());
}

/**
* Validate that the given {@link AccessorModel} parameters are valid for
* accessing a buffer with the given capacity
Expand Down Expand Up @@ -512,6 +576,13 @@ public static Number[] computeMin(AccessorData accessorData)
return NumberArrays.asNumbers(
accessorFloatData.computeMin());
}
if (accessorData instanceof AccessorDoubleData)
{
AccessorDoubleData accessorDoubleData =
(AccessorDoubleData) accessorData;
return NumberArrays.asNumbers(
accessorDoubleData.computeMin());
}
throw new IllegalArgumentException(
"Invalid data type: " + accessorData);
}
Expand Down Expand Up @@ -554,6 +625,13 @@ public static Number[] computeMax(AccessorData accessorData)
return NumberArrays.asNumbers(
accessorFloatData.computeMax());
}
if (accessorData instanceof AccessorDoubleData)
{
AccessorDoubleData accessorDoubleData =
(AccessorDoubleData) accessorData;
return NumberArrays.asNumbers(
accessorDoubleData.computeMax());
}
throw new IllegalArgumentException(
"Invalid data type: " + accessorData);
}
Expand All @@ -565,6 +643,7 @@ public static Number[] computeMax(AccessorData accessorData)
* {@link AccessorShortData#createString(Locale, String, int)},
* {@link AccessorIntData#createString(Locale, String, int)} or
* {@link AccessorFloatData#createString(Locale, String, int)},
* {@link AccessorDoubleData#createString(Locale, String, int)},
* depending on the type of the given data, with an unspecified
* format string.
*
Expand Down
Loading