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.
/**
* 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.
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.
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;
*/
public GraphicsBenchmark() {
initializeWindow();
- initializeTextures();
- initializeCubeTextureIndices();
registerTests();
startNextTest();
}
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());
frameCount = 0;
testStartTime = System.currentTimeMillis();
- currentTest.setup(shapes, textures, cubeTextureIndices);
+ currentTest.setup(shapes);
}
private void finishBenchmark() {
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) {
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;
}
@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;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
/**
* Benchmark test for textured cubes.
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() {
}
@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;
}
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
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;
}
@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;