Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.

Graphics but without Vulkan and FoW changes #788

Open
wants to merge 105 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
1b42a92
speedup game start
paulwedeck Jan 22, 2019
0380223
reduce functions calls per draw command
paulwedeck Jan 22, 2019
951e365
fix GLFW window resizing, minor refactoring for ContextCreators
paulwedeck Jan 24, 2019
a97fc46
minimal refactoring
paulwedeck Jan 24, 2019
220c4fe
fix resizing while using glfw, make glfw fps limit aware, add option …
paulwedeck Jan 25, 2019
e496f22
rename resize_gl to resizeContext
paulwedeck Feb 1, 2019
c8e2e35
inline bindFormat to improve performance
paulwedeck Feb 1, 2019
77587ea
fix shadows in MapCreator
paulwedeck Feb 2, 2019
d6daee1
optimize PartitionManger#removePositionTo
paulwedeck Feb 2, 2019
4f82c29
bundle multiple updateGeometry calls into one
paulwedeck Feb 3, 2019
30c7e14
increase accuracy of FramerateComputer
paulwedeck Feb 3, 2019
ca14ccc
make dim logic independent from rendering
paulwedeck Feb 4, 2019
2f4f6ff
move fowWritten logic to Background
paulwedeck Feb 4, 2019
90ea7d8
stop updating fow while pausing
paulwedeck Feb 8, 2019
3b32693
move UpdateGeometryCache to go.graphics
paulwedeck Feb 8, 2019
be6b46d
stop rewinding buffers inside and after updateGeometry
paulwedeck Feb 8, 2019
5cea18b
fix savegame loading
paulwedeck Feb 9, 2019
bf07942
fix terrain type and height updates, guard fowWritten access
paulwedeck Feb 9, 2019
cdef778
fix GLES11DrawContext#updateGeometryAt
paulwedeck Feb 10, 2019
7bdc23f
fill asyncBufferBuilding==true code path, replace backgroundColorChan…
paulwedeck Feb 15, 2019
ff34e58
change fowWritten from boolean[][] BitSet
paulwedeck Feb 16, 2019
f2037e1
split updated in AdvancedUpdateGeometryCache in multiple BitSets
paulwedeck Feb 16, 2019
83476cc
reduce updateGeometry calls in AndroidTextDrawer
paulwedeck Feb 16, 2019
d8a4bfe
make FOG_OF_WAR_DIM independent of FO_OG_WAR_DIM_FRAMERATE
paulwedeck Feb 16, 2019
6207c2e
fix some warnings and formating
paulwedeck Feb 16, 2019
7652659
expose gamespeed in IGameClock and adapt fow dimming to it
paulwedeck Feb 16, 2019
bdf4cc5
minor changes
paulwedeck Feb 16, 2019
aef34dc
stop creating textures from heap buffers
paulwedeck Feb 23, 2019
706036e
remove unused fpsLimit in MapContent
paulwedeck Feb 23, 2019
11fe17f
minor refactoring, fix DatFileViewer
paulwedeck Jun 11, 2019
19e7045
improve DatFileViewer
paulwedeck Jun 11, 2019
e52e739
Fix Arrows
paulwedeck Jun 11, 2019
e624319
Stop attacking dead enemies
paulwedeck Jun 11, 2019
c2aeab3
stop adding getOffset?() to every render location, just add this offs…
paulwedeck Jun 12, 2019
d23541c
Limit updated locations to actually existing ones
paulwedeck Jun 12, 2019
3734755
add game speed and pause menu
paulwedeck Jun 13, 2019
3dae4b6
Remove unused MultiImage* stuff
paulwedeck Jun 14, 2019
8aa9d9e
reduce number of created textures
paulwedeck Jun 14, 2019
194b836
minor changes to Shared* classes
paulwedeck Jun 15, 2019
40ffd34
Stop attacking dead enemies with infrantry
paulwedeck Jun 15, 2019
2ec2978
increase resolution of MapContents time measurement and add depth buf…
paulwedeck Jun 15, 2019
06af0a3
improve z-order in MapObjectDrawer
paulwedeck Jun 15, 2019
04a74eb
change settlers z order
paulwedeck Jun 16, 2019
d98c470
allow GLDrawContext to notice that the frame is ready
paulwedeck Jun 16, 2019
125b075
small shader refactoring
paulwedeck Jun 16, 2019
2f6fa0f
remove glFinish because of performance impact
paulwedeck Jun 17, 2019
2a73e5d
add GL(ES) 3.1 path that merge multiple draw calls with different uni…
paulwedeck Jun 18, 2019
70882a8
rename GL(ES)3 render path to GL(ES)3.2 because it is
paulwedeck Jun 18, 2019
aca374a
add drawUnified2DArray render path that is currently only used by pla…
paulwedeck Jun 20, 2019
40f192e
stop compiling unifiedArray shader if its not possible
paulwedeck Jun 20, 2019
7c711b4
move GLES31 path to GLES30
paulwedeck Jun 21, 2019
af1acfe
some bug fixing involving legacy opengl
paulwedeck Jun 21, 2019
9489709
fix shadow_depth value of multi shader
paulwedeck Jun 22, 2019
0f58019
improve error handling in GLContainer and ContextCreators
paulwedeck Jun 23, 2019
cf686d8
put GLES 3.0 stuff of GLES20DrawContext into GLES30DrawContext,
paulwedeck Jun 23, 2019
0243230
remove wrong comments
paulwedeck Jun 23, 2019
7a53392
just some small cleanup
paulwedeck Jun 23, 2019
51fe5f3
fix android Background
paulwedeck Jun 24, 2019
04cee55
minor refactoring
paulwedeck Jun 30, 2019
8775fc5
some textdrawer changes
paulwedeck Jul 1, 2019
50c996d
fix drawing of buildings that are in construction
paulwedeck Jul 6, 2019
1a0349e
stop updating buffers to show progress of BarFill
paulwedeck Jul 7, 2019
4ff1620
fix z of in construction buildings
paulwedeck Jul 7, 2019
e15d7ed
some minor LWJGL improvments
paulwedeck Jul 7, 2019
0d60c23
Rename GeometryHandle to BufferHandle
paulwedeck Jul 12, 2019
ef52bb5
rewrite of all render paths
paulwedeck Jul 16, 2019
0b0ea33
rename *20DrawContext and *20DrawContext to *DrawContext
paulwedeck Jul 16, 2019
f8e6910
fix non-debug WGL and default context creation
paulwedeck Jul 16, 2019
747d0ee
fix construction progress drawing
paulwedeck Jul 17, 2019
f6361e5
fix drawOnlyShadow and drawOnlyImage in SettlerImage
paulwedeck Jul 17, 2019
c3a39ec
automate caching
paulwedeck Jul 17, 2019
ce3e03e
make AndroidTextDrawer more LWJGLTextDrawer like
paulwedeck Jul 17, 2019
1ea3fbc
Merge branch 'master' of githubpaul:jsettlers/settlers-remake into gr…
paulwedeck Jul 17, 2019
ceab17b
fix dock drawing
paulwedeck Jul 17, 2019
3c73174
fix font drawing after a while
paulwedeck Jul 17, 2019
bc0d979
fix building image in UI panel
paulwedeck Jul 18, 2019
c3efe76
change spaces to tabs in some shaders, fix colored font drawing
paulwedeck Jul 18, 2019
419b2e2
Share more code between LWJGL and Android TextDrawer,
paulwedeck Jul 20, 2019
b967b72
Merge branch 'master' into graphics
paulwedeck Jul 20, 2019
2dbcda6
fix stock drawing
paulwedeck Jul 24, 2019
13773db
Merge branch 'graphics' of github:paulwedeck/settlers-remake into gra…
paulwedeck Jul 24, 2019
1136184
fix filterBounds inline
paulwedeck Jul 25, 2019
d540bde
update test files
paulwedeck Jul 25, 2019
47265fd
fix DistancesCalculationAlgorithm
paulwedeck Jul 25, 2019
823a0eb
update test files again
paulwedeck Jul 25, 2019
0d0ec52
update test files again the 3rd
paulwedeck Jul 25, 2019
26330b5
merge master
paulwedeck Sep 14, 2019
d24ed35
fix too small framebuffers when using native scaling,
paulwedeck Sep 22, 2019
28e9293
fix SettingsSlider documentation
paulwedeck Sep 22, 2019
ad14160
some bug/potential bug/strange driver behavior fixing
paulwedeck Oct 12, 2019
2074e26
some font/panel size fixing
paulwedeck Oct 13, 2019
9e0eeb9
improve use of EGL_KHR_debug
paulwedeck Oct 13, 2019
c282e88
replace most gl imports with static imports
paulwedeck Oct 13, 2019
5a169c1
fix ProgressBar font
paulwedeck Oct 13, 2019
eff4bea
improve error reporting while context creation
paulwedeck Oct 21, 2019
7f3c871
fix GLFW canvas size
paulwedeck Oct 25, 2019
0f42c3e
Remove forgotten debug code
paulwedeck Oct 31, 2019
c156d32
Use UTF-8 encoding in gradle compilation
andreas-eberle Apr 25, 2020
b370143
fix UnifiedDrawCalls buffer size
paulwedeck Apr 25, 2020
5f7b48d
revert parts of 'speedup game start' 1b42a92b7f2423e17da5e961f28325db…
paulwedeck Apr 25, 2020
3031ba4
remove new FogOfWar algorithm
paulwedeck Apr 25, 2020
964854e
fix newline in AbstractTextDrawer
paulwedeck May 2, 2020
4b82f4d
add textdrawer todo
paulwedeck Apr 29, 2020
03376be
some swing stuff
paulwedeck May 3, 2020
eda2b4d
replace geometry shader in unified-multi with instancing (potentially…
paulwedeck May 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ subprojects {
into sourceSets.test.output.classesDir
}
processTestResources.dependsOn copyTestResources

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
}
plugins.withType(ApplicationPlugin).whenPluginAdded {
startScripts {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,339 +1,87 @@
/*******************************************************************************
* Copyright (c) 2015 - 2017
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*******************************************************************************/
package go.graphics.android;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

import go.graphics.AbstractColor;
import go.graphics.EGeometryFormatType;
import go.graphics.EGeometryType;
import go.graphics.GeometryHandle;
import go.graphics.IllegalBufferException;
import go.graphics.TextureHandle;
import go.graphics.text.EFontSize;
import go.graphics.text.TextDrawer;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.TypedValue;
import android.widget.TextView;

public class AndroidTextDrawer implements TextDrawer {

private static final int TEXTURE_HEIGHT = 512;
private static final int TEXTURE_WIDTH = 512;

private static AndroidTextDrawer[] instances = new AndroidTextDrawer[EFontSize.values().length];

private final EFontSize size;
private final GLES11DrawContext context;
private TextureHandle texture = null;
/**
* The number of lines we use on our texture.
*/
private int lines;
/**
* The current string starting in line i.
* <p>
*/
private String[] linestrings;

/**
* The width of line i. This width can be higher than TEXTURE_WIDTH. Then the string is split to multiple lines.
*/
private int[] linewidths;

/**
* An index of the next tile if the width of the current line is bigger than TEXTURE_WIDTH. This forms an linked list. -1 means no next tile.
*/
private int[] nextTile;

private int lineheight;

/**
* Data to do LRU
*/
private int lastUsedCount = 0;
private int[] lastused;

private TextView renderer;
private float pixelScale;
private GeometryHandle texturepos;

private static final float[] textureposarray = {
// top left
0,
0,
0,
0,

// bottom left
0,
0,
0,
0,

// bottom right
TEXTURE_WIDTH,
0,
1,
0,

// top right
TEXTURE_WIDTH,
0,
1,
0,
};
import go.graphics.text.AbstractTextDrawer;
import go.graphics.text.EFontSize;

private AndroidTextDrawer(EFontSize size, GLES11DrawContext context) {
this.size = size;
this.context = context;
pixelScale = context.getAndroidContext().getResources().getDisplayMetrics().scaledDensity;
initGeometry();
}
import static android.opengl.GLES20.*;

private final ByteBuffer updateBfr = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder());
public class AndroidTextDrawer extends AbstractTextDrawer<GLESDrawContext> {

private void updateTexturePos(int pos, float value) throws IllegalBufferException {
updateBfr.rewind();
updateBfr.putFloat(value);
context.updateGeometryAt(texturepos, pos*4, updateBfr);
}

private void checkInvariants() {
boolean[] isNextTile = new boolean[lines];
for (int i = 0; i < lines; i++) {
int next = nextTile[i];
if (next >= 0) {
if (isNextTile[next]) {
System.err.println("WARNING: The line " + next + " is linked multiple times as next line.");
}
isNextTile[next] = true;
}
}
for (int i = 0; i < lines; i++) {
if (isNextTile[i]) {
if (linestrings[i] != null) {
System.out.println("Linestring should be null for line " + i);
}
if (lastused[i] != Integer.MAX_VALUE) {
System.out.println("Last used should not be set for line " + i);
}
}
}
public AndroidTextDrawer(GLESDrawContext gl) {
super(gl, 0);
}

@Override
public void renderCentered(float cx, float cy, String text) {
// TODO: we may want to optimize this.
drawString(cx - getWidth(text) / 2, cy - getHeight(text) / 2, text);
protected float calculateScalingFactor() {
return drawContext.getAndroidContext().getResources().getDisplayMetrics().density;
}

@Override
public void drawString(float x, float y, String string) {
initialize();

int line = findLineFor(string);

for (; line >= 0; line = nextTile[line], x += TEXTURE_WIDTH) {
// texture mirrored
float bottom = (float) ((line + 1) * lineheight) / TEXTURE_HEIGHT;
float top = (float) (line * lineheight) / TEXTURE_HEIGHT;
try {
updateTexturePos(3, top);
updateTexturePos(7, bottom);
updateTexturePos(11, bottom);
updateTexturePos(15, top);
} catch (IllegalBufferException e) {
e.printStackTrace();
}

context.draw2D(texturepos, texture, EGeometryType.Quad, 0, 4, x, y, 0f, 1f, 1f, 1f, color, 1);
}
}
private Paint paint;

private int findExistingString(String string) {
int length = lines;
for (int i = 0; i < length; i++) {
if (string.equals(linestrings[i])) {
lastused[i] = lastUsedCount++;
return i;
}
}
return -1;
}
@Override
protected int init() {
paint = new Paint();
paint.setTextSize(TEXTURE_GENERATION_SIZE);

private int findLineToUse() {
int unnededline = 0;
int unnededrating = Integer.MAX_VALUE;
float[] float_char_widths = new float[CHARACTER_COUNT];
paint.getTextWidths(CHARACTERS, float_char_widths);
for(int i = 0;i != CHARACTER_COUNT; i++) char_widths[i] = (int)float_char_widths[i];

for (int i = 0; i < lines; i++) {
if (lastused[i] < unnededrating) {
unnededline = i;
unnededrating = lastused[i];
}
}
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
gentex_line_height = fm.leading-fm.ascent+fm.descent;

// now free the next lines
for (int next = unnededline; next > -1; next = nextTile[next]) {
nextTile[next] = -1;
lastused[next] = 0;
linestrings[next] = null;
}

return unnededline;
}
Paint sizedFont = new Paint(paint);

private int findLineFor(String string) {
int line = findExistingString(string);
if (line >= 0) {
return line;
}
EFontSize[] values = EFontSize.values();
for(int i = 0; i != values.length; i++) {
sizedFont.setTextSize(values[i].getSize());

int width = (int) Math.ceil(computeWidth(string) + 25);
renderer = new TextView(context.getAndroidContext());
renderer.setTextColor(Color.WHITE);
renderer.setSingleLine(true);
renderer.setTextSize(TypedValue.COMPLEX_UNIT_PX, getScaledSize());
renderer.setText(string);
Paint.FontMetricsInt sized_fm = sizedFont.getFontMetricsInt();

int firstLine = findLineToUse();
// System.out.println("string cache miss for " + string +
// ", allocating new line: " + firstLine);
int lastLine = firstLine;

for (int x = 0; x < width; x += TEXTURE_WIDTH) {
if (x == 0) {
line = firstLine;
} else {
line = findLineToUse();
nextTile[lastLine] = line;
linestrings[line] = null;
linewidths[line] = -1;
}
// important to not allow cycles.
lastused[line] = Integer.MAX_VALUE;
// just to be sure.
nextTile[line] = -1;

// render the new text to that line.
Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, lineheight, Bitmap.Config.ALPHA_8);
Canvas canvas = new Canvas(bitmap);
renderer.layout(0, 0, width, lineheight);
canvas.translate(-x, 0);
renderer.draw(canvas);
// canvas.translate(50, .8f * lineheight);
int points = lineheight * TEXTURE_WIDTH;
ByteBuffer alpha8 = ByteBuffer.allocateDirect(points);
bitmap.copyPixelsToBuffer(alpha8);
ByteBuffer updateBuffer;
if(context instanceof GLES20DrawContext) {
updateBuffer = ByteBuffer.allocateDirect(points*4);
for(int i = 0;i != points;i++) {
updateBuffer.putInt(0xFFFFFF00|alpha8.get(i));
}
} else {
updateBuffer = alpha8;
}
updateBuffer.rewind();
context.updateFontTexture(texture, 0, line*lineheight, TEXTURE_WIDTH, lineheight, updateBuffer);
lastLine = line;
heightPerSize[i] = (sized_fm.leading-sized_fm.ascent+sized_fm.descent);
}
lastused[firstLine] = lastUsedCount++;
linestrings[firstLine] = string;
linewidths[firstLine] = width;

checkInvariants();
return firstLine;
}

private void initGeometry() {
if(texturepos == null || !texturepos.isValid()) texturepos = context.storeGeometry(textureposarray, EGeometryFormatType.Texture2D, true, "android-textdrawer" + size.getSize());
return fm.descent;
}

private void initialize() {
if (texture == null || !texture.isValid()) {
texture = context.generateFontTexture(TEXTURE_WIDTH, TEXTURE_HEIGHT);
lineheight = (int) (getScaledSize() * 1.3);
lines = TEXTURE_HEIGHT / lineheight;
linestrings = new String[lines];
linewidths = new int[lines];
lastused = new int[lines];
nextTile = new int[lines];
Arrays.fill(nextTile, -1);

try {
updateTexturePos(1, lineheight);
updateTexturePos(13, lineheight);
} catch (IllegalBufferException e) {
e.printStackTrace();
}

}
initGeometry();
}
private Bitmap pre_render;
private Canvas canvas;

@Override
public float getWidth(String string) {
int index = findExistingString(string);
if (index < 0) {
return computeWidth(string);
} else {
return linewidths[index];
}
}

private float computeWidth(String string) {
Paint paint = new Paint();
paint.setTextSize(getScaledSize());
return paint.measureText(string);
protected void setupBitmapDraw() {
pre_render = Bitmap.createBitmap(tex_width, tex_height, Bitmap.Config.ALPHA_8);
canvas = new Canvas(pre_render);
paint.setColor(0);
canvas.drawPaint(paint);
paint.setColor(0xFFFFFFFF);
}

@Override
public float getHeight(String string) {
return getScaledSize();
}

private float getScaledSize() {
return size.getSize() * pixelScale;
protected void drawChar(char[] character, int x, int y) {
canvas.drawText(character, 0, 1, x, y, paint);
}

private AbstractColor color;

@Override
public void setColor(AbstractColor color) {
this.color = color;
protected int[] getRGB() {
int[] pixels = new int[tex_width*tex_height];
pre_render.getPixels(pixels, 0, tex_width, 0, 0, tex_width, tex_height);
return pixels;
}

public static TextDrawer getInstance(EFontSize size, GLES11DrawContext context) {
int ordinal = size.ordinal();
if (instances[ordinal] == null) {
instances[ordinal] = new AndroidTextDrawer(size, context);
}
return instances[ordinal];
@Override
protected void endDraw() {
pre_render = null;
canvas = null;
}

public static void invalidateTextures() {
for (int i = 0; i < instances.length; i++) {
instances[i] = null;
}
@Override
protected void setTexParams() {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

}
Loading