📄 textureretained.java
字号:
(filter4FuncPts.length != weights.length)) { filter4FuncPts = new float[weights.length]; } for (int i = 0; i < weights.length; i++) { filter4FuncPts[i] = weights[i]; } } } final int getFilter4FuncPointsCount() { if (filter4FuncPts == null) { return 0; } else { return filter4FuncPts.length; } } final void getFilter4Func(float[] weights) { if (filter4FuncPts != null) { for (int i = 0; i < filter4FuncPts.length; i++) { weights[i] = filter4FuncPts[i]; } } } /** * internal method only -- returns internal function points */ final float[] getSharpenTextureFunc() { return sharpenTextureFuncPts; } final float[] getFilter4Func(){ return filter4FuncPts; } void setLive(boolean backgroundGroup, int refCount) { // This line should be assigned before calling doSetLive, so that // the mirror object's enable is assigned correctly! enable = userSpecifiedEnable; super.doSetLive(backgroundGroup, refCount); // XXXX: for now, do setLive for all the defined images. // But in theory, we only need to setLive those within the // baseLevel and maximumLevel range. But then we'll need // setLive and clearLive image when the range changes. if (images != null) { for (int j = 0; j < numFaces; j++) { for (int i = 0; i < maxLevels; i++){ if (images[j][i] == null) { throw new IllegalArgumentException( J3dI18N.getString("TextureRetained3") + i); } images[j][i].setLive(backgroundGroup, refCount); } } } // Issue 172 : assertion check the sizes of the images after we have // checked for all mipmap levels being set if (images != null) { for (int j = 0; j < numFaces; j++) { checkSizes(images[j]); } } // Send a message to Rendering Attr stucture to update the resourceMask J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.TEXTURE_CHANGED; createMessage.args[0] = this; createMessage.args[1]= new Integer(UPDATE_IMAGE); createMessage.args[2] = null; createMessage.args[3] = new Integer(changedFrequent); VirtualUniverse.mc.processMessage(createMessage); // If the user has set enable to true, then if the image is null // turn off texture enable if (userSpecifiedEnable) { if (images != null) { for (int j = 0; j < numFaces && enable; j++) { for (int i = baseLevel; i <= maximumLevel && enable; i++){ if (images[j][i].isByReference()) { if (images[j][i].getRefImage(0) == null) { enable = false; } } else { if (images[j][i].getImageData(isUseAsRaster()).get() == null) { enable = false; } } } } } else { enable = false; } if (!enable) sendMessage(ENABLE_CHANGED, Boolean.FALSE); } super.markAsLive(); } void clearLive(int refCount) { super.clearLive(refCount); if (images != null) { for (int j = 0; j < numFaces; j++) { for (int i = 0; i < maxLevels; i++) { images[j][i].clearLive(refCount); images[j][i].removeUser(mirror); } } } } /* * The following methods update the native context. * The implementation for Texture2D happens here. * Texture3D and TextureCubeMap implement their own versions. */ void bindTexture(Context ctx, int objectId, boolean enable) { Pipeline.getPipeline().bindTexture2D(ctx, objectId, enable); } void updateTextureBoundary(Context ctx, int boundaryModeS, int boundaryModeT, float boundaryRed, float boundaryGreen, float boundaryBlue, float boundaryAlpha) { Pipeline.getPipeline().updateTexture2DBoundary(ctx, boundaryModeS, boundaryModeT, boundaryRed, boundaryGreen, boundaryBlue, boundaryAlpha); } void updateTextureFilterModes(Context ctx, int minFilter, int magFilter) { Pipeline.getPipeline().updateTexture2DFilterModes(ctx, minFilter, magFilter); } void updateTextureSharpenFunc(Context ctx, int numSharpenTextureFuncPts, float[] sharpenTextureFuncPts) { Pipeline.getPipeline().updateTexture2DSharpenFunc(ctx, numSharpenTextureFuncPts, sharpenTextureFuncPts); } void updateTextureFilter4Func(Context ctx, int numFilter4FuncPts, float[] filter4FuncPts) { Pipeline.getPipeline().updateTexture2DFilter4Func(ctx, numFilter4FuncPts, filter4FuncPts); } void updateTextureAnisotropicFilter(Context ctx, float degree) { Pipeline.getPipeline().updateTexture2DAnisotropicFilter(ctx, degree); } void updateTextureLodRange(Context ctx, int baseLevel, int maximumLevel, float minimumLod, float maximumLod) { Pipeline.getPipeline().updateTexture2DLodRange(ctx, baseLevel, maximumLevel, minimumLod, maximumLod); } void updateTextureLodOffset(Context ctx, float lodOffsetX, float lodOffsetY, float lodOffsetZ) { Pipeline.getPipeline().updateTexture2DLodOffset(ctx, lodOffsetX, lodOffsetY, lodOffsetZ); } // get an ID for Texture 2D int getTextureId() { return (VirtualUniverse.mc.getTexture2DId()); } // free a Texture2D id void freeTextureId(int id) { synchronized (resourceLock) { if (objectId == id) { objectId = -1; VirtualUniverse.mc.freeTexture2DId(id); } } } private boolean isEnabled(Canvas3D cv) { if(widthOrHeightIsNPOT && !isUseAsRaster() && ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_NON_POWER_OF_TWO ) == 0)) { return false; } return enable; } // bind a named texture to a texturing target void bindTexture(Canvas3D cv) { synchronized(resourceLock) { if (objectId == -1) { objectId = getTextureId(); } cv.addTextureResource(objectId, this); } bindTexture(cv.ctx, objectId, isEnabled(cv)); } /** * load level 0 explicitly with null pointer to enable * mipmapping when level 0 is not the base level */ void updateTextureDimensions(Canvas3D cv) { if(images[0][0] != null) { updateTextureImage(cv, 0, maxLevels, 0, format, images[0][0].getImageFormatTypeIntValue(false), width, height, boundaryWidth, images[0][0].getImageDataTypeIntValue(), null); } } void updateTextureLOD(Canvas3D cv) { if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_LOD_RANGE) != 0 ) { int max = 0; if( mipmapMode == Texture.BASE_LEVEL ) { max = maxMipMapLevels; } else { max = maximumLevel; } updateTextureLodRange(cv.ctx, baseLevel, max, minimumLod, maximumLod); } if ((lodOffset != null) && ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_LOD_OFFSET) != 0)) { updateTextureLodOffset(cv.ctx, lodOffset.x, lodOffset.y, lodOffset.z); } } void updateTextureBoundary(Canvas3D cv) { updateTextureBoundary(cv.ctx, boundaryModeS, boundaryModeT, boundaryColor.x, boundaryColor.y, boundaryColor.z, boundaryColor.w); } void updateTextureFields(Canvas3D cv) { int magnificationFilter = magFilter; int minificationFilter = minFilter; // update sharpen texture function if applicable if ((magnificationFilter >= Texture.LINEAR_SHARPEN) && (magnificationFilter <= Texture.LINEAR_SHARPEN_ALPHA)) { if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_SHARPEN) != 0 ) { // send down sharpen texture LOD function // updateTextureSharpenFunc(cv.ctx, numSharpenTextureFuncPts, sharpenTextureFuncPts); } else { // sharpen texture is not supported by the underlying // library, fallback to BASE_LEVEL_LINEAR magnificationFilter = Texture.BASE_LEVEL_LINEAR; } } else if ((magnificationFilter >= Texture2D.LINEAR_DETAIL) && (magnificationFilter <= Texture2D.LINEAR_DETAIL_ALPHA)) { if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_DETAIL) == 0) { // detail texture is not supported by the underlying // library, fallback to BASE_LEVEL_LINEAR magnificationFilter = Texture.BASE_LEVEL_LINEAR; } } if (minificationFilter == Texture.FILTER4 || magnificationFilter == Texture.FILTER4) { boolean noFilter4 = false; if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_FILTER4) != 0) { if (filter4FuncPts == null) { // filter4 function is not defined, // fallback to BASE_LEVEL_LINEAR noFilter4 = true; } else { updateTextureFilter4Func(cv.ctx, filter4FuncPts.length, filter4FuncPts); } } else { // filter4 is not supported by the underlying // library, fallback to BASE_LEVEL_LINEAR noFilter4 = true; } if (noFilter4) { if (minificationFilter == Texture.FILTER4) { minificationFilter = Texture.BASE_LEVEL_LINEAR; } if (magnificationFilter == Texture.FILTER4) { magnificationFilter = Texture.BASE_LEVEL_LINEAR; } } } // Fallback to BASE mode if hardware mipmap generation is not supported. if ((mipmapMode == Texture.BASE_LEVEL) && ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) == 0)) { if (minificationFilter == Texture.NICEST || minificationFilter == Texture.MULTI_LEVEL_LINEAR) { minificationFilter = Texture.BASE_LEVEL_LINEAR; } else if (minificationFilter == Texture.MULTI_LEVEL_POINT) { minificationFilter = Texture.BASE_LEVEL_POINT; } } // update texture filtering modes updateTextureFilterModes(cv.ctx, minificationFilter, magnificationFilter); if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_ANISOTROPIC_FILTER) != 0) { if (anisotropicFilterMode == Texture.ANISOTROPIC_NONE) { updateTextureAnisotropicFilter(cv.ctx, 1.0f); } else { updateTextureAnisotropicFilter(cv.ctx, anisotropicFilterDegree); } } // update texture boundary modes, boundary color updateTextureBoundary(cv); } // Wrapper around the native call for 2D textures; overridden for // TextureCureMap void updateTextureImage(Canvas3D cv, int face, int numLevels, int level, int textureFormat, int imageFormat, int width, int height, int boundaryWidth, int imageDataType, Object data) { Pipeline.getPipeline().updateTexture2DImage(cv.ctx, numLevels, level, textureFormat, imageFormat, width, height, boundaryWidth, imageDataType, data, useAutoMipMapGeneration(cv)); } // Wrapper around the native call for 2D textures; overridden for // TextureCureMap void updateTextureSubImage(Canvas3D cv, int face, int level, int xoffset, int yoffset, int textureFormat, int imageFormat, int imgXOffset, int imgYOffset, int tilew, int width, int height, int imageDataType, Object data) { Pipeline.getPipeline().updateTexture2DSubImage(cv.ctx, level, xoffset, yoffset, textureFormat, imageFormat, imgXOffset, imgYOffset, tilew, width, height, imageDataType, data, useAutoMipMapGeneration(cv)); } /** * reloadTextureImage is used to load a particular level of image * This method needs to take care of RenderedImage as well as * BufferedImage */ void reloadTextureImage(Canvas3D cv, int face, int level, ImageComponentRetained image, int numLevels) { boolean useAsRaster = isUseAsRaster(); ImageComponentRetained.ImageData imageData = image.getImageData(useAsRaster); assert imageData != null; updateTextureImage(cv, face, numLevels, level, format, image.getImageFormatTypeIntValue(useAsRaster), imageData.getWidth(), imageData.getHeight(), boundaryWidth, image.getImageDataTypeIntValue(), imageData.get()); // TODO : Dead code - need to clean up for 1.6 // Now take care of the RenderedImage (byRef and yUp) case. Note, if image // is a RenderedImage ( byRef and yUp), then imageData will be null if (imageData == null) { // System.err.println("==========. subImage"); // Download all the tiles for this texture int xoffset = 0, yoffset = 0; int tmpw = image.width; int tmph = image.height; int endXTile = image.tilew; int endYTile = image.tileh; int curw = endXTile; int curh = endYTile; if (tmpw < curw) { curw = tmpw; } if (tmph < curh) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -