Update #45 - Fixed various issues with the client

This commit is contained in:
lax1dude
2024-12-14 20:54:34 -08:00
parent 12535d429f
commit 346047cf24
39 changed files with 571 additions and 208 deletions

View File

@ -930,6 +930,8 @@ public class EaglercraftGPU {
InstancedParticleRenderer.destroy();
EffectPipelineFXAA.destroy();
TextureCopyUtil.destroy();
FixedFunctionPipeline.flushCache();
StreamBuffer.destroyPool();
emulatedVAOs = false;
emulatedVAOState = null;
glesVers = -1;

View File

@ -76,8 +76,8 @@ public class FixedFunctionPipeline {
StreamBufferInstance sb = self.streamBuffer.getBuffer(buffer.remaining());
self.currentVertexArray = sb;
EaglercraftGPU.bindGLBufferArray(sb.vertexArray);
EaglercraftGPU.bindGLArrayBuffer(sb.vertexBuffer);
EaglercraftGPU.bindGLBufferArray(sb.getVertexArray());
EaglercraftGPU.bindGLArrayBuffer(sb.getVertexBuffer());
_wglBufferSubData(GL_ARRAY_BUFFER, 0, buffer);

View File

@ -7,7 +7,7 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
/**
* Copyright (c) 2023 lax1dude. All Rights Reserved.
* Copyright (c) 2023-2024 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -23,10 +23,48 @@ import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
*/
public class StreamBuffer {
public static final int poolSize = 16;
public final int initialSize;
public final int initialCount;
public final int maxCount;
protected static final PoolInstance[] pool = new PoolInstance[poolSize];
protected static int poolBufferID = 0;
static {
for(int i = 0; i < poolSize; ++i) {
pool[i] = new PoolInstance();
}
}
protected static class PoolInstance {
protected IBufferGL vertexBuffer = null;
protected int vertexBufferSize = 0;
}
private static PoolInstance fillPoolInstance() {
PoolInstance ret = pool[poolBufferID++];
if(poolBufferID > poolSize - 1) {
poolBufferID = 0;
}
return ret;
}
private static void resizeInstance(PoolInstance instance, int requiredMemory) {
if(instance.vertexBuffer == null) {
instance.vertexBuffer = _wglGenBuffers();
}
if(instance.vertexBufferSize < requiredMemory) {
int newSize = (requiredMemory & 0xFFFFF000) + 0x2000;
EaglercraftGPU.bindGLArrayBuffer(instance.vertexBuffer);
_wglBufferData(GL_ARRAY_BUFFER, newSize, GL_STREAM_DRAW);
instance.vertexBufferSize = newSize;
}
}
protected StreamBufferInstance[] buffers;
protected int currentBufferId = 0;
@ -36,9 +74,8 @@ public class StreamBuffer {
public static class StreamBufferInstance {
protected PoolInstance poolInstance = null;
protected IBufferArrayGL vertexArray = null;
protected IBufferGL vertexBuffer = null;
protected int vertexBufferSize = 0;
public boolean bindQuad16 = false;
public boolean bindQuad32 = false;
@ -48,7 +85,7 @@ public class StreamBuffer {
}
public IBufferGL getVertexBuffer() {
return vertexBuffer;
return poolInstance.vertexBuffer;
}
}
@ -58,9 +95,14 @@ public class StreamBuffer {
}
public StreamBuffer(int initialSize, int initialCount, int maxCount, IStreamBufferInitializer initializer) {
if(maxCount > poolSize) {
maxCount = poolSize;
}
this.buffers = new StreamBufferInstance[initialCount];
for(int i = 0; i < this.buffers.length; ++i) {
this.buffers[i] = new StreamBufferInstance();
StreamBufferInstance j = new StreamBufferInstance();
j.poolInstance = fillPoolInstance();
this.buffers[i] = j;
}
this.initialSize = initialSize;
this.initialCount = initialCount;
@ -70,18 +112,10 @@ public class StreamBuffer {
public StreamBufferInstance getBuffer(int requiredMemory) {
StreamBufferInstance next = buffers[(currentBufferId++) % buffers.length];
if(next.vertexBuffer == null) {
next.vertexBuffer = _wglGenBuffers();
}
resizeInstance(next.poolInstance, requiredMemory);
if(next.vertexArray == null) {
next.vertexArray = EaglercraftGPU.createGLBufferArray();
initializer.initialize(next.vertexArray, next.vertexBuffer);
}
if(next.vertexBufferSize < requiredMemory) {
int newSize = (requiredMemory & 0xFFFFF000) + 0x2000;
EaglercraftGPU.bindGLArrayBuffer(next.vertexBuffer);
_wglBufferData(GL_ARRAY_BUFFER, newSize, GL_STREAM_DRAW);
next.vertexBufferSize = newSize;
initializer.initialize(next.vertexArray, next.poolInstance.vertexBuffer);
}
return next;
}
@ -102,12 +136,10 @@ public class StreamBuffer {
if(buffers[i].vertexArray != null) {
EaglercraftGPU.destroyGLBufferArray(buffers[i].vertexArray);
}
if(buffers[i].vertexBuffer != null) {
_wglDeleteBuffers(buffers[i].vertexBuffer);
}
}
}
buffers = newArray;
refill();
}
overflowCounter = 0;
}else if(overflowCounter > 15) {
@ -125,25 +157,51 @@ public class StreamBuffer {
}
}
buffers = newArray;
refill();
}
overflowCounter = 0;
}
currentBufferId = 0;
}
private void refill() {
for(int i = 0; i < buffers.length; ++i) {
PoolInstance j = fillPoolInstance();
StreamBufferInstance k = buffers[i];
if(j != k.poolInstance) {
PoolInstance l = k.poolInstance;
k.poolInstance = j;
if(k.vertexArray != null) {
if(j.vertexBuffer == null) {
resizeInstance(j, l.vertexBufferSize);
}
initializer.initialize(k.vertexArray, j.vertexBuffer);
}
}
}
}
public void destroy() {
for(int i = 0; i < buffers.length; ++i) {
StreamBufferInstance next = buffers[i];
if(next.vertexArray != null) {
EaglercraftGPU.destroyGLBufferArray(next.vertexArray);
}
if(next.vertexBuffer != null) {
_wglDeleteBuffers(next.vertexBuffer);
}
}
buffers = new StreamBufferInstance[initialCount];
for(int i = 0; i < buffers.length; ++i) {
buffers[i] = new StreamBufferInstance();
for(int i = 0; i < initialCount; ++i) {
StreamBufferInstance j = new StreamBufferInstance();
j.poolInstance = fillPoolInstance();
buffers[i] = j;
}
}
public static void destroyPool() {
for(int i = 0; i < pool.length; ++i) {
if(pool[i].vertexBuffer != null) {
_wglDeleteBuffers(pool[i].vertexBuffer);
pool[i].vertexBuffer = null;
}
}
}