Skip to content

Commit

Permalink
Fix buffer not populated for VERTEX_BUF_OR_GLOBAL
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Apr 23, 2024
1 parent 4f07f6a commit 53e9033
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import cn.zbx1425.sowcer.object.VertArray;
import cn.zbx1425.sowcer.shader.ShaderManager;
import cn.zbx1425.sowcer.util.DrawContext;
#if DEBUG
import org.lwjgl.opengl.KHRDebug;
#endif

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public enum VertAttrSrc {
/** If specified in EnqueueProp or MaterialProp use global, otherwise use instance VBO */
INSTANCE_BUF_OR_GLOBAL;

boolean isToggleable() {
public boolean isToggleable() {
return this == VERTEX_BUF_OR_GLOBAL || this == INSTANCE_BUF_OR_GLOBAL;
}

public boolean inVertBuf() {
return this == VERTEX_BUF || this == VERTEX_BUF_OR_GLOBAL;
}
}
14 changes: 5 additions & 9 deletions common/src/main/java/cn/zbx1425/sowcerext/model/RawMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,26 @@ public void upload(Mesh mesh, VertAttrMapping mapping) {

ByteBuffer vertBuf = OffHeapAllocator.allocate(vertices.size() * mapping.strideVertex);
for (int i = 0; i < vertices.size(); ++i) {
if (shouldWriteVertBuf(mapping, VertAttrType.POSITION)) {
if (mapping.sources.get(VertAttrType.POSITION).inVertBuf()) {
Vector3f pos = vertices.get(i).position;
// vertBuf.position(getVertBufPos(mapping, i, VertAttrType.POSITION));
vertBuf.putFloat(pos.x()).putFloat(pos.y()).putFloat(pos.z());
}
if (shouldWriteVertBuf(mapping, VertAttrType.COLOR)) {
if (mapping.sources.get(VertAttrType.COLOR).inVertBuf()) {
// vertBuf.position(getVertBufPos(mapping, i, VertAttrType.COLOR));
vertBuf.putInt(vertices.get(i).color);
}
if (shouldWriteVertBuf(mapping, VertAttrType.UV_TEXTURE)) {
if (mapping.sources.get(VertAttrType.UV_TEXTURE).inVertBuf()) {
float u = vertices.get(i).u;
float v = vertices.get(i).v;
// vertBuf.position(getVertBufPos(mapping, i, VertAttrType.UV_TEXTURE));
vertBuf.putFloat(u).putFloat(v);
}
if (shouldWriteVertBuf(mapping, VertAttrType.UV_LIGHTMAP)) {
if (mapping.sources.get(VertAttrType.UV_LIGHTMAP).inVertBuf()) {
// vertBuf.position(getVertBufPos(mapping, i, VertAttrType.UV_LIGHTMAP));
vertBuf.putInt(vertices.get(i).light);
}
if (shouldWriteVertBuf(mapping, VertAttrType.NORMAL)) {
if (mapping.sources.get(VertAttrType.NORMAL).inVertBuf()) {
Vector3f mojNormal = vertices.get(i).normal.copy();
mojNormal.normalize();
// vertBuf.position(getVertBufPos(mapping, i, VertAttrType.NORMAL));
Expand Down Expand Up @@ -231,10 +231,6 @@ public Mesh upload(VertAttrMapping mapping) {
return target;
}

private static boolean shouldWriteVertBuf(VertAttrMapping mapping, VertAttrType type) {
return mapping.sources.get(type) == VertAttrSrc.VERTEX_BUF;
}

private static int getVertBufPos(VertAttrMapping mapping, int vertId, VertAttrType type) {
return mapping.strideVertex * vertId + mapping.pointers.get(type);
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 53e9033

Please sign in to comment.