Did some things

This commit is contained in:
PeytonPlayz595 2024-03-18 01:26:45 -04:00
parent 0c9cf255cf
commit a4c4ca9652
27 changed files with 7423 additions and 7684 deletions

View File

@ -1,2 +1,2 @@
@echo off @echo off
java -jar desktopRuntime/eclipseProject/jars/CompilePackage.jar "desktopRuntime/resources/" "js/resources.mc" java -jar desktopRuntime/eclipseProject/jars/CompilePackage.jar "desktopRuntime/resources/" "web/resources.mc"

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
java -jar desktopRuntime/eclipseProject/jars/CompilePackage.jar "desktopRuntime/resources/" "js/resources.mc" java -jar desktopRuntime/eclipseProject/jars/CompilePackage.jar "desktopRuntime/resources/" "web/resources.mc"

View File

@ -1,9 +1,7 @@
// eaglercraft opengl 1.3 emulation // copyright (c) 2020-2023 lax1dude
// copyright (c) 2020 calder young
// creative commons BY-NC 4.0
#line 7 #line 4
precision highp int; precision highp int;
precision highp sampler2D; precision highp sampler2D;
@ -99,6 +97,8 @@ in vec2 v_texture0;
out vec4 fragColor; out vec4 fragColor;
#define TEX_MAT3x2(mat4In) mat3x2(mat4In[0].xy,mat4In[1].xy,mat4In[3].xy)
void main(){ void main(){
#ifdef CC_a_color #ifdef CC_a_color
vec4 color = colorUniform * v_color; vec4 color = colorUniform * v_color;
@ -108,9 +108,9 @@ void main(){
#ifdef CC_unit0 #ifdef CC_unit0
#ifdef CC_a_texture0 #ifdef CC_a_texture0
color *= texture(tex0, (matrix_t * vec4(v_texture0, 0.0, 1.0)).xy).rgba; color *= texture(tex0, (TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0)).xy).rgba;
#else #else
color *= texture(tex0, (matrix_t * vec4(texCoordV0, 0.0, 1.0)).xy).rgba; color *= texture(tex0, (TEX_MAT3x2(matrix_t) * vec3(texCoordV0, 1.0)).xy).rgba;
#endif #endif
#endif #endif
@ -133,7 +133,7 @@ void main(){
#ifdef CC_fog #ifdef CC_fog
float dist = sqrt(dot(v_position, v_position)); float dist = sqrt(dot(v_position, v_position));
float i = (fogMode == 1) ? clamp((dist - fogStart) / (fogEnd - fogStart), 0.0, 1.0) : clamp(1.0 - pow(2.718, -(fogDensity * dist)), 0.0, 1.0); float i = (fogMode == 1) ? clamp((dist - fogStart) / (fogEnd - fogStart), 0.0, 1.0) : clamp(1.0 - exp(-(fogDensity * dist)), 0.0, 1.0);
color.rgb = mix(color.rgb, fogColor.xyz, i * fogColor.a); color.rgb = mix(color.rgb, fogColor.xyz, i * fogColor.a);
#endif #endif
@ -141,4 +141,3 @@ void main(){
} }
#endif #endif

View File

@ -1,9 +1,7 @@
// eaglercraft opengl 1.3 emulation // copyright (c) 2020-2023 lax1dude
// copyright (c) 2020 calder young
// creative commons BY-NC 4.0
#line 7 #line 4
precision highp int; precision highp int;
precision highp sampler2D; precision highp sampler2D;
@ -99,6 +97,8 @@ in vec2 v_texture0;
out vec4 fragColor; out vec4 fragColor;
#define TEX_MAT3x2(mat4In) mat3x2(mat4In[0].xy,mat4In[1].xy,mat4In[3].xy)
void main(){ void main(){
#ifdef CC_a_color #ifdef CC_a_color
vec4 color = colorUniform * v_color; vec4 color = colorUniform * v_color;
@ -108,9 +108,9 @@ void main(){
#ifdef CC_unit0 #ifdef CC_unit0
#ifdef CC_a_texture0 #ifdef CC_a_texture0
color *= texture(tex0, (matrix_t * vec4(v_texture0, 0.0, 1.0)).xy).rgba; color *= texture(tex0, (TEX_MAT3x2(matrix_t) * vec3(v_texture0, 1.0)).xy).rgba;
#else #else
color *= texture(tex0, (matrix_t * vec4(texCoordV0, 0.0, 1.0)).xy).rgba; color *= texture(tex0, (TEX_MAT3x2(matrix_t) * vec3(texCoordV0, 1.0)).xy).rgba;
#endif #endif
#endif #endif
@ -133,7 +133,7 @@ void main(){
#ifdef CC_fog #ifdef CC_fog
float dist = sqrt(dot(v_position, v_position)); float dist = sqrt(dot(v_position, v_position));
float i = (fogMode == 1) ? clamp((dist - fogStart) / (fogEnd - fogStart), 0.0, 1.0) : clamp(1.0 - pow(2.718, -(fogDensity * dist)), 0.0, 1.0); float i = (fogMode == 1) ? clamp((dist - fogStart) / (fogEnd - fogStart), 0.0, 1.0) : clamp(1.0 - exp(-(fogDensity * dist)), 0.0, 1.0);
color.rgb = mix(color.rgb, fogColor.xyz, i * fogColor.a); color.rgb = mix(color.rgb, fogColor.xyz, i * fogColor.a);
#endif #endif
@ -141,4 +141,3 @@ void main(){
} }
#endif #endif

View File

@ -210,6 +210,7 @@ public class EaglerAdapterImpl2 {
public static final int _wGL_ELEMENT_ARRAY_BUFFER = GL15.GL_ELEMENT_ARRAY_BUFFER; public static final int _wGL_ELEMENT_ARRAY_BUFFER = GL15.GL_ELEMENT_ARRAY_BUFFER;
public static final int _wGL_STATIC_DRAW = GL15.GL_STATIC_DRAW; public static final int _wGL_STATIC_DRAW = GL15.GL_STATIC_DRAW;
public static final int _wGL_DYNAMIC_DRAW = GL15.GL_DYNAMIC_DRAW; public static final int _wGL_DYNAMIC_DRAW = GL15.GL_DYNAMIC_DRAW;
public static final int _wGL_STREAM_DRAW = GL15.GL_STREAM_DRAW;
public static final int _wGL_INVALID_ENUM = GL11.GL_INVALID_ENUM; public static final int _wGL_INVALID_ENUM = GL11.GL_INVALID_ENUM;
public static final int _wGL_INVALID_VALUE = GL11.GL_INVALID_VALUE; public static final int _wGL_INVALID_VALUE = GL11.GL_INVALID_VALUE;
public static final int _wGL_INVALID_OPERATION = GL11.GL_INVALID_OPERATION; public static final int _wGL_INVALID_OPERATION = GL11.GL_INVALID_OPERATION;
@ -530,6 +531,10 @@ public class EaglerAdapterImpl2 {
GL15.glBufferData(p1, p2, p3); GL15.glBufferData(p1, p2, p3);
} }
public static final void _wglBufferData00(int p1, long len, int p3) {
GL15.glBufferData(p1, len, p3);
}
public static final void _wglBufferSubData0(int p1, int p2, IntBuffer p3) { public static final void _wglBufferSubData0(int p1, int p2, IntBuffer p3) {
GL15.glBufferSubData(p1, p2, p3); GL15.glBufferSubData(p1, p2, p3);
} }
@ -674,6 +679,10 @@ public class EaglerAdapterImpl2 {
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, p1, GL11.GL_TEXTURE_2D, p2.obj, 0); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, p1, GL11.GL_TEXTURE_2D, p2.obj, 0);
} }
public static final void _wglFramebufferTexture2D(int p1, TextureGL p2, int lvl) {
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, p1, GL11.GL_TEXTURE_2D, p2.obj, lvl);
}
public static final RenderbufferGL _wglCreateRenderBuffer() { public static final RenderbufferGL _wglCreateRenderBuffer() {
return new RenderbufferGL(GL30.glGenRenderbuffers()); return new RenderbufferGL(GL30.glGenRenderbuffers());
} }
@ -746,7 +755,8 @@ public class EaglerAdapterImpl2 {
try { try {
BufferedImage img = ImageIO.read(new ByteArrayInputStream(data)); BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
int[] pxls = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth()); int[] pxls = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth());
return new EaglerImage(pxls, img.getWidth(), img.getHeight(), true); IntBuffer buffer = IntBuffer.wrap(pxls);
return new EaglerImage(buffer, img.getWidth(), img.getHeight(), true);
} catch (IOException e) { } catch (IOException e) {
System.err.println("Could not load PNG file:"); System.err.println("Could not load PNG file:");
e.printStackTrace(); e.printStackTrace();

View File

@ -2,11 +2,15 @@ package net.PeytonPlayz585.glemu;
import static net.PeytonPlayz585.opengl.GL11.*; import static net.PeytonPlayz585.opengl.GL11.*;
import java.util.ArrayList;
import java.util.List;
import net.PeytonPlayz585.glemu.vector.*; import net.PeytonPlayz585.glemu.vector.*;
public class FixedFunctionShader { public class FixedFunctionShader {
private static final FixedFunctionShader[] instances = new FixedFunctionShader[128]; private static final FixedFunctionShader[] instances = new FixedFunctionShader[128];
private static final List<FixedFunctionShader> instanceList = new ArrayList();
public static void refreshCoreGL() { public static void refreshCoreGL() {
for (int i = 0; i < instances.length; ++i) { for (int i = 0; i < instances.length; ++i) {
@ -15,6 +19,7 @@ public class FixedFunctionShader {
instances[i] = null; instances[i] = null;
} }
} }
instanceList.clear();
shaderSource = null; shaderSource = null;
} }
@ -59,6 +64,7 @@ public class FixedFunctionShader {
} }
s = new FixedFunctionShader(i, CC_a_color, CC_a_normal, CC_a_texture0, CC_lighting, CC_fog, CC_alphatest, CC_unit0); s = new FixedFunctionShader(i, CC_a_color, CC_a_normal, CC_a_texture0, CC_lighting, CC_fog, CC_alphatest, CC_unit0);
instances[i] = s; instances[i] = s;
instanceList.add(s);
} }
return s; return s;
} }
@ -102,8 +108,7 @@ public class FixedFunctionShader {
private final int attributeIndexesToEnable; private final int attributeIndexesToEnable;
public final BufferArrayGL genericArray; public final StreamBuffer streamBuffer;
public final BufferGL genericBuffer;
public boolean bufferIsInitialized = false; public boolean bufferIsInitialized = false;
private FixedFunctionShader(int j, boolean CC_a_color, boolean CC_a_normal, boolean CC_a_texture0, private FixedFunctionShader(int j, boolean CC_a_color, boolean CC_a_normal, boolean CC_a_texture0,
@ -226,11 +231,11 @@ public class FixedFunctionShader {
_wglUniform1i(_wglGetUniformLocation(globject, "tex0"), 0); _wglUniform1i(_wglGetUniformLocation(globject, "tex0"), 0);
u_texCoordV0 = _wglGetUniformLocation(globject, "texCoordV0"); u_texCoordV0 = _wglGetUniformLocation(globject, "texCoordV0");
genericArray = _wglCreateVertexArray(); streamBuffer = new StreamBuffer(0x8000, 3, 8, (vertexArray, vertexBuffer) -> {
genericBuffer = _wglCreateBuffer(); _wglBindVertexArray0(vertexArray);
_wglBindVertexArray(genericArray); _wglBindBuffer(_wGL_ARRAY_BUFFER, vertexBuffer);
_wglBindBuffer(_wGL_ARRAY_BUFFER, genericBuffer);
setupArrayForProgram(); setupArrayForProgram();
});
} }
@ -259,6 +264,13 @@ public class FixedFunctionShader {
} }
public static void optimize() {
FixedFunctionShader pp;
for(int i = 0, l = instanceList.size(); i < l; ++i) {
instanceList.get(i).streamBuffer.optimize();
}
}
private float[] modelBuffer = new float[16]; private float[] modelBuffer = new float[16];
private float[] projectionBuffer = new float[16]; private float[] projectionBuffer = new float[16];
private float[] textureBuffer = new float[16]; private float[] textureBuffer = new float[16];

View File

@ -0,0 +1,72 @@
package net.PeytonPlayz585.glemu;
import static net.PeytonPlayz585.opengl.GL11.*;
import java.nio.ByteBuffer;
public class GameOverlayFramebuffer {
private long age = -1l;
private int currentWidth = -1;
private int currentHeight = -1;
private FramebufferGL framebuffer = null;
private TextureGL framebufferColor = null;
private RenderbufferGL depthBuffer = null;
public void beginRender(int width, int height) {
if(framebuffer == null) {
framebuffer = _wglCreateFramebuffer();
depthBuffer = _wglCreateRenderBuffer();
framebufferColor = _wglGenTextures();
_wglBindFramebuffer(_wGL_FRAMEBUFFER, framebuffer);
glBindTexture(_wGL_TEXTURE_2D, framebufferColor);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
_wglFramebufferTexture2D(_wGL_COLOR_ATTACHMENT0, framebufferColor, 0);
_wglBindRenderbuffer(depthBuffer);
_wglFramebufferRenderbuffer(_wGL_DEPTH_ATTACHMENT, depthBuffer);
}
if(currentWidth != width || currentHeight != height) {
currentWidth = width;
currentHeight = height;
glBindTexture(_wGL_TEXTURE_2D, framebufferColor);
_wglTexImage2D(_wGL_TEXTURE_2D, 0, _wGL_RGBA8, width, height, 0, _wGL_RGBA, _wGL_UNSIGNED_BYTE, (ByteBuffer)null);
_wglBindRenderbuffer(depthBuffer);
_wglRenderbufferStorage(0x81A5, width, height);
}
_wglBindFramebuffer(_wGL_FRAMEBUFFER, framebuffer);
}
public void endRender() {
_wglBindFramebuffer(_wGL_FRAMEBUFFER, null);
age = System.currentTimeMillis();
}
public long getAge() {
return age == -1l ? -1l : (System.currentTimeMillis() - age);
}
public void bindTexture() {
glBindTexture(_wGL_TEXTURE_2D, framebufferColor);
}
public void destroy() {
if(framebuffer != null) {
_wglDeleteFramebuffer(framebuffer);
_wglDeleteRenderbuffer(depthBuffer);
_wglDeleteTextures(framebufferColor);
framebuffer = null;
depthBuffer = null;
framebufferColor = null;
age = -1l;
_wglBindFramebuffer(_wGL_FRAMEBUFFER, null);
}
}
}

View File

@ -0,0 +1,130 @@
package net.PeytonPlayz585.glemu;
import static net.PeytonPlayz585.opengl.GL11.*;
public class StreamBuffer {
public final int initialSize;
public final int initialCount;
public final int maxCount;
protected StreamBufferInstance[] buffers;
protected int currentBufferId = 0;
protected int overflowCounter = 0;
protected final IStreamBufferInitializer initializer;
public static class StreamBufferInstance {
public BufferArrayGL vertexArray = null;
public BufferGL vertexBuffer = null;
protected int vertexBufferSize = 0;
public boolean bindQuad16 = false;
public boolean bindQuad32 = false;
public BufferArrayGL getVertexArray() {
return vertexArray;
}
public BufferGL getVertexBuffer() {
return vertexBuffer;
}
}
public static interface IStreamBufferInitializer {
void initialize(BufferArrayGL vertexArray, BufferGL vertexBuffer);
}
public StreamBuffer(int initialSize, int initialCount, int maxCount, IStreamBufferInitializer initializer) {
this.buffers = new StreamBufferInstance[initialCount];
for(int i = 0; i < this.buffers.length; ++i) {
this.buffers[i] = new StreamBufferInstance();
}
this.initialSize = initialSize;
this.initialCount = initialCount;
this.maxCount = maxCount;
this.initializer = initializer;
}
public StreamBufferInstance getBuffer(int requiredMemory) {
StreamBufferInstance next = buffers[(currentBufferId++) % buffers.length];
if(next.vertexBuffer == null) {
next.vertexBuffer = _wglCreateBuffer();
}
if(next.vertexArray == null) {
next.vertexArray = _wglCreateVertexArray();
initializer.initialize(next.vertexArray, next.vertexBuffer);
}
if(next.vertexBufferSize < requiredMemory) {
int newSize = (requiredMemory & 0xFFFFF000) + 0x2000;
_wglBindBuffer(_wGL_ARRAY_BUFFER, next.vertexBuffer);
_wglBufferData00(_wGL_ARRAY_BUFFER, newSize, _wGL_STREAM_DRAW);
next.vertexBufferSize = newSize;
}
return next;
}
public void optimize() {
overflowCounter += currentBufferId - buffers.length;
if(overflowCounter < -25) {
int newCount = buffers.length - 1 + ((overflowCounter + 25) / 5);
if(newCount < initialCount) {
newCount = initialCount;
}
if(newCount < buffers.length) {
StreamBufferInstance[] newArray = new StreamBufferInstance[newCount];
for(int i = 0; i < buffers.length; ++i) {
if(i < newArray.length) {
newArray[i] = buffers[i];
}else {
if(buffers[i].vertexArray != null) {
_wglDeleteVertexArray(buffers[i].vertexArray);
}
if(buffers[i].vertexBuffer != null) {
_wglDeleteBuffer(buffers[i].vertexBuffer);
}
}
}
buffers = newArray;
}
overflowCounter = 0;
}else if(overflowCounter > 15) {
int newCount = buffers.length + 1 + ((overflowCounter - 15) / 5);
if(newCount > maxCount) {
newCount = maxCount;
}
if(newCount > buffers.length) {
StreamBufferInstance[] newArray = new StreamBufferInstance[newCount];
for(int i = 0; i < newArray.length; ++i) {
if(i < buffers.length) {
newArray[i] = buffers[i];
}else {
newArray[i] = new StreamBufferInstance();
}
}
buffers = newArray;
}
overflowCounter = 0;
}
currentBufferId = 0;
}
public void destroy() {
for(int i = 0; i < buffers.length; ++i) {
StreamBufferInstance next = buffers[i];
if(next.vertexArray != null) {
_wglDeleteVertexArray(next.vertexArray);
}
if(next.vertexBuffer != null) {
_wglDeleteBuffer(next.vertexBuffer);
}
}
buffers = new StreamBufferInstance[initialCount];
for(int i = 0; i < buffers.length; ++i) {
buffers[i] = new StreamBufferInstance();
}
}
}

View File

@ -15,6 +15,8 @@ import net.minecraft.src.GLAllocation;
import net.minecraft.src.Vec3D; import net.minecraft.src.Vec3D;
import net.PeytonPlayz585.glemu.vector.*; import net.PeytonPlayz585.glemu.vector.*;
import static net.PeytonPlayz585.glemu.StreamBuffer.StreamBufferInstance;
public class EaglerAdapterGL30 extends EaglerAdapterImpl2 { public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final int GL_ZERO = RealOpenGLEnums.GL_ZERO; public static final int GL_ZERO = RealOpenGLEnums.GL_ZERO;
@ -547,8 +549,18 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glBlendFunc(int p1, int p2) { public static final void glBlendFunc(int p1, int p2) {
fogPremultiply = (p1 == GL_ONE && p2 == GL_ONE_MINUS_SRC_ALPHA); fogPremultiply = (p1 == GL_ONE && p2 == GL_ONE_MINUS_SRC_ALPHA);
if(overlayFBOBlending) {
_wglBlendFuncSeparate(p1, p2, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}else {
_wglBlendFunc(p1, p2); _wglBlendFunc(p1, p2);
} }
}
private static boolean overlayFBOBlending = false;
public static final void enableOverlayFramebufferBlending(boolean en) {
overlayFBOBlending = en;
}
public static final void glBlendFuncSeparate(int p1, int p2, int p3, int p4) { public static final void glBlendFuncSeparate(int p1, int p2, int p3, int p4) {
fogPremultiply = (p3 == GL_ONE && p4 == GL_ONE_MINUS_SRC_ALPHA); fogPremultiply = (p3 == GL_ONE && p4 == GL_ONE_MINUS_SRC_ALPHA);
@ -568,6 +580,10 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
_wglBindTexture(_wGL_TEXTURE_2D, t); _wglBindTexture(_wGL_TEXTURE_2D, t);
} }
public static final void glBindTexture(int p1, TextureGL p2) {
_wglBindTexture(_wGL_TEXTURE_2D, p2);
}
public static final void glCopyTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { public static final void glCopyTexSubImage2D(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) {
_wglCopyTexSubImage2D(_wGL_TEXTURE_2D, p2, p3, p4, p5, p6, p7, p8); _wglCopyTexSubImage2D(_wGL_TEXTURE_2D, p2, p3, p4, p5, p6, p7, p8);
} }
@ -672,6 +688,18 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
} }
} }
public static final void flushDisplayList(int p1) {
DisplayList d = displayListsInitialized.get(p1);
if (d != null) {
if (d.glbuffer != null) {
_wglDeleteBuffer(d.glbuffer);
_wglDeleteVertexArray(d.glarray);
d.glbuffer = null;
d.glarray = null;
}
}
}
public static final void glColor3f(float p1, float p2, float p3) { public static final void glColor3f(float p1, float p2, float p3) {
colorR = p1; colorR = p1;
colorG = p2; colorG = p2;
@ -836,13 +864,15 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
System.err.println("only GL_QUADS supported in a display list"); System.err.println("only GL_QUADS supported in a display list");
} }
} else { } else {
bytesUploaded += _wArrayByteLength(buffer); int bl = _wArrayByteLength(buffer);
bytesUploaded += bl;
vertexDrawn += p3; vertexDrawn += p3;
bindTheShader(); bindTheShader();
_wglBindVertexArray0(shader.genericArray); StreamBufferInstance sb = shader.streamBuffer.getBuffer(bl);
_wglBindBuffer(_wGL_ARRAY_BUFFER, shader.genericBuffer); _wglBindVertexArray0(sb.vertexArray);
_wglBindBuffer(_wGL_ARRAY_BUFFER, sb.vertexBuffer);
if (!shader.bufferIsInitialized) { if (!shader.bufferIsInitialized) {
shader.bufferIsInitialized = true; shader.bufferIsInitialized = true;
_wglBufferData(_wGL_ARRAY_BUFFER, blankUploadArray, _wGL_DYNAMIC_DRAW); _wglBufferData(_wGL_ARRAY_BUFFER, blankUploadArray, _wGL_DYNAMIC_DRAW);
@ -1179,6 +1209,10 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
} }
} }
public static final void optimize() {
FixedFunctionShader.optimize();
}
private static long lastBandwidthReset = 0l; private static long lastBandwidthReset = 0l;
private static int lastBandwidth = 0; private static int lastBandwidth = 0;

View File

@ -1,43 +1,55 @@
package net.lax1dude.eaglercraft; package net.lax1dude.eaglercraft;
import java.io.ByteArrayInputStream; import java.nio.IntBuffer;
import java.io.IOException;
public class EaglerImage { public class EaglerImage {
public final int[] data; public final IntBuffer data;
public final int w; public final int w;
public final int h; public final int h;
public final boolean alpha; public final boolean alpha;
private final int wh;
public EaglerImage(int pw, int ph, boolean palpha) { public EaglerImage(int pw, int ph, boolean palpha) {
this.w = pw; this.w = pw;
this.h = ph; this.h = ph;
this.alpha = palpha; this.alpha = palpha;
this.data = new int[pw * ph]; this.data = IntBuffer.allocate(pw * ph);
this.wh = pw * ph;
} }
public EaglerImage(int[] pdata, int pw, int ph, boolean palpha) { public EaglerImage(IntBuffer pdata, int pw, int ph, boolean palpha) {
if (pdata.length != pw * ph) { if (pdata.capacity() != pw * ph) {
throw new IllegalArgumentException("array size does not equal image size"); throw new IllegalArgumentException("buffer capacity does not equal image size");
} }
this.w = pw; w = pw;
this.h = ph; h = ph;
this.alpha = palpha; alpha = palpha;
if (!palpha) { wh = pw * ph;
for (int i = 0; i < pdata.length; ++i) { if (!alpha) {
pdata[i] = pdata[i] | 0xFF000000; for (int i = 0; i < wh; ++i) {
pdata.put(i, pdata.get(i) | 0xFF000000);
} }
pdata.rewind();
} }
this.data = pdata; data = pdata;
} }
public EaglerImage getSubImage(int x, int y, int pw, int ph) { public EaglerImage getSubImage(int x, int y, int pw, int ph) {
int[] img = new int[pw * ph]; int start = y * w + x;
for (int i = 0; i < ph; ++i) { IntBuffer subBuffer = data.slice();
System.arraycopy(data, (i + y) * this.w + x, img, i * pw, pw); subBuffer.position(start);
} subBuffer.limit(start + pw * ph);
return new EaglerImage(img, pw, ph, alpha); int[] temp = new int[pw * ph];
subBuffer.get(temp);
IntBuffer newBuffer = IntBuffer.wrap(temp);
return new EaglerImage(newBuffer, pw, ph, alpha);
} }
public int[] data() {
int[] array = new int[wh];
data.rewind();
data.get(array);
return array;
}
} }

View File

@ -107,6 +107,8 @@ public class Minecraft implements Runnable {
private int field_6300_ab = 0; private int field_6300_ab = 0;
private static Minecraft mc; private static Minecraft mc;
public static int debugFPS;
public Minecraft() { public Minecraft() {
new ThreadSleepForever(this, "Timer hack thread"); new ThreadSleepForever(this, "Timer hack thread");
this.displayWidth = GL11.getCanvasWidth(); this.displayWidth = GL11.getCanvasWidth();
@ -190,6 +192,7 @@ public class Minecraft implements Runnable {
GL11.glAlphaFunc(516, 0.1F); GL11.glAlphaFunc(516, 0.1F);
GL11.glFlush(); GL11.glFlush();
GL11.updateDisplay(); GL11.updateDisplay();
GL11.optimize();
} }
public void func_6274_a(int var1, int var2, int var3, int var4, int var5, int var6) { public void func_6274_a(int var1, int var2, int var3, int var4, int var5, int var6) {
@ -345,11 +348,14 @@ public class Minecraft implements Runnable {
} }
this.checkGLError("Post render"); this.checkGLError("Post render");
GL11.optimize();
++var3; ++var3;
for(this.field_6316_m = true && this.currentScreen != null && this.currentScreen.doesGuiPauseGame(); System.currentTimeMillis() >= var1 + 1000L; var3 = 0) { for(this.field_6316_m = true && this.currentScreen != null && this.currentScreen.doesGuiPauseGame(); System.currentTimeMillis() >= var1 + 1000L;) {
this.field_6292_I = var3 + " fps, " + WorldRenderer.field_1762_b + " chunk updates"; this.field_6292_I = var3 + " fps, " + WorldRenderer.field_1762_b + " chunk updates";
WorldRenderer.field_1762_b = 0; WorldRenderer.field_1762_b = 0;
debugFPS = var3;
var3 = 0;
var1 += 1000L; var1 += 1000L;
} }
} }

View File

@ -7,7 +7,7 @@ public class ColorizerFoliage {
public static int func_4146_a(double var0, double var2) { public static int func_4146_a(double var0, double var2) {
if(field_6529_a == null) { if(field_6529_a == null) {
field_6529_a = GL11.loadPNG(GL11.loadResourceBytes("/misc/foliagecolor.png")).data; field_6529_a = GL11.loadPNG(GL11.loadResourceBytes("/misc/foliagecolor.png")).data();
} }
var2 *= var0; var2 *= var0;
int var4 = (int)((1.0D - var0) * 255.0D); int var4 = (int)((1.0D - var0) * 255.0D);

View File

@ -7,7 +7,7 @@ public class ColorizerGrass {
public static int func_4147_a(double var0, double var2) { public static int func_4147_a(double var0, double var2) {
if(field_6540_a == null) { if(field_6540_a == null) {
field_6540_a = GL11.loadPNG(GL11.loadResourceBytes("/misc/grasscolor.png")).data; field_6540_a = GL11.loadPNG(GL11.loadResourceBytes("/misc/grasscolor.png")).data();
} }
var2 *= var0; var2 *= var0;
int var4 = (int)((1.0D - var0) * 255.0D); int var4 = (int)((1.0D - var0) * 255.0D);

View File

@ -4,6 +4,7 @@ import java.nio.FloatBuffer;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import net.PeytonPlayz585.glemu.GameOverlayFramebuffer;
import net.PeytonPlayz585.input.Keyboard; import net.PeytonPlayz585.input.Keyboard;
import net.PeytonPlayz585.input.Mouse; import net.PeytonPlayz585.input.Mouse;
import net.PeytonPlayz585.opengl.GL11; import net.PeytonPlayz585.opengl.GL11;
@ -27,8 +28,11 @@ public class EntityRenderer {
private float field_1382_n; private float field_1382_n;
private float field_1381_o; private float field_1381_o;
private GameOverlayFramebuffer overlayFramebuffer;
public EntityRenderer(Minecraft var1) { public EntityRenderer(Minecraft var1) {
this.mc = var1; this.mc = var1;
this.overlayFramebuffer = new GameOverlayFramebuffer();
this.field_1395_a = new ItemRenderer(var1); this.field_1395_a = new ItemRenderer(var1);
} }
@ -293,7 +297,43 @@ public class EntityRenderer {
if(this.mc.theWorld != null) { if(this.mc.theWorld != null) {
this.func_4134_c(var1); this.func_4134_c(var1);
if(!(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(2))) { if(!(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(2))) {
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
long framebufferAge = this.overlayFramebuffer.getAge();
if(framebufferAge == -1l || framebufferAge > (Minecraft.debugFPS < 25 ? 125l : 75l)) {
this.overlayFramebuffer.beginRender(mc.displayWidth, mc.displayHeight);
GL11.glColorMask(true, true, true, true);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.enableOverlayFramebufferBlending(true);
this.mc.ingameGUI.renderGameOverlay(var1, this.mc.currentScreen != null, var10, var11); this.mc.ingameGUI.renderGameOverlay(var1, this.mc.currentScreen != null, var10, var11);
GL11.enableOverlayFramebufferBlending(false);
this.overlayFramebuffer.endRender();
GL11.glClearColor(this.field_4270_e, this.field_4269_f, this.field_4268_g, 0.0F);
}
this.func_905_b();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
if (Minecraft.getMinecraft().gameSettings.fancyGraphics) {
this.mc.ingameGUI.func_4064_a(this.mc.thePlayer.getEntityBrightness(var1), var8, var9);
}
this.mc.ingameGUI.renderCrossHairs(var8, var9);
this.overlayFramebuffer.bindTexture();
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(false);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(0.0D, (double) var9, -90.0D, 0.0D, 0.0D);
tessellator.addVertexWithUV((double) var8, (double) var9, -90.0D, 1.0D, 0.0D);
tessellator.addVertexWithUV((double) var8, 0.0D, -90.0D, 1.0D, 1.0D);
tessellator.addVertexWithUV(0.0D, 0.0D, -90.0D, 0.0D, 1.0D);
tessellator.draw();
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_BLEND);
} }
} else { } else {
GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight); GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);

View File

@ -16,7 +16,7 @@ public class FontRenderer {
EaglerImage bufferedimage = GL11.loadPNG(GL11.loadResourceBytes(s)); EaglerImage bufferedimage = GL11.loadPNG(GL11.loadResourceBytes(s));
int i = bufferedimage.w; int i = bufferedimage.w;
int j = bufferedimage.h; int j = bufferedimage.h;
int ai[] = bufferedimage.data; int ai[] = bufferedimage.data();
for (int k = 0; k < 256; k++) { for (int k = 0; k < 256; k++) {
int l = k % 16; int l = k % 16;
int k1 = k / 16; int k1 = k / 16;

View File

@ -32,9 +32,6 @@ public class GuiIngame extends Gui {
FontRenderer var8 = this.mc.fontRenderer; FontRenderer var8 = this.mc.fontRenderer;
this.mc.field_9243_r.func_905_b(); this.mc.field_9243_r.func_905_b();
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
if(this.mc.gameSettings.fancyGraphics) {
this.func_4064_a(this.mc.thePlayer.getEntityBrightness(var1), var6, var7);
}
ItemStack var9 = this.mc.thePlayer.inventory.armorItemInSlot(3); ItemStack var9 = this.mc.thePlayer.inventory.armorItemInSlot(3);
if(!this.mc.gameSettings.thirdPersonView && var9 != null && var9.itemID == Block.pumpkin.blockID) { if(!this.mc.gameSettings.thirdPersonView && var9 != null && var9.itemID == Block.pumpkin.blockID) {
@ -54,9 +51,6 @@ public class GuiIngame extends Gui {
this.drawTexturedModalRect(var6 / 2 - 91 - 1 + var11.currentItem * 20, var7 - 22 - 1, 0, 22, 24, 22); this.drawTexturedModalRect(var6 / 2 - 91 - 1 + var11.currentItem * 20, var7 - 22 - 1, 0, 22, 24, 22);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/gui/icons.png")); GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/gui/icons.png"));
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR);
this.drawTexturedModalRect(var6 / 2 - 7, var7 / 2 - 7, 0, 0, 16, 16);
GL11.glDisable(GL11.GL_BLEND);
boolean var12 = this.mc.thePlayer.field_9306_bj / 3 % 2 == 1; boolean var12 = this.mc.thePlayer.field_9306_bj / 3 % 2 == 1;
if(this.mc.thePlayer.field_9306_bj < 10) { if(this.mc.thePlayer.field_9306_bj < 10) {
var12 = false; var12 = false;
@ -236,7 +230,7 @@ public class GuiIngame extends Gui {
GL11.glDisable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_BLEND);
} }
private void func_4063_a(int var1, int var2) { public void func_4063_a(int var1, int var2) {
GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(false); GL11.glDepthMask(false);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
@ -256,8 +250,9 @@ public class GuiIngame extends Gui {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
} }
private void func_4064_a(float var1, int var2, int var3) { public void func_4064_a(float var1, int var2, int var3) {
var1 = 1.0F - var1; var1 = 1.0F - var1 * 0.5f;
if (var1 < 0.0F) { if (var1 < 0.0F) {
var1 = 0.0F; var1 = 0.0F;
} }
@ -410,4 +405,13 @@ public class GuiIngame extends Gui {
return (red << 16) | (green << 8) | blue; return (red << 16) | (green << 8) | blue;
} }
public void renderCrossHairs(int w, int h) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/gui/icons.png"));
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR);
this.drawTexturedModalRect(w / 2 - 7, h / 2 - 7, 0, 0, 16, 16);
}
} }

View File

@ -18,6 +18,7 @@ public class RenderEngine {
textureNameToImageMap = new HashMap<Integer, EaglerImage>(); textureNameToImageMap = new HashMap<Integer, EaglerImage>();
singleIntBuffer = GLAllocation.createDirectIntBuffer(1); singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
imageDataB1 = GLAllocation.createDirectByteBuffer(0x100000); imageDataB1 = GLAllocation.createDirectByteBuffer(0x100000);
imageDataB2 = GLAllocation.createDirectByteBuffer(0x100000);
textureList = new ArrayList<TextureFX>(); textureList = new ArrayList<TextureFX>();
clampTexture = false; clampTexture = false;
blurTexture = false; blurTexture = false;
@ -80,8 +81,9 @@ public class RenderEngine {
public void setupTexture(EaglerImage bufferedimage, int i) { public void setupTexture(EaglerImage bufferedimage, int i) {
bindTexture(i); bindTexture(i);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, GL11.GL_NEAREST_MIPMAP_LINEAR);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9728 /* GL_NEAREST */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, GL11.GL_NEAREST /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, GL11.GL_TEXTURE_MAX_LEVEL, 4);
if (blurTexture) { if (blurTexture) {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9729 /* GL_LINEAR */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9729 /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9729 /* GL_LINEAR */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9729 /* GL_LINEAR */);
@ -95,7 +97,7 @@ public class RenderEngine {
} }
int j = bufferedimage.w; int j = bufferedimage.w;
int k = bufferedimage.h; int k = bufferedimage.h;
int ai[] = bufferedimage.data; int ai[] = bufferedimage.data();
byte abyte0[] = new byte[j * k * 4]; byte abyte0[] = new byte[j * k * 4];
for (int l = 0; l < ai.length; l++) { for (int l = 0; l < ai.length; l++) {
int j1 = ai[l] >> 24 & 0xff; int j1 = ai[l] >> 24 & 0xff;
@ -120,12 +122,40 @@ public class RenderEngine {
imageDataB1.position(0).limit(abyte0.length); imageDataB1.position(0).limit(abyte0.length);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, 6408 /* GL_RGBA */, j, k, 0, 6408 /* GL_RGBA */, GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, 6408 /* GL_RGBA */, j, k, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB1); 5121 /* GL_UNSIGNED_BYTE */, imageDataB1);
for (int i1 = 1; i1 <= 4; i1++) {
int k1 = j >> i1 - 1;
int i2 = j >> i1;
int k2 = k >> i1;
imageDataB2.clear();
for (int i3 = 0; i3 < i2; i3++) {
for (int k3 = 0; k3 < k2; k3++) {
int i4 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 0) * k1) * 4);
int k4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 0) * k1) * 4);
int l4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 1) * k1) * 4);
int i5 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 1) * k1) * 4);
int j5 = averageColor(averageColor(i4, k4), averageColor(l4, i5));
imageDataB2.putInt((i3 + k3 * i2) * 4, j5);
}
}
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, i1, 6408 /* GL_RGBA */, i2, k2, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB2);
ByteBuffer tmp = imageDataB1;
imageDataB1 = imageDataB2;
imageDataB2 = tmp;
}
} }
public void deleteTexture(int i) { public void deleteTexture(int i) {
GL11.glDeleteTextures(i); GL11.glDeleteTextures(i);
} }
private int averageColor(int i, int j) {
int k = (i & 0xff000000) >> 24 & 0xff;
int l = (j & 0xff000000) >> 24 & 0xff;
return ((k + l >> 1) << 24) + ((i & 0xfefefe) + (j & 0xfefefe) >> 1);
}
public void registerTextureFX(TextureFX texturefx) { public void registerTextureFX(TextureFX texturefx) {
textureList.add(texturefx); textureList.add(texturefx);
texturefx.func_783_a(); texturefx.func_783_a();
@ -209,6 +239,7 @@ public class RenderEngine {
private HashMap<Integer, EaglerImage> textureNameToImageMap; private HashMap<Integer, EaglerImage> textureNameToImageMap;
public IntBuffer singleIntBuffer; public IntBuffer singleIntBuffer;
private ByteBuffer imageDataB1; private ByteBuffer imageDataB1;
private ByteBuffer imageDataB2;
private java.util.List<TextureFX> textureList; private java.util.List<TextureFX> textureList;
private GameSettings options; private GameSettings options;
private boolean clampTexture; private boolean clampTexture;

View File

@ -492,7 +492,7 @@ public class RenderGlobal implements IWorldAccess {
var11 = (float)var10 * (float)Math.PI * 2.0F / (float)var9; var11 = (float)var10 * (float)Math.PI * 2.0F / (float)var9;
float var12 = MathHelper.sin(var11); float var12 = MathHelper.sin(var11);
float var13 = MathHelper.cos(var11); float var13 = MathHelper.cos(var11);
var14.addVertex((double)(var12 * 120.0F), (double)(var13 * 120.0F), (double)(-var13 * 40.0F * var15[3])); var14.addVertex((double)(var12 * 120.0F), (double)(var13 * 120.0F), (double)(var13 * 40.0F * var15[3]));
} }
var14.draw(); var14.draw();
@ -781,7 +781,7 @@ public class RenderGlobal implements IWorldAccess {
var8 = this.worldObj.getBlockId(var2.blockX, var2.blockY, var2.blockZ); var8 = this.worldObj.getBlockId(var2.blockX, var2.blockY, var2.blockZ);
Block var9 = var8 > 0 ? Block.blocksList[var8] : null; Block var9 = var8 > 0 ? Block.blocksList[var8] : null;
GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glPolygonOffset(-3.0F, -3.0F); GL11.glPolygonOffset(3.0F, 3.0F);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL); GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
var6.startDrawingQuads(); var6.startDrawingQuads();
double var10 = var1.lastTickPosX + (var1.posX - var1.lastTickPosX) * (double)var5; double var10 = var1.lastTickPosX + (var1.posX - var1.lastTickPosX) * (double)var5;

View File

@ -157,7 +157,7 @@ public class TextureCompassFX extends TextureFX {
public TextureCompassFX(Minecraft var1) { public TextureCompassFX(Minecraft var1) {
super(Item.compass.getIconIndex(null)); super(Item.compass.getIconIndex(null));
field_1128_f = 1; field_1128_f = 1;
this.compassSpriteSheet = GL11.loadPNG(GL11.loadResourceBytes("/gui/items.png")).data; this.compassSpriteSheet = GL11.loadPNG(GL11.loadResourceBytes("/gui/items.png")).data();
this.compassSpriteSheetLength = compassSpriteSheet.length / 256; this.compassSpriteSheetLength = compassSpriteSheet.length / 256;
} }

View File

@ -15,8 +15,8 @@ public class TextureWatchFX extends TextureFX {
EaglerImage bufferedimage = GL11.loadPNG(GL11.loadResourceBytes("/gui/items.png")); EaglerImage bufferedimage = GL11.loadPNG(GL11.loadResourceBytes("/gui/items.png"));
int i = (field_1126_b % 16) * 16; int i = (field_1126_b % 16) * 16;
int j = (field_1126_b / 16) * 16; int j = (field_1126_b / 16) * 16;
field_4224_h = bufferedimage.getSubImage(i, j, 16, 16).data; field_4224_h = bufferedimage.getSubImage(i, j, 16, 16).data();
field_4223_i = GL11.loadPNG(GL11.loadResourceBytes("/misc/dial.png")).data; field_4223_i = GL11.loadPNG(GL11.loadResourceBytes("/misc/dial.png")).data();
} }
public void func_783_a() { public void func_783_a() {

View File

@ -158,6 +158,13 @@ public class WorldRenderer {
this.field_1737_F.removeAll(var21); this.field_1737_F.removeAll(var21);
this.field_1747_A = Chunk.field_1540_a; this.field_1747_A = Chunk.field_1540_a;
this.field_1739_E = true; this.field_1739_E = true;
if(field_1748_p[0]) {
GL11.flushDisplayList(field_1744_C);
}
if(field_1748_p[1]) {
GL11.flushDisplayList(field_1744_C + 1);
}
} }
} }
@ -171,6 +178,8 @@ public class WorldRenderer {
public void func_1195_b() { public void func_1195_b() {
for(int var1 = 0; var1 < 2; ++var1) { for(int var1 = 0; var1 < 2; ++var1) {
this.field_1748_p[var1] = true; this.field_1748_p[var1] = true;
GL11.flushDisplayList(field_1744_C);
GL11.flushDisplayList(field_1744_C + 1);
} }
this.field_1749_o = false; this.field_1749_o = false;

View File

@ -52,7 +52,6 @@ public class Client {
private static void run1() { private static void run1() {
GL11.canvas.focus(); GL11.canvas.focus();
GL11.canvasBack.focus();
instance.run(); instance.run();
} }

View File

@ -26,6 +26,7 @@ import org.teavm.jso.browser.TimerHandler;
import org.teavm.jso.browser.Window; import org.teavm.jso.browser.Window;
import org.teavm.jso.canvas.CanvasRenderingContext2D; import org.teavm.jso.canvas.CanvasRenderingContext2D;
import org.teavm.jso.canvas.ImageData; import org.teavm.jso.canvas.ImageData;
import org.teavm.jso.dom.css.CSSStyleDeclaration;
import org.teavm.jso.dom.events.Event; import org.teavm.jso.dom.events.Event;
import org.teavm.jso.dom.events.EventListener; import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.events.KeyboardEvent; import org.teavm.jso.dom.events.KeyboardEvent;
@ -38,6 +39,7 @@ import org.teavm.jso.dom.html.HTMLElement;
import org.teavm.jso.dom.html.HTMLImageElement; import org.teavm.jso.dom.html.HTMLImageElement;
import org.teavm.jso.dom.html.HTMLInputElement; import org.teavm.jso.dom.html.HTMLInputElement;
import org.teavm.jso.typedarrays.ArrayBuffer; import org.teavm.jso.typedarrays.ArrayBuffer;
import org.teavm.jso.typedarrays.DataView;
import org.teavm.jso.typedarrays.Float32Array; import org.teavm.jso.typedarrays.Float32Array;
import org.teavm.jso.typedarrays.Int32Array; import org.teavm.jso.typedarrays.Int32Array;
import org.teavm.jso.typedarrays.Int8Array; import org.teavm.jso.typedarrays.Int8Array;
@ -165,9 +167,10 @@ public class EaglerAdapterImpl2 {
public static HTMLDocument doc = null; public static HTMLDocument doc = null;
public static HTMLElement parent = null; public static HTMLElement parent = null;
public static HTMLCanvasElement canvas = null; public static HTMLCanvasElement canvas = null;
public static CanvasRenderingContext2D canvasContext = null;
public static HTMLCanvasElement canvasBack = null;
public static WebGL2RenderingContext webgl = null; public static WebGL2RenderingContext webgl = null;
public static FramebufferGL backBuffer = null;
public static RenderbufferGL backBufferColor = null;
public static RenderbufferGL backBufferDepth = null;
public static Window win = null; public static Window win = null;
private static byte[] loadedPackage = null; private static byte[] loadedPackage = null;
private static EventListener contextmenu = null; private static EventListener contextmenu = null;
@ -206,21 +209,24 @@ public class EaglerAdapterImpl2 {
win = Window.current(); win = Window.current();
doc = win.getDocument(); doc = win.getDocument();
canvas = (HTMLCanvasElement)doc.createElement("canvas"); canvas = (HTMLCanvasElement)doc.createElement("canvas");
width = rootElement.getClientWidth(); double r = win.getDevicePixelRatio();
height = rootElement.getClientHeight(); width = (int)(rootElement.getClientWidth() * r);
height = (int)(rootElement.getClientHeight() * r);
canvas.setWidth(width); canvas.setWidth(width);
canvas.setHeight(height); canvas.setHeight(height);
canvasContext = (CanvasRenderingContext2D) canvas.getContext("2d");
canvas.setAttribute("id", "deevis589723589"); canvas.setAttribute("id", "deevis589723589");
rootElement.appendChild(canvas); rootElement.appendChild(canvas);
canvasBack = (HTMLCanvasElement)doc.createElement("canvas"); CSSStyleDeclaration canvasStyle = canvas.getStyle();
canvasBack.setWidth(width); canvasStyle.setProperty("width", "100%");
canvasBack.setHeight(height); canvasStyle.setProperty("height", "100%");
webgl = (WebGL2RenderingContext) canvasBack.getContext("webgl2", youEagler()); canvasStyle.setProperty("image-rendering", "pixelated");
webgl = (WebGL2RenderingContext) canvas.getContext("webgl2", youEagler());
if(webgl == null) { if(webgl == null) {
throw new RuntimeException("WebGL 2.0 is not supported in your browser ("+getUA()+")"); throw new RuntimeException("WebGL 2.0 is not supported in your browser ("+getUA()+")");
} }
setContextVar(webgl); setContextVar(webgl);
setupBackBuffer();
resizeBackBuffer(width, height);
webgl.getExtension("EXT_texture_filter_anisotropic"); webgl.getExtension("EXT_texture_filter_anisotropic");
@ -251,8 +257,9 @@ public class EaglerAdapterImpl2 {
}); });
canvas.addEventListener("mousemove", mousemove = new EventListener<MouseEvent>() { canvas.addEventListener("mousemove", mousemove = new EventListener<MouseEvent>() {
public void handleEvent(MouseEvent evt) { public void handleEvent(MouseEvent evt) {
mouseX = getOffsetX(evt); double r = win.getDevicePixelRatio();
mouseY = canvas.getClientHeight() - getOffsetY(evt); mouseX = (int)(getOffsetX(evt) * r);
mouseY = (int)((canvas.getClientHeight() - getOffsetY(evt)) * r);
mouseDX += evt.getMovementX(); mouseDX += evt.getMovementX();
mouseDY += -evt.getMovementY(); mouseDY += -evt.getMovementY();
evt.preventDefault(); evt.preventDefault();
@ -356,7 +363,7 @@ public class EaglerAdapterImpl2 {
private static boolean enableRepeatEvents = false; private static boolean enableRepeatEvents = false;
private static boolean isWindowFocused = true; private static boolean isWindowFocused = true;
@JSBody(params = { }, script = "return {antialias: false, depth: true, powerPreference: \"high-performance\", desynchronized: false, preserveDrawingBuffer: false, premultipliedAlpha: false, alpha: false};") @JSBody(params = { }, script = "return {antialias: false, depth: true, powerPreference: \"high-performance\", desynchronized: true, preserveDrawingBuffer: false, premultipliedAlpha: false, alpha: false};")
public static native JSObject youEagler(); public static native JSObject youEagler();
public static final int _wGL_TEXTURE_2D = TEXTURE_2D; public static final int _wGL_TEXTURE_2D = TEXTURE_2D;
@ -416,6 +423,7 @@ public class EaglerAdapterImpl2 {
public static final int _wGL_ELEMENT_ARRAY_BUFFER = ELEMENT_ARRAY_BUFFER; public static final int _wGL_ELEMENT_ARRAY_BUFFER = ELEMENT_ARRAY_BUFFER;
public static final int _wGL_STATIC_DRAW = STATIC_DRAW; public static final int _wGL_STATIC_DRAW = STATIC_DRAW;
public static final int _wGL_DYNAMIC_DRAW = DYNAMIC_DRAW; public static final int _wGL_DYNAMIC_DRAW = DYNAMIC_DRAW;
public static final int _wGL_STREAM_DRAW = STREAM_DRAW;
public static final int _wGL_INVALID_ENUM = INVALID_ENUM; public static final int _wGL_INVALID_ENUM = INVALID_ENUM;
public static final int _wGL_INVALID_VALUE= INVALID_VALUE; public static final int _wGL_INVALID_VALUE= INVALID_VALUE;
public static final int _wGL_INVALID_OPERATION = INVALID_OPERATION; public static final int _wGL_INVALID_OPERATION = INVALID_OPERATION;
@ -681,6 +689,9 @@ public class EaglerAdapterImpl2 {
Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4); Uint8Array data = Uint8Array.create(uploadBuffer.getBuffer(), 0, len*4);
webgl.bufferData(p1, data, p3); webgl.bufferData(p1, data, p3);
} }
public static final void _wglBufferData00(int p1, long len, int p3) {
webgl.bufferData(p1, (int)len, p3);
}
public static final void _wglBufferSubData0(int p1, int p2, IntBuffer p3) { public static final void _wglBufferSubData0(int p1, int p2, IntBuffer p3) {
int len = p3.remaining(); int len = p3.remaining();
Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer()); Int32Array deevis = Int32Array.create(uploadBuffer.getBuffer());
@ -773,7 +784,7 @@ public class EaglerAdapterImpl2 {
webgl.vertexAttribPointer(p1, p2, p3, p4, p5, p6); webgl.vertexAttribPointer(p1, p2, p3, p4, p5, p6);
} }
public static final void _wglBindFramebuffer(int p1, FramebufferGL p2) { public static final void _wglBindFramebuffer(int p1, FramebufferGL p2) {
webgl.bindFramebuffer(p1, p2 == null ? null : p2.obj); webgl.bindFramebuffer(p1, p2 == null ? backBuffer.obj : p2.obj);
} }
public static final FramebufferGL _wglCreateFramebuffer() { public static final FramebufferGL _wglCreateFramebuffer() {
return new FramebufferGL(webgl.createFramebuffer()); return new FramebufferGL(webgl.createFramebuffer());
@ -784,6 +795,9 @@ public class EaglerAdapterImpl2 {
public static final void _wglFramebufferTexture2D(int p1, TextureGL p2) { public static final void _wglFramebufferTexture2D(int p1, TextureGL p2) {
webgl.framebufferTexture2D(FRAMEBUFFER, p1, TEXTURE_2D, p2 == null ? null : p2.obj, 0); webgl.framebufferTexture2D(FRAMEBUFFER, p1, TEXTURE_2D, p2 == null ? null : p2.obj, 0);
} }
public static final void _wglFramebufferTexture2D(int p1, TextureGL p2, int p3) {
webgl.framebufferTexture2D(FRAMEBUFFER, p1, TEXTURE_2D, p2 == null ? null : p2.obj, p3);
}
public static final QueryGL _wglCreateQuery() { public static final QueryGL _wglCreateQuery() {
return new QueryGL(webgl.createQuery()); return new QueryGL(webgl.createQuery());
} }
@ -867,6 +881,9 @@ public class EaglerAdapterImpl2 {
return loadPNG0(arr); return loadPNG0(arr);
} }
@JSBody(params = { "cccc", "ennn" }, script = "cccc.imageSmoothingEnabled = ennn;")
private static native void setImageSmoothingMode(CanvasRenderingContext2D cc, boolean en);
@Async @Async
private static native EaglerImage loadPNG0(ArrayBuffer data); private static native EaglerImage loadPNG0(ArrayBuffer data);
@ -885,6 +902,7 @@ public class EaglerAdapterImpl2 {
} }
if(imageLoadContext == null) { if(imageLoadContext == null) {
imageLoadContext = (CanvasRenderingContext2D) imageLoadCanvas.getContext("2d"); imageLoadContext = (CanvasRenderingContext2D) imageLoadCanvas.getContext("2d");
setImageSmoothingMode(imageLoadContext, false);
} }
imageLoadContext.clearRect(0, 0, toLoad.getWidth(), toLoad.getHeight()); imageLoadContext.clearRect(0, 0, toLoad.getWidth(), toLoad.getHeight());
imageLoadContext.drawImage(toLoad, 0, 0, toLoad.getWidth(), toLoad.getHeight()); imageLoadContext.drawImage(toLoad, 0, 0, toLoad.getWidth(), toLoad.getHeight());
@ -896,11 +914,14 @@ public class EaglerAdapterImpl2 {
ret.complete(null); ret.complete(null);
return; return;
} }
DataView dv = DataView.create(pxls.getBuffer());
int[] pixels = new int[totalPixels]; int[] pixels = new int[totalPixels];
for(int i = 0; i < pixels.length; ++i) { for(int i = 0, j; i < pixels.length; ++i) {
pixels[i] = (pxls.get(i * 4) << 16) | (pxls.get(i * 4 + 1) << 8) | pxls.get(i * 4 + 2) | (pxls.get(i * 4 + 3) << 24); j = dv.getUint32(i << 2, false);
pixels[i] = ((j >> 8) & 0xFFFFFF) | ((j & 0xFF) << 24);
} }
ret.complete(new EaglerImage(pixels, pxlsDat.getWidth(), pxlsDat.getHeight(), true)); IntBuffer buffer = IntBuffer.wrap(pixels);
ret.complete(new EaglerImage(buffer, pxlsDat.getWidth(), pxlsDat.getHeight(), true));
} }
}); });
toLoad.addEventListener("error", new EventListener<Event>() { toLoad.addEventListener("error", new EventListener<Event>() {
@ -1001,10 +1022,10 @@ public class EaglerAdapterImpl2 {
return mouseY; return mouseY;
} }
public static final int mouseGetEventX() { public static final int mouseGetEventX() {
return currentEvent == null ? -1 : currentEvent.getClientX(); return currentEvent == null ? -1 : (int)(currentEvent.getClientX() * win.getDevicePixelRatio());
} }
public static final int mouseGetEventY() { public static final int mouseGetEventY() {
return currentEvent == null ? -1 : canvas.getClientHeight() - currentEvent.getClientY(); return currentEvent == null ? -1 : (int)((canvas.getClientHeight() - currentEvent.getClientY()) * win.getDevicePixelRatio());
} }
public static final boolean keysNext() { public static final boolean keysNext() {
if(unpressCTRL) { //un-press ctrl after copy/paste permission if(unpressCTRL) { //un-press ctrl after copy/paste permission
@ -1072,28 +1093,51 @@ public class EaglerAdapterImpl2 {
return isKeyDown(mod) && p1 >= 59 && p1 <= 67 & isKeyDown(2 + (p1 - 59)); return isKeyDown(mod) && p1 >= 59 && p1 <= 67 & isKeyDown(2 + (p1 - 59));
} }
@JSBody(params = { "obj" }, script = "if(obj.commit) obj.commit();")
private static native int commitContext(JSObject obj);
public static final void updateDisplay() { public static final void updateDisplay() {
commitContext(webgl); double r = win.getDevicePixelRatio();
canvasContext.drawImage(canvasBack, 0d, 0d, canvas.getWidth(), canvas.getHeight()); int w = (int)(canvas.getClientWidth() * r);
int h = (int)(canvas.getClientHeight() * r);
int ww = canvas.getClientWidth(); if(canvas.getWidth() != w) {
int hh = canvas.getClientHeight(); canvas.setWidth(w);
if(ww != width || hh != height) { }
width = ww; if(canvas.getHeight() != h) {
height = hh; canvas.setHeight(h);
canvasBack.setWidth(ww);
canvasBack.setHeight(hh);
} }
webgl.bindFramebuffer(FRAMEBUFFER, null);
webgl.bindFramebuffer(READ_FRAMEBUFFER, backBuffer.obj);
webgl.bindFramebuffer(DRAW_FRAMEBUFFER, null);
webgl.blitFramebuffer(0, 0, backBufferWidth, backBufferHeight, 0, 0, w, h, COLOR_BUFFER_BIT, NEAREST);
webgl.bindFramebuffer(FRAMEBUFFER, backBuffer.obj);
resizeBackBuffer(w, h);
try { try {
Thread.sleep(1l); Thread.sleep(1l);
} catch (InterruptedException e) { } catch (InterruptedException e) {
; ;
} }
} }
public static final void setupBackBuffer() {
backBuffer = _wglCreateFramebuffer();
_wglBindFramebuffer(_wGL_FRAMEBUFFER, null);
backBufferColor = _wglCreateRenderBuffer();
_wglBindRenderbuffer(backBufferColor);
_wglFramebufferRenderbuffer(_wGL_COLOR_ATTACHMENT0, backBufferColor);
backBufferDepth = _wglCreateRenderBuffer();
_wglBindRenderbuffer(backBufferDepth);
_wglFramebufferRenderbuffer(_wGL_DEPTH_ATTACHMENT, backBufferDepth);
}
private static int backBufferWidth = -1;
private static int backBufferHeight = -1;
public static final void resizeBackBuffer(int w, int h) {
if(w != backBufferWidth || h != backBufferHeight) {
_wglBindRenderbuffer(backBufferColor);
_wglRenderbufferStorage(_wGL_RGBA8, w, h);
_wglBindRenderbuffer(backBufferDepth);
_wglRenderbufferStorage(_wGL_DEPTH_COMPONENT32F, w, h);
backBufferWidth = w;
backBufferHeight = h;
}
}
public static final void setVSyncEnabled(boolean p1) { public static final void setVSyncEnabled(boolean p1) {
} }
@ -1127,22 +1171,10 @@ public class EaglerAdapterImpl2 {
return win.getScreen().getAvailHeight(); return win.getScreen().getAvailHeight();
} }
public static final int getCanvasWidth() { public static final int getCanvasWidth() {
int w = parent.getClientWidth(); return (int)(parent.getClientWidth() * win.getDevicePixelRatio());
if(w != width) {
canvas.setWidth(w);
canvasBack.setWidth(w);
width = w;
}
return w;
} }
public static final int getCanvasHeight() { public static final int getCanvasHeight() {
int h = parent.getClientHeight(); return (int)(parent.getClientHeight() * win.getDevicePixelRatio());
if(h != height) {
canvas.setHeight(h);
canvasBack.setHeight(h);
height = h;
}
return h;
} }
public static final void setDisplaySize(int x, int y) { public static final void setDisplaySize(int x, int y) {

View File

@ -233,8 +233,8 @@ public class Tessellator {
* integer). * integer).
*/ */
public void setColorOpaque_I(int par1) { public void setColorOpaque_I(int par1) {
int var2 = par1 >> 16 & 255; int var2 = par1 >>> 16 & 255;
int var3 = par1 >> 8 & 255; int var3 = par1 >>> 8 & 255;
int var4 = par1 & 255; int var4 = par1 & 255;
this.setColorOpaque(var2, var3, var4); this.setColorOpaque(var2, var3, var4);
} }
@ -244,8 +244,8 @@ public class Tessellator {
* values. * values.
*/ */
public void setColorRGBA_I(int par1, int par2) { public void setColorRGBA_I(int par1, int par2) {
int var3 = par1 >> 16 & 255; int var3 = par1 >>> 16 & 255;
int var4 = par1 >> 8 & 255; int var4 = par1 >>> 8 & 255;
int var5 = par1 & 255; int var5 = par1 & 255;
this.setColorRGBA(var3, var4, var5, par2); this.setColorRGBA(var3, var4, var5, par2);
} }
@ -262,10 +262,10 @@ public class Tessellator {
*/ */
public void setNormal(float par1, float par2, float par3) { public void setNormal(float par1, float par2, float par3) {
this.hasNormals = true; this.hasNormals = true;
float len = (float) Math.sqrt(par1 * par1 + par2 * par2 + par3 * par3); //float len = (float) Math.sqrt(par1 * par1 + par2 * par2 + par3 * par3);
int var4 = (int)((par1 / len) * 127.0F) + 127; int var4 = (int)((par1) * 127.0F) + 127;
int var5 = (int)((par2 / len) * 127.0F) + 127; int var5 = (int)((par2) * 127.0F) + 127;
int var6 = (int)((par3 / len) * 127.0F) + 127; int var6 = (int)((par3) * 127.0F) + 127;
this.normal = var4 & 255 | (var5 & 255) << 8 | (var6 & 255) << 16; this.normal = var4 & 255 | (var5 & 255) << 8 | (var6 & 255) << 16;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.