Skip to content

Commit

Permalink
Texture3D abstraction layer
Browse files Browse the repository at this point in the history
  • Loading branch information
JoopAue committed Mar 24, 2016
1 parent 810b58a commit 124d53c
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 157 deletions.
89 changes: 89 additions & 0 deletions jme3-core/src/main/java/com/jme3/texture/Texture3D.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.jme3.texture;

import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;

import java.io.IOException;

public abstract class Texture3D extends Texture{

protected WrapMode wrapR = WrapMode.EdgeClamp;

public Texture3D() {
super();
}

@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);
}

/**
* <code>setWrap</code> sets the wrap mode of this texture for a
* particular axis.
*
* @param axis
* the texture axis to define a wrapmode on.
* @param mode
* the wrap mode for the given axis of the texture.
* @throws IllegalArgumentException
* if axis or mode are null
*/
public void setWrap(WrapAxis axis, WrapMode mode) {
super.setWrap(axis, mode);
if(axis == WrapAxis.R) {
this.wrapR = mode;
}
}

/**
* <code>setWrap</code> sets the wrap mode of this texture for all axis.
*
* @param mode
* the wrap mode for the given axis of the texture.
* @throws IllegalArgumentException
* if mode is null
*/
public void setWrap(WrapMode mode) {
super.setWrap(mode);
this.wrapR = mode;
}

/**
* <code>getWrap</code> returns the wrap mode for a given coordinate axis
* on this texture.
*
* @param axis
* the axis to return for
* @return the wrap mode of the texture.
* @throws IllegalArgumentException
* if axis is null
*/
public WrapMode getWrap(WrapAxis axis) {
if (axis == WrapAxis.R) {
return wrapR;
}
return super.getWrap(axis);
}

@Override
public void write(JmeExporter e) throws IOException {
super.write(e);
OutputCapsule capsule = e.getCapsule(this);
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);
}
}
76 changes: 1 addition & 75 deletions jme3-core/src/main/java/com/jme3/texture/TextureCubeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
*
* @author Joshua Slack
*/
public class TextureCubeMap extends Texture {

private WrapMode wrapR = WrapMode.EdgeClamp;
public class TextureCubeMap extends Texture3D {

/**
* Face of the Cubemap as described by its directional offset from the
Expand Down Expand Up @@ -95,62 +93,6 @@ public Texture createSimpleClone() {
return createSimpleClone(new TextureCubeMap());
}

@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);
}

/**
* <code>setWrap</code> sets the wrap mode of this texture for a
* particular axis.
*
* @param axis
* the texture axis to define a wrapmode on.
* @param mode
* the wrap mode for the given axis of the texture.
* @throws IllegalArgumentException
* if axis or mode are null
*/
public void setWrap(WrapAxis axis, WrapMode mode) {
super.setWrap(axis, mode);
if(axis == WrapAxis.R) {
this.wrapR = mode;
}
}

/**
* <code>setWrap</code> sets the wrap mode of this texture for all axis.
*
* @param mode
* the wrap mode for the given axis of the texture.
* @throws IllegalArgumentException
* if mode is null
*/
public void setWrap(WrapMode mode) {
super.setWrap(mode);
this.wrapR = mode;
}

/**
* <code>getWrap</code> returns the wrap mode for a given coordinate axis
* on this texture.
*
* @param axis
* the axis to return for
* @return the wrap mode of the texture.
* @throws IllegalArgumentException
* if axis is null
*/
public WrapMode getWrap(WrapAxis axis) {
if (axis == WrapAxis.R) {
return wrapR;
}
return super.getWrap(axis);
}

@Override
public Type getType() {
return Type.CubeMap;
Expand All @@ -175,20 +117,4 @@ public int 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(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);
}
}
78 changes: 2 additions & 76 deletions jme3-core/src/main/java/com/jme3/texture/TextureDefault3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
/**
* @author Maarten Steur
*/
public class TextureDefault3D extends Texture {

private WrapMode wrapR = WrapMode.EdgeClamp;
public class TextureDefault3D extends Texture3D {

/**
* Creates a new two-dimensional texture with default attributes.
Expand Down Expand Up @@ -98,65 +96,7 @@ public TextureDefault3D(int width, int height, int depth, int numSamples, Image.

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

@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);
}

/**
* <code>setWrap</code> sets the wrap mode of this texture for a
* particular axis.
*
* @param axis
* the texture axis to define a wrapmode on.
* @param mode
* the wrap mode for the given axis of the texture.
* @throws IllegalArgumentException
* if axis or mode are null
*/
public void setWrap(WrapAxis axis, WrapMode mode) {
super.setWrap(axis, mode);
if(axis == WrapAxis.R) {
this.wrapR = mode;
}
}

/**
* <code>setWrap</code> sets the wrap mode of this texture for all axis.
*
* @param mode
* the wrap mode for the given axis of the texture.
* @throws IllegalArgumentException
* if mode is null
*/
public void setWrap(WrapMode mode) {
super.setWrap(mode);
this.wrapR = mode;
}

/**
* <code>getWrap</code> returns the wrap mode for a given coordinate axis
* on this texture.
*
* @param axis
* the axis to return for
* @return the wrap mode of the texture.
* @throws IllegalArgumentException
* if axis is null
*/
public WrapMode getWrap(WrapAxis axis) {
if (axis == WrapAxis.R) {
return wrapR;
}
return super.getWrap(axis);
return createSimpleClone(new TextureDefault3D());
}

@Override
Expand All @@ -176,19 +116,5 @@ public boolean equals(Object other) {
return super.equals(other);
}

@Override
public void write(JmeExporter e) throws IOException {
super.write(e);
OutputCapsule capsule = e.getCapsule(this);
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);
}
}
12 changes: 6 additions & 6 deletions jme3-core/src/main/resources/com/jme3/system/version.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# THIS IS AN AUTO-GENERATED FILE..
# DO NOT MODIFY!
build.date=2016-03-21
git.revision=5387
git.revision=5388
git.branch=test-texture
git.hash=c5b83a57ec6ffca5369b77a4e381d7061a400c4f
git.hash.short=c5b83a5
git.tag=v3.1-alpha1-229-gc5b83a5
name.full=jMonkeyEngine 3.1-test-texture-5387
version.full=3.1-test-texture-5387
git.hash=8a4fc350becaf8719fb76bae268ccead6e1b0ee6
git.hash.short=8a4fc35
git.tag=v3.1-alpha1-230-g8a4fc35
name.full=jMonkeyEngine 3.1-test-texture-5388
version.full=3.1-test-texture-5388
version.number=3.1.0
version.tag=SNAPSHOT

0 comments on commit 124d53c

Please sign in to comment.