📄 textureretained.java
字号:
if (reloadTexture) { // reload all levels of texture image // update texture parameters such as boundary modes, filtering updateTextureFields(cv); // update texture Lod parameters updateTextureLOD(cv); // update all texture images reloadTexture(cv); if (cv.useSharedCtx) { cv.makeCtxCurrent(cv.ctx); synchronized(resourceLock) { resourceCreationMask |= cv.screen.renderer.rendererBit; resourceUpdatedMask |= cv.screen.renderer.rendererBit; resourceLodUpdatedMask |= cv.screen.renderer.rendererBit; } } else { synchronized(resourceLock) { resourceCreationMask |= cv.canvasBit; resourceUpdatedMask |= cv.canvasBit; resourceLodUpdatedMask |= cv.canvasBit; } } } else if (updateTextureLod || updateTexture) { if (updateTextureLod) { updateTextureLOD(cv); } if (updateTexture) { // update texture image int resourceBit = 0; if (cv.useSharedCtx) { resourceBit = cv.screen.renderer.rendererBit; } else { resourceBit = cv.canvasBit; } // update texture based on the imageComponent update info updateTexture(cv, resourceBit); } // set the appropriate bit in the resource update masks showing // that the resource is up-to-date if (cv.useSharedCtx) { cv.makeCtxCurrent(cv.ctx); synchronized(resourceLock) { resourceUpdatedMask |= cv.screen.renderer.rendererBit; resourceLodUpdatedMask |= cv.screen.renderer.rendererBit; } } else { synchronized(resourceLock) { resourceUpdatedMask |= cv.canvasBit; resourceLodUpdatedMask |= cv.canvasBit; } } } } synchronized void createMirrorObject() { if (mirror == null) { if (this instanceof Texture3DRetained) { Texture3DRetained t3d = (Texture3DRetained)this; Texture3D tex = new Texture3D(t3d.mipmapMode, t3d.format, t3d.width, t3d.height, t3d.depth, t3d.boundaryWidth); mirror = (Texture3DRetained)tex.retained;; } else if (this instanceof TextureCubeMapRetained) { TextureCubeMap tex = new TextureCubeMap(mipmapMode, format, width, boundaryWidth); mirror = (TextureCubeMapRetained)tex.retained; } else { Texture2D tex = new Texture2D(mipmapMode, format, width, height, boundaryWidth); mirror = (Texture2DRetained)tex.retained; } ((TextureRetained)mirror).objectId = -1; } initMirrorObject(); } /** * Initializes a mirror object, point the mirror object to the retained * object if the object is not editable */ synchronized void initMirrorObject() { mirror.source = source; if (this instanceof Texture3DRetained) { Texture3DRetained t3d = (Texture3DRetained)this; ((Texture3DRetained)mirror).boundaryModeR = t3d.boundaryModeR; ((Texture3DRetained)mirror).depth = t3d.depth; } TextureRetained mirrorTexture = (TextureRetained)mirror; mirrorTexture.boundaryModeS = boundaryModeS; mirrorTexture.boundaryModeT = boundaryModeT; mirrorTexture.minFilter = minFilter; mirrorTexture.magFilter = magFilter; mirrorTexture.boundaryColor.set(boundaryColor); mirrorTexture.enable = enable; mirrorTexture.userSpecifiedEnable = enable; mirrorTexture.enable = enable; mirrorTexture.numFaces = numFaces; mirrorTexture.resourceCreationMask = 0x0; mirrorTexture.resourceUpdatedMask = 0x0; mirrorTexture.resourceLodUpdatedMask = 0x0; mirrorTexture.resourceInReloadList = 0x0; // LOD information mirrorTexture.baseLevel = baseLevel; mirrorTexture.maximumLevel = maximumLevel; mirrorTexture.minimumLod = minimumLod; mirrorTexture.maximumLod = maximumLod; mirrorTexture.lodOffset = lodOffset; // sharpen texture LOD function mirrorTexture.numSharpenTextureFuncPts = numSharpenTextureFuncPts; if (sharpenTextureFuncPts == null) { mirrorTexture.sharpenTextureFuncPts = null; } else { if ((mirrorTexture.sharpenTextureFuncPts == null) || (mirrorTexture.sharpenTextureFuncPts.length != sharpenTextureFuncPts.length)) { mirrorTexture.sharpenTextureFuncPts = new float[sharpenTextureFuncPts.length]; } for (int i = 0; i < sharpenTextureFuncPts.length; i++) { mirrorTexture.sharpenTextureFuncPts[i] = sharpenTextureFuncPts[i]; } } // filter4 function if (filter4FuncPts == null) { mirrorTexture.filter4FuncPts = null; } else { if ((mirrorTexture.filter4FuncPts == null) || (mirrorTexture.filter4FuncPts.length != filter4FuncPts.length)) { mirrorTexture.filter4FuncPts = new float[filter4FuncPts.length]; } for (int i = 0; i < filter4FuncPts.length; i++) { mirrorTexture.filter4FuncPts[i] = filter4FuncPts[i]; } } // Anisotropic Filter mirrorTexture.anisotropicFilterMode = anisotropicFilterMode; mirrorTexture.anisotropicFilterDegree = anisotropicFilterDegree; mirrorTexture.maxLevels = maxLevels; if (images != null) { for (int j = 0; j < numFaces; j++) { for (int i = 0; i < maxLevels; i++) { mirrorTexture.images[j][i] = images[j][i]; // add texture to the userList of the images if (images[j][i] != null) { images[j][i].addUser(mirrorTexture); } } } } } boolean useAutoMipMapGeneration(Canvas3D cv) { if (mipmapMode == Texture.BASE_LEVEL && (minFilter == Texture.NICEST || minFilter == Texture.MULTI_LEVEL_POINT || minFilter == Texture.MULTI_LEVEL_LINEAR) && ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_AUTO_MIPMAP_GENERATION) != 0)) { return true; } return false; } /** * Go through the image update info list * and remove those that are already done * by all the resources */ void pruneImageUpdateInfo() { ImageComponentUpdateInfo info; //System.err.println("Texture.pruneImageUpdateInfo"); for (int k = 0; k < numFaces; k++) { for (int i = baseLevel; i <= maximumLevel; i++) { if ((imageUpdatePruneMask[k] & (1<<i)) != 0) { if (imageUpdateInfo[k][i] != null) { for (int j = 0; j < imageUpdateInfo[k][i].size(); j++) { info = (ImageComponentUpdateInfo) imageUpdateInfo[k][i].get(j); if (info.updateMask == 0) { // this update info is done, remove it // from the update list imageUpdateInfo[k][i].remove(j); } } } imageUpdatePruneMask[k] &= ~(1<<i); } } } } /** * addImageUpdateInfo(int level) is to update a particular level. * In this case, it supercedes all the subImage update for this level, * and all those update info can be removed from the update list. * * Note: this method is called from mirror only */ void addImageUpdateInfo(int level, int face, ImageComponentUpdateInfo arg) { ImageComponentUpdateInfo info; if (imageUpdateInfo == null) { imageUpdateInfo = new ArrayList[numFaces][maxLevels]; } if (imageUpdateInfo[face][level] == null) { imageUpdateInfo[face][level] = new ArrayList(); } info = new ImageComponentUpdateInfo(); if (arg == null) { // no subimage info, so the entire image is to be updated info.entireImage = true; // Fix issue 117 using ogl subimage always// } else if ((arg.width >= width/2) && (arg.height >= height/2)) {//// // if the subimage dimension is close to the complete dimension,// // use the full update (it's more efficient)// info.entireImage = true; } else { info.entireImage = false; } if (info.entireImage) { // the entire image update supercedes all the subimage update; // hence, remove all the existing updates from the list imageUpdateInfo[face][level].clear(); // reset the update prune mask for this level if (imageUpdatePruneMask != null) { imageUpdatePruneMask[face] &= ~(1 << level); } } else { // subimage update, needs to save the subimage info info.x = arg.x; info.y = arg.y; info.z = arg.z; info.width = arg.width; info.height = arg.height; } // save the mask which shows the canvases that have created resources // for this image, aka, these are the resources that need to be // updated. info.updateMask = resourceCreationMask; // add the image update to the list imageUpdateInfo[face][level].add(info); // check if the update list stills need to be pruned if (imageUpdatePruneMask != null) { pruneImageUpdateInfo(); } } void validate() { enable = true; for (int j = 0; j < numFaces && enable; j++) { for (int i = baseLevel; i <= maximumLevel && enable; i++) { if (images[j][i] == null) { enable = false; } } } } /** * Update the "component" field of the mirror object with the * given "value" */ synchronized void updateMirrorObject(int component, Object value) { TextureRetained mirrorTexture = (TextureRetained)mirror; if ((component & ENABLE_CHANGED) != 0) { mirrorTexture.enable = ((Boolean)value).booleanValue(); } else if ((component & IMAGE_CHANGED) != 0) { Object [] arg = (Object []) value; int level = ((Integer)arg[0]).intValue(); ImageComponent image = (ImageComponent)arg[1]; int face = ((Integer)arg[2]).intValue(); // first remove texture from the userList of the current // referencing image and if (mirrorTexture.images[face][level] != null) { mirrorTexture.images[face][level].removeUser(mirror); } // assign the new image and add texture to the userList if (image == null) { mirrorTexture.images[face][level] = null; } else { mirrorTexture.images[face][level] = (ImageComponentRetained)image.retained; mirrorTexture.images[face][level].addUser(mirror); } // NOTE: the old image has to be removed from the // renderBins' NodeComponentList and new image has to be // added to the lists. This will be taken care of // in the RenderBin itself in response to the // IMAGE_CHANGED message // mark that texture images need to be updated mirrorTexture.resourceUpdatedMask = 0; // add update info to the update list mirrorTexture.addImageUpdateInfo(level, face, null); } else if ((component & IMAGES_CHANGED) != 0) { Object [] arg = (Object []) value; ImageComponent [] images = (ImageComponent[])arg[0]; int face = ((Integer)arg[1]).intValue(); for (int i = 0; i < images.length; i++) { // first remove texture from the userList of the current // referencing image if (mirrorTexture.images[face][i] != null) { mirrorTexture.images[face][i].removeUser(mirror); } // assign the new image and add texture to the userList if (images[i] == null) { mirrorTexture.images[face][i] = null; } else { mirrorTexture.images[face][i] = (ImageComponentRetained)images[i].retained; mirrorTexture.images[face][i].addUser(mirror); } } mirrorTexture.updateResourceCreationMask(); // NOTE: the old images have to be removed from the // renderBins' NodeComponentList and new image have to be // added to the lists. This will be taken care of // in the RenderBin itself in response to the // IMAGES_CHANGED message } else if ((component & BASE_LEVEL_CHANGED) != 0) { int level = ((Integer)value).intValue(); if (level < mirrorTexture.baseLevel) { // add texture to the userList of those new levels of // enabling images for (int j = 0; j < numFaces; j++) { for (int i = level; i < mirrorTexture.baseLevel; i++) { if (mirrorTexture.images[j][i] == null) { mirrorTexture.enable = false; } else { mirrorTexture.addImageUpdateInfo(i, j, null); } } } mirrorTexture.baseLevel = level; // mark that texture images need to be updated mirrorTexture.resourceUpdatedMask = 0; } else { mirrorTexture.baseLevel = level; if (userSpecifiedEnable && (mirrorTexture.enable == false)) { // if texture is to be enabled but is currently // disabled, it's probably disabled because // some of the images are missing. Now that // the baseLevel is modified, validate the // texture images again mirrorTexture.validate(); } } // mark that texture lod info needs to be updated mirrorTexture.resourceLodUpdatedMask = 0; } else if ((component & MAX_LEVEL_CHANGED) != 0) { int level = ((Integer)value).intValue(); if (level > mirrorTexture.maximumLevel) { // add texture to the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -