Uploading latest changes
This commit is contained in:
parent
7a7d9c1fd0
commit
5fd1ff4904
|
@ -1,3 +1,4 @@
|
|||
# Tests that should be done.
|
||||
|
||||
- Test starting animations with delays of each other to see if they act properly.
|
||||
- Test starting animations with delays of each other to see if they act properly.
|
||||
- Reafactor the GL_TEXTURE_FORMAT because it's in desperate need of an refactor.
|
|
@ -62,6 +62,7 @@ dependencies {
|
|||
implementation "org.lwjgl:lwjgl-opengl"
|
||||
implementation "org.lwjgl:lwjgl-stb"
|
||||
implementation "org.lwjgl:lwjgl-nfd"
|
||||
implementation "org.lwjgl:lwjgl-freetype"
|
||||
implementation "org.lwjgl:lwjgl-nanovg"
|
||||
implementation "org.lwjgl:lwjgl::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-glfw::$lwjglNatives"
|
||||
|
@ -70,8 +71,11 @@ dependencies {
|
|||
implementation "org.lwjgl:lwjgl-opengl::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-stb::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-nfd::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-freetype::$lwjglNatives"
|
||||
implementation "org.lwjgl:lwjgl-nanovg::$lwjglNatives"
|
||||
|
||||
|
||||
|
||||
//Gson
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
org.gradle.jvmargs=-Xmx2G
|
||||
|
||||
lwjglVersion = 3.3.3
|
||||
lwjglVersion = 3.3.4
|
||||
lwjglNatives = natives-windows
|
|
@ -69,7 +69,7 @@ public class NewInputTest {
|
|||
Joystick.INSTANCE.init(manager, bus);
|
||||
FileDrop.INSTANCE.init(bus);
|
||||
manager.addDevices(Mouse.INSTANCE, Keyboard.INSTANCE, Joystick.INSTANCE, FileDrop.INSTANCE);
|
||||
Window window = manager.builder().title("Testing Engine").build();
|
||||
Window window = manager.builder().title("Testing Engine").antialis(16).build();
|
||||
shaderTest.register();
|
||||
guiShader.register();
|
||||
assets.addListener(GLStateTracker.instance().shaders);
|
||||
|
@ -82,6 +82,7 @@ public class NewInputTest {
|
|||
|
||||
IFontProvider provider = STBTrueTypeProvider.create(AssetLocation.of("font/roboto/font.json"), assets);
|
||||
guiShader.get().proView.set(new Matrix4f().ortho(0, 0, window.width(), window.height(), 1000, -1000));
|
||||
guiShader.get().model.set(new Matrix4f().scale(1.1F));
|
||||
|
||||
int size = 512;
|
||||
int half = size >> 1;
|
||||
|
@ -101,7 +102,7 @@ public class NewInputTest {
|
|||
// texture.bind();
|
||||
Drawable drawable = new Drawable(GLTextureFormat.RGBA, half, half);
|
||||
drawable.fill(0, 0, half, half, 255, 255, 0, 255);
|
||||
drawable.upload(base * 3, base * 3, base, base, base * 2, base * 2);
|
||||
drawable.upload(texture.id(), base * 3, base * 3, base, base, base * 2, base * 2);
|
||||
drawable.close();
|
||||
}
|
||||
else if(T.key() == GLFW.GLFW_KEY_Z) {
|
||||
|
@ -114,7 +115,7 @@ public class NewInputTest {
|
|||
public Glyth bake(IGlythSheetInfo info) {
|
||||
int width = info.width();
|
||||
int height = info.height();
|
||||
info.upload(half - (width >> 1), half - (height >> 1));
|
||||
info.upload(texture.id(), half - (width >> 1), half - (height >> 1));
|
||||
System.out.println("Test2: "+width+", "+height);
|
||||
return null;
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ public class NewInputTest {
|
|||
public Glyth bake(IGlythSheetInfo info) {
|
||||
int width = info.width();
|
||||
int height = info.height();
|
||||
info.upload(half - (width >> 1), half - (height >> 1));
|
||||
info.upload(texture.id(), half - (width >> 1), half - (height >> 1));
|
||||
System.out.println("Test3: "+width+", "+height);
|
||||
return null;
|
||||
}
|
||||
|
@ -144,7 +145,7 @@ public class NewInputTest {
|
|||
builder.pos(-0.5F, 0.5F, 0).tex(0F, 0F).rgba(-1).endVertex();
|
||||
builder.pos(-0.5F, -0.5F, 0).tex(0F, 1F).rgba(-1).endVertex();
|
||||
|
||||
Font font = fonts.createFont(18.5F);
|
||||
Font font = fonts.createFont(18F, 4F);
|
||||
TestModel model = new TestModel(builder.getBytes());
|
||||
TestModel[] guiModel = new TestModel[1];
|
||||
List<GLDraw> draws = new ObjectArrayList<>();
|
||||
|
@ -154,25 +155,24 @@ public class NewInputTest {
|
|||
System.out.println("Testing: "+V.length+" bytes, "+K.size());
|
||||
}));
|
||||
|
||||
GLStateTracker tracker = GLStateTracker.instance();
|
||||
GL11.glClearColor(0.2F, 0.55F, 0.66F, 1F);
|
||||
while(!window.shouldClose()) {
|
||||
GLFW.glfwPollEvents();
|
||||
window.beginFrame();
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
shaderTest.bind();
|
||||
shaderTest.get().texture.set(texture);
|
||||
model.bindArray();
|
||||
GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), 6);
|
||||
model.unbindArray();
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
// texture.bind();
|
||||
// shaderTest.bind();
|
||||
// model.bindArray();
|
||||
// GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), 6);
|
||||
// model.unbindArray();
|
||||
guiModel[0].bindArray();
|
||||
guiShader.bind();
|
||||
for(GLDraw draw : draws) {
|
||||
// System.out.println("Draw: "+draw.texture()+", "+draw.startVertex()+", "+draw.vertexCount());
|
||||
guiShader.get().texture.set(draw.texture());
|
||||
tracker.textures.bind(draw.texture());
|
||||
GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), draw.startVertex(), draw.vertexCount());
|
||||
}
|
||||
guiModel[0].unbindArray();
|
||||
|
||||
window.handleInput();
|
||||
window.finishFrame();
|
||||
try { Thread.sleep(100); }
|
||||
|
@ -216,6 +216,7 @@ public class NewInputTest {
|
|||
int count = builder.size() - lastVertex;
|
||||
draws.add(new GLDraw(previousId, lastVertex, count));
|
||||
callbacks.accept(draws, builder.getBytes());
|
||||
builder.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -227,6 +228,7 @@ public class NewInputTest {
|
|||
public static class GuiShader extends SimpleShader {
|
||||
public TextureUniform texture = uniforms.addTexture("texture", 0);
|
||||
public Matrix4fUniform proView = uniforms.addMat("proViewMatrix", new Matrix4f());
|
||||
public Matrix4fUniform model = uniforms.addMat("modelmatrix", new Matrix4f());
|
||||
|
||||
public GuiShader(IAssetProvider provider) {
|
||||
super(provider, "gui_shader", AssetLocation.of("shader/testGui/vertex.vs"), AssetLocation.of("shader/testGui/fragment.fs"), "in_position", "in_tex", "in_color");
|
||||
|
|
|
@ -63,13 +63,15 @@ public class Font {
|
|||
float maxX = glyth.right() + x;
|
||||
float maxY = glyth.bottom() + y;
|
||||
|
||||
// System.out.println("Test: MinX="+minX+", MinY="+minY+", MaxX="+maxX+", MaxY="+maxY+", MinU="+glyth.minU()+", MinV="+glyth.minV()+", MaxU="+glyth.maxU()+", MaxV="+glyth.maxV());
|
||||
|
||||
IVertexBuilder builder = buffer.builderForTexture(glyth.texture());
|
||||
builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(-1).endVertex();
|
||||
builder.pos(maxX, minY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex();
|
||||
builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(-1).endVertex();
|
||||
builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(-1).endVertex();
|
||||
builder.pos(minX, maxY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex();
|
||||
builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(-1).endVertex();
|
||||
builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex();
|
||||
builder.pos(maxX, minY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(-1).endVertex();
|
||||
builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex();
|
||||
builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex();
|
||||
builder.pos(minX, maxY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(-1).endVertex();
|
||||
builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex();
|
||||
}
|
||||
x += data.advance();
|
||||
i += Character.charCount(codepoint);
|
||||
|
|
|
@ -23,7 +23,7 @@ import speiger.src.coreengine.rendering.gui.font.providers.STBTrueTypeProvider;
|
|||
import speiger.src.coreengine.utils.helpers.JsonUtil;
|
||||
|
||||
public class FontManager extends SteppedReloadableAsset<Map<AssetLocation, ObjectList<IFontProvider>>> {
|
||||
private static final int TEXTURE_SIZE = 2048;
|
||||
private static final int TEXTURE_SIZE = 512;
|
||||
private static final AssetFilter FILTER = AssetFilter.json("font");
|
||||
Map<AssetLocation, FontGroup> fonts = Object2ObjectMap.builder().linkedMap();
|
||||
Map<String, BiFunction<JsonObject, IAssetProvider, IFontProvider>> fontParsers = Object2ObjectMap.builder().map();
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package speiger.src.coreengine.rendering.gui.font;
|
||||
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL45;
|
||||
|
||||
import speiger.src.coreengine.assets.base.IAssetProvider;
|
||||
import speiger.src.coreengine.math.MathUtils;
|
||||
import speiger.src.coreengine.rendering.gui.font.glyth.Glyth;
|
||||
import speiger.src.coreengine.rendering.gui.font.glyth.IGlythSheetInfo;
|
||||
import speiger.src.coreengine.rendering.textures.base.BaseTexture;
|
||||
|
@ -16,10 +18,10 @@ import speiger.src.coreengine.rendering.utils.values.textures.GLTextureValue;
|
|||
|
||||
public class FontTexture extends BaseTexture {
|
||||
private static final TextureMetadata COLOR = TextureMetadata.builder()
|
||||
.externalFormat(GLTextureFormat.RGBA).internalFormat(GLTextureFormat.RGBA).dataFormat(GLDataType.UNSIGNED_BYTE).mipmapping(false)
|
||||
.externalFormat(GLTextureFormat.RGBA).internalFormat(GLTextureFormat.RGBAI).dataFormat(GLDataType.UNSIGNED_BYTE).mipmapping(false)
|
||||
.arguement(GLTextureParameter.MIN_FILTER, GLTextureValue.NEAREST).arguement(GLTextureParameter.MAG_FILTER, GLTextureValue.NEAREST)
|
||||
.arguement(GLTextureParameter.WRAP_S, GLTextureValue.CLAMP_TO_EDGE).arguement(GLTextureParameter.WRAP_T, GLTextureValue.CLAMP_TO_EDGE).build();
|
||||
private static final TextureMetadata NO_COLOR = COLOR.copy().internalFormat(GLTextureFormat.LUMINANCE).externalFormat(GLTextureFormat.LUMINANCE).arguement(GLTextureParameter.SWIZZLE_RGBA, GLTextureValue.RED).build();
|
||||
private static final TextureMetadata NO_COLOR = COLOR.copy().internalFormat(GLTextureFormat.LUMINANCE).externalFormat(GLTextureFormat.R).specialarguments(FontTexture::swizzle).build();
|
||||
|
||||
boolean color;
|
||||
int bounds;
|
||||
|
@ -33,36 +35,36 @@ public class FontTexture extends BaseTexture {
|
|||
}
|
||||
|
||||
public static ITextureComponentFormat formatByColor(boolean colored) {
|
||||
return colored ? GLTextureFormat.RGBA : GLTextureFormat.LUMINANCE;
|
||||
return colored ? GLTextureFormat.RGBA : GLTextureFormat.R;
|
||||
}
|
||||
|
||||
public static TextureMetadata metadataByColor(boolean colored) {
|
||||
return colored ? COLOR : NO_COLOR;
|
||||
}
|
||||
|
||||
private static void swizzle(int texture) {
|
||||
GL45.glTextureParameterIiv(texture, GLTextureParameter.SWIZZLE_RGBA.glValue(), new int[]{GL11.GL_RED, GL11.GL_RED, GL11.GL_RED, GL11.GL_RED});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(IAssetProvider provider) {
|
||||
createTexture();
|
||||
TextureMetadata metadata = metadataByColor(color);
|
||||
metadata.applyArguments(textureType());
|
||||
long allocate = MemoryUtil.nmemAlloc(bounds * bounds * formatByColor(color).components());
|
||||
ITextureComponentFormat format = formatByColor(color);
|
||||
GLFunctions.upload2DImage(textureType(), 0, format, bounds, bounds, 0, format, GLDataType.UNSIGNED_BYTE, allocate);
|
||||
// GLFunctions.upload2DImage(textureType(), 0, metadata, bounds, bounds, 0, allocate);
|
||||
MemoryUtil.nmemFree(allocate);
|
||||
metadata.applyArguments(id());
|
||||
GLFunctions.prepare2DImage(id(), 1, metadata, bounds, bounds);
|
||||
}
|
||||
|
||||
public Glyth build(IGlythSheetInfo info) {
|
||||
if(color != info.isColored()) return null;
|
||||
Slot result = slot.insert(info);
|
||||
if(result != null) {
|
||||
bind();
|
||||
info.upload(result.x, result.y);
|
||||
float minU = (slot.x + 0.01F) / bounds;
|
||||
float maxU = (slot.x - 0.01F + info.width()) / bounds;
|
||||
float minV = (slot.y + 0.01F) / bounds;
|
||||
float maxV = (slot.y - 0.01F + info.height()) / bounds;
|
||||
return new Glyth(id(), minU, minV, maxU, maxV);
|
||||
info.upload(id(), result.x, result.y);
|
||||
float minU = (float)(result.x) / (float)bounds;
|
||||
float maxU = (float)((result.x) + info.width()) / (float)bounds;
|
||||
float minV = (float)(result.y) / (float)bounds;
|
||||
float maxV = (float)((result.y) + info.height()) / (float)bounds;
|
||||
System.out.println("Baking: MinU="+minU+", MinV="+minV+", MaxU="+maxU+", MaxV="+maxV+", "+result.x+", "+result.y);
|
||||
return new Glyth(id(), minU, minV, maxU, maxV, info.left(), info.right(), info.top(), info.bottom());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -100,9 +102,17 @@ public class FontTexture extends BaseTexture {
|
|||
}
|
||||
int dw = width - iw;
|
||||
int dh = height - ih;
|
||||
children = new Slot[dw > 0 && dh > 0 ? 3 : 2];
|
||||
children[0] = new Slot(x, y, iw, ih);
|
||||
expandSlot(iw, ih, dw, dh);
|
||||
children = new Slot[2];
|
||||
if(dw > dh) {
|
||||
int offset = MathUtils.ceil(iw / 50F);
|
||||
children[0] = new Slot(x, y, iw, height);
|
||||
children[1] = new Slot(x + iw + offset, y, dw - offset, height);
|
||||
}
|
||||
else {
|
||||
int offset = MathUtils.ceil(ih / 50F);
|
||||
children[0] = new Slot(x, y, width, ih);
|
||||
children[1] = new Slot(x, y + ih + offset, width, dh - offset);
|
||||
}
|
||||
return children[0].insert(info);
|
||||
}
|
||||
for(int i = 0,m=children.length;i<m;i++) {
|
||||
|
@ -111,22 +121,7 @@ public class FontTexture extends BaseTexture {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void expandSlot(int rw, int rh, int dw, int dh) {
|
||||
if(dw > 0 && dh > 0) {
|
||||
if(dw >= dh) {
|
||||
children[1] = new Slot(x + rw, y, dw, rh);
|
||||
children[2] = new Slot(x, y + rh, width, dh);
|
||||
}
|
||||
else {
|
||||
children[1] = new Slot(x, y + rh, rw, dh);
|
||||
children[2] = new Slot(x + rw, y, dw, height);
|
||||
}
|
||||
}
|
||||
else if(dw == 0) children[1] = new Slot(x, y + rh, rw, dh);
|
||||
else if(dh == 0) children[1] = new Slot(x + rw, y, dw, rh);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Slot[x="+x+", y="+y+", w="+width+", h="+height+"]";
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package speiger.src.coreengine.rendering.gui.font.glyth;
|
||||
|
||||
public record Glyth(int texture, float minU, float minV, float maxU, float maxV, int left, int right, int top, int bottom) {
|
||||
public record Glyth(int texture, float minU, float minV, float maxU, float maxV, float left, float right, float top, float bottom) {
|
||||
public static final Glyth EMPTY = new Glyth();
|
||||
|
||||
private Glyth() {
|
||||
this(-1, 0F, 0F, 0F, 0F, 0, 0, 0, 0);
|
||||
this(-1, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F);
|
||||
}
|
||||
|
||||
public Glyth(int texture, float minU, float minV, float maxU, float maxV) {
|
||||
|
|
|
@ -7,7 +7,7 @@ public interface IGlythSheetInfo {
|
|||
public default float yOffset() { return 3F; }
|
||||
public float oversample();
|
||||
public boolean isColored();
|
||||
public void upload(int x, int y);
|
||||
public void upload(int texture, int x, int y);
|
||||
|
||||
public default float left() { return xOffset(); }
|
||||
public default float right() { return xOffset() + width() / oversample(); }
|
||||
|
|
|
@ -41,10 +41,10 @@ public class MissingGlyth implements GlythData {
|
|||
@Override
|
||||
public int height() { return height; }
|
||||
@Override
|
||||
public void upload(int x, int y) {
|
||||
public void upload(int texture, int x, int y) {
|
||||
Drawable drawable = new Drawable(FontTexture.formatByColor(false), width, height);
|
||||
draw(drawable);
|
||||
drawable.upload(x, y, 0, 0, width, height);
|
||||
drawable.upload(texture, x, y, 0, 0, width, height);
|
||||
drawable.close();
|
||||
}
|
||||
@Override
|
||||
|
@ -58,7 +58,7 @@ public class MissingGlyth implements GlythData {
|
|||
|
||||
private void draw(Drawable texture) {
|
||||
texture.fill(0, 0, width, height, 255);
|
||||
int offset = MathUtils.ceil(width / 7.5F);
|
||||
int offset = MathUtils.ceil(width / 5F);
|
||||
texture.fill(offset, offset, width - offset * 2, height - offset * 2, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package speiger.src.coreengine.rendering.gui.font.providers;
|
||||
|
||||
import org.lwjgl.util.freetype.FreeType;
|
||||
|
||||
import speiger.src.coreengine.rendering.gui.font.glyth.GlythData;
|
||||
|
||||
public class FreeTypeProvider implements IFontProvider {
|
||||
|
||||
public void test() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlythData glythData(int codepoint, int style, float size, float oversample) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,6 @@ import speiger.src.coreengine.rendering.gui.font.glyth.GlythData;
|
|||
import speiger.src.coreengine.rendering.gui.font.glyth.GlythData.EmptyGlythData;
|
||||
import speiger.src.coreengine.rendering.gui.font.glyth.IGlythSheetInfo;
|
||||
import speiger.src.coreengine.rendering.textures.custom.Drawable;
|
||||
import speiger.src.coreengine.rendering.utils.GLStateTracker;
|
||||
import speiger.src.coreengine.utils.helpers.JsonUtil;
|
||||
|
||||
public class STBTrueTypeProvider implements IFontProvider {
|
||||
|
@ -203,11 +202,10 @@ public class STBTrueTypeProvider implements IFontProvider {
|
|||
@Override
|
||||
public boolean isColored() { return false; }
|
||||
@Override
|
||||
public void upload(int x, int y) {
|
||||
System.out.println("Testing: "+GLStateTracker.instance().textures.getTextureId(0));
|
||||
public void upload(int texture, int x, int y) {
|
||||
Drawable drawable = new Drawable(FontTexture.formatByColor(false), width, height);
|
||||
drawable.drawFont(owner.info, glyth, owner.xOff, owner.yOff, 0, 0, width, height, scale, scale);
|
||||
drawable.upload(x, y, 0, 0, width, height);
|
||||
drawable.upload(texture, x, y, 0, 0, width, height);
|
||||
drawable.close();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,28 +2,20 @@ package speiger.src.coreengine.rendering.shader.uniform.base;
|
|||
|
||||
import org.lwjgl.opengl.GL41;
|
||||
|
||||
import speiger.src.coreengine.rendering.shader.uniform.IAutoUniform;
|
||||
import speiger.src.coreengine.rendering.shader.uniform.Uniform;
|
||||
import speiger.src.coreengine.rendering.textures.base.ITexture;
|
||||
import speiger.src.coreengine.rendering.utils.AllocationTracker;
|
||||
import speiger.src.coreengine.rendering.utils.GLStateTracker;
|
||||
|
||||
public class TextureUniform extends Uniform implements IAutoUniform {
|
||||
final int unit;
|
||||
int value;
|
||||
public class TextureUniform extends Uniform {
|
||||
int unit;
|
||||
|
||||
public TextureUniform(String name, int unit) {
|
||||
super(name);
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public TextureUniform set(ITexture texture) {
|
||||
return set(texture.id());
|
||||
}
|
||||
|
||||
public TextureUniform set(int id) {
|
||||
if(this.value != id) {
|
||||
this.value = id;
|
||||
public TextureUniform set(int unit) {
|
||||
if(this.unit != unit) {
|
||||
this.unit = unit;
|
||||
update();
|
||||
}
|
||||
return this;
|
||||
|
@ -31,12 +23,7 @@ public class TextureUniform extends Uniform implements IAutoUniform {
|
|||
|
||||
@Override
|
||||
protected void processChanges(int programId, int location) {
|
||||
GL41.glProgramUniform1i(programId, location, value);
|
||||
GL41.glProgramUniform1i(programId, location, unit);
|
||||
AllocationTracker.INSTANCE.addGPUBytes(4L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(int programId) {
|
||||
GLStateTracker.instance().textures.bind(unit, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,11 @@ public class VertexBuilder implements IVertexBuilder {
|
|||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
MemoryUtil.memFree(buffer);
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
public VertexBuilder start(GLMode mode, VertexFormat format) {
|
||||
this.mode = mode;
|
||||
this.format = format;
|
||||
|
|
|
@ -16,8 +16,7 @@ public abstract class BaseTexture implements ITexture {
|
|||
}
|
||||
|
||||
protected void createTexture() {
|
||||
this.id = GLFunctions.createTexture();
|
||||
bind();
|
||||
this.id = GLFunctions.createTexture(textureType());
|
||||
}
|
||||
|
||||
protected IGLValue textureType() {
|
||||
|
|
|
@ -15,20 +15,20 @@ public class TextureMetadata {
|
|||
int internalFormat;
|
||||
int externalFormat;
|
||||
int dataFormat;
|
||||
boolean isSTBData = true;
|
||||
boolean mipmapping = true;
|
||||
boolean isSTBData = false;
|
||||
boolean mipmapping = false;
|
||||
LongList arguments = new LongArrayList();
|
||||
IntConsumer specialarguments;
|
||||
|
||||
private TextureMetadata() {}
|
||||
|
||||
public void applyArguments(IGLValue textureType) {
|
||||
public void applyArguments(int texture) {
|
||||
for(int i = 0,m=arguments.size();i<m;i++) {
|
||||
long value = arguments.getLong(i);
|
||||
GLFunctions.textureParameter(textureType.glValue(), BitUtil.intKey(value), BitUtil.intValue(value));
|
||||
GLFunctions.textureParameter(texture, BitUtil.intKey(value), BitUtil.intValue(value));
|
||||
}
|
||||
if(specialarguments != null) {
|
||||
specialarguments.accept(textureType.glValue());
|
||||
specialarguments.accept(texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,7 @@ import speiger.src.coreengine.math.misc.ColorSpaces;
|
|||
import speiger.src.coreengine.rendering.utils.GLFunctions;
|
||||
import speiger.src.coreengine.rendering.utils.GLStateTracker;
|
||||
import speiger.src.coreengine.rendering.utils.values.GLDataType;
|
||||
import speiger.src.coreengine.rendering.utils.values.IGLValue;
|
||||
import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureComponentFormat;
|
||||
import speiger.src.coreengine.rendering.utils.values.textures.GLTextureType;
|
||||
|
||||
public class Drawable implements IDrawable, AutoCloseable {
|
||||
ITextureComponentFormat format;
|
||||
|
@ -73,11 +71,11 @@ public class Drawable implements IDrawable, AutoCloseable {
|
|||
STBTruetype.nstbtt_MakeGlyphBitmapSubpixel(info.address(), pixels + offset(targetX, targetY), width, height, width(), scaleX, scaleY, sourceX, sourceY, glyth);
|
||||
}
|
||||
|
||||
public void upload(int targetX, int targetY, int sourceX, int sourceY, int width, int height) {
|
||||
upload(GLTextureType.TEXTURE_2D, 0, targetX, targetY, sourceX, sourceY, width, height);
|
||||
public void upload(int texture, int targetX, int targetY, int sourceX, int sourceY, int width, int height) {
|
||||
upload(texture, 0, targetX, targetY, sourceX, sourceY, width, height);
|
||||
}
|
||||
|
||||
public void upload(IGLValue textureType, int level, int targetX, int targetY, int sourceX, int sourceY, int width, int height) {
|
||||
public void upload(int texture, int level, int targetX, int targetY, int sourceX, int sourceY, int width, int height) {
|
||||
ensureValid(sourceX, sourceY);
|
||||
ensureValid(sourceX + width, sourceY + height);
|
||||
GLStateTracker tracker = GLStateTracker.instance();
|
||||
|
@ -85,7 +83,7 @@ public class Drawable implements IDrawable, AutoCloseable {
|
|||
tracker.unpack_alignment.set(format.components());
|
||||
tracker.unpack_skip_pixel.set(sourceX);
|
||||
tracker.unpack_skip_rows.set(sourceY);
|
||||
GLFunctions.upload2DSubImage(textureType, level, targetX, targetY, width, height, format, GLDataType.UNSIGNED_BYTE, pixels);
|
||||
GLFunctions.upload2DSubImage(texture, level, targetX, targetY, width, height, format, GLDataType.UNSIGNED_BYTE, pixels);
|
||||
tracker.unpack_row_length.setDefault();
|
||||
tracker.unpack_skip_pixel.setDefault();
|
||||
tracker.unpack_skip_rows.setDefault();
|
||||
|
|
|
@ -18,7 +18,7 @@ import speiger.src.coreengine.rendering.utils.values.textures.GLTextureParameter
|
|||
import speiger.src.coreengine.rendering.utils.values.textures.GLTextureValue;
|
||||
|
||||
public class DynamicTexture extends BaseTexture implements IDynamicTexture {
|
||||
public static final TextureMetadata DEFAULT_PARAMETERS = TextureMetadata.builder()
|
||||
public static final TextureMetadata DEFAULT_PARAMETERS = TextureMetadata.builder().internalFormat(GLTextureFormat.RGBAI).externalFormat(GLTextureFormat.RGBA).dataFormat(GLDataType.UNSIGNED_BYTE)
|
||||
.arguement(GLTextureParameter.MIN_FILTER, GLTextureValue.NEAREST).arguement(GLTextureParameter.MAG_FILTER, GLTextureValue.NEAREST)
|
||||
.arguement(GLTextureParameter.WRAP_S, GLTextureValue.CLAMP_TO_EDGE).arguement(GLTextureParameter.WRAP_T, GLTextureValue.CLAMP_TO_EDGE).build();
|
||||
IntSet dirtySections = new IntLinkedOpenHashSet();
|
||||
|
@ -39,8 +39,8 @@ public class DynamicTexture extends BaseTexture implements IDynamicTexture {
|
|||
@Override
|
||||
public void load(IAssetProvider provider) {
|
||||
createTexture();
|
||||
metadata.applyArguments(textureType());
|
||||
GLFunctions.upload2DImage(textureType(), 0, GLTextureFormat.RGBA, width, height, 0, GLTextureFormat.RGBA, GLDataType.UNSIGNED_BYTE, data);
|
||||
metadata.applyArguments(id());
|
||||
GLFunctions.prepare2DImage(id(), 1, metadata, width, height);
|
||||
dirtySections.clear();
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,8 @@ public class DynamicTexture extends BaseTexture implements IDynamicTexture {
|
|||
|
||||
@Override
|
||||
public void process(boolean full) {
|
||||
bind();
|
||||
if(full) {
|
||||
GLFunctions.upload2DImage(textureType(), 0, GLTextureFormat.RGBA, width, height, 0, GLTextureFormat.RGBA, GLDataType.UNSIGNED_BYTE, data);
|
||||
GLFunctions.upload2DSubImage(id(), 0, 0, 0, width, height, GLTextureFormat.RGBA, GLDataType.UNSIGNED_BYTE, data);
|
||||
dirtySections.clear();
|
||||
return;
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ public class DynamicTexture extends BaseTexture implements IDynamicTexture {
|
|||
protected void uploadPixels(GLStateTracker tracker, int x, int y) {
|
||||
tracker.unpack_skip_pixel.set(x);
|
||||
tracker.unpack_skip_rows.set(y);
|
||||
GLFunctions.upload2DSubImage(textureType(), 0, x, y, 16, 16, GLTextureFormat.RGBA, GLDataType.UNSIGNED_BYTE, data);
|
||||
GLFunctions.upload2DSubImage(id(), 0, x, y, 16, 16, GLTextureFormat.RGBA, GLDataType.UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
protected long offset(int x, int y) {
|
||||
|
|
|
@ -48,8 +48,8 @@ public class DirectTexture extends BaseTexture {
|
|||
|
||||
private void loadTexture() {
|
||||
createTexture();
|
||||
metadata.applyArguments(textureType());
|
||||
GLFunctions.upload2DImage(textureType(), 0, metadata, width, height, 0, imageData);
|
||||
metadata.applyArguments(id());
|
||||
GLFunctions.upload2DImage(id(), 0, metadata, width, height, 0, imageData);
|
||||
if(metadata.generateMipMappings()) GLFunctions.generateMipMaps(textureType());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import speiger.src.coreengine.rendering.utils.values.textures.GLTextureValue;
|
|||
|
||||
public class SimpleTexture extends BaseTexture {
|
||||
public static final TextureMetadata DEFAULT_DATA = TextureMetadata.builder()
|
||||
.externalFormat(GLTextureFormat.RGBA).internalFormat(GLTextureFormat.RGBA).dataFormat(GLDataType.UNSIGNED_BYTE).mipmapping(false)
|
||||
.externalFormat(GLTextureFormat.RGBA).internalFormat(GLTextureFormat.RGBAI).dataFormat(GLDataType.UNSIGNED_BYTE).mipmapping(false)
|
||||
.arguement(GLTextureParameter.MIN_FILTER, GLTextureValue.NEAREST).arguement(GLTextureParameter.MAG_FILTER, GLTextureValue.NEAREST)
|
||||
.arguement(GLTextureParameter.WRAP_S, GLTextureValue.CLAMP_TO_EDGE).arguement(GLTextureParameter.WRAP_T, GLTextureValue.CLAMP_TO_EDGE).build();
|
||||
AssetLocation location;
|
||||
|
@ -58,8 +58,8 @@ public class SimpleTexture extends BaseTexture {
|
|||
}
|
||||
if(address == 0L) return;
|
||||
createTexture();
|
||||
metadata.applyArguments(textureType());
|
||||
GLFunctions.upload2DImage(textureType(), 0, metadata, width, height, 0, address);
|
||||
metadata.applyArguments(id());
|
||||
GLFunctions.upload2DImage(id(), 0, metadata, width, height, 0, address);
|
||||
if(metadata.generateMipMappings()) GLFunctions.generateMipMaps(textureType());
|
||||
STBImage.nstbi_image_free(address);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package speiger.src.coreengine.rendering.utils;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL45;
|
||||
|
||||
import speiger.src.coreengine.rendering.textures.base.TextureMetadata;
|
||||
import speiger.src.coreengine.rendering.utils.values.IGLValue;
|
||||
|
@ -12,46 +12,51 @@ import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureParameter;
|
|||
|
||||
public class GLFunctions {
|
||||
|
||||
public static int createTexture() {
|
||||
return GL11.glGenTextures();
|
||||
public static int createTexture(IGLValue textureType) {
|
||||
return GL45.glCreateTextures(textureType.glValue());
|
||||
}
|
||||
|
||||
public static void deleteTextures(int... id) {
|
||||
GL11.glDeleteTextures(id);
|
||||
}
|
||||
|
||||
public static void textureParameter(IGLValue type, ITextureParameter parameter, IGLValue value) {
|
||||
textureParameter(type, parameter, value.glValue());
|
||||
public static void textureParameter(int texture, ITextureParameter parameter, IGLValue value) {
|
||||
textureParameter(texture, parameter, value.glValue());
|
||||
}
|
||||
|
||||
public static void textureParameter(IGLValue type, ITextureParameter parameter, int value) {
|
||||
public static void textureParameter(int texture, ITextureParameter parameter, int value) {
|
||||
if(!parameter.isValid(value)) throw new IllegalArgumentException("Value ["+value+"] isn't supported for GL Function ["+parameter.glValue()+"], only int functions are supported with this");
|
||||
textureParameter(type.glValue(), parameter.glValue(), value);
|
||||
textureParameter(texture, parameter.glValue(), value);
|
||||
}
|
||||
|
||||
public static void textureParameter(int type, int parameter, int value) {
|
||||
GL15.glTexParameteri(type, parameter, value);
|
||||
public static void textureParameter(int texture, int parameter, int value) {
|
||||
GL45.glTextureParameteri(texture, parameter, value);
|
||||
}
|
||||
|
||||
public static void upload2DImage(IGLValue target, int mipmaps, TextureMetadata metadata, int width, int height, int border, long pixels) {
|
||||
upload2DImage(target.glValue(), mipmaps, metadata.getInternalFormat(), width, width, border, metadata.getExternalFormat(), metadata.getDataFormat(), pixels);
|
||||
public static void prepare2DImage(int texture, int levels, TextureMetadata metadata, int width, int height) {
|
||||
GL45.glTextureStorage2D(texture, levels, metadata.getInternalFormat(), width, height);
|
||||
}
|
||||
|
||||
public static void upload2DImage(IGLValue target, int mipmaps, ITextureFormatType internalFormat, int width, int height, int border, ITextureFormatType externalFormat, IGLDataType data, long pixels) {
|
||||
upload2DImage(target.glValue(), mipmaps, internalFormat.glValue(), width, height, border, externalFormat.glValue(), data.glValue(), pixels);
|
||||
public static void upload2DImage(int texture, int mipmaps, TextureMetadata metadata, int width, int height, int border, long pixels) {
|
||||
upload2DImage(texture, mipmaps, metadata.getInternalFormat(), width, width, border, metadata.getExternalFormat(), metadata.getDataFormat(), pixels);
|
||||
}
|
||||
|
||||
public static void upload2DImage(int target, int mipmaps, int internalFormat, int width, int height, int border, int externalFormat, int dataFormat, long pixels) {
|
||||
GL11.glTexImage2D(target, mipmaps, internalFormat, width, height, border, externalFormat, dataFormat, pixels);
|
||||
public static void upload2DImage(int texture, int mipmaps, ITextureFormatType internalFormat, int width, int height, int border, ITextureFormatType externalFormat, IGLDataType data, long pixels) {
|
||||
upload2DImage(texture, mipmaps, internalFormat.glValue(), width, height, border, externalFormat.glValue(), data.glValue(), pixels);
|
||||
}
|
||||
|
||||
public static void upload2DSubImage(IGLValue target, int level, int xoffset, int yoffset, int width, int height, ITextureFormatType format, IGLDataType type, long pixels) {
|
||||
upload2DSubImage(target.glValue(), level, xoffset, yoffset, width, height, format.glValue(), type.glValue(), pixels);
|
||||
public static void upload2DImage(int texture, int mipmaps, int internalFormat, int width, int height, int border, int externalFormat, int dataFormat, long pixels) {
|
||||
GL45.glTextureStorage2D(texture, mipmaps+1, internalFormat, width, height);
|
||||
GL45.glTextureSubImage2D(texture, mipmaps, 0, 0, width, height, externalFormat, dataFormat, pixels);
|
||||
}
|
||||
|
||||
public static void upload2DSubImage(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, long pixels) {
|
||||
GL15.nglTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, pixels);
|
||||
|
||||
public static void upload2DSubImage(int texture, int level, int xoffset, int yoffset, int width, int height, ITextureFormatType format, IGLDataType type, long pixels) {
|
||||
// if(format.internal()) throw new IllegalArgumentException("Format ["+format.glValue()+"] is internal");
|
||||
upload2DSubImage(texture, level, xoffset, yoffset, width, height, format.glValue(), type.glValue(), pixels);
|
||||
}
|
||||
|
||||
public static void upload2DSubImage(int texture, int level, int xOffset, int yOffset, int width, int height, int format, int type, long pixels) {
|
||||
GL45.glTextureSubImage2D(texture, level, xOffset, yOffset, width, height, format, type, pixels);
|
||||
}
|
||||
|
||||
public static void generateMipMaps(IGLValue type) {
|
||||
|
|
|
@ -8,6 +8,10 @@ import org.lwjgl.opengl.GL45;
|
|||
public class TextureState implements IGLState {
|
||||
int[] textures = new int[GL20.GL_TEXTURE31 - GL20.GL_TEXTURE0];
|
||||
|
||||
public TextureState bind(int texture) {
|
||||
return bind(0, texture);
|
||||
}
|
||||
|
||||
public TextureState bind(int unit, int texture) {
|
||||
if(textures[unit] != texture) {
|
||||
this.textures[unit] = texture;
|
||||
|
|
|
@ -6,14 +6,16 @@ import org.lwjgl.opengl.GL30;
|
|||
import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureComponentFormat;
|
||||
|
||||
public enum GLTextureFormat implements ITextureComponentFormat {
|
||||
R(GL11.GL_RED, 1, 0, -1, -1, -1, true),
|
||||
RG(GL30.GL_RG, 2, 0, 1, -1, -1, true),
|
||||
RGB(GL11.GL_RGB, 3, 0, 1, 2, -1, true),
|
||||
RGBA(GL11.GL_RGBA, 4, 0, 1, 2, 3, true),
|
||||
DEPTH(GL11.GL_DEPTH_COMPONENT, 1, 0, -1, -1, -1, true),
|
||||
DEPTH_STENCIL(GL30.GL_DEPTH_STENCIL, 2, 0, 1, -1, -1, true),
|
||||
LUMINANCE(GL11.GL_LUMINANCE, 1, 0, 0, 0, 0, true),
|
||||
LUMINANCE_ALPHA(GL11.GL_LUMINANCE_ALPHA, 2, 0, -1, -1, 1, true);
|
||||
R(GL11.GL_RED, 1, 0, -1, -1, -1, false),
|
||||
RG(GL30.GL_RG, 2, 0, 1, -1, -1, false),
|
||||
RGB(GL11.GL_RGB, 3, 0, 1, 2, -1, false),
|
||||
RGBI(GL11.GL_RGB8, 3, 0, 1, 2, -1, true),
|
||||
RGBA(GL11.GL_RGBA, 4, 0, 1, 2, 3, false),
|
||||
RGBAI(GL11.GL_RGBA8, 4, 0, 1, 2, 3, true),
|
||||
DEPTH(GL11.GL_DEPTH_COMPONENT, 1, 0, -1, -1, -1, false),
|
||||
DEPTH_STENCIL(GL30.GL_DEPTH_STENCIL, 2, 0, 1, -1, -1, false),
|
||||
LUMINANCE(GL30.GL_R8, 1, 0, 0, 0, 0, true),
|
||||
LUMINANCE_ALPHA(GL11.GL_LUMINANCE8_ALPHA8, 2, 0, -1, -1, 1, true);
|
||||
|
||||
int glMode;
|
||||
boolean internal;
|
||||
|
@ -52,8 +54,8 @@ public enum GLTextureFormat implements ITextureComponentFormat {
|
|||
|
||||
public static int stbComponents(int glValue) {
|
||||
return switch(glValue) {
|
||||
case GL11.GL_LUMINANCE -> 1;
|
||||
case GL11.GL_LUMINANCE_ALPHA -> 2;
|
||||
case GL30.GL_R8, GL11.GL_RED -> 1;
|
||||
case GL11.GL_LUMINANCE8_ALPHA8, GL30.GL_RG -> 2;
|
||||
case GL11.GL_RGB -> 3;
|
||||
case GL11.GL_RGBA -> 4;
|
||||
default -> 0;
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
"type": "stb-ttf",
|
||||
"regular": {
|
||||
"file": "font/roboto/Roboto-Medium.ttf",
|
||||
"size": 18.5,
|
||||
"oversample": 3,
|
||||
"oversample": 1,
|
||||
"shadowOffset": 1,
|
||||
"skip": "",
|
||||
"offset": { "x": 0, "y": 0 }
|
||||
|
|
|
@ -8,6 +8,7 @@ out vec4 pass_color;
|
|||
out vec2 pass_tex;
|
||||
|
||||
uniform mat4 proViewMatrix;
|
||||
uniform mat4 modelmatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#version 330
|
||||
#version 420
|
||||
|
||||
in vec4 pass_color;
|
||||
in vec2 pass_tex;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D texture;
|
||||
layout(binding = 0) uniform sampler2D texture;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#version 330
|
||||
#version 420
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec2 in_tex;
|
||||
|
|
Loading…
Reference in New Issue