gpu: add sin/cos table to UBO
This commit is contained in:
@@ -152,7 +152,8 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
|
|
||||||
private int textureArrayId;
|
private int textureArrayId;
|
||||||
|
|
||||||
private final IntBuffer uniformBuffer = GpuIntBuffer.allocateDirect(5);
|
private int uniformBufferId;
|
||||||
|
private final IntBuffer uniformBuffer = GpuIntBuffer.allocateDirect(5 + 3 + 2048 * 4);
|
||||||
private final float[] textureOffsets = new float[128];
|
private final float[] textureOffsets = new float[128];
|
||||||
|
|
||||||
private GpuIntBuffer vertexBuffer;
|
private GpuIntBuffer vertexBuffer;
|
||||||
@@ -211,7 +212,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bufferId = uvBufferId = -1;
|
bufferId = uvBufferId = uniformBufferId = -1;
|
||||||
|
|
||||||
vertexBuffer = new GpuIntBuffer();
|
vertexBuffer = new GpuIntBuffer();
|
||||||
uvBuffer = new GpuFloatBuffer();
|
uvBuffer = new GpuFloatBuffer();
|
||||||
@@ -265,6 +266,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
initVao();
|
initVao();
|
||||||
initProgram();
|
initProgram();
|
||||||
initInterfaceTexture();
|
initInterfaceTexture();
|
||||||
|
initUniformBuffer();
|
||||||
|
|
||||||
client.setDrawCallbacks(this);
|
client.setDrawCallbacks(this);
|
||||||
client.setGpu(true);
|
client.setGpu(true);
|
||||||
@@ -338,6 +340,12 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
uvBufferId = -1;
|
uvBufferId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (uniformBufferId != -1)
|
||||||
|
{
|
||||||
|
GLUtil.glDeleteBuffer(gl, uniformBufferId);
|
||||||
|
uniformBufferId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
shutdownInterfaceTexture();
|
shutdownInterfaceTexture();
|
||||||
shutdownProgram();
|
shutdownProgram();
|
||||||
shutdownVao();
|
shutdownVao();
|
||||||
@@ -522,6 +530,25 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
interfaceTexture = -1;
|
interfaceTexture = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initUniformBuffer()
|
||||||
|
{
|
||||||
|
uniformBufferId = glGenBuffers(gl);
|
||||||
|
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, uniformBufferId);
|
||||||
|
uniformBuffer.clear();
|
||||||
|
uniformBuffer.put(new int[8]);
|
||||||
|
final int[] pad = new int[2];
|
||||||
|
for (int i = 0; i < 2048; i++)
|
||||||
|
{
|
||||||
|
uniformBuffer.put(Perspective.SINE[i]);
|
||||||
|
uniformBuffer.put(Perspective.COSINE[i]);
|
||||||
|
uniformBuffer.put(pad);
|
||||||
|
}
|
||||||
|
uniformBuffer.flip();
|
||||||
|
|
||||||
|
gl.glBufferData(gl.GL_UNIFORM_BUFFER, uniformBuffer.limit() * Integer.BYTES, uniformBuffer, gl.GL_STATIC_DRAW);
|
||||||
|
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
private void createProjectionMatrix(float left, float right, float bottom, float top, float near, float far)
|
private void createProjectionMatrix(float left, float right, float bottom, float top, float near, float far)
|
||||||
{
|
{
|
||||||
// create a standard orthographic projection
|
// create a standard orthographic projection
|
||||||
@@ -695,7 +722,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
gl.GL_STREAM_DRAW);
|
gl.GL_STREAM_DRAW);
|
||||||
|
|
||||||
// UBO
|
// UBO
|
||||||
int uniformBufferId = glGenBuffers(gl);
|
|
||||||
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, uniformBufferId);
|
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, uniformBufferId);
|
||||||
uniformBuffer.clear();
|
uniformBuffer.clear();
|
||||||
uniformBuffer
|
uniformBuffer
|
||||||
@@ -706,7 +732,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
.put(client.getScale());
|
.put(client.getScale());
|
||||||
uniformBuffer.flip();
|
uniformBuffer.flip();
|
||||||
|
|
||||||
gl.glBufferData(gl.GL_UNIFORM_BUFFER, uniformBuffer.limit() * Integer.BYTES, uniformBuffer, gl.GL_STATIC_DRAW);
|
gl.glBufferSubData(gl.GL_UNIFORM_BUFFER, 0, uniformBuffer.limit() * Integer.BYTES, uniformBuffer);
|
||||||
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, 0);
|
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
gl.glUniformBlockBinding(glSmallComputeProgram, uniBlockSmall, 0);
|
gl.glUniformBlockBinding(glSmallComputeProgram, uniBlockSmall, 0);
|
||||||
@@ -815,8 +841,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
|
|||||||
gl.glUseProgram(0);
|
gl.glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDeleteBuffer(gl, uniformBufferId);
|
|
||||||
|
|
||||||
vertexBuffer.clear();
|
vertexBuffer.clear();
|
||||||
uvBuffer.clear();
|
uvBuffer.clear();
|
||||||
modelBuffer.clear();
|
modelBuffer.clear();
|
||||||
|
|||||||
@@ -29,8 +29,9 @@
|
|||||||
* Rotate a vertex by a given orientation in JAU
|
* Rotate a vertex by a given orientation in JAU
|
||||||
*/
|
*/
|
||||||
ivec4 rotate(ivec4 vertex, int orientation) {
|
ivec4 rotate(ivec4 vertex, int orientation) {
|
||||||
int s = int(65536.0f * sin(orientation * UNIT));
|
ivec2 sinCos = sinCosTable[orientation];
|
||||||
int c = int(65536.0f * cos(orientation * UNIT));
|
int s = sinCos.x;
|
||||||
|
int c = sinCos.y;
|
||||||
int x = vertex.z * s + vertex.x * c >> 16;
|
int x = vertex.z * s + vertex.x * c >> 16;
|
||||||
int z = vertex.z * c - vertex.x * s >> 16;
|
int z = vertex.z * c - vertex.x * s >> 16;
|
||||||
return ivec4(x, vertex.y, z, vertex.w);
|
return ivec4(x, vertex.y, z, vertex.w);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ layout(std140) uniform uniforms {
|
|||||||
int centerX;
|
int centerX;
|
||||||
int centerY;
|
int centerY;
|
||||||
int zoom;
|
int zoom;
|
||||||
|
ivec2 sinCosTable[2048];
|
||||||
};
|
};
|
||||||
|
|
||||||
shared int totalNum[12]; // number of faces with a given priority
|
shared int totalNum[12]; // number of faces with a given priority
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ layout(std140) uniform uniforms {
|
|||||||
int centerX;
|
int centerX;
|
||||||
int centerY;
|
int centerY;
|
||||||
int zoom;
|
int zoom;
|
||||||
|
ivec2 sinCosTable[2048];
|
||||||
};
|
};
|
||||||
|
|
||||||
shared int totalNum[12]; // number of faces with a given priority
|
shared int totalNum[12]; // number of faces with a given priority
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ layout(std140) uniform Uniforms {
|
|||||||
int centerX;
|
int centerX;
|
||||||
int centerY;
|
int centerY;
|
||||||
int zoom;
|
int zoom;
|
||||||
|
ivec2 sinCosTable[2048];
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
|
|||||||
Reference in New Issue
Block a user