gpu: add sin/cos table to UBO

This commit is contained in:
Dennis
2018-11-18 15:36:36 +01:00
committed by Adam
parent 1e83a36c42
commit 9c791f5b09
5 changed files with 36 additions and 8 deletions

View File

@@ -152,7 +152,8 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
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 GpuIntBuffer vertexBuffer;
@@ -211,7 +212,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
{
try
{
bufferId = uvBufferId = -1;
bufferId = uvBufferId = uniformBufferId = -1;
vertexBuffer = new GpuIntBuffer();
uvBuffer = new GpuFloatBuffer();
@@ -265,6 +266,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
initVao();
initProgram();
initInterfaceTexture();
initUniformBuffer();
client.setDrawCallbacks(this);
client.setGpu(true);
@@ -338,6 +340,12 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
uvBufferId = -1;
}
if (uniformBufferId != -1)
{
GLUtil.glDeleteBuffer(gl, uniformBufferId);
uniformBufferId = -1;
}
shutdownInterfaceTexture();
shutdownProgram();
shutdownVao();
@@ -522,6 +530,25 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
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)
{
// create a standard orthographic projection
@@ -695,7 +722,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
gl.GL_STREAM_DRAW);
// UBO
int uniformBufferId = glGenBuffers(gl);
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, uniformBufferId);
uniformBuffer.clear();
uniformBuffer
@@ -706,7 +732,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
.put(client.getScale());
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.glUniformBlockBinding(glSmallComputeProgram, uniBlockSmall, 0);
@@ -815,8 +841,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
gl.glUseProgram(0);
}
glDeleteBuffer(gl, uniformBufferId);
vertexBuffer.clear();
uvBuffer.clear();
modelBuffer.clear();

View File

@@ -29,8 +29,9 @@
* Rotate a vertex by a given orientation in JAU
*/
ivec4 rotate(ivec4 vertex, int orientation) {
int s = int(65536.0f * sin(orientation * UNIT));
int c = int(65536.0f * cos(orientation * UNIT));
ivec2 sinCos = sinCosTable[orientation];
int s = sinCos.x;
int c = sinCos.y;
int x = vertex.z * s + vertex.x * c >> 16;
int z = vertex.z * c - vertex.x * s >> 16;
return ivec4(x, vertex.y, z, vertex.w);

View File

@@ -33,6 +33,7 @@ layout(std140) uniform uniforms {
int centerX;
int centerY;
int zoom;
ivec2 sinCosTable[2048];
};
shared int totalNum[12]; // number of faces with a given priority

View File

@@ -33,6 +33,7 @@ layout(std140) uniform uniforms {
int centerX;
int centerY;
int zoom;
ivec2 sinCosTable[2048];
};
shared int totalNum[12]; // number of faces with a given priority

View File

@@ -37,6 +37,7 @@ layout(std140) uniform Uniforms {
int centerX;
int centerY;
int zoom;
ivec2 sinCosTable[2048];
};
uniform mat4 projectionMatrix;