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

Testing & Refactoring by Remco Tjeerdsma & Mart Oude Weernink #23

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
1 change: 1 addition & 0 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.0.28-beta'
testCompile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10'
testCompile 'org.hamcrest:hamcrest-library:1.3'
deployerJars "org.apache.maven.wagon:wagon-ssh:2.9"
}

Expand Down
10 changes: 6 additions & 4 deletions jme3-core/src/main/java/com/jme3/texture/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ public Image(Format format, int width, int height, int depth, ArrayList<ByteBuff
setFormat(format);
this.width = width;
this.height = height;
this.data = data;
if(data != null) {
this.data = data;
}
this.depth = depth;
this.mipMapSizes = mipMapSizes;
this.colorSpace = colorSpace;
Expand Down Expand Up @@ -731,9 +733,9 @@ public void setData(ArrayList<ByteBuffer> data) {
* the data that contains the image information.
*/
public void setData(ByteBuffer data) {
this.data = new ArrayList<ByteBuffer>(1);
this.data.add(data);
setUpdateNeeded();
ArrayList<ByteBuffer> list = new ArrayList<ByteBuffer>(1);
list.add(data);
setData(list);
}

public void addData(ByteBuffer data) {
Expand Down
14 changes: 6 additions & 8 deletions jme3-core/src/main/java/com/jme3/texture/Texture2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.texture.image.ColorSpace;

import java.io.IOException;

/**
Expand Down Expand Up @@ -92,15 +93,13 @@ public Texture2D(int width, int height, Image.Format format){
* @param numSamples
*/
public Texture2D(int width, int height, int numSamples, Image.Format format){
this(new Image(format, width, height, null, ColorSpace.Linear));
this(width, height, format);
getImage().setMultiSamples(numSamples);
}

@Override
public Texture createSimpleClone() {
Texture2D clone = new Texture2D();
createSimpleClone(clone);
return clone;
return createSimpleClone(new Texture2D());
}

@Override
Expand Down Expand Up @@ -151,8 +150,8 @@ public void setWrap(WrapMode mode) {
if (mode == null) {
throw new IllegalArgumentException("mode can not be null.");
}
this.wrapS = mode;
this.wrapT = mode;
setWrap(WrapAxis.S, mode);
setWrap(WrapAxis.T, mode);
}

/**
Expand Down Expand Up @@ -183,9 +182,8 @@ public Type getType() {

@Override
public boolean equals(Object other) {
if (!(other instanceof Texture2D)) {
if (!(other instanceof Texture2D))
return false;
}
Texture2D that = (Texture2D) other;
if (this.getWrap(WrapAxis.S) != that.getWrap(WrapAxis.S))
return false;
Expand Down
47 changes: 15 additions & 32 deletions jme3-core/src/main/java/com/jme3/texture/Texture3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
/**
* @author Maarten Steur
*/
public class Texture3D extends Texture {
public class Texture3D extends Texture2D {

private WrapMode wrapS = WrapMode.EdgeClamp;
private WrapMode wrapT = WrapMode.EdgeClamp;
private WrapMode wrapR = WrapMode.EdgeClamp;

/**
Expand Down Expand Up @@ -94,21 +92,18 @@ public Texture3D(int width, int height, int depth, Image.Format format) {
* @param numSamples
*/
public Texture3D(int width, int height, int depth, int numSamples, Image.Format format) {
this(new Image(format, width, height, depth, null, ColorSpace.Linear));
this(width, height, depth, format);
getImage().setMultiSamples(numSamples);
}

@Override
public Texture createSimpleClone() {
Texture3D clone = new Texture3D();
createSimpleClone(clone);
return clone;
return createSimpleClone(new Texture3D());

}

@Override
public Texture createSimpleClone(Texture rVal) {
rVal.setWrap(WrapAxis.S, wrapS);
rVal.setWrap(WrapAxis.T, wrapT);
rVal.setWrap(WrapAxis.R, wrapR);
return super.createSimpleClone(rVal);
}
Expand All @@ -131,15 +126,11 @@ public void setWrap(WrapAxis axis, WrapMode mode) {
throw new IllegalArgumentException("axis can not be null.");
}
switch (axis) {
case S:
this.wrapS = mode;
break;
case T:
this.wrapT = mode;
break;
case R:
this.wrapR = mode;
break;
default:
super.setWrap(axis, mode);
}
}

Expand All @@ -155,8 +146,7 @@ public void setWrap(WrapMode mode) {
if (mode == null) {
throw new IllegalArgumentException("mode can not be null.");
}
this.wrapS = mode;
this.wrapT = mode;
super.setWrap(mode);
this.wrapR = mode;
}

Expand All @@ -172,14 +162,10 @@ public void setWrap(WrapMode mode) {
*/
public WrapMode getWrap(WrapAxis axis) {
switch (axis) {
case S:
return wrapS;
case T:
return wrapT;
case R:
return wrapR;
}
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
return super.getWrap(axis);
}

@Override
Expand All @@ -193,33 +179,30 @@ public boolean equals(Object other) {
return false;
}
Texture3D that = (Texture3D) other;
if (this.getWrap(WrapAxis.S) != that.getWrap(WrapAxis.S)) {
return false;
}
if (this.getWrap(WrapAxis.T) != that.getWrap(WrapAxis.T)) {
return false;
}
if (this.getWrap(WrapAxis.R) != that.getWrap(WrapAxis.R)) {
return false;
}
return super.equals(other);
}

@Override
public int hashCode() {
int hash = super.hashCode();
hash = 53 * hash + (this.wrapR != null ? this.wrapR.hashCode() : 0);
return hash;
}

@Override
public void write(JmeExporter e) throws IOException {
super.write(e);
OutputCapsule capsule = e.getCapsule(this);
capsule.write(wrapS, "wrapS", WrapMode.EdgeClamp);
capsule.write(wrapT, "wrapT", WrapMode.EdgeClamp);
capsule.write(wrapR, "wrapR", WrapMode.EdgeClamp);
}

@Override
public void read(JmeImporter e) throws IOException {
super.read(e);
InputCapsule capsule = e.getCapsule(this);
wrapS = capsule.readEnum("wrapS", WrapMode.class, WrapMode.EdgeClamp);
wrapT = capsule.readEnum("wrapT", WrapMode.class, WrapMode.EdgeClamp);
wrapR = capsule.readEnum("wrapR", WrapMode.class, WrapMode.EdgeClamp);
}
}
56 changes: 3 additions & 53 deletions jme3-core/src/main/java/com/jme3/texture/TextureArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
* renderManager.getRenderer().getCaps().contains(Caps.TextureArray)
* @author phate666
*/
public class TextureArray extends Texture {

private WrapMode wrapS = WrapMode.EdgeClamp;
private WrapMode wrapT = WrapMode.EdgeClamp;
public class TextureArray extends Texture2D {

/**
* Construct a TextureArray
Expand Down Expand Up @@ -94,62 +91,15 @@ public TextureArray(List<Image> images) {
setImage(arrayImage);
}

@Override
public Texture createSimpleClone() {
TextureArray clone = new TextureArray();
createSimpleClone(clone);
return clone;
}

@Override
public Texture createSimpleClone(Texture rVal) {
rVal.setWrap(WrapAxis.S, wrapS);
rVal.setWrap(WrapAxis.T, wrapT);
return super.createSimpleClone(rVal);
}

@Override
public Type getType() {
return Type.TwoDimensionalArray;
}

@Override
public WrapMode getWrap(WrapAxis axis) {
switch (axis) {
case S:
return wrapS;
case T:
return wrapT;
default:
throw new IllegalArgumentException("invalid WrapAxis: " + axis);
}
}
public Texture createSimpleClone() {
return createSimpleClone(new TextureArray());

@Override
public void setWrap(WrapAxis axis, WrapMode mode) {
if (mode == null) {
throw new IllegalArgumentException("mode can not be null.");
} else if (axis == null) {
throw new IllegalArgumentException("axis can not be null.");
}
switch (axis) {
case S:
this.wrapS = mode;
break;
case T:
this.wrapT = mode;
break;
default:
throw new IllegalArgumentException("Not applicable for 2D textures");
}
}

@Override
public void setWrap(WrapMode mode) {
if (mode == null) {
throw new IllegalArgumentException("mode can not be null.");
}
this.wrapS = mode;
this.wrapT = mode;
}
}
Loading