Skip to content

Commit

Permalink
Adds a preference for setting the default intensity of lights in OpenGL
Browse files Browse the repository at this point in the history
Redefines LightStatement and LightDefinition to use it by default.
  • Loading branch information
AlexisDrogoul committed Mar 16, 2022
1 parent d1efcb4 commit a2bb315
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Expand Up @@ -607,8 +607,8 @@ public static class Displays {

/** The Constant OPENGL_DEFAULT_CAM. */
public static final Pref<String> OPENGL_DEFAULT_CAM =
create("pref_display_camera", "Default camera to use when none is specified", "From above", IType.STRING,
true).among(ICameraDefinition.PRESETS).in(NAME, RENDERING);
create("pref_display_camera", "Default camera to use when none is specified", "From above",
IType.STRING, true).among(ICameraDefinition.PRESETS).in(NAME, RENDERING);

/** The Constant OPENGL_CLIPBOARD_CAM. */
public static final Pref<Boolean> OPENGL_CLIPBOARD_CAM = create("pref_display_clipboard_cam",
Expand All @@ -620,6 +620,10 @@ public static class Displays {
"Use GAMA image cache when building textures in OpenGL (potentially faster when running several simulations, but uses more memory)",
true, IType.BOOL, true).in(NAME, RENDERING);

/** The Constant OPENGL_DEFAULT_LIGHT_INTENSITY. */
public static final Pref<Integer> OPENGL_DEFAULT_LIGHT_INTENSITY = create("pref_display_light_intensity",
"Set the default intensity of the ambient and default lights (from 0, completely dark, to 255, completely light)",
160, IType.INT, true).in(NAME, RENDERING).between(0, 255);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions msi.gama.core/src/msi/gama/outputs/LayeredDisplayData.java
Expand Up @@ -10,6 +10,9 @@
********************************************************************************************************/
package msi.gama.outputs;

import static msi.gama.common.interfaces.IKeyword.DEFAULT;
import static msi.gama.outputs.layers.properties.ILightDefinition.ambient;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -1149,8 +1152,10 @@ public void resetRotation() {
/** The lights. */
private final Map<String, ILightDefinition> lights = new LinkedHashMap<>() {
{
put(ILightDefinition.ambient, new GenericLightDefinition(ILightDefinition.ambient, -1, 127));
put(IKeyword.DEFAULT, new GenericLightDefinition(IKeyword.DEFAULT, 0, 127));
put(ambient, new GenericLightDefinition(ambient, -1,
GamaPreferences.Displays.OPENGL_DEFAULT_LIGHT_INTENSITY.getValue()));
put(DEFAULT, new GenericLightDefinition(DEFAULT, 0,
GamaPreferences.Displays.OPENGL_DEFAULT_LIGHT_INTENSITY.getValue()));
}
};

Expand Down
9 changes: 4 additions & 5 deletions msi.gama.core/src/msi/gama/outputs/LayeredDisplayOutput.java
Expand Up @@ -425,9 +425,7 @@ public void validate(final IDescription d) {
}
// Are we in OpenGL world ?
final IExpressionDescription type = d.getFacet(TYPE);
final Boolean isOpenGLDefault = !"Java2D".equals(GamaPreferences.Displays.CORE_DISPLAY.getValue());
final Boolean isOpenGLWanted = type == null ? isOpenGLDefault
: LayeredDisplayData.OPENGL.equals(type.getExpression().literalValue());
final boolean isOpenGLDefault = !"Java2D".equals(GamaPreferences.Displays.CORE_DISPLAY.getValue());
if (type != null) {
// Addresses and fixes Issue 833.
final String s = type.getExpression().literalValue();
Expand All @@ -437,8 +435,9 @@ public void validate(final IDescription d) {
IGamlIssue.UNKNOWN_KEYWORD, TYPE);
return;
}
} else if (isOpenGLDefault) {
d.setFacet(TYPE, LabelExpressionDescription.create(LayeredDisplayData.OPENGL));
} else {
d.setFacet(TYPE, LabelExpressionDescription
.create(isOpenGLDefault ? LayeredDisplayData.OPENGL : LayeredDisplayData.JAVA2D));
}

// final String camera = d.firstFacetFoundAmong(CAMERA_LOCATION, CAMERA_TARGET, CAMERA_ORIENTATION,
Expand Down
Expand Up @@ -59,7 +59,7 @@ public interface ILightDefinition extends INamed {
Double DEFAULT_ANGLE = 45d;

/** The default intensity. */
GamaColor DEFAULT_INTENSITY = new GamaColor(127, 127, 127, 255);
// GamaColor DEFAULT_INTENSITY = new GamaColor(160, 160, 160, 255);

/**
* Checks if is dynamic.
Expand Down Expand Up @@ -94,7 +94,7 @@ public interface ILightDefinition extends INamed {
*
* @return the intensity
*/
default GamaColor getIntensity() { return DEFAULT_INTENSITY; }
GamaColor getIntensity();

/**
* Gets the type.
Expand Down
Expand Up @@ -11,6 +11,7 @@
package msi.gama.outputs.layers.properties;

import msi.gama.common.interfaces.IKeyword;
import msi.gama.common.preferences.GamaPreferences;
import msi.gama.metamodel.shape.GamaPoint;
import msi.gama.runtime.IScope;
import msi.gama.util.GamaColor;
Expand Down Expand Up @@ -75,13 +76,14 @@ public LightDefinition(final LightStatement lightStatement) {
angleAttribute = create("angle", Types.FLOAT, DEFAULT_ANGLE);
drawAttribute = create("show", Types.BOOL, false);
activeAttribute = create("active", Types.BOOL, true);
Integer i = GamaPreferences.Displays.OPENGL_DEFAULT_LIGHT_INTENSITY.getValue();
intensityAttribute = create("intensity", (scope, exp) -> {
if (exp.getGamlType() == Types.INT) {
int v = Cast.asInt(scope, exp.value(scope));
return new GamaColor(v, v, v, 255);
}
return Cast.asColor(scope, exp.value(scope));
}, Types.COLOR, DEFAULT_INTENSITY, exp -> {
}, Types.COLOR, new GamaColor(i, i, i, 255), exp -> {
if (exp.getGamlType() == Types.INT) {
int v = Cast.asInt(null, exp.getConstValue());
return new GamaColor(v, v, v, 255);
Expand Down

0 comments on commit a2bb315

Please sign in to comment.