Skip to content

Commit

Permalink
Texture2D refactor part 2
Browse files Browse the repository at this point in the history
:
  • Loading branch information
JoopAue committed Mar 24, 2016
1 parent a7ce89c commit ec47807
Show file tree
Hide file tree
Showing 46 changed files with 273 additions and 318 deletions.
26 changes: 13 additions & 13 deletions jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/CombinedTexture.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.jme3.texture.TextureDefault2D;
import jme3tools.converters.ImageToAwt;

import com.jme3.math.ColorRGBA;
Expand All @@ -33,7 +34,6 @@
import com.jme3.texture.Texture.MagFilter;
import com.jme3.texture.Texture.MinFilter;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.texture.Texture2D;
import com.jme3.texture.TextureCubeMap;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;
Expand Down Expand Up @@ -96,7 +96,7 @@ public CombinedTexture(int mappingType, boolean discardCoveredTextures) {
* the blender context
*/
public void add(Texture texture, TextureBlender textureBlender, int uvCoordinatesType, int projectionType, Structure textureStructure, String uvCoordinatesName, BlenderContext blenderContext) {
if (!(texture instanceof GeneratedTexture) && !(texture instanceof Texture2D)) {
if (!(texture instanceof GeneratedTexture) && !(texture instanceof TextureDefault2D)) {
throw new IllegalArgumentException("Unsupported texture type: " + (texture == null ? "null" : texture.getClass()));
}
if (!(texture instanceof GeneratedTexture) || blenderContext.getBlenderKey().isLoadGeneratedTextures()) {
Expand All @@ -120,7 +120,7 @@ public void add(Texture texture, TextureBlender textureBlender, int uvCoordinate
}

/**
* This method flattens the texture and creates a single result of Texture2D
* This method flattens the texture and creates a single result of TextureDefault2D
* type.
*
* @param geometry
Expand Down Expand Up @@ -149,7 +149,7 @@ public void flatten(Geometry geometry, Long geometriesOMA, Map<String, List<Vect
if (previousTexture == null) {// the first texture will lead the others to its shape
if (textureData.texture instanceof GeneratedTexture) {
resultTexture = ((GeneratedTexture) textureData.texture).triangulate(mesh, geometriesOMA, textureData.uvCoordinatesType, blenderContext);
} else if (textureData.texture instanceof Texture2D) {
} else if (textureData.texture instanceof TextureDefault2D) {
resultTexture = textureData.texture;

if (textureData.uvCoordinatesType == UVCoordinatesType.TEXCO_UV && userDefinedUVCoordinates != null && userDefinedUVCoordinates.size() > 0) {
Expand All @@ -174,7 +174,7 @@ public void flatten(Geometry geometry, Long geometriesOMA, Map<String, List<Vect
} else {
if (textureData.texture instanceof GeneratedTexture) {
if (!(resultTexture instanceof TriangulatedTexture)) {
resultTexture = new TriangulatedTexture((Texture2D) resultTexture, resultUVS, blenderContext);
resultTexture = new TriangulatedTexture((TextureDefault2D) resultTexture, resultUVS, blenderContext);
resultUVS = null;
previousTexture = resultTexture;
}
Expand All @@ -183,14 +183,14 @@ public void flatten(Geometry geometry, Long geometriesOMA, Map<String, List<Vect
triangulatedTexture.castToUVS((TriangulatedTexture) resultTexture, blenderContext);
triangulatedTexture.blend(textureData.textureBlender, (TriangulatedTexture) resultTexture, blenderContext);
resultTexture = previousTexture = triangulatedTexture;
} else if (textureData.texture instanceof Texture2D) {
if (this.isUVTypesMatch(masterUVCoordinatesType, masterUserUVSetName, textureData.uvCoordinatesType, textureData.uvCoordinatesName) && resultTexture instanceof Texture2D) {
this.scale((Texture2D) textureData.texture, resultTexture.getImage().getWidth(), resultTexture.getImage().getHeight());
} else if (textureData.texture instanceof TextureDefault2D) {
if (this.isUVTypesMatch(masterUVCoordinatesType, masterUserUVSetName, textureData.uvCoordinatesType, textureData.uvCoordinatesName) && resultTexture instanceof TextureDefault2D) {
this.scale((TextureDefault2D) textureData.texture, resultTexture.getImage().getWidth(), resultTexture.getImage().getHeight());
ImageUtils.merge(resultTexture.getImage(), textureData.texture.getImage());
previousTexture = resultTexture;
} else {
if (!(resultTexture instanceof TriangulatedTexture)) {
resultTexture = new TriangulatedTexture((Texture2D) resultTexture, resultUVS, blenderContext);
resultTexture = new TriangulatedTexture((TextureDefault2D) resultTexture, resultUVS, blenderContext);
resultUVS = null;
}
// first triangulate the current texture
Expand All @@ -205,7 +205,7 @@ public void flatten(Geometry geometry, Long geometriesOMA, Map<String, List<Vect
TemporalMesh geometries = (TemporalMesh) blenderContext.getLoadedFeature(geometriesOMA, LoadedDataType.TEMPORAL_MESH);
textureUVS = UVCoordinatesGenerator.generateUVCoordinatesFor2DTexture(mesh, textureData.uvCoordinatesType, textureData.projectionType, geometries);
}
TriangulatedTexture triangulatedTexture = new TriangulatedTexture((Texture2D) textureData.texture, textureUVS, blenderContext);
TriangulatedTexture triangulatedTexture = new TriangulatedTexture((TextureDefault2D) textureData.texture, textureUVS, blenderContext);
// then move the texture to different UV's
triangulatedTexture.castToUVS((TriangulatedTexture) resultTexture, blenderContext);
// merge triangulated textures
Expand Down Expand Up @@ -259,7 +259,7 @@ public TextureCubeMap generateSkyTexture(ColorRGBA horizontalColor, ColorRGBA ze
LOGGER.fine("Computing the texture size.");
int size = -1;
for (TextureData textureData : textureDatas) {
if (textureData.texture instanceof Texture2D) {
if (textureData.texture instanceof TextureDefault2D) {
size = Math.max(textureData.texture.getImage().getWidth(), size);
size = Math.max(textureData.texture.getImage().getHeight(), size);
}
Expand Down Expand Up @@ -354,7 +354,7 @@ private boolean isUVTypesMatch(UVCoordinatesType type1, String uvSetName1, UVCoo
private void blend(Texture texture, TextureBlender textureBlender, BlenderContext blenderContext) {
if (texture instanceof TriangulatedTexture) {
((TriangulatedTexture) texture).blend(textureBlender, null, blenderContext);
} else if (texture instanceof Texture2D) {
} else if (texture instanceof TextureDefault2D) {
Image blendedImage = textureBlender.blend(texture.getImage(), null, blenderContext);
texture.setImage(blendedImage);
} else {
Expand Down Expand Up @@ -490,7 +490,7 @@ private boolean isWithoutAlpha(TextureData textureData, BlenderContext blenderCo
* @param height
* new height of the texture
*/
private void scale(Texture2D texture, int width, int height) {
private void scale(TextureDefault2D texture, int width, int height) {
// first determine if scaling is required
boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height;

Expand Down
6 changes: 3 additions & 3 deletions jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/TextureHelper.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.MinFilter;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.texture.Texture2D;
import com.jme3.texture.TextureDefault2D;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;

Expand Down Expand Up @@ -250,11 +250,11 @@ public Texture loadImageAsTexture(Structure imageStructure, int imaflag, Blender
blenderContext.getInputStream().setPosition(dataFileBlock.getBlockPosition());

// Should the texture be flipped? It works for sinbad ..
result = new Texture2D(new ImageLoader().loadImage(blenderContext.getInputStream(), dataFileBlock.getBlockPosition(), true));
result = new TextureDefault2D(new ImageLoader().loadImage(blenderContext.getInputStream(), dataFileBlock.getBlockPosition(), true));
}
}
//} else {
// result = new Texture2D(im);
// result = new TextureDefault2D(im);
// }

if (result != null) {// render result is not being loaded
Expand Down
20 changes: 10 additions & 10 deletions jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/TriangulatedTexture.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;
import java.util.TreeSet;

import com.jme3.texture.TextureDefault2D;
import jme3tools.converters.ImageToAwt;

import com.jme3.bounding.BoundingBox;
Expand All @@ -30,7 +31,6 @@
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;

Expand All @@ -41,7 +41,7 @@
*
* @author Marcin Roguski (Kaelthas)
*/
/* package */class TriangulatedTexture extends Texture2D {
/* package */class TriangulatedTexture extends TextureDefault2D {
/** The result image format. */
private Format format;
/** The collection of images for each face. */
Expand All @@ -54,20 +54,20 @@
/** A variable that can prevent removing identical textures. */
private boolean keepIdenticalTextures = false;
/** The result texture. */
private Texture2D resultTexture;
private TextureDefault2D resultTexture;
/** The result texture's UV coordinates. */
private List<Vector2f> resultUVS;

/**
* This method triangulates the given flat texture. The given texture is not
* changed.
*
* @param texture2d
* @param textureDefault2D
* the texture to be triangulated
* @param uvs
* the UV coordinates for each face
*/
public TriangulatedTexture(Texture2D texture2d, List<Vector2f> uvs, BlenderContext blenderContext) {
public TriangulatedTexture(TextureDefault2D textureDefault2D, List<Vector2f> uvs, BlenderContext blenderContext) {
maxTextureSize = blenderContext.getBlenderKey().getMaxTextureSize();
faceTextures = new TreeSet<TriangleTextureElement>(new Comparator<TriangleTextureElement>() {
public int compare(TriangleTextureElement o1, TriangleTextureElement o2) {
Expand All @@ -76,9 +76,9 @@ public int compare(TriangleTextureElement o1, TriangleTextureElement o2) {
});
int facesCount = uvs.size() / 3;
for (int i = 0; i < facesCount; ++i) {
faceTextures.add(new TriangleTextureElement(i, texture2d.getImage(), uvs, true, blenderContext));
faceTextures.add(new TriangleTextureElement(i, textureDefault2D.getImage(), uvs, true, blenderContext));
}
format = texture2d.getImage().getFormat();
format = textureDefault2D.getImage().getFormat();
}

/**
Expand Down Expand Up @@ -179,7 +179,7 @@ public void castToUVS(TriangulatedTexture targetTexture, BlenderContext blenderC
* computed vefore)
* @return flat result texture (all images merged into one)
*/
public Texture2D getResultTexture(boolean rebuild) {
public TextureDefault2D getResultTexture(boolean rebuild) {
if (resultTexture == null || rebuild) {
// sorting the parts by their height (from highest to the lowest)
List<TriangleTextureElement> list = new ArrayList<TriangleTextureElement>(faceTextures);
Expand Down Expand Up @@ -244,7 +244,7 @@ public int compare(TriangleTextureElement o1, TriangleTextureElement o2) {
}

Image resultImage = new Image(format, resultImageWidth, resultImageHeight, BufferUtils.createByteBuffer(resultImageWidth * resultImageHeight * (format.getBitsPerPixel() >> 3)), ColorSpace.Linear);
resultTexture = new Texture2D(resultImage);
resultTexture = new TextureDefault2D(resultImage);
for (Entry<TriangleTextureElement, Integer[]> entry : imageLayoutData.entrySet()) {
if (!duplicatedFaceIndexes.contains(entry.getKey().faceIndex)) {
this.draw(resultImage, entry.getKey().image, entry.getValue()[0], entry.getValue()[1]);
Expand All @@ -263,7 +263,7 @@ public int compare(TriangleTextureElement o1, TriangleTextureElement o2) {
/**
* @return the result flat texture
*/
public Texture2D getResultTexture() {
public TextureDefault2D getResultTexture() {
return this.getResultTexture(false);
}

Expand Down
8 changes: 4 additions & 4 deletions jme3-core/src/main/java/com/jme3/font/BitmapTextPage.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.texture.Texture2D;
import com.jme3.texture.TextureDefault2D;
import com.jme3.util.BufferUtils;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
Expand All @@ -54,7 +54,7 @@ class BitmapTextPage extends Geometry {
private final short[] idx;
private final byte[] color;
private final int page;
private final Texture2D texture;
private final TextureDefault2D texture;
private final LinkedList<LetterQuad> pageQuads = new LinkedList<LetterQuad>();

BitmapTextPage(BitmapFont font, boolean arrayBased, int page) {
Expand All @@ -73,7 +73,7 @@ class BitmapTextPage extends Geometry {
}

setMaterial(mat);
this.texture = (Texture2D) mat.getTextureParam("ColorMap").getTextureValue();
this.texture = (TextureDefault2D) mat.getTextureParam("ColorMap").getTextureValue();

// initialize buffers
Mesh m = getMesh();
Expand Down Expand Up @@ -112,7 +112,7 @@ class BitmapTextPage extends Geometry {
this(font, false, 0);
}

Texture2D getTexture() {
TextureDefault2D getTexture() {
return texture;
}

Expand Down
25 changes: 13 additions & 12 deletions jme3-core/src/main/java/com/jme3/post/Filter.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
import com.jme3.texture.TextureDefault2D;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
Expand Down Expand Up @@ -82,8 +83,8 @@ public Filter(String name) {
public class Pass {

protected FrameBuffer renderFrameBuffer;
protected Texture2D renderedTexture;
protected Texture2D depthTexture;
protected TextureDefault2D renderedTexture;
protected TextureDefault2D depthTexture;
protected Material passMaterial;

/**
Expand All @@ -99,18 +100,18 @@ public void init(Renderer renderer, int width, int height, Format textureFormat,
Collection<Caps> caps = renderer.getCaps();
if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample) && caps.contains(Caps.OpenGL31)) {
renderFrameBuffer = new FrameBuffer(width, height, numSamples);
renderedTexture = new Texture2D(width, height, numSamples, textureFormat);
renderedTexture = new TextureDefault2D(width, height, numSamples, textureFormat);
renderFrameBuffer.setDepthBuffer(depthBufferFormat);
if (renderDepth) {
depthTexture = new Texture2D(width, height, numSamples, depthBufferFormat);
depthTexture = new TextureDefault2D(width, height, numSamples, depthBufferFormat);
renderFrameBuffer.setDepthTexture(depthTexture);
}
} else {
renderFrameBuffer = new FrameBuffer(width, height, 1);
renderedTexture = new Texture2D(width, height, textureFormat);
renderedTexture = new TextureDefault2D(width, height, textureFormat);
renderFrameBuffer.setDepthBuffer(depthBufferFormat);
if (renderDepth) {
depthTexture = new Texture2D(width, height, depthBufferFormat);
depthTexture = new TextureDefault2D(width, height, depthBufferFormat);
renderFrameBuffer.setDepthTexture(depthTexture);
}
}
Expand Down Expand Up @@ -170,15 +171,15 @@ public void setRenderFrameBuffer(FrameBuffer renderFrameBuffer) {
this.renderFrameBuffer = renderFrameBuffer;
}

public Texture2D getDepthTexture() {
public TextureDefault2D getDepthTexture() {
return depthTexture;
}

public Texture2D getRenderedTexture() {
public TextureDefault2D getRenderedTexture() {
return renderedTexture;
}

public void setRenderedTexture(Texture2D renderedTexture) {
public void setRenderedTexture(TextureDefault2D renderedTexture) {
this.renderedTexture = renderedTexture;
}

Expand Down Expand Up @@ -379,15 +380,15 @@ protected void setRenderFrameBuffer(FrameBuffer renderFrameBuffer) {
* returns the rendered texture of this filter
* @return
*/
protected Texture2D getRenderedTexture() {
protected TextureDefault2D getRenderedTexture() {
return defaultPass.renderedTexture;
}

/**
* sets the rendered texture of this filter
* @param renderedTexture
*/
protected void setRenderedTexture(Texture2D renderedTexture) {
protected void setRenderedTexture(TextureDefault2D renderedTexture) {
this.defaultPass.renderedTexture = renderedTexture;
}

Expand Down
Loading

0 comments on commit ec47807

Please sign in to comment.