mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-25 14:44:28 +00:00
Adjust vsync and fps limiters, and fix WSR with player models (#2002)
This commit is contained in:
1 parent
8c31eec525
commit
3659b59db9
36 files changed
+1494
-292
No files matched your search
@@ -0,0 +1,8 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
import net.minecraft.client.model.TexturedQuad;
|
||||
|
||||
public interface ModelBoxQuads {
|
||||
|
||||
TexturedQuad[] angelica$getQuadList();
|
||||
}
|
||||
@@ -106,6 +106,10 @@ public final class ClientProxy extends CommonProxy {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
public static void applyVSyncMode(boolean vsyncEnabled) {
|
||||
GLStateManager.setVSyncMode(options().advanced.vsyncMode, vsyncEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
ModStatus.preInit();
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.gtnewhorizons.angelica.rendering;
|
||||
|
||||
import com.gtnewhorizons.angelica.AngelicaMod;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.backend.VSyncMode;
|
||||
|
||||
public final class FramePacer {
|
||||
|
||||
private static final int MIN_PLAUSIBLE_REFRESH_HZ = 20;
|
||||
private static final int MAX_PLAUSIBLE_REFRESH_HZ = 1000;
|
||||
private static final long REFRESH_POLL_NANOS = 1_000_000_000L;
|
||||
|
||||
private static long lastFrameTime;
|
||||
private static long fpsLimitOverhead;
|
||||
|
||||
private static long lastRefreshPollNanos;
|
||||
private static int cachedRefreshHz;
|
||||
private static boolean warnedUnknownRefresh;
|
||||
|
||||
private static VSyncMode lastVSyncMode = VSyncMode.ON;
|
||||
private static int lastCapHz;
|
||||
private static int lastRefreshHz;
|
||||
|
||||
private FramePacer() {}
|
||||
|
||||
public static int plausibleRefreshHz(int hz) {
|
||||
return hz >= MIN_PLAUSIBLE_REFRESH_HZ && hz <= MAX_PLAUSIBLE_REFRESH_HZ ? hz : 0;
|
||||
}
|
||||
|
||||
public static int pacingCeilingHz(VSyncMode mode, int capHz, int refreshHz) {
|
||||
if (mode.blocksOnVBlank()) return 0;
|
||||
final int cap = Math.max(capHz, 0);
|
||||
if (mode != VSyncMode.MAILBOX) return cap;
|
||||
final int refresh = plausibleRefreshHz(refreshHz);
|
||||
if (cap == 0) return refresh;
|
||||
return refresh == 0 ? cap : Math.min(cap, refresh);
|
||||
}
|
||||
|
||||
public static long sleepNanosFor(long targetNanos, long lastWorkNanos, long overheadNanos) {
|
||||
return targetNanos - lastWorkNanos - overheadNanos;
|
||||
}
|
||||
|
||||
public static int updateCeiling(int capHz) {
|
||||
lastVSyncMode = GLStateManager.getEffectiveVSyncMode();
|
||||
lastCapHz = Math.max(capHz, 0);
|
||||
lastRefreshHz = refreshHz();
|
||||
return pacingCeilingHz(lastVSyncMode, lastCapHz, lastRefreshHz);
|
||||
}
|
||||
|
||||
public static long pace(int ceilingHz) {
|
||||
if (ceilingHz > 0) {
|
||||
final long time = System.nanoTime();
|
||||
final long targetNanos = 1_000_000_000L / ceilingHz;
|
||||
|
||||
final long sleepNanos = sleepNanosFor(targetNanos, time - lastFrameTime, fpsLimitOverhead);
|
||||
if (sleepNanos > 0) {
|
||||
try {
|
||||
Thread.sleep(sleepNanos / 1_000_000, (int) sleepNanos % 1_000_000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
long overhead = System.nanoTime() - time - sleepNanos;
|
||||
if (overhead < 0 || overhead > targetNanos / 2) overhead = 0;
|
||||
fpsLimitOverhead = overhead;
|
||||
}
|
||||
}
|
||||
|
||||
final long time = System.nanoTime();
|
||||
final long period = time - lastFrameTime;
|
||||
lastFrameTime = time;
|
||||
return period;
|
||||
}
|
||||
|
||||
private static int refreshHz() {
|
||||
final long now = System.nanoTime();
|
||||
if (lastRefreshPollNanos == 0L || now - lastRefreshPollNanos >= REFRESH_POLL_NANOS) {
|
||||
lastRefreshPollNanos = now;
|
||||
cachedRefreshHz = GLStateManager.getDisplayRefreshRateHz();
|
||||
}
|
||||
final int hz = plausibleRefreshHz(cachedRefreshHz);
|
||||
|
||||
if (hz == 0 && lastVSyncMode == VSyncMode.MAILBOX && !warnedUnknownRefresh) {
|
||||
warnedUnknownRefresh = true;
|
||||
AngelicaMod.LOGGER.warn("Display refresh rate reported as {}Hz; Mailbox will not be paced to the refresh rate. The Max Framerate setting still applies.", cachedRefreshHz);
|
||||
}
|
||||
return hz;
|
||||
}
|
||||
|
||||
public static String debugIndicator(VSyncMode mode, int refreshHz, int capHz) {
|
||||
final boolean vsync = mode.blocksOnVBlank();
|
||||
final boolean mailbox = mode == VSyncMode.MAILBOX;
|
||||
|
||||
final boolean showCap = capHz > 0 && !vsync;
|
||||
if (!vsync && !mailbox && !showCap) return null;
|
||||
|
||||
final StringBuilder sb = new StringBuilder(" [");
|
||||
if (vsync || mailbox) {
|
||||
sb.append(vsync ? "vsync" : "mailbox");
|
||||
if (refreshHz > 0) sb.append(' ').append(refreshHz);
|
||||
if (showCap) sb.append(", ");
|
||||
}
|
||||
if (showCap) sb.append("cap ").append(capHz);
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
|
||||
public static String debugIndicator() {
|
||||
return debugIndicator(lastVSyncMode, lastRefreshHz, lastCapHz);
|
||||
}
|
||||
|
||||
public static VSyncMode lastVSyncMode() { return lastVSyncMode; }
|
||||
|
||||
public static int lastCapHz() { return lastCapHz; }
|
||||
|
||||
public static int lastRefreshHz() { return lastRefreshHz; }
|
||||
}
|
||||
@@ -5,66 +5,103 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFlags;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.QuadConverter;
|
||||
import com.gtnewhorizons.angelica.glsm.profiling.Tracy;
|
||||
import com.gtnewhorizons.angelica.glsm.states.ColorMask;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureInfo;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ModelBoxQuads;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.PassRebindGate;
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.blending.DepthColorStorage;
|
||||
import net.coderbot.iris.gl.image.GlImage;
|
||||
import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.model.ModelBox;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.client.model.PositionTextureVertex;
|
||||
import net.minecraft.client.model.TexturedQuad;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memAddress0;
|
||||
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memAlloc;
|
||||
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memFree;
|
||||
|
||||
/**
|
||||
* Skins in 1.7.10 are 64x32 while modern has 64x64 textures. We have to address it here.
|
||||
* Feeds the shaderpack's world-space player reflection, which expects the modern 12-box player model:
|
||||
* 288 vertices over a 64x64 skin layout. 1.7.10 has 7 boxes and a 64x32 layout, so both are synthesized here.
|
||||
*/
|
||||
public final class PlayerReflectionCapture {
|
||||
|
||||
public static final int VERTEX_COUNT = 288;
|
||||
public static final int FLOATS_PER_VERTEX = 5; // x, y, z, u, v
|
||||
public static final int PART_COUNT = 12;
|
||||
public static final int VERTICES_PER_PART = VERTEX_COUNT / PART_COUNT;
|
||||
|
||||
private static final int RAW_INTS_PER_VERTEX = 8;
|
||||
|
||||
private static final int ATLAS_LAYOUT = 64;
|
||||
|
||||
private static final int VERTEX_FLAGS = VertexFlags.convertToFlags(true, false, true, false);
|
||||
|
||||
private static final Tracy.ZoneId Z_PLAYER_REFLECTION_FLUSH = Tracy.zoneId("playerReflectionFlush", Tracy.COLOR_IRIS);
|
||||
|
||||
private static boolean active;
|
||||
private static boolean drawnThisCapture;
|
||||
private static boolean captured;
|
||||
@Getter
|
||||
private static Object target;
|
||||
|
||||
@Getter
|
||||
private static EntityPlayer targetEntity;
|
||||
|
||||
private static boolean pending;
|
||||
private static final Matrix4f pendingModelView = new Matrix4f();
|
||||
private static int pendingSkin;
|
||||
private static int pendingEntityId;
|
||||
|
||||
private static int vbo;
|
||||
private static int vao;
|
||||
|
||||
private static int[] rawData;
|
||||
private static float[] vertexScratch;
|
||||
private static int skin64Tex;
|
||||
private static int skin64Size;
|
||||
private static boolean skin64Valid;
|
||||
private static ByteBuffer skinPixels;
|
||||
private static int lastCapturedSkin;
|
||||
private static int lastUploadedAtlas;
|
||||
private static int skinCopyWidth = 64;
|
||||
private static int skinCopyHeight = 32;
|
||||
private static TextureInfo lastCapturedInfo;
|
||||
private static int lastCapturedGeneration = -1;
|
||||
private static TextureInfo lastUploadedAtlasInfo;
|
||||
private static int lastUploadedAtlasGeneration = -1;
|
||||
private static int skinCopyWidth;
|
||||
private static int skinCopyHeight;
|
||||
private static ByteBuffer repackBuffer;
|
||||
private static long repackAddress;
|
||||
private static int repackCapacity;
|
||||
|
||||
private static final ModelRenderer[] partOrder = new ModelRenderer[PART_COUNT];
|
||||
private static final Matrix4f partMatrix = new Matrix4f();
|
||||
private static final Vector3f partVertex = new Vector3f();
|
||||
private static final Matrix4f savedModelView = new Matrix4f();
|
||||
|
||||
private PlayerReflectionCapture() {}
|
||||
|
||||
public static void begin(EntityPlayer player) {
|
||||
active = false;
|
||||
drawnThisCapture = false;
|
||||
captured = false;
|
||||
pending = false;
|
||||
target = null;
|
||||
targetEntity = null;
|
||||
if (player == null) return;
|
||||
@@ -79,24 +116,122 @@ public final class PlayerReflectionCapture {
|
||||
|
||||
public static void end() {
|
||||
active = false;
|
||||
pending = false;
|
||||
target = null;
|
||||
targetEntity = null;
|
||||
}
|
||||
|
||||
public static boolean shouldCapture() {
|
||||
return active && !drawnThisCapture;
|
||||
return active && !captured;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the 288-vertex player batch VBO.
|
||||
*/
|
||||
public static void drawPlayerCapture(float[] xyzuv) {
|
||||
if (drawnThisCapture) return;
|
||||
drawnThisCapture = true;
|
||||
public static void emitAndSubmit(ModelBiped model, float scale) {
|
||||
captured = true;
|
||||
|
||||
final float[] data = vertexScratch();
|
||||
emitModel(model, scale, data);
|
||||
|
||||
pendingModelView.set(GLStateManager.getModelViewMatrix());
|
||||
pendingSkin = GLStateManager.getBoundTextureForServerState(0);
|
||||
pendingEntityId = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity();
|
||||
pending = true;
|
||||
}
|
||||
|
||||
public static ModelRenderer[] partOrder(ModelBiped model, ModelRenderer[] out) {
|
||||
out[0] = model.bipedHead;
|
||||
out[1] = model.bipedHeadwear;
|
||||
out[2] = model.bipedRightArm;
|
||||
out[3] = model.bipedRightArm;
|
||||
out[4] = model.bipedLeftLeg;
|
||||
out[5] = model.bipedLeftLeg;
|
||||
out[6] = model.bipedLeftArm;
|
||||
out[7] = model.bipedLeftArm;
|
||||
out[8] = model.bipedRightLeg;
|
||||
out[9] = model.bipedRightLeg;
|
||||
out[10] = model.bipedBody;
|
||||
out[11] = model.bipedBody;
|
||||
return out;
|
||||
}
|
||||
|
||||
private static void emitModel(ModelBiped model, float scale, float[] out) {
|
||||
final ModelRenderer[] parts = partOrder(model, partOrder);
|
||||
int o = 0;
|
||||
for (int i = 0; i < PART_COUNT; i++) {
|
||||
o = emitBox(parts[i], quadsOf(parts[i]), out, o, scale);
|
||||
}
|
||||
}
|
||||
|
||||
private static TexturedQuad[] quadsOf(ModelRenderer part) {
|
||||
if (part == null || part.cubeList == null || part.cubeList.isEmpty()) return null;
|
||||
final ModelBox box = part.cubeList.getFirst();
|
||||
return ((ModelBoxQuads) box).angelica$getQuadList();
|
||||
}
|
||||
|
||||
public static int emitBox(ModelRenderer part, TexturedQuad[] quads, float[] out, int o, float scale) {
|
||||
if (part == null || quads == null || part.isHidden || !part.showModel || part.textureWidth > ATLAS_LAYOUT || part.textureHeight > ATLAS_LAYOUT) {
|
||||
final int end = o + VERTICES_PER_PART * FLOATS_PER_VERTEX;
|
||||
Arrays.fill(out, o, end, 0.0f);
|
||||
return end;
|
||||
}
|
||||
|
||||
final Matrix4f m = partMatrix
|
||||
.rotationZYX(part.rotateAngleZ, part.rotateAngleY, part.rotateAngleX)
|
||||
.setTranslation(
|
||||
part.offsetX + part.rotationPointX * scale,
|
||||
part.offsetY + part.rotationPointY * scale,
|
||||
part.offsetZ + part.rotationPointZ * scale);
|
||||
|
||||
final float uScale = part.textureWidth / ATLAS_LAYOUT;
|
||||
final float vScale = part.textureHeight / ATLAS_LAYOUT;
|
||||
final Vector3f v = partVertex;
|
||||
for (int q = 0; q < 6; q++) {
|
||||
final PositionTextureVertex[] corners = quads[q].vertexPositions;
|
||||
for (int c = 0; c < 4; c++) {
|
||||
final PositionTextureVertex corner = corners[c];
|
||||
v.set((float) corner.vector3D.xCoord * scale,
|
||||
(float) corner.vector3D.yCoord * scale,
|
||||
(float) corner.vector3D.zCoord * scale);
|
||||
m.transformPosition(v);
|
||||
out[o++] = v.x;
|
||||
out[o++] = v.y;
|
||||
out[o++] = v.z;
|
||||
out[o++] = corner.texturePositionX * uScale;
|
||||
out[o++] = corner.texturePositionY * vScale;
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public static void flush() {
|
||||
if (!pending) return;
|
||||
pending = false;
|
||||
if (!Iris.enabled) return;
|
||||
|
||||
final float[] xyzuv = vertexScratch;
|
||||
if (xyzuv == null || xyzuv.length < VERTEX_COUNT * FLOATS_PER_VERTEX) return;
|
||||
|
||||
// Build the Tessellator layout
|
||||
if (rawData == null) rawData = new int[VERTEX_COUNT * RAW_INTS_PER_VERTEX];
|
||||
PassRebindGate.rebindIfDirty();
|
||||
if (!(Iris.getPipelineManager().getPipelineNullable() instanceof DeferredWorldRenderingPipeline pipeline)) return;
|
||||
if (GLStateManager.getActiveProgram() != pipeline.getActivePassProgramId()) return;
|
||||
|
||||
if (Tracy.ENABLED) Tracy.beginZone(Z_PLAYER_REFLECTION_FLUSH);
|
||||
try {
|
||||
flushInner(xyzuv);
|
||||
} finally {
|
||||
if (Tracy.ENABLED) Tracy.endZone();
|
||||
}
|
||||
}
|
||||
|
||||
private static void flushInner(float[] xyzuv) {
|
||||
if (rawData == null) {
|
||||
rawData = new int[VERTEX_COUNT * RAW_INTS_PER_VERTEX];
|
||||
for (int i = 0; i < VERTEX_COUNT; i++) {
|
||||
final int d = i * RAW_INTS_PER_VERTEX;
|
||||
rawData[d + 5] = 0xFFFFFFFF; // color
|
||||
rawData[d + 6] = 0x00008000; // normal
|
||||
rawData[d + 7] = 0x00F000F0; // light
|
||||
}
|
||||
}
|
||||
final int[] raw = rawData;
|
||||
for (int i = 0; i < VERTEX_COUNT; i++) {
|
||||
final int s = i * FLOATS_PER_VERTEX;
|
||||
@@ -106,12 +241,8 @@ public final class PlayerReflectionCapture {
|
||||
raw[d + 2] = Float.floatToRawIntBits(xyzuv[s + 2]);
|
||||
raw[d + 3] = Float.floatToRawIntBits(xyzuv[s + 3]);
|
||||
raw[d + 4] = Float.floatToRawIntBits(xyzuv[s + 4]);
|
||||
raw[d + 5] = 0xFFFFFFFF; // color
|
||||
raw[d + 6] = 0x00008000; // normal
|
||||
raw[d + 7] = 0x00F000F0; // light
|
||||
}
|
||||
|
||||
// Pack into our own native buffer using the player model's vertex format
|
||||
final VertexFormat format = DefaultVertexFormat.ALL_FORMATS[VERTEX_FLAGS];
|
||||
ensureRepackCapacity(VERTEX_COUNT * format.getVertexSize());
|
||||
|
||||
@@ -119,25 +250,33 @@ public final class PlayerReflectionCapture {
|
||||
repackBuffer.position(0);
|
||||
repackBuffer.limit((int) (writePtr - repackAddress));
|
||||
|
||||
// Upload to our dedicated VBO at offset 0
|
||||
ensureVAO(format);
|
||||
GLStateManager.glBindVertexArray(vao);
|
||||
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
|
||||
GLStateManager.glBufferData(GL15.GL_ARRAY_BUFFER, repackBuffer, GL15.GL_STREAM_DRAW);
|
||||
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
// Bind a 64x64 copy of the skin as `tex`
|
||||
final int activeSkin = GLStateManager.getBoundTextureForServerState();
|
||||
final boolean haveSkin = activeSkin != 0 && activeSkin != skin64Tex;
|
||||
if (haveSkin) {
|
||||
ensureSkin64Texture();
|
||||
final int prevUnit = GL13.GL_TEXTURE0 + GLStateManager.getActiveTextureUnitForServerState();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
final int prevTexture = GLStateManager.getBoundTextureForServerState();
|
||||
|
||||
if (pendingSkin > 0 && pendingSkin != skin64Tex) {
|
||||
final TextureInfo info = TextureInfoCache.INSTANCE.getInfo(pendingSkin);
|
||||
final int skinGeneration = info.getUploadGeneration();
|
||||
final boolean skinChanged = info != lastCapturedInfo || skinGeneration != lastCapturedGeneration;
|
||||
|
||||
final GlImage atlas = GlImage.BY_NAME.get("playerAtlas_img");
|
||||
final int atlasId = atlas != null ? atlas.getId() : 0;
|
||||
final boolean skinChanged = activeSkin != lastCapturedSkin;
|
||||
final TextureInfo atlasInfo = atlasId > 0 ? TextureInfoCache.INSTANCE.getInfo(atlasId) : null;
|
||||
final int atlasGeneration = atlasInfo != null ? atlasInfo.getUploadGeneration() : 0;
|
||||
final boolean atlasChanged = atlasInfo != lastUploadedAtlasInfo || atlasGeneration != lastUploadedAtlasGeneration;
|
||||
|
||||
if (skinChanged) {
|
||||
final TextureInfo info = TextureInfoCache.INSTANCE.getInfo(activeSkin);
|
||||
lastCapturedInfo = info;
|
||||
lastCapturedGeneration = skinGeneration;
|
||||
skinCopyWidth = 0;
|
||||
skinCopyHeight = 0;
|
||||
|
||||
final int srcW = info.getWidth();
|
||||
final int srcH = info.getHeight();
|
||||
if (srcW > 0 && srcH > 0) {
|
||||
@@ -145,48 +284,72 @@ public final class PlayerReflectionCapture {
|
||||
if (skinPixels == null || skinPixels.capacity() < required) {
|
||||
skinPixels = ByteBuffer.allocateDirect(required).order(ByteOrder.nativeOrder());
|
||||
}
|
||||
// The 1.7.10 model UVs only address the top 64x32 region.
|
||||
skinCopyWidth = Math.min(64, srcW);
|
||||
skinCopyHeight = Math.min(32, srcH);
|
||||
|
||||
skinPixels.clear();
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, activeSkin);
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, pendingSkin);
|
||||
GLStateManager.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, skinPixels);
|
||||
lastCapturedSkin = activeSkin;
|
||||
skinCopyWidth = srcW;
|
||||
skinCopyHeight = srcH;
|
||||
}
|
||||
}
|
||||
|
||||
if (skinPixels != null && (skinChanged || atlasId != lastUploadedAtlas)) {
|
||||
skinPixels.rewind();
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, skin64Tex);
|
||||
GLStateManager.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, skinCopyWidth, skinCopyHeight, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, skinPixels);
|
||||
if (skinCopyWidth > 0 && (skinChanged || atlasChanged)) {
|
||||
ensureSkin64Texture(Math.max(skinCopyWidth, skinCopyHeight));
|
||||
|
||||
if (atlas != null) {
|
||||
final int prevRowLength = GLStateManager.glGetInteger(GL11.GL_UNPACK_ROW_LENGTH);
|
||||
GLStateManager.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, skinCopyWidth);
|
||||
try {
|
||||
skinPixels.rewind();
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, atlasId);
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, skin64Tex);
|
||||
GLStateManager.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, skinCopyWidth, skinCopyHeight, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, skinPixels);
|
||||
skin64Valid = true;
|
||||
|
||||
if (atlasInfo != null) {
|
||||
final int dstW = Math.min(atlasInfo.getWidth(), skinCopyWidth);
|
||||
final int dstH = Math.min(atlasInfo.getHeight(), skinCopyHeight);
|
||||
if (dstW > 0 && dstH > 0) {
|
||||
skinPixels.rewind();
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, atlasId);
|
||||
GLStateManager.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, dstW, dstH, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, skinPixels);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
GLStateManager.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, prevRowLength);
|
||||
}
|
||||
lastUploadedAtlas = atlasId;
|
||||
lastUploadedAtlasInfo = atlasInfo;
|
||||
lastUploadedAtlasGeneration = atlasInfo != null ? atlasInfo.getUploadGeneration() : 0;
|
||||
}
|
||||
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, skin64Tex);
|
||||
if (skin64Valid) GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, skin64Tex);
|
||||
}
|
||||
|
||||
final boolean maskable = !DepthColorStorage.isDepthColorLocked();
|
||||
final ColorMask prevColor = GLStateManager.getColorMask();
|
||||
final boolean pr = prevColor.red, pg = prevColor.green, pb = prevColor.blue, pa = prevColor.alpha;
|
||||
final boolean prevDepthWrite = GLStateManager.getDepthState().isEnabled();
|
||||
|
||||
GLStateManager.glColorMask(false, false, false, false);
|
||||
GLStateManager.glDepthMask(false);
|
||||
QuadConverter.drawQuadsAsTriangles(0, VERTEX_COUNT);
|
||||
GLStateManager.glDepthMask(prevDepthWrite);
|
||||
GLStateManager.glColorMask(pr, pg, pb, pa);
|
||||
final int prevEntityId = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity();
|
||||
savedModelView.set(GLStateManager.getModelViewMatrix());
|
||||
|
||||
if (haveSkin) {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, activeSkin);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(pendingEntityId);
|
||||
GLStateManager.setModelViewMatrix(pendingModelView);
|
||||
if (maskable) {
|
||||
GLStateManager.glColorMask(false, false, false, false);
|
||||
GLStateManager.glDepthMask(false);
|
||||
}
|
||||
try {
|
||||
QuadConverter.drawQuadsAsTriangles(0, VERTEX_COUNT);
|
||||
} finally {
|
||||
if (maskable) {
|
||||
GLStateManager.glDepthMask(prevDepthWrite);
|
||||
GLStateManager.glColorMask(pr, pg, pb, pa);
|
||||
}
|
||||
GLStateManager.setModelViewMatrix(savedModelView);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(prevEntityId);
|
||||
|
||||
GLStateManager.glBindVertexArray(0);
|
||||
GLStateManager.glBindVertexArray(0);
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, prevTexture);
|
||||
GLStateManager.glActiveTexture(prevUnit);
|
||||
}
|
||||
}
|
||||
|
||||
public static float[] vertexScratch() {
|
||||
@@ -205,16 +368,16 @@ public final class PlayerReflectionCapture {
|
||||
GLStateManager.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
private static void ensureSkin64Texture() {
|
||||
if (skin64Tex != 0) return;
|
||||
final int prev = GLStateManager.getBoundTextureForServerState();
|
||||
skin64Tex = GLStateManager.glGenTextures();
|
||||
private static void ensureSkin64Texture(int size) {
|
||||
if (skin64Tex != 0 && skin64Size == size) return;
|
||||
if (skin64Tex == 0) skin64Tex = GLStateManager.glGenTextures();
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, skin64Tex);
|
||||
final ByteBuffer zero = ByteBuffer.allocateDirect(64 * 64 * 4);
|
||||
GLStateManager.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, 64, 64, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, zero);
|
||||
final ByteBuffer zero = ByteBuffer.allocateDirect(size * size * 4);
|
||||
GLStateManager.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, zero);
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, prev);
|
||||
skin64Size = size;
|
||||
skin64Valid = false;
|
||||
}
|
||||
|
||||
private static void ensureRepackCapacity(int requiredBytes) {
|
||||
|
||||
+4
@@ -78,6 +78,10 @@ public class CeleritasDebugScreenHandler {
|
||||
if (transferInfo != null) {
|
||||
lines.add(transferInfo);
|
||||
}
|
||||
final String presentInfo = RENDER_BACKEND.getPresentDebugInfo();
|
||||
if (presentInfo != null) {
|
||||
lines.add(presentInfo);
|
||||
}
|
||||
if (SystemProperties.DEBUG_F3_DETAIL) {
|
||||
lines.addAll(TesrBatchRenderer.INSTANCE.getDebugDetailStrings());
|
||||
lines.add(ModelPartBatcher.INSTANCE.getDebugString());
|
||||
|
||||
Reference in new issue
Block a user