public class SoIndexedTexture2 extends SoTexture
SoTexture2
, each texel contains a color value that is directly applied to the geometry. In this node each texel contains a
data value that is mapped to a color value using the color map defined by the current SoColorMap
node.
This image is stored in the current texture unit (see SoTextureUnit
) and the texture is applied to subsequent shapes as they are rendered.
The image data is stored in an SoSFArray2D
. This array can contain different types of data (UNSIGNED_BYTE, UNSIGNED_SHORT, UNSIGNED_INT32, SIGNED_BYTE, SIGNED_SHORT, SIGNED_INT32, FLOAT).
When Open Inventor creates the OpenGL texture image from the data array, the data values must be scaled into the range of values of the texture (0-255 for an 8-bit indexed texture). The minValue
and maxValue
fields specify the range of data values that will be scaled into the range of texture values. For example, if minValue
is set to 10000 and maxValue
to 38000, all values less than or equal to 10000 will be mapped to the entry 0 of the color map and all values greater than or equal to 38000 to the last entry. The image below illustrates the process of mapping and shows how it can be used to map only the used data range to the color map:
If minValue
or maxValue
change, then the OpenGL texture must be recreated. If the texture is large, this may be time consuming. Generally it's more efficient to modify the SoColorMap
node because the OpenGL texture corresponding to the data does not need to be recreated
NOTE: Texture data values are stored with 12 bits of precision instead of the usual 8 bits, when:
The following example shows how to apply an indexed texture on a geometry node:
SoColorMap colorMap = new SoColorMap(); colorMap.predefinedColorMap.setValue( SoColorMap.PredefinedColorMaps.TEMPERATURE ); colorMap.min.setValue( -1000 ); colorMap.max.setValue( 20000 ); SoIndexedTexture2 indexedTexture = new SoIndexedTexture2(); indexedTexture.imageIndex.setValue(size, SoSFArray.DataTypes.SIGNED_SHORT, data); root.addChild( colorMap ); root.addChild( indexedTexture ); root.addChild( geometry );
On graphics cards supporting
ARB_fragment_program , the model
field will be ignored and multitexturing will not work. It is possible to circumvent this limitation by using a custom shader. The following GLSL code shows how to do multitexturing between two indexed textures sharing the same color map:
The scene graph would be initialized like this:// Fragment shader uniform sampler2D colormap; uniform sampler2D indexedTex1; uniform sampler2D indexedTex2; void main() { // Fetch first value and its assigned color float value1 = texture2D(indexedTex1, gl_TexCoord[0].xy).x; vec4 color1 = texture2D(colormap, vec2(value1, 0)); // Fetch second and its assigned color float value2 = texture2D(indexedTex2, gl_TexCoord[0].xy).x; vec4 color2 = texture2D(colormap, vec2(value2, 0)); // Combine the colors gl_FragColor = color1 * color2 * gl_Color; }
File format/default:SoColorMap colorMap = new SoColorMap(); . . . SoIndexedTexture2 indexedTex1 = new SoIndexedTexture2(); . . . SoIndexedTexture2 indexedTex2 = new SoIndexedTexture2(); . . . SoFragmentShader fragShader = new SoFragmentShader(); fragShader.sourceProgram.setValue( "filename.glsl" ); SoShaderParameter1i parameter = new SoShaderParameter1i(); parameter.name.setValue( "colorMap" ); parameter.value.setValue( 0 ); fragShader.parameter.set1Value( 0, parameter ); parameter = new SoShaderParameter1i(); parameter.name.setValue( "indexedTex1" ); parameter.value.setValue( 1 ); fragShader.parameter.set1Value( 1, parameter ); parameter = new SoShaderParameter1i(); parameter.name.setValue( "indexedTex2" ); parameter.value.setValue( 2 ); fragShader.parameter.set1Value( 2, parameter ); SoShaderProgram shaderProgram = new SoShaderProgram(); shaderProgram.shaderObject.setValue(fragShader); SoTextureUnit textureUnit = new SoTextureUnit(); textureUnit.unit.setValue( 2 ); //Texture unit for the second indexed texture root.addChild(colorMap); //Color map must come first (texture unit 1) root.addChild(indexedTex1); //First indexed texture (texture unit 0) root.addChild(textureUnit); root.addChild(indexedTex2); //Second indexed texture (texture unit 2) root.addChild(shaderProgram); root.addChild(geometry);
IndexedTexture2 {
minValue | 0 |
maxValue | 0 |
imageIndex | 0 0 |
rescaleTexCoord | false |
wrapS | REPEAT |
wrapT | REPEAT |
model | MODULATE |
blendColor | 0 0 0 |
enableBorder | false |
borderColor | 0 0 0 0 |
maxAnisotropy | 1.0 |
minFilter | AUTO |
magFilter | AUTO |
useAutoMipmap | false |
internalFormat | AUTO_INTERNAL_FORMAT |
Action behavior:
SoGLRenderAction
, SoCallbackAction
Sets: SoTextureImageElement
See also:
SoTexture2Transform
, SoTextureCoordinate2
, SoTextureCoordinateFunction
, SoColorMap
, SoSFArray2D
.
SoTexture.FileTypes, SoTexture.Filters, SoTexture.HW_Features, SoTexture.InternalFormats, SoTexture.Models, SoTexture.WrapType
SoNode.RenderModes
Inventor.ConstructorCommand
Modifier and Type | Field and Description |
---|---|
SoSFArray2D |
imageIndex
This field contains the in-memory representation of the indexed texture image.
|
SoSFFloat |
maxValue
See
minValue . |
SoSFFloat |
minValue
Specifies the range of values which is mapped onto the color map (see
SoColorMap ). |
SoSFBool |
rescaleTexCoord
This field controls the way an image with non-power-of-two dimension is handled:
If the graphics card supports
GL_ARB_texture_non_power_of_two , this field is ignored and the image is sent directly to OpenGL.
|
SoSFEnum<SoTexture.WrapType> |
wrapT
Indicates what to do when texture coordinates in the T (vertical) direction lie outside the range 0-1.
|
blendColor, borderColor, enableBorder, enableCompressedTexture, internalFormat, magFilter, maxAnisotropy, minFilter, model, wrapS
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoIndexedTexture2()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
computeDataRange()
|
getBitmapFileType, isSupported, readTexture, readTexture, setBitmapFileType
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderEngineMode, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
getNativeResourceHandle
public final SoSFFloat minValue
SoColorMap
).
When minValue
and maxValue
are equal to 0 (the default), the entire range of the data type is mapped onto the color map, except in the case of float data. For example, for a color map of size N:
minValue
will be mapped to the first entry of the color map. Likewise, all values greater than or equal to maxValue
will be mapped to the last entry of the color map.public final SoSFArray2D imageIndex
public final SoSFBool rescaleTexCoord
rescaleTexCoord
is false (the default), the image is rescaled to the next lower power-of-two dimensions. The scaling is done with a box filter.
rescaleTexCoord
is true, the image is not rescaled but is only copied into a texture with the next higher power-of-two dimension, and its texture coordinates are scaled by applying a texture transform in order to only display the actual image.
Default is false.
When this field is enabled, if other texture transforms are applied to the texture coordinates (especially if the texture is repeated), the unused part of the larger texture could be displayed. Furthermore, in this mode, if non-power-of-two textures occur one after another in the scene graph, an incorrect image may result because texture transforms are cumulative. For example, the following code would give incorrect results:
The correct way is to use a separator above each texture, as shown:root.addChild( colorMap ); root.addChild( nonPowerOfTwoIndexedTexture1 ); root.addChild( nonPowerOfTwoIndexedTexture2 ); root.addChild( nonPowerOfTwoIndexedTexture3 );
root.addChild( colorMap ); root.addChild( separator1 ); separator1.addChild( nonPowerOfTwoIndexedTexture1 ); root.addChild( separator2 ); separator2.addChild( nonPowerOfTwoIndexedTexture2 ); root.addChild( separator3 ); separator3.addChild( nonPowerOfTwoIndexedTexture3 );
public final SoSFEnum<SoTexture.WrapType> wrapT
Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com