Skip to content

Refactor: Uniform optimization + javadoc #2528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions jme3-core/src/main/java/com/jme3/shader/ShaderVariable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2025 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,42 +31,69 @@
*/
package com.jme3.shader;

/**
* Represents a generic variable within a shader program.
* <p>
* This abstract class provides the fundamental properties shared by different
* types of shader variables, such as uniforms or attributes.
*/
public class ShaderVariable {

public static final int LOC_UNKNOWN = -2,
LOC_NOT_DEFINED = -1;

// if -2, location not known
// if -1, not defined in shader
// if >= 0, uniform defined and available.
protected int location = LOC_UNKNOWN;
public static final int LOC_UNKNOWN = -2;
public static final int LOC_NOT_DEFINED = -1;

/**
* <ul>
* <li>If {@code LOC_UNKNOWN} (-2): The location is currently unknown.</li>
* <li>If {@code LOC_NOT_DEFINED} (-1): The variable is not defined in the shader.</li>
* <li>If {@code >= 0}: The uniform variable is defined and available.</li>
* </ul>
*/
protected int location = LOC_UNKNOWN;
/**
* Name of the uniform as was declared in the shader.
* E.g. name = "g_WorldMatrix" if the declaration was
* "uniform mat4 g_WorldMatrix;".
*/
protected String name = null;

/**
* True if the shader value was changed.
*/
protected boolean updateNeeded = true;;
protected boolean updateNeeded = true;


public void setLocation(int location){
/**
* Sets the location of this shader variable.
*
* @param location The integer location of the variable in the shader.
*/
public void setLocation(int location) {
this.location = location;
}

public int getLocation(){
/**
* Returns the location of this shader variable.
*
* @return The integer location of the variable.
*/
public int getLocation() {
return location;
}

public void setName(String name){
/**
* Sets the name of this shader variable as it's defined in the shader code.
*
* @param name The string name of the variable.
*/
public void setName(String name) {
this.name = name;
}

public String getName(){
/**
* Returns the name of this shader variable.
*
* @return The string name of the variable.
*/
public String getName() {
return name;
}

Expand Down
Loading