Skip to content

Commit

Permalink
chore: reusue Floatbuffer for uniform (#4762)
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Jun 15, 2021
1 parent 49a3add commit 718c2ff
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class GLSLMaterial extends BaseMaterial {
private DisposalAction disposalAction;
private MaterialData materialData;

private final FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);

public GLSLMaterial(ResourceUrn urn, AssetType<?, MaterialData> assetType, MaterialData data,
LwjglGraphicsProcessing graphicsProcessing, GLSLMaterial.DisposalAction disposalAction) {
super(urn, assetType, disposalAction);
Expand Down Expand Up @@ -481,20 +483,20 @@ public void setMatrix3(String desc, Matrix3fc value, boolean currentOnly) {
if (isDisposed()) {
return;
}
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
value.get(buffer);
matrixBuffer.rewind();
value.get(matrixBuffer);
if (currentOnly) {
enable();
int id = getUniformLocation(getActiveShaderProgramId(), desc);
GL20.glUniformMatrix3fv(id, false, buffer);
GL20.glUniformMatrix3fv(id, false, matrixBuffer);
} else {
TIntIntIterator it = disposalAction.shaderPrograms.iterator();
while (it.hasNext()) {
it.advance();

GL20.glUseProgram(it.value());
int id = getUniformLocation(it.value(), desc);
GL20.glUniformMatrix3fv(id, false, buffer);
GL20.glUniformMatrix3fv(id, false, matrixBuffer);
}

restoreStateAfterUniformsSet();
Expand Down Expand Up @@ -529,20 +531,20 @@ public void setMatrix4(String desc, Matrix4fc value, boolean currentOnly) {
if (isDisposed()) {
return;
}
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
value.get(buffer);
matrixBuffer.rewind();
value.get(matrixBuffer);
if (currentOnly) {
enable();
int id = getUniformLocation(getActiveShaderProgramId(), desc);
GL20.glUniformMatrix4fv(id, false, buffer);
GL20.glUniformMatrix4fv(id, false, matrixBuffer);
} else {
TIntIntIterator it = disposalAction.shaderPrograms.iterator();
while (it.hasNext()) {
it.advance();

GL20.glUseProgram(it.value());
int id = getUniformLocation(it.value(), desc);
GL20.glUniformMatrix4fv(id, false, buffer);
GL20.glUniformMatrix4fv(id, false, matrixBuffer);
}

restoreStateAfterUniformsSet();
Expand Down

0 comments on commit 718c2ff

Please sign in to comment.