Skip to content

Commit

Permalink
remove sincos table
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Apr 17, 2024
1 parent 9900629 commit 6c3f4a4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -806,18 +806,7 @@ private void initUniformBuffer()
{
initGlBuffer(uniformBuffer);

IntBuffer uniformBuf = GpuIntBuffer.allocateDirect(8 + 2048 * 4);
uniformBuf.put(new int[8]); // uniform block
final int[] pad = new int[2];
for (int i = 0; i < 2048; i++)
{
uniformBuf.put(Perspective.SINE[i]);
uniformBuf.put(Perspective.COSINE[i]);
uniformBuf.put(pad); // ivec2 alignment in std140 is 16 bytes
}
uniformBuf.flip();

updateBuffer(uniformBuffer, GL43C.GL_UNIFORM_BUFFER, uniformBuf, GL43C.GL_DYNAMIC_DRAW, CL12.CL_MEM_READ_ONLY);
updateBuffer(uniformBuffer, GL43C.GL_UNIFORM_BUFFER, 8 * Integer.BYTES, GL43C.GL_DYNAMIC_DRAW, CL12.CL_MEM_READ_ONLY);
GL43C.glBindBuffer(GL43C.GL_UNIFORM_BUFFER, 0);
}

Expand Down Expand Up @@ -885,7 +874,7 @@ public void drawScene(double cameraX, double cameraY, double cameraZ, double cam
// viewport buffer.
targetBufferOffset = 0;

// UBO. Only the first 32 bytes get modified here, the rest is the constant sin/cos table.
// UBO.
// We can reuse the vertex buffer since it isn't used yet.
vertexBuffer.clear();
vertexBuffer.ensureCapacity(32);
Expand All @@ -901,8 +890,7 @@ public void drawScene(double cameraX, double cameraY, double cameraZ, double cam
.put(Float.floatToIntBits((float) cameraZ));
uniformBuf.flip();

GL43C.glBindBuffer(GL43C.GL_UNIFORM_BUFFER, uniformBuffer.glBufferId);
GL43C.glBufferSubData(GL43C.GL_UNIFORM_BUFFER, 0, uniformBuf);
updateBuffer(uniformBuffer, GL43C.GL_UNIFORM_BUFFER, uniformBuf, GL43C.GL_DYNAMIC_DRAW, CL12.CL_MEM_READ_ONLY);
GL43C.glBindBuffer(GL43C.GL_UNIFORM_BUFFER, 0);

GL43C.glBindBufferBase(GL43C.GL_UNIFORM_BUFFER, 0, uniformBuffer.glBufferId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ vec4 rotatef(vec4 vertex, int orientation) {
float rad = orientation * UNIT;
float s = sin(rad);
float c = cos(rad);
mat4 m = mat4(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
// clang-format off
mat4 m = mat4(
c, 0, s, 0,
0, 1, 0, 0,
-s, 0, c, 0,
0, 0, 0, 1
);
// clang-format on
return vertex * m;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ layout(std140) uniform uniforms {
float cameraX;
float cameraY;
float cameraZ;
ivec2 sinCosTable[2048];
};

struct modelinfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ layout(std140) uniform uniforms {
float cameraX;
float cameraY;
float cameraZ;
ivec2 sinCosTable[2048];
};

#include "uv.glsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ layout(std140) uniform uniforms {
float cameraX;
float cameraY;
float cameraZ;
ivec2 sinCosTable[2048];
};

uniform float brightness;
Expand Down

0 comments on commit 6c3f4a4

Please sign in to comment.