Update #0 - First Release

This commit is contained in:
LAX1DUDE
2022-12-25 01:12:28 -08:00
commit e7179fad45
2154 changed files with 256324 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
class DisplayList {
IBufferArrayGL vertexArray = null;
IBufferGL vertexBuffer = null;
int attribs = -1;
int mode = -1;
int count = 0;
boolean bindQuad16 = false;
boolean bindQuad32 = false;
}

View File

@ -0,0 +1,461 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.IntBuffer;
import java.util.HashMap;
import java.util.Map;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.GLObjectMap;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IQueryGL;
import net.lax1dude.eaglercraft.v1_8.internal.ITextureGL;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformBufferFunctions;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class EaglercraftGPU {
static final GLObjectMap<ITextureGL> mapTexturesGL = new GLObjectMap(32767);
static final GLObjectMap<IQueryGL> mapQueriesGL = new GLObjectMap(32767);
static final GLObjectMap<DisplayList> mapDisplayListsGL = new GLObjectMap(32767);
public static final String gluErrorString(int i) {
switch(i) {
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
case 1286: return "GL_INVALID_FRAMEBUFFER_OPERATION";
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
case GL_CONTEXT_LOST_WEBGL: return "CONTEXT_LOST_WEBGL";
default: return "Unknown Error";
}
}
public static final void glTexParameteri(int target, int param, int value) {
_wglTexParameteri(target, param, value);
}
public static final void glTexParameterf(int target, int param, float value) {
_wglTexParameterf(target, param, value);
}
public static final void glCopyTexSubImage2D(int target, int level, int sx, int sy, int dx, int dy, int w, int h) {
_wglCopyTexSubImage2D(target, level, sx, sy, dx, dy, w, h);
}
private static DisplayList currentList = null;
private static ByteBuffer displayListBuffer = EagRuntime.allocateByteBuffer(0x100000);
public static final void glNewList(int target, int op) {
if(currentList != null) {
throw new IllegalStateException("A display list is already being compiled you eagler!");
}
if(op != GL_COMPILE) {
throw new UnsupportedOperationException("Only GL_COMPILE is supported by glNewList");
}
DisplayList dp = currentList = mapDisplayListsGL.get(target);
if(dp == null) {
throw new IllegalArgumentException("Unknown display list: " + target);
}
if(dp.vertexArray != null && dp.attribs > 0) {
EaglercraftGPU.bindGLBufferArray(dp.vertexArray);
int c = 0;
if((dp.attribs & ATTRIB_TEXTURE) == ATTRIB_TEXTURE) {
_wglDisableVertexAttribArray(++c);
}
if((dp.attribs & ATTRIB_COLOR) == ATTRIB_COLOR) {
_wglDisableVertexAttribArray(++c);
}
if((dp.attribs & ATTRIB_NORMAL) == ATTRIB_NORMAL) {
_wglDisableVertexAttribArray(++c);
}
if((dp.attribs & ATTRIB_LIGHTMAP) == ATTRIB_LIGHTMAP) {
_wglDisableVertexAttribArray(++c);
}
}
dp.attribs = -1;
dp.mode = -1;
dp.count = 0;
}
private static final void growDisplayListBuffer(int len) {
int wantSize = displayListBuffer.position() + len;
if(displayListBuffer.capacity() < wantSize) {
int newSize = (wantSize & 0xFFFE0000) + 0x40000;
ByteBuffer newBuffer = EagRuntime.allocateByteBuffer(newSize);
PlatformBufferFunctions.put(newBuffer, (ByteBuffer)displayListBuffer.flip());
EagRuntime.freeByteBuffer(displayListBuffer);
displayListBuffer = newBuffer;
}
}
public static final void glEndList() {
DisplayList dp = currentList;
if(dp == null) {
throw new IllegalStateException("No list is currently being compiled!");
}
if(dp.attribs == -1) {
if(dp.vertexArray != null) {
_wglDeleteVertexArrays(dp.vertexArray);
dp.vertexArray = null;
}
if(dp.vertexBuffer != null) {
_wglDeleteBuffers(dp.vertexBuffer);
dp.vertexBuffer = null;
}
return;
}
if(dp.vertexArray == null) {
dp.vertexArray = _wglGenVertexArrays();
dp.bindQuad16 = false;
dp.bindQuad32 = false;
}
if(dp.vertexBuffer == null) {
dp.vertexBuffer = _wglGenBuffers();
}
bindGLArrayBuffer(dp.vertexBuffer);
displayListBuffer.flip();
_wglBufferData(GL_ARRAY_BUFFER, displayListBuffer, GL_STATIC_DRAW);
displayListBuffer.clear();
FixedFunctionPipeline.setupDisplayList(dp);
currentList = null;
}
public static void glCallList(int displayList) {
DisplayList dp = mapDisplayListsGL.get(displayList);
if(dp == null) {
throw new NullPointerException("Tried to call a display list that does not exist: " + displayList);
}
if(dp.attribs != -1) {
FixedFunctionPipeline p = FixedFunctionPipeline.setupRenderDisplayList(dp.attribs).update();
bindGLBufferArray(dp.vertexArray);
if(dp.mode == GL_QUADS) {
int cnt = dp.count;
if(cnt > 0xFFFF) {
if(!dp.bindQuad32) {
dp.bindQuad16 = false;
dp.bindQuad32 = true;
attachQuad32EmulationBuffer(cnt, true);
}else {
attachQuad32EmulationBuffer(cnt, false);
}
p.drawElements(GL_TRIANGLES, cnt + (cnt >> 1), GL_UNSIGNED_INT, 0);
}else {
if(!dp.bindQuad16) {
dp.bindQuad16 = true;
dp.bindQuad32 = false;
attachQuad16EmulationBuffer(cnt, true);
}else {
attachQuad16EmulationBuffer(cnt, false);
}
p.drawElements(GL_TRIANGLES, cnt + (cnt >> 1), GL_UNSIGNED_SHORT, 0);
}
}else {
p.drawArrays(dp.mode, 0, dp.count);
}
}
}
public static final void flushDisplayList(int displayList) {
DisplayList dp = mapDisplayListsGL.get(displayList);
if(dp == null) {
throw new NullPointerException("Tried to flush a display list that does not exist: " + displayList);
}
dp.attribs = -1;
if(dp.vertexArray != null) {
_wglDeleteVertexArrays(dp.vertexArray);
dp.vertexArray = null;
}
if(dp.vertexBuffer != null) {
_wglDeleteBuffers(dp.vertexBuffer);
dp.vertexBuffer = null;
}
}
public static final void glNormal3f(float x, float y, float z) {
GlStateManager.stateNormalX = x;
GlStateManager.stateNormalY = y;
GlStateManager.stateNormalZ = z;
++GlStateManager.stateNormalSerial;
}
private static final Map<Integer,String> stringCache = new HashMap();
public static final String glGetString(int param) {
String str = stringCache.get(param);
if(str == null) {
str = _wglGetString(param);
stringCache.put(param, str);
}
return str;
}
public static final void glGetInteger(int param, int[] values) {
switch(param) {
case GL_VIEWPORT:
values[0] = GlStateManager.viewportX;
values[1] = GlStateManager.viewportY;
values[2] = GlStateManager.viewportW;
values[3] = GlStateManager.viewportH;
break;
default:
throw new UnsupportedOperationException("glGetInteger only accepts GL_VIEWPORT as a parameter");
}
}
public static final int glGetInteger(int param) {
return _wglGetInteger(param);
}
public static final void glTexImage2D(int target, int level, int internalFormat, int w, int h, int unused,
int format, int type, IntBuffer pixels) {
_wglTexImage2D(target, level, internalFormat, w, h, unused, format, type, pixels);
}
public static final void glTexSubImage2D(int target, int level, int x, int y, int w, int h, int format,
int type, IntBuffer pixels) {
_wglTexSubImage2D(target, level, x, y, w, h, format, type, pixels);
}
public static final void glLineWidth(float f) {
_wglLineWidth(f);
}
public static final void glFog(int param, FloatBuffer valueBuffer) {
int pos = valueBuffer.position();
switch(param) {
case GL_FOG_COLOR:
GlStateManager.stateFogColorR = valueBuffer.get();
GlStateManager.stateFogColorG = valueBuffer.get();
GlStateManager.stateFogColorB = valueBuffer.get();
GlStateManager.stateFogColorA = valueBuffer.get();
++GlStateManager.stateFogSerial;
break;
default:
throw new UnsupportedOperationException("Only GL_FOG_COLOR is configurable!");
}
valueBuffer.position(pos);
}
public static final void glFogi(int param, int value) {
// I'm not sure what this is for currently
}
public static final int glGenLists() {
return mapDisplayListsGL.register(new DisplayList());
}
public static final void glDeleteLists(int id) {
DisplayList d = mapDisplayListsGL.free(id);
if(d != null) {
if(d.vertexArray != null) {
_wglDeleteVertexArrays(d.vertexArray);
}
if(d.vertexBuffer != null) {
_wglDeleteBuffers(d.vertexBuffer);
}
}
}
public static final int glGetError() {
return _wglGetError();
}
public static final void glBlendEquation(int equation) {
if(equation != GlStateManager.stateBlendEquation) {
_wglBlendEquation(equation);
GlStateManager.stateBlendEquation = equation;
}
}
private static IBufferArrayGL currentBufferArray = null;
static final void bindGLBufferArray(IBufferArrayGL buffer) {
if(currentBufferArray != buffer) {
PlatformOpenGL._wglBindVertexArray(buffer);
currentBufferArray = buffer;
}
}
private static IBufferGL currentArrayBuffer = null;
static final void bindGLArrayBuffer(IBufferGL buffer) {
if(currentArrayBuffer != buffer) {
PlatformOpenGL._wglBindBuffer(GL_ARRAY_BUFFER, buffer);
currentArrayBuffer = buffer;
}
}
private static IProgramGL currentShaderProgram = null;
static final void bindGLShaderProgram(IProgramGL prog) {
if(currentShaderProgram != prog) {
PlatformOpenGL._wglUseProgram(prog);
currentShaderProgram = prog;
}
}
public static final int ATTRIB_TEXTURE = 1;
public static final int ATTRIB_COLOR = 2;
public static final int ATTRIB_NORMAL = 4;
public static final int ATTRIB_LIGHTMAP = 8;
public static final void renderBuffer(ByteBuffer buffer, int attrib, int mode, int count) {
if(currentList != null) {
if(currentList.attribs == -1) {
currentList.attribs = attrib;
}else if(currentList.attribs != attrib) {
throw new UnsupportedOperationException("Inconsistent vertex format in display list (only one is allowed)");
}
if(currentList.mode == -1) {
currentList.mode = mode;
}else if(currentList.mode != mode) {
throw new UnsupportedOperationException("Inconsistent draw mode in display list (only one is allowed)");
}
currentList.count += count;
if(buffer.remaining() > displayListBuffer.remaining()) {
growDisplayListBuffer(buffer.remaining());
}
displayListBuffer.put(buffer);
lastRender = null;
}else {
lastRender = FixedFunctionPipeline.setupDirect(buffer, attrib).update();
lastRender.drawDirectArrays(mode, 0, count);
lastMode = mode;
lastCount = count;
}
}
private static FixedFunctionPipeline lastRender = null;
private static int lastMode = 0;
private static int lastCount = 0;
public static final void renderAgain() {
if(lastRender == null) {
throw new UnsupportedOperationException("Cannot render the same verticies twice while generating display list");
}
EaglercraftGPU.bindGLBufferArray(lastRender.getDirectModeBufferArray());
lastRender.update().drawDirectArrays(lastMode, 0, lastCount);
}
private static IBufferGL quad16EmulationBuffer = null;
private static int quad16EmulationBufferSize = 0;
private static IBufferGL quad32EmulationBuffer = null;
private static int quad32EmulationBufferSize = 0;
static final void attachQuad16EmulationBuffer(int vertexCount, boolean bind) {
IBufferGL buf = quad16EmulationBuffer;
if(buf == null) {
quad16EmulationBuffer = buf = _wglGenBuffers();
int newSize = quad16EmulationBufferSize = (vertexCount & 0xFFFFF000) + 0x2000;
if(newSize > 0xFFFF) {
newSize = 0xFFFF;
}
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
resizeQuad16EmulationBuffer(newSize >> 2);
}else {
int cnt = quad16EmulationBufferSize;
if(cnt < vertexCount) {
int newSize = quad16EmulationBufferSize = (vertexCount & 0xFFFFF000) + 0x2000;
if(newSize > 0xFFFF) {
newSize = 0xFFFF;
}
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
resizeQuad16EmulationBuffer(newSize >> 2);
}else if(bind) {
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
}
}
}
static final void attachQuad32EmulationBuffer(int vertexCount, boolean bind) {
IBufferGL buf = quad32EmulationBuffer;
if(buf == null) {
quad32EmulationBuffer = buf = _wglGenBuffers();
int newSize = quad32EmulationBufferSize = (vertexCount & 0xFFFFC000) + 0x8000;
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
resizeQuad32EmulationBuffer(newSize >> 2);
}else {
int cnt = quad32EmulationBufferSize;
if(cnt < vertexCount) {
int newSize = quad32EmulationBufferSize = (vertexCount & 0xFFFFC000) + 0x8000;
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
resizeQuad32EmulationBuffer(newSize >> 2);
}else if(bind) {
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
}
}
}
private static final void resizeQuad16EmulationBuffer(int quadCount) {
IntBuffer buf = EagRuntime.allocateIntBuffer(quadCount * 3);
int v1, v2, v3, v4;
for(int i = 0; i < quadCount; ++i) {
v1 = i << 2;
v2 = v1 + 1;
v3 = v2 + 1;
v4 = v3 + 1;
buf.put(v1 | (v2 << 16));
buf.put(v4 | (v2 << 16));
buf.put(v3 | (v4 << 16));
}
buf.flip();
_wglBufferData(GL_ELEMENT_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
EagRuntime.freeIntBuffer(buf);
}
private static final void resizeQuad32EmulationBuffer(int quadCount) {
IntBuffer buf = EagRuntime.allocateIntBuffer(quadCount * 6);
int v1, v2, v3, v4;
for(int i = 0; i < quadCount; ++i) {
v1 = i << 2;
v2 = v1 + 1;
v3 = v2 + 1;
v4 = v3 + 1;
buf.put(v1); buf.put(v2);
buf.put(v4); buf.put(v2);
buf.put(v3); buf.put(v4);
}
buf.flip();
_wglBufferData(GL_ELEMENT_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
EagRuntime.freeIntBuffer(buf);
}
public static final void warmUpCache() {
EaglercraftGPU.glGetString(7936);
EaglercraftGPU.glGetString(7937);
EaglercraftGPU.glGetString(7938);
SpriteLevelMixer.initialize();
InstancedFontRenderer.initialize();
InstancedParticleRenderer.initialize();
}
public static final ITextureGL getNativeTexture(int tex) {
return mapTexturesGL.get(tex);
}
}

View File

@ -0,0 +1,975 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
import net.minecraft.util.MathHelper;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
class FixedFunctionPipeline {
private static final Logger LOGGER = LogManager.getLogger("FixedFunctionPipeline");
static final int STATE_HAS_ATTRIB_TEXTURE = 1;
static final int STATE_HAS_ATTRIB_COLOR = 2;
static final int STATE_HAS_ATTRIB_NORMAL = 4;
static final int STATE_HAS_ATTRIB_LIGHTMAP = 8;
static final int STATE_ENABLE_TEXTURE2D = 16;
static final int STATE_ENABLE_LIGHTMAP = 32;
static final int STATE_ENABLE_ALPHA_TEST = 64;
static final int STATE_ENABLE_MC_LIGHTING = 128;
static final int STATE_ENABLE_END_PORTAL = 256;
static final int STATE_ENABLE_ANISOTROPIC_FIX = 512;
static final int STATE_ENABLE_FOG = 1024;
static final int STATE_ENABLE_BLEND_ADD = 2048;
static final int getFragmentState() {
return (GlStateManager.stateTexture[0] ? STATE_ENABLE_TEXTURE2D : 0) |
(GlStateManager.stateTexture[1] ? STATE_ENABLE_LIGHTMAP : 0) |
(GlStateManager.stateAlphaTest ? STATE_ENABLE_ALPHA_TEST : 0) |
((GlStateManager.stateLighting && GlStateManager.stateMaterial)
? STATE_ENABLE_MC_LIGHTING : 0) |
((GlStateManager.stateTexture[0] && GlStateManager.stateTexGen)
? STATE_ENABLE_END_PORTAL : 0) |
/* TODO: (GlStateManager.??? ? STATE_ENABLE_ANISOTROPIC_FIX : 0) | */
((GlStateManager.stateFog && GlStateManager.stateFogDensity > 0.0f)
? STATE_ENABLE_FOG : 0) |
(GlStateManager.stateEnableShaderBlendColor ? STATE_ENABLE_BLEND_ADD : 0);
}
static FixedFunctionPipeline setupDirect(ByteBuffer buffer, int attrib) {
FixedFunctionPipeline self = getPipelineInstance(attrib | getFragmentState());
EaglercraftGPU.bindGLBufferArray(self.vertexArray);
EaglercraftGPU.bindGLArrayBuffer(self.vertexBuffer);
int wantSize = buffer.remaining();
if(self.vertexBufferSize < wantSize) {
int newSize = (wantSize & 0xFFFFF000) + 0x2000;
_wglBufferData(GL_ARRAY_BUFFER, newSize, GL_DYNAMIC_DRAW);
self.vertexBufferSize = newSize;
}
_wglBufferSubData(GL_ARRAY_BUFFER, 0, buffer);
return self;
}
static void setupDisplayList(DisplayList list) {
FixedFunctionPipeline self = getPipelineInstance(list.attribs | getFragmentState());
EaglercraftGPU.bindGLBufferArray(list.vertexArray);
EaglercraftGPU.bindGLArrayBuffer(list.vertexBuffer);
_wglEnableVertexAttribArray(0);
_wglVertexAttribPointer(0, VertexFormat.COMPONENT_POSITION_SIZE,
VertexFormat.COMPONENT_POSITION_FORMAT, false, self.attribStride, 0);
if(self.attribTextureIndex != -1) {
_wglEnableVertexAttribArray(self.attribTextureIndex);
_wglVertexAttribPointer(self.attribTextureIndex, VertexFormat.COMPONENT_TEX_SIZE,
VertexFormat.COMPONENT_TEX_FORMAT, false, self.attribStride, self.attribTextureOffset);
}
if(self.attribColorIndex != -1) {
_wglEnableVertexAttribArray(self.attribColorIndex);
_wglVertexAttribPointer(self.attribColorIndex, VertexFormat.COMPONENT_COLOR_SIZE,
VertexFormat.COMPONENT_COLOR_FORMAT, true, self.attribStride, self.attribColorOffset);
}
if(self.attribNormalIndex != -1) {
_wglEnableVertexAttribArray(self.attribNormalIndex);
_wglVertexAttribPointer(self.attribNormalIndex, VertexFormat.COMPONENT_NORMAL_SIZE,
VertexFormat.COMPONENT_NORMAL_FORMAT, true, self.attribStride, self.attribNormalOffset);
}
if(self.attribLightmapIndex != -1) {
_wglEnableVertexAttribArray(self.attribLightmapIndex);
_wglVertexAttribPointer(self.attribLightmapIndex, VertexFormat.COMPONENT_LIGHTMAP_SIZE,
VertexFormat.COMPONENT_LIGHTMAP_FORMAT, false, self.attribStride, self.attribLightmapOffset);
}
}
static FixedFunctionPipeline setupRenderDisplayList(int attribs) {
return getPipelineInstance(attribs | getFragmentState());
}
void drawArrays(int mode, int offset, int count) {
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
PlatformOpenGL._wglDrawArrays(mode, offset, count);
}
void drawDirectArrays(int mode, int offset, int count) {
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
if(mode == GL_QUADS) {
if(count > 0xFFFF) {
if(!bindQuad32) {
bindQuad16 = false;
bindQuad32 = true;
EaglercraftGPU.attachQuad32EmulationBuffer(count, true);
}else {
EaglercraftGPU.attachQuad32EmulationBuffer(count, false);
}
PlatformOpenGL._wglDrawElements(GL_TRIANGLES, count + (count >> 1),
GL_UNSIGNED_INT, 0);
}else {
if(!bindQuad16) {
bindQuad16 = true;
bindQuad32 = false;
EaglercraftGPU.attachQuad16EmulationBuffer(count, true);
}else {
EaglercraftGPU.attachQuad16EmulationBuffer(count, false);
}
PlatformOpenGL._wglDrawElements(GL_TRIANGLES, count + (count >> 1),
GL_UNSIGNED_SHORT, 0);
}
}else {
PlatformOpenGL._wglDrawArrays(mode, offset, count);
}
}
void drawElements(int mode, int count, int type, int offset) {
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
PlatformOpenGL._wglDrawElements(mode, count, type, offset);
}
private static final FixedFunctionPipeline[] pipelineStateCache = new FixedFunctionPipeline[4096];
private static String shaderSourceCacheVSH = null;
private static String shaderSourceCacheFSH = null;
private static FixedFunctionPipeline getPipelineInstance(int bits) {
FixedFunctionPipeline pp = pipelineStateCache[bits];
if(pp == null) {
if(shaderSourceCacheVSH == null) {
shaderSourceCacheVSH = EagRuntime.getResourceString(FixedFunctionConstants.FILENAME_VSH);
if(shaderSourceCacheVSH == null) {
throw new RuntimeException("Could not load: " + FixedFunctionConstants.FILENAME_VSH);
}
}
if(shaderSourceCacheFSH == null) {
shaderSourceCacheFSH = EagRuntime.getResourceString(FixedFunctionConstants.FILENAME_FSH);
if(shaderSourceCacheFSH == null) {
throw new RuntimeException("Could not load: " + FixedFunctionConstants.FILENAME_FSH);
}
}
String macros = FixedFunctionConstants.VERSION + "\n";
if((bits & STATE_HAS_ATTRIB_TEXTURE) == STATE_HAS_ATTRIB_TEXTURE) {
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_TEXTURE + "\n");
}
if((bits & STATE_HAS_ATTRIB_COLOR) == STATE_HAS_ATTRIB_COLOR) {
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_COLOR + "\n");
}
if((bits & STATE_HAS_ATTRIB_NORMAL) == STATE_HAS_ATTRIB_NORMAL) {
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_NORMAL + "\n");
}
if((bits & STATE_HAS_ATTRIB_LIGHTMAP) == STATE_HAS_ATTRIB_LIGHTMAP) {
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_LIGHTMAP + "\n");
}
if((bits & STATE_ENABLE_TEXTURE2D) == STATE_ENABLE_TEXTURE2D) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_TEXTURE2D + "\n");
}
if((bits & STATE_ENABLE_LIGHTMAP) == STATE_ENABLE_LIGHTMAP) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_LIGHTMAP + "\n");
}
if((bits & STATE_ENABLE_ALPHA_TEST) == STATE_ENABLE_ALPHA_TEST) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_ALPHA_TEST + "\n");
}
if((bits & STATE_ENABLE_MC_LIGHTING) == STATE_ENABLE_MC_LIGHTING) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_MC_LIGHTING + "\n");
}
if((bits & STATE_ENABLE_END_PORTAL) == STATE_ENABLE_END_PORTAL) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_END_PORTAL + "\n");
}
if((bits & STATE_ENABLE_ANISOTROPIC_FIX) == STATE_ENABLE_ANISOTROPIC_FIX) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_ANISOTROPIC_FIX + "\n");
}
if((bits & STATE_ENABLE_FOG) == STATE_ENABLE_FOG) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_FOG + "\n");
}
if((bits & STATE_ENABLE_BLEND_ADD) == STATE_ENABLE_BLEND_ADD) {
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_BLEND_ADD + "\n");
}
macros += ("precision " + FixedFunctionConstants.PRECISION_INT + " int;\n");
macros += ("precision " + FixedFunctionConstants.PRECISION_FLOAT + " float;\n");
macros += ("precision " + FixedFunctionConstants.PRECISION_SAMPLER + " sampler2D;\n\n");
IShaderGL vsh = _wglCreateShader(GL_VERTEX_SHADER);
_wglShaderSource(vsh, macros + shaderSourceCacheVSH);
_wglCompileShader(vsh);
if(_wglGetShaderi(vsh, GL_COMPILE_STATUS) != GL_TRUE) {
LOGGER.error("Failed to compile GL_VERTEX_SHADER for state {} !", getStateBits(bits, 11));
String log = _wglGetShaderInfoLog(vsh);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
LOGGER.error("[VERT] {}", lines[i]);
}
}
_wglDeleteShader(vsh);
throw new IllegalStateException("Vertex shader could not be compiled!");
}
IShaderGL fsh = _wglCreateShader(GL_FRAGMENT_SHADER);
_wglShaderSource(fsh, macros + shaderSourceCacheFSH);
_wglCompileShader(fsh);
if(_wglGetShaderi(fsh, GL_COMPILE_STATUS) != GL_TRUE) {
LOGGER.error("Failed to compile GL_FRAGMENT_SHADER for state {} !", getStateBits(bits, 11));
String log = _wglGetShaderInfoLog(fsh);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
LOGGER.error("[FRAG] {}", lines[i]);
}
}
_wglDeleteShader(fsh);
_wglDeleteShader(vsh);
throw new IllegalStateException("Fragment shader could not be compiled!");
}
IProgramGL prog = _wglCreateProgram();
_wglAttachShader(prog, vsh);
_wglAttachShader(prog, fsh);
IllegalStateException err = null;
try {
pp = new FixedFunctionPipeline(bits, prog);
}catch(IllegalStateException t) {
err = t;
}
_wglDetachShader(prog, vsh);
_wglDetachShader(prog, fsh);
_wglDeleteShader(fsh);
_wglDeleteShader(vsh);
if(err != null) {
_wglDeleteProgram(prog);
throw err;
}else {
pipelineStateCache[bits] = pp;
}
}
return pp;
}
private static String getStateBits(int input, int bits) {
String out = "";
for(int i = bits - 1; i >= 0; --i) {
out += (input >> bits) & 1;
}
return out;
}
private final int stateBits;
private final boolean stateHasAttribTexture;
private final boolean stateHasAttribColor;
private final boolean stateHasAttribNormal;
private final boolean stateHasAttribLightmap;
private final boolean stateEnableTexture2D;
private final boolean stateEnableLightmap;
private final boolean stateEnableAlphaTest;
private final boolean stateEnableMCLighting;
private final boolean stateEnableEndPortal;
private final boolean stateEnableAnisotropicFix;
private final boolean stateEnableFog;
private final boolean stateEnableBlendAdd;
private final int attribTextureIndex;
private final int attribTextureOffset;
private final int attribColorIndex;
private final int attribColorOffset;
private final int attribNormalIndex;
private final int attribNormalOffset;
private final int attribLightmapIndex;
private final int attribLightmapOffset;
private final int attribStride;
private final IProgramGL shaderProgram;
private final IUniformGL stateColorUniform4f;
private float stateColorR = -999.0f;
private float stateColorG = -999.0f;
private float stateColorB = -999.0f;
private float stateColorA = -999.0f;
private int stateColorSerial = -1;
private final IUniformGL stateShaderBlendSrcColorUniform4f;
private float stateShaderBlendSrcColorR = -999.0f;
private float stateShaderBlendSrcColorG = -999.0f;
private float stateShaderBlendSrcColorB = -999.0f;
private float stateShaderBlendSrcColorA = -999.0f;
private final IUniformGL stateShaderBlendAddColorUniform4f;
private float stateShaderBlendAddColorR = -999.0f;
private float stateShaderBlendAddColorG = -999.0f;
private float stateShaderBlendAddColorB = -999.0f;
private float stateShaderBlendAddColorA = -999.0f;
private int stateShaderBlendColorSerial = -1;
private final IUniformGL stateAlphaTestUniform1f;
private float stateAlphaTestRef = -999.0f;
private final IUniformGL stateLightsEnabledUniform1i;
private final IUniformGL[] stateLightsVectorsArrayUniform4f = new IUniformGL[4];
private int stateLightsEnabled = -1;
private final Vector4f[] stateLightsVectors = new Vector4f[4];
private int stateLightingSerial = -1;
private final IUniformGL stateLightingAmbientUniform3f;
private float stateLightingAmbientR = -999.0f;
private float stateLightingAmbientG = -999.0f;
private float stateLightingAmbientB = -999.0f;
private int stateLightingAmbientSerial = -1;
private final IUniformGL stateNormalUniform3f;
private float stateNormalX = -999.0f;
private float stateNormalY = -999.0f;
private float stateNormalZ = -999.0f;
private int stateNormalSerial = -1;
// X = Linear or Exp, Y = Density, Z = start, W = end
private final IUniformGL stateFogParamUniform4f;
private boolean stateFogEXP = false;
private float stateFogDensity = -999.0f;
private float stateFogStart = -999.0f;
private float stateFogEnd = -999.0f;
private final IUniformGL stateFogColorUniform4f;
private float stateFogColorR = -999.0f;
private float stateFogColorG = -999.0f;
private float stateFogColorB = -999.0f;
private float stateFogColorA = -999.0f;
private int stateFogSerial = -1;
private final IUniformGL stateTexGenPlaneUniform4i;
private int stateTexGenSPlane = -1;
private final IUniformGL stateTexGenSVectorUniform4f;
private final Vector4f stateTexGenSVector = new Vector4f();
private int stateTexGenTPlane = -1;
private final IUniformGL stateTexGenTVectorUniform4f;
private final Vector4f stateTexGenTVector = new Vector4f();
private int stateTexGenRPlane = -1;
private final IUniformGL stateTexGenRVectorUniform4f;
private final Vector4f stateTexGenRVector = new Vector4f();
private int stateTexGenQPlane = -1;
private final IUniformGL stateTexGenQVectorUniform4f;
private final Vector4f stateTexGenQVector = new Vector4f();
private int stateTexGenSerial = -1;
private final IUniformGL stateModelMatrixUniformMat4f;
private int stateModelMatrixSerial = -1;
private static final Matrix4f tmpMatrixForInv = new Matrix4f();
private static final Vector4f tmpVec4ForTex = new Vector4f();
private final IUniformGL stateProjectionMatrixUniformMat4f;
private int stateProjectionMatrixSerial = -1;
// implement only 2 textures
private final IUniformGL stateTextureMatrix01UniformMat4f;
private final IUniformGL stateTextureMatrix02UniformMat4f;
private final int[] stateTextureMatrixSerial = new int[8];
private final IUniformGL stateTextureCoords01Uniform2f;
private final IUniformGL stateTextureCoords02Uniform2f;
private final float[] stateTextureCoordsX = new float[8];
private final float[] stateTextureCoordsY = new float[8];
private final int[] stateTextureCoordsAccessSerial = new int[8];
private final int[] stateTextureCoordsMatrixSerial = new int[8];
private final IUniformGL stateAnisotropicFix2f;
private float stateAnisotropicFixW = -999.0f;
private float stateAnisotropicFixH = -999.0f;
private float stateAnisotropicFixSerial = 0;
private final IBufferArrayGL vertexArray;
private final IBufferGL vertexBuffer;
private int vertexBufferSize = -1;
private boolean bindQuad16 = false;
private boolean bindQuad32 = false;
private static FloatBuffer matrixCopyBuffer = null;
private FixedFunctionPipeline(int bits, IProgramGL compiledProg) {
shaderProgram = compiledProg;
stateBits = bits;
stateHasAttribTexture = (bits & STATE_HAS_ATTRIB_TEXTURE) == STATE_HAS_ATTRIB_TEXTURE;
stateHasAttribColor = (bits & STATE_HAS_ATTRIB_COLOR) == STATE_HAS_ATTRIB_COLOR;
stateHasAttribNormal = (bits & STATE_HAS_ATTRIB_NORMAL) == STATE_HAS_ATTRIB_NORMAL;
stateHasAttribLightmap = (bits & STATE_HAS_ATTRIB_LIGHTMAP) == STATE_HAS_ATTRIB_LIGHTMAP;
int index = 0;
int stride = 0;
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_POSITION);
stride += VertexFormat.COMPONENT_POSITION_STRIDE; // vec3f
if(stateHasAttribColor) {
attribColorIndex = ++index;
attribColorOffset = stride;
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_COLOR);
stride += VertexFormat.COMPONENT_COLOR_STRIDE; // vec4b
}else {
attribColorIndex = -1;
attribColorOffset = -1;
}
if(stateHasAttribTexture) {
attribTextureIndex = ++index;
attribTextureOffset = stride;
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_TEXTURE);
stride += VertexFormat.COMPONENT_TEX_STRIDE; // vec2f
}else {
attribTextureIndex = -1;
attribTextureOffset = -1;
}
if(stateHasAttribNormal) {
attribNormalIndex = ++index;
attribNormalOffset = stride;
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_NORMAL);
stride += VertexFormat.COMPONENT_NORMAL_STRIDE; // vec4b
}else {
attribNormalIndex = -1;
attribNormalOffset = -1;
}
if(stateHasAttribLightmap) {
attribLightmapIndex = ++index;
attribLightmapOffset = stride;
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_LIGHTMAP);
stride += VertexFormat.COMPONENT_LIGHTMAP_STRIDE; // vec2s
}else {
attribLightmapIndex = -1;
attribLightmapOffset = -1;
}
attribStride = stride;
_wglLinkProgram(compiledProg);
if(_wglGetProgrami(compiledProg, GL_LINK_STATUS) != GL_TRUE) {
LOGGER.error("Program could not be linked for state {} !", getStateBits(bits, 11));
String log = _wglGetProgramInfoLog(compiledProg);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
LOGGER.error("[LINK] {}", lines[i]);
}
}
throw new IllegalStateException("Program could not be linked!");
}
vertexArray = PlatformOpenGL._wglGenVertexArrays();
vertexBuffer = PlatformOpenGL._wglGenBuffers();
EaglercraftGPU.bindGLBufferArray(vertexArray);
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
_wglEnableVertexAttribArray(0);
_wglVertexAttribPointer(0, VertexFormat.COMPONENT_POSITION_SIZE,
VertexFormat.COMPONENT_POSITION_FORMAT, false, attribStride, 0);
if(attribTextureIndex != -1) {
_wglEnableVertexAttribArray(attribTextureIndex);
_wglVertexAttribPointer(attribTextureIndex, VertexFormat.COMPONENT_TEX_SIZE,
VertexFormat.COMPONENT_TEX_FORMAT, false, attribStride, attribTextureOffset);
}
if(attribColorIndex != -1) {
_wglEnableVertexAttribArray(attribColorIndex);
_wglVertexAttribPointer(attribColorIndex, VertexFormat.COMPONENT_COLOR_SIZE,
VertexFormat.COMPONENT_COLOR_FORMAT, true, attribStride, attribColorOffset);
}
if(attribNormalIndex != -1) {
_wglEnableVertexAttribArray(attribNormalIndex);
_wglVertexAttribPointer(attribNormalIndex, VertexFormat.COMPONENT_NORMAL_SIZE,
VertexFormat.COMPONENT_NORMAL_FORMAT, true, attribStride, attribNormalOffset);
}
if(attribLightmapIndex != -1) {
_wglEnableVertexAttribArray(attribLightmapIndex);
_wglVertexAttribPointer(attribLightmapIndex, VertexFormat.COMPONENT_LIGHTMAP_SIZE,
VertexFormat.COMPONENT_LIGHTMAP_FORMAT, false, attribStride, attribLightmapOffset);
}
stateEnableTexture2D = (bits & STATE_ENABLE_TEXTURE2D) == STATE_ENABLE_TEXTURE2D;
stateEnableLightmap = (bits & STATE_ENABLE_LIGHTMAP) == STATE_ENABLE_LIGHTMAP;
stateEnableAlphaTest = (bits & STATE_ENABLE_ALPHA_TEST) == STATE_ENABLE_ALPHA_TEST;
stateEnableMCLighting = (bits & STATE_ENABLE_MC_LIGHTING) == STATE_ENABLE_MC_LIGHTING;
stateEnableEndPortal = (bits & STATE_ENABLE_END_PORTAL) == STATE_ENABLE_END_PORTAL;
stateEnableAnisotropicFix = (bits & STATE_ENABLE_ANISOTROPIC_FIX) == STATE_ENABLE_ANISOTROPIC_FIX;
stateEnableFog = (bits & STATE_ENABLE_FOG) == STATE_ENABLE_FOG;
stateEnableBlendAdd = (bits & STATE_ENABLE_BLEND_ADD) == STATE_ENABLE_BLEND_ADD;
for(int i = 0; i < stateLightsVectors.length; ++i) {
stateLightsVectors[i] = new Vector4f(-999.0f, -999.0f, -999.0f, 0.0f);
}
for(int i = 0; i < stateTextureMatrixSerial.length; ++i) {
stateTextureMatrixSerial[i] = -1;
}
stateColorUniform4f = _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_COLOR_NAME);
stateAlphaTestUniform1f = stateEnableAlphaTest ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_ALPHA_TEST_NAME) : null;
stateLightsEnabledUniform1i = stateEnableMCLighting ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_LIGHTS_ENABLED_NAME) : null;
if(stateEnableMCLighting) {
for(int i = 0; i < stateLightsVectorsArrayUniform4f.length; ++i) {
stateLightsVectorsArrayUniform4f[i] =_wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_LIGHTS_VECTORS_NAME + "[" + i + "]");
}
}
stateLightingAmbientUniform3f = stateEnableMCLighting ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_LIGHTS_AMBIENT_NAME) : null;
stateNormalUniform3f = (!stateHasAttribNormal && stateEnableMCLighting) ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_CONSTANT_NORMAL_NAME) : null;
stateFogParamUniform4f = stateEnableFog ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_FOG_PARAM_NAME) : null;
stateFogColorUniform4f = stateEnableFog ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_FOG_COLOR_NAME) : null;
stateTexGenPlaneUniform4i = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEX_GEN_PLANE_NAME) : null;
stateTexGenSVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEX_GEN_S_NAME) : null;
stateTexGenTVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEX_GEN_T_NAME) : null;
stateTexGenRVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEX_GEN_R_NAME) : null;
stateTexGenQVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEX_GEN_Q_NAME) : null;
stateModelMatrixUniformMat4f = _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_MODEL_MATRIX_NAME);
stateProjectionMatrixUniformMat4f = _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_PROJECTION_MATRIX_NAME);
stateTextureMatrix01UniformMat4f = (stateEnableEndPortal || stateHasAttribTexture) ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEXTURE_MATRIX_01_NAME) : null;
stateTextureMatrix02UniformMat4f = stateHasAttribLightmap ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEXTURE_MATRIX_02_NAME) : null;
stateTextureCoords01Uniform2f = (!stateHasAttribTexture && stateEnableTexture2D) ? _wglGetUniformLocation(
compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_COORDS_01_NAME) : null;
stateTextureCoords02Uniform2f = (!stateHasAttribLightmap && stateEnableLightmap) ? _wglGetUniformLocation(
compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_COORDS_02_NAME) : null;
stateAnisotropicFix2f = stateEnableAnisotropicFix ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_TEXTURE_ANISOTROPIC_FIX) : null;
stateShaderBlendSrcColorUniform4f = stateEnableBlendAdd ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_BLEND_SRC_COLOR_NAME) : null;
stateShaderBlendAddColorUniform4f = stateEnableBlendAdd ? _wglGetUniformLocation(compiledProg,
FixedFunctionConstants.UNIFORM_BLEND_ADD_COLOR_NAME) : null;
if(stateEnableTexture2D) {
EaglercraftGPU.bindGLShaderProgram(compiledProg);
_wglUniform1i(_wglGetUniformLocation(compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_UNIT_01_NAME), 0);
}
if(stateEnableLightmap) {
EaglercraftGPU.bindGLShaderProgram(compiledProg);
_wglUniform1i(_wglGetUniformLocation(compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_UNIT_02_NAME), 1);
}
}
public FixedFunctionPipeline update() {
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
int serial = GlStateManager.stateColorSerial;
if(stateColorSerial != serial) {
stateColorSerial = serial;
float r = GlStateManager.stateColorR;
float g = GlStateManager.stateColorG;
float b = GlStateManager.stateColorB;
float a = GlStateManager.stateColorA;
if(stateColorR != r || stateColorG != g ||
stateColorB != b || stateColorA != a) {
_wglUniform4f(stateColorUniform4f, r, g, b, a);
stateColorR = r;
stateColorG = g;
stateColorB = b;
stateColorA = a;
}
}
if(matrixCopyBuffer == null) {
matrixCopyBuffer = PlatformRuntime.allocateFloatBuffer(16);
}
int ptr = GlStateManager.modelMatrixStackPointer;
serial = GlStateManager.modelMatrixStackAccessSerial[ptr];
if(stateModelMatrixSerial != serial) {
stateModelMatrixSerial = serial;
matrixCopyBuffer.clear();
GlStateManager.modelMatrixStack[ptr].store(matrixCopyBuffer);
matrixCopyBuffer.flip();
_wglUniformMatrix4fv(stateModelMatrixUniformMat4f, false, matrixCopyBuffer);
}
ptr = GlStateManager.projectionMatrixStackPointer;
serial = GlStateManager.projectionMatrixStackAccessSerial[ptr];
if(stateProjectionMatrixSerial != serial) {
stateProjectionMatrixSerial = serial;
matrixCopyBuffer.clear();
GlStateManager.projectionMatrixStack[ptr].store(matrixCopyBuffer);
matrixCopyBuffer.flip();
_wglUniformMatrix4fv(stateProjectionMatrixUniformMat4f, false, matrixCopyBuffer);
}
if(stateEnableAlphaTest) {
float v = GlStateManager.stateAlphaTestRef;
if(stateAlphaTestRef != v) {
stateAlphaTestRef = v;
_wglUniform1f(stateAlphaTestUniform1f, v);
}
}
if(stateEnableTexture2D) {
ptr = GlStateManager.textureMatrixStackPointer[0];
serial = GlStateManager.textureMatrixStackAccessSerial[0][ptr];
if(stateHasAttribTexture || stateEnableEndPortal) {
if(stateTextureMatrixSerial[0] != serial) {
stateTextureMatrixSerial[0] = serial;
matrixCopyBuffer.clear();
GlStateManager.textureMatrixStack[0][ptr].store(matrixCopyBuffer);
matrixCopyBuffer.flip();
_wglUniformMatrix4fv(stateTextureMatrix01UniformMat4f, false, matrixCopyBuffer);
}
}
if(!stateHasAttribTexture && !stateEnableEndPortal) {
int serial2 = GlStateManager.textureCoordsAccessSerial[0];
if(stateTextureCoordsAccessSerial[0] != serial2 || stateTextureCoordsMatrixSerial[0] != serial) {
stateTextureCoordsAccessSerial[0] = serial2;
stateTextureCoordsMatrixSerial[0] = serial;
tmpVec4ForTex.x = GlStateManager.textureCoordsX[0];
tmpVec4ForTex.y = GlStateManager.textureCoordsY[0];
tmpVec4ForTex.z = 0.0f;
tmpVec4ForTex.w = 1.0f;
Matrix4f.transform(GlStateManager.textureMatrixStack[0][ptr], tmpVec4ForTex, tmpVec4ForTex);
float x = tmpVec4ForTex.x / tmpVec4ForTex.w;
float y = tmpVec4ForTex.y / tmpVec4ForTex.w;
if(x != stateTextureCoordsX[0] || y != stateTextureCoordsY[0]) {
stateTextureCoordsX[0] = x;
stateTextureCoordsY[0] = y;
_wglUniform2f(stateTextureCoords01Uniform2f, x, y);
}
}
}
}
if(stateEnableLightmap) {
ptr = GlStateManager.textureMatrixStackPointer[1];
serial = GlStateManager.textureMatrixStackAccessSerial[1][ptr];
if(!stateHasAttribLightmap) {
int serial2 = GlStateManager.textureCoordsAccessSerial[1];
if(stateTextureCoordsAccessSerial[1] != serial2 || stateTextureCoordsMatrixSerial[1] != serial) {
stateTextureCoordsAccessSerial[1] = serial2;
stateTextureCoordsMatrixSerial[1] = serial;
tmpVec4ForTex.x = GlStateManager.textureCoordsX[1];
tmpVec4ForTex.y = GlStateManager.textureCoordsY[1];
tmpVec4ForTex.z = 0.0f;
tmpVec4ForTex.w = 1.0f;
Matrix4f.transform(GlStateManager.textureMatrixStack[1][ptr], tmpVec4ForTex, tmpVec4ForTex);
float x = tmpVec4ForTex.x / tmpVec4ForTex.w;
float y = tmpVec4ForTex.y / tmpVec4ForTex.w;
if(x != stateTextureCoordsX[1] || y != stateTextureCoordsY[1]) {
stateTextureCoordsX[1] = x;
stateTextureCoordsY[1] = y;
_wglUniform2f(stateTextureCoords02Uniform2f, x, y);
}
}
}else {
if(stateTextureMatrixSerial[1] != serial) {
stateTextureMatrixSerial[1] = serial;
matrixCopyBuffer.clear();
GlStateManager.textureMatrixStack[1][ptr].store(matrixCopyBuffer);
matrixCopyBuffer.flip();
_wglUniformMatrix4fv(stateTextureMatrix02UniformMat4f, false, matrixCopyBuffer);
}
}
}
if(stateEnableMCLighting) {
ptr = GlStateManager.stateLightsStackPointer;
serial = GlStateManager.stateLightingSerial[ptr];
if(stateLightingSerial != serial) {
stateLightingSerial = serial;
boolean[] en = GlStateManager.stateLightsEnabled[ptr];
int lightsCounter = 0;
for(int i = 0; i < en.length; ++i) {
if(en[i]) {
Vector4f lightDirOld = stateLightsVectors[lightsCounter];
Vector4f lightDirNew = GlStateManager.stateLightsStack[ptr][i];
float x = lightDirNew.x;
float y = lightDirNew.y;
float z = lightDirNew.z;
float w = lightDirNew.w;
if(lightDirOld.x != x || lightDirOld.y != y || lightDirOld.z != z || lightDirOld.w != w) {
lightDirOld.x = x;
lightDirOld.y = y;
lightDirOld.z = z;
lightDirOld.w = w;
_wglUniform4f(stateLightsVectorsArrayUniform4f[lightsCounter], x, y, z, w);
}
if(++lightsCounter >= stateLightsVectors.length) {
break;
}
}
}
if(stateLightsEnabled != lightsCounter) {
stateLightsEnabled = lightsCounter;
_wglUniform1i(stateLightsEnabledUniform1i, lightsCounter);
}
}
serial = GlStateManager.stateLightingAmbientSerial;
if(stateLightingAmbientSerial != serial) {
stateLightingAmbientSerial = serial;
float r = GlStateManager.stateLightingAmbientR;
float g = GlStateManager.stateLightingAmbientG;
float b = GlStateManager.stateLightingAmbientB;
if(stateLightingAmbientR != r || stateLightingAmbientG != g ||
stateLightingAmbientB != b) {
stateLightingAmbientR = r;
stateLightingAmbientG = g;
stateLightingAmbientB = b;
_wglUniform3f(stateLightingAmbientUniform3f, r, g, b);
}
}
if(!stateHasAttribNormal) {
serial = GlStateManager.stateNormalSerial;
if(stateNormalSerial != serial) {
stateNormalSerial = serial;
float x = GlStateManager.stateNormalX;
float y = GlStateManager.stateNormalY;
float z = GlStateManager.stateNormalZ;
float c = 1.0f / MathHelper.sqrt_float(x * x + y * y + z * z);
x *= c; y *= c; z *= c;
if(stateNormalX != x || stateNormalY != y || stateNormalZ != z) {
stateNormalX = x;
stateNormalY = y;
stateNormalZ = z;
_wglUniform3f(stateNormalUniform3f, x, y, z);
}
}
}
}
if(stateEnableFog) {
serial = GlStateManager.stateFogSerial;
if(stateFogSerial != serial) {
stateFogSerial = serial;
boolean fogEXP = GlStateManager.stateFogEXP;
float fogDensity = GlStateManager.stateFogDensity;
float fogStart = GlStateManager.stateFogStart;
float fogEnd = GlStateManager.stateFogEnd;
if(stateFogEXP != fogEXP || stateFogDensity != fogDensity ||
stateFogStart != fogStart || stateFogEnd != fogEnd) {
stateFogEXP = fogEXP;
stateFogDensity = fogDensity;
stateFogStart = fogStart;
stateFogEnd = fogEnd;
_wglUniform4f(stateFogParamUniform4f, fogEXP ? 1.0f : 0.0f, fogDensity, fogStart, fogEnd);
}
float r = GlStateManager.stateFogColorR;
float g = GlStateManager.stateFogColorG;
float b = GlStateManager.stateFogColorB;
float a = GlStateManager.stateFogColorA;
if(stateFogColorR != r || stateFogColorG != g ||
stateFogColorB != b || stateFogColorA != a) {
stateFogColorR = r;
stateFogColorG = g;
stateFogColorB = b;
stateFogColorA = a;
_wglUniform4f(stateFogColorUniform4f, r, g, b, a);
}
}
}
if(stateEnableAnisotropicFix) {
serial = GlStateManager.stateAnisotropicFixSerial;
if(stateAnisotropicFixSerial != serial) {
stateAnisotropicFixSerial = serial;
float w = GlStateManager.stateAnisotropicFixW;
float h = GlStateManager.stateAnisotropicFixH;
if(stateAnisotropicFixW != w || stateAnisotropicFixH != h) {
stateAnisotropicFixW = w;
stateAnisotropicFixH = h;
_wglUniform2f(stateAnisotropicFix2f, w, h);
}
}
}
if(stateEnableEndPortal) {
serial = GlStateManager.stateTexGenSerial;
if(stateTexGenSerial != serial) {
stateTexGenSerial = serial;
int planeS = GlStateManager.TexGen.S.plane;
int planeT = GlStateManager.TexGen.T.plane;
int planeR = GlStateManager.TexGen.R.plane;
int planeQ = GlStateManager.TexGen.Q.plane;
if(stateTexGenSPlane != planeS || stateTexGenTPlane != planeT ||
stateTexGenRPlane != planeR || stateTexGenQPlane != planeQ) {
stateTexGenSPlane = planeS;
stateTexGenTPlane = planeT;
stateTexGenRPlane = planeR;
stateTexGenQPlane = planeQ;
_wglUniform4i(stateTexGenPlaneUniform4i, planeS == GL_EYE_PLANE ? 1 : 0,
planeT == GL_EYE_PLANE ? 1 : 0, planeR == GL_EYE_PLANE ? 1 : 0,
planeQ == GL_EYE_PLANE ? 1 : 0);
}
Vector4f vecS = GlStateManager.TexGen.S.vector;
if (stateTexGenSVector.x != vecS.x || stateTexGenSVector.y != vecS.y ||
stateTexGenSVector.z != vecS.z || stateTexGenSVector.w != vecS.w) {
stateTexGenSVector.x = vecS.x;
stateTexGenSVector.y = vecS.y;
stateTexGenSVector.z = vecS.z;
stateTexGenSVector.w = vecS.w;
_wglUniform4f(stateTexGenSVectorUniform4f, vecS.x, vecS.y, vecS.z, vecS.w);
}
Vector4f vecT = GlStateManager.TexGen.T.vector;
if (stateTexGenTVector.x != vecT.x || stateTexGenTVector.y != vecT.y ||
stateTexGenTVector.z != vecT.z || stateTexGenTVector.w != vecT.w) {
stateTexGenTVector.x = vecT.x;
stateTexGenTVector.y = vecT.y;
stateTexGenTVector.z = vecT.z;
stateTexGenTVector.w = vecT.w;
_wglUniform4f(stateTexGenTVectorUniform4f, vecT.x, vecT.y, vecT.z, vecT.w);
}
Vector4f vecR = GlStateManager.TexGen.R.vector;
if (stateTexGenRVector.x != vecR.x || stateTexGenRVector.y != vecR.y ||
stateTexGenRVector.z != vecR.z || stateTexGenRVector.w != vecR.w) {
stateTexGenRVector.x = vecR.x;
stateTexGenRVector.y = vecR.y;
stateTexGenRVector.z = vecR.z;
stateTexGenRVector.w = vecR.w;
_wglUniform4f(stateTexGenRVectorUniform4f, vecR.x, vecR.y, vecR.z, vecR.w);
}
Vector4f vecQ = GlStateManager.TexGen.Q.vector;
if (stateTexGenQVector.x != vecQ.x || stateTexGenQVector.y != vecQ.y ||
stateTexGenQVector.z != vecQ.z || stateTexGenQVector.w != vecQ.w) {
stateTexGenQVector.x = vecQ.x;
stateTexGenQVector.y = vecQ.y;
stateTexGenQVector.z = vecQ.z;
stateTexGenQVector.w = vecQ.w;
_wglUniform4f(stateTexGenQVectorUniform4f, vecQ.x, vecQ.y, vecQ.z, vecQ.w);
}
}
}
if(stateEnableBlendAdd) {
serial = GlStateManager.stateShaderBlendColorSerial;
if(stateShaderBlendColorSerial != serial) {
stateShaderBlendColorSerial = serial;
float r = GlStateManager.stateShaderBlendSrcColorR;
float g = GlStateManager.stateShaderBlendSrcColorG;
float b = GlStateManager.stateShaderBlendSrcColorB;
float a = GlStateManager.stateShaderBlendSrcColorA;
if(stateShaderBlendSrcColorR != r || stateShaderBlendSrcColorG != g ||
stateShaderBlendSrcColorB != b || stateShaderBlendSrcColorA != a) {
_wglUniform4f(stateShaderBlendSrcColorUniform4f, r, g, b, a);
stateShaderBlendSrcColorR = r;
stateShaderBlendSrcColorG = g;
stateShaderBlendSrcColorB = b;
stateShaderBlendSrcColorA = a;
}
r = GlStateManager.stateShaderBlendAddColorR;
g = GlStateManager.stateShaderBlendAddColorG;
b = GlStateManager.stateShaderBlendAddColorB;
a = GlStateManager.stateShaderBlendAddColorA;
if(stateShaderBlendAddColorR != r || stateShaderBlendAddColorG != g ||
stateShaderBlendAddColorB != b || stateShaderBlendAddColorA != a) {
_wglUniform4f(stateShaderBlendAddColorUniform4f, r, g, b, a);
stateShaderBlendAddColorR = r;
stateShaderBlendAddColorG = g;
stateShaderBlendAddColorB = b;
stateShaderBlendAddColorA = a;
}
}
}
return this;
}
public static void flushCache() {
shaderSourceCacheVSH = null;
shaderSourceCacheFSH = null;
for(int i = 0; i < pipelineStateCache.length; ++i) {
if(pipelineStateCache[i] != null) {
pipelineStateCache[i].destroy();
pipelineStateCache[i] = null;
}
}
}
public void destroy() {
PlatformOpenGL._wglDeleteProgram(shaderProgram);
PlatformOpenGL._wglDeleteVertexArrays(vertexArray);
PlatformOpenGL._wglDeleteBuffers(vertexBuffer);
}
public IBufferArrayGL getDirectModeBufferArray() {
return vertexArray;
}
}

View File

@ -0,0 +1,78 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
class FixedFunctionShader {
class FixedFunctionConstants {
static final String VERSION = "#version 300 es";
static final String FILENAME_VSH = "/assets/eagler/glsl/core.vsh";
static final String FILENAME_FSH = "/assets/eagler/glsl/core.fsh";
static final String PRECISION_INT = "lowp";
static final String PRECISION_FLOAT = "highp";
static final String PRECISION_SAMPLER = "lowp";
static final String MACRO_ATTRIB_TEXTURE = "COMPILE_TEXTURE_ATTRIB";
static final String MACRO_ATTRIB_COLOR = "COMPILE_COLOR_ATTRIB";
static final String MACRO_ATTRIB_NORMAL = "COMPILE_NORMAL_ATTRIB";
static final String MACRO_ATTRIB_LIGHTMAP = "COMPILE_LIGHTMAP_ATTRIB";
static final String MACRO_ENABLE_TEXTURE2D = "COMPILE_ENABLE_TEXTURE2D";
static final String MACRO_ENABLE_LIGHTMAP = "COMPILE_ENABLE_LIGHTMAP";
static final String MACRO_ENABLE_ALPHA_TEST = "COMPILE_ENABLE_ALPHA_TEST";
static final String MACRO_ENABLE_MC_LIGHTING = "COMPILE_ENABLE_MC_LIGHTING";
static final String MACRO_ENABLE_END_PORTAL = "COMPILE_ENABLE_TEX_GEN";
static final String MACRO_ENABLE_ANISOTROPIC_FIX = "COMPILE_ENABLE_ANISOTROPIC_FIX";
static final String MACRO_ENABLE_FOG = "COMPILE_ENABLE_FOG";
static final String MACRO_ENABLE_BLEND_ADD = "COMPILE_BLEND_ADD";
static final String ATTRIB_POSITION = "a_position3f";
static final String ATTRIB_TEXTURE = "a_texture2f";
static final String ATTRIB_COLOR = "a_color4f";
static final String ATTRIB_NORMAL = "a_normal4f";
static final String ATTRIB_LIGHTMAP = "a_lightmap2f";
static final String UNIFORM_COLOR_NAME = "u_color4f";
static final String UNIFORM_BLEND_SRC_COLOR_NAME = "u_colorBlendSrc4f";
static final String UNIFORM_BLEND_ADD_COLOR_NAME = "u_colorBlendAdd4f";
static final String UNIFORM_ALPHA_TEST_NAME = "u_alphaTestRef1f";
static final String UNIFORM_LIGHTS_ENABLED_NAME = "u_lightsEnabled1i";
static final String UNIFORM_LIGHTS_VECTORS_NAME = "u_lightsDirections4fv";
static final String UNIFORM_LIGHTS_AMBIENT_NAME = "u_lightsAmbient3f";
static final String UNIFORM_CONSTANT_NORMAL_NAME = "u_uniformNormal3f";
static final String UNIFORM_FOG_PARAM_NAME = "u_fogParameters4f";
static final String UNIFORM_FOG_COLOR_NAME = "u_fogColor4f";
static final String UNIFORM_TEX_GEN_S_NAME = "u_texGenS4f";
static final String UNIFORM_TEX_GEN_T_NAME = "u_texGenT4f";
static final String UNIFORM_TEX_GEN_R_NAME = "u_texGenR4f";
static final String UNIFORM_TEX_GEN_Q_NAME = "u_texGenQ4f";
static final String UNIFORM_MODEL_MATRIX_NAME = "u_modelviewMat4f";
static final String UNIFORM_TEX_GEN_PLANE_NAME = "u_texGenPlane4i";
static final String UNIFORM_PROJECTION_MATRIX_NAME = "u_projectionMat4f";
static final String UNIFORM_TEXTURE_COORDS_01_NAME = "u_textureCoords01";
static final String UNIFORM_TEXTURE_MATRIX_01_NAME = "u_textureMat4f01";
static final String UNIFORM_TEXTURE_COORDS_02_NAME = "u_textureCoords02";
static final String UNIFORM_TEXTURE_MATRIX_02_NAME = "u_textureMat4f02";
static final String UNIFORM_TEXTURE_ANISOTROPIC_FIX = "u_textureAnisotropicFix";
static final String UNIFORM_TEXTURE_UNIT_01_NAME = "u_samplerTexture";
static final String UNIFORM_TEXTURE_UNIT_02_NAME = "u_samplerLightmap";
static final String OUTPUT_COLOR = "output4f";
}
}

View File

@ -0,0 +1,964 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
import net.lax1dude.eaglercraft.v1_8.vector.Vector3f;
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class GlStateManager {
static final Logger logger = LogManager.getLogger("GlStateManager");
static boolean stateDepthTest = false;
static int stateDepthFunc = -1;
static boolean stateDepthMask = true;
static boolean stateCull = false;
static int stateCullFace = GL_BACK;
static boolean statePolygonOffset = false;
static float statePolygonOffsetFactor = 0.0f;
static float statePolygonOffsetUnits = 0.0f;
static float stateColorR = 1.0f;
static float stateColorG = 1.0f;
static float stateColorB = 1.0f;
static float stateColorA = 1.0f;
static int stateColorSerial = 0;
static float stateShaderBlendSrcColorR = 1.0f;
static float stateShaderBlendSrcColorG = 1.0f;
static float stateShaderBlendSrcColorB = 1.0f;
static float stateShaderBlendSrcColorA = 1.0f;
static float stateShaderBlendAddColorR = 0.0f;
static float stateShaderBlendAddColorG = 0.0f;
static float stateShaderBlendAddColorB = 0.0f;
static float stateShaderBlendAddColorA = 0.0f;
static int stateShaderBlendColorSerial = 0;
static boolean stateEnableShaderBlendColor = false;
static boolean stateBlend = false;
static int stateBlendEquation = -1;
static int stateBlendSRC = -1;
static int stateBlendDST = -1;
static boolean stateAlphaTest = false;
static float stateAlphaTestRef = 0.1f;
static boolean stateMaterial = false;
static boolean stateLighting = false;
static int stateLightsStackPointer = 0;
static final boolean[][] stateLightsEnabled = new boolean[4][8];
static final Vector4f[][] stateLightsStack = new Vector4f[4][8];
static final int[] stateLightingSerial = new int[4];
static float stateLightingAmbientR = 0.0f;
static float stateLightingAmbientG = 0.0f;
static float stateLightingAmbientB = 0.0f;
static int stateLightingAmbientSerial = 0;
static float stateNormalX = 0.0f;
static float stateNormalY = 0.0f;
static float stateNormalZ = -1.0f;
static int stateNormalSerial = 0;
static boolean stateFog = false;
static boolean stateFogEXP = false;
static float stateFogDensity = 1.0f;
static float stateFogStart = 0.0f;
static float stateFogEnd = 1.0f;
static float stateFogColorR = 1.0f;
static float stateFogColorG = 1.0f;
static float stateFogColorB = 1.0f;
static float stateFogColorA = 1.0f;
static int stateFogSerial = 0;
static int activeTexture = 0;
static final boolean[] stateTexture = new boolean[16];
static final int[] boundTexture = new int[] {
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1
};
static float stateAnisotropicFixW = -999.0f;
static float stateAnisotropicFixH = -999.0f;
static int stateAnisotropicFixSerial = 0;
static boolean stateTexGen = false;
static int viewportX = -1;
static int viewportY = -1;
static int viewportW = -1;
static int viewportH = -1;
static int colorMaskBits = 15;
static float clearColorR = 0.0f;
static float clearColorG = 0.0f;
static float clearColorB = 0.0f;
static float clearColorA = 1.0f;
static float clearDepth = -999.0f;
public static enum TexGen {
S, T, R, Q;
int source = GL_OBJECT_LINEAR;
int plane = GL_OBJECT_PLANE;
Vector4f vector = new Vector4f();
}
static int stateTexGenSerial = 0;
static int stateMatrixMode = GL_MODELVIEW;
static final Matrix4f[] modelMatrixStack = new Matrix4f[48];
static final int[] modelMatrixStackAccessSerial = new int[48];
private static int modelMatrixAccessSerial = 0;
static int modelMatrixStackPointer = 0;
static final Matrix4f[] projectionMatrixStack = new Matrix4f[8];
static final int[] projectionMatrixStackAccessSerial = new int[8];
private static int projectionMatrixAccessSerial = 0;
static int projectionMatrixStackPointer = 0;
static final float[] textureCoordsX = new float[8];
static final float[] textureCoordsY = new float[8];
static final int[] textureCoordsAccessSerial = new int[8];
static final Matrix4f[][] textureMatrixStack = new Matrix4f[8][8];
static final int[][] textureMatrixStackAccessSerial = new int[8][8];
static int[] textureMatrixAccessSerial = new int[8];
static int[] textureMatrixStackPointer = new int[8];
private static final Matrix4f tmpInvertedMatrix = new Matrix4f();
static {
populateStack(modelMatrixStack);
populateStack(projectionMatrixStack);
populateStack(textureMatrixStack);
populateStack(stateLightsStack);
}
static void populateStack(Matrix4f[] stack) {
for(int i = 0; i < stack.length; ++i) {
stack[i] = new Matrix4f();
}
}
static void populateStack(Matrix4f[][] stack) {
for(int i = 0; i < stack.length; ++i) {
populateStack(stack[i]);
}
}
static void populateStack(Vector4f[][] stack) {
for(int i = 0; i < stack.length; ++i) {
for(int j = 0; j < stack[i].length; ++j) {
stack[i][j] = new Vector4f(0.0f, -1.0f, 0.0f, 0.0f);
}
}
}
public static final void pushLightCoords() {
int push = stateLightsStackPointer + 1;
if(push < stateLightsStack.length) {
Vector4f[] copyFrom = stateLightsStack[stateLightsStackPointer];
boolean[] copyFrom2 = stateLightsEnabled[stateLightsStackPointer];
Vector4f[] copyTo = stateLightsStack[push];
boolean[] copyTo2 = stateLightsEnabled[push];
for(int i = 0; i < copyFrom.length; ++i) {
if(copyFrom2[i]) {
copyTo[i].set(copyFrom[i]);
copyTo2[i] = true;
}else {
copyTo2[i] = false;
}
}
stateLightingSerial[push] = stateLightingSerial[stateLightsStackPointer];
stateLightsStackPointer = push;
}else {
Throwable t = new IndexOutOfBoundsException("GL_LIGHT direction stack overflow!" +
" Exceeded " + stateLightsStack.length + " calls to GlStateManager.pushLightCoords");
logger.error(t);
}
}
public static final void popLightCoords() {
if(stateLightsStackPointer > 0) {
--stateLightsStackPointer;
}else {
Throwable t = new IndexOutOfBoundsException("GL_LIGHT direction stack underflow!" +
" Called GlStateManager.popLightCoords on an empty light stack");
logger.error(t);
}
}
public static final void disableAlpha() {
stateAlphaTest = false;
}
public static final void enableAlpha() {
stateAlphaTest = true;
}
public static final void alphaFunc(int func, float ref) {
if(func != GL_GREATER) {
throw new UnsupportedOperationException("Only GL_GREATER alphaFunc is supported");
}else {
stateAlphaTestRef = ref;
}
}
public static final void enableLighting() {
stateLighting = true;
}
public static final void disableLighting() {
stateLighting = false;
}
private static final Vector4f paramVector4 = new Vector4f();
public static final void enableMCLight(int light, float diffuse, double dirX,
double dirY, double dirZ, double dirW) {
paramVector4.x = (float)dirX;
paramVector4.y = (float)dirY;
paramVector4.z = (float)dirZ;
paramVector4.w = (float)dirW;
Matrix4f.transform(modelMatrixStack[modelMatrixStackPointer], paramVector4, paramVector4);
paramVector4.normalise();
Vector4f dest = stateLightsStack[stateLightsStackPointer][light];
dest.x = paramVector4.x;
dest.y = paramVector4.y;
dest.z = paramVector4.z;
dest.w = diffuse;
stateLightsEnabled[stateLightsStackPointer][light] = true;
++stateLightingSerial[stateLightsStackPointer];
}
public static final void disableMCLight(int light) {
stateLightsEnabled[stateLightsStackPointer][light] = false;
++stateLightingSerial[stateLightsStackPointer];
}
public static final void setMCLightAmbient(float r, float g, float b) {
stateLightingAmbientR = r;
stateLightingAmbientG = g;
stateLightingAmbientB = b;
++stateLightingAmbientSerial;
}
public static final void enableColorMaterial() {
stateMaterial = true;
}
public static final void disableColorMaterial() {
stateMaterial = false;
}
public static final void disableDepth() {
if(stateDepthTest) {
_wglDisable(GL_DEPTH_TEST);
stateDepthTest = false;
}
}
public static final void enableDepth() {
if(!stateDepthTest) {
_wglEnable(GL_DEPTH_TEST);
stateDepthTest = true;
}
}
public static final void depthFunc(int depthFunc) {
int rev = depthFunc;
switch(depthFunc) {
case GL_GREATER:
rev = GL_LESS;
break;
case GL_GEQUAL:
rev = GL_LEQUAL;
break;
case GL_EQUAL:
rev = GL_EQUAL;
break;
case GL_LEQUAL:
rev = GL_GEQUAL;
break;
case GL_LESS:
rev = GL_GREATER;
break;
}
if(rev != stateDepthFunc) {
_wglDepthFunc(rev);
stateDepthFunc = rev;
}
}
public static final void depthMask(boolean flagIn) {
if(flagIn != stateDepthMask) {
_wglDepthMask(flagIn);
stateDepthMask = flagIn;
}
}
public static final void disableBlend() {
if(stateBlend) {
_wglDisable(GL_BLEND);
stateBlend = false;
}
}
public static final void enableBlend() {
if(!stateBlend) {
_wglEnable(GL_BLEND);
stateBlend = true;
}
}
public static final void blendFunc(int srcFactor, int dstFactor) {
int srcBits = (srcFactor | (srcFactor << 16));
int dstBits = (dstFactor | (dstFactor << 16));
if(srcBits != stateBlendSRC || dstBits != stateBlendDST) {
_wglBlendFunc(srcFactor, dstFactor);
stateBlendSRC = srcBits;
stateBlendDST = dstBits;
}
}
public static final void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) {
int srcBits = (srcFactor | (srcFactorAlpha << 16));
int dstBits = (dstFactor | (dstFactorAlpha << 16));
if(srcBits != stateBlendSRC || dstBits != stateBlendDST) {
_wglBlendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
stateBlendSRC = srcBits;
stateBlendDST = dstBits;
}
}
public static final void setShaderBlendSrc(float r, float g, float b, float a) {
stateShaderBlendSrcColorR = r;
stateShaderBlendSrcColorG = g;
stateShaderBlendSrcColorB = b;
stateShaderBlendSrcColorA = a;
++stateShaderBlendColorSerial;
}
public static final void setShaderBlendAdd(float r, float g, float b, float a) {
stateShaderBlendAddColorR = r;
stateShaderBlendAddColorG = g;
stateShaderBlendAddColorB = b;
stateShaderBlendAddColorA = a;
++stateShaderBlendColorSerial;
}
public static final void enableShaderBlendAdd() {
stateEnableShaderBlendColor = true;
}
public static final void disableShaderBlendAdd() {
stateEnableShaderBlendColor = false;
}
public static final void enableFog() {
stateFog = true;
}
public static final void disableFog() {
stateFog = false;
}
public static final void setFog(int param) {
stateFogEXP = param == GL_EXP;
++stateFogSerial;
}
public static final void setFogDensity(float param) {
stateFogDensity = param;
++stateFogSerial;
}
public static final void setFogStart(float param) {
stateFogStart = param;
++stateFogSerial;
}
public static final void setFogEnd(float param) {
stateFogEnd = param;
++stateFogSerial;
}
public static final void enableCull() {
if(!stateCull) {
_wglEnable(GL_CULL_FACE);
stateCull = true;
}
}
public static final void disableCull() {
if(stateCull) {
_wglDisable(GL_CULL_FACE);
stateCull = false;
}
}
public static final void cullFace(int mode) {
if(stateCullFace != mode) {
_wglCullFace(mode);
stateCullFace = mode;
}
}
public static final void enablePolygonOffset() {
if(!statePolygonOffset) {
_wglEnable(GL_POLYGON_OFFSET_FILL);
statePolygonOffset = true;
}
}
public static final void disablePolygonOffset() {
if(statePolygonOffset) {
_wglDisable(GL_POLYGON_OFFSET_FILL);
statePolygonOffset = false;
}
}
public static final void doPolygonOffset(float factor, float units) {
if(factor != statePolygonOffsetFactor || units != statePolygonOffsetUnits) {
_wglPolygonOffset(-factor, units);
statePolygonOffsetFactor = factor;
statePolygonOffsetUnits = units;
}
}
public static final void enableColorLogic() {
System.err.println("TODO: rewrite text field cursor to use blending");
}
public static final void disableColorLogic() {
}
public static final void colorLogicOp(int opcode) {
}
public static final void enableTexGen() {
stateTexGen = true;
}
public static final void disableTexGen() {
stateTexGen = false;
}
public static final void texGen(GlStateManager.TexGen coord, int source) {
coord.source = source;
++stateTexGenSerial;
}
public static final void func_179105_a(GlStateManager.TexGen coord, int plane, FloatBuffer vector) {
coord.plane = plane;
coord.vector.load(vector);
if(plane == GL_EYE_PLANE) {
tmpInvertedMatrix.load(GlStateManager.modelMatrixStack[GlStateManager.modelMatrixStackPointer]).invert().transpose();
Matrix4f.transform(tmpInvertedMatrix, coord.vector, coord.vector);
}
++stateTexGenSerial;
}
public static final void setActiveTexture(int texture) {
int textureIdx = texture - GL_TEXTURE0;
if(textureIdx != activeTexture) {
_wglActiveTexture(texture);
activeTexture = textureIdx;
}
}
public static final void enableTexture2D() {
stateTexture[activeTexture] = true;
}
public static final void disableTexture2D() {
stateTexture[activeTexture] = false;
}
public static final void texCoords2D(float x, float y) {
textureCoordsX[activeTexture] = x;
textureCoordsY[activeTexture] = y;
++textureCoordsAccessSerial[activeTexture];
}
public static final int generateTexture() {
return EaglercraftGPU.mapTexturesGL.register(_wglGenTextures());
}
public static final void deleteTexture(int texture) {
_wglDeleteTextures(EaglercraftGPU.mapTexturesGL.free(texture));
}
public static final void bindTexture(int texture) {
if(texture != boundTexture[activeTexture]) {
_wglBindTexture(GL_TEXTURE_2D, EaglercraftGPU.mapTexturesGL.get(texture));
boundTexture[activeTexture] = texture;
}
}
public static final int getTextureBound() {
return boundTexture[activeTexture];
}
public static final void shadeModel(int mode) {
}
public static final void enableRescaleNormal() {
// still not sure what this is for
}
public static final void disableRescaleNormal() {
}
public static final void viewport(int x, int y, int w, int h) {
if(viewportX != x || viewportY != y || viewportW != w || viewportH != h) {
_wglViewport(x, y, w, h);
viewportX = x;
viewportY = y;
viewportW = w;
viewportH = h;
}
}
public static final void colorMask(boolean red, boolean green, boolean blue, boolean alpha) {
int bits = (red ? 1 : 0) | (green ? 2 : 0) | (blue ? 4 : 0) | (alpha ? 8 : 0);
if(bits != colorMaskBits) {
_wglColorMask(red, green, blue, alpha);
colorMaskBits = bits;
}
}
public static final void clearDepth(float depth) {
depth = 1.0f - depth;
if(depth != clearDepth) {
_wglClearDepth(depth);
clearDepth = depth;
}
}
public static final void clearColor(float red, float green, float blue, float alpha) {
if(red != clearColorR || green != clearColorG || blue != clearColorB || alpha != clearColorA) {
_wglClearColor(red, green, blue, alpha);
clearColorR = red;
clearColorG = green;
clearColorB = blue;
clearColorA = alpha;
}
}
public static final void clear(int mask) {
_wglClear(mask);
}
public static final void matrixMode(int mode) {
stateMatrixMode = mode;
}
public static final void loadIdentity() {
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
modelMatrixStack[modelMatrixStackPointer].setIdentity();
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
projectionMatrixStack[projectionMatrixStackPointer].setIdentity();
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
textureMatrixStack[activeTexture][textureMatrixStackPointer[activeTexture]].setIdentity();
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
}
public static final void pushMatrix() {
int push;
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
push = modelMatrixStackPointer + 1;
if(push < modelMatrixStack.length) {
modelMatrixStack[push].load(modelMatrixStack[modelMatrixStackPointer]);
modelMatrixStackAccessSerial[push] = modelMatrixStackAccessSerial[modelMatrixStackPointer];
modelMatrixStackPointer = push;
}else {
Throwable t = new IndexOutOfBoundsException("GL_MODELVIEW matrix stack overflow!" +
" Exceeded " + modelMatrixStack.length + " calls to GlStateManager.pushMatrix");
logger.error(t);
}
break;
case GL_PROJECTION:
push = projectionMatrixStackPointer + 1;
if(push < projectionMatrixStack.length) {
projectionMatrixStack[push].load(projectionMatrixStack[projectionMatrixStackPointer]);
projectionMatrixStackAccessSerial[push] = projectionMatrixStackAccessSerial[projectionMatrixStackPointer];
projectionMatrixStackPointer = push;
}else {
Throwable t = new IndexOutOfBoundsException("GL_PROJECTION matrix stack overflow!" +
" Exceeded " + projectionMatrixStack.length + " calls to GlStateManager.pushMatrix");
logger.error(t);
}
break;
case GL_TEXTURE:
push = textureMatrixStackPointer[activeTexture] + 1;
if(push < textureMatrixStack.length) {
int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][push].load(textureMatrixStack[activeTexture][ptr]);
textureMatrixStackAccessSerial[activeTexture][push] = textureMatrixStackAccessSerial[activeTexture][ptr];
textureMatrixStackPointer[activeTexture] = push;
}else {
Throwable t = new IndexOutOfBoundsException("GL_TEXTURE #" + activeTexture + " matrix stack overflow!" +
" Exceeded " + textureMatrixStack.length + " calls to GlStateManager.pushMatrix");
logger.error(t);
}
break;
}
}
public static final void popMatrix() {
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
if(modelMatrixStackPointer > 0) {
--modelMatrixStackPointer;
}else {
Throwable t = new IndexOutOfBoundsException("GL_MODELVIEW matrix stack underflow!" +
" Called GlStateManager.popMatrix on an empty matrix stack");
logger.error(t);
}
break;
case GL_PROJECTION:
if(projectionMatrixStackPointer > 0) {
--projectionMatrixStackPointer;
}else {
Throwable t = new IndexOutOfBoundsException("GL_PROJECTION matrix stack underflow!" +
" Called GlStateManager.popMatrix on an empty matrix stack");
logger.error(t);
}
break;
case GL_TEXTURE:
if(textureMatrixStackPointer[activeTexture] > 0) {
--textureMatrixStackPointer[activeTexture];
}else {
Throwable t = new IndexOutOfBoundsException("GL_TEXTURE #" + activeTexture +
" matrix stack underflow! Called GlStateManager.popMatrix on an empty matrix stack");
logger.error(t);
}
break;
}
}
public static final void getFloat(int pname, float[] params) {
switch(pname) {
case GL_MODELVIEW_MATRIX:
modelMatrixStack[modelMatrixStackPointer].store(params);
break;
case GL_PROJECTION_MATRIX:
projectionMatrixStack[projectionMatrixStackPointer].store(params);
break;
case GL_TEXTURE_MATRIX:
textureMatrixStack[activeTexture][textureMatrixStackPointer[activeTexture]].store(params);
break;
default:
throw new UnsupportedOperationException("glGetFloat can only be used to retrieve matricies!");
}
}
public static final void ortho(double left, double right, double bottom, double top, double zNear, double zFar) {
Matrix4f matrix;
switch(stateMatrixMode) {
case GL_MODELVIEW:
matrix = modelMatrixStack[modelMatrixStackPointer];
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
default:
matrix = projectionMatrixStack[projectionMatrixStackPointer];
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
matrix = textureMatrixStack[activeTexture][ptr];
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
matrix.m00 = 2.0f / (float)(right - left);
matrix.m01 = 0.0f;
matrix.m02 = 0.0f;
matrix.m03 = 0.0f;
matrix.m10 = 0.0f;
matrix.m11 = 2.0f / (float)(top - bottom);
matrix.m12 = 0.0f;
matrix.m13 = 0.0f;
matrix.m20 = 0.0f;
matrix.m21 = 0.0f;
matrix.m22 = 2.0f / (float)(zFar - zNear);
matrix.m23 = 0.0f;
matrix.m30 = (float)(-(right + left) / (right - left));
matrix.m31 = (float)(-(top + bottom) / (top - bottom));
matrix.m32 = (float)((zFar + zNear) / (zFar - zNear));
matrix.m33 = 1.0f;
}
private static final Vector3f paramVector = new Vector3f();
private static final float toRad = 0.0174532925f;
public static final void rotate(float angle, float x, float y, float z) {
paramVector.x = x;
paramVector.y = y;
paramVector.z = z;
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
modelMatrixStack[modelMatrixStackPointer].rotate(angle * toRad, paramVector);
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
projectionMatrixStack[projectionMatrixStackPointer].rotate(angle * toRad, paramVector);
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].rotate(angle * toRad, paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
}
public static final void scale(float x, float y, float z) {
paramVector.x = x;
paramVector.y = y;
paramVector.z = z;
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
modelMatrixStack[modelMatrixStackPointer].scale(paramVector);
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
projectionMatrixStack[projectionMatrixStackPointer].scale(paramVector);
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].scale(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
}
public static final void scale(double x, double y, double z) {
paramVector.x = (float)x;
paramVector.y = (float)y;
paramVector.z = (float)z;
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
modelMatrixStack[modelMatrixStackPointer].scale(paramVector);
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
projectionMatrixStack[projectionMatrixStackPointer].scale(paramVector);
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].scale(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
}
public static final void translate(float x, float y, float z) {
paramVector.x = x;
paramVector.y = y;
paramVector.z = z;
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
modelMatrixStack[modelMatrixStackPointer].translate(paramVector);
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
projectionMatrixStack[projectionMatrixStackPointer].translate(paramVector);
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].translate(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
}
public static final void translate(double x, double y, double z) {
paramVector.x = (float)x;
paramVector.y = (float)y;
paramVector.z = (float)z;
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
modelMatrixStack[modelMatrixStackPointer].translate(paramVector);
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
projectionMatrixStack[projectionMatrixStackPointer].translate(paramVector);
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].translate(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
}
private static final Matrix4f paramMatrix = new Matrix4f();
public static final void multMatrix(float[] matrix) {
Matrix4f modeMatrix;
switch(stateMatrixMode) {
case GL_MODELVIEW:
default:
modeMatrix = modelMatrixStack[modelMatrixStackPointer];
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
modeMatrix = projectionMatrixStack[projectionMatrixStackPointer];
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
modeMatrix = textureMatrixStack[activeTexture][ptr];
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
paramMatrix.load(matrix);
Matrix4f.mul(modeMatrix, paramMatrix, modeMatrix);
}
public static final void color(float colorRed, float colorGreen, float colorBlue, float colorAlpha) {
stateColorR = colorRed;
stateColorG = colorGreen;
stateColorB = colorBlue;
stateColorA = colorAlpha;
++stateColorSerial;
}
public static final void color(float colorRed, float colorGreen, float colorBlue) {
stateColorR = colorRed;
stateColorG = colorGreen;
stateColorB = colorBlue;
stateColorA = 1.0f;
++stateColorSerial;
}
public static final void resetColor() {
stateColorR = 1.0f;
stateColorG = 1.0f;
stateColorB = 1.0f;
stateColorA = 1.0f;
++stateColorSerial;
}
public static final void callList(int list) {
EaglercraftGPU.glCallList(list);
}
public static final void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
Matrix4f matrix;
switch(stateMatrixMode) {
case GL_MODELVIEW:
matrix = modelMatrixStack[modelMatrixStackPointer];
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
break;
case GL_PROJECTION:
default:
matrix = projectionMatrixStack[projectionMatrixStackPointer];
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
break;
case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture];
matrix = textureMatrixStack[activeTexture][ptr];
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break;
}
float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f);
matrix.m00 = cotangent / aspect;
matrix.m01 = 0.0f;
matrix.m02 = 0.0f;
matrix.m03 = 0.0f;
matrix.m10 = 0.0f;
matrix.m11 = cotangent;
matrix.m12 = 0.0f;
matrix.m13 = 0.0f;
matrix.m20 = 0.0f;
matrix.m21 = 0.0f;
matrix.m22 = (zFar + zNear) / (zFar - zNear);
matrix.m23 = -1.0f;
matrix.m30 = 0.0f;
matrix.m31 = 0.0f;
matrix.m32 = 2.0f * zFar * zNear / (zFar - zNear);
matrix.m33 = 0.0f;
}
private static final Matrix4f unprojA = new Matrix4f();
private static final Matrix4f unprojB = new Matrix4f();
private static final Vector4f unprojC = new Vector4f();
public static final void gluUnProject(float p1, float p2, float p3, float[] modelview, float[] projection,
int[] viewport, float[] objectcoords) {
unprojA.load(modelview);
unprojB.load(projection);
Matrix4f.mul(unprojA, unprojB, unprojB);
unprojB.invert();
unprojC.set(((p1 - (float)viewport[0]) / (float)viewport[2]) * 2f - 1f,
((p2 - (float)viewport[1]) / (float)viewport[3]) * 2f - 1f, p3, 1.0f);
Matrix4f.transform(unprojB, unprojC, unprojC);
objectcoords[0] = unprojC.x / unprojC.w;
objectcoords[1] = unprojC.y / unprojC.w;
objectcoords[2] = unprojC.z / unprojC.w;
}
public static void recompileShaders() {
FixedFunctionPipeline.flushCache();
}
}

View File

@ -0,0 +1,136 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import java.io.InputStream;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformAssets;
public class ImageData {
public final int width;
public final int height;
public final int[] pixels;
public final boolean alpha;
public ImageData(int width, int height, int[] pixels, boolean alpha) {
this.width = width;
this.height = height;
this.pixels = pixels;
this.alpha = alpha;
}
public ImageData(int width, int height, boolean alpha) {
this.width = width;
this.height = height;
this.pixels = new int[width * height];
this.alpha = alpha;
}
public ImageData fillAlpha() {
for(int i = 0; i < pixels.length; ++i) {
pixels[i] = pixels[i] | 0xFF000000;
}
return this;
}
public ImageData getSubImage(int x, int y, int pw, int ph) {
int[] img = new int[pw * ph];
for(int i = 0; i < ph; ++i) {
System.arraycopy(pixels, (i + y) * this.width + x, img, i * pw, pw);
}
return new ImageData(pw, ph, img, alpha);
}
public static final ImageData loadImageFile(String path) {
byte[] fileData = EagRuntime.getResourceBytes(path);
if(fileData != null) {
return loadImageFile(fileData);
}else {
return null;
}
}
public static final ImageData loadImageFile(InputStream data) {
return PlatformAssets.loadImageFile(data);
}
public static final ImageData loadImageFile(byte[] data) {
return PlatformAssets.loadImageFile(data);
}
public void getRGB(int startX, int startY, int w, int h,
int[] rgbArray, int offset, int scansize) {
for(int y = 0; y < h; ++y) {
System.arraycopy(pixels, offset + (y + startY) * scansize + startX, rgbArray, y * w, w);
}
}
public void copyPixelsFrom(ImageData input, int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2) {
if(sx2 - sx1 != dx2 - dx1) {
throw new IllegalArgumentException("Width of the copied region must match the"
+ "width of the pasted region");
}
int cw = sx2 - sx1;
if(sy2 - sy1 != dy2 - dy1) {
throw new IllegalArgumentException("Height of the copied region must match the"
+ "height of the pasted region");
}
int ch = sy2 - sy1;
for(int y = 0; y < ch; ++y) {
System.arraycopy(input.pixels, sx1 + (sy1 + y) * cw, pixels, dx1 + (dy1 + y) * cw, cw);
}
}
public void drawLayer(ImageData input, int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2) {
if(sx2 - sx1 != dx2 - dx1) {
throw new IllegalArgumentException("Width of the copied region must match the"
+ "width of the pasted region");
}
int cw = sx2 - sx1;
if(sy2 - sy1 != dy2 - dy1) {
throw new IllegalArgumentException("Height of the copied region must match the"
+ "height of the pasted region");
}
int ch = sy2 - sy1;
for(int y = 0; y < ch; ++y) {
for(int x = 0; x < cw; ++x) {
int si = (sy1 + y) * cw + sx1 + x;
int di = (dy1 + y) * cw + dx1 + x;
int spx = input.pixels[si];
int dpx = pixels[di];
if((spx & 0xFF000000) == 0xFF000000 || (dpx & 0xFF000000) == 0) {
pixels[di] = spx;
}else {
int sa = (spx >> 24) & 0xFF;
int da = (dpx >> 24) & 0xFF;
int r = ((spx >> 16) & 0xFF) * sa / 255;
int g = ((spx >> 8) & 0xFF) * sa / 255;
int b = (spx & 0xFF) * sa / 255;
int aa = (255 - sa) * da;
r += ((dpx >> 16) & 0xFF) * aa / 65025;
g += ((dpx >> 8) & 0xFF) * aa / 65025;
b += (dpx & 0xFF) * aa / 65025;
sa += da;
if(sa > 0xFF) sa = 0xFF;
pixels[di] = ((sa) << 24) | (r << 16) | (g << 8) | b;
}
}
}
}
public ImageData swapRB() {
for(int i = 0; i < pixels.length; ++i) {
int j = pixels[i];
pixels[i] = (j & 0xFF00FF00) | ((j & 0x00FF0000) >> 16) |
((j & 0x000000FF) << 16);
}
return this;
}
public static int swapRB(int c) {
return (c & 0xFF00FF00) | ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16);
}
}

View File

@ -0,0 +1,460 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class InstancedFontRenderer {
private static final Logger logger = LogManager.getLogger("InstancedFontRenderer");
public static final String vertexShaderPath = "/assets/eagler/glsl/accel_font.vsh";
public static final String fragmentShaderPath = "/assets/eagler/glsl/accel_font.fsh";
private static final int BYTES_PER_CHARACTER = 10;
private static final int CHARACTER_LIMIT = 6553;
private static IProgramGL shaderProgram = null;
private static IUniformGL u_matrixTransform = null;
private static FloatBuffer matrixCopyBuffer = null;
private static IUniformGL u_charSize2f = null;
private static IUniformGL u_charCoordSize2f = null;
private static IUniformGL u_color4f = null;
private static IUniformGL u_colorBias4f = null;
private static IBufferArrayGL vertexArray = null;
private static IBufferGL vertexBuffer = null;
private static IBufferGL instancesBuffer = null;
private static float stateColorR = -999.0f;
private static float stateColorG = -999.0f;
private static float stateColorB = -999.0f;
private static float stateColorA = -999.0f;
private static int stateColorSerial = -1;
private static float stateColorBiasR = -999.0f;
private static float stateColorBiasG = -999.0f;
private static float stateColorBiasB = -999.0f;
private static float stateColorBiasA = -999.0f;
private static final Matrix4f tmpMatrix = new Matrix4f();
private static final Vector4f tmpVector = new Vector4f();
private static int stateModelMatrixSerial = -1;
private static int stateProjectionMatrixSerial = -1;
private static float charWidthValue = -1;
private static float charHeightValue = -1;
private static float charCoordWidthValue = -1.0f;
private static float charCoordHeightValue = -1.0f;
static void initialize() {
String vertexSource = EagRuntime.getResourceString(vertexShaderPath);
if(vertexSource == null) {
throw new RuntimeException("InstancedFontRenderer shader \"" + vertexShaderPath + "\" is missing!");
}
String fragmentSource = EagRuntime.getResourceString(fragmentShaderPath);
if(fragmentSource == null) {
throw new RuntimeException("InstancedFontRenderer shader \"" + fragmentShaderPath + "\" is missing!");
}
IShaderGL vert = _wglCreateShader(GL_VERTEX_SHADER);
IShaderGL frag = _wglCreateShader(GL_FRAGMENT_SHADER);
_wglShaderSource(vert, FixedFunctionConstants.VERSION + "\n" + vertexSource);
_wglCompileShader(vert);
if(_wglGetShaderi(vert, GL_COMPILE_STATUS) != GL_TRUE) {
logger.error("Failed to compile GL_VERTEX_SHADER \"" + vertexShaderPath + "\" for InstancedFontRenderer!");
String log = _wglGetShaderInfoLog(vert);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[VERT] {}", lines[i]);
}
}
throw new IllegalStateException("Vertex shader \"" + vertexShaderPath + "\" could not be compiled!");
}
_wglShaderSource(frag, FixedFunctionConstants.VERSION + "\n" + fragmentSource);
_wglCompileShader(frag);
if(_wglGetShaderi(frag, GL_COMPILE_STATUS) != GL_TRUE) {
logger.error("Failed to compile GL_FRAGMENT_SHADER \"" + fragmentShaderPath + "\" for InstancedFontRenderer!");
String log = _wglGetShaderInfoLog(frag);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[FRAG] {}", lines[i]);
}
}
throw new IllegalStateException("Fragment shader \"" + fragmentShaderPath + "\" could not be compiled!");
}
shaderProgram = _wglCreateProgram();
_wglAttachShader(shaderProgram, vert);
_wglAttachShader(shaderProgram, frag);
_wglBindAttribLocation(shaderProgram, 0, "a_position2f");
_wglBindAttribLocation(shaderProgram, 1, "c_position2i");
_wglBindAttribLocation(shaderProgram, 2, "c_coords2i");
_wglBindAttribLocation(shaderProgram, 3, "c_color4f");
_wglLinkProgram(shaderProgram);
_wglDetachShader(shaderProgram, vert);
_wglDetachShader(shaderProgram, frag);
_wglDeleteShader(vert);
_wglDeleteShader(frag);
if(_wglGetProgrami(shaderProgram, GL_LINK_STATUS) != GL_TRUE) {
logger.error("Failed to link shader program for InstancedFontRenderer!");
String log = _wglGetProgramInfoLog(shaderProgram);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[LINK] {}", lines[i]);
}
}
throw new IllegalStateException("Shader program for InstancedFontRenderer could not be linked!");
}
matrixCopyBuffer = EagRuntime.allocateFloatBuffer(16);
fontDataBuffer = EagRuntime.allocateByteBuffer(CHARACTER_LIMIT * BYTES_PER_CHARACTER);
fontBoldDataBuffer = EagRuntime.allocateByteBuffer(CHARACTER_LIMIT * BYTES_PER_CHARACTER);
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
u_matrixTransform = _wglGetUniformLocation(shaderProgram, "u_matrixTransform");
u_charSize2f = _wglGetUniformLocation(shaderProgram, "u_charSize2f");
u_charCoordSize2f = _wglGetUniformLocation(shaderProgram, "u_charCoordSize2f");
u_color4f = _wglGetUniformLocation(shaderProgram, "u_color4f");
u_colorBias4f = _wglGetUniformLocation(shaderProgram, "u_colorBias4f");
_wglUniform1i(_wglGetUniformLocation(shaderProgram, "u_inputTexture"), 0);
vertexArray = _wglGenVertexArrays();
vertexBuffer = _wglGenBuffers();
instancesBuffer = _wglGenBuffers();
FloatBuffer verts = EagRuntime.allocateFloatBuffer(108);
verts.put(new float[] {
// (0 - 6 - 12) regular:
0.0f, 0.0f, 0.25f, 0.0f, 1.0f, 0.25f, 1.0f, 0.0f, 0.25f,
1.0f, 0.0f, 0.25f, 0.0f, 1.0f, 0.25f, 1.0f, 1.0f, 0.25f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
// (12 - 24 - 36) bold shadow:
0.0f, 0.0f, 0.25f, 0.0f, 1.0f, 0.25f, 1.0f, 0.0f, 0.25f,
1.0f, 0.0f, 0.25f, 0.0f, 1.0f, 0.25f, 1.0f, 1.0f, 0.25f,
0.0f, 0.0f, 0.75f, 0.0f, 1.0f, 0.75f, 1.0f, 0.0f, 0.75f,
1.0f, 0.0f, 0.75f, 0.0f, 1.0f, 0.75f, 1.0f, 1.0f, 0.75f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f, 1.0f, 0.5f, 1.0f, 0.0f, 0.5f,
1.0f, 0.0f, 0.5f, 0.0f, 1.0f, 0.5f, 1.0f, 1.0f, 0.5f
});
verts.flip();
EaglercraftGPU.bindGLBufferArray(vertexArray);
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
_wglBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
EagRuntime.freeFloatBuffer(verts);
_wglEnableVertexAttribArray(0);
_wglVertexAttribPointer(0, 3, GL_FLOAT, false, 12, 0);
_wglVertexAttribDivisor(0, 0);
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
_wglBufferData(GL_ARRAY_BUFFER, fontDataBuffer.remaining(), GL_STATIC_DRAW);
_wglEnableVertexAttribArray(1);
_wglVertexAttribPointer(1, 2, GL_SHORT, false, 10, 0);
_wglVertexAttribDivisor(1, 1);
_wglEnableVertexAttribArray(2);
_wglVertexAttribPointer(2, 2, GL_UNSIGNED_BYTE, false, 10, 4);
_wglVertexAttribDivisor(2, 1);
_wglEnableVertexAttribArray(3);
_wglVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, true, 10, 6);
_wglVertexAttribDivisor(3, 1);
}
private static ByteBuffer fontDataBuffer = null;
private static int charactersDrawn = 0;
private static ByteBuffer fontBoldDataBuffer = null;
private static int boldCharactersDrawn = 0;
private static boolean hasOverflowed = false;
private static boolean hasBoldOverflowed = false;
private static boolean fogEnabled = false;
private static int widthCalcLeast = Integer.MAX_VALUE;
private static int heightCalcLeast = Integer.MAX_VALUE;
private static int widthCalcMost = Integer.MAX_VALUE;
private static int heightCalcMost = Integer.MAX_VALUE;
public static void begin() {
fontDataBuffer.clear();
charactersDrawn = 0;
fontBoldDataBuffer.clear();
boldCharactersDrawn = 0;
hasOverflowed = false;
hasBoldOverflowed = false;
fogEnabled = GlStateManager.stateFog && GlStateManager.stateFogDensity > 0.0f;
if(fogEnabled) {
widthCalcLeast = Integer.MAX_VALUE;
heightCalcLeast = Integer.MAX_VALUE;
widthCalcMost = Integer.MAX_VALUE;
heightCalcMost = Integer.MAX_VALUE;
}
}
public static void render(float charWidth, float charHeight, float charCoordWidth, float charCoordHeight, boolean shadow) {
if(charactersDrawn == 0 && boldCharactersDrawn == 0) {
return;
}
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
if(charWidth != charWidthValue || charHeight != charHeightValue) {
charWidthValue = charWidth;
charHeightValue = charHeight;
_wglUniform2f(u_charSize2f, (float)charWidth, (float)charHeight);
}
if(charCoordWidth != charCoordWidthValue || charCoordHeight != charCoordHeightValue) {
charCoordWidthValue = charCoordWidth;
charCoordHeightValue = charCoordHeight;
_wglUniform2f(u_charCoordSize2f, charCoordWidth, charCoordHeight);
}
int ptr1 = GlStateManager.modelMatrixStackPointer;
int serial1 = GlStateManager.modelMatrixStackAccessSerial[ptr1];
int ptr2 = GlStateManager.projectionMatrixStackPointer;
int serial2 = GlStateManager.projectionMatrixStackAccessSerial[ptr2];
if(stateModelMatrixSerial != serial1 || stateProjectionMatrixSerial != serial2) {
stateModelMatrixSerial = serial1;
stateProjectionMatrixSerial = serial2;
Matrix4f.mul(GlStateManager.projectionMatrixStack[ptr2], GlStateManager.modelMatrixStack[ptr1], tmpMatrix);
matrixCopyBuffer.clear();
tmpMatrix.store(matrixCopyBuffer);
matrixCopyBuffer.flip();
_wglUniformMatrix4fv(u_matrixTransform, false, matrixCopyBuffer);
}
if(!fogEnabled) {
int serial = GlStateManager.stateColorSerial;
if(stateColorSerial != serial) {
stateColorSerial = serial;
float r = GlStateManager.stateColorR;
float g = GlStateManager.stateColorG;
float b = GlStateManager.stateColorB;
float a = GlStateManager.stateColorA;
if(stateColorR != r || stateColorG != g ||
stateColorB != b || stateColorA != a) {
_wglUniform4f(u_color4f, r, g, b, a);
stateColorR = r;
stateColorG = g;
stateColorB = b;
stateColorA = a;
}
}
if(stateColorBiasR != 0.0f || stateColorBiasG != 0.0f ||
stateColorBiasB != 0.0f || stateColorBiasA != 0.0f) {
_wglUniform4f(u_colorBias4f, 0.0f, 0.0f, 0.0f, 0.0f);
stateColorBiasR = 0.0f;
stateColorBiasG = 0.0f;
stateColorBiasB = 0.0f;
stateColorBiasA = 0.0f;
}
}else {
stateColorSerial = -1;
Vector4f vec4 = tmpVector;
vec4.x = (float)(widthCalcLeast + (widthCalcMost - widthCalcLeast + 1.0f) * 0.5f) * charWidth;
vec4.y = (float)(heightCalcLeast + (heightCalcMost - heightCalcLeast + 1.0f) * 0.5f)* charHeight;
vec4.z = 0.0f;
vec4.w = 1.0f;
Matrix4f.transform(GlStateManager.modelMatrixStack[ptr1], vec4, vec4);
vec4.x /= vec4.w;
vec4.y /= vec4.w;
vec4.z /= vec4.w;
vec4.w = 1.0f;
vec4.x *= vec4.x;
vec4.y *= vec4.y;
vec4.z *= vec4.z;
float fogFactor = (float) Math.sqrt(vec4.x + vec4.y + vec4.z);
if(GlStateManager.stateFogEXP) {
fogFactor = 1.0f - (float) Math.pow(2.718, -(GlStateManager.stateFogDensity * fogFactor));
}else {
fogFactor = (fogFactor - GlStateManager.stateFogStart) / (GlStateManager.stateFogEnd - GlStateManager.stateFogStart);
}
if(fogFactor > 1.0f) fogFactor = 1.0f;
if(fogFactor < 0.0f) fogFactor = 0.0f;
float r = GlStateManager.stateColorR;
float g = GlStateManager.stateColorG;
float b = GlStateManager.stateColorB;
float a = GlStateManager.stateColorA;
float fogFactor2 = (1.0f - fogFactor) * GlStateManager.stateFogColorA;
r *= fogFactor2;
g *= fogFactor2;
b *= fogFactor2;
if(stateColorR != r || stateColorG != g ||
stateColorB != b || stateColorA != a) {
_wglUniform4f(u_color4f, r, g, b, a);
stateColorR = r;
stateColorG = g;
stateColorB = b;
stateColorA = a;
}
fogFactor *= GlStateManager.stateFogColorA;
float biasR = GlStateManager.stateFogColorR * fogFactor;
float biasG = GlStateManager.stateFogColorG * fogFactor;
float biasB = GlStateManager.stateFogColorB * fogFactor;
float biasA = 0.0f;
if(stateColorBiasR != biasR || stateColorBiasG != biasG ||
stateColorBiasB != biasB || stateColorBiasA != biasA) {
_wglUniform4f(u_colorBias4f, biasR, biasG, biasB, biasA);
stateColorBiasR = biasR;
stateColorBiasG = biasG;
stateColorBiasB = biasB;
stateColorBiasA = biasA;
}
}
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
EaglercraftGPU.bindGLBufferArray(vertexArray);
if(charactersDrawn > 0) {
int p = fontDataBuffer.position();
int l = fontDataBuffer.limit();
fontDataBuffer.flip();
_wglBufferSubData(GL_ARRAY_BUFFER, 0, fontDataBuffer);
fontDataBuffer.position(p);
fontDataBuffer.limit(l);
_wglDrawArraysInstanced(GL_TRIANGLES, shadow ? 0 : 6, shadow ? 12 : 6, charactersDrawn);
}
if(boldCharactersDrawn > 0) {
int p = fontBoldDataBuffer.position();
int l = fontBoldDataBuffer.limit();
fontBoldDataBuffer.flip();
_wglBufferSubData(GL_ARRAY_BUFFER, 0, fontBoldDataBuffer);
fontBoldDataBuffer.position(p);
fontBoldDataBuffer.limit(l);
_wglDrawArraysInstanced(GL_TRIANGLES, shadow ? 12 : 24, shadow ? 24 : 12, boldCharactersDrawn);
}
}
public static void appendQuad(int x, int y, int cx, int cy, int color, boolean italic) {
if(hasOverflowed) {
return;
}
if(charactersDrawn >= CHARACTER_LIMIT) {
hasOverflowed = true;
logger.error("Font renderer buffer has overflowed! Exceeded {} regular characters, no more regular characters will be rendered.", CHARACTER_LIMIT);
return;
}
++charactersDrawn;
ByteBuffer buf = fontDataBuffer;
buf.putShort((short)x);
buf.putShort((short)y);
buf.put((byte)cx);
buf.put((byte)cy);
color = ((color >> 1) & 0x7F000000) | (color & 0xFFFFFF);
if(italic) {
color |= 0x80000000;
}
buf.putInt(color);
if(fogEnabled) {
updateBounds(x, y);
}
}
public static void appendBoldQuad(int x, int y, int cx, int cy, int color, boolean italic) {
if(hasBoldOverflowed) {
return;
}
if(boldCharactersDrawn >= CHARACTER_LIMIT) {
hasBoldOverflowed = true;
logger.error("Font renderer buffer has overflowed! Exceeded {} bold characters, no more bold characters will be rendered.", CHARACTER_LIMIT);
return;
}
++boldCharactersDrawn;
ByteBuffer buf = fontBoldDataBuffer;
buf.putShort((short)x);
buf.putShort((short)y);
buf.put((byte)cx);
buf.put((byte)cy);
color = ((color >> 1) & 0x7F000000) | (color & 0xFFFFFF);
if(italic) {
color |= 0x80000000;
}
buf.putInt(color);
if(fogEnabled) {
updateBounds(x, y);
}
}
private static final void updateBounds(int x, int y) {
if(x < widthCalcLeast || widthCalcLeast == Integer.MAX_VALUE) widthCalcLeast = x;
if(x > widthCalcMost || widthCalcMost == Integer.MAX_VALUE) widthCalcMost = x;
if(y < heightCalcLeast || heightCalcLeast == Integer.MAX_VALUE) heightCalcLeast = y;
if(y > heightCalcMost || heightCalcMost == Integer.MAX_VALUE) heightCalcMost = y;
}
}

View File

@ -0,0 +1,327 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class InstancedParticleRenderer {
private static final Logger logger = LogManager.getLogger("InstancedParticleRenderer");
public static final String vertexShaderPath = "/assets/eagler/glsl/accel_particle.vsh";
public static final String fragmentShaderPath = "/assets/eagler/glsl/accel_particle.fsh";
private static ByteBuffer particleBuffer = null;
private static int particleCount = 0;
private static boolean particlesHasOverflowed = false;
private static final int BYTES_PER_PARTICLE = 24;
private static final int PARTICLE_LIMIT = 5461;
private static IProgramGL shaderProgram = null;
private static IUniformGL u_matrixTransform = null;
private static FloatBuffer matrixCopyBuffer = null;
private static IUniformGL u_texCoordSize2f_particleSize1f = null;
private static IUniformGL u_transformParam_1_2_3_4_f = null;
private static IUniformGL u_transformParam_5_f = null;
private static IUniformGL u_color4f = null;
private static IBufferArrayGL vertexArray = null;
private static IBufferGL vertexBuffer = null;
private static IBufferGL instancesBuffer = null;
private static float stateColorR = -999.0f;
private static float stateColorG = -999.0f;
private static float stateColorB = -999.0f;
private static float stateColorA = -999.0f;
private static int stateColorSerial = -1;
private static final Matrix4f tmpMatrix = new Matrix4f();
private static int stateModelMatrixSerial = -1;
private static int stateProjectionMatrixSerial = -1;
private static float stateTexCoordWidth = -999.0f;
private static float stateTexCoordHeight = -999.0f;
private static float stateParticleCoordSize = -999.0f;
private static float stateTransformParam1 = -999.0f;
private static float stateTransformParam2 = -999.0f;
private static float stateTransformParam3 = -999.0f;
private static float stateTransformParam4 = -999.0f;
private static float stateTransformParam5 = -999.0f;
static void initialize() {
String vertexSource = EagRuntime.getResourceString(vertexShaderPath);
if(vertexSource == null) {
throw new RuntimeException("InstancedParticleRenderer shader \"" + vertexShaderPath + "\" is missing!");
}
String fragmentSource = EagRuntime.getResourceString(fragmentShaderPath);
if(fragmentSource == null) {
throw new RuntimeException("InstancedParticleRenderer shader \"" + fragmentShaderPath + "\" is missing!");
}
IShaderGL vert = _wglCreateShader(GL_VERTEX_SHADER);
IShaderGL frag = _wglCreateShader(GL_FRAGMENT_SHADER);
_wglShaderSource(vert, FixedFunctionConstants.VERSION + "\n" + vertexSource);
_wglCompileShader(vert);
if(_wglGetShaderi(vert, GL_COMPILE_STATUS) != GL_TRUE) {
logger.error("Failed to compile GL_VERTEX_SHADER \"" + vertexShaderPath + "\" for InstancedParticleRenderer!");
String log = _wglGetShaderInfoLog(vert);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[VERT] {}", lines[i]);
}
}
throw new IllegalStateException("Vertex shader \"" + vertexShaderPath + "\" could not be compiled!");
}
_wglShaderSource(frag, FixedFunctionConstants.VERSION + "\n" + fragmentSource);
_wglCompileShader(frag);
if(_wglGetShaderi(frag, GL_COMPILE_STATUS) != GL_TRUE) {
logger.error("Failed to compile GL_FRAGMENT_SHADER \"" + fragmentShaderPath + "\" for InstancedParticleRenderer!");
String log = _wglGetShaderInfoLog(frag);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[FRAG] {}", lines[i]);
}
}
throw new IllegalStateException("Fragment shader \"" + fragmentShaderPath + "\" could not be compiled!");
}
shaderProgram = _wglCreateProgram();
_wglAttachShader(shaderProgram, vert);
_wglAttachShader(shaderProgram, frag);
_wglBindAttribLocation(shaderProgram, 0, "a_position2f");
_wglBindAttribLocation(shaderProgram, 1, "p_position3f");
_wglBindAttribLocation(shaderProgram, 2, "p_texCoords2i");
_wglBindAttribLocation(shaderProgram, 3, "p_lightMap2f");
_wglBindAttribLocation(shaderProgram, 4, "p_particleSize_texCoordsSize_2i");
_wglBindAttribLocation(shaderProgram, 5, "p_color4f");
_wglLinkProgram(shaderProgram);
_wglDetachShader(shaderProgram, vert);
_wglDetachShader(shaderProgram, frag);
_wglDeleteShader(vert);
_wglDeleteShader(frag);
if(_wglGetProgrami(shaderProgram, GL_LINK_STATUS) != GL_TRUE) {
logger.error("Failed to link shader program for InstancedParticleRenderer!");
String log = _wglGetProgramInfoLog(shaderProgram);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
logger.error("[LINK] {}", lines[i]);
}
}
throw new IllegalStateException("Shader program for InstancedParticleRenderer could not be linked!");
}
matrixCopyBuffer = EagRuntime.allocateFloatBuffer(16);
particleBuffer = EagRuntime.allocateByteBuffer(PARTICLE_LIMIT * BYTES_PER_PARTICLE);
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
u_matrixTransform = _wglGetUniformLocation(shaderProgram, "u_matrixTransform");
u_texCoordSize2f_particleSize1f = _wglGetUniformLocation(shaderProgram, "u_texCoordSize2f_particleSize1f");
u_transformParam_1_2_3_4_f = _wglGetUniformLocation(shaderProgram, "u_transformParam_1_2_3_4_f");
u_transformParam_5_f = _wglGetUniformLocation(shaderProgram, "u_transformParam_5_f");
u_color4f = _wglGetUniformLocation(shaderProgram, "u_color4f");
_wglUniform1i(_wglGetUniformLocation(shaderProgram, "u_inputTexture"), 0);
_wglUniform1i(_wglGetUniformLocation(shaderProgram, "u_lightmapTexture"), 1);
vertexArray = _wglGenVertexArrays();
vertexBuffer = _wglGenBuffers();
instancesBuffer = _wglGenBuffers();
FloatBuffer verts = EagRuntime.allocateFloatBuffer(12);
verts.put(new float[] {
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f
});
verts.flip();
EaglercraftGPU.bindGLBufferArray(vertexArray);
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
_wglBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
EagRuntime.freeFloatBuffer(verts);
_wglEnableVertexAttribArray(0);
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 8, 0);
_wglVertexAttribDivisor(0, 0);
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
_wglBufferData(GL_ARRAY_BUFFER, particleBuffer.remaining(), GL_STATIC_DRAW);
_wglEnableVertexAttribArray(1);
_wglVertexAttribPointer(1, 3, GL_FLOAT, false, 24, 0);
_wglVertexAttribDivisor(1, 1);
_wglEnableVertexAttribArray(2);
_wglVertexAttribPointer(2, 2, GL_UNSIGNED_SHORT, false, 24, 12);
_wglVertexAttribDivisor(2, 1);
_wglEnableVertexAttribArray(3);
_wglVertexAttribPointer(3, 2, GL_UNSIGNED_BYTE, true, 24, 16);
_wglVertexAttribDivisor(3, 1);
_wglEnableVertexAttribArray(4);
_wglVertexAttribPointer(4, 2, GL_UNSIGNED_BYTE, false, 24, 18);
_wglVertexAttribDivisor(4, 1);
_wglEnableVertexAttribArray(5);
_wglVertexAttribPointer(5, 4, GL_UNSIGNED_BYTE, true, 24, 20);
_wglVertexAttribDivisor(5, 1);
}
public static void begin() {
particleBuffer.clear();
particleCount = 0;
particlesHasOverflowed = false;
}
public static void appendParticle(float posX, float posY, float posZ, int particleTextureX, int particleTextureY,
int lightMapX, int lightMapY, int particleSize, int particleTexSize, float r, float g, float b, float a) {
int color = ((int)(a * 255.0f) << 24) | ((int)(r * 255.0f) << 16) | ((int)(g * 255.0f) << 8) | (int)(b * 255.0f);
appendParticle(posX, posY, posZ, particleTextureX, particleTextureY, lightMapX, lightMapY, particleSize, particleTexSize, color);
}
public static void appendParticle(float posX, float posY, float posZ, int particleTextureX, int particleTextureY,
int lightMapX, int lightMapY, int particleSize, int particleTexSize, int rgba) {
if(particlesHasOverflowed) {
return;
}
if(particleCount >= PARTICLE_LIMIT) {
particlesHasOverflowed = true;
logger.error("Particle buffer has overflowed! Exceeded {} particles, no more particles will be rendered.", PARTICLE_LIMIT);
return;
}
++particleCount;
ByteBuffer buf = particleBuffer;
buf.putFloat(posX);
buf.putFloat(posY);
buf.putFloat(posZ);
buf.putShort((short)particleTextureX);
buf.putShort((short)particleTextureY);
buf.put((byte)lightMapX);
buf.put((byte)lightMapY);
buf.put((byte)particleSize);
buf.put((byte)particleTexSize);
buf.putInt(rgba);
}
public static void render(float texCoordWidth, float texCoordHeight, float particleCoordSize, float transformParam1,
float transformParam2, float transformParam3, float transformParam4, float transformParam5) {
if(particleCount == 0) {
return;
}
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
if (texCoordWidth != stateTexCoordWidth || texCoordHeight != stateTexCoordHeight
|| particleCoordSize != stateParticleCoordSize) {
_wglUniform3f(u_texCoordSize2f_particleSize1f, texCoordWidth, texCoordHeight, particleCoordSize);
stateTexCoordWidth = texCoordWidth;
stateTexCoordHeight = texCoordHeight;
stateParticleCoordSize = particleCoordSize;
}
if (transformParam1 != stateTransformParam1 || transformParam2 != stateTransformParam2
|| transformParam3 != stateTransformParam3 || transformParam4 != stateTransformParam4) {
_wglUniform4f(u_transformParam_1_2_3_4_f, transformParam1, transformParam2, transformParam3, transformParam4);
stateTransformParam1 = transformParam1;
stateTransformParam2 = transformParam2;
stateTransformParam3 = transformParam3;
stateTransformParam4 = transformParam4;
}
if (transformParam5 != stateTransformParam5) {
_wglUniform1f(u_transformParam_5_f, transformParam5);
stateTransformParam5 = transformParam5;
}
int serial = GlStateManager.stateColorSerial;
if(stateColorSerial != serial) {
stateColorSerial = serial;
float r = GlStateManager.stateColorR;
float g = GlStateManager.stateColorG;
float b = GlStateManager.stateColorB;
float a = GlStateManager.stateColorA;
if(stateColorR != r || stateColorG != g ||
stateColorB != b || stateColorA != a) {
_wglUniform4f(u_color4f, r, g, b, a);
stateColorR = r;
stateColorG = g;
stateColorB = b;
stateColorA = a;
}
}
int ptr1 = GlStateManager.modelMatrixStackPointer;
int serial1 = GlStateManager.modelMatrixStackAccessSerial[ptr1];
int ptr2 = GlStateManager.projectionMatrixStackPointer;
int serial2 = GlStateManager.projectionMatrixStackAccessSerial[ptr2];
if(stateModelMatrixSerial != serial1 || stateProjectionMatrixSerial != serial2) {
stateModelMatrixSerial = serial1;
stateProjectionMatrixSerial = serial2;
Matrix4f.mul(GlStateManager.projectionMatrixStack[ptr2], GlStateManager.modelMatrixStack[ptr1], tmpMatrix);
matrixCopyBuffer.clear();
tmpMatrix.store(matrixCopyBuffer);
matrixCopyBuffer.flip();
_wglUniformMatrix4fv(u_matrixTransform, false, matrixCopyBuffer);
}
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
EaglercraftGPU.bindGLBufferArray(vertexArray);
int p = particleBuffer.position();
int l = particleBuffer.limit();
particleBuffer.flip();
_wglBufferSubData(GL_ARRAY_BUFFER, 0, particleBuffer);
particleBuffer.position(p);
particleBuffer.limit(l);
_wglDrawArraysInstanced(GL_TRIANGLES, 0, 6, particleCount);
}
}

View File

@ -0,0 +1,29 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class OpenGlHelper {
public static final int defaultTexUnit = RealOpenGLEnums.GL_TEXTURE0;
public static final int lightmapTexUnit = RealOpenGLEnums.GL_TEXTURE1;
public static void setLightmapTextureCoords(int unit, float x, float y) {
GlStateManager.setActiveTexture(lightmapTexUnit);
GlStateManager.texCoords2D(x, y);
GlStateManager.setActiveTexture(defaultTexUnit);
}
}

View File

@ -0,0 +1,825 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class RealOpenGLEnums {
public static final int GL_ACCUM = 256;
public static final int GL_LOAD = 257;
public static final int GL_RETURN = 258;
public static final int GL_MULT = 259;
public static final int GL_ADD = 260;
public static final int GL_NEVER = 512;
public static final int GL_LESS = 513;
public static final int GL_EQUAL = 514;
public static final int GL_LEQUAL = 515;
public static final int GL_GREATER = 516;
public static final int GL_NOTEQUAL = 517;
public static final int GL_GEQUAL = 518;
public static final int GL_ALWAYS = 519;
public static final int GL_CURRENT_BIT = 1;
public static final int GL_POINT_BIT = 2;
public static final int GL_LINE_BIT = 4;
public static final int GL_POLYGON_BIT = 8;
public static final int GL_POLYGON_STIPPLE_BIT = 16;
public static final int GL_PIXEL_MODE_BIT = 32;
public static final int GL_LIGHTING_BIT = 64;
public static final int GL_FOG_BIT = 128;
public static final int GL_DEPTH_BUFFER_BIT = 256;
public static final int GL_ACCUM_BUFFER_BIT = 512;
public static final int GL_STENCIL_BUFFER_BIT = 1024;
public static final int GL_VIEWPORT_BIT = 2048;
public static final int GL_TRANSFORM_BIT = 4096;
public static final int GL_ENABLE_BIT = 8192;
public static final int GL_COLOR_BUFFER_BIT = 16384;
public static final int GL_HINT_BIT = 32768;
public static final int GL_EVAL_BIT = 65536;
public static final int GL_LIST_BIT = 131072;
public static final int GL_TEXTURE_BIT = 262144;
public static final int GL_SCISSOR_BIT = 524288;
public static final int GL_ALL_ATTRIB_BITS = 1048575;
public static final int GL_POINTS = 0;
public static final int GL_LINES = 1;
public static final int GL_LINE_LOOP = 2;
public static final int GL_LINE_STRIP = 3;
public static final int GL_TRIANGLES = 4;
public static final int GL_TRIANGLE_STRIP = 5;
public static final int GL_TRIANGLE_FAN = 6;
public static final int GL_QUADS = 7;
public static final int GL_QUAD_STRIP = 8;
public static final int GL_POLYGON = 9;
public static final int GL_ZERO = 0;
public static final int GL_ONE = 1;
public static final int GL_SRC_COLOR = 768;
public static final int GL_ONE_MINUS_SRC_COLOR = 769;
public static final int GL_SRC_ALPHA = 770;
public static final int GL_ONE_MINUS_SRC_ALPHA = 771;
public static final int GL_DST_ALPHA = 772;
public static final int GL_ONE_MINUS_DST_ALPHA = 773;
public static final int GL_DST_COLOR = 774;
public static final int GL_ONE_MINUS_DST_COLOR = 775;
public static final int GL_SRC_ALPHA_SATURATE = 776;
public static final int GL_CONSTANT_COLOR = 32769;
public static final int GL_ONE_MINUS_CONSTANT_COLOR = 32770;
public static final int GL_CONSTANT_ALPHA = 32771;
public static final int GL_ONE_MINUS_CONSTANT_ALPHA = 32772;
public static final int GL_TRUE = 1;
public static final int GL_FALSE = 0;
public static final int GL_CLIP_PLANE0 = 12288;
public static final int GL_CLIP_PLANE1 = 12289;
public static final int GL_CLIP_PLANE2 = 12290;
public static final int GL_CLIP_PLANE3 = 12291;
public static final int GL_CLIP_PLANE4 = 12292;
public static final int GL_CLIP_PLANE5 = 12293;
public static final int GL_BYTE = 5120;
public static final int GL_UNSIGNED_BYTE = 5121;
public static final int GL_SHORT = 5122;
public static final int GL_UNSIGNED_SHORT = 5123;
public static final int GL_INT = 5124;
public static final int GL_UNSIGNED_INT = 5125;
public static final int GL_FLOAT = 5126;
public static final int GL_2_BYTES = 5127;
public static final int GL_3_BYTES = 5128;
public static final int GL_4_BYTES = 5129;
public static final int GL_DOUBLE = 5130;
public static final int GL_NONE = 0;
public static final int GL_FRONT_LEFT = 1024;
public static final int GL_FRONT_RIGHT = 1025;
public static final int GL_BACK_LEFT = 1026;
public static final int GL_BACK_RIGHT = 1027;
public static final int GL_FRONT = 1028;
public static final int GL_BACK = 1029;
public static final int GL_LEFT = 1030;
public static final int GL_RIGHT = 1031;
public static final int GL_FRONT_AND_BACK = 1032;
public static final int GL_AUX0 = 1033;
public static final int GL_AUX1 = 1034;
public static final int GL_AUX2 = 1035;
public static final int GL_AUX3 = 1036;
public static final int GL_NO_ERROR = 0;
public static final int GL_INVALID_ENUM = 1280;
public static final int GL_INVALID_VALUE = 1281;
public static final int GL_INVALID_OPERATION = 1282;
public static final int GL_STACK_OVERFLOW = 1283;
public static final int GL_STACK_UNDERFLOW = 1284;
public static final int GL_OUT_OF_MEMORY = 1285;
public static final int GL_2D = 1536;
public static final int GL_3D = 1537;
public static final int GL_3D_COLOR = 1538;
public static final int GL_3D_COLOR_TEXTURE = 1539;
public static final int GL_4D_COLOR_TEXTURE = 1540;
public static final int GL_PASS_THROUGH_TOKEN = 1792;
public static final int GL_POINT_TOKEN = 1793;
public static final int GL_LINE_TOKEN = 1794;
public static final int GL_POLYGON_TOKEN = 1795;
public static final int GL_BITMAP_TOKEN = 1796;
public static final int GL_DRAW_PIXEL_TOKEN = 1797;
public static final int GL_COPY_PIXEL_TOKEN = 1798;
public static final int GL_LINE_RESET_TOKEN = 1799;
public static final int GL_EXP = 2048;
public static final int GL_EXP2 = 2049;
public static final int GL_CW = 2304;
public static final int GL_CCW = 2305;
public static final int GL_COEFF = 2560;
public static final int GL_ORDER = 2561;
public static final int GL_DOMAIN = 2562;
public static final int GL_CURRENT_COLOR = 2816;
public static final int GL_CURRENT_INDEX = 2817;
public static final int GL_CURRENT_NORMAL = 2818;
public static final int GL_CURRENT_TEXTURE_COORDS = 2819;
public static final int GL_CURRENT_RASTER_COLOR = 2820;
public static final int GL_CURRENT_RASTER_INDEX = 2821;
public static final int GL_CURRENT_RASTER_TEXTURE_COORDS = 2822;
public static final int GL_CURRENT_RASTER_POSITION = 2823;
public static final int GL_CURRENT_RASTER_POSITION_VALID = 2824;
public static final int GL_CURRENT_RASTER_DISTANCE = 2825;
public static final int GL_POINT_SMOOTH = 2832;
public static final int GL_POINT_SIZE = 2833;
public static final int GL_POINT_SIZE_RANGE = 2834;
public static final int GL_POINT_SIZE_GRANULARITY = 2835;
public static final int GL_LINE_SMOOTH = 2848;
public static final int GL_LINE_WIDTH = 2849;
public static final int GL_LINE_WIDTH_RANGE = 2850;
public static final int GL_LINE_WIDTH_GRANULARITY = 2851;
public static final int GL_LINE_STIPPLE = 2852;
public static final int GL_LINE_STIPPLE_PATTERN = 2853;
public static final int GL_LINE_STIPPLE_REPEAT = 2854;
public static final int GL_LIST_MODE = 2864;
public static final int GL_MAX_LIST_NESTING = 2865;
public static final int GL_LIST_BASE = 2866;
public static final int GL_LIST_INDEX = 2867;
public static final int GL_POLYGON_MODE = 2880;
public static final int GL_POLYGON_SMOOTH = 2881;
public static final int GL_POLYGON_STIPPLE = 2882;
public static final int GL_EDGE_FLAG = 2883;
public static final int GL_CULL_FACE = 2884;
public static final int GL_CULL_FACE_MODE = 2885;
public static final int GL_FRONT_FACE = 2886;
public static final int GL_LIGHTING = 2896;
public static final int GL_LIGHT_MODEL_LOCAL_VIEWER = 2897;
public static final int GL_LIGHT_MODEL_TWO_SIDE = 2898;
public static final int GL_LIGHT_MODEL_AMBIENT = 2899;
public static final int GL_SHADE_MODEL = 2900;
public static final int GL_COLOR_MATERIAL_FACE = 2901;
public static final int GL_COLOR_MATERIAL_PARAMETER = 2902;
public static final int GL_COLOR_MATERIAL = 2903;
public static final int GL_FOG = 2912;
public static final int GL_FOG_INDEX = 2913;
public static final int GL_FOG_DENSITY = 2914;
public static final int GL_FOG_START = 2915;
public static final int GL_FOG_END = 2916;
public static final int GL_FOG_MODE = 2917;
public static final int GL_FOG_COLOR = 2918;
public static final int GL_DEPTH_RANGE = 2928;
public static final int GL_DEPTH_TEST = 2929;
public static final int GL_DEPTH_WRITEMASK = 2930;
public static final int GL_DEPTH_CLEAR_VALUE = 2931;
public static final int GL_DEPTH_FUNC = 2932;
public static final int GL_ACCUM_CLEAR_VALUE = 2944;
public static final int GL_STENCIL_TEST = 2960;
public static final int GL_STENCIL_CLEAR_VALUE = 2961;
public static final int GL_STENCIL_FUNC = 2962;
public static final int GL_STENCIL_VALUE_MASK = 2963;
public static final int GL_STENCIL_FAIL = 2964;
public static final int GL_STENCIL_PASS_DEPTH_FAIL = 2965;
public static final int GL_STENCIL_PASS_DEPTH_PASS = 2966;
public static final int GL_STENCIL_REF = 2967;
public static final int GL_STENCIL_WRITEMASK = 2968;
public static final int GL_MATRIX_MODE = 2976;
public static final int GL_NORMALIZE = 2977;
public static final int GL_VIEWPORT = 2978;
public static final int GL_MODELVIEW_STACK_DEPTH = 2979;
public static final int GL_PROJECTION_STACK_DEPTH = 2980;
public static final int GL_TEXTURE_STACK_DEPTH = 2981;
public static final int GL_MODELVIEW_MATRIX = 2982;
public static final int GL_PROJECTION_MATRIX = 2983;
public static final int GL_TEXTURE_MATRIX = 2984;
public static final int GL_ATTRIB_STACK_DEPTH = 2992;
public static final int GL_CLIENT_ATTRIB_STACK_DEPTH = 2993;
public static final int GL_ALPHA_TEST = 3008;
public static final int GL_ALPHA_TEST_FUNC = 3009;
public static final int GL_ALPHA_TEST_REF = 3010;
public static final int GL_DITHER = 3024;
public static final int GL_BLEND_DST = 3040;
public static final int GL_BLEND_SRC = 3041;
public static final int GL_BLEND = 3042;
public static final int GL_LOGIC_OP_MODE = 3056;
public static final int GL_INDEX_LOGIC_OP = 3057;
public static final int GL_COLOR_LOGIC_OP = 3058;
public static final int GL_AUX_BUFFERS = 3072;
public static final int GL_DRAW_BUFFER = 3073;
public static final int GL_READ_BUFFER = 3074;
public static final int GL_SCISSOR_BOX = 3088;
public static final int GL_SCISSOR_TEST = 3089;
public static final int GL_INDEX_CLEAR_VALUE = 3104;
public static final int GL_INDEX_WRITEMASK = 3105;
public static final int GL_COLOR_CLEAR_VALUE = 3106;
public static final int GL_COLOR_WRITEMASK = 3107;
public static final int GL_INDEX_MODE = 3120;
public static final int GL_RGBA_MODE = 3121;
public static final int GL_DOUBLEBUFFER = 3122;
public static final int GL_STEREO = 3123;
public static final int GL_RENDER_MODE = 3136;
public static final int GL_PERSPECTIVE_CORRECTION_HINT = 3152;
public static final int GL_POINT_SMOOTH_HINT = 3153;
public static final int GL_LINE_SMOOTH_HINT = 3154;
public static final int GL_POLYGON_SMOOTH_HINT = 3155;
public static final int GL_FOG_HINT = 3156;
public static final int GL_TEXTURE_GEN_S = 3168;
public static final int GL_TEXTURE_GEN_T = 3169;
public static final int GL_TEXTURE_GEN_R = 3170;
public static final int GL_TEXTURE_GEN_Q = 3171;
public static final int GL_PIXEL_MAP_I_TO_I = 3184;
public static final int GL_PIXEL_MAP_S_TO_S = 3185;
public static final int GL_PIXEL_MAP_I_TO_R = 3186;
public static final int GL_PIXEL_MAP_I_TO_G = 3187;
public static final int GL_PIXEL_MAP_I_TO_B = 3188;
public static final int GL_PIXEL_MAP_I_TO_A = 3189;
public static final int GL_PIXEL_MAP_R_TO_R = 3190;
public static final int GL_PIXEL_MAP_G_TO_G = 3191;
public static final int GL_PIXEL_MAP_B_TO_B = 3192;
public static final int GL_PIXEL_MAP_A_TO_A = 3193;
public static final int GL_PIXEL_MAP_I_TO_I_SIZE = 3248;
public static final int GL_PIXEL_MAP_S_TO_S_SIZE = 3249;
public static final int GL_PIXEL_MAP_I_TO_R_SIZE = 3250;
public static final int GL_PIXEL_MAP_I_TO_G_SIZE = 3251;
public static final int GL_PIXEL_MAP_I_TO_B_SIZE = 3252;
public static final int GL_PIXEL_MAP_I_TO_A_SIZE = 3253;
public static final int GL_PIXEL_MAP_R_TO_R_SIZE = 3254;
public static final int GL_PIXEL_MAP_G_TO_G_SIZE = 3255;
public static final int GL_PIXEL_MAP_B_TO_B_SIZE = 3256;
public static final int GL_PIXEL_MAP_A_TO_A_SIZE = 3257;
public static final int GL_UNPACK_SWAP_BYTES = 3312;
public static final int GL_UNPACK_LSB_FIRST = 3313;
public static final int GL_UNPACK_ROW_LENGTH = 3314;
public static final int GL_UNPACK_SKIP_ROWS = 3315;
public static final int GL_UNPACK_SKIP_PIXELS = 3316;
public static final int GL_UNPACK_ALIGNMENT = 3317;
public static final int GL_PACK_SWAP_BYTES = 3328;
public static final int GL_PACK_LSB_FIRST = 3329;
public static final int GL_PACK_ROW_LENGTH = 3330;
public static final int GL_PACK_SKIP_ROWS = 3331;
public static final int GL_PACK_SKIP_PIXELS = 3332;
public static final int GL_PACK_ALIGNMENT = 3333;
public static final int GL_MAP_COLOR = 3344;
public static final int GL_MAP_STENCIL = 3345;
public static final int GL_INDEX_SHIFT = 3346;
public static final int GL_INDEX_OFFSET = 3347;
public static final int GL_RED_SCALE = 3348;
public static final int GL_RED_BIAS = 3349;
public static final int GL_ZOOM_X = 3350;
public static final int GL_ZOOM_Y = 3351;
public static final int GL_GREEN_SCALE = 3352;
public static final int GL_GREEN_BIAS = 3353;
public static final int GL_BLUE_SCALE = 3354;
public static final int GL_BLUE_BIAS = 3355;
public static final int GL_ALPHA_SCALE = 3356;
public static final int GL_ALPHA_BIAS = 3357;
public static final int GL_DEPTH_SCALE = 3358;
public static final int GL_DEPTH_BIAS = 3359;
public static final int GL_MAX_EVAL_ORDER = 3376;
public static final int GL_MAX_LIGHTS = 3377;
public static final int GL_MAX_CLIP_PLANES = 3378;
public static final int GL_MAX_TEXTURE_SIZE = 3379;
public static final int GL_MAX_PIXEL_MAP_TABLE = 3380;
public static final int GL_MAX_ATTRIB_STACK_DEPTH = 3381;
public static final int GL_MAX_MODELVIEW_STACK_DEPTH = 3382;
public static final int GL_MAX_NAME_STACK_DEPTH = 3383;
public static final int GL_MAX_PROJECTION_STACK_DEPTH = 3384;
public static final int GL_MAX_TEXTURE_STACK_DEPTH = 3385;
public static final int GL_MAX_VIEWPORT_DIMS = 3386;
public static final int GL_MAX_CLIENT_ATTRIB_STACK_DEPTH = 3387;
public static final int GL_SUBPIXEL_BITS = 3408;
public static final int GL_INDEX_BITS = 3409;
public static final int GL_RED_BITS = 3410;
public static final int GL_GREEN_BITS = 3411;
public static final int GL_BLUE_BITS = 3412;
public static final int GL_ALPHA_BITS = 3413;
public static final int GL_DEPTH_BITS = 3414;
public static final int GL_STENCIL_BITS = 3415;
public static final int GL_ACCUM_RED_BITS = 3416;
public static final int GL_ACCUM_GREEN_BITS = 3417;
public static final int GL_ACCUM_BLUE_BITS = 3418;
public static final int GL_ACCUM_ALPHA_BITS = 3419;
public static final int GL_NAME_STACK_DEPTH = 3440;
public static final int GL_AUTO_NORMAL = 3456;
public static final int GL_MAP1_COLOR_4 = 3472;
public static final int GL_MAP1_INDEX = 3473;
public static final int GL_MAP1_NORMAL = 3474;
public static final int GL_MAP1_TEXTURE_COORD_1 = 3475;
public static final int GL_MAP1_TEXTURE_COORD_2 = 3476;
public static final int GL_MAP1_TEXTURE_COORD_3 = 3477;
public static final int GL_MAP1_TEXTURE_COORD_4 = 3478;
public static final int GL_MAP1_VERTEX_3 = 3479;
public static final int GL_MAP1_VERTEX_4 = 3480;
public static final int GL_MAP2_COLOR_4 = 3504;
public static final int GL_MAP2_INDEX = 3505;
public static final int GL_MAP2_NORMAL = 3506;
public static final int GL_MAP2_TEXTURE_COORD_1 = 3507;
public static final int GL_MAP2_TEXTURE_COORD_2 = 3508;
public static final int GL_MAP2_TEXTURE_COORD_3 = 3509;
public static final int GL_MAP2_TEXTURE_COORD_4 = 3510;
public static final int GL_MAP2_VERTEX_3 = 3511;
public static final int GL_MAP2_VERTEX_4 = 3512;
public static final int GL_MAP1_GRID_DOMAIN = 3536;
public static final int GL_MAP1_GRID_SEGMENTS = 3537;
public static final int GL_MAP2_GRID_DOMAIN = 3538;
public static final int GL_MAP2_GRID_SEGMENTS = 3539;
public static final int GL_TEXTURE_1D = 3552;
public static final int GL_TEXTURE_2D = 3553;
public static final int GL_FEEDBACK_BUFFER_POINTER = 3568;
public static final int GL_FEEDBACK_BUFFER_SIZE = 3569;
public static final int GL_FEEDBACK_BUFFER_TYPE = 3570;
public static final int GL_SELECTION_BUFFER_POINTER = 3571;
public static final int GL_SELECTION_BUFFER_SIZE = 3572;
public static final int GL_TEXTURE_WIDTH = 4096;
public static final int GL_TEXTURE_HEIGHT = 4097;
public static final int GL_TEXTURE_INTERNAL_FORMAT = 4099;
public static final int GL_TEXTURE_BORDER_COLOR = 4100;
public static final int GL_TEXTURE_BORDER = 4101;
public static final int GL_DONT_CARE = 4352;
public static final int GL_FASTEST = 4353;
public static final int GL_NICEST = 4354;
public static final int GL_LIGHT0 = 16384;
public static final int GL_LIGHT1 = 16385;
public static final int GL_LIGHT2 = 16386;
public static final int GL_LIGHT3 = 16387;
public static final int GL_LIGHT4 = 16388;
public static final int GL_LIGHT5 = 16389;
public static final int GL_LIGHT6 = 16390;
public static final int GL_LIGHT7 = 16391;
public static final int GL_AMBIENT = 4608;
public static final int GL_DIFFUSE = 4609;
public static final int GL_SPECULAR = 4610;
public static final int GL_POSITION = 4611;
public static final int GL_SPOT_DIRECTION = 4612;
public static final int GL_SPOT_EXPONENT = 4613;
public static final int GL_SPOT_CUTOFF = 4614;
public static final int GL_CONSTANT_ATTENUATION = 4615;
public static final int GL_LINEAR_ATTENUATION = 4616;
public static final int GL_QUADRATIC_ATTENUATION = 4617;
public static final int GL_COMPILE = 4864;
public static final int GL_COMPILE_AND_EXECUTE = 4865;
public static final int GL_CLEAR = 5376;
public static final int GL_AND = 5377;
public static final int GL_AND_REVERSE = 5378;
public static final int GL_COPY = 5379;
public static final int GL_AND_INVERTED = 5380;
public static final int GL_NOOP = 5381;
public static final int GL_XOR = 5382;
public static final int GL_OR = 5383;
public static final int GL_NOR = 5384;
public static final int GL_EQUIV = 5385;
public static final int GL_INVERT = 5386;
public static final int GL_OR_REVERSE = 5387;
public static final int GL_COPY_INVERTED = 5388;
public static final int GL_OR_INVERTED = 5389;
public static final int GL_NAND = 5390;
public static final int GL_SET = 5391;
public static final int GL_EMISSION = 5632;
public static final int GL_SHININESS = 5633;
public static final int GL_AMBIENT_AND_DIFFUSE = 5634;
public static final int GL_COLOR_INDEXES = 5635;
public static final int GL_MODELVIEW = 5888;
public static final int GL_PROJECTION = 5889;
public static final int GL_TEXTURE = 5890;
public static final int GL_COLOR = 6144;
public static final int GL_DEPTH = 6145;
public static final int GL_STENCIL = 6146;
public static final int GL_COLOR_INDEX = 6400;
public static final int GL_STENCIL_INDEX = 6401;
public static final int GL_DEPTH_COMPONENT = 6402;
public static final int GL_RED = 6403;
public static final int GL_GREEN = 6404;
public static final int GL_BLUE = 6405;
public static final int GL_ALPHA = 6406;
public static final int GL_RGB = 6407;
public static final int GL_RGBA = 6408;
public static final int GL_LUMINANCE = 6409;
public static final int GL_LUMINANCE_ALPHA = 6410;
public static final int GL_BITMAP = 6656;
public static final int GL_POINT = 6912;
public static final int GL_LINE = 6913;
public static final int GL_FILL = 6914;
public static final int GL_RENDER = 7168;
public static final int GL_FEEDBACK = 7169;
public static final int GL_SELECT = 7170;
public static final int GL_FLAT = 7424;
public static final int GL_SMOOTH = 7425;
public static final int GL_KEEP = 7680;
public static final int GL_REPLACE = 7681;
public static final int GL_INCR = 7682;
public static final int GL_DECR = 7683;
public static final int GL_VENDOR = 7936;
public static final int GL_RENDERER = 7937;
public static final int GL_VERSION = 7938;
public static final int GL_EXTENSIONS = 7939;
public static final int GL_S = 8192;
public static final int GL_T = 8193;
public static final int GL_R = 8194;
public static final int GL_Q = 8195;
public static final int GL_MODULATE = 8448;
public static final int GL_DECAL = 8449;
public static final int GL_TEXTURE_ENV_MODE = 8704;
public static final int GL_TEXTURE_ENV_COLOR = 8705;
public static final int GL_TEXTURE_ENV = 8960;
public static final int GL_EYE_LINEAR = 9216;
public static final int GL_OBJECT_LINEAR = 9217;
public static final int GL_SPHERE_MAP = 9218;
public static final int GL_TEXTURE_GEN_MODE = 9472;
public static final int GL_OBJECT_PLANE = 9473;
public static final int GL_EYE_PLANE = 9474;
public static final int GL_NEAREST = 9728;
public static final int GL_LINEAR = 9729;
public static final int GL_NEAREST_MIPMAP_NEAREST = 9984;
public static final int GL_LINEAR_MIPMAP_NEAREST = 9985;
public static final int GL_NEAREST_MIPMAP_LINEAR = 9986;
public static final int GL_LINEAR_MIPMAP_LINEAR = 9987;
public static final int GL_TEXTURE_MAG_FILTER = 10240;
public static final int GL_TEXTURE_MIN_FILTER = 10241;
public static final int GL_TEXTURE_WRAP_S = 10242;
public static final int GL_TEXTURE_WRAP_T = 10243;
public static final int GL_CLAMP = 10496;
public static final int GL_REPEAT = 10497;
public static final int GL_CLIENT_PIXEL_STORE_BIT = 1;
public static final int GL_CLIENT_VERTEX_ARRAY_BIT = 2;
public static final int GL_ALL_CLIENT_ATTRIB_BITS = -1;
public static final int GL_POLYGON_OFFSET_FACTOR = 32824;
public static final int GL_POLYGON_OFFSET_UNITS = 10752;
public static final int GL_POLYGON_OFFSET_POINT = 10753;
public static final int GL_POLYGON_OFFSET_LINE = 10754;
public static final int GL_POLYGON_OFFSET_FILL = 32823;
public static final int GL_ALPHA4 = 32827;
public static final int GL_ALPHA8 = 32828;
public static final int GL_ALPHA12 = 32829;
public static final int GL_ALPHA16 = 32830;
public static final int GL_LUMINANCE4 = 32831;
public static final int GL_LUMINANCE8 = 32832;
public static final int GL_LUMINANCE12 = 32833;
public static final int GL_LUMINANCE16 = 32834;
public static final int GL_LUMINANCE4_ALPHA4 = 32835;
public static final int GL_LUMINANCE6_ALPHA2 = 32836;
public static final int GL_LUMINANCE8_ALPHA8 = 32837;
public static final int GL_LUMINANCE12_ALPHA4 = 32838;
public static final int GL_LUMINANCE12_ALPHA12 = 32839;
public static final int GL_LUMINANCE16_ALPHA16 = 32840;
public static final int GL_INTENSITY = 32841;
public static final int GL_INTENSITY4 = 32842;
public static final int GL_INTENSITY8 = 32843;
public static final int GL_INTENSITY12 = 32844;
public static final int GL_INTENSITY16 = 32845;
public static final int GL_R3_G3_B2 = 10768;
public static final int GL_RGB4 = 32847;
public static final int GL_RGB5 = 32848;
public static final int GL_RGB8 = 32849;
public static final int GL_RGB10 = 32850;
public static final int GL_RGB12 = 32851;
public static final int GL_RGB16 = 32852;
public static final int GL_RGBA2 = 32853;
public static final int GL_RGBA4 = 32854;
public static final int GL_RGB5_A1 = 32855;
public static final int GL_RGBA8 = 32856;
public static final int GL_RGB10_A2 = 32857;
public static final int GL_RGBA12 = 32858;
public static final int GL_RGBA16 = 32859;
public static final int GL_TEXTURE_RED_SIZE = 32860;
public static final int GL_TEXTURE_GREEN_SIZE = 32861;
public static final int GL_TEXTURE_BLUE_SIZE = 32862;
public static final int GL_TEXTURE_ALPHA_SIZE = 32863;
public static final int GL_TEXTURE_LUMINANCE_SIZE = 32864;
public static final int GL_TEXTURE_INTENSITY_SIZE = 32865;
public static final int GL_PROXY_TEXTURE_1D = 32867;
public static final int GL_PROXY_TEXTURE_2D = 32868;
public static final int GL_TEXTURE_PRIORITY = 32870;
public static final int GL_TEXTURE_RESIDENT = 32871;
public static final int GL_TEXTURE_BINDING_1D = 32872;
public static final int GL_TEXTURE_BINDING_2D = 32873;
public static final int GL_VERTEX_ARRAY = 32884;
public static final int GL_NORMAL_ARRAY = 32885;
public static final int GL_COLOR_ARRAY = 32886;
public static final int GL_INDEX_ARRAY = 32887;
public static final int GL_TEXTURE_COORD_ARRAY = 32888;
public static final int GL_EDGE_FLAG_ARRAY = 32889;
public static final int GL_VERTEX_ARRAY_SIZE = 32890;
public static final int GL_VERTEX_ARRAY_TYPE = 32891;
public static final int GL_VERTEX_ARRAY_STRIDE = 32892;
public static final int GL_NORMAL_ARRAY_TYPE = 32894;
public static final int GL_NORMAL_ARRAY_STRIDE = 32895;
public static final int GL_COLOR_ARRAY_SIZE = 32897;
public static final int GL_COLOR_ARRAY_TYPE = 32898;
public static final int GL_COLOR_ARRAY_STRIDE = 32899;
public static final int GL_INDEX_ARRAY_TYPE = 32901;
public static final int GL_INDEX_ARRAY_STRIDE = 32902;
public static final int GL_TEXTURE_COORD_ARRAY_SIZE = 32904;
public static final int GL_TEXTURE_COORD_ARRAY_TYPE = 32905;
public static final int GL_TEXTURE_COORD_ARRAY_STRIDE = 32906;
public static final int GL_EDGE_FLAG_ARRAY_STRIDE = 32908;
public static final int GL_VERTEX_ARRAY_POINTER = 32910;
public static final int GL_NORMAL_ARRAY_POINTER = 32911;
public static final int GL_COLOR_ARRAY_POINTER = 32912;
public static final int GL_INDEX_ARRAY_POINTER = 32913;
public static final int GL_TEXTURE_COORD_ARRAY_POINTER = 32914;
public static final int GL_EDGE_FLAG_ARRAY_POINTER = 32915;
public static final int GL_V2F = 10784;
public static final int GL_V3F = 10785;
public static final int GL_C4UB_V2F = 10786;
public static final int GL_C4UB_V3F = 10787;
public static final int GL_C3F_V3F = 10788;
public static final int GL_N3F_V3F = 10789;
public static final int GL_C4F_N3F_V3F = 10790;
public static final int GL_T2F_V3F = 10791;
public static final int GL_T4F_V4F = 10792;
public static final int GL_T2F_C4UB_V3F = 10793;
public static final int GL_T2F_C3F_V3F = 10794;
public static final int GL_T2F_N3F_V3F = 10795;
public static final int GL_T2F_C4F_N3F_V3F = 10796;
public static final int GL_T4F_C4F_N3F_V4F = 10797;
public static final int GL_LOGIC_OP = 3057;
public static final int GL_TEXTURE_COMPONENTS = 4099;
public static final int GL_TEXTURE_BINDING_3D = 32874;
public static final int GL_PACK_SKIP_IMAGES = 32875;
public static final int GL_PACK_IMAGE_HEIGHT = 32876;
public static final int GL_UNPACK_SKIP_IMAGES = 32877;
public static final int GL_UNPACK_IMAGE_HEIGHT = 32878;
public static final int GL_TEXTURE_3D = 32879;
public static final int GL_PROXY_TEXTURE_3D = 32880;
public static final int GL_TEXTURE_DEPTH = 32881;
public static final int GL_TEXTURE_WRAP_R = 32882;
public static final int GL_MAX_3D_TEXTURE_SIZE = 32883;
public static final int GL_BGR = 32992;
public static final int GL_BGRA = 32993;
public static final int GL_UNSIGNED_BYTE_3_3_2 = 32818;
public static final int GL_UNSIGNED_BYTE_2_3_3_REV = 33634;
public static final int GL_UNSIGNED_SHORT_5_6_5 = 33635;
public static final int GL_UNSIGNED_SHORT_5_6_5_REV = 33636;
public static final int GL_UNSIGNED_SHORT_4_4_4_4 = 32819;
public static final int GL_UNSIGNED_SHORT_4_4_4_4_REV = 33637;
public static final int GL_UNSIGNED_SHORT_5_5_5_1 = 32820;
public static final int GL_UNSIGNED_SHORT_1_5_5_5_REV = 33638;
public static final int GL_UNSIGNED_INT_8_8_8_8 = 32821;
public static final int GL_UNSIGNED_INT_8_8_8_8_REV = 33639;
public static final int GL_UNSIGNED_INT_10_10_10_2 = 32822;
public static final int GL_UNSIGNED_INT_2_10_10_10_REV = 33640;
public static final int GL_RESCALE_NORMAL = 32826;
public static final int GL_LIGHT_MODEL_COLOR_CONTROL = 33272;
public static final int GL_SINGLE_COLOR = 33273;
public static final int GL_SEPARATE_SPECULAR_COLOR = 33274;
public static final int GL_CLAMP_TO_EDGE = 33071;
public static final int GL_TEXTURE_MIN_LOD = 33082;
public static final int GL_TEXTURE_MAX_LOD = 33083;
public static final int GL_TEXTURE_BASE_LEVEL = 33084;
public static final int GL_TEXTURE_MAX_LEVEL = 33085;
public static final int GL_MAX_ELEMENTS_VERTICES = 33000;
public static final int GL_MAX_ELEMENTS_INDICES = 33001;
public static final int GL_ALIASED_POINT_SIZE_RANGE = 33901;
public static final int GL_ALIASED_LINE_WIDTH_RANGE = 33902;
public static final int GL_SMOOTH_POINT_SIZE_RANGE = 2834;
public static final int GL_SMOOTH_POINT_SIZE_GRANULARITY = 2835;
public static final int GL_SMOOTH_LINE_WIDTH_RANGE = 2850;
public static final int GL_SMOOTH_LINE_WIDTH_GRANULARITY = 2851;
public static final int GL_TEXTURE0 = 33984;
public static final int GL_TEXTURE1 = 33985;
public static final int GL_TEXTURE2 = 33986;
public static final int GL_TEXTURE3 = 33987;
public static final int GL_TEXTURE4 = 33988;
public static final int GL_TEXTURE5 = 33989;
public static final int GL_TEXTURE6 = 33990;
public static final int GL_TEXTURE7 = 33991;
public static final int GL_TEXTURE8 = 33992;
public static final int GL_TEXTURE9 = 33993;
public static final int GL_TEXTURE10 = 33994;
public static final int GL_TEXTURE11 = 33995;
public static final int GL_TEXTURE12 = 33996;
public static final int GL_TEXTURE13 = 33997;
public static final int GL_TEXTURE14 = 33998;
public static final int GL_TEXTURE15 = 33999;
public static final int GL_TEXTURE16 = 34000;
public static final int GL_TEXTURE17 = 34001;
public static final int GL_TEXTURE18 = 34002;
public static final int GL_TEXTURE19 = 34003;
public static final int GL_TEXTURE20 = 34004;
public static final int GL_TEXTURE21 = 34005;
public static final int GL_TEXTURE22 = 34006;
public static final int GL_TEXTURE23 = 34007;
public static final int GL_TEXTURE24 = 34008;
public static final int GL_TEXTURE25 = 34009;
public static final int GL_TEXTURE26 = 34010;
public static final int GL_TEXTURE27 = 34011;
public static final int GL_TEXTURE28 = 34012;
public static final int GL_TEXTURE29 = 34013;
public static final int GL_TEXTURE30 = 34014;
public static final int GL_TEXTURE31 = 34015;
public static final int GL_ACTIVE_TEXTURE = 34016;
public static final int GL_CLIENT_ACTIVE_TEXTURE = 34017;
public static final int GL_MAX_TEXTURE_UNITS = 34018;
public static final int GL_NORMAL_MAP = 34065;
public static final int GL_REFLECTION_MAP = 34066;
public static final int GL_TEXTURE_CUBE_MAP = 34067;
public static final int GL_TEXTURE_BINDING_CUBE_MAP = 34068;
public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_X = 34069;
public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 34070;
public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 34071;
public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 34072;
public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 34073;
public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 34074;
public static final int GL_PROXY_TEXTURE_CUBE_MAP = 34075;
public static final int GL_MAX_CUBE_MAP_TEXTURE_SIZE = 34076;
public static final int GL_COMPRESSED_ALPHA = 34025;
public static final int GL_COMPRESSED_LUMINANCE = 34026;
public static final int GL_COMPRESSED_LUMINANCE_ALPHA = 34027;
public static final int GL_COMPRESSED_INTENSITY = 34028;
public static final int GL_COMPRESSED_RGB = 34029;
public static final int GL_COMPRESSED_RGBA = 34030;
public static final int GL_TEXTURE_COMPRESSION_HINT = 34031;
public static final int GL_TEXTURE_COMPRESSED_IMAGE_SIZE = 34464;
public static final int GL_TEXTURE_COMPRESSED = 34465;
public static final int GL_NUM_COMPRESSED_TEXTURE_FORMATS = 34466;
public static final int GL_COMPRESSED_TEXTURE_FORMATS = 34467;
public static final int GL_MULTISAMPLE = 32925;
public static final int GL_SAMPLE_ALPHA_TO_COVERAGE = 32926;
public static final int GL_SAMPLE_ALPHA_TO_ONE = 32927;
public static final int GL_SAMPLE_COVERAGE = 32928;
public static final int GL_SAMPLE_BUFFERS = 32936;
public static final int GL_SAMPLES = 32937;
public static final int GL_SAMPLE_COVERAGE_VALUE = 32938;
public static final int GL_SAMPLE_COVERAGE_INVERT = 32939;
public static final int GL_MULTISAMPLE_BIT = 536870912;
public static final int GL_TRANSPOSE_MODELVIEW_MATRIX = 34019;
public static final int GL_TRANSPOSE_PROJECTION_MATRIX = 34020;
public static final int GL_TRANSPOSE_TEXTURE_MATRIX = 34021;
public static final int GL_TRANSPOSE_COLOR_MATRIX = 34022;
public static final int GL_COMBINE = 34160;
public static final int GL_COMBINE_RGB = 34161;
public static final int GL_COMBINE_ALPHA = 34162;
public static final int GL_SOURCE0_RGB = 34176;
public static final int GL_SOURCE1_RGB = 34177;
public static final int GL_SOURCE2_RGB = 34178;
public static final int GL_SOURCE0_ALPHA = 34184;
public static final int GL_SOURCE1_ALPHA = 34185;
public static final int GL_SOURCE2_ALPHA = 34186;
public static final int GL_OPERAND0_RGB = 34192;
public static final int GL_OPERAND1_RGB = 34193;
public static final int GL_OPERAND2_RGB = 34194;
public static final int GL_OPERAND0_ALPHA = 34200;
public static final int GL_OPERAND1_ALPHA = 34201;
public static final int GL_OPERAND2_ALPHA = 34202;
public static final int GL_RGB_SCALE = 34163;
public static final int GL_ADD_SIGNED = 34164;
public static final int GL_INTERPOLATE = 34165;
public static final int GL_SUBTRACT = 34023;
public static final int GL_CONSTANT = 34166;
public static final int GL_PRIMARY_COLOR = 34167;
public static final int GL_PREVIOUS = 34168;
public static final int GL_DOT3_RGB = 34478;
public static final int GL_DOT3_RGBA = 34479;
public static final int GL_CLAMP_TO_BORDER = 33069;
public static final int GL_ARRAY_BUFFER = 34962;
public static final int GL_ELEMENT_ARRAY_BUFFER = 34963;
public static final int GL_ARRAY_BUFFER_BINDING = 34964;
public static final int GL_ELEMENT_ARRAY_BUFFER_BINDING = 34965;
public static final int GL_VERTEX_ARRAY_BUFFER_BINDING = 34966;
public static final int GL_NORMAL_ARRAY_BUFFER_BINDING = 34967;
public static final int GL_COLOR_ARRAY_BUFFER_BINDING = 34968;
public static final int GL_INDEX_ARRAY_BUFFER_BINDING = 34969;
public static final int GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING = 34970;
public static final int GL_EDGE_FLAG_ARRAY_BUFFER_BINDING = 34971;
public static final int GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING = 34972;
public static final int GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING = 34973;
public static final int GL_WEIGHT_ARRAY_BUFFER_BINDING = 34974;
public static final int GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 34975;
public static final int GL_STREAM_DRAW = 35040;
public static final int GL_STREAM_READ = 35041;
public static final int GL_STREAM_COPY = 35042;
public static final int GL_STATIC_DRAW = 35044;
public static final int GL_STATIC_READ = 35045;
public static final int GL_STATIC_COPY = 35046;
public static final int GL_DYNAMIC_DRAW = 35048;
public static final int GL_DYNAMIC_READ = 35049;
public static final int GL_DYNAMIC_COPY = 35050;
public static final int GL_READ_ONLY = 35000;
public static final int GL_WRITE_ONLY = 35001;
public static final int GL_READ_WRITE = 35002;
public static final int GL_BUFFER_SIZE = 34660;
public static final int GL_BUFFER_USAGE = 34661;
public static final int GL_BUFFER_ACCESS = 35003;
public static final int GL_BUFFER_MAPPED = 35004;
public static final int GL_BUFFER_MAP_POINTER = 35005;
public static final int GL_FOG_COORD_SRC = 33872;
public static final int GL_FOG_COORD = 33873;
public static final int GL_CURRENT_FOG_COORD = 33875;
public static final int GL_FOG_COORD_ARRAY_TYPE = 33876;
public static final int GL_FOG_COORD_ARRAY_STRIDE = 33877;
public static final int GL_FOG_COORD_ARRAY_POINTER = 33878;
public static final int GL_FOG_COORD_ARRAY = 33879;
public static final int GL_FOG_COORD_ARRAY_BUFFER_BINDING = 34973;
public static final int GL_SRC0_RGB = 34176;
public static final int GL_SRC1_RGB = 34177;
public static final int GL_SRC2_RGB = 34178;
public static final int GL_SRC0_ALPHA = 34184;
public static final int GL_SRC1_ALPHA = 34185;
public static final int GL_SRC2_ALPHA = 34186;
public static final int GL_SAMPLES_PASSED = 35092;
public static final int GL_QUERY_COUNTER_BITS = 34916;
public static final int GL_CURRENT_QUERY = 34917;
public static final int GL_QUERY_RESULT = 34918;
public static final int GL_QUERY_RESULT_AVAILABLE = 34919;
public static final int GL_SHADING_LANGUAGE_VERSION = 35724;
public static final int GL_CURRENT_PROGRAM = 35725;
public static final int GL_SHADER_TYPE = 35663;
public static final int GL_DELETE_STATUS = 35712;
public static final int GL_COMPILE_STATUS = 35713;
public static final int GL_LINK_STATUS = 35714;
public static final int GL_VALIDATE_STATUS = 35715;
public static final int GL_INFO_LOG_LENGTH = 35716;
public static final int GL_ATTACHED_SHADERS = 35717;
public static final int GL_ACTIVE_UNIFORMS = 35718;
public static final int GL_ACTIVE_UNIFORM_MAX_LENGTH = 35719;
public static final int GL_ACTIVE_ATTRIBUTES = 35721;
public static final int GL_ACTIVE_ATTRIBUTE_MAX_LENGTH = 35722;
public static final int GL_SHADER_SOURCE_LENGTH = 35720;
public static final int GL_SHADER_OBJECT = 35656;
public static final int GL_FLOAT_VEC2 = 35664;
public static final int GL_FLOAT_VEC3 = 35665;
public static final int GL_FLOAT_VEC4 = 35666;
public static final int GL_INT_VEC2 = 35667;
public static final int GL_INT_VEC3 = 35668;
public static final int GL_INT_VEC4 = 35669;
public static final int GL_BOOL = 35670;
public static final int GL_BOOL_VEC2 = 35671;
public static final int GL_BOOL_VEC3 = 35672;
public static final int GL_BOOL_VEC4 = 35673;
public static final int GL_FLOAT_MAT2 = 35674;
public static final int GL_FLOAT_MAT3 = 35675;
public static final int GL_FLOAT_MAT4 = 35676;
public static final int GL_SAMPLER_1D = 35677;
public static final int GL_SAMPLER_2D = 35678;
public static final int GL_SAMPLER_3D = 35679;
public static final int GL_SAMPLER_CUBE = 35680;
public static final int GL_SAMPLER_1D_SHADOW = 35681;
public static final int GL_SAMPLER_2D_SHADOW = 35682;
public static final int GL_VERTEX_SHADER = 35633;
public static final int GL_MAX_VERTEX_UNIFORM_COMPONENTS = 35658;
public static final int GL_MAX_VARYING_FLOATS = 35659;
public static final int GL_MAX_VERTEX_ATTRIBS = 34921;
public static final int GL_MAX_TEXTURE_IMAGE_UNITS = 34930;
public static final int GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 35660;
public static final int GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = 35661;
public static final int GL_MAX_TEXTURE_COORDS = 34929;
public static final int GL_VERTEX_PROGRAM_POINT_SIZE = 34370;
public static final int GL_VERTEX_PROGRAM_TWO_SIDE = 34371;
public static final int GL_VERTEX_ATTRIB_ARRAY_ENABLED = 34338;
public static final int GL_VERTEX_ATTRIB_ARRAY_SIZE = 34339;
public static final int GL_VERTEX_ATTRIB_ARRAY_STRIDE = 34340;
public static final int GL_VERTEX_ATTRIB_ARRAY_TYPE = 34341;
public static final int GL_VERTEX_ATTRIB_ARRAY_NORMALIZED = 34922;
public static final int GL_CURRENT_VERTEX_ATTRIB = 34342;
public static final int GL_VERTEX_ATTRIB_ARRAY_POINTER = 34373;
public static final int GL_FRAGMENT_SHADER = 35632;
public static final int GL_MAX_FRAGMENT_UNIFORM_COMPONENTS = 35657;
public static final int GL_FRAGMENT_SHADER_DERIVATIVE_HINT = 35723;
public static final int GL_MAX_DRAW_BUFFERS = 34852;
public static final int GL_DRAW_BUFFER0 = 34853;
public static final int GL_DRAW_BUFFER1 = 34854;
public static final int GL_DRAW_BUFFER2 = 34855;
public static final int GL_DRAW_BUFFER3 = 34856;
public static final int GL_DRAW_BUFFER4 = 34857;
public static final int GL_DRAW_BUFFER5 = 34858;
public static final int GL_DRAW_BUFFER6 = 34859;
public static final int GL_DRAW_BUFFER7 = 34860;
public static final int GL_DRAW_BUFFER8 = 34861;
public static final int GL_DRAW_BUFFER9 = 34862;
public static final int GL_DRAW_BUFFER10 = 34863;
public static final int GL_DRAW_BUFFER11 = 34864;
public static final int GL_DRAW_BUFFER12 = 34865;
public static final int GL_DRAW_BUFFER13 = 34866;
public static final int GL_DRAW_BUFFER14 = 34867;
public static final int GL_DRAW_BUFFER15 = 34868;
public static final int GL_POINT_SPRITE = 34913;
public static final int GL_COORD_REPLACE = 34914;
public static final int GL_POINT_SPRITE_COORD_ORIGIN = 36000;
public static final int GL_LOWER_LEFT = 36001;
public static final int GL_UPPER_LEFT = 36002;
public static final int GL_STENCIL_BACK_FUNC = 34816;
public static final int GL_STENCIL_BACK_FAIL = 34817;
public static final int GL_STENCIL_BACK_PASS_DEPTH_FAIL = 34818;
public static final int GL_STENCIL_BACK_PASS_DEPTH_PASS = 34819;
public static final int GL_STENCIL_BACK_REF = 36003;
public static final int GL_STENCIL_BACK_VALUE_MASK = 36004;
public static final int GL_STENCIL_BACK_WRITEMASK = 36005;
public static final int GL_BLEND_EQUATION_RGB = 32777;
public static final int GL_BLEND_EQUATION_ALPHA = 34877;
public static final int GL_TEXTURE_MAX_ANISOTROPY = 34046;
public static final int GL_CONTEXT_LOST_WEBGL = -100;
}

View File

@ -0,0 +1,230 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
import net.lax1dude.eaglercraft.v1_8.vector.Matrix3f;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class SpriteLevelMixer {
private static final Logger LOGGER = LogManager.getLogger("SpriteLevelMixer");
public static final String vertexShaderPath = "/assets/eagler/glsl/local.vsh";
public static final String fragmentShaderPath = "/assets/eagler/glsl/texture_mix.fsh";
private static IBufferGL vertexBuffer = null;
private static IBufferArrayGL vertexArray = null;
private static IProgramGL shaderProgram = null;
private static IUniformGL u_textureLod1f = null;
private static IUniformGL u_blendFactor4f = null;
private static IUniformGL u_blendBias4f = null;
private static IUniformGL u_matrixTransform = null;
private static FloatBuffer matrixCopyBuffer = null;
private static boolean blendColorChanged = true;
private static float blendColorR = 1.0f;
private static float blendColorG = 1.0f;
private static float blendColorB = 1.0f;
private static float blendColorA = 1.0f;
private static boolean biasColorChanged = true;
private static float biasColorR = 0.0f;
private static float biasColorG = 0.0f;
private static float biasColorB = 0.0f;
private static float biasColorA = 0.0f;
private static boolean matrixChanged = true;
private static final Matrix3f transformMatrix = new Matrix3f();
private static final Matrix3f identityMatrix = new Matrix3f();
static void initialize() {
String vertexSource = EagRuntime.getResourceString(vertexShaderPath);
if(vertexSource == null) {
throw new RuntimeException("SpriteLevelMixer shader \"" + vertexShaderPath + "\" is missing!");
}
String fragmentSource = EagRuntime.getResourceString(fragmentShaderPath);
if(fragmentSource == null) {
throw new RuntimeException("SpriteLevelMixer shader \"" + fragmentShaderPath + "\" is missing!");
}
IShaderGL vert = _wglCreateShader(GL_VERTEX_SHADER);
IShaderGL frag = _wglCreateShader(GL_FRAGMENT_SHADER);
_wglShaderSource(vert, FixedFunctionConstants.VERSION + "\n" + vertexSource);
_wglCompileShader(vert);
if(_wglGetShaderi(vert, GL_COMPILE_STATUS) != GL_TRUE) {
LOGGER.error("Failed to compile GL_VERTEX_SHADER \"" + vertexShaderPath + "\" for SpriteLevelMixer!");
String log = _wglGetShaderInfoLog(vert);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
LOGGER.error("[VERT] {}", lines[i]);
}
}
throw new IllegalStateException("Vertex shader \"" + vertexShaderPath + "\" could not be compiled!");
}
_wglShaderSource(frag, FixedFunctionConstants.VERSION + "\n" + fragmentSource);
_wglCompileShader(frag);
if(_wglGetShaderi(frag, GL_COMPILE_STATUS) != GL_TRUE) {
LOGGER.error("Failed to compile GL_FRAGMENT_SHADER \"" + fragmentShaderPath + "\" for SpriteLevelMixer!");
String log = _wglGetShaderInfoLog(frag);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
LOGGER.error("[FRAG] {}", lines[i]);
}
}
throw new IllegalStateException("Fragment shader \"" + fragmentShaderPath + "\" could not be compiled!");
}
shaderProgram = _wglCreateProgram();
_wglAttachShader(shaderProgram, vert);
_wglAttachShader(shaderProgram, frag);
_wglBindAttribLocation(shaderProgram, 0, "a_position2f");
_wglLinkProgram(shaderProgram);
_wglDetachShader(shaderProgram, vert);
_wglDetachShader(shaderProgram, frag);
_wglDeleteShader(vert);
_wglDeleteShader(frag);
if(_wglGetProgrami(shaderProgram, GL_LINK_STATUS) != GL_TRUE) {
LOGGER.error("Failed to link shader program for SpriteLevelMixer!");
String log = _wglGetProgramInfoLog(shaderProgram);
if(log != null) {
String[] lines = log.split("(\\r\\n|\\r|\\n)");
for(int i = 0; i < lines.length; ++i) {
LOGGER.error("[LINK] {}", lines[i]);
}
}
throw new IllegalStateException("Shader program for SpriteLevelMixer could not be linked!");
}
matrixCopyBuffer = EagRuntime.allocateFloatBuffer(9);
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
u_textureLod1f = _wglGetUniformLocation(shaderProgram, "u_textureLod1f");
u_blendFactor4f = _wglGetUniformLocation(shaderProgram, "u_blendFactor4f");
u_blendBias4f = _wglGetUniformLocation(shaderProgram, "u_blendBias4f");
u_matrixTransform = _wglGetUniformLocation(shaderProgram, "u_matrixTransform");
_wglUniform1i(_wglGetUniformLocation(shaderProgram, "u_inputTexture"), 0);
vertexArray = _wglGenVertexArrays();
vertexBuffer = _wglGenBuffers();
FloatBuffer verts = EagRuntime.allocateFloatBuffer(12);
verts.put(new float[] {
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f
});
verts.flip();
EaglercraftGPU.bindGLBufferArray(vertexArray);
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
_wglBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
EagRuntime.freeFloatBuffer(verts);
_wglEnableVertexAttribArray(0);
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 8, 0);
}
public static void setBlendColor(float r, float g, float b, float a) {
if(r != blendColorR || g != blendColorG || b != blendColorB || a != blendColorA) {
blendColorChanged = true;
blendColorR = r;
blendColorG = g;
blendColorB = b;
blendColorA = a;
}
}
public static void setBiasColor(float r, float g, float b, float a) {
if(r != biasColorR || g != biasColorG || b != biasColorB || a != biasColorA) {
biasColorChanged = true;
biasColorR = r;
biasColorG = g;
biasColorB = b;
biasColorA = a;
}
}
public static void setIdentityMatrix() {
setMatrix3f(identityMatrix);
}
public static void setMatrix3f(Matrix3f matrix) {
if(!matrix.equals(transformMatrix)) {
matrixChanged = true;
transformMatrix.load(matrix);
}
}
public static void drawSprite(float level) {
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
_wglUniform1f(u_textureLod1f, level);
if(blendColorChanged) {
_wglUniform4f(u_blendFactor4f, blendColorR, blendColorG, blendColorB, blendColorA);
blendColorChanged = false;
}
if(biasColorChanged) {
_wglUniform4f(u_blendBias4f, biasColorR, biasColorG, biasColorB, biasColorA);
biasColorChanged = false;
}
if(matrixChanged) {
matrixCopyBuffer.clear();
transformMatrix.store(matrixCopyBuffer);
matrixCopyBuffer.flip();
_wglUniformMatrix3fv(u_matrixTransform, false, matrixCopyBuffer);
matrixChanged = false;
}
EaglercraftGPU.bindGLBufferArray(vertexArray);
_wglDrawArrays(GL_TRIANGLES, 0, 6);
}
}

View File

@ -0,0 +1,199 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public enum VertexFormat {
BLOCK(true, true, false, true),
ITEM(true, true, true, false),
OLDMODEL_POSITION_TEX_NORMAL(true, false, true, false),
PARTICLE_POSITION_TEX_COLOR_LMAP(true, true, true, true),
POSITION(false, false, false, false),
POSITION_COLOR(false, true, false, false),
POSITION_TEX(true, false, false, false),
POSITION_NORMAL(false, false, true, false),
POSITION_TEX_COLOR(true, true, false, false),
POSITION_TEX_NORMAL(true, false, true, false),
POSITION_TEX_LMAP_COLOR(true, true, false, true),
POSITION_TEX_COLOR_NORMAL(true, true, true, false);
public static final int COMPONENT_POSITION_SIZE = 3;
public static final int COMPONENT_POSITION_FORMAT = GL_FLOAT;
public static final int COMPONENT_POSITION_STRIDE = 12;
public static final int COMPONENT_TEX_SIZE = 2;
public static final int COMPONENT_TEX_FORMAT = GL_FLOAT;
public static final int COMPONENT_TEX_STRIDE = 8;
public static final int COMPONENT_COLOR_SIZE = 4;
public static final int COMPONENT_COLOR_FORMAT = GL_UNSIGNED_BYTE;
public static final int COMPONENT_COLOR_STRIDE = 4;
public static final int COMPONENT_NORMAL_SIZE = 4;
public static final int COMPONENT_NORMAL_FORMAT = GL_BYTE;
public static final int COMPONENT_NORMAL_STRIDE = 4;
public static final int COMPONENT_LIGHTMAP_SIZE = 2;
public static final int COMPONENT_LIGHTMAP_FORMAT = GL_UNSIGNED_SHORT;
public static final int COMPONENT_LIGHTMAP_STRIDE = 4;
public final boolean attribPositionEnabled;
public final int attribPositionIndex;
public final int attribPositionOffset;
public final int attribPositionFormat;
public final boolean attribPositionNormalized;
public final int attribPositionSize;
public final int attribPositionStride;
public final boolean attribTextureEnabled;
public final int attribTextureIndex;
public final int attribTextureOffset;
public final int attribTextureFormat;
public final boolean attribTextureNormalized;
public final int attribTextureSize;
public final int attribTextureStride;
public final boolean attribColorEnabled;
public final int attribColorIndex;
public final int attribColorOffset;
public final int attribColorFormat;
public final boolean attribColorNormalized;
public final int attribColorSize;
public final int attribColorStride;
public final boolean attribNormalEnabled;
public final int attribNormalIndex;
public final int attribNormalOffset;
public final int attribNormalFormat;
public final boolean attribNormalNormalized;
public final int attribNormalSize;
public final int attribNormalStride;
public final boolean attribLightmapEnabled;
public final int attribLightmapIndex;
public final int attribLightmapOffset;
public final int attribLightmapFormat;
public final boolean attribLightmapNormalized;
public final int attribLightmapSize;
public final int attribLightmapStride;
public final int attribCount;
public final int attribStride;
public final int eaglercraftAttribBits;
private VertexFormat(boolean texture, boolean color, boolean normal, boolean lightmap) {
int index = 0;
int bytes = 0;
int bitfield = 0;
attribPositionEnabled = true;
attribPositionIndex = index++;
attribPositionOffset = bytes;
attribPositionFormat = COMPONENT_POSITION_FORMAT;
attribPositionNormalized = false;
attribPositionSize = COMPONENT_POSITION_SIZE;
attribPositionStride = COMPONENT_POSITION_STRIDE;
bytes += COMPONENT_POSITION_STRIDE;
if(color) {
attribColorEnabled = true;
attribColorIndex = index++;
attribColorOffset = bytes;
attribColorFormat = COMPONENT_COLOR_FORMAT;
attribColorNormalized = true;
attribColorSize = COMPONENT_COLOR_SIZE;
attribColorStride = COMPONENT_COLOR_STRIDE;
bytes += COMPONENT_COLOR_STRIDE;
bitfield |= EaglercraftGPU.ATTRIB_COLOR;
}else {
attribColorEnabled = false;
attribColorIndex = -1;
attribColorOffset = -1;
attribColorFormat = -1;
attribColorNormalized = false;
attribColorSize = -1;
attribColorStride = -1;
}
if(texture) {
attribTextureEnabled = true;
attribTextureIndex = index++;
attribTextureOffset = bytes;
attribTextureFormat = COMPONENT_TEX_FORMAT;
attribTextureNormalized = false;
attribTextureSize = COMPONENT_TEX_SIZE;
attribTextureStride = COMPONENT_TEX_STRIDE;
bytes += COMPONENT_TEX_STRIDE;
bitfield |= EaglercraftGPU.ATTRIB_TEXTURE;
}else {
attribTextureEnabled = false;
attribTextureIndex = -1;
attribTextureOffset = -1;
attribTextureFormat = -1;
attribTextureNormalized = false;
attribTextureSize = -1;
attribTextureStride = -1;
}
if(normal) {
attribNormalEnabled = true;
attribNormalIndex = index++;
attribNormalOffset = bytes;
attribNormalFormat = COMPONENT_NORMAL_FORMAT;
attribNormalNormalized = true;
attribNormalSize = COMPONENT_NORMAL_SIZE;
attribNormalStride = COMPONENT_NORMAL_STRIDE;
bytes += COMPONENT_NORMAL_STRIDE;
bitfield |= EaglercraftGPU.ATTRIB_NORMAL;
}else {
attribNormalEnabled = false;
attribNormalIndex = -1;
attribNormalOffset = -1;
attribNormalFormat = -1;
attribNormalNormalized = false;
attribNormalSize = -1;
attribNormalStride = -1;
}
if(lightmap) {
attribLightmapEnabled = true;
attribLightmapIndex = index++;
attribLightmapOffset = bytes;
attribLightmapFormat = COMPONENT_LIGHTMAP_FORMAT;
attribLightmapNormalized = false;
attribLightmapSize = COMPONENT_LIGHTMAP_SIZE;
attribLightmapStride = COMPONENT_LIGHTMAP_STRIDE;
bytes += COMPONENT_LIGHTMAP_STRIDE;
bitfield |= EaglercraftGPU.ATTRIB_LIGHTMAP;
}else {
attribLightmapEnabled = false;
attribLightmapIndex = -1;
attribLightmapOffset = -1;
attribLightmapFormat = -1;
attribLightmapNormalized = false;
attribLightmapSize = -1;
attribLightmapStride = -1;
}
attribCount = index;
attribStride = bytes;
eaglercraftAttribBits = bitfield;
}
}

View File

@ -0,0 +1,464 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.IntBuffer;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformBufferFunctions;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.util.MathHelper;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class WorldRenderer {
private boolean needsUpdate;
private int drawMode;
private double xOffset;
private double yOffset;
private double zOffset;
private boolean isDrawing;
private VertexFormat vertexFormat;
private int vertexCount;
private ByteBuffer byteBuffer;
private IntBuffer intBuffer;
private FloatBuffer floatBuffer;
private boolean hasBeenFreed = false;
public WorldRenderer(int bufferSizeIn) {
this.byteBuffer = GLAllocation.createDirectByteBuffer(bufferSizeIn << 2);
this.intBuffer = this.byteBuffer.asIntBuffer();
this.floatBuffer = this.byteBuffer.asFloatBuffer();
}
public void free() {
if(!hasBeenFreed) {
hasBeenFreed = true;
EagRuntime.freeByteBuffer(byteBuffer);
}
}
public void finalize() {
free();
}
private void grow(int parInt1) {
int pos = (this.vertexCount * this.vertexFormat.attribStride) >> 2;
int i = this.byteBuffer.capacity() >> 2;
if (parInt1 > (i - pos)) {
int k = (((pos + parInt1 + (parInt1 >> 1)) >> 16) + 1) << 16;
LogManager.getLogger() .warn("Needed to grow BufferBuilder buffer: Old size " + (i << 2) +
" bytes, new size " + (k << 2) + " bytes.");
ByteBuffer bytebuffer = GLAllocation.createDirectByteBuffer(k << 2);
this.byteBuffer.position(0);
bytebuffer.put(this.byteBuffer);
bytebuffer.rewind();
EagRuntime.freeByteBuffer(this.byteBuffer);
this.byteBuffer = bytebuffer;
this.intBuffer = this.byteBuffer.asIntBuffer();
this.floatBuffer = this.byteBuffer.asFloatBuffer();
}
}
/**
* MOST LIKELY USED TO SORT QUADS BACK TO FRONT
*/
public void func_181674_a(float parFloat1, float parFloat2, float parFloat3) {
int i = this.vertexCount / 4;
final float[] afloat = new float[i];
for (int j = 0; j < i; ++j) {
afloat[j] = func_181665_a(this.floatBuffer, (float) ((double) parFloat1 + this.xOffset),
(float) ((double) parFloat2 + this.yOffset), (float) ((double) parFloat3 + this.zOffset),
this.vertexFormat.attribStride >> 2, j * this.vertexFormat.attribStride);
}
Integer[] ainteger = new Integer[i];
for (int k = 0; k < ainteger.length; ++k) {
ainteger[k] = Integer.valueOf(k);
}
Arrays.sort(ainteger, new Comparator<Integer>() {
public int compare(Integer integer, Integer integer1) {
return Float.compare(afloat[integer1.intValue()], afloat[integer.intValue()]);
}
});
BitSet bitset = new BitSet();
int l = this.vertexFormat.attribStride;
int[] aint = new int[l];
for (int l1 = 0; (l1 = bitset.nextClearBit(l1)) < ainteger.length; ++l1) {
int i1 = ainteger[l1].intValue();
if (i1 != l1) {
this.intBuffer.limit(i1 * l + l);
this.intBuffer.position(i1 * l);
this.intBuffer.get(aint);
int j1 = i1;
for (int k1 = ainteger[i1].intValue(); j1 != l1; k1 = ainteger[k1].intValue()) {
this.intBuffer.limit(k1 * l + l);
this.intBuffer.position(k1 * l);
IntBuffer intbuffer = this.intBuffer.slice();
this.intBuffer.limit(j1 * l + l);
this.intBuffer.position(j1 * l);
this.intBuffer.put(intbuffer);
bitset.set(j1);
j1 = k1;
}
this.intBuffer.limit(l1 * l + l);
this.intBuffer.position(l1 * l);
this.intBuffer.put(aint);
}
bitset.set(l1);
this.intBuffer.clear();
}
}
/**
* SLOW AND STUPID UPLOAD QUEUE SYSTEM, MUST BE REPLACED
*/
public WorldRenderer.State func_181672_a() {
this.intBuffer.position(0);
VertexFormat fmt = this.vertexFormat;
int i = (fmt.attribStride >> 2) * vertexCount;
this.intBuffer.limit(i);
int[] aint = new int[i];
this.intBuffer.get(aint);
return new WorldRenderer.State(aint, fmt);
}
/**
* MOST LIKELY A SLOW AND RETARDED WAY TO GET THE DISTANCE TO A QUAD
*/
private static float func_181665_a(FloatBuffer parFloatBuffer, float parFloat1, float parFloat2, float parFloat3,
int parInt1, int parInt2) {
float f = parFloatBuffer.get(parInt2 + parInt1 * 0 + 0);
float f1 = parFloatBuffer.get(parInt2 + parInt1 * 0 + 1);
float f2 = parFloatBuffer.get(parInt2 + parInt1 * 0 + 2);
float f3 = parFloatBuffer.get(parInt2 + parInt1 * 1 + 0);
float f4 = parFloatBuffer.get(parInt2 + parInt1 * 1 + 1);
float f5 = parFloatBuffer.get(parInt2 + parInt1 * 1 + 2);
float f6 = parFloatBuffer.get(parInt2 + parInt1 * 2 + 0);
float f7 = parFloatBuffer.get(parInt2 + parInt1 * 2 + 1);
float f8 = parFloatBuffer.get(parInt2 + parInt1 * 2 + 2);
float f9 = parFloatBuffer.get(parInt2 + parInt1 * 3 + 0);
float f10 = parFloatBuffer.get(parInt2 + parInt1 * 3 + 1);
float f11 = parFloatBuffer.get(parInt2 + parInt1 * 3 + 2);
float f12 = (f + f3 + f6 + f9) * 0.25F - parFloat1;
float f13 = (f1 + f4 + f7 + f10) * 0.25F - parFloat2;
float f14 = (f2 + f5 + f8 + f11) * 0.25F - parFloat3;
return f12 * f12 + f13 * f13 + f14 * f14;
}
/**
* SLOW AND STUPID COMPANION FUNCTION TO 'func_181672_a'
*/
public void setVertexState(WorldRenderer.State state) {
this.grow(state.getRawBuffer().length);
PlatformBufferFunctions.put(this.intBuffer, 0, state.getRawBuffer());
this.vertexCount = state.getVertexCount();
this.vertexFormat = state.getVertexFormat();
}
public void reset() {
this.vertexCount = 0;
this.byteBuffer.clear();
this.intBuffer.clear();
}
public void begin(int parInt1, VertexFormat parVertexFormat) {
if (this.isDrawing) {
throw new IllegalStateException("WorldRenderer already building you eagler!");
} else {
this.isDrawing = true;
this.reset();
this.drawMode = parInt1;
this.vertexFormat = parVertexFormat;
this.needsUpdate = false;
this.byteBuffer.limit(this.byteBuffer.capacity());
}
}
public WorldRenderer tex(double parDouble1, double parDouble2) {
VertexFormat fmt = this.vertexFormat;
int i = this.vertexCount * fmt.attribStride + fmt.attribTextureOffset;
this.byteBuffer.putFloat(i, (float) parDouble1);
this.byteBuffer.putFloat(i + 4, (float) parDouble2);
return this;
}
public WorldRenderer lightmap(int parInt1, int parInt2) {
VertexFormat fmt = this.vertexFormat;
int i = this.vertexCount * fmt.attribStride + fmt.attribLightmapOffset;
this.byteBuffer.putShort(i, (short) parInt2);
this.byteBuffer.putShort(i + 2, (short) parInt1);
return this;
}
/**
* update lightmap color of the last 4 verticies, used in AO calculation
*/
public void putBrightness4(int parInt1, int parInt2, int parInt3, int parInt4) {
VertexFormat fmt = this.vertexFormat;
int j = fmt.attribStride >> 2;
int i = (this.vertexCount - 4) * j + (fmt.attribLightmapOffset >> 2);
this.intBuffer.put(i, parInt1);
this.intBuffer.put(i + j, parInt2);
this.intBuffer.put(i + j * 2, parInt3);
this.intBuffer.put(i + j * 3, parInt4);
}
/**
* translates the last 4 verticies to the given position plus current offset
*/
public void putPosition(double x, double y, double z) {
int i = this.vertexFormat.attribStride;
int j = (this.vertexCount - 4) * i;
for (int k = 0; k < 4; ++k) {
int l = j + k * i;
int i1 = l + 4;
int j1 = i1 + 4;
this.byteBuffer.putFloat(l, (float) (x + this.xOffset) + this.byteBuffer.getFloat(l));
this.byteBuffer.putFloat(i1, (float) (y + this.yOffset) + this.byteBuffer.getFloat(i1));
this.byteBuffer.putFloat(j1, (float) (z + this.zOffset) + this.byteBuffer.getFloat(j1));
}
}
/**
* gets the color index of a vertex parInt1 indicies before the current vertex
*/
private int getColorIndex(int parInt1) {
return ((this.vertexCount - parInt1) * this.vertexFormat.attribStride +
this.vertexFormat.attribColorOffset) >> 2;
}
/**
* multiplies the color of a vertex parInt1 indicies before the current vertex,
* skips if !this.needsUpdate
*/
public void putColorMultiplier(float red, float green, float blue, int parInt1) {
int i = this.getColorIndex(parInt1);
int j = -1;
if (!this.needsUpdate) {
j = this.intBuffer.get(i);
int k = (int) ((float) (j & 255) * red);
int l = (int) ((float) (j >> 8 & 255) * green);
int i1 = (int) ((float) (j >> 16 & 255) * blue);
j = j & -16777216;
j = j | i1 << 16 | l << 8 | k;
}
this.intBuffer.put(i, j);
}
/**
* sets color multiplier of a vertex parInt1 indicies before the current vertex
*/
private void putColor(int argb, int parInt2) {
int i = this.getColorIndex(parInt2);
int j = argb >> 16 & 255;
int k = argb >> 8 & 255;
int l = argb & 255;
int i1 = argb >> 24 & 255;
this.putColorRGBA(i, j, k, l, i1);
}
/**
* sets color multiplier of a vertex parInt1 indicies before the current vertex
*/
public void putColorRGB_F(float red, float green, float blue, int parInt1) {
int i = this.getColorIndex(parInt1);
int j = MathHelper.clamp_int((int) (red * 255.0F), 0, 255);
int k = MathHelper.clamp_int((int) (green * 255.0F), 0, 255);
int l = MathHelper.clamp_int((int) (blue * 255.0F), 0, 255);
this.putColorRGBA(i, j, k, l, 255);
}
/**
* sets color multiplier of a vertex parInt1 indicies before the current vertex
*/
private void putColorRGBA(int index, int red, int parInt3, int parInt4, int parInt5) {
this.intBuffer.put(index, parInt5 << 24 | parInt4 << 16 | parInt3 << 8 | red);
}
/**
* Marks the current renderer data as dirty (makes it skip certain calls)
*/
public void markDirty() {
this.needsUpdate = true;
}
/**
* sets color of current vertex
*/
public WorldRenderer color(float parFloat1, float parFloat2, float parFloat3, float parFloat4) {
return this.color((int) (parFloat1 * 255.0F), (int) (parFloat2 * 255.0F), (int) (parFloat3 * 255.0F),
(int) (parFloat4 * 255.0F));
}
/**
* sets color of current vertex
*/
public WorldRenderer color(int parInt1, int parInt2, int parInt3, int parInt4) {
if (this.needsUpdate) {
return this;
} else {
VertexFormat fmt = this.vertexFormat;
int i = this.vertexCount * fmt.attribStride + fmt.attribColorOffset;
this.byteBuffer.putInt(i, parInt1 | parInt2 << 8 | parInt3 << 16 | parInt4 << 24);
return this;
}
}
/**
* adds cached vertex data to the buffer
*/
public void addVertexData(int[] vertexData) {
this.grow(vertexData.length);
PlatformBufferFunctions.put(this.intBuffer, (this.vertexCount * this.vertexFormat.attribStride) >> 2, vertexData);
this.vertexCount += vertexData.length / (this.vertexFormat.attribStride >> 2);
}
/**
* increases the index of the current vertex by 1
*/
public void endVertex() {
++this.vertexCount;
this.grow(this.vertexFormat.attribStride >> 2);
}
/**
* sets position of current vertex
*/
public WorldRenderer pos(double parDouble1, double parDouble2, double parDouble3) {
int i = this.vertexCount * this.vertexFormat.attribStride;
this.byteBuffer.putFloat(i, (float) (parDouble1 + this.xOffset));
this.byteBuffer.putFloat(i + 4, (float) (parDouble2 + this.yOffset));
this.byteBuffer.putFloat(i + 8, (float) (parDouble3 + this.zOffset));
return this;
}
/**
* sets the normal of the previous 4 verticies in the buffer
*/
public void putNormal(float x, float y, float z) {
int i = (byte) ((int) (x * 127.0F)) & 255;
int j = (byte) ((int) (y * 127.0F)) & 255;
int k = (byte) ((int) (z * 127.0F)) & 255;
int l = i | j << 8 | k << 16;
VertexFormat fmt = this.vertexFormat;
int i1 = fmt.attribStride;
int j1 = (this.vertexCount - 4) * i1 + fmt.attribNormalOffset;
this.byteBuffer.putInt(j1, l);
this.byteBuffer.putInt(j1 + i1, l);
this.byteBuffer.putInt(j1 + i1 * 2, l);
this.byteBuffer.putInt(j1 + i1 * 3, l);
}
/**
* set normal of current vertex
*/
public WorldRenderer normal(float parFloat1, float parFloat2, float parFloat3) { //TODO: crash with particles
VertexFormat fmt = this.vertexFormat;
int i = this.vertexCount * fmt.attribStride + fmt.attribNormalOffset;
this.byteBuffer.put(i, (byte) ((int) parFloat1 * 127 & 255));
this.byteBuffer.put(i + 1, (byte) ((int) parFloat2 * 127 & 255));
this.byteBuffer.put(i + 2, (byte) ((int) parFloat3 * 127 & 255));
return this;
}
/**
* sets translation applied to all positions set by functions
*/
public void setTranslation(double x, double y, double z) {
this.xOffset = x;
this.yOffset = y;
this.zOffset = z;
}
public void finishDrawing() {
if (!this.isDrawing) {
throw new IllegalStateException("Not building!");
} else {
this.isDrawing = false;
this.byteBuffer.position(0);
this.byteBuffer.limit(this.vertexCount * this.vertexFormat.attribStride);
}
}
public ByteBuffer getByteBuffer() {
return this.byteBuffer;
}
public VertexFormat getVertexFormat() {
return this.vertexFormat;
}
public int getVertexCount() {
return this.vertexCount;
}
public int getDrawMode() {
return this.drawMode;
}
public void putColor4(int argb) {
for (int i = 0; i < 4; ++i) {
this.putColor(argb, i + 1);
}
}
public void putColorRGB_F4(float red, float green, float blue) {
for (int i = 0; i < 4; ++i) {
this.putColorRGB_F(red, green, blue, i + 1);
}
}
public class State {
private final int[] stateRawBuffer;
private final VertexFormat stateVertexFormat;
public State(int[] parArrayOfInt, VertexFormat parVertexFormat) {
this.stateRawBuffer = parArrayOfInt;
this.stateVertexFormat = parVertexFormat;
}
public int[] getRawBuffer() {
return this.stateRawBuffer;
}
public int getVertexCount() {
return this.stateRawBuffer.length / (this.stateVertexFormat.attribStride >> 2);
}
public VertexFormat getVertexFormat() {
return this.stateVertexFormat;
}
}
}

View File

@ -0,0 +1,30 @@
package net.lax1dude.eaglercraft.v1_8.opengl;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class WorldVertexBufferUploader {
public void func_181679_a(WorldRenderer parWorldRenderer) {
int cunt = parWorldRenderer.getVertexCount();
if (cunt > 0) {
VertexFormat fmt = parWorldRenderer.getVertexFormat();
ByteBuffer buf = parWorldRenderer.getByteBuffer();
buf.position(0).limit(cunt * fmt.attribStride);
EaglercraftGPU.renderBuffer(buf, fmt.eaglercraftAttribBits,
parWorldRenderer.getDrawMode(), cunt);
parWorldRenderer.reset();
}
}
}