refactor(benchmark): move texture creation into TexturedCubesTest
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 15 Mar 2026 03:53:18 +0000 (05:53 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 15 Mar 2026 03:53:18 +0000 (05:53 +0200)
Simplify BenchmarkTest.setup() signature by removing texture parameters
that only TexturedCubesTest needed. Each test now manages its own
resources independently.

src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/BenchmarkTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/GraphicsBenchmark.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/SolidCubesTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/TexturedCubesTest.java
src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/WireframeCubesTest.java

index 13326c3..dec1514 100644 (file)
@@ -6,7 +6,6 @@
 package eu.svjatoslav.sixth.e3d.examples.benchmark;
 
 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
-import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
 
 /**
  * Interface for a single benchmark test.
@@ -23,10 +22,8 @@ public interface BenchmarkTest {
     /**
      * Sets up the test scene by adding shapes to the collection.
      * @param shapes the shape collection to populate
-     * @param textures available textures for textured tests
-     * @param cubeTextureIndices texture index for each cube
      */
-    void setup(ShapeCollection shapes, Texture[] textures, int[] cubeTextureIndices);
+    void setup(ShapeCollection shapes);
 
     /**
      * Tears down the test scene by removing all shapes added during setup.
index 5d9a77d..14e4d1b 100644 (file)
@@ -11,13 +11,11 @@ import eu.svjatoslav.sixth.e3d.gui.FrameListener;
 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
-import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
 
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Random;
 
 /**
  * Automated graphics benchmark that tests the engine's rendering performance.
@@ -42,19 +40,13 @@ public class GraphicsBenchmark implements FrameListener {
     private static final double ORBIT_DISTANCE = 1200;
     private static final double ORBIT_SPEED = 0.0003;
     private static final double WOBBLE_AMPLITUDE = 800;
-    private static final int TEXTURE_COUNT = 20;
     private static final int TEST_DURATION_MS = 30000;
-    private static final long RANDOM_SEED = 42;
 
     private ViewFrame viewFrame;
     private ViewPanel viewPanel;
     private ShapeCollection shapes;
-    private final Random random = new Random(RANDOM_SEED);
     private Camera camera;
 
-    private final Texture[] textures = new Texture[TEXTURE_COUNT];
-    private final int[] cubeTextureIndices = new int[GRID_SIZE * GRID_SIZE * GRID_SIZE];
-
     private double orbitAngle = 0;
     private long testStartTime;
     private long frameCount;
@@ -76,8 +68,6 @@ public class GraphicsBenchmark implements FrameListener {
      */
     public GraphicsBenchmark() {
         initializeWindow();
-        initializeTextures();
-        initializeCubeTextureIndices();
         registerTests();
         startNextTest();
     }
@@ -91,23 +81,6 @@ public class GraphicsBenchmark implements FrameListener {
         camera = viewPanel.getCamera();
     }
 
-    private void initializeTextures() {
-        for (int i = 0; i < TEXTURE_COUNT; i++) {
-            textures[i] = createGlowTexture(
-                    50 + random.nextInt(200),
-                    50 + random.nextInt(200),
-                    50 + random.nextInt(200)
-            );
-        }
-    }
-
-    private void initializeCubeTextureIndices() {
-        random.setSeed(RANDOM_SEED);
-        for (int i = 0; i < cubeTextureIndices.length; i++) {
-            cubeTextureIndices[i] = random.nextInt(TEXTURE_COUNT);
-        }
-    }
-
     private void registerTests() {
         tests.add(new SolidCubesTest());
         tests.add(new TexturedCubesTest());
@@ -127,7 +100,7 @@ public class GraphicsBenchmark implements FrameListener {
         frameCount = 0;
         testStartTime = System.currentTimeMillis();
 
-        currentTest.setup(shapes, textures, cubeTextureIndices);
+        currentTest.setup(shapes);
     }
 
     private void finishBenchmark() {
@@ -163,32 +136,6 @@ public class GraphicsBenchmark implements FrameListener {
         System.out.println(separator);
     }
 
-    private Texture createGlowTexture(int r, int g, int b) {
-        int texSize = 64;
-        Texture texture = new Texture(texSize, texSize, 2);
-
-        java.awt.Graphics2D gr = texture.graphics;
-        gr.setBackground(new java.awt.Color(r, g, b, 80));
-        gr.clearRect(0, 0, texSize, texSize);
-
-        int glowWidth = 6;
-        for (int i = 0; i < glowWidth; i++) {
-            int intensity = (int) (255.0 * (glowWidth - i) / glowWidth);
-            java.awt.Color glowColor = new java.awt.Color(
-                    Math.min(255, r + intensity),
-                    Math.min(255, g + intensity),
-                    Math.min(255, b + intensity),
-                    200 - i * 30
-            );
-            gr.setColor(glowColor);
-            gr.drawRect(i, i, texSize - 1 - 2 * i, texSize - 1 - 2 * i);
-        }
-
-        gr.dispose();
-        texture.resetResampledBitmapCache();
-        return texture;
-    }
-
     @Override
     public boolean onFrame(ViewPanel viewPanel, int millisecondsSinceLastFrame) {
         if (currentTest == null) {
index ca1a7dc..d9e9773 100644 (file)
@@ -9,7 +9,6 @@ import eu.svjatoslav.sixth.e3d.geometry.Point3D;
 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.solid.SolidPolygonCube;
-import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -36,7 +35,7 @@ public class SolidCubesTest implements BenchmarkTest {
     }
 
     @Override
-    public void setup(ShapeCollection shapes, Texture[] textures, int[] cubeTextureIndices) {
+    public void setup(ShapeCollection shapes) {
         random.setSeed(RANDOM_SEED);
         double offset = -(GRID_SIZE - 1) * SPACING / 2;
 
index 15b99f8..c8f4798 100644 (file)
@@ -11,6 +11,7 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Random;
 
 /**
  * Benchmark test for textured cubes.
@@ -22,8 +23,13 @@ public class TexturedCubesTest implements BenchmarkTest {
     private static final int GRID_SIZE = 16;
     private static final double SPACING = 80;
     private static final double CUBE_SIZE = 25;
+    private static final int TEXTURE_COUNT = 20;
+    private static final long RANDOM_SEED = 42;
 
+    private final Random random = new Random(RANDOM_SEED);
     private final List<Object> cubes = new ArrayList<>();
+    private Texture[] textures;
+    private int[] cubeTextureIndices;
 
     @Override
     public String getName() {
@@ -31,7 +37,10 @@ public class TexturedCubesTest implements BenchmarkTest {
     }
 
     @Override
-    public void setup(ShapeCollection shapes, Texture[] textures, int[] cubeTextureIndices) {
+    public void setup(ShapeCollection shapes) {
+        initializeTextures();
+        initializeCubeTextureIndices();
+
         double offset = -(GRID_SIZE - 1) * SPACING / 2;
         int idx = 0;
 
@@ -63,4 +72,49 @@ public class TexturedCubesTest implements BenchmarkTest {
         }
         cubes.clear();
     }
+
+    private void initializeTextures() {
+        textures = new Texture[TEXTURE_COUNT];
+        for (int i = 0; i < TEXTURE_COUNT; i++) {
+            textures[i] = createGlowTexture(
+                    50 + random.nextInt(200),
+                    50 + random.nextInt(200),
+                    50 + random.nextInt(200)
+            );
+        }
+    }
+
+    private void initializeCubeTextureIndices() {
+        random.setSeed(RANDOM_SEED);
+        cubeTextureIndices = new int[GRID_SIZE * GRID_SIZE * GRID_SIZE];
+        for (int i = 0; i < cubeTextureIndices.length; i++) {
+            cubeTextureIndices[i] = random.nextInt(TEXTURE_COUNT);
+        }
+    }
+
+    private Texture createGlowTexture(int r, int g, int b) {
+        int texSize = 64;
+        Texture texture = new Texture(texSize, texSize, 2);
+
+        java.awt.Graphics2D gr = texture.graphics;
+        gr.setBackground(new java.awt.Color(r, g, b, 80));
+        gr.clearRect(0, 0, texSize, texSize);
+
+        int glowWidth = 6;
+        for (int i = 0; i < glowWidth; i++) {
+            int intensity = (int) (255.0 * (glowWidth - i) / glowWidth);
+            java.awt.Color glowColor = new java.awt.Color(
+                    Math.min(255, r + intensity),
+                    Math.min(255, g + intensity),
+                    Math.min(255, b + intensity),
+                    200 - i * 30
+            );
+            gr.setColor(glowColor);
+            gr.drawRect(i, i, texSize - 1 - 2 * i, texSize - 1 - 2 * i);
+        }
+
+        gr.dispose();
+        texture.resetResampledBitmapCache();
+        return texture;
+    }
 }
\ No newline at end of file
index c76a184..4ea1ea9 100644 (file)
@@ -10,7 +10,6 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.WireframeBox;
-import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -36,7 +35,7 @@ public class WireframeCubesTest implements BenchmarkTest {
     }
 
     @Override
-    public void setup(ShapeCollection shapes, Texture[] textures, int[] cubeTextureIndices) {
+    public void setup(ShapeCollection shapes) {
         random.setSeed(RANDOM_SEED);
         double offset = -(GRID_SIZE - 1) * SPACING / 2;