Skip to content

Commit d411586

Browse files
committed
Minor code changes
1 parent 3827238 commit d411586

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

chapter-21/src/main/java/org/lwjglb/engine/graph/RenderBuffers.java

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public final int getStaticVaoId() {
8181
public void loadAnimatedModels(Scene scene) {
8282
List<Model> modelList = scene.getModelMap().values().stream().filter(Model::isAnimated).toList();
8383
loadBindingPoses(modelList);
84-
loadAnimationData(modelList);
84+
loadBonesMatricesBuffer(modelList);
8585
loadBonesIndicesWeights(modelList);
8686

8787
animVaoId = glGenVertexArrays();
@@ -123,7 +123,6 @@ public void loadAnimatedModels(Scene scene) {
123123
destAnimationBuffer = glGenBuffers();
124124
vboIdList.add(destAnimationBuffer);
125125
FloatBuffer meshesBuffer = MemoryUtil.memAllocFloat(positionsSize + normalsSize * 3 + textureCoordsSize);
126-
127126
for (Model model : modelList) {
128127
model.getEntitiesList().forEach(e -> {
129128
for (MeshData meshData : model.getMeshDataList()) {
@@ -158,45 +157,6 @@ public void loadAnimatedModels(Scene scene) {
158157
glBindVertexArray(0);
159158
}
160159

161-
private void loadAnimationData(List<Model> modelList) {
162-
int bufferSize = 0;
163-
for (Model model : modelList) {
164-
List<Model.Animation> animationsList = model.getAnimationList();
165-
for (Model.Animation animation : animationsList) {
166-
List<Model.AnimatedFrame> frameList = animation.frames();
167-
for (Model.AnimatedFrame frame : frameList) {
168-
Matrix4f[] matrices = frame.getBonesMatrices();
169-
bufferSize += matrices.length * 64;
170-
}
171-
}
172-
}
173-
174-
bonesMatricesBuffer = glGenBuffers();
175-
vboIdList.add(bonesMatricesBuffer);
176-
ByteBuffer dataBuffer = MemoryUtil.memAlloc(bufferSize);
177-
int matrixSize = 4 * 4 * 4;
178-
for (Model model : modelList) {
179-
List<Model.Animation> animationsList = model.getAnimationList();
180-
for (Model.Animation animation : animationsList) {
181-
List<Model.AnimatedFrame> frameList = animation.frames();
182-
for (Model.AnimatedFrame frame : frameList) {
183-
frame.setOffset(dataBuffer.position() / matrixSize);
184-
Matrix4f[] matrices = frame.getBonesMatrices();
185-
for (Matrix4f matrix : matrices) {
186-
matrix.get(dataBuffer);
187-
dataBuffer.position(dataBuffer.position() + matrixSize);
188-
}
189-
frame.clearData();
190-
}
191-
}
192-
}
193-
dataBuffer.flip();
194-
195-
glBindBuffer(GL_SHADER_STORAGE_BUFFER, bonesMatricesBuffer);
196-
glBufferData(GL_SHADER_STORAGE_BUFFER, dataBuffer, GL_STATIC_DRAW);
197-
MemoryUtil.memFree(dataBuffer);
198-
}
199-
200160
private void loadBindingPoses(List<Model> modelList) {
201161
int meshSize = 0;
202162
for (Model model : modelList) {
@@ -259,6 +219,45 @@ private void loadBonesIndicesWeights(List<Model> modelList) {
259219
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
260220
}
261221

222+
private void loadBonesMatricesBuffer(List<Model> modelList) {
223+
int bufferSize = 0;
224+
for (Model model : modelList) {
225+
List<Model.Animation> animationsList = model.getAnimationList();
226+
for (Model.Animation animation : animationsList) {
227+
List<Model.AnimatedFrame> frameList = animation.frames();
228+
for (Model.AnimatedFrame frame : frameList) {
229+
Matrix4f[] matrices = frame.getBonesMatrices();
230+
bufferSize += matrices.length * 64;
231+
}
232+
}
233+
}
234+
235+
bonesMatricesBuffer = glGenBuffers();
236+
vboIdList.add(bonesMatricesBuffer);
237+
ByteBuffer dataBuffer = MemoryUtil.memAlloc(bufferSize);
238+
int matrixSize = 4 * 4 * 4;
239+
for (Model model : modelList) {
240+
List<Model.Animation> animationsList = model.getAnimationList();
241+
for (Model.Animation animation : animationsList) {
242+
List<Model.AnimatedFrame> frameList = animation.frames();
243+
for (Model.AnimatedFrame frame : frameList) {
244+
frame.setOffset(dataBuffer.position() / matrixSize);
245+
Matrix4f[] matrices = frame.getBonesMatrices();
246+
for (Matrix4f matrix : matrices) {
247+
matrix.get(dataBuffer);
248+
dataBuffer.position(dataBuffer.position() + matrixSize);
249+
}
250+
frame.clearData();
251+
}
252+
}
253+
}
254+
dataBuffer.flip();
255+
256+
glBindBuffer(GL_SHADER_STORAGE_BUFFER, bonesMatricesBuffer);
257+
glBufferData(GL_SHADER_STORAGE_BUFFER, dataBuffer, GL_STATIC_DRAW);
258+
MemoryUtil.memFree(dataBuffer);
259+
}
260+
262261
public void loadStaticModels(Scene scene) {
263262
List<Model> modelList = scene.getModelMap().values().stream().filter(m -> !m.isAnimated()).toList();
264263
staticVaoId = glGenVertexArrays();

0 commit comments

Comments
 (0)