Skip to content

Commit

Permalink
Remove custom exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
integeruser committed Nov 19, 2016
1 parent ab6014d commit 92ad15a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 60 deletions.
38 changes: 8 additions & 30 deletions src/integeruser/jglsdk/glimg/ImageCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class ImageCreator {
this.arrayCount = arrayCount;
this.faceCount = faceCount;

if (faceCount != 6 && faceCount != 1) throw new BadFaceCountException();
if (faceCount == 6 && ddsDimensions.numDimensions != 2) throw new CubemapsMustBe2DException();
if (ddsDimensions.numDimensions == 3 && arrayCount != 1) throw new No3DTextureArrayException();
if (mipmapCount <= 0 || arrayCount <= 0) throw new NoImagesSpecifiedException();
if (faceCount != 6 && faceCount != 1) throw new RuntimeException("Bad face count.");
if (faceCount == 6 && ddsDimensions.numDimensions != 2) throw new RuntimeException("Cubemaps must be 2D.");
if (ddsDimensions.numDimensions == 3 && arrayCount != 1) throw new RuntimeException("No 3D texture array.");
if (mipmapCount <= 0 || arrayCount <= 0) throw new RuntimeException("No images specified.");

imageData = new ArrayList<>(mipmapCount);
imageSizes = new int[mipmapCount];
Expand All @@ -43,12 +43,12 @@ class ImageCreator {

////////////////////////////////
void setImageData(byte sourceData[], boolean isTopLeft, int mipmapLevel, int arrayIx, int faceIx) {
if (imageData.isEmpty()) throw new ImageSetAlreadyCreatedException();
if (imageData.isEmpty()) throw new RuntimeException("ImageSet already created.");

// Check inputs.
if ((arrayIx < 0) || (arrayCount <= arrayIx)) throw new ArrayIndexOutOfBoundsException();
if ((faceIx < 0) || (faceCount <= faceIx)) throw new FaceIndexOutOfBoundsException();
if ((mipmapLevel < 0) || (mipmapCount <= mipmapLevel)) throw new MipmapLayerOutOfBoundsException();
if ((faceIx < 0) || (faceCount <= faceIx)) throw new RuntimeException("Face index out of bounds.");
if ((mipmapLevel < 0) || (mipmapCount <= mipmapLevel)) throw new RuntimeException("Mipmap layer out of bounds.");

// Get the image relative to mipmapLevel
byte[] imageData = this.imageData.get(mipmapLevel);
Expand All @@ -63,7 +63,7 @@ void setImageData(byte sourceData[], boolean isTopLeft, int mipmapLevel, int arr


ImageSet createImage() {
if (imageData.isEmpty()) throw new ImageSetAlreadyCreatedException();
if (imageData.isEmpty()) throw new RuntimeException("ImageSet already created.");
return new ImageSet(imageFormat, imageDimensions, mipmapCount, arrayCount, faceCount, imageData, imageSizes);
}

Expand All @@ -78,28 +78,6 @@ ImageSet createImage() {
private ArrayList<byte[]> imageData;
private int[] imageSizes;


private static class BadFaceCountException extends RuntimeException {
}

private static class CubemapsMustBe2DException extends RuntimeException {
}

private static class No3DTextureArrayException extends RuntimeException {
}

private static class NoImagesSpecifiedException extends RuntimeException {
}

private static class ImageSetAlreadyCreatedException extends RuntimeException {
}

private static class MipmapLayerOutOfBoundsException extends RuntimeException {
}

private static class FaceIndexOutOfBoundsException extends RuntimeException {
}

////////////////////////////////
private void copyImageFlipped(byte[] sourceData, byte[] imageData, int imageDataOffset, int mipmapLevel) {
assert (sourceData.length * faceCount * arrayCount) == imageData.length;
Expand Down
9 changes: 1 addition & 8 deletions src/integeruser/jglsdk/glimg/ImageFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private String validateFormatText() {
this.uncheckedImageFormat = uncheckedImageFormat;

String message = this.uncheckedImageFormat.validateFormatText();
if (!message.equals("")) throw new InvalidFormatException(message);
if (!message.equals("")) throw new RuntimeException(message);
}


Expand Down Expand Up @@ -349,11 +349,4 @@ int getLineAlignment() {


private UncheckedImageFormat uncheckedImageFormat;


private static class InvalidFormatException extends RuntimeException {
InvalidFormatException(String message) {
super(message);
}
}
}
25 changes: 3 additions & 22 deletions src/integeruser/jglsdk/glimg/TextureGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ private static void throwIfLANotSupported() {

private static void throwIfForceRendertarget(int forceConvertBits) {
if ((forceConvertBits & ForcedConvertFlags.FORCE_COLOR_RENDERABLE_FMT) != 0) {
throw new CannotForceRenderTargetException();
throw new RuntimeException("The image format cannot be forced to be a renderable format without compromising the data.");
}
}

Expand Down Expand Up @@ -1012,29 +1012,10 @@ void bind(int textureTarget, int texture) {
}


private static class CannotForceTextureStorage extends RuntimeException {
private CannotForceTextureStorage() {
super("The current OpenGL implementation does not support ARB_texture_storage or GL 4.2 or above.");
}
}

private static class CannotForceDSAUsage extends RuntimeException {
private CannotForceDSAUsage() {
super("The current OpenGL implementation does not support EXT_direct_state_access.");
}
}

private static class CannotForceRenderTargetException extends RuntimeException {
private CannotForceRenderTargetException() {
super("The image format cannot be forced to be a renderable format without compromising the data.");
}
}


private static void createTexture(int textureName, ImageSet imageSet, int forceConvertBits) {
if ((forceConvertBits & ForcedConvertFlags.FORCE_TEXTURE_STORAGE) != 0) {
if (!isTextureStorageSupported()) {
throw new CannotForceTextureStorage();
throw new RuntimeException("The current OpenGL implementation does not support ARB_texture_storage or GL 4.2 or above.");
}

forceConvertBits |= ForcedConvertFlags.USE_TEXTURE_STORAGE;
Expand All @@ -1048,7 +1029,7 @@ private static void createTexture(int textureName, ImageSet imageSet, int forceC

if ((forceConvertBits & ForcedConvertFlags.FORCE_DSA) != 0) {
if (!isDirectStateAccessSupported()) {
throw new CannotForceDSAUsage();
throw new RuntimeException("The current OpenGL implementation does not support EXT_direct_state_access.");
}

forceConvertBits |= ForcedConvertFlags.USE_DSA;
Expand Down

0 comments on commit 92ad15a

Please sign in to comment.