⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textureunitstateretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $RCSfile: TextureUnitStateRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.8 $ * $Date: 2007/04/12 17:34:07 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.Color4f;import java.util.ArrayList;class TextureUnitStateRetained extends NodeComponentRetained {    static final int TEXTURE_CHANGED		= 0x0001;    static final int TEXTURE_ATTRS_CHANGED 	= 0x0002;    static final int TEXCOORD_GEN_CHANGED	= 0x0004;    static final int ALL_STATE_CHANGED		= 0x0008;    TextureRetained texture = null;    TextureAttributesRetained texAttrs = null;    TexCoordGenerationRetained texGen = null;    /**     * An abstract method to validate the texture unit state component     */    final void setTextureUnitStateComponent(NodeComponent comp,					    NodeComponentRetained thisComp,					    int messageOp) {	if (source.isLive()) {  	   	    if ((comp == null && thisComp == null) ||		(comp != null && comp.retained == thisComp))		return;	    if (thisComp != null) {		thisComp.clearLive(refCount);		thisComp.removeMirrorUsers(this);	    }	    if (comp != null) {		((NodeComponentRetained)comp.retained).setLive(inBackgroundGroup, refCount);		// If texture unit is live, then copy all the users of this		// texture unit state as users of this texture component		((NodeComponentRetained)comp.retained).copyMirrorUsers(this);	    }		    if (messageOp != -1) {	        sendMessage(messageOp, 		    (comp == null ? null : 		        ((NodeComponentRetained)comp.retained).mirror));	    }	}     }    final void initTextureUnitState(Texture texture,              TextureAttributes texAttrs,              TexCoordGeneration texGen) {	initTexture(texture);	initTextureAttributes(texAttrs);	initTexCoordGeneration(texGen);    }    final void setTextureUnitState(Texture texture,              TextureAttributes texAttrs,              TexCoordGeneration texGen) {	setTextureUnitStateComponent(texture, this.texture, -1);	setTextureUnitStateComponent(texAttrs, this.texAttrs, -1);	setTextureUnitStateComponent(texGen, this.texGen, -1);	// send all changes to the target threads in one	// message to avoid modifying the renderBin repeatedly	Object args[] = new Object[3];	args[0] = (texture == null ? null : 			((TextureRetained)texture.retained).mirror);	args[1] = (texAttrs == null ? null :			((TextureAttributesRetained)texAttrs.retained).mirror);	args[2] = (texGen == null ? null :			((TexCoordGenerationRetained)texGen.retained).mirror);	sendMessage(ALL_STATE_CHANGED, args);	initTextureUnitState(texture, texAttrs, texGen);    }    final void initTexture(Texture texture) {	if (texture == null)	    this.texture = null;	else	    this.texture = (TextureRetained)texture.retained;    }    final void setTexture(Texture texture) {	setTextureUnitStateComponent(texture, this.texture, TEXTURE_CHANGED);	initTexture(texture);    }    final void initTextureAttributes(TextureAttributes texAttrs) {	if (texAttrs == null)	    this.texAttrs = null;	else	    this.texAttrs = (TextureAttributesRetained)texAttrs.retained;    }    final void setTextureAttributes(TextureAttributes texAttrs) {	setTextureUnitStateComponent(texAttrs, this.texAttrs,					TEXTURE_ATTRS_CHANGED);	initTextureAttributes(texAttrs);    }	    final void initTexCoordGeneration(TexCoordGeneration texGen) {	if (texGen == null)	    this.texGen = null;	else	    this.texGen = (TexCoordGenerationRetained)texGen.retained;    }    final void setTexCoordGeneration(TexCoordGeneration texGen) {	setTextureUnitStateComponent(texGen, this.texGen, TEXCOORD_GEN_CHANGED);	initTexCoordGeneration(texGen);    }	    Texture getTexture() {	return (texture == null ? null : (Texture)texture.source);    }    TextureAttributes getTextureAttributes() {	return (texAttrs == null ? null : (TextureAttributes)texAttrs.source);    }    TexCoordGeneration getTexCoordGeneration() {	return (texGen == null ? null : (TexCoordGeneration)texGen.source);    }    void updateNative(int unitIndex, Canvas3D cv, 			boolean reload, boolean simulate) {	//System.err.println("TextureUnitState/updateNative: unitIndex= " + unitIndex + " reload= " + reload + " simulate= " + simulate);	// unitIndex can be -1 for the single texture case, so	// can't use unitIndex to index into the cv.texUnitState;	// in this case, use index 0	int index = unitIndex;	if (index < 0)	    index = 0;		boolean dirty = ((cv.canvasDirty & (Canvas3D.TEXTUREATTRIBUTES_DIRTY|Canvas3D.TEXTUREBIN_DIRTY)) != 0);        if (this.texture == null) {	    // if texture is null, then texture mapped is	    // disabled for this texture unit; and no more	    // state update is needed	    //System.err.println("texture is null");	    if (cv.texUnitState[index].texture != null) {	        cv.resetTexture(cv.ctx, unitIndex);		cv.texUnitState[index].texture = null;	    }	    cv.canvasDirty &= ~Canvas3D.TEXTUREATTRIBUTES_DIRTY;	    return;        } else {	    Pipeline.getPipeline().updateTextureUnitState(cv.ctx, unitIndex, true);        }        // reload is needed in a multi-texture case to bind the	// texture parameters to the texture unit state	if (reload || dirty || cv.texUnitState[index].texture != this.texture) {	    // texture cannot be null at this point because it is	    // already checked above            this.texture.updateNative(cv);	    cv.texUnitState[index].texture = this.texture;        }        if (this.texAttrs == null) {	    if (reload || dirty || cv.texUnitState[index].texAttrs != null) {                cv.resetTextureAttributes(cv.ctx);		if (VirtualUniverse.mc.isD3D() &&		    (texGen != null) &&		    ((texGen.genMode == TexCoordGeneration.EYE_LINEAR) ||		    ((texGen.genMode == TexCoordGeneration.SPHERE_MAP)))) {		    // We need to reload tex since eye linear 		    // and sphere map in D3D will change the 		    // texture transform matrix also.		    dirty = true;		}		cv.setBlendFunc(cv.ctx, TransparencyAttributes.BLEND_ONE,				TransparencyAttributes.BLEND_ZERO);	    	cv.texUnitState[index].texAttrs = null;	    }        } else {	    TextureAttributesRetained mTexAttrs;	    if (this.texAttrs.mirror == null) {		mTexAttrs = this.texAttrs;			    } else {		mTexAttrs = (TextureAttributesRetained) this.texAttrs.mirror;   	    }	    if (mTexAttrs.mirrorCompDirty) {		// This happen when canvas reference is same as		// texUnitState.texAttrs and we update the later without		// notify cache.		cv.texUnitState[index].texAttrs = null;		mTexAttrs.mirrorCompDirty = false;	    }	    if (reload || dirty || cv.texUnitState[index].texAttrs != mTexAttrs) {                this.texAttrs.updateNative(cv, simulate, texture.format);		if (VirtualUniverse.mc.isD3D() &&		    (texGen != null) &&		    ((texGen.genMode == TexCoordGeneration.EYE_LINEAR) ||		    ((texGen.genMode == TexCoordGeneration.SPHERE_MAP)))) {		    dirty = true;		}	    	cv.texUnitState[index].texAttrs = mTexAttrs;	    }        } 	if (this.texGen == null) {	    if (reload || dirty || cv.texUnitState[index].texGen != null) {		cv.resetTexCoordGeneration(cv.ctx);		cv.texUnitState[index].texGen = null;	    }        } else {	    TexCoordGenerationRetained mTexGen;	    if (this.texGen.mirror == null) {		mTexGen = this.texGen;			    } else {		mTexGen = (TexCoordGenerationRetained)this.texGen.mirror;		    }	    if (mTexGen.mirrorCompDirty) {		// This happen when canvas reference is same as		// texUnitState.texGen and we update the later without		// notify cache.		cv.texUnitState[index].texGen = null;		mTexGen.mirrorCompDirty = false;	    }	    if (reload || dirty || cv.texUnitState[index].texGen != mTexGen) {		this.texGen.updateNative(cv);		cv.texUnitState[index].texGen = mTexGen;            }        } 	cv.canvasDirty &= ~Canvas3D.TEXTUREATTRIBUTES_DIRTY;    }   /**    * Creates and initializes a mirror object, point the mirror object     * to the retained object if the object is not editable    */    synchronized void createMirrorObject() {	if (mirror == null) {	    TextureUnitStateRetained mirrorTus  = 			new TextureUnitStateRetained();	    mirror = mirrorTus;        }	mirror.source = source;	initMirrorObject();    }    synchronized void initMirrorObject() {	TextureUnitStateRetained mirrorTus = 		(TextureUnitStateRetained)mirror;	if (this.texture != null)	    mirrorTus.texture = (TextureRetained)this.texture.mirror;	else	    mirrorTus.texture = null;	if (this.texAttrs != null)	    mirrorTus.texAttrs = 		(TextureAttributesRetained)this.texAttrs.mirror;	else	    mirrorTus.texAttrs = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -