Skip to content
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

Projector component #172

Merged
merged 17 commits into from
Oct 13, 2023
Merged
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
21 changes: 8 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.marginallyclever</groupId>
<artifactId>RobotOverlord</artifactId>
<version>2.8.0</version>
<version>2.9.0</version>
<name>Robot Overlord</name>
<description>A friendly 3D user interface for controlling robots.</description>
<url>http://www.marginallyclever.com/</url>
Expand Down Expand Up @@ -334,7 +334,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
<version>2.11.0</version>
</dependency>

<!-- https://github.com/java-native/jssc/ -->
Expand All @@ -358,13 +358,13 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.9</version>
<version>1.4.7</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<version>2.0.5</version>
</dependency>

<dependency>
Expand All @@ -391,13 +391,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.2</version>
<version>2.15.2</version>
</dependency>
<!-- annotations let us ignore transient variables. -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.10.2</version>
<version>2.15.2</version>
</dependency>

<!-- SSH for Java -->
Expand All @@ -411,7 +411,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>15.0</version>
<version>24.0.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/batik/batik-xml -->
Expand Down Expand Up @@ -453,7 +453,7 @@
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>0.64.0</version>
<version>0.64.8</version>
</dependency>

<dependency>
Expand All @@ -479,11 +479,6 @@
<artifactId>classgraph</artifactId>
<version>4.8.161</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.161</version>
</dependency>

<dependency>
<groupId>com.github.sarxos</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.marginallyclever.robotoverlord.systems.render;
package com.marginallyclever.convenience;

import javax.vecmath.Vector2d;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void checkGLError(GL3 gl3,org.slf4j.Logger logger) {
int err = gl3.glGetError();
if(err != GL.GL_NO_ERROR) {
GLU glu = new GLU();
logger.error("GL error " + err + ": " + glu.gluErrorString(err));
logger.error("GL error {}: {}", err, glu.gluErrorString(err));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

import com.jogamp.opengl.GL3;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;
import com.marginallyclever.convenience.helpers.FileHelper;
import com.marginallyclever.robotoverlord.renderpanel.TextureFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
* A texture file name. Loads the texture when needed from a pool to reduce duplication.
* @author Dan Royer
*/
public class TextureParameter extends FilenameParameter {
public static final HashMap<String, Texture> texturePool = new HashMap<>();
private static final Logger logger = LoggerFactory.getLogger(TextureParameter.class);

// supported file formats
Expand All @@ -37,6 +43,44 @@ public static List<FileFilter> getFilters() {
return filters;
}

public static Texture createTexture(String filename) {
Texture texture = texturePool.get(filename);
if (texture == null) {
texture = loadTextureFromFile(filename);
if (texture != null)
texturePool.put(filename, texture);
}
return texture;
}

private static Texture loadTextureFromFile(String filename) {
Texture t = null;

try {
t = TextureIO.newTexture(FileHelper.open(filename), false, filename.substring(filename.lastIndexOf('.') + 1));
} catch (IOException e) {
//e.printStackTrace();
logger.error("Failed to load {}", filename, e);
}

return t;
}

public static void unloadAll(GL3 gl) {
for (Texture t : texturePool.values()) {
t.destroy(gl);
}
}

public static void loadAll() {
Set<String> keys = texturePool.keySet();
texturePool.clear();
for (String key : keys) {
Texture t = TextureParameter.createTexture(key);
texturePool.put(key, t);
}
}

public void render(GL3 gl) {
if(textureDirty) {
unloadTexture(gl);
Expand All @@ -63,7 +107,7 @@ public void loadTexture(GL3 gl) {

String value = get();
if(value != null && !value.isEmpty()) {
texture = TextureFactory.createTexture(value);
texture = TextureParameter.createTexture(value);
if(texture != null) textureDirty = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class MatrixMaterialRenderSet {
public MatrixMaterialRenderSet(List<Entity> list) {
super();

Set<RenderComponent> alreadyAdded = new HashSet<>();

// collect all entities with a RenderComponent
Queue<Entity> toRender = new LinkedList<>(list);
while(!toRender.isEmpty()) {
Expand All @@ -32,6 +34,8 @@ public MatrixMaterialRenderSet(List<Entity> list) {

RenderComponent renderComponent = entity.getComponent(RenderComponent.class);
if(renderComponent==null) continue;
if(alreadyAdded.contains(renderComponent)) continue;
alreadyAdded.add(renderComponent);

PoseComponent pose = entity.getComponent(PoseComponent.class);
Matrix4d m = (pose==null) ? MatrixHelper.createIdentityMatrix4() : pose.getWorld();
Expand Down
Loading