glslshaderobjectsstate.java

来自「java 3d game jme 工程开发源代码」· Java 代码 · 共 917 行 · 第 1/3 页

JAVA
917
字号
     *
     * @param name uniform variable to change
     * @param value1 the new value
     * @param value2 the new value
     * @param value3 the new value
     */
    public void setUniform(String name, boolean value1, boolean value2,
            boolean value3) {
        ShaderVariableInt3 shaderUniform =
                getShaderUniform(name, ShaderVariableInt3.class);
        shaderUniform.value1 = value1 ? 1 : 0;
        shaderUniform.value2 = value2 ? 1 : 0;
        shaderUniform.value3 = value3 ? 1 : 0;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value1 the new value
     * @param value2 the new value
     * @param value3 the new value
     */
    public void setUniform(String name, int value1, int value2, int value3) {
        ShaderVariableInt3 shaderUniform =
                getShaderUniform(name, ShaderVariableInt3.class);
        shaderUniform.value1 = value1;
        shaderUniform.value2 = value2;
        shaderUniform.value3 = value3;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value1 the new value
     * @param value2 the new value
     * @param value3 the new value
     */
    public void setUniform(String name, float value1, float value2,
            float value3) {
        ShaderVariableFloat3 shaderUniform =
                getShaderUniform(name, ShaderVariableFloat3.class);
        shaderUniform.value1 = value1;
        shaderUniform.value2 = value2;
        shaderUniform.value3 = value3;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value1 the new value
     * @param value2 the new value
     * @param value3 the new value
     * @param value4 the new value
     */
    public void setUniform(String name, boolean value1, boolean value2,
            boolean value3, boolean value4) {
        ShaderVariableInt4 shaderUniform =
                getShaderUniform(name, ShaderVariableInt4.class);
        shaderUniform.value1 = value1 ? 1 : 0;
        shaderUniform.value2 = value2 ? 1 : 0;
        shaderUniform.value3 = value3 ? 1 : 0;
        shaderUniform.value4 = value4 ? 1 : 0;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value1 the new value
     * @param value2 the new value
     * @param value3 the new value
     * @param value4 the new value
     */
    public void setUniform(String name, int value1, int value2, int value3,
            int value4) {
        ShaderVariableInt4 shaderUniform =
                getShaderUniform(name, ShaderVariableInt4.class);
        shaderUniform.value1 = value1;
        shaderUniform.value2 = value2;
        shaderUniform.value3 = value3;
        shaderUniform.value4 = value4;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value1 the new value
     * @param value2 the new value
     * @param value3 the new value
     * @param value4 the new value
     */
    public void setUniform(String name, float value1, float value2,
            float value3, float value4) {
        ShaderVariableFloat4 shaderUniform =
                getShaderUniform(name, ShaderVariableFloat4.class);
        shaderUniform.value1 = value1;
        shaderUniform.value2 = value2;
        shaderUniform.value3 = value3;
        shaderUniform.value4 = value4;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value the new value
     */
    public void setUniform(String name, Vector2f value) {
        ShaderVariableFloat2 shaderUniform =
                getShaderUniform(name, ShaderVariableFloat2.class);
        shaderUniform.value1 = value.x;
        shaderUniform.value2 = value.y;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value the new value
     */
    public void setUniform(String name, Vector3f value) {
        ShaderVariableFloat3 shaderUniform =
                getShaderUniform(name, ShaderVariableFloat3.class);
        shaderUniform.value1 = value.x;
        shaderUniform.value2 = value.y;
        shaderUniform.value3 = value.z;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value the new value
     */
    public void setUniform(String name, ColorRGBA value) {
        ShaderVariableFloat4 shaderUniform =
                getShaderUniform(name, ShaderVariableFloat4.class);
        shaderUniform.value1 = value.r;
        shaderUniform.value2 = value.g;
        shaderUniform.value3 = value.b;
        shaderUniform.value4 = value.a;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value the new value
     */
    public void setUniform(String name, Quaternion value) {
        ShaderVariableFloat4 shaderUniform =
                getShaderUniform(name, ShaderVariableFloat4.class);
        shaderUniform.value1 = value.x;
        shaderUniform.value2 = value.y;
        shaderUniform.value3 = value.z;
        shaderUniform.value4 = value.w;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value the new value (a float buffer of size 4)
     * @param rowMajor true if is this in row major order
     */
    public void setUniform(String name, float value[], boolean rowMajor) {
        if (value.length != 4)
            return;

        ShaderVariableMatrix2 shaderUniform =
                getShaderUniform(name, ShaderVariableMatrix2.class);
        shaderUniform.matrixBuffer.clear();
        shaderUniform.matrixBuffer.put(value[0]);
        shaderUniform.matrixBuffer.put(value[1]);
        shaderUniform.matrixBuffer.put(value[2]);
        shaderUniform.matrixBuffer.put(value[3]);
        shaderUniform.rowMajor = rowMajor;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value the new value
     * @param rowMajor true if is this in row major order
     */
    public void setUniform(String name, Matrix3f value, boolean rowMajor) {
        ShaderVariableMatrix3 shaderUniform =
                getShaderUniform(name, ShaderVariableMatrix3.class);
        // prepare buffer for writing
        shaderUniform.matrixBuffer.rewind();
        value.fillFloatBuffer(shaderUniform.matrixBuffer);
        // prepare buffer for reading
        shaderUniform.matrixBuffer.rewind();
        shaderUniform.rowMajor = rowMajor;

        setNeedsRefresh(true);
    }

    /**
     * Set an uniform value for this shader object.
     *
     * @param name uniform variable to change
     * @param value the new value
     * @param rowMajor true if is this in row major order
     */
    public void setUniform(String name, Matrix4f value, boolean rowMajor) {
        ShaderVariableMatrix4 shaderUniform =
                getShaderUniform(name, ShaderVariableMatrix4.class);
        // prepare buffer for writing
        shaderUniform.matrixBuffer.rewind();
        value.fillFloatBuffer(shaderUniform.matrixBuffer);
        // prepare buffer for reading
        shaderUniform.matrixBuffer.rewind();
        shaderUniform.rowMajor = rowMajor;

        setNeedsRefresh(true);
    }

    /** <code>clearUniforms</code> clears all uniform values from this state. */
    public void clearUniforms() {
        shaderUniforms.clear();
    }

    /**
     * Set an attribute pointer value for this shader object.
     *
     * @param name attribute variable to change
     * @param size Specifies the number of values for each element of the
     * generic vertex attribute array. Must be 1, 2, 3, or 4.
     * @param normalized Specifies whether fixed-point data values should be
     * normalized or converted directly as fixed-point values when they are
     * accessed.
     * @param stride Specifies the byte offset between consecutive attribute
     * values. If stride is 0 (the initial value), the attribute values are
     * understood to be tightly packed in the array.
     * @param data The actual data to use as attribute pointer
     */
    public void setAttributePointer(String name, int size, boolean normalized,
            int stride, FloatBuffer data) {
        ShaderVariablePointerFloat shaderUniform =
                getShaderAttribute(name, ShaderVariablePointerFloat.class);
        shaderUniform.size = size;
        shaderUniform.normalized = normalized;
        shaderUniform.stride = stride;
        shaderUniform.data = data;

        setNeedsRefresh(true);
    }

    /**
     * Set an attribute pointer value for this shader object.
     *
     * @param name attribute variable to change
     * @param size Specifies the number of values for each element of the
     * generic vertex attribute array. Must be 1, 2, 3, or 4.
     * @param normalized Specifies whether fixed-point data values should be
     * normalized or converted directly as fixed-point values when they are
     * accessed.
     * @param unsigned Specifies wheter the data is signed or unsigned
     * @param stride Specifies the byte offset between consecutive attribute
     * values. If stride is 0 (the initial value), the attribute values are
     * understood to be tightly packed in the array.
     * @param data The actual data to use as attribute pointer
     */
    public void setAttributePointer(String name, int size, boolean normalized,
            boolean unsigned, int stride, ByteBuffer data) {
        ShaderVariablePointerByte shaderUniform =
                getShaderAttribute(name, ShaderVariablePointerByte.class);
        shaderUniform.size = size;
        shaderUniform.normalized = normalized;
        shaderUniform.unsigned = unsigned;
        shaderUniform.stride = stride;
        shaderUniform.data = data;

        setNeedsRefresh(true);
    }

    /**
     * Set an attribute pointer value for this shader object.

⌨️ 快捷键说明

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