Skip to content

VarType: javadoc #2519

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 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 52 additions & 6 deletions jme3-core/src/main/java/com/jme3/shader/VarType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2024 jMonkeyEngine
* Copyright (c) 2009-2025 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -45,6 +45,9 @@
import com.jme3.texture.TextureCubeMap;
import com.jme3.texture.TextureImage;

/**
* Enum representing various GLSL variable types and their corresponding Java types.
*/
public enum VarType {

Float("float", float.class, Float.class),
Expand All @@ -59,7 +62,7 @@ public enum VarType {
Vector4Array(true, false, "vec4", Vector4f[].class),

Int("int", int.class, Integer.class),
Boolean("bool", Boolean.class, boolean.class),
Boolean("bool", boolean.class, Boolean.class),

Matrix3(true, false, "mat3", Matrix3f.class),
Matrix4(true, false, "mat4", Matrix4f.class),
Expand All @@ -83,8 +86,14 @@ public enum VarType {
private boolean textureType = false;
private boolean imageType = false;
private final String glslType;
private Class<?>[] javaTypes;
private final Class<?>[] javaTypes;

/**
* Constructs a VarType with the specified GLSL type and corresponding Java types.
*
* @param glslType the GLSL type name(s)
* @param javaTypes the Java classes mapped to this GLSL type
*/
VarType(String glslType, Class<?>... javaTypes) {
this.glslType = glslType;
if (javaTypes != null) {
Expand All @@ -94,6 +103,14 @@ public enum VarType {
}
}

/**
* Constructs a VarType with additional flags for multi-data and texture types.
*
* @param multiData true if this type uses multiple data elements (e.g. arrays, matrices)
* @param textureType true if this type represents a texture sampler
* @param glslType the GLSL type name(s)
* @param javaTypes the Java classes mapped to this GLSL type
*/
VarType(boolean multiData, boolean textureType, String glslType, Class<?>... javaTypes) {
this.usesMultiData = multiData;
this.textureType = textureType;
Expand All @@ -104,7 +121,16 @@ public enum VarType {
this.javaTypes = new Class<?>[0];
}
}


/**
* Constructs a VarType with flags for multi-data, texture, and image types.
*
* @param multiData true if this type uses multiple data elements
* @param textureType true if this type represents a texture sampler
* @param imageType true if this type represents an image
* @param glslType the GLSL type name(s)
* @param javaTypes the Java classes mapped to this GLSL type
*/
VarType(boolean multiData, boolean textureType, boolean imageType, String glslType, Class<?>... javaTypes) {
this(multiData, textureType, glslType, javaTypes);
this.imageType = imageType;
Expand All @@ -127,25 +153,45 @@ public boolean isOfType(Object o) {

/**
* Get the java types mapped to this VarType
*
*
* @return an array of classes mapped to this VarType
*/
public Class<?>[] getJavaType() {
return javaTypes;
}

/**
* Returns whether this VarType represents a texture sampler type.
*
* @return true if this is a texture type, false otherwise
*/
public boolean isTextureType() {
return textureType;
}


/**
* Returns whether this VarType represents an image type.
*
* @return true if this is an image type, false otherwise
*/
public boolean isImageType() {
return imageType;
}

/**
* Returns whether this VarType uses multiple data elements (e.g. arrays or matrices).
*
* @return true if this type uses multiple data elements, false otherwise
*/
public boolean usesMultiData() {
return usesMultiData;
}

/**
* Returns the GLSL type name(s) associated with this VarType.
*
* @return the GLSL type string (e.g. "float", "vec3", "sampler2D")
*/
public String getGlslType() {
return glslType;
}
Expand Down