📄 textureattributesretained.java
字号:
/* * $RCSfile: TextureAttributesRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.7 $ * $Date: 2007/04/12 17:34:07 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.Color4f;import java.util.ArrayList;/** * The TextureAttributes object defines attributes that apply to * to texture mapping. */class TextureAttributesRetained extends NodeComponentRetained { // A list of pre-defined bits to indicate which component // in this TextureAttributes object changed. static final int TRANSFORM_CHANGED = 0x0001; static final int MODE_CHANGED = 0x0002; static final int COLOR_CHANGED = 0x0004; static final int CORRECTION_CHANGED = 0x0008; static final int TEXTURE_COLOR_TABLE_CHANGED = 0x0010; static final int COMBINE_RGB_MODE_CHANGED = 0x0020; static final int COMBINE_ALPHA_MODE_CHANGED = 0x0040; static final int COMBINE_RGB_SRC_CHANGED = 0x0080; static final int COMBINE_ALPHA_SRC_CHANGED = 0x0100; static final int COMBINE_RGB_FCN_CHANGED = 0x0200; static final int COMBINE_ALPHA_FCN_CHANGED = 0x0400; static final int COMBINE_RGB_SCALE_CHANGED = 0x0800; static final int COMBINE_ALPHA_SCALE_CHANGED = 0x1000; // static class variable for commands used in messages static Integer commandInt[] = null; // static class variable for enums. Currently only supports 0 - 9. static Integer enums[] = null; // Texture transform Transform3D transform = new Transform3D(); // Texture mode int textureMode = TextureAttributes.REPLACE; // Texture blend color Color4f textureBlendColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f); // Texture color table int textureColorTable[] = null; int numTextureColorTableComponents = 0; int textureColorTableSize = 0; // Texture Combine Mode int combineRgbMode = TextureAttributes.COMBINE_MODULATE; int combineAlphaMode = TextureAttributes.COMBINE_MODULATE; // the following fields are only applicable if textureMode specifies // COMBINE. If COMBINE mode is specified, then each of the following // fields will be referencing an array of 3 integers, each representing // an operand in the combine equation. int [] combineRgbSrc = null; int [] combineAlphaSrc = null; int [] combineRgbFcn = null; int [] combineAlphaFcn = null; int combineRgbScale = 1; int combineAlphaScale = 1; //Perspective correction mode, used for color/texCoord interpolation int perspCorrectionMode = TextureAttributes.NICEST; // true when mirror texCoord component set boolean mirrorCompDirty = false; static final void initTextureEnums() { // create some of the enums Integer to be used in the messages // this can be eliminated if the message is modified to take // integer itself // // NOTE: check with the actual enum value before using this // list. This list only supports 0 - 9 if (enums == null) { enums = new Integer[10]; for (int i = 0; i < 10; i++) { enums[i] = new Integer(i); } } } TextureAttributesRetained() { initTextureEnums(); } // initCombineMode -- initializes the combine mode related fields // delay the allocation of memory to minimize // memory footprint final void initCombineMode(TextureAttributesRetained tr) { tr.combineRgbSrc = new int[3]; tr.combineAlphaSrc = new int[3]; tr.combineRgbFcn = new int[3]; tr.combineAlphaFcn = new int[3]; //default values tr.combineRgbSrc[0] = TextureAttributes.COMBINE_TEXTURE_COLOR; tr.combineRgbSrc[1] = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE; tr.combineRgbSrc[2] = TextureAttributes.COMBINE_CONSTANT_COLOR; tr.combineAlphaSrc[0] = TextureAttributes.COMBINE_TEXTURE_COLOR; tr.combineAlphaSrc[1] = TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE; tr.combineAlphaSrc[2] = TextureAttributes.COMBINE_CONSTANT_COLOR; tr.combineRgbFcn[0] = TextureAttributes.COMBINE_SRC_COLOR; tr.combineRgbFcn[1] = TextureAttributes.COMBINE_SRC_COLOR; tr.combineRgbFcn[2] = TextureAttributes.COMBINE_SRC_COLOR; tr.combineAlphaFcn[0] = TextureAttributes.COMBINE_SRC_ALPHA; tr.combineAlphaFcn[1] = TextureAttributes.COMBINE_SRC_ALPHA; tr.combineAlphaFcn[2] = TextureAttributes.COMBINE_SRC_ALPHA; } final void initTextureMode(int textureMode) { this.textureMode = textureMode; if (textureMode == TextureAttributes.COMBINE) { if (combineRgbSrc == null) { initCombineMode(this); } } } /** * Sets the texture mode parameter for this * appearance component object. * @param textureMode the texture mode, one of: MODULATE, * DECAL, BLEND, or REPLACE */ final void setTextureMode(int textureMode) { initTextureMode(textureMode); sendMessage(MODE_CHANGED, enums[textureMode], null); } /** * Gets the texture mode parameter for this * texture attributes object. * @return textureMode the texture mode */ final int getTextureMode() { return textureMode; } final void initTextureBlendColor(Color4f textureBlendColor) { this.textureBlendColor.set(textureBlendColor); } /** * Sets the texture blend color for this * texture attributes object. * @param textureBlendColor the texture blend color used when * the mode is BLEND */ final void setTextureBlendColor(Color4f textureBlendColor) { this.textureBlendColor.set(textureBlendColor); sendMessage(COLOR_CHANGED, new Color4f(textureBlendColor), null); } final void initTextureBlendColor(float r, float g, float b, float a) { this.textureBlendColor.set(r, g, b, a); } /** * Sets the texture blend color for this * appearance component object. This color is used when * the mode is BLEND. * @param r the red component of the color * @param g the green component of the color * @param b the blue component of the color * @param a the alpha component of the color */ final void setTextureBlendColor(float r, float g, float b, float a) { this.textureBlendColor.set(r, g, b, a); sendMessage(COLOR_CHANGED, new Color4f(r, g, b, a), null); } /** * Gets the texture blend color for this * appearance component object. * @param textureBlendColor the vector that will receive the texture * blend color used when the mode is BLEND */ final void getTextureBlendColor(Color4f textureBlendColor) { textureBlendColor.set(this.textureBlendColor); } final void initTextureTransform(Transform3D transform) { this.transform.set(transform); } /** * Sets the texture transform object used to transform texture * coordinates. A copy of the specified Transform3D object is * stored in this TextureAttributes object. * @param transform the new transform object */ final void setTextureTransform(Transform3D transform) { this.transform.set(transform); sendMessage(TRANSFORM_CHANGED, new Transform3D(transform), null); } /** * Retrieves a copy of the texture transform object. * @param transform the transform object that will receive the * current texture transform. */ final void getTextureTransform(Transform3D transform) { transform.set(this.transform); } final void initPerspectiveCorrectionMode(int mode) { this.perspCorrectionMode = mode; } /** * Sets perspective correction mode to be used for color * and/or texture coordinate interpolation. * A value of NICEST indicates that perspective correction should be * performed and that the highest quality method should be used. * A value of FASTEST indicates that the most efficient perspective * correction method should be used. * @param mode one of NICEST or FASTEST. * The default value is NICEST. */ final void setPerspectiveCorrectionMode(int mode) { this.perspCorrectionMode = mode; sendMessage(CORRECTION_CHANGED, enums[mode], null); } /** * Gets perspective correction mode value. * @return mode the value of perspective correction mode. */ final int getPerspectiveCorrectionMode() { return perspCorrectionMode; } final void setTextureColorTable(int[][] table) { initTextureColorTable(table); //clone a copy of the texture for the mirror object if (table == null) { sendMessage(TEXTURE_COLOR_TABLE_CHANGED, null, null); } else { int ctable[] = new int[textureColorTableSize * numTextureColorTableComponents]; System.arraycopy(textureColorTable, 0, ctable, 0, textureColorTable.length); Object args[] = new Object[3]; args[0] = new Integer(numTextureColorTableComponents); args[1] = new Integer(textureColorTableSize); args[2] = ctable; sendMessage(TEXTURE_COLOR_TABLE_CHANGED, args, null); } } final void initTextureColorTable(int[][] table) { numTextureColorTableComponents = 0; textureColorTableSize = 0; if (table == null) { textureColorTable = null; return; } if (table.length < 3 || table.length > 4) { throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes13")); } if (Texture.getPowerOf2(table[0].length) == -1) { throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes14")); } for (int i = 1; i < table.length; i++) { if (table[i].length != table[0].length) throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes15")); } numTextureColorTableComponents = table.length; textureColorTableSize = table[0].length; if (textureColorTable == null || textureColorTable.length != numTextureColorTableComponents * textureColorTableSize) { textureColorTable = new int[numTextureColorTableComponents * textureColorTableSize]; } int k = 0; for (int i = 0; i < textureColorTableSize; i++) { for (int j = 0; j < numTextureColorTableComponents; j++) { textureColorTable[k++] = table[j][i]; } } } final void getTextureColorTable(int[][] table) { if (textureColorTable == null) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -