From: Svjatoslav Agejenko Date: Sun, 15 Mar 2026 03:53:18 +0000 (+0200) Subject: refactor(benchmark): move texture creation into TexturedCubesTest X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=9a1886d68c032d7788c09c73e07ded90e0f65789;p=sixth-3d-demos.git refactor(benchmark): move texture creation into TexturedCubesTest Simplify BenchmarkTest.setup() signature by removing texture parameters that only TexturedCubesTest needed. Each test now manages its own resources independently. --- diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/BenchmarkTest.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/BenchmarkTest.java index 13326c3..dec1514 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/BenchmarkTest.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/BenchmarkTest.java @@ -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. diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/GraphicsBenchmark.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/GraphicsBenchmark.java index 5d9a77d..14e4d1b 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/GraphicsBenchmark.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/GraphicsBenchmark.java @@ -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) { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/SolidCubesTest.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/SolidCubesTest.java index ca1a7dc..d9e9773 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/SolidCubesTest.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/SolidCubesTest.java @@ -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; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/TexturedCubesTest.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/TexturedCubesTest.java index 15b99f8..c8f4798 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/TexturedCubesTest.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/TexturedCubesTest.java @@ -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 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 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/WireframeCubesTest.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/WireframeCubesTest.java index c76a184..4ea1ea9 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/WireframeCubesTest.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/benchmark/WireframeCubesTest.java @@ -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;