2017-01-22 13:46:38 +01:00
|
|
|
package org.warp.picalculator;
|
|
|
|
|
2017-01-31 22:29:49 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2018-06-09 19:37:34 +02:00
|
|
|
import org.warp.picalculator.deps.DEngine;
|
|
|
|
import org.warp.picalculator.deps.DSystem;
|
2017-04-09 22:01:03 +02:00
|
|
|
import org.warp.picalculator.device.Keyboard;
|
2018-06-30 18:46:53 +02:00
|
|
|
import org.warp.picalculator.event.Key;
|
|
|
|
import org.warp.picalculator.event.KeyPressedEvent;
|
|
|
|
import org.warp.picalculator.event.KeyReleasedEvent;
|
|
|
|
import org.warp.picalculator.event.KeyboardEventListener;
|
2017-05-16 22:02:44 +02:00
|
|
|
import org.warp.picalculator.gui.expression.InputContext;
|
2017-04-12 13:04:35 +02:00
|
|
|
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
|
2017-03-26 22:44:09 +02:00
|
|
|
import org.warp.picalculator.gui.expression.containers.NormalInputContainer;
|
2017-02-02 10:30:45 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
2017-05-16 22:02:44 +02:00
|
|
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
|
|
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
|
|
|
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
2017-02-02 10:30:45 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.Skin;
|
2017-03-03 23:06:43 +01:00
|
|
|
import org.warp.picalculator.math.MathContext;
|
|
|
|
import org.warp.picalculator.math.MathematicalSymbols;
|
|
|
|
import org.warp.picalculator.math.functions.Expression;
|
2017-03-26 22:44:09 +02:00
|
|
|
import org.warp.picalculator.math.parser.MathParser;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-01-22 13:46:38 +01:00
|
|
|
public class TestGPU {
|
|
|
|
|
2018-06-09 19:37:34 +02:00
|
|
|
public static final GraphicEngine d = DEngine.newGPUEngine();
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
public static void main(String[] args) throws IOException, Error {
|
2017-10-17 22:49:21 +02:00
|
|
|
StaticVars.debugOn = true;
|
2017-01-22 13:46:38 +01:00
|
|
|
Utils.debugThirdScreen = false;
|
|
|
|
d.create();
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2018-06-30 18:46:53 +02:00
|
|
|
Keyboard k = new Keyboard();
|
|
|
|
k.startKeyboard();
|
|
|
|
k.setAdditionalKeyboardListener(new KeyboardEventListener() {
|
2017-04-09 22:01:03 +02:00
|
|
|
@Override
|
2018-06-30 18:46:53 +02:00
|
|
|
public boolean onKeyPressed(KeyPressedEvent k) {
|
2018-03-11 21:49:41 +01:00
|
|
|
try {
|
2018-06-30 18:46:53 +02:00
|
|
|
switch (k.getKey()) {
|
2018-03-11 21:49:41 +01:00
|
|
|
case LEFT:
|
|
|
|
c.moveLeft();
|
|
|
|
return true;
|
|
|
|
case RIGHT:
|
|
|
|
c.moveRight();
|
|
|
|
return true;
|
|
|
|
case NUM0:
|
|
|
|
c.typeChar('0');
|
|
|
|
return true;
|
|
|
|
case NUM1:
|
|
|
|
c.typeChar('1');
|
|
|
|
return true;
|
|
|
|
case NUM2:
|
|
|
|
c.typeChar('2');
|
|
|
|
return true;
|
|
|
|
case NUM3:
|
|
|
|
c.typeChar('3');
|
|
|
|
return true;
|
|
|
|
case NUM4:
|
|
|
|
c.typeChar('4');
|
|
|
|
return true;
|
|
|
|
case NUM5:
|
|
|
|
c.typeChar('5');
|
|
|
|
return true;
|
|
|
|
case NUM6:
|
|
|
|
c.typeChar('6');
|
|
|
|
return true;
|
|
|
|
case NUM7:
|
|
|
|
c.typeChar('7');
|
|
|
|
return true;
|
|
|
|
case NUM8:
|
|
|
|
c.typeChar('8');
|
|
|
|
return true;
|
|
|
|
case NUM9:
|
|
|
|
c.typeChar('9');
|
|
|
|
return true;
|
|
|
|
case PLUS:
|
|
|
|
c.typeChar(MathematicalSymbols.SUM);
|
|
|
|
return true;
|
|
|
|
case MINUS:
|
|
|
|
c.typeChar(MathematicalSymbols.SUBTRACTION);
|
|
|
|
return true;
|
|
|
|
case MULTIPLY:
|
|
|
|
c.typeChar(MathematicalSymbols.MULTIPLICATION);
|
|
|
|
return true;
|
|
|
|
case DIVIDE:
|
|
|
|
c.typeChar(MathematicalSymbols.DIVISION);
|
|
|
|
return true;
|
|
|
|
case SQRT:
|
|
|
|
c.typeChar(MathematicalSymbols.SQUARE_ROOT);
|
|
|
|
return true;
|
|
|
|
case PARENTHESIS_OPEN:
|
|
|
|
case SINE:
|
|
|
|
c.typeChar(MathematicalSymbols.PARENTHESIS_OPEN);
|
|
|
|
return true;
|
|
|
|
case PARENTHESIS_CLOSE:
|
|
|
|
case debug_DEG:
|
|
|
|
c.moveRight();
|
|
|
|
return true;
|
|
|
|
case DELETE:
|
|
|
|
c.del();
|
|
|
|
return true;
|
|
|
|
case RESET:
|
|
|
|
c.clear();
|
|
|
|
return true;
|
2018-03-29 19:20:28 +02:00
|
|
|
case POWEROFF:
|
2018-03-11 21:49:41 +01:00
|
|
|
d.destroy();
|
2018-06-09 19:37:34 +02:00
|
|
|
DSystem.exit(0);
|
2018-03-11 21:49:41 +01:00
|
|
|
return true;
|
|
|
|
case EQUAL:
|
|
|
|
Expression expr;
|
|
|
|
try {
|
|
|
|
expr = MathParser.parseInput(new MathContext(), c);
|
|
|
|
System.out.println("Parsed input:" + expr.toString());
|
|
|
|
} catch (final Error e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
2018-05-12 21:18:29 +02:00
|
|
|
} catch (final Exception ex) {
|
2018-03-11 21:49:41 +01:00
|
|
|
ex.printStackTrace();
|
2017-04-09 22:01:03 +02:00
|
|
|
}
|
|
|
|
return false;
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-04-09 22:01:03 +02:00
|
|
|
}
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-04-09 22:01:03 +02:00
|
|
|
@Override
|
2018-06-30 18:46:53 +02:00
|
|
|
public boolean onKeyReleased(KeyReleasedEvent k) {
|
2017-04-09 22:01:03 +02:00
|
|
|
return false;
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-04-09 22:01:03 +02:00
|
|
|
}
|
|
|
|
});
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-05-16 22:02:44 +02:00
|
|
|
new Scene(d);
|
2017-01-22 13:46:38 +01:00
|
|
|
}
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-04-09 22:01:03 +02:00
|
|
|
private static NormalInputContainer c = null;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-02-02 10:30:45 +01:00
|
|
|
private static class Scene implements RenderingLoop {
|
2017-01-22 13:46:38 +01:00
|
|
|
|
2017-04-10 22:50:43 +02:00
|
|
|
private final BinaryFont exampleFont;
|
2017-02-02 10:30:45 +01:00
|
|
|
private final Skin exampleSkin;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
private final Renderer r;
|
2017-02-02 10:30:45 +01:00
|
|
|
private final GraphicEngine d;
|
2017-04-09 22:01:03 +02:00
|
|
|
private long lastTime = 0L;
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
public Scene(GraphicEngine d) throws IOException, Error {
|
2017-01-22 13:46:38 +01:00
|
|
|
this.d = d;
|
2017-03-03 23:06:43 +01:00
|
|
|
r = d.getRenderer();
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-11-19 12:55:48 +01:00
|
|
|
exampleFont = d.loadFont("norm");
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
exampleSkin = d.loadSkin("skin.png");
|
|
|
|
|
2017-11-19 12:55:48 +01:00
|
|
|
BlockContainer.initializeFonts(d.loadFont("norm"), d.loadFont("smal"));
|
2017-03-03 23:06:43 +01:00
|
|
|
|
|
|
|
//New expression framework test
|
2017-05-16 22:02:44 +02:00
|
|
|
c = new NormalInputContainer(new InputContext(), false, 0, 200);
|
2017-03-26 22:44:09 +02:00
|
|
|
c.typeChar(MathematicalSymbols.DIVISION);
|
|
|
|
c.typeChar('5');
|
|
|
|
c.typeChar(MathematicalSymbols.MULTIPLICATION);
|
|
|
|
c.typeChar('2');
|
|
|
|
c.moveRight();
|
|
|
|
c.typeChar('2');
|
|
|
|
c.moveRight();
|
|
|
|
c.typeChar(MathematicalSymbols.MULTIPLICATION);
|
|
|
|
c.typeChar('2');
|
|
|
|
c.typeChar('2');
|
2017-03-03 23:06:43 +01:00
|
|
|
c.recomputeDimensions();
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-01-22 13:46:38 +01:00
|
|
|
d.start(this);
|
|
|
|
|
|
|
|
// fonts = new RAWFont[1];
|
|
|
|
// textures = new int[100];
|
|
|
|
// fonts[0] = new RAWFont();
|
|
|
|
// fonts[0].create("big");
|
2017-01-31 22:29:49 +01:00
|
|
|
new Thread(() -> {
|
2017-01-22 13:46:38 +01:00
|
|
|
try {
|
2017-01-31 22:29:49 +01:00
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Utils.printSystemResourcesUsage();
|
|
|
|
Thread.sleep(5000);
|
|
|
|
}
|
|
|
|
} catch (final InterruptedException e) {
|
2017-01-22 13:46:38 +01:00
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2017-10-17 22:49:21 +02:00
|
|
|
if (!StaticVars.debugOn) {
|
2017-04-09 22:01:03 +02:00
|
|
|
d.destroy();
|
2018-06-09 19:37:34 +02:00
|
|
|
DSystem.exit(0);
|
2017-04-09 22:01:03 +02:00
|
|
|
}
|
2017-01-22 13:46:38 +01:00
|
|
|
}).start();
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
d.waitForExit();
|
2017-01-22 13:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void refresh() {
|
2017-01-31 22:29:49 +01:00
|
|
|
exampleSkin.use(d);
|
|
|
|
r.glClearColor(0xFFD0FDCF);
|
|
|
|
r.glClear(d.getWidth(), d.getHeight());
|
|
|
|
r.glColor3f(1.0f, 1.0f, 1.0f);
|
|
|
|
r.glFillRect(2, 2, 160, 160, 0, 0, 16, 16);
|
|
|
|
exampleFont.use(d);
|
|
|
|
r.glColor3f(1, 0, 0);
|
2017-03-03 23:06:43 +01:00
|
|
|
r.glDrawStringLeft(10, 170, "Prova! 123456789 222");
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-02-02 10:30:45 +01:00
|
|
|
//MSAA TEST
|
|
|
|
r.glDrawStringLeft(10f, 190.5f, "Test MSAA");
|
|
|
|
exampleSkin.use(d);
|
|
|
|
r.glColor3f(1.0f, 1.0f, 1.0f);
|
|
|
|
r.glFillRect(162, 2.5f, 160, 160, 0, 0, 16, 16);
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
//New expression framework test
|
2017-04-09 22:01:03 +02:00
|
|
|
if (lastTime == 0) {
|
|
|
|
lastTime = System.currentTimeMillis();
|
|
|
|
}
|
2017-04-10 22:50:43 +02:00
|
|
|
final double delta = System.currentTimeMillis() - lastTime;
|
2017-04-09 22:01:03 +02:00
|
|
|
lastTime = System.currentTimeMillis();
|
2017-04-10 22:50:43 +02:00
|
|
|
c.beforeRender((float) (delta / 1000d));
|
2017-03-26 22:44:09 +02:00
|
|
|
c.draw(d, r, 10, 220);
|
2017-01-22 13:46:38 +01:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-01-22 13:46:38 +01:00
|
|
|
}
|
|
|
|
}
|