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

📄 shaderprogramretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $RCSfile: ShaderProgramRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.6 $ * $Date: 2007/04/10 15:51:49 $ * $State: Exp $ */package javax.media.j3d;import java.util.*;import javax.vecmath.*;/** * The ShaderProgramRetained object is a component object of an AppearanceRetained  * object that defines the shader properties used when programmable shader is * enabled. ShaderProgramRetained object is an abstract class. All shader program  * objects must be created as either a GLSLShaderProgramRetained object or a * CgShaderProgramRetained object. */abstract class ShaderProgramRetained extends NodeComponentRetained {    // Each element in the array corresponds to a unique renderer if shared    // context or a unique canvas otherwise.    protected ShaderProgramData shaderProgramData[];    // Flag indicating whether an UNSUPPORTED_LANGUAGE_ERROR has    // already been reported for this shader program object.  It is    // set in verifyShaderProgram and cleared in setLive or clearLive.    // TODO KCR: Add code to clear this in setLive or clearLive    private boolean unsupportedErrorReported = false;    // Flag indicating whether a LINK_ERROR has occurred for this shader program    // object.  It is set in updateNative to indicate that the linkShaderProgram    // operation failed. It is cleared in setLive or clearLive.    // TODO KCR: Add code to clear this in setLive or clearLive    private boolean linkErrorOccurred = false;    // an array of shaders used by this shader program    protected ShaderRetained[] shaders;    // an array of vertex attribute names    protected String[] vertexAttrNames;    // an array of (uniform) shader attribute names    protected String[] shaderAttrNames;        // Set of ShaderAttribute objects for which we have already reported an error    private HashSet shaderAttrErrorSet = null;    // need to synchronize access from multiple rendering threads     Object resourceLock = new Object();        // Package-scope default constructor    ShaderProgramRetained() {    }    /**     * Sets the vertex attribute names array for this ShaderProgram     * object. Each element in the array specifies the shader     * attribute name that is bound to the corresponding numbered     * vertex attribute within a GeometryArray object that uses this     * shader program. Array element 0 specifies the name of     * GeometryArray vertex attribute 0, array element 1 specifies the     * name of GeometryArray vertex attribute 1, and so forth.     * The array of names may be null or empty (0 length), but the     * elements of the array must be non-null.     *     * @param vertexAttrNames array of vertex attribute names for this     * shader program. A copy of this array is made.     */    void setVertexAttrNames(String[] vertexAttrNames) {        if (vertexAttrNames == null) {            this.vertexAttrNames = null;        }        else {            this.vertexAttrNames = (String[])vertexAttrNames.clone();        }    }    /**     * Retrieves the vertex attribute names array from this     * ShaderProgram object.     *     * @return a copy of this ShaderProgram's array of vertex attribute names.     */    String[] getVertexAttrNames() {        if (vertexAttrNames == null) {	    return null;	} 		return (String[])vertexAttrNames.clone();    }    /**     * Sets the shader attribute names array for this ShaderProgram     * object. Each element in the array specifies a shader     * attribute name that may be set via a ShaderAttribute object.     * Only those attributes whose names that appear in the shader     * attribute names array can be set for a given shader program.     * The array of names may be null or empty (0 length), but the     * elements of the array must be non-null.     *     * @param shaderAttrNames array of shader attribute names for this     * shader program. A copy of this array is made.     */    void setShaderAttrNames(String[] shaderAttrNames) {        if (shaderAttrNames == null) {            this.shaderAttrNames = null;        }        else {            this.shaderAttrNames = (String[])shaderAttrNames.clone();        }    }    /**     * Retrieves the shader attribute names array from this     * ShaderProgram object.     *     * @return a copy of this ShaderProgram's array of shader attribute names.     */    String[] getShaderAttrNames() {        if (shaderAttrNames == null) {	    return null;	} 		return (String[])shaderAttrNames.clone();    }    /**     * Copies the specified array of shaders into this shader     * program. This method makes a shallow copy of the array. The     * array of shaders may be null or empty (0 length), but the     * elements of the array must be non-null. The shading     * language of each shader in the array must match the     * subclass. Subclasses may impose additional restrictions.     *     * @param shaders array of Shader objects to be copied into this     * ShaderProgram     *     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     *     * @exception IllegalArgumentException if the shading language of     * any shader in the shaders array doesn't match the type of the     * subclass.     */    void setShaders(Shader[] shaders) {	if (shaders == null) {	    this.shaders = null;	    return;	}		this.shaders = new ShaderRetained[shaders.length];	// Copy vertex and fragment shader	for (int i = 0; i < shaders.length; i++) {	    this.shaders[i] = (ShaderRetained)shaders[i].retained;	}    }    /**     * Retrieves the array of shaders from this shader program. A     * shallow copy of the array is returned. The return value may     * be null.     *     * @return a copy of this ShaderProgram's array of Shader objects     *     */    Shader[] getShaders() {	if (shaders == null) {	    return null;	} else {	    Shader shads[] = 		new Shader[shaders.length];	    for (int i = 0; i < shaders.length; i++) {		if (shaders[i] != null) {		    shads[i] = (Shader) shaders[i].source;		} else {		    shads[i] = null;		}	    }	    return shads;	}    }    /**     * Method to create the native shader.     */    abstract ShaderError createShader(Context ctx, ShaderRetained shader, ShaderId[] shaderIdArr);     /**     * Method to destroy the native shader.     */    abstract ShaderError destroyShader(Context ctx, ShaderId shaderId);    /**     * Method to compile the native shader.     */    abstract ShaderError compileShader(Context ctx, ShaderId shaderId, String source);    /**     * Method to create the native shader program.     */    abstract ShaderError createShaderProgram(Context ctx, ShaderProgramId[] shaderProgramIdArr);    /**     * Method to destroy the native shader program.     */    abstract ShaderError destroyShaderProgram(Context ctx, ShaderProgramId shaderProgramId);    /**     * Method to link the native shader program.     */    abstract ShaderError linkShaderProgram(Context ctx, ShaderProgramId shaderProgramId, ShaderId[] shaderIds);    /**     * Method to bind a vertex attribute name to the specified index.     */    abstract ShaderError bindVertexAttrName(Context ctx, ShaderProgramId shaderProgramId, String attrName, int attrIndex);    /**     * Method to lookup a list of (uniform) shader attribute names and return     * information about the attributes.     */    abstract void lookupShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, AttrNameInfo[] attrNameInfoArr);        /*     * Method to lookup a list of vertex attribute names.     */    abstract void lookupVertexAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, boolean[] errArr);    /**     * Method to use the native shader program.     */    abstract ShaderError enableShaderProgram(Context ctx, ShaderProgramId shaderProgramId);        /**     * Method to disable the native shader program.     */    abstract ShaderError disableShaderProgram(Context ctx);        // ShaderAttributeValue methods    abstract ShaderError setUniform1i(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    int value);        abstract ShaderError setUniform1f(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    float value);        abstract ShaderError setUniform2i(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    int[] value);        abstract ShaderError setUniform2f(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    float[] value);        abstract ShaderError setUniform3i(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    int[] value);        abstract ShaderError setUniform3f(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    float[] value);            abstract ShaderError setUniform4i(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    int[] value);        abstract ShaderError setUniform4f(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    float[] value);            abstract ShaderError setUniformMatrix3f(Context ctx,					   ShaderProgramId shaderProgramId,				           ShaderAttrLoc uniformLocation,					   float[] value);    abstract ShaderError setUniformMatrix4f(Context ctx,					   ShaderProgramId shaderProgramId,			         	   ShaderAttrLoc uniformLocation,					   float[] value);    // ShaderAttributeArray methods        abstract ShaderError setUniform1iArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      int[] value);        abstract ShaderError setUniform1fArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      float[] value);        abstract ShaderError setUniform2iArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      int[] value);        abstract ShaderError setUniform2fArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      float[] value);        abstract ShaderError setUniform3iArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      int[] value);        abstract ShaderError setUniform3fArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      float[] value);            abstract ShaderError setUniform4iArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      int[] value);        abstract ShaderError setUniform4fArray(Context ctx,				      ShaderProgramId shaderProgramId,				      ShaderAttrLoc uniformLocation,				      int numElements,				      float[] value);            abstract ShaderError setUniformMatrix3fArray(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    int numElements,					    float[] value);    abstract ShaderError setUniformMatrix4fArray(Context ctx,					    ShaderProgramId shaderProgramId,					    ShaderAttrLoc uniformLocation,					    int numElements,					    float[] value);        /**     * Method to return a flag indicating whether this     * ShaderProgram is supported on the specified Canvas.     */    abstract boolean isSupported(Canvas3D cv);    void setLive(boolean backgroundGroup, int refCount) {		// System.err.println("ShaderProgramRetained.setLive()");	if (shaders != null) {	    for (int i = 0; i < shaders.length; i++){		shaders[i].setLive(backgroundGroup, refCount);	    }	}		super.doSetLive(backgroundGroup, refCount);        super.markAsLive();    }    void clearLive(int refCount) {        // System.err.println("ShaderProgramRetained.clearLive()");	super.clearLive(refCount);	if (shaders != null) {	    for (int i = 0; i < shaders.length; i++) {

⌨️ 快捷键说明

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