Updated some graphic libraries

This commit is contained in:
Andrea Cavalli 2018-03-29 00:30:47 +02:00
parent 4e9f4350f0
commit 575e9f4871
11 changed files with 79 additions and 42 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@
font_easter.png font_easter.png
font_easter.rft font_easter.rft
font_fu32.rft font_fu32.rft
VBO_Example.java
/target/ /target/
!/target/*.jar !/target/*.jar

BIN
libs/raspi2fb Normal file

Binary file not shown.

View File

@ -1,5 +1,12 @@
package org.warp.picalculator; package org.warp.picalculator;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.PIHardwareDisplay; import org.warp.picalculator.device.PIHardwareDisplay;
import org.warp.picalculator.gui.CalculatorHUD; import org.warp.picalculator.gui.CalculatorHUD;
@ -47,6 +54,11 @@ public class Main {
if (Utils.isRunningOnRaspberry() && !Utils.isInArray("-noraspi", args) && isRaspi) { if (Utils.isRunningOnRaspberry() && !Utils.isInArray("-noraspi", args) && isRaspi) {
Gpio.wiringPiSetupPhys(); Gpio.wiringPiSetupPhys();
Gpio.pinMode(12, Gpio.PWM_OUTPUT); Gpio.pinMode(12, Gpio.PWM_OUTPUT);
try {
Files.createFile(Paths.get("/boot/warppi_loaded"));
} catch (IOException e) {
e.printStackTrace();
}
} else { } else {
StaticVars.screenPos = new int[] { 0, 0 }; StaticVars.screenPos = new int[] { 0, 0 };
StaticVars.debugOn = true; StaticVars.debugOn = true;

View File

@ -76,6 +76,7 @@ public class Utils {
public static String forceEngine; public static String forceEngine;
public static boolean msDosMode; public static boolean msDosMode;
public static boolean debugCache; public static boolean debugCache;
public static boolean newtMode = true;
public static final class AdvancedOutputStream extends StringWriter { public static final class AdvancedOutputStream extends StringWriter {

View File

@ -303,7 +303,9 @@ public final class DisplayManager implements RenderingLoop {
if (error != null) { if (error != null) {
BinaryFont fnt = Utils.getFont(false, false); BinaryFont fnt = Utils.getFont(false, false);
fnt.use(engine); if (fnt != null && fnt != engine.getRenderer().getCurrentFont()) {
fnt.use(engine);
}
renderer.glColor3i(129, 28, 22); renderer.glColor3i(129, 28, 22);
renderer.glDrawStringRight(StaticVars.screenSize[0] - 2, StaticVars.screenSize[1] - (fnt.getCharacterHeight() + 2), StaticVars.calculatorNameUPPER + " CALCULATOR"); renderer.glDrawStringRight(StaticVars.screenSize[0] - 2, StaticVars.screenSize[1] - (fnt.getCharacterHeight() + 2), StaticVars.calculatorNameUPPER + " CALCULATOR");
renderer.glColor3i(149, 32, 26); renderer.glColor3i(149, 32, 26);
@ -314,11 +316,15 @@ public final class DisplayManager implements RenderingLoop {
renderer.glDrawStringLeft(2, 22 + i, stackPart); renderer.glDrawStringLeft(2, 22 + i, stackPart);
i += 11; i += 11;
} }
fonts[0].use(engine); if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
fonts[0].use(engine);
}
renderer.glColor3i(129, 28, 22); renderer.glColor3i(129, 28, 22);
renderer.glDrawStringCenter((StaticVars.screenSize[0] / 2), 11, "UNEXPECTED EXCEPTION"); renderer.glDrawStringCenter((StaticVars.screenSize[0] / 2), 11, "UNEXPECTED EXCEPTION");
} else { } else {
fonts[0].use(engine); if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
fonts[0].use(engine);
}
hud.renderBackground(); hud.renderBackground();
screen.render(); screen.render();
hud.render(); hud.render();

View File

@ -143,7 +143,7 @@ public class FBEngine implements GraphicEngine {
realFb.getBuffer().clear(); realFb.getBuffer().clear();
realFb.getBuffer().put(fb); realFb.getBuffer().put(fb);
for (int i = 0; i < fb.capacity()/2; i++) { for (int i = 0; i < fb.capacity()/2; i++) {
realFb.getBuffer().put(i, (byte) (0xFF)); realFb.getBuffer().put(i, (byte) (_________________TMP < 50 ? 0xFF : 0xF0));
} }
for (int i = fb.capacity()/2; i < fb.capacity(); i++) { for (int i = fb.capacity()/2; i < fb.capacity(); i++) {
realFb.getBuffer().put(i, (byte) (0x18)); realFb.getBuffer().put(i, (byte) (0x18));
@ -184,6 +184,7 @@ public class FBEngine implements GraphicEngine {
if (Utils.headlessOverride) { if (Utils.headlessOverride) {
return false; return false;
} }
/*
File fbFile = new File("/dev/fb1"); File fbFile = new File("/dev/fb1");
try { try {
fbFileRW = new RandomAccessFile(fbFile, "rw"); fbFileRW = new RandomAccessFile(fbFile, "rw");
@ -194,6 +195,7 @@ public class FBEngine implements GraphicEngine {
System.err.println("Cannot read framebuffer fb1."); System.err.println("Cannot read framebuffer fb1.");
ex.printStackTrace(); ex.printStackTrace();
} }
*/
return false; return false;
} }

View File

@ -193,4 +193,4 @@ public class GPUEngine implements GraphicEngine {
return registeredFonts; return registeredFonts;
} }
} }

View File

@ -292,13 +292,46 @@ public class GPURenderer implements Renderer {
return tex; return tex;
} }
public void startDrawCycle(boolean first) { public void initDrawCycle() {
final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex;
startDrawSegment(false);
if (textureChange) {
changeTexture();
}
if (fbVertices == null) { if (fbVertices == null) {
fbVertices = Buffers.newDirectFloatBuffer(3 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER); fbVertices = Buffers.newDirectFloatBuffer(3 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER);
txVertices = Buffers.newDirectFloatBuffer(2 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER); txVertices = Buffers.newDirectFloatBuffer(2 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER);
colVertices = Buffers.newDirectFloatBuffer(4 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER); colVertices = Buffers.newDirectFloatBuffer(4 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER);
} }
if (first || fbVertices == null || cycleEnded) { }
public void endDrawCycle() {
final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex;
if (textureChange) {
if (fbElements > 0) {
endDrawSegment();
}
changeTexture();
} else {
if (fbElements > 0) {
endDrawSegment();
}
}
}
private void changeTexture() {
precTexEnabled = currentTexEnabled;
precTex = currentTex;
if (currentTexEnabled) {
gl.glEnable(GL.GL_TEXTURE_2D);
currentTex.bind(gl);
} else {
gl.glDisable(GL.GL_TEXTURE_2D);
}
}
public void startDrawSegment(boolean continuation) {
if (!continuation || cycleEnded) {
fbElements = 0; fbElements = 0;
} }
cycleEnded = false; cycleEnded = false;
@ -308,42 +341,24 @@ public class GPURenderer implements Renderer {
private Texture precTex; private Texture precTex;
private boolean cycleEnded = true; private boolean cycleEnded = true;
public void updateDrawCycle() { public void doDrawSegment() {
updateDrawCycle(false, false);
}
public void updateDrawCycle(boolean first, boolean last) {
final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex; final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex;
final boolean changeRequired = last || fbElements >= ELEMENTS_MAX_COUNT_PER_BUFFER; final boolean changeRequired = fbElements >= ELEMENTS_MAX_COUNT_PER_BUFFER;
if (first) {
startDrawCycle(true);
}
if (textureChange) { if (textureChange) {
if (!first && fbElements > 0) { if (fbElements > 0) {
endDrawCycle(); endDrawSegment();
if (!last) { startDrawSegment(false);
startDrawCycle(true);
}
} }
precTexEnabled = currentTexEnabled; changeTexture();
precTex = currentTex; } else {
if (currentTexEnabled) {
gl.glEnable(GL.GL_TEXTURE_2D);
currentTex.bind(gl);
} else {
gl.glDisable(GL.GL_TEXTURE_2D);
}
} else if (!first) {
if (fbElements > 0 && changeRequired) { if (fbElements > 0 && changeRequired) {
endDrawCycle(); endDrawSegment();
if (!last) { startDrawSegment(true);
startDrawCycle(false);
}
} }
} }
} }
public void endDrawCycle() { public void endDrawSegment() {
fbVertices.limit(fbVertices.position()); fbVertices.limit(fbVertices.position());
txVertices.limit(txVertices.position()); txVertices.limit(txVertices.position());
colVertices.limit(colVertices.position()); colVertices.limit(colVertices.position());
@ -380,18 +395,18 @@ public class GPURenderer implements Renderer {
public void glClearSkin() { public void glClearSkin() {
if (currentTex != null) { if (currentTex != null) {
currentTex = null; currentTex = null;
updateDrawCycle(); doDrawSegment();
} }
} }
void disableTexture() { void disableTexture() {
currentTexEnabled = false; currentTexEnabled = false;
updateDrawCycle(); doDrawSegment();
} }
void enableTexture() { void enableTexture() {
currentTexEnabled = true; currentTexEnabled = true;
updateDrawCycle(); doDrawSegment();
} }
void useTexture(Texture t, float w, float h) { void useTexture(Texture t, float w, float h) {
@ -400,4 +415,4 @@ public class GPURenderer implements Renderer {
currentTexHeight = h; currentTexHeight = h;
enableTexture(); enableTexture();
} }
} }

View File

@ -343,12 +343,12 @@ class NEWTWindow implements GLEventListener {
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY); gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
renderer.updateDrawCycle(true, false); renderer.initDrawCycle();
disp.repaint(); disp.repaint();
renderer.updateDrawCycle(false, true); renderer.endDrawCycle();
GPURenderer.gl = null; GPURenderer.gl = null;

BIN
src/main/jni/libpicalc.so Normal file

Binary file not shown.

Binary file not shown.