Skip to content

Commit

Permalink
Impl v1
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed May 30, 2022
1 parent 0ad73f8 commit b9ff46e
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/net/coderbot/iris/IrisApiV0Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import net.coderbot.iris.pipeline.FixedFunctionWorldRenderingPipeline;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.shadows.ShadowRenderingState;
import net.coderbot.iris.vertices.IrisTextVertexSinkImpl;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.api.v0.IrisApiConfig;
import net.irisshaders.iris.api.v0.IrisTextVertexSink;
import net.minecraft.client.gui.screens.Screen;

import java.nio.ByteBuffer;
import java.util.function.IntFunction;

public class IrisApiV0Impl implements IrisApi {
public static final IrisApiV0Impl INSTANCE = new IrisApiV0Impl();
private static final IrisApiV0ConfigImpl CONFIG = new IrisApiV0ConfigImpl();
Expand Down Expand Up @@ -47,4 +52,9 @@ public String getMainScreenLanguageKey() {
public IrisApiConfig getConfig() {
return CONFIG;
}

@Override
public IrisTextVertexSink createTextVertexSink(int maxQuadCount, IntFunction<ByteBuffer> bufferProvider) {
return new IrisTextVertexSinkImpl(maxQuadCount, bufferProvider);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package net.coderbot.iris.vertices;

import com.mojang.blaze3d.platform.MemoryTracker;
import com.mojang.blaze3d.vertex.VertexFormat;
import me.jellysquid.mods.sodium.client.gl.attribute.BufferVertexFormat;
import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView;
import net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp.GlyphVertexBufferWriterUnsafe;
import net.irisshaders.iris.api.v0.IrisTextVertexSink;

import java.nio.ByteBuffer;
import java.util.function.IntFunction;

public class IrisTextVertexSinkImpl implements IrisTextVertexSink, VertexBufferView {
static VertexFormat format = IrisVertexFormats.TERRAIN;
private final ByteBuffer buffer;
private int vertexCount;
private int elementOffset;
private GlyphVertexBufferWriterUnsafe drain;

public IrisTextVertexSinkImpl(int maxQuadSize, IntFunction<ByteBuffer> buffer) {
this.buffer = buffer.apply(format.getVertexSize() * 4 * maxQuadSize);
this.drain = new GlyphVertexBufferWriterUnsafe(this);
}

@Override
public VertexFormat getUnderlyingVertexFormat() {
return format;
}

@Override
public void quad(float minX, float minY, float maxX, float maxY, float z, int color, float minU, float minV, float maxU, float maxV, int light) {
drain.writeGlyph(minX, minY, 0.0F, color, minU, minV, light);
drain.writeGlyph(minX, maxY, 0.0F, color, minU, maxV, light);
drain.writeGlyph(maxX, maxY, 0.0F, color, maxU, maxV, light);
drain.writeGlyph(maxX, minY, 0.0F, color, maxU, minV, light);
}

@Override
public void flush() {
drain.flush();
}

@Override
public boolean ensureBufferCapacity(int i) {
return false;
}

@Override
public ByteBuffer getDirectBuffer() {
return buffer;
}

@Override
public int getWriterPosition() {
return this.elementOffset;
}

@Override
public void flush(int i, BufferVertexFormat bufferVertexFormat) {
this.vertexCount += vertexCount;
this.elementOffset += vertexCount * format.getVertexSize();
}

@Override
public BufferVertexFormat getVertexFormat() {
return BufferVertexFormat.from(format);
}
}
11 changes: 10 additions & 1 deletion src/main/java/net/irisshaders/iris/api/v0/IrisApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import net.coderbot.iris.IrisApiV0Impl;

import java.nio.ByteBuffer;
import java.util.function.IntFunction;

/**
* The entry point to the Iris API, major version 0. This is currently the latest
* version of the API.
Expand All @@ -22,7 +25,7 @@ static IrisApi getInstance() {
* if they wish to check whether given API calls are available on
* the currently installed Iris version.
*
* @return The current minor revision. Currently, revision 0.
* @return The current minor revision. Currently, revision 1.
*/
int getMinorApiRevision();

Expand Down Expand Up @@ -94,4 +97,10 @@ static IrisApi getInstance() {
* @since API v0.0
*/
IrisApiConfig getConfig();

/**
* Gets a text vertex sink to render into.
* @since API 0.1
*/
IrisTextVertexSink createTextVertexSink(int maxQuadCount, IntFunction<ByteBuffer> bufferProvider);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.irisshaders.iris.api.v0;

import com.mojang.blaze3d.vertex.VertexFormat;

public interface IrisTextVertexSink {
VertexFormat getUnderlyingVertexFormat();
void quad(float x1, float y1, float x2, float y2, float z, int rgba, float u1, float v1, float u2, float v2, int light);
void flush();
}

0 comments on commit b9ff46e

Please sign in to comment.