mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-27 18:38:14 -05:00
Update #35 - Fixes, improved dynamic lighting
This commit is contained in:
@ -66,7 +66,6 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -3,6 +3,7 @@ package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.IOUtils;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ImageData;
|
||||
|
||||
/**
|
||||
@ -75,4 +76,15 @@ public class EaglerBitwisePackedTexture {
|
||||
return img;
|
||||
}
|
||||
|
||||
public static ImageData loadTextureSafe(InputStream is, int alpha) throws IOException {
|
||||
ImageData bufferedimage;
|
||||
try {
|
||||
bufferedimage = loadTexture(is, alpha);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
|
||||
return bufferedimage;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class PBRTextureMapUtils {
|
||||
}catch(Throwable t) {
|
||||
}
|
||||
try {
|
||||
return EaglerBitwisePackedTexture.loadTexture(resMgr.getResource(new ResourceLocation("eagler:glsl/deferred/assets_pbr/" + fname + ".ebp")).getInputStream(), 255);
|
||||
return EaglerBitwisePackedTexture.loadTextureSafe(resMgr.getResource(new ResourceLocation("eagler:glsl/deferred/assets_pbr/" + fname + ".ebp")).getInputStream(), 255);
|
||||
}catch(Throwable t) {
|
||||
// dead code because teavm
|
||||
t.toString();
|
||||
|
@ -4,7 +4,6 @@ import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -17,30 +17,21 @@ package net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights;
|
||||
*/
|
||||
class DynamicLightInstance {
|
||||
|
||||
public final String lightName;
|
||||
long lastCacheHit = 0l;
|
||||
|
||||
double posX;
|
||||
double posY;
|
||||
double posZ;
|
||||
float radius;
|
||||
|
||||
public DynamicLightInstance(String lightName) {
|
||||
this.lightName = lightName;
|
||||
public DynamicLightInstance() {
|
||||
}
|
||||
|
||||
public void updateLight(double posX, double posY, double posZ, float radius) {
|
||||
this.lastCacheHit = System.currentTimeMillis();
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.posZ = posZ;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
public float getRadiusInWorld() {
|
||||
return radius;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionSta
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.IExtPipelineCompiler;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.ShaderSource;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights.program.DynamicLightsExtPipelineShader;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
|
||||
/**
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionPipeline;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
@ -31,14 +30,15 @@ import net.minecraft.util.MathHelper;
|
||||
public class DynamicLightsStateManager {
|
||||
|
||||
static final DynamicLightsPipelineCompiler deferredExtPipeline = new DynamicLightsPipelineCompiler();
|
||||
static final Map<String, DynamicLightInstance> lightRenderers = new HashMap();
|
||||
private static List<DynamicLightInstance> lightInstancePool = new ArrayList();
|
||||
private static int instancePoolIndex = 0;
|
||||
private static int maxListLengthTracker = 0;
|
||||
static final List<DynamicLightInstance> lightRenderList = new LinkedList();
|
||||
static final Matrix4f inverseViewMatrix = new Matrix4f();
|
||||
static int inverseViewMatrixSerial = 0;
|
||||
static DynamicLightBucketLoader bucketLoader = null;
|
||||
static DynamicLightsAcceleratedEffectRenderer accelParticleRenderer = null;
|
||||
static int lastTotal = 0;
|
||||
static long renderTimeout = 5000l;
|
||||
private static long lastTick = 0l;
|
||||
|
||||
public static final void enableDynamicLightsRender() {
|
||||
@ -52,6 +52,9 @@ public class DynamicLightsStateManager {
|
||||
accelParticleRenderer = new DynamicLightsAcceleratedEffectRenderer();
|
||||
accelParticleRenderer.initialize();
|
||||
}
|
||||
lightRenderList.clear();
|
||||
instancePoolIndex = 0;
|
||||
maxListLengthTracker = 0;
|
||||
}
|
||||
|
||||
public static final void bindAcceleratedEffectRenderer(EffectRenderer renderer) {
|
||||
@ -72,6 +75,8 @@ public class DynamicLightsStateManager {
|
||||
}
|
||||
destroyAll();
|
||||
lightRenderList.clear();
|
||||
instancePoolIndex = 0;
|
||||
maxListLengthTracker = 0;
|
||||
}
|
||||
|
||||
public static final boolean isDynamicLightsRender() {
|
||||
@ -99,21 +104,27 @@ public class DynamicLightsStateManager {
|
||||
|
||||
public static final void renderDynamicLight(String lightName, double posX, double posY, double posZ, float radius) {
|
||||
if(bucketLoader != null) {
|
||||
DynamicLightInstance dl = lightRenderers.get(lightName);
|
||||
if(dl == null) {
|
||||
lightRenderers.put(lightName, dl = new DynamicLightInstance(lightName));
|
||||
DynamicLightInstance dl;
|
||||
if(instancePoolIndex < lightInstancePool.size()) {
|
||||
dl = lightInstancePool.get(instancePoolIndex);
|
||||
}else {
|
||||
lightInstancePool.add(dl = new DynamicLightInstance());
|
||||
}
|
||||
++instancePoolIndex;
|
||||
dl.updateLight(posX, posY, posZ, radius);
|
||||
lightRenderList.add(dl);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void clearRenderList() {
|
||||
if(instancePoolIndex > maxListLengthTracker) {
|
||||
maxListLengthTracker = instancePoolIndex;
|
||||
}
|
||||
lightRenderList.clear();
|
||||
instancePoolIndex = 0;
|
||||
}
|
||||
|
||||
public static final void commitLightSourceBuckets(double renderPosX, double renderPosY, double renderPosZ) {
|
||||
updateTimers();
|
||||
lastTotal = lightRenderList.size();
|
||||
if(bucketLoader != null) {
|
||||
bucketLoader.clearBuckets();
|
||||
@ -131,7 +142,8 @@ public class DynamicLightsStateManager {
|
||||
bucketLoader.setRenderPos(renderPosX, renderPosY, renderPosZ);
|
||||
bucketLoader.truncateOverflowingBuffers();
|
||||
}
|
||||
lightRenderList.clear();
|
||||
updateTimers();
|
||||
clearRenderList();
|
||||
}
|
||||
|
||||
public static final void setupInverseViewMatrix() {
|
||||
@ -141,25 +153,21 @@ public class DynamicLightsStateManager {
|
||||
|
||||
private static final void updateTimers() {
|
||||
long millis = System.currentTimeMillis();
|
||||
if(millis - lastTick > 1000l) {
|
||||
if(millis - lastTick > 5000l) {
|
||||
lastTick = millis;
|
||||
Iterator<DynamicLightInstance> itr = lightRenderers.values().iterator();
|
||||
while(itr.hasNext()) {
|
||||
DynamicLightInstance dl = itr.next();
|
||||
if(millis - dl.lastCacheHit > renderTimeout) {
|
||||
dl.destroy();
|
||||
itr.remove();
|
||||
if(maxListLengthTracker < (lightInstancePool.size() >> 1)) {
|
||||
List<DynamicLightInstance> newPool = new ArrayList(Math.max(maxListLengthTracker, 16));
|
||||
for(int i = 0; i < maxListLengthTracker; ++i) {
|
||||
newPool.add(lightInstancePool.get(i));
|
||||
}
|
||||
lightInstancePool = newPool;
|
||||
}
|
||||
maxListLengthTracker = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void destroyAll() {
|
||||
Iterator<DynamicLightInstance> itr = lightRenderers.values().iterator();
|
||||
while(itr.hasNext()) {
|
||||
itr.next().destroy();
|
||||
}
|
||||
lightRenderers.clear();
|
||||
lightInstancePool = new ArrayList();
|
||||
}
|
||||
|
||||
public static String getF3String() {
|
||||
|
@ -1,11 +1,7 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_FRAGMENT_SHADER;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_VERTEX_SHADER;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
|
Reference in New Issue
Block a user