Skip to main content

Problems with multiple Textures (using TextureUnitStates)

4 replies [Last post]
Patter
Offline
Joined: 2012-02-19
Points: 0

I have some trouble with code working on one computer under XP but not on another machine where both Win7 and Linux (OpenSuse 12.1) is installed. One thing doesn't work under neither OS on that machine: Textures set to a TextureUnitState are not shown anymore (no Exception is thrown). I want to show projections of images from the six sides of a box virtually sourrounding my object (Shape3D) onto that object (plus one "individual" texture). Some details of how I'm doing this:

PolygonAttributes for the Appearance of my Shape3D:

new PolygonAttributes(PolygonAttributes.POLYGON_FILL,  PolygonAttributes.CULL_BACK, 0.0f);

TextureUnitStates are created for the 7 sides:

final TextureUnitState[] textureUnitStates = new TextureUnitState[SIDES.length];
for (final int side : SIDES) {
        final TextureAttributes texturing = new TextureAttributes();
        texturing.setTextureMode(TextureAttributes.MODULATE);
        textureUnitStates[side] = new TextureUnitState(null, texturing, null); // no TexCoordGeneration (null) => use the coordinates provided with the geometry!
        textureUnitStates[side].setCapability(TextureUnitState.ALLOW_STATE_WRITE);
}
appearance.setTextureUnitState(textureUnitStates);

I've also tried to use a TexCoordGeneration object here (with no luck).
A QuadArray defines the geometry of my Shape3D:

new QuadArray(numberOfPoints, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2, numOfTextures, texCoordSetMap);

where numOfTextures is 7 and texCoordSetMap simply is an identity mapping (textCoordSetMap[i] = i, for all i in 0...6)
Finally the coordinates and texture coordinates are created like this (for all points and the 6+1 "sides"):

quadArray1.setCoordinate(i1, point);
...
quadArray1.setTextureCoordinate(side, i2, new TexCoord2f((float)(v1.x * fx + dx), (float)(v1.y * fy + dy)));
...

Then the textures should be set (and dynamically changed) by:

shape.getAppearance().getTextureUnitState(side).setTexture(texture);

Unfortunalely this has no visible effect. As I mentioned before it works just fine on another machine. I could also set one texture directly to the Appearance by Appearance.setTexture(texture) but I couldn't get the TextureUnitState thing to work. Curretly I have absolutely no idea what I should try next, so any hint would be highly appreciated...

Thanks in advance,
Patter

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
interactivemesh
Offline
Joined: 2006-06-07
Points: 0

Did you check up your graphical environment on the supported number of texture coordinates sets and unit states?

java.util.Map propMap = myCanvas3D.queryProperties();

int maxTexCoordSets = (int)propMap.get("textureCoordSetsMax");
int maxTexUnitStates = (int)propMap.get("textureUnitStateMax");
August

Patter
Offline
Joined: 2012-02-19
Points: 0

Yeah, that's it! Thank you very much! I never thought that my new "baby" could be more limited than the old one...

Old computer:
textureUnitStateMax = 8
textureCoordSetsMax = 8

New one:
textureUnitStateMax = 4 <- and I always tried to set only the 7th texture *grmpf* :-)
textureCoordSetsMax = 8

Is it always possible to define more TextureUnitStates than given by textureUnitStateMax and those which are over that limit just won't be used? I mean without the risk of getting error messages and/or exceptions?

Thanks again,
Patter

interactivemesh
Offline
Joined: 2006-06-07
Points: 0

After checking the source code (see TextureBin.updateAttributes(Canvas3D cv)) it seems none of the texture units are being used (silently) if their number exceeds 'textureUnitStateMax'. August

Patter
Offline
Joined: 2012-02-19
Points: 0

Good to know, many thanks again!

In the meanwhile I changed my code slightly, such that I need at most 4 textures: one "individual" texture + 3 projections from the six sides of a box virtually sourrounding the scene. This is ok, since I do not need to set textures from two opposite sides (e.g. from the left AND from the right side of that box) on the same shape (at the same time). If 'textureUnitStateMax' is even less than 4, a warning will be displayed now. It's really a relief that the creation of TextureUnitStates and coordinates etc. could stay unmodified then...

Kind regards,
Patter