!feature: refactor mesh for GL330 (#4620)
* !feature: refactor mesh for GL330 * bugfix: correct canvasRenderer * chore: clean up layout logic - remove vbo pool from mesh - remove unused methods from canvas * bugfix: fix OpenGLSkeletalmesh * paritially fixed block selection * fix block breaking animation * cleanup code * unbind vbo * remove UV1 * Revert "remove UV1" This reverts commit 8d92496004c9d79ff7002f9fe87d9b59f2bf96ae. * clean up imports * add mising dispose action * lower matrix stackdevelop
parent
ea66683c55
commit
d7f7549028
|
@ -111,11 +111,11 @@ public class LwjglGraphicsManager implements LwjglGraphicsProcessing {
|
|||
"materials");
|
||||
assetTypeManager.registerCoreAssetType(Mesh.class, (AssetFactory<Mesh, MeshData>)
|
||||
(urn, assetType, data) ->
|
||||
new OpenGLMesh(urn, assetType, bufferPool, data, this),
|
||||
new OpenGLMesh(urn, assetType, data, this),
|
||||
"mesh");
|
||||
assetTypeManager.registerCoreAssetType(SkeletalMesh.class, (AssetFactory<SkeletalMesh, SkeletalMeshData>)
|
||||
(urn, assetType, data) ->
|
||||
new OpenGLSkeletalMesh(urn, assetType, bufferPool, data, this),
|
||||
new OpenGLSkeletalMesh(urn, assetType, data, this),
|
||||
"skeletalMesh");
|
||||
assetTypeManager.registerCoreAssetType(MeshAnimation.class, MeshAnimationImpl::new,
|
||||
"animations", "skeletalMesh");
|
||||
|
|
|
@ -61,6 +61,7 @@ public class ShaderManagerLwjgl implements ShaderManager {
|
|||
addShaderProgram("toneMapping");
|
||||
addShaderProgram("sky");
|
||||
addShaderProgram("chunk");
|
||||
addShaderProgram("blockSelection");
|
||||
if (GL.createCapabilities().OpenGL33) { //TODO remove this "if" when rendering will use OpenGL3 by default
|
||||
addShaderProgram("particle");
|
||||
} else {
|
||||
|
|
|
@ -11,12 +11,6 @@ import org.terasology.joml.geom.AABBfc;
|
|||
|
||||
public abstract class Mesh extends Asset<MeshData> {
|
||||
|
||||
public static final int VERTEX_SIZE = 3;
|
||||
public static final int TEX_COORD_0_SIZE = 2;
|
||||
public static final int TEX_COORD_1_SIZE = 3;
|
||||
public static final int COLOR_SIZE = 4;
|
||||
public static final int NORMAL_SIZE = 3;
|
||||
|
||||
protected Mesh(ResourceUrn urn, AssetType<?, MeshData> assetType) {
|
||||
super(urn, assetType);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class MeshBuilder {
|
|||
20, 21, 22, 20, 22, 23 // left
|
||||
};
|
||||
|
||||
private MeshData meshData = new MeshData();
|
||||
private StandardMeshData meshData = new StandardMeshData();
|
||||
private int vertexCount;
|
||||
private TextureMapper textureMapper;
|
||||
|
||||
|
@ -92,22 +92,22 @@ public class MeshBuilder {
|
|||
}
|
||||
|
||||
public MeshBuilder addColor(Colorc c1, Colorc... colors) {
|
||||
meshData.getColors().add(c1.rf());
|
||||
meshData.getColors().add(c1.gf());
|
||||
meshData.getColors().add(c1.bf());
|
||||
meshData.getColors().add(c1.af());
|
||||
meshData.color0.add(c1.rf());
|
||||
meshData.color0.add(c1.gf());
|
||||
meshData.color0.add(c1.bf());
|
||||
meshData.color0.add(c1.af());
|
||||
for (Colorc c : colors) {
|
||||
meshData.getColors().add(c.rf());
|
||||
meshData.getColors().add(c.gf());
|
||||
meshData.getColors().add(c.bf());
|
||||
meshData.getColors().add(c.af());
|
||||
meshData.color0.add(c.rf());
|
||||
meshData.color0.add(c.gf());
|
||||
meshData.color0.add(c.bf());
|
||||
meshData.color0.add(c.af());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MeshBuilder addTexCoord(float x, float y) {
|
||||
meshData.getTexCoord0().add(x);
|
||||
meshData.getTexCoord0().add(y);
|
||||
meshData.uv0.add(x);
|
||||
meshData.uv0.add(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ public class MeshBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public MeshData getMeshData() {
|
||||
public StandardMeshData getMeshData() {
|
||||
return meshData;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,45 +4,66 @@ package org.terasology.engine.rendering.assets.mesh;
|
|||
|
||||
import gnu.trove.list.TFloatList;
|
||||
import gnu.trove.list.TIntList;
|
||||
import gnu.trove.list.array.TFloatArrayList;
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL33;
|
||||
import org.lwjgl.opengl.GL44;
|
||||
import org.terasology.assets.AssetData;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.Layout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class MeshData implements AssetData {
|
||||
public abstract class MeshData implements AssetData {
|
||||
public enum DrawingMode {
|
||||
POINTS(GL30.GL_POINT),
|
||||
LINES(GL30.GL_LINES),
|
||||
LINE_LOOP(GL30.GL_LINE_LOOP),
|
||||
LINE_STRIP(GL30.GL_LINE_STRIP),
|
||||
TRIANGLES(GL30.GL_TRIANGLES),
|
||||
TRIANGLE_STRIP(GL30.GL_TRIANGLE_STRIP),
|
||||
TRIANGLE_FAN(GL30.GL_TRIANGLE_FAN),
|
||||
LINES_ADJACENCY(GL33.GL_LINES_ADJACENCY),
|
||||
LINE_STRIP_ADJACENCY(GL44.GL_LINE_STRIP_ADJACENCY),
|
||||
TRIANGLES_ADJACENCY(GL44.GL_TRIANGLES_ADJACENCY),
|
||||
TRIANGLE_STRIP_ADJACENCY(GL44.GL_TRIANGLE_STRIP_ADJACENCY);
|
||||
|
||||
private TFloatList vertices = new TFloatArrayList();
|
||||
private TFloatList texCoord0 = new TFloatArrayList();
|
||||
private TFloatList texCoord1 = new TFloatArrayList();
|
||||
private TFloatList normals = new TFloatArrayList();
|
||||
private TFloatList colors = new TFloatArrayList();
|
||||
public final int glCall;
|
||||
DrawingMode(int gl) {
|
||||
this.glCall = gl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private List<Layout> layouts = new ArrayList<>();
|
||||
private TIntList indices = new TIntArrayList();
|
||||
private final DrawingMode mode;
|
||||
|
||||
public MeshData() {
|
||||
this(DrawingMode.TRIANGLES);
|
||||
}
|
||||
|
||||
public TFloatList getVertices() {
|
||||
return vertices;
|
||||
public MeshData(DrawingMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public TFloatList getTexCoord0() {
|
||||
return texCoord0;
|
||||
public MeshData addLayout(Layout layout) {
|
||||
this.getLayouts().add(layout);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TFloatList getTexCoord1() {
|
||||
return texCoord1;
|
||||
public List<Layout> getLayouts() {
|
||||
return this.layouts;
|
||||
}
|
||||
|
||||
public TFloatList getNormals() {
|
||||
return normals;
|
||||
}
|
||||
|
||||
public TFloatList getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public TIntList getIndices() {
|
||||
return indices;
|
||||
}
|
||||
public DrawingMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public abstract TFloatList getVertices();
|
||||
public abstract int getSize();
|
||||
|
||||
}
|
||||
|
|
|
@ -50,15 +50,15 @@ public class ObjMeshFormat extends AbstractAssetFileFormat<MeshData> {
|
|||
throw new IOException("No index data");
|
||||
}
|
||||
|
||||
MeshData data = processData(rawVertices, rawNormals, rawTexCoords, rawIndices);
|
||||
StandardMeshData data = processData(rawVertices, rawNormals, rawTexCoords, rawIndices);
|
||||
|
||||
if (data.getVertices() == null) {
|
||||
throw new IOException("No vertices define");
|
||||
}
|
||||
if (!data.getNormals().isEmpty() && data.getNormals().size() != data.getVertices().size()) {
|
||||
if (!data.normals.isEmpty() && data.normals.size() != data.getVertices().size()) {
|
||||
throw new IOException("The number of normals does not match the number of vertices.");
|
||||
}
|
||||
if (!data.getTexCoord0().isEmpty() && data.getTexCoord0().size() / 2 != data.getVertices().size() / 3) {
|
||||
if (!data.uv0.isEmpty() && data.uv0.size() / 2 != data.getVertices().size() / 3) {
|
||||
throw new IOException("The number of tex coords does not match the number of vertices.");
|
||||
}
|
||||
|
||||
|
@ -66,11 +66,11 @@ public class ObjMeshFormat extends AbstractAssetFileFormat<MeshData> {
|
|||
}
|
||||
}
|
||||
|
||||
private MeshData processData(List<Vector3f> rawVertices, List<Vector3f> rawNormals, List<Vector2f> rawTexCoords, List<Vector3i[]> rawIndices) throws IOException {
|
||||
MeshData result = new MeshData();
|
||||
TFloatList vertices = result.getVertices();
|
||||
TFloatList texCoord0 = result.getTexCoord0();
|
||||
TFloatList normals = result.getNormals();
|
||||
private StandardMeshData processData(List<Vector3f> rawVertices, List<Vector3f> rawNormals, List<Vector2f> rawTexCoords, List<Vector3i[]> rawIndices) throws IOException {
|
||||
StandardMeshData result = new StandardMeshData();
|
||||
TFloatList vertices = result.vertices;
|
||||
TFloatList texCoord0 = result.uv0;
|
||||
TFloatList normals = result.normals;
|
||||
TIntList indices = result.getIndices();
|
||||
int vertCount = 0;
|
||||
for (Vector3i[] face : rawIndices) {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.engine.rendering.assets.mesh;
|
||||
|
||||
import gnu.trove.list.TFloatList;
|
||||
import gnu.trove.list.array.TFloatArrayList;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.FloatLayout;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.Layout;
|
||||
|
||||
public class StandardMeshData extends MeshData {
|
||||
public static final int VERTEX_INDEX = 0;
|
||||
public static final int NORMAL_INDEX = 1;
|
||||
public static final int UV0_INDEX = 2;
|
||||
public static final int UV1_INDEX = 3;
|
||||
public static final int COLOR0_INDEX = 4;
|
||||
public static final int LIGHT0_INDEX = 5;
|
||||
|
||||
|
||||
public final TFloatList vertices;
|
||||
public final TFloatList uv0;
|
||||
public final TFloatList uv1;
|
||||
public final TFloatList normals;
|
||||
public final TFloatList color0;
|
||||
public final TFloatList light0;
|
||||
|
||||
public StandardMeshData() {
|
||||
this.vertices = new TFloatArrayList();
|
||||
this.uv0 = new TFloatArrayList();
|
||||
this.uv1 = new TFloatArrayList();
|
||||
this.normals = new TFloatArrayList();
|
||||
this.color0 = new TFloatArrayList();
|
||||
this.light0 = new TFloatArrayList();
|
||||
|
||||
addLayout(new FloatLayout(VERTEX_INDEX, 3, vertices, Layout.FLOATING_POINT));
|
||||
addLayout(new FloatLayout(NORMAL_INDEX, 3, normals, Layout.FLOATING_POINT));
|
||||
addLayout(new FloatLayout(UV0_INDEX, 2, uv0, Layout.FLOATING_POINT));
|
||||
addLayout(new FloatLayout(UV1_INDEX, 2, uv1, Layout.FLOATING_POINT));
|
||||
addLayout(new FloatLayout(COLOR0_INDEX, 4, color0, Layout.FLOATING_POINT));
|
||||
addLayout(new FloatLayout(LIGHT0_INDEX, 3, light0, Layout.FLOATING_POINT));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TFloatList getVertices() {
|
||||
return vertices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return (this.vertices.size() / 3);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.engine.rendering.assets.mesh.layout;
|
||||
|
||||
import gnu.trove.list.TByteList;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class ByteLayout extends Layout<TByteList> {
|
||||
public ByteLayout(int location, int size, TByteList buffer, long flags) {
|
||||
super(location, size, buffer, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent() {
|
||||
return buffer.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int index, ByteBuffer data) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
data.put(buffer.get(index * size + x));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytes() {
|
||||
return this.size * Byte.BYTES;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.engine.rendering.assets.mesh.layout;
|
||||
|
||||
import gnu.trove.list.TDoubleList;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class DoubleLayout extends Layout<TDoubleList> {
|
||||
public DoubleLayout(int location, int size, TDoubleList buffer, long flags) {
|
||||
super(location, size, buffer, flags | Layout.FLOATING_POINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent() {
|
||||
return buffer.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int index, ByteBuffer data) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
data.putDouble(buffer.get(index * size + x));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytes() {
|
||||
return this.size * Double.BYTES;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.engine.rendering.assets.mesh.layout;
|
||||
|
||||
import gnu.trove.list.TFloatList;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class FloatLayout extends Layout<TFloatList> {
|
||||
|
||||
public FloatLayout(int location, int size, TFloatList buffer, long flags) {
|
||||
super(location, size, buffer, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent() {
|
||||
return buffer.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int index, ByteBuffer data) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
data.putFloat(buffer.get(index * size + x));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytes() {
|
||||
return this.size * Float.BYTES;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.engine.rendering.assets.mesh.layout;
|
||||
|
||||
import gnu.trove.list.TIntList;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class IntLayout extends Layout<TIntList> {
|
||||
public IntLayout(int location, int size, TIntList buffer, long flags) {
|
||||
super(location, size, buffer, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent() {
|
||||
return this.buffer.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int index, ByteBuffer data) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
data.putInt(buffer.get(index * size + x));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytes() {
|
||||
return this.size * Integer.BYTES;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.engine.rendering.assets.mesh.layout;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public abstract class Layout<T> {
|
||||
public static final int NONE = 0x0;
|
||||
public static final int FLOATING_POINT = 0x1;
|
||||
public static final int NORMALIZED = 0x2;
|
||||
|
||||
public final int location;
|
||||
public final int size;
|
||||
public final T buffer;
|
||||
public final long flag;
|
||||
|
||||
public Layout(int location, int size, T buffer, long flag) {
|
||||
this.location = location;
|
||||
this.size = size;
|
||||
this.buffer = buffer;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public abstract boolean hasContent();
|
||||
|
||||
public abstract void write(int index, ByteBuffer data);
|
||||
|
||||
public abstract int bytes();
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.engine.rendering.assets.mesh.layout;
|
||||
|
||||
import gnu.trove.list.TShortList;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class ShortLayout extends Layout<TShortList> {
|
||||
public ShortLayout(int location, int size, TShortList buffer, long flags) {
|
||||
super(location, size, buffer, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent() {
|
||||
return buffer.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int index, ByteBuffer data) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
data.putShort(buffer.get(index * size + x));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bytes() {
|
||||
return this.size * Short.BYTES;
|
||||
}
|
||||
}
|
|
@ -5,12 +5,11 @@ package org.terasology.engine.rendering.assets.shader;
|
|||
import java.util.Collection;
|
||||
|
||||
public enum ShaderProgramFeature {
|
||||
FEATURE_REFRACTIVE_PASS(0b00000001),
|
||||
FEATURE_ALPHA_REJECT(0b00000010),
|
||||
FEATURE_LIGHT_POINT(0b00000100),
|
||||
FEATURE_LIGHT_DIRECTIONAL(0b00001000),
|
||||
FEATURE_USE_MATRIX_STACK(0b00100000),
|
||||
FEATURE_USE_FORWARD_LIGHTING(0b01000000);
|
||||
FEATURE_REFRACTIVE_PASS(0x01),
|
||||
FEATURE_ALPHA_REJECT(0x02),
|
||||
FEATURE_LIGHT_POINT(0x04),
|
||||
FEATURE_LIGHT_DIRECTIONAL(0x08),
|
||||
FEATURE_USE_FORWARD_LIGHTING(0x10);
|
||||
|
||||
private int value;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import gnu.trove.list.TIntList;
|
|||
import gnu.trove.list.array.TIntArrayList;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.terasology.engine.rendering.assets.mesh.StandardMeshData;
|
||||
import org.terasology.joml.geom.AABBf;
|
||||
import org.terasology.engine.rendering.assets.mesh.MeshBuilder;
|
||||
import org.terasology.engine.rendering.assets.mesh.MeshData;
|
||||
|
@ -56,10 +57,10 @@ public class SkeletalMeshDataBuilder {
|
|||
return addMesh(bone, builder.getMeshData());
|
||||
}
|
||||
|
||||
public SkeletalMeshDataBuilder addMesh(Bone bone, MeshData data) {
|
||||
public SkeletalMeshDataBuilder addMesh(Bone bone, StandardMeshData data) {
|
||||
TFloatList meshVertices = data.getVertices();
|
||||
TIntList meshIndices = data.getIndices();
|
||||
TFloatList texCoord0 = data.getTexCoord0();
|
||||
TFloatList texCoord0 = data.uv0;
|
||||
int weightsStart = weights.size();
|
||||
addBone(bone);
|
||||
for (int i = 0; i < meshVertices.size() / 3; i++) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
*
|
||||
* The default instance of this class resets both matrices to identity matrices, OpenGL's default.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LookThrough implements StateChange {
|
||||
private static StateChange defaultInstance = new LookThroughDefault();
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.terasology.assets.format.AssetDataFile;
|
|||
import org.terasology.assets.management.AssetManager;
|
||||
import org.terasology.assets.module.annotations.RegisterAssetFileFormat;
|
||||
import org.terasology.engine.rendering.assets.mesh.MeshData;
|
||||
import org.terasology.engine.rendering.assets.mesh.StandardMeshData;
|
||||
import org.terasology.engine.rendering.gltf.model.GLTF;
|
||||
import org.terasology.engine.rendering.gltf.model.GLTFAccessor;
|
||||
import org.terasology.engine.rendering.gltf.model.GLTFBufferView;
|
||||
|
@ -62,7 +63,7 @@ public class GLTFMeshFormat extends GLTFCommonFormat<MeshData> {
|
|||
|
||||
List<byte[]> loadedBuffers = loadBinaryBuffers(urn, gltf);
|
||||
|
||||
MeshData mesh = new MeshData();
|
||||
StandardMeshData mesh = new StandardMeshData();
|
||||
for (MeshAttributeSemantic semantic : MeshAttributeSemantic.values()) {
|
||||
GLTFAccessor gltfAccessor = getAccessor(semantic, gltfPrimitive, gltf);
|
||||
if (gltfAccessor != null && gltfAccessor.getBufferView() != null) {
|
||||
|
@ -78,7 +79,7 @@ public class GLTFMeshFormat extends GLTFCommonFormat<MeshData> {
|
|||
checkIndicesBuffer(indicesBuffer);
|
||||
|
||||
readBuffer(loadedBuffers.get(indicesBuffer.getBuffer()), indicesAccessor, indicesBuffer, mesh.getIndices());
|
||||
applyTransformations(gltf, mesh.getVertices(), mesh.getNormals());
|
||||
applyTransformations(gltf, mesh.getVertices(), mesh.normals);
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet;
|
|||
import gnu.trove.list.TFloatList;
|
||||
import gnu.trove.list.array.TFloatArrayList;
|
||||
import org.terasology.engine.rendering.assets.mesh.MeshData;
|
||||
import org.terasology.engine.rendering.assets.mesh.StandardMeshData;
|
||||
import org.terasology.engine.rendering.gltf.model.GLTFAttributeType;
|
||||
import org.terasology.engine.rendering.gltf.model.GLTFComponentType;
|
||||
|
||||
|
@ -16,24 +17,24 @@ import java.util.function.Function;
|
|||
* Enumeration of the vertex Attribute Semantics supported by Terasology.
|
||||
*/
|
||||
public enum MeshAttributeSemantic {
|
||||
Normal("NORMAL", GLTFAttributeType.VEC3, GLTFComponentType.FLOAT, MeshData::getNormals),
|
||||
Normal("NORMAL", GLTFAttributeType.VEC3, GLTFComponentType.FLOAT, k -> k.normals),
|
||||
Position("POSITION", GLTFAttributeType.VEC3, GLTFComponentType.FLOAT, MeshData::getVertices),
|
||||
Texcoord_0("TEXCOORD_0", GLTFAttributeType.VEC2, GLTFComponentType.FLOAT, MeshData::getTexCoord0),
|
||||
Texcoord_1("TEXCOORD_1", GLTFAttributeType.VEC2, GLTFComponentType.FLOAT, MeshData::getTexCoord1),
|
||||
Color_0("COLOR_0", new GLTFAttributeType[]{GLTFAttributeType.VEC4}, new GLTFComponentType[]{GLTFComponentType.FLOAT}, MeshData::getColors),
|
||||
Texcoord_0("TEXCOORD_0", GLTFAttributeType.VEC2, GLTFComponentType.FLOAT, k -> k.uv0),
|
||||
Texcoord_1("TEXCOORD_1", GLTFAttributeType.VEC2, GLTFComponentType.FLOAT, k -> k.uv1),
|
||||
Color_0("COLOR_0", new GLTFAttributeType[]{GLTFAttributeType.VEC4}, new GLTFComponentType[]{GLTFComponentType.FLOAT}, k-> k.color0),
|
||||
Joints_0("JOINTS_0", new GLTFAttributeType[]{GLTFAttributeType.VEC4}, new GLTFComponentType[]{GLTFComponentType.UNSIGNED_BYTE, GLTFComponentType.UNSIGNED_SHORT}, x -> new TFloatArrayList()),
|
||||
Weights_0("WEIGHTS_0", new GLTFAttributeType[]{GLTFAttributeType.VEC4}, new GLTFComponentType[]{GLTFComponentType.FLOAT}, x -> new TFloatArrayList());
|
||||
|
||||
private final String name;
|
||||
private final Set<GLTFAttributeType> supportedAccessorTypes;
|
||||
private final Set<GLTFComponentType> supportedComponentTypes;
|
||||
private final Function<MeshData, TFloatList> targetBufferSupplier;
|
||||
private final Function<StandardMeshData, TFloatList> targetBufferSupplier;
|
||||
|
||||
MeshAttributeSemantic(String name, GLTFAttributeType supportedAccessorType, GLTFComponentType supportedComponentType, Function<MeshData, TFloatList> targetBufferSupplier) {
|
||||
MeshAttributeSemantic(String name, GLTFAttributeType supportedAccessorType, GLTFComponentType supportedComponentType, Function<StandardMeshData, TFloatList> targetBufferSupplier) {
|
||||
this(name, new GLTFAttributeType[]{supportedAccessorType}, new GLTFComponentType[]{supportedComponentType}, targetBufferSupplier);
|
||||
}
|
||||
|
||||
MeshAttributeSemantic(String name, GLTFAttributeType[] supportedAccessorTypes, GLTFComponentType[] supportedComponentTypes, Function<MeshData, TFloatList> targetBufferSupplier) {
|
||||
MeshAttributeSemantic(String name, GLTFAttributeType[] supportedAccessorTypes, GLTFComponentType[] supportedComponentTypes, Function<StandardMeshData, TFloatList> targetBufferSupplier) {
|
||||
this.name = name;
|
||||
this.supportedAccessorTypes = ImmutableSet.copyOf(supportedAccessorTypes);
|
||||
this.supportedComponentTypes = ImmutableSet.copyOf(supportedComponentTypes);
|
||||
|
@ -65,7 +66,7 @@ public enum MeshAttributeSemantic {
|
|||
* @param meshData
|
||||
* @return The list of floats from mesh data that corresponds to this attribute
|
||||
*/
|
||||
public TFloatList getTargetFloatBuffer(MeshData meshData) {
|
||||
public TFloatList getTargetFloatBuffer(StandardMeshData meshData) {
|
||||
return (TFloatList) targetBufferSupplier.apply(meshData);
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,6 @@ public class MeshRenderer extends BaseComponentSystem implements RenderSystem {
|
|||
|
||||
for (Material material : meshByMaterial.keySet()) {
|
||||
if (material.isRenderable()) {
|
||||
OpenGLMesh lastMesh = null;
|
||||
material.enable();
|
||||
material.setFloat("sunlight", 1.0f, true);
|
||||
material.setFloat("blockLight", 1.0f, true);
|
||||
|
@ -202,32 +201,21 @@ public class MeshRenderer extends BaseComponentSystem implements RenderSystem {
|
|||
|
||||
AABBf aabb = meshComp.mesh.getAABB().transform(new Matrix4f().translationRotateScale(worldPos, worldRot, worldScale), new AABBf());
|
||||
if (worldRenderer.getActiveCamera().hasInSight(aabb)) {
|
||||
if (meshComp.mesh != lastMesh) {
|
||||
if (lastMesh != null) {
|
||||
lastMesh.postRender();
|
||||
}
|
||||
lastMesh = (OpenGLMesh) meshComp.mesh;
|
||||
lastMesh.preRender();
|
||||
}
|
||||
|
||||
modelViewMatrix.set(worldRenderer.getActiveCamera().getViewMatrix()).mul(matrixCameraSpace);
|
||||
modelViewMatrix.get(tempMatrixBuffer44);
|
||||
modelViewMatrix.normal(normalMatrix).get(tempMatrixBuffer33);
|
||||
|
||||
material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix(), true);
|
||||
material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true);
|
||||
material.setMatrix4("modelViewMatrix", tempMatrixBuffer44, true);
|
||||
material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
|
||||
|
||||
material.setFloat3("colorOffset", meshComp.color.rf(), meshComp.color.gf(), meshComp.color.bf(), true);
|
||||
material.setFloat("sunlight", worldRenderer.getMainLightIntensityAt(worldPos), true);
|
||||
material.setFloat("blockLight", Math.max(worldRenderer.getBlockLightIntensityAt(worldPos), meshComp.selfLuminance), true);
|
||||
|
||||
lastMesh.doRender();
|
||||
meshComp.mesh.render();
|
||||
}
|
||||
}
|
||||
if (lastMesh != null) {
|
||||
lastMesh.postRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class RegionOutlineRenderer extends BaseComponentSystem implements Render
|
|||
modelViewMatrix.get(tempMatrixBuffer44);
|
||||
modelViewMatrix.normal(normalMatrix).get(tempMatrixBuffer33);
|
||||
|
||||
material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true);
|
||||
material.setMatrix4("modelViewMatrix", tempMatrixBuffer44, true);
|
||||
material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
|
||||
|
||||
for (RegionOutlineComponent regionOutline : entityToRegionOutlineMap.values()) {
|
||||
|
|
|
@ -268,7 +268,7 @@ public class SkeletonRenderer extends BaseComponentSystem implements RenderSyste
|
|||
|
||||
Matrix4f modelViewMatrix = worldRenderer.getActiveCamera().getViewMatrix().mul(matrixCameraSpace, new Matrix4f());
|
||||
modelViewMatrix.get(tempMatrixBuffer44);
|
||||
skeletalMesh.material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true);
|
||||
skeletalMesh.material.setMatrix4("modelViewMatrix", tempMatrixBuffer44, true);
|
||||
|
||||
modelViewMatrix.normal(new Matrix3f()).get(tempMatrixBuffer33);
|
||||
skeletalMesh.material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
|
||||
|
@ -331,7 +331,7 @@ public class SkeletonRenderer extends BaseComponentSystem implements RenderSyste
|
|||
|
||||
Matrix4f modelViewMatrix = worldRenderer.getActiveCamera().getViewMatrix().mul(matrixCameraSpace, new Matrix4f());
|
||||
modelViewMatrix.get(tempMatrixBuffer44);
|
||||
material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true);
|
||||
material.setMatrix4("modelViewMatrix", tempMatrixBuffer44, true);
|
||||
|
||||
modelViewMatrix.get3x3(new Matrix3f()).invert().get(tempMatrixBuffer33);
|
||||
material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
|
||||
|
|
|
@ -5,7 +5,9 @@ package org.terasology.engine.rendering.nui.internal;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fStack;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Quaternionfc;
|
||||
import org.joml.Vector2f;
|
||||
|
@ -13,7 +15,6 @@ import org.joml.Vector2i;
|
|||
import org.joml.Vector2ic;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.terasology.assets.ResourceUrn;
|
||||
import org.terasology.assets.management.AssetManager;
|
||||
|
@ -23,11 +24,12 @@ import org.terasology.engine.context.Context;
|
|||
import org.terasology.engine.core.subsystem.DisplayDevice;
|
||||
import org.terasology.engine.rendering.assets.font.FontMeshBuilder;
|
||||
import org.terasology.engine.rendering.assets.material.Material;
|
||||
import org.terasology.engine.rendering.assets.mesh.Mesh;
|
||||
import org.terasology.engine.rendering.assets.mesh.MeshBuilder;
|
||||
import org.terasology.engine.rendering.assets.shader.ShaderProgramFeature;
|
||||
import org.terasology.engine.rendering.assets.texture.TextureRegion;
|
||||
import org.terasology.engine.rendering.opengl.FrameBufferObject;
|
||||
import org.terasology.engine.rendering.opengl.LwjglFrameBufferObject;
|
||||
import org.terasology.engine.utilities.Assets;
|
||||
import org.terasology.joml.geom.AABBfc;
|
||||
import org.terasology.joml.geom.Rectanglef;
|
||||
import org.terasology.joml.geom.Rectanglei;
|
||||
|
@ -40,13 +42,9 @@ import org.terasology.nui.TextLineBuilder;
|
|||
import org.terasology.nui.UITextureRegion;
|
||||
import org.terasology.nui.VerticalAlign;
|
||||
import org.terasology.nui.asset.font.Font;
|
||||
import org.terasology.nui.util.RectUtility;
|
||||
import org.terasology.engine.rendering.assets.mesh.Mesh;
|
||||
import org.terasology.engine.utilities.Assets;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -55,29 +53,17 @@ import java.util.Set;
|
|||
|
||||
import static org.lwjgl.opengl.GL11.GL_BLEND;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
|
||||
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.glBlendFunc;
|
||||
import static org.lwjgl.opengl.GL11.glClear;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glLoadIdentity;
|
||||
import static org.lwjgl.opengl.GL11.glLoadMatrixf;
|
||||
import static org.lwjgl.opengl.GL11.glMatrixMode;
|
||||
import static org.lwjgl.opengl.GL11.glOrtho;
|
||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glScalef;
|
||||
import static org.lwjgl.opengl.GL11.glTranslatef;
|
||||
|
||||
public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyChangeListener {
|
||||
|
||||
private static final String CROPPING_BOUNDARIES_PARAM = "croppingBoundaries";
|
||||
private static final Rectanglef FULL_REGION = new Rectanglef(0, 0, 1, 1);
|
||||
private Matrix4f modelView;
|
||||
private FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
|
||||
private Mesh billboard;
|
||||
|
||||
private Material textureMat;
|
||||
|
@ -100,6 +86,9 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
private DisplayDevice displayDevice;
|
||||
private float uiScale = 1f;
|
||||
|
||||
private Matrix4fStack modelMatrixStack = new Matrix4fStack(1000);
|
||||
private Matrix4f projMatrix = new Matrix4f();
|
||||
|
||||
public LwjglCanvasRenderer(Context context) {
|
||||
// TODO use context to get assets instead of static methods
|
||||
this.textureMat = Assets.getMaterial("engine:UITexture").orElseThrow(
|
||||
|
@ -123,20 +112,10 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, displayDevice.getWidth(), displayDevice.getHeight(), 0, 0, 2048f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
modelView = new Matrix4f().setTranslation(0, 0, -1024f);
|
||||
|
||||
modelView.get(matrixBuffer);
|
||||
glLoadMatrixf(matrixBuffer);
|
||||
matrixBuffer.rewind();
|
||||
|
||||
glScalef(uiScale, uiScale, uiScale);
|
||||
projMatrix.setOrtho(0, displayDevice.getWidth(), displayDevice.getHeight(),0,0, 2048f);
|
||||
modelMatrixStack.pushMatrix();
|
||||
modelMatrixStack.set(new Matrix4f().setTranslation(0,0,-1024));
|
||||
modelMatrixStack.scale(uiScale, uiScale, uiScale);
|
||||
|
||||
requestedCropRegion = new Rectanglei(0, 0,displayDevice.getWidth(), displayDevice.getHeight());
|
||||
currentTextureCropRegion = requestedCropRegion;
|
||||
|
@ -166,11 +145,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
}
|
||||
usedTextures.clear();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
modelMatrixStack.popMatrix();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
@ -183,22 +158,21 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
|
||||
AABBfc meshAABB = mesh.getAABB();
|
||||
Vector3f meshExtents = meshAABB.extent(new Vector3f());
|
||||
float fitScale = 0.35f * Math.min(drawRegion.lengthX(), drawRegion.lengthY()) / Math.max(meshExtents.x, Math.max(meshExtents.y, meshExtents.z));
|
||||
float fitScale = 0.35f * Math.min(drawRegion.getSizeX(), drawRegion.getSizeY()) / Math.max(meshExtents.x, Math.max(meshExtents.y, meshExtents.z));
|
||||
Vector3f centerOffset = meshAABB.center(new Vector3f());
|
||||
centerOffset.mul(-1.0f);
|
||||
|
||||
Matrix4f centerTransform = new Matrix4f().translationRotateScale(centerOffset,new Quaternionf(),1);
|
||||
Matrix4f userTransform = new Matrix4f().translationRotateScale( offset,rotation, -fitScale * scale);
|
||||
Matrix4f translateTransform = new Matrix4f().translationRotateScale(
|
||||
new Vector3f((drawRegion.minX + drawRegion.lengthX() / 2) * uiScale,
|
||||
(drawRegion.minY + drawRegion.lengthY() / 2) * uiScale, 0), new Quaternionf(), 1);
|
||||
new Vector3f((drawRegion.minX + drawRegion.getSizeX() / 2) * uiScale,
|
||||
(drawRegion.minY + drawRegion.getSizeY() / 2) * uiScale, 0), new Quaternionf(), 1);
|
||||
|
||||
userTransform.mul(centerTransform);
|
||||
translateTransform.mul(userTransform);
|
||||
|
||||
Matrix4f finalMat = new Matrix4f(modelView);
|
||||
Matrix4f finalMat = new Matrix4f().setTranslation(0, 0, -1024f);
|
||||
finalMat.mul(translateTransform);
|
||||
finalMat.get(matrixBuffer);
|
||||
|
||||
material.setFloat4(
|
||||
CROPPING_BOUNDARIES_PARAM,
|
||||
|
@ -206,28 +180,24 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
cropRegion.maxX * uiScale,
|
||||
cropRegion.minY * uiScale,
|
||||
cropRegion.maxY * uiScale);
|
||||
material.setMatrix4("posMatrix", translateTransform);
|
||||
|
||||
glEnable(GL11.GL_DEPTH_TEST);
|
||||
glClear(GL11.GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL11.GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadMatrixf(matrixBuffer);
|
||||
|
||||
glScalef(this.uiScale, this.uiScale, this.uiScale);
|
||||
matrixBuffer.rewind();
|
||||
modelMatrixStack.pushMatrix();
|
||||
modelMatrixStack.set(finalMat);
|
||||
modelMatrixStack.scale(this.uiScale, this.uiScale, this.uiScale);
|
||||
|
||||
material.setMatrix4("posMatrix", translateTransform);
|
||||
material.setMatrix4("projectionMatrix", projMatrix);
|
||||
material.setMatrix4("modelViewMatrix", modelMatrixStack);
|
||||
material.setMatrix3("normalMatrix", modelMatrixStack.normal(new Matrix3f()));
|
||||
|
||||
boolean matrixStackSupported = material.supportsFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK);
|
||||
if (matrixStackSupported) {
|
||||
material.activateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK);
|
||||
}
|
||||
material.setFloat("alpha", alpha);
|
||||
material.bindTextures();
|
||||
mesh.render();
|
||||
if (matrixStackSupported) {
|
||||
material.deactivateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
modelMatrixStack.popMatrix();
|
||||
glDisable(GL11.GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
|
@ -237,12 +207,16 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
}
|
||||
|
||||
@Override
|
||||
// so this is unused??
|
||||
public void drawMaterialAt(Material material, Rectanglei drawRegion) {
|
||||
glPushMatrix();
|
||||
glTranslatef(drawRegion.minX, drawRegion.minY, 0f);
|
||||
glScalef(drawRegion.lengthX(), drawRegion.lengthY(), 1);
|
||||
modelMatrixStack.pushMatrix();
|
||||
modelMatrixStack.translate(drawRegion.minX, drawRegion.minY, 0f);
|
||||
modelMatrixStack.scale(drawRegion.getSizeX(), drawRegion.getSizeY(), 1);
|
||||
|
||||
material.setMatrix4("projectionMatrix", projMatrix);
|
||||
material.setMatrix4("modelViewMatrix", modelMatrixStack);
|
||||
billboard.render();
|
||||
glPopMatrix();
|
||||
modelMatrixStack.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -293,7 +267,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
switch (mode) {
|
||||
case TILED: {
|
||||
Vector2i textureSize = texture.size();
|
||||
TextureCacheKey key = new TextureCacheKey(textureSize, new Vector2i(absoluteRegion.lengthX(),absoluteRegion.lengthY()));
|
||||
TextureCacheKey key = new TextureCacheKey(textureSize, new Vector2i(absoluteRegion.getSizeX(),absoluteRegion.getSizeY()));
|
||||
usedTextures.add(key);
|
||||
mesh = cachedTextures.get(key);
|
||||
if (mesh == null || mesh.isDisposed()) {
|
||||
|
@ -307,36 +281,40 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
absoluteRegion.minX,
|
||||
absoluteRegion.minY);
|
||||
|
||||
textureMat.setFloat2("texOffset", textureArea.minX + ux * textureArea.lengthX(), textureArea.minY + uy * textureArea.lengthY());
|
||||
textureMat.setFloat2("texSize", uw * textureArea.lengthX(), uh * textureArea.lengthY());
|
||||
textureMat.setFloat2("texOffset", textureArea.minX + ux * textureArea.getSizeX(), textureArea.minY + uy * textureArea.getSizeY());
|
||||
textureMat.setFloat2("texSize", uw * textureArea.getSizeX(), uh * textureArea.getSizeY());
|
||||
break;
|
||||
}
|
||||
case SCALE_FILL: {
|
||||
textureMat.setFloat2("offset", absoluteRegion.minX, absoluteRegion.minY);
|
||||
textureMat.setFloat2("scale", absoluteRegion.lengthX(), absoluteRegion.lengthY());
|
||||
textureMat.setFloat2("scale", absoluteRegion.getSizeX(), absoluteRegion.getSizeY());
|
||||
|
||||
float texBorderX = (scale.x - absoluteRegion.lengthX()) / scale.x * uw;
|
||||
float texBorderY = (scale.y - absoluteRegion.lengthY()) / scale.y * uh;
|
||||
float texBorderX = (scale.x - absoluteRegion.getSizeX()) / scale.x * uw;
|
||||
float texBorderY = (scale.y - absoluteRegion.getSizeY()) / scale.y * uh;
|
||||
|
||||
textureMat.setFloat2("texOffset", textureArea.minX + (ux + 0.5f * texBorderX) * textureArea.lengthX(),
|
||||
textureArea.minY + (uy + 0.5f * texBorderY) * textureArea.lengthY());
|
||||
textureMat.setFloat2("texSize", (uw - texBorderX) * textureArea.lengthX(), (uh - texBorderY) * textureArea.lengthY());
|
||||
textureMat.setFloat2("texOffset", textureArea.minX + (ux + 0.5f * texBorderX) * textureArea.getSizeX(),
|
||||
textureArea.minY + (uy + 0.5f * texBorderY) * textureArea.getSizeY());
|
||||
textureMat.setFloat2("texSize", (uw - texBorderX) * textureArea.getSizeX(), (uh - texBorderY) * textureArea.getSizeY());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
textureMat.setFloat2("scale", scale);
|
||||
textureMat.setFloat2("offset",
|
||||
absoluteRegion.minX + 0.5f * (absoluteRegion.lengthX() - scale.x),
|
||||
absoluteRegion.minY + 0.5f * (absoluteRegion.lengthY() - scale.y));
|
||||
absoluteRegion.minX + 0.5f * (absoluteRegion.getSizeX() - scale.x),
|
||||
absoluteRegion.minY + 0.5f * (absoluteRegion.getSizeY() - scale.y));
|
||||
|
||||
textureMat.setFloat2("texOffset", textureArea.minX + ux * textureArea.lengthX(), textureArea.minY + uy * textureArea.lengthY());
|
||||
textureMat.setFloat2("texSize", uw * textureArea.lengthX(), uh * textureArea.lengthY());
|
||||
textureMat.setFloat2("texOffset", textureArea.minX + ux * textureArea.getSizeX(), textureArea.minY + uy * textureArea.getSizeY());
|
||||
textureMat.setFloat2("texSize", uw * textureArea.getSizeX(), uh * textureArea.getSizeY());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
textureMat.setTexture("texture", ((TextureRegion)texture).getTexture());
|
||||
textureMat.setFloat4("color", color.rf(), color.gf(), color.bf(), color.af() * alpha);
|
||||
|
||||
textureMat.setMatrix4("projectionMatrix", projMatrix);
|
||||
textureMat.setMatrix4("modelViewMatrix", modelMatrixStack);
|
||||
|
||||
textureMat.bindTextures();
|
||||
mesh.render();
|
||||
}
|
||||
|
@ -346,10 +324,10 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
Colorc color, Colorc shadowColor, float alpha, boolean underlined) {
|
||||
Rectanglei absoluteRegion = new Rectanglei(absoluteRegionRectangle);
|
||||
|
||||
TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.lengthX(), hAlign, color, shadowColor, underlined);
|
||||
TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
|
||||
usedText.add(key);
|
||||
Map<Material, Mesh> fontMesh = cachedText.get(key);
|
||||
List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.lengthX());
|
||||
List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.getSizeX());
|
||||
if (fontMesh != null) {
|
||||
for (Mesh mesh : fontMesh.values()) {
|
||||
if (mesh.isDisposed()) {
|
||||
|
@ -359,7 +337,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
}
|
||||
}
|
||||
if (fontMesh == null) {
|
||||
fontMesh = fontMeshBuilder.createTextMesh((org.terasology.engine.rendering.assets.font.Font)font, lines, absoluteRegion.lengthX(), hAlign, color, shadowColor, underlined);
|
||||
fontMesh = fontMeshBuilder.createTextMesh((org.terasology.engine.rendering.assets.font.Font)font, lines, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
|
||||
cachedText.put(key, fontMesh);
|
||||
}
|
||||
|
||||
|
@ -368,6 +346,8 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
|
||||
fontMesh.entrySet().stream().filter(entry -> entry.getKey().isRenderable()).forEach(entry -> {
|
||||
entry.getKey().bindTextures();
|
||||
entry.getKey().setMatrix4("projectionMatrix", projMatrix);
|
||||
entry.getKey().setMatrix4("modelViewMatrix", modelMatrixStack);
|
||||
entry.getKey().setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX, requestedCropRegion.maxX,
|
||||
requestedCropRegion.minY, requestedCropRegion.maxY);
|
||||
entry.getKey().setFloat2("offset", offset.x, offset.y);
|
||||
|
@ -394,7 +374,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
|
||||
Vector2i textureSize = new Vector2i(TeraMath.ceilToInt(texture.getWidth() * uw), TeraMath.ceilToInt(texture.getHeight() * uh));
|
||||
|
||||
TextureCacheKey key = new TextureCacheKey(textureSize, new Vector2i(region.lengthX(), region.lengthY()), border, tile);
|
||||
TextureCacheKey key = new TextureCacheKey(textureSize, new Vector2i(region.getSizeX(), region.getSizeY()), border, tile);
|
||||
usedTextures.add(key);
|
||||
Mesh mesh = cachedTextures.get(key);
|
||||
if (mesh == null || mesh.isDisposed()) {
|
||||
|
@ -405,20 +385,21 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
float leftTex = (float) border.getLeft() / textureSize.x;
|
||||
float bottomTex = 1f - (float) border.getBottom() / textureSize.y;
|
||||
float rightTex = 1f - (float) border.getRight() / textureSize.x;
|
||||
int centerHoriz = region.lengthX() - border.getTotalWidth();
|
||||
int centerVert = region.lengthY() - border.getTotalHeight();
|
||||
int centerHoriz = region.getSizeX() - border.getTotalWidth();
|
||||
int centerVert = region.getSizeY() - border.getTotalHeight();
|
||||
|
||||
float top = (float) border.getTop() / region.lengthY();
|
||||
float left = (float) border.getLeft() / region.lengthX();
|
||||
float bottom = 1f - (float) border.getBottom() / region.lengthY();
|
||||
float right = 1f - (float) border.getRight() / region.lengthX();
|
||||
float top = (float) border.getTop() / region.getSizeY();
|
||||
float left = (float) border.getLeft() / region.getSizeX();
|
||||
float bottom = 1f - (float) border.getBottom() / region.getSizeY();
|
||||
float right = 1f - (float) border.getRight() / region.getSizeX();
|
||||
|
||||
if (border.getTop() != 0) {
|
||||
if (border.getLeft() != 0) {
|
||||
addRectPoly(builder, 0, 0, left, top, 0, 0, leftTex, topTex);
|
||||
}
|
||||
if (tile) {
|
||||
addTiles(builder, RectUtility.createFromMinAndSize(border.getLeft(), 0, centerHoriz, border.getTop()),
|
||||
|
||||
addTiles(builder, new Rectanglei(border.getLeft(), 0).setSize(centerHoriz, border.getTop()),
|
||||
new Rectanglef(left, 0, right, top),
|
||||
new Vector2i(textureSize.x - border.getTotalWidth(), border.getTop()),
|
||||
new Rectanglef(leftTex, 0, rightTex, topTex));
|
||||
|
@ -432,7 +413,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
|
||||
if (border.getLeft() != 0) {
|
||||
if (tile) {
|
||||
addTiles(builder, RectUtility.createFromMinAndSize(0, border.getTop(), border.getLeft(), centerVert),
|
||||
addTiles(builder, new Rectanglei(0, border.getTop()).setSize(border.getLeft(), centerVert),
|
||||
new Rectanglef(0, top, left, bottom),
|
||||
new Vector2i(border.getLeft(), textureSize.y - border.getTotalHeight()),
|
||||
new Rectanglef(0, topTex, leftTex, bottomTex));
|
||||
|
@ -442,7 +423,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
}
|
||||
|
||||
if (tile) {
|
||||
addTiles(builder, RectUtility.createFromMinAndSize(border.getLeft(), border.getTop(), centerHoriz, centerVert),
|
||||
addTiles(builder, new Rectanglei(border.getLeft(), border.getTop()).setSize(centerHoriz, centerVert),
|
||||
new Rectanglef(left, top, right, bottom),
|
||||
new Vector2i(textureSize.x - border.getTotalWidth(), textureSize.y - border.getTotalHeight()),
|
||||
new Rectanglef(leftTex, topTex, rightTex, bottomTex));
|
||||
|
@ -452,7 +433,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
|
||||
if (border.getRight() != 0) {
|
||||
if (tile) {
|
||||
addTiles(builder, RectUtility.createFromMinAndSize(region.lengthX() - border.getRight(), border.getTop(), border.getRight(), centerVert),
|
||||
addTiles(builder, new Rectanglei(region.getSizeX() - border.getRight(), border.getTop()).setSize(border.getRight(), centerVert),
|
||||
new Rectanglef(right, top, 1, bottom),
|
||||
new Vector2i(border.getRight(), textureSize.y - border.getTotalHeight()),
|
||||
new Rectanglef(rightTex, topTex, 1, bottomTex));
|
||||
|
@ -466,7 +447,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
addRectPoly(builder, 0, bottom, left, 1, 0, bottomTex, leftTex, 1);
|
||||
}
|
||||
if (tile) {
|
||||
addTiles(builder, RectUtility.createFromMinAndSize(border.getLeft(), region.lengthY() - border.getBottom(), centerHoriz, border.getBottom()),
|
||||
addTiles(builder, new Rectanglei(border.getLeft(), region.getSizeY() - border.getBottom()).setSize(centerHoriz, border.getBottom()),
|
||||
new Rectanglef(left, bottom, right, 1),
|
||||
new Vector2i(textureSize.x - border.getTotalWidth(), border.getBottom()),
|
||||
new Rectanglef(leftTex, bottomTex, rightTex, 1));
|
||||
|
@ -481,7 +462,7 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
mesh = builder.build();
|
||||
cachedTextures.put(key, mesh);
|
||||
}
|
||||
textureMat.setFloat2("scale", region.lengthX(), region.lengthY());
|
||||
textureMat.setFloat2("scale", region.getSizeX(), region.getSizeY());
|
||||
textureMat.setFloat2("offset", region.minX, region.minY);
|
||||
|
||||
Rectanglef textureArea = texture.getRegion();
|
||||
|
@ -510,25 +491,25 @@ public class LwjglCanvasRenderer implements TerasologyCanvasRenderer, PropertyCh
|
|||
private void addTiles(MeshBuilder builder, Rectanglei drawRegion, Rectanglef subDrawRegion, Vector2i textureSize, Rectanglef subTextureRegion) {
|
||||
int tileW = textureSize.x;
|
||||
int tileH = textureSize.y;
|
||||
int horizTiles = TeraMath.fastAbs((drawRegion.lengthX() - 1) / tileW) + 1;
|
||||
int vertTiles = TeraMath.fastAbs((drawRegion.lengthY() - 1) / tileH) + 1;
|
||||
int horizTiles = TeraMath.fastAbs((drawRegion.getSizeX() - 1) / tileW) + 1;
|
||||
int vertTiles = TeraMath.fastAbs((drawRegion.getSizeY() - 1) / tileH) + 1;
|
||||
|
||||
int offsetX = (drawRegion.lengthX() - horizTiles * tileW) / 2;
|
||||
int offsetY = (drawRegion.lengthY() - vertTiles * tileH) / 2;
|
||||
int offsetX = (drawRegion.getSizeX() - horizTiles * tileW) / 2;
|
||||
int offsetY = (drawRegion.getSizeY() - vertTiles * tileH) / 2;
|
||||
|
||||
for (int tileY = 0; tileY < vertTiles; tileY++) {
|
||||
for (int tileX = 0; tileX < horizTiles; tileX++) {
|
||||
int left = offsetX + tileW * tileX;
|
||||
int top = offsetY + tileH * tileY;
|
||||
|
||||
float vertLeft = subDrawRegion.minX + subDrawRegion.lengthX() * Math.max((float) left / drawRegion.lengthX(), 0);
|
||||
float vertTop = subDrawRegion.minY + subDrawRegion.lengthY() * Math.max((float) top / drawRegion.lengthY(), 0);
|
||||
float vertRight = subDrawRegion.minX + subDrawRegion.lengthX() * Math.min((float) (left + tileW) / drawRegion.lengthX(), 1);
|
||||
float vertBottom = subDrawRegion.minY + subDrawRegion.lengthY() * Math.min((float) (top + tileH) / drawRegion.lengthY(), 1);
|
||||
float texCoordLeft = subTextureRegion.minX + subTextureRegion.lengthX() * (Math.max(left, 0) - left) / tileW;
|
||||
float texCoordTop = subTextureRegion.minY + subTextureRegion.lengthY() * (Math.max(top, 0) - top) / tileH;
|
||||
float texCoordRight = subTextureRegion.minX + subTextureRegion.lengthX() * (Math.min(left + tileW, drawRegion.lengthX()) - left) / tileW;
|
||||
float texCoordBottom = subTextureRegion.minY + subTextureRegion.lengthY() * (Math.min(top + tileH, drawRegion.lengthY()) - top) / tileH;
|
||||
float vertLeft = subDrawRegion.minX + subDrawRegion.getSizeX() * Math.max((float) left / drawRegion.getSizeX(), 0);
|
||||
float vertTop = subDrawRegion.minY + subDrawRegion.getSizeY() * Math.max((float) top / drawRegion.getSizeY(), 0);
|
||||
float vertRight = subDrawRegion.minX + subDrawRegion.getSizeX() * Math.min((float) (left + tileW) / drawRegion.getSizeX(), 1);
|
||||
float vertBottom = subDrawRegion.minY + subDrawRegion.getSizeY() * Math.min((float) (top + tileH) / drawRegion.getSizeY(), 1);
|
||||
float texCoordLeft = subTextureRegion.minX + subTextureRegion.getSizeX() * (Math.max(left, 0) - left) / tileW;
|
||||
float texCoordTop = subTextureRegion.minY + subTextureRegion.getSizeY() * (Math.max(top, 0) - top) / tileH;
|
||||
float texCoordRight = subTextureRegion.minX + subTextureRegion.getSizeX() * (Math.min(left + tileW, drawRegion.getSizeX()) - left) / tileW;
|
||||
float texCoordBottom = subTextureRegion.minY + subTextureRegion.getSizeY() * (Math.min(top + tileH, drawRegion.getSizeY()) - top) / tileH;
|
||||
|
||||
addRectPoly(builder, vertLeft, vertTop, vertRight, vertBottom, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom);
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ import org.terasology.engine.input.cameraTarget.CameraTargetSystem;
|
|||
import org.terasology.engine.logic.players.LocalPlayer;
|
||||
import org.terasology.engine.math.Orientation;
|
||||
import org.terasology.engine.monitoring.PerformanceMonitor;
|
||||
import org.terasology.engine.rendering.primitives.ChunkTessellator;
|
||||
import org.terasology.nui.databinding.ReadOnlyBinding;
|
||||
import org.terasology.nui.widgets.UILabel;
|
||||
import org.terasology.engine.persistence.StorageManager;
|
||||
import org.terasology.engine.registry.In;
|
||||
import org.terasology.engine.rendering.nui.CoreScreenLayer;
|
||||
import org.terasology.engine.rendering.primitives.ChunkTessellator;
|
||||
import org.terasology.engine.world.WorldProvider;
|
||||
import org.terasology.engine.world.chunks.Chunks;
|
||||
import org.terasology.nui.databinding.ReadOnlyBinding;
|
||||
import org.terasology.nui.widgets.UILabel;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
|
|
@ -2,16 +2,14 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
package org.terasology.engine.rendering.opengl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import gnu.trove.iterator.TFloatIterator;
|
||||
import gnu.trove.iterator.TIntIterator;
|
||||
import gnu.trove.list.TFloatList;
|
||||
import gnu.trove.list.TIntList;
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL33;
|
||||
import org.lwjgl.opengl.GL41;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.assets.AssetType;
|
||||
|
@ -19,56 +17,37 @@ import org.terasology.assets.ResourceUrn;
|
|||
import org.terasology.engine.core.GameThread;
|
||||
import org.terasology.engine.core.subsystem.lwjgl.GLBufferPool;
|
||||
import org.terasology.engine.core.subsystem.lwjgl.LwjglGraphicsProcessing;
|
||||
import org.terasology.joml.geom.AABBf;
|
||||
import org.terasology.joml.geom.AABBfc;
|
||||
import org.terasology.engine.rendering.VertexBufferObjectUtil;
|
||||
import org.terasology.engine.rendering.assets.mesh.Mesh;
|
||||
import org.terasology.engine.rendering.assets.mesh.MeshData;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.ByteLayout;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.DoubleLayout;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.FloatLayout;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.IntLayout;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.Layout;
|
||||
import org.terasology.engine.rendering.assets.mesh.layout.ShortLayout;
|
||||
import org.terasology.joml.geom.AABBf;
|
||||
import org.terasology.joml.geom.AABBfc;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_NORMAL_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_COORD_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT;
|
||||
import static org.lwjgl.opengl.GL11.GL_VERTEX_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.glColorPointer;
|
||||
import static org.lwjgl.opengl.GL11.glDisableClientState;
|
||||
import static org.lwjgl.opengl.GL11.glEnableClientState;
|
||||
import static org.lwjgl.opengl.GL11.glNormalPointer;
|
||||
import static org.lwjgl.opengl.GL11.glTexCoordPointer;
|
||||
import static org.lwjgl.opengl.GL11.glVertexPointer;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class OpenGLMesh extends Mesh {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenGLMesh.class);
|
||||
|
||||
private static final int FLOAT_SIZE = 4;
|
||||
private AABBf aabb = new AABBf();
|
||||
|
||||
private MeshData data;
|
||||
|
||||
private int stride;
|
||||
private int vertexOffset;
|
||||
private int texCoord0Offset;
|
||||
private int texCoord1Offset;
|
||||
private int colorOffset;
|
||||
private int normalOffset;
|
||||
|
||||
private boolean hasTexCoord0;
|
||||
private boolean hasTexCoord1;
|
||||
private boolean hasColor;
|
||||
private boolean hasNormal;
|
||||
private int indexCount;
|
||||
|
||||
private DisposalAction disposalAction;
|
||||
|
||||
public OpenGLMesh(ResourceUrn urn, AssetType<?, MeshData> assetType, GLBufferPool bufferPool, MeshData data, LwjglGraphicsProcessing graphicsProcessing) {
|
||||
public OpenGLMesh(ResourceUrn urn, AssetType<?, MeshData> assetType, MeshData data, LwjglGraphicsProcessing graphicsProcessing) {
|
||||
super(urn, assetType);
|
||||
this.disposalAction = new DisposalAction(urn, bufferPool);
|
||||
this.disposalAction = new DisposalAction(urn);
|
||||
getDisposalHook().setDisposeAction(disposalAction);
|
||||
graphicsProcessing.asynchToDisplayThread(() -> {
|
||||
reload(data);
|
||||
});
|
||||
|
@ -93,188 +72,127 @@ public class OpenGLMesh extends Mesh {
|
|||
return data.getVertices();
|
||||
}
|
||||
|
||||
public void preRender() {
|
||||
if (!isDisposed()) {
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
if (hasTexCoord0 || hasTexCoord1) {
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
if (hasColor) {
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
if (hasNormal) {
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, disposalAction.vboVertexBuffer);
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, disposalAction.vboIndexBuffer);
|
||||
|
||||
glVertexPointer(VERTEX_SIZE, GL11.GL_FLOAT, stride, vertexOffset);
|
||||
|
||||
if (hasTexCoord0) {
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
|
||||
glTexCoordPointer(TEX_COORD_0_SIZE, GL11.GL_FLOAT, stride, texCoord0Offset);
|
||||
}
|
||||
|
||||
if (hasTexCoord1) {
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE1);
|
||||
glTexCoordPointer(TEX_COORD_1_SIZE, GL11.GL_FLOAT, stride, texCoord1Offset);
|
||||
}
|
||||
|
||||
if (hasColor) {
|
||||
glColorPointer(COLOR_SIZE, GL11.GL_FLOAT, stride, colorOffset);
|
||||
}
|
||||
if (hasNormal) {
|
||||
glNormalPointer(GL11.GL_FLOAT, stride, normalOffset);
|
||||
}
|
||||
} else {
|
||||
logger.error("Attempted to render disposed mesh: {}", getUrn());
|
||||
}
|
||||
}
|
||||
|
||||
public void postRender() {
|
||||
if (!isDisposed()) {
|
||||
if (hasNormal) {
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
if (hasColor) {
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
if (hasTexCoord0 || hasTexCoord1) {
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
} else {
|
||||
logger.error("Attempted to render disposed mesh: {}", getUrn());
|
||||
}
|
||||
}
|
||||
|
||||
public void doRender() {
|
||||
if (!isDisposed()) {
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
|
||||
} else {
|
||||
logger.error("Attempted to render disposed mesh: {}", getUrn());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
if (!isDisposed()) {
|
||||
preRender();
|
||||
doRender();
|
||||
postRender();
|
||||
GL30.glBindVertexArray(disposalAction.vao);
|
||||
GL30.glDrawElements(data.getMode().glCall, this.indexCount, GL_UNSIGNED_INT, 0);
|
||||
GL30.glBindVertexArray(0);
|
||||
} else {
|
||||
logger.error("Attempted to render disposed mesh: {}", getUrn());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void buildMesh(MeshData newData) {
|
||||
this.data = newData;
|
||||
|
||||
List<TFloatIterator> parts = Lists.newArrayList();
|
||||
TIntList partSizes = new TIntArrayList();
|
||||
int vertexCount = newData.getVertices().size() / VERTEX_SIZE;
|
||||
int vertexSize = VERTEX_SIZE;
|
||||
parts.add(newData.getVertices().iterator());
|
||||
partSizes.add(VERTEX_SIZE);
|
||||
this.disposalAction.dispose();
|
||||
this.disposalAction.vao = GL30.glGenVertexArrays();
|
||||
this.disposalAction.vbo = GL30.glGenBuffers();
|
||||
this.disposalAction.ebo = GL30.glGenBuffers();
|
||||
|
||||
if (newData.getTexCoord0() != null && newData.getTexCoord0().size() / TEX_COORD_0_SIZE == vertexCount) {
|
||||
parts.add(newData.getTexCoord0().iterator());
|
||||
partSizes.add(TEX_COORD_0_SIZE);
|
||||
texCoord0Offset = vertexSize * FLOAT_SIZE;
|
||||
vertexSize += TEX_COORD_0_SIZE;
|
||||
hasTexCoord0 = true;
|
||||
}
|
||||
if (newData.getTexCoord1() != null && newData.getTexCoord1().size() / TEX_COORD_1_SIZE == vertexCount) {
|
||||
parts.add(newData.getTexCoord1().iterator());
|
||||
partSizes.add(TEX_COORD_1_SIZE);
|
||||
texCoord1Offset = vertexSize * FLOAT_SIZE;
|
||||
vertexSize += TEX_COORD_1_SIZE;
|
||||
hasTexCoord1 = true;
|
||||
}
|
||||
if (newData.getNormals() != null && newData.getNormals().size() / NORMAL_SIZE == vertexCount) {
|
||||
parts.add(newData.getNormals().iterator());
|
||||
partSizes.add(NORMAL_SIZE);
|
||||
normalOffset = vertexSize * FLOAT_SIZE;
|
||||
vertexSize += NORMAL_SIZE;
|
||||
hasNormal = true;
|
||||
}
|
||||
if (newData.getColors() != null && newData.getColors().size() / COLOR_SIZE == vertexCount) {
|
||||
parts.add(newData.getColors().iterator());
|
||||
partSizes.add(COLOR_SIZE);
|
||||
colorOffset = vertexSize * FLOAT_SIZE;
|
||||
vertexSize += COLOR_SIZE;
|
||||
hasColor = true;
|
||||
}
|
||||
stride = vertexSize * FLOAT_SIZE;
|
||||
indexCount = newData.getIndices().size();
|
||||
List<Layout> layouts = newData.getLayouts();
|
||||
List<Layout> targets = new ArrayList<>();
|
||||
|
||||
createVertexBuffer(parts, partSizes, vertexCount, vertexSize);
|
||||
createIndexBuffer(newData.getIndices());
|
||||
getBound(newData, aabb);
|
||||
}
|
||||
|
||||
private void createVertexBuffer(List<TFloatIterator> parts, TIntList partSizes, int vertexCount, int vertexSize) {
|
||||
FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexSize * vertexCount);
|
||||
for (int v = 0; v < vertexCount; ++v) {
|
||||
for (int partIndex = 0; partIndex < parts.size(); ++partIndex) {
|
||||
TFloatIterator part = parts.get(partIndex);
|
||||
for (int i = 0; i < partSizes.get(partIndex); ++i) {
|
||||
vertexBuffer.put(part.next());
|
||||
}
|
||||
int stride = 0;
|
||||
for (Layout layout : layouts) {
|
||||
if (layout.hasContent()) {
|
||||
stride += layout.bytes();
|
||||
targets.add(layout);
|
||||
}
|
||||
}
|
||||
vertexBuffer.flip();
|
||||
if (disposalAction.vboVertexBuffer == 0) {
|
||||
disposalAction.vboVertexBuffer = disposalAction.bufferPool.get(getUrn().toString());
|
||||
}
|
||||
VertexBufferObjectUtil.bufferVboData(disposalAction.vboVertexBuffer, vertexBuffer, GL15.GL_STATIC_DRAW);
|
||||
vertexBuffer.flip();
|
||||
}
|
||||
|
||||
private void createIndexBuffer(TIntList indexList) {
|
||||
IntBuffer indexBuffer = BufferUtils.createIntBuffer(indexList.size());
|
||||
TIntIterator iterator = indexList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
indexBuffer.put(iterator.next());
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(stride * newData.getSize());
|
||||
for (int x = 0; x < newData.getSize(); x++) {
|
||||
for (Layout layout : targets) {
|
||||
layout.write(x, buffer);
|
||||
}
|
||||
}
|
||||
indexBuffer.flip();
|
||||
buffer.flip();
|
||||
|
||||
if (disposalAction.vboIndexBuffer == 0) {
|
||||
disposalAction.vboIndexBuffer = disposalAction.bufferPool.get(getUrn().toString());
|
||||
// bind vertex array and buffer
|
||||
GL30.glBindVertexArray(this.disposalAction.vao);
|
||||
GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.disposalAction.vbo);
|
||||
GL30.glBufferData(GL30.GL_ARRAY_BUFFER, buffer, GL30.GL_STATIC_DRAW);
|
||||
|
||||
int offset = 0;
|
||||
for (Layout layout : targets) {
|
||||
GL30.glEnableVertexAttribArray(layout.location);
|
||||
if ((layout.flag & Layout.FLOATING_POINT) > 0) {
|
||||
if (layout instanceof FloatLayout) {
|
||||
GL30.glVertexAttribPointer(layout.location, layout.size, GL30.GL_FLOAT, (layout.flag & Layout.NORMALIZED) > 0, stride, offset);
|
||||
} else if (layout instanceof ShortLayout) {
|
||||
GL30.glVertexAttribPointer(layout.location, layout.size, GL30.GL_SHORT, (layout.flag & Layout.NORMALIZED) > 0, stride, offset);
|
||||
} else if (layout instanceof IntLayout) {
|
||||
GL30.glVertexAttribPointer(layout.location, layout.size, GL30.GL_INT, (layout.flag & Layout.NORMALIZED) > 0, stride, offset);
|
||||
} else if (layout instanceof ByteLayout) {
|
||||
GL30.glVertexAttribPointer(layout.location, layout.size, GL30.GL_BYTE, (layout.flag & Layout.NORMALIZED) > 0, stride, offset);
|
||||
} else if (layout instanceof DoubleLayout) {
|
||||
GL41.glVertexAttribLPointer(layout.location, layout.size, GL30.GL_DOUBLE, stride, offset);
|
||||
} else {
|
||||
throw new RuntimeException("invalid layout for class: " + layout.getClass());
|
||||
}
|
||||
} else {
|
||||
if (layout instanceof ShortLayout) {
|
||||
GL30.glVertexAttribIPointer(layout.location, layout.size, GL30.GL_SHORT, stride, offset);
|
||||
} else if (layout instanceof IntLayout) {
|
||||
GL30.glVertexAttribIPointer(layout.location, layout.size, GL30.GL_INT, stride, offset);
|
||||
} else if (layout instanceof ByteLayout) {
|
||||
GL30.glVertexAttribIPointer(layout.location, layout.size, GL30.GL_BYTE, stride, offset);
|
||||
} else {
|
||||
throw new RuntimeException("invalid layout for class: " + layout.getClass());
|
||||
}
|
||||
}
|
||||
offset += layout.bytes();
|
||||
}
|
||||
VertexBufferObjectUtil.bufferVboElementData(disposalAction.vboIndexBuffer, indexBuffer, GL15.GL_STATIC_DRAW);
|
||||
indexBuffer.flip();
|
||||
|
||||
TIntList indices = newData.getIndices();
|
||||
IntBuffer bufferIndices = BufferUtils.createIntBuffer(indices.size());
|
||||
bufferIndices.put(indices.toArray());
|
||||
bufferIndices.flip();
|
||||
|
||||
GL30.glBindBuffer(GL30.GL_ELEMENT_ARRAY_BUFFER, this.disposalAction.ebo);
|
||||
GL30.glBufferData(GL30.GL_ELEMENT_ARRAY_BUFFER, bufferIndices, GL30.GL_STATIC_DRAW);
|
||||
indexCount = indices.size();
|
||||
|
||||
GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, 0);
|
||||
GL30.glBindVertexArray(0);
|
||||
getBound(newData, aabb);
|
||||
}
|
||||
|
||||
private static class DisposalAction implements Runnable {
|
||||
|
||||
private final ResourceUrn urn;
|
||||
private final GLBufferPool bufferPool;
|
||||
|
||||
private int vboVertexBuffer;
|
||||
private int vboIndexBuffer;
|
||||
private int vao = 0;
|
||||
private int vbo = 0;
|
||||
private int ebo = 0;
|
||||
|
||||
DisposalAction(ResourceUrn urn, GLBufferPool bufferPool) {
|
||||
DisposalAction(ResourceUrn urn) {
|
||||
this.urn = urn;
|
||||
this.bufferPool = bufferPool;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (vao != 0) {
|
||||
GL30.glDeleteVertexArrays(vao);
|
||||
}
|
||||
if (vbo != 0) {
|
||||
GL30.glDeleteBuffers(vbo);
|
||||
}
|
||||
if (ebo != 0) {
|
||||
GL30.glDeleteBuffers(ebo);
|
||||
}
|
||||
vao = 0;
|
||||
vbo = 0;
|
||||
ebo = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
GameThread.synch(() -> {
|
||||
if (vboVertexBuffer != 0) {
|
||||
bufferPool.dispose(vboVertexBuffer);
|
||||
vboVertexBuffer = 0;
|
||||
}
|
||||
if (vboIndexBuffer != 0) {
|
||||
bufferPool.dispose(vboIndexBuffer);
|
||||
vboIndexBuffer = 0;
|
||||
}
|
||||
dispose();
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Failed to dispose {}", urn, e);
|
||||
|
|
|
@ -6,46 +6,34 @@ import org.joml.Matrix4f;
|
|||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.assets.AssetType;
|
||||
import org.terasology.assets.ResourceUrn;
|
||||
import org.terasology.engine.core.GameThread;
|
||||
import org.terasology.engine.core.subsystem.lwjgl.GLBufferPool;
|
||||
import org.terasology.engine.core.subsystem.lwjgl.LwjglGraphicsProcessing;
|
||||
import org.terasology.joml.geom.AABBf;
|
||||
import org.terasology.engine.rendering.VertexBufferObjectUtil;
|
||||
import org.terasology.engine.rendering.assets.mesh.StandardMeshData;
|
||||
import org.terasology.engine.rendering.assets.skeletalmesh.Bone;
|
||||
import org.terasology.engine.rendering.assets.skeletalmesh.SkeletalMesh;
|
||||
import org.terasology.engine.rendering.assets.skeletalmesh.SkeletalMeshData;
|
||||
import org.terasology.joml.geom.AABBf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_FLOAT;
|
||||
import static org.lwjgl.opengl.GL11.GL_NORMAL_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_COORD_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT;
|
||||
import static org.lwjgl.opengl.GL11.GL_VERTEX_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.glDisableClientState;
|
||||
import static org.lwjgl.opengl.GL11.glEnableClientState;
|
||||
import static org.lwjgl.opengl.GL11.glNormalPointer;
|
||||
import static org.lwjgl.opengl.GL11.glTexCoordPointer;
|
||||
import static org.lwjgl.opengl.GL11.glVertexPointer;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class OpenGLSkeletalMesh extends SkeletalMesh {
|
||||
|
||||
private static final int TEX_COORD_SIZE = 2;
|
||||
private static final int VECTOR3_SIZE = 3;
|
||||
private static final int STRIDE = 24;
|
||||
private static final int NORMAL_OFFSET = VECTOR3_SIZE * 4;
|
||||
private static final int VERTEX_SIZE = 3 * Float.BYTES;
|
||||
private static final int NORMAL_SIZE = 3 * Float.BYTES;
|
||||
private static final int UV_SIZE = 2 * Float.BYTES;
|
||||
private static final int VERTEX_NORMAL_SIZE = (VERTEX_SIZE + NORMAL_SIZE);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenGLSkeletalMesh.class);
|
||||
|
||||
|
@ -56,10 +44,10 @@ public class OpenGLSkeletalMesh extends SkeletalMesh {
|
|||
|
||||
private DisposalAction disposalAction;
|
||||
|
||||
public OpenGLSkeletalMesh(ResourceUrn urn, AssetType<?, SkeletalMeshData> assetType, GLBufferPool bufferPool,
|
||||
public OpenGLSkeletalMesh(ResourceUrn urn, AssetType<?, SkeletalMeshData> assetType,
|
||||
SkeletalMeshData data, LwjglGraphicsProcessing graphicsProcessing) {
|
||||
super(urn, assetType);
|
||||
disposalAction = new DisposalAction(urn, bufferPool);
|
||||
disposalAction = new DisposalAction(urn);
|
||||
getDisposalHook().setDisposeAction(disposalAction);
|
||||
graphicsProcessing.asynchToDisplayThread(() -> {
|
||||
reload(data);
|
||||
|
@ -77,58 +65,54 @@ public class OpenGLSkeletalMesh extends SkeletalMesh {
|
|||
GameThread.synch(() -> {
|
||||
this.data = newData;
|
||||
|
||||
if (disposalAction.vboPosNormBuffer == 0) {
|
||||
disposalAction.vboPosNormBuffer = disposalAction.bufferPool.get(getUrn().toString());
|
||||
if (this.disposalAction.vao == 0) {
|
||||
this.disposalAction.vao = GL30.glGenVertexArrays();
|
||||
this.disposalAction.vbo = GL30.glGenBuffers();
|
||||
this.disposalAction.ebo = GL30.glGenBuffers();
|
||||
}
|
||||
// bind vertex array and buffer
|
||||
GL30.glBindVertexArray(this.disposalAction.vao);
|
||||
GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.disposalAction.vbo);
|
||||
|
||||
GL30.glEnableVertexAttribArray(StandardMeshData.VERTEX_INDEX);
|
||||
GL30.glVertexAttribPointer(StandardMeshData.VERTEX_INDEX, 3, GL30.GL_FLOAT, false, VERTEX_NORMAL_SIZE, 0);
|
||||
|
||||
GL30.glEnableVertexAttribArray(StandardMeshData.NORMAL_INDEX);
|
||||
GL30.glVertexAttribPointer(StandardMeshData.NORMAL_INDEX, 3, GL30.GL_FLOAT, false, VERTEX_NORMAL_SIZE, VERTEX_SIZE);
|
||||
|
||||
GL30.glEnableVertexAttribArray(StandardMeshData.UV0_INDEX);
|
||||
GL30.glVertexAttribPointer(StandardMeshData.UV0_INDEX, 2, GL30.GL_FLOAT, false, UV_SIZE, (long) VERTEX_NORMAL_SIZE * newData.getVertexCount());
|
||||
|
||||
int payloadSize = (UV_SIZE + VERTEX_SIZE + NORMAL_SIZE) * newData.getVertexCount();
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(payloadSize);
|
||||
|
||||
buffer.position(newData.getVertexCount() * VERTEX_NORMAL_SIZE);
|
||||
|
||||
for (Vector2f uv : newData.getUVs()) {
|
||||
buffer.putFloat(uv.x);
|
||||
buffer.putFloat(uv.y);
|
||||
}
|
||||
buffer.flip();
|
||||
GL30.glBufferData(GL30.GL_ARRAY_BUFFER, buffer, GL30.GL_DYNAMIC_DRAW);
|
||||
|
||||
IntBuffer indexBuffer = BufferUtils.createIntBuffer(newData.getIndices().size());
|
||||
indexBuffer.put(newData.getIndices().toArray());
|
||||
indexBuffer.flip();
|
||||
if (disposalAction.vboIndexBuffer == 0) {
|
||||
disposalAction.vboIndexBuffer = disposalAction.bufferPool.get(getUrn().toString());
|
||||
}
|
||||
VertexBufferObjectUtil.bufferVboElementData(disposalAction.vboIndexBuffer, indexBuffer, GL15.GL_STATIC_DRAW);
|
||||
GL30.glBindBuffer(GL30.GL_ELEMENT_ARRAY_BUFFER, this.disposalAction.ebo);
|
||||
GL30.glBufferData(GL30.GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL30.GL_STATIC_DRAW);
|
||||
|
||||
FloatBuffer uvBuffer = BufferUtils.createFloatBuffer(newData.getUVs().size() * 2);
|
||||
for (Vector2f uv : newData.getUVs()) {
|
||||
uvBuffer.put(uv.x);
|
||||
uvBuffer.put(uv.y);
|
||||
}
|
||||
uvBuffer.flip();
|
||||
|
||||
if (disposalAction.vboUVBuffer == 0) {
|
||||
disposalAction.vboUVBuffer = disposalAction.bufferPool.get(getUrn().toString());
|
||||
}
|
||||
VertexBufferObjectUtil.bufferVboData(disposalAction.vboUVBuffer, uvBuffer, GL15.GL_STATIC_DRAW);
|
||||
GL30.glBindVertexArray(0);
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Failed to reload {}", getUrn(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void preRender() {
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, disposalAction.vboUVBuffer);
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
|
||||
glTexCoordPointer(2, GL11.GL_FLOAT, TEX_COORD_SIZE * 4, 0);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, disposalAction.vboIndexBuffer);
|
||||
}
|
||||
|
||||
public void postRender() {
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
public void doRender(List<Vector3f> verts, List<Vector3f> normals) {
|
||||
FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(verts.size() * 6);
|
||||
GL30.glBindVertexArray(disposalAction.vao);
|
||||
|
||||
FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(verts.size() * VERTEX_NORMAL_SIZE);
|
||||
for (int i = 0; i < verts.size(); ++i) {
|
||||
Vector3f vert = verts.get(i);
|
||||
vertBuffer.put(vert.x * scale.x + translate.x);
|
||||
|
@ -140,27 +124,23 @@ public class OpenGLSkeletalMesh extends SkeletalMesh {
|
|||
vertBuffer.put(norm.z);
|
||||
}
|
||||
vertBuffer.flip();
|
||||
VertexBufferObjectUtil.bufferVboData(disposalAction.vboPosNormBuffer, vertBuffer, GL15.GL_DYNAMIC_DRAW);
|
||||
GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.disposalAction.vbo);
|
||||
GL30.glBufferSubData(GL30.GL_ARRAY_BUFFER, 0, vertBuffer);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, disposalAction.vboPosNormBuffer);
|
||||
glVertexPointer(VECTOR3_SIZE, GL_FLOAT, STRIDE, 0);
|
||||
glNormalPointer(GL_FLOAT, STRIDE, NORMAL_OFFSET);
|
||||
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, data.getIndices().size(), GL_UNSIGNED_INT, 0);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
GL30.glDrawElements(GL30.GL_TRIANGLES, data.getIndices().size(), GL_UNSIGNED_INT, 0);
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void render() {
|
||||
preRender();
|
||||
// preRender();
|
||||
doRender(data.getBindPoseVertexPositions(), data.getBindPoseVertexNormals());
|
||||
postRender();
|
||||
// postRender();
|
||||
}
|
||||
|
||||
public void render(List<Matrix4f> boneTransforms) {
|
||||
preRender();
|
||||
// preRender();
|
||||
doRender(data.getVertexPositions(boneTransforms), data.getVertexNormals(boneTransforms));
|
||||
postRender();
|
||||
// postRender();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -186,33 +166,35 @@ public class OpenGLSkeletalMesh extends SkeletalMesh {
|
|||
private static class DisposalAction implements Runnable {
|
||||
|
||||
private final ResourceUrn urn;
|
||||
private GLBufferPool bufferPool;
|
||||
|
||||
private int vboPosNormBuffer;
|
||||
private int vboUVBuffer;
|
||||
private int vboIndexBuffer;
|
||||
private int vao = 0;
|
||||
private int vbo = 0;
|
||||
private int ebo = 0;
|
||||
|
||||
DisposalAction(ResourceUrn urn, GLBufferPool bufferPool) {
|
||||
DisposalAction(ResourceUrn urn) {
|
||||
this.urn = urn;
|
||||
this.bufferPool = bufferPool;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (vao != 0) {
|
||||
GL30.glDeleteVertexArrays(vao);
|
||||
}
|
||||
if (vbo != 0) {
|
||||
GL30.glDeleteBuffers(vbo);
|
||||
}
|
||||
if (ebo != 0) {
|
||||
GL30.glDeleteBuffers(ebo);
|
||||
}
|
||||
vao = 0;
|
||||
vbo = 0;
|
||||
ebo = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
GameThread.synch(() -> {
|
||||
if (vboIndexBuffer != 0) {
|
||||
bufferPool.dispose(vboIndexBuffer);
|
||||
vboIndexBuffer = 0;
|
||||
}
|
||||
if (vboPosNormBuffer != 0) {
|
||||
bufferPool.dispose(vboPosNormBuffer);
|
||||
vboPosNormBuffer = 0;
|
||||
}
|
||||
if (vboUVBuffer != 0) {
|
||||
bufferPool.dispose(vboUVBuffer);
|
||||
vboUVBuffer = 0;
|
||||
}
|
||||
dispose();
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Failed to dispose {}", urn, e);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.joml.Vector3f;
|
|||
import org.joml.Vector3fc;
|
||||
import org.joml.Vector4f;
|
||||
import org.terasology.assets.ResourceUrn;
|
||||
import org.terasology.engine.rendering.assets.mesh.StandardMeshData;
|
||||
import org.terasology.module.sandbox.API;
|
||||
import org.terasology.engine.rendering.assets.mesh.Mesh;
|
||||
import org.terasology.engine.rendering.assets.mesh.MeshData;
|
||||
|
@ -18,7 +19,7 @@ import org.terasology.engine.world.block.shapes.BlockMeshPart;
|
|||
@API
|
||||
public class Tessellator {
|
||||
|
||||
private MeshData meshData = new MeshData();
|
||||
private StandardMeshData meshData = new StandardMeshData();
|
||||
|
||||
private int nextIndex;
|
||||
|
||||
|
@ -54,30 +55,29 @@ public class Tessellator {
|
|||
if (vertices.length != texCoords.length || vertices.length < 3) {
|
||||
throw new IllegalArgumentException("addPoly expected vertices.length == texCoords.length > 2");
|
||||
}
|
||||
|
||||
for (int i = 0; i < vertices.length; ++i) {
|
||||
meshData.getVertices().add(vertices[i].x);
|
||||
meshData.getVertices().add(vertices[i].y);
|
||||
meshData.getVertices().add(vertices[i].z);
|
||||
|
||||
meshData.getColors().add(activeColor.x);
|
||||
meshData.getColors().add(activeColor.y);
|
||||
meshData.getColors().add(activeColor.z);
|
||||
meshData.getColors().add(activeColor.w);
|
||||
meshData.color0.add(activeColor.x);
|
||||
meshData.color0.add(activeColor.y);
|
||||
meshData.color0.add(activeColor.z);
|
||||
meshData.color0.add(activeColor.w);
|
||||
|
||||
if (useNormals) {
|
||||
meshData.getNormals().add(activeNormal.x);
|
||||
meshData.getNormals().add(activeNormal.y);
|
||||
meshData.getNormals().add(activeNormal.z);
|
||||
meshData.normals.add(activeNormal.x);
|
||||
meshData.normals.add(activeNormal.y);
|
||||
meshData.normals.add(activeNormal.z);
|
||||
}
|
||||
|
||||
meshData.getTexCoord0().add(texCoords[i].x);
|
||||
meshData.getTexCoord0().add(texCoords[i].y);
|
||||
meshData.uv0.add(texCoords[i].x);
|
||||
meshData.uv0.add(texCoords[i].y);
|
||||
|
||||
if (useLighting) {
|
||||
meshData.getTexCoord1().add(lighting.x);
|
||||
meshData.getTexCoord1().add(lighting.y);
|
||||
meshData.getTexCoord1().add(lighting.z);
|
||||
meshData.uv1.add(lighting.x);
|
||||
meshData.uv1.add(lighting.y);
|
||||
meshData.uv1.add(lighting.z);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,23 +105,23 @@ public class Tessellator {
|
|||
meshData.getVertices().add(vertex.y());
|
||||
meshData.getVertices().add(vertex.z());
|
||||
|
||||
meshData.getColors().add(activeColor.x);
|
||||
meshData.getColors().add(activeColor.y);
|
||||
meshData.getColors().add(activeColor.z);
|
||||
meshData.getColors().add(activeColor.w);
|
||||
meshData.color0.add(activeColor.x);
|
||||
meshData.color0.add(activeColor.y);
|
||||
meshData.color0.add(activeColor.z);
|
||||
meshData.color0.add(activeColor.w);
|
||||
|
||||
Vector3fc normal = part.getNormal(i);
|
||||
meshData.getNormals().add(normal.x());
|
||||
meshData.getNormals().add(normal.y());
|
||||
meshData.getNormals().add(normal.z());
|
||||
meshData.normals.add(normal.x());
|
||||
meshData.normals.add(normal.y());
|
||||
meshData.normals.add(normal.z());
|
||||
|
||||
Vector2fc uv = part.getTexCoord(i);
|
||||
meshData.getTexCoord0().add(uv.x());
|
||||
meshData.getTexCoord0().add(uv.y());
|
||||
meshData.uv0.add(uv.x());
|
||||
meshData.uv0.add(uv.y());
|
||||
|
||||
meshData.getTexCoord1().add(lighting.x);
|
||||
meshData.getTexCoord1().add(lighting.y);
|
||||
meshData.getTexCoord1().add(lighting.z);
|
||||
meshData.light0.add(lighting.x);
|
||||
meshData.light0.add(lighting.y);
|
||||
meshData.light0.add(lighting.z);
|
||||
}
|
||||
|
||||
for (int i = 0; i < part.indicesSize(); ++i) {
|
||||
|
@ -159,20 +159,20 @@ public class Tessellator {
|
|||
|
||||
public MeshData generateMeshData() {
|
||||
MeshData result = meshData;
|
||||
meshData = new MeshData();
|
||||
meshData = new StandardMeshData();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Mesh generateMesh(ResourceUrn urn) {
|
||||
Preconditions.checkNotNull(urn);
|
||||
Mesh result = Assets.generateAsset(urn, meshData, Mesh.class);
|
||||
meshData = new MeshData();
|
||||
meshData = new StandardMeshData();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Mesh generateMesh() {
|
||||
Mesh result = Assets.generateAsset(meshData, Mesh.class);
|
||||
meshData = new MeshData();
|
||||
meshData = new StandardMeshData();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
package org.terasology.engine.rendering.world.selection;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector3ic;
|
||||
import org.joml.Vector4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
@ -11,6 +13,7 @@ import org.terasology.engine.rendering.assets.material.Material;
|
|||
import org.terasology.engine.rendering.assets.shader.ShaderProgramFeature;
|
||||
import org.terasology.engine.rendering.assets.texture.Texture;
|
||||
import org.terasology.engine.rendering.assets.texture.TextureRegionAsset;
|
||||
import org.terasology.engine.rendering.cameras.Camera;
|
||||
import org.terasology.engine.rendering.primitives.Tessellator;
|
||||
import org.terasology.engine.rendering.primitives.TessellatorHelper;
|
||||
import org.terasology.joml.geom.Rectanglef;
|
||||
|
@ -45,9 +48,12 @@ public class BlockSelectionRenderer {
|
|||
private Texture effectsTexture;
|
||||
private Material defaultTextured;
|
||||
private Rectanglef textureRegion = new Rectanglef(0, 0, 1, 1);
|
||||
private WorldRenderer worldRenderer;
|
||||
|
||||
public BlockSelectionRenderer(Texture effectsTexture) {
|
||||
this.effectsTexture = effectsTexture;
|
||||
this.worldRenderer = CoreRegistry.get(WorldRenderer.class);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
@ -55,7 +61,7 @@ public class BlockSelectionRenderer {
|
|||
Vector2f min = new Vector2f(textureRegion.minX(), textureRegion.minY());
|
||||
Tessellator tessellator = new Tessellator();
|
||||
TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1, 1, 1, 1f),
|
||||
min , textureRegion.getSize(new Vector2f()),
|
||||
min, textureRegion.getSize(new Vector2f()),
|
||||
1.001f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
|
||||
overlayMesh = tessellator.generateMesh();
|
||||
tessellator = new Tessellator();
|
||||
|
@ -63,7 +69,7 @@ public class BlockSelectionRenderer {
|
|||
min, textureRegion.getSize(new Vector2f()), 1.001f, 1.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f);
|
||||
overlayMesh2 = tessellator.generateMesh();
|
||||
defaultTextured = Assets.getMaterial("engine:prog.defaultTextured").get();
|
||||
defaultTextured = Assets.getMaterial("engine:prog.blockSelection").get();
|
||||
}
|
||||
|
||||
public void setEffectsTexture(TextureRegionAsset textureRegionAsset) {
|
||||
|
@ -78,7 +84,8 @@ public class BlockSelectionRenderer {
|
|||
this.effectsTexture = newEffectsTexture;
|
||||
} else {
|
||||
// This should not be possible with the current BlockSelectionRenderSystem implementation
|
||||
throw new RuntimeException("New effectsTexture must have same height and width as the original effectsTexture");
|
||||
throw new RuntimeException("New effectsTexture must have same height and width as the original " +
|
||||
"effectsTexture");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,11 +93,12 @@ public class BlockSelectionRenderer {
|
|||
if (effectsTexture == null || !effectsTexture.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
defaultTextured.activateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
|
||||
Camera camera = worldRenderer.getActiveCamera();
|
||||
defaultTextured.enable();
|
||||
|
||||
glBindTexture(GL11.GL_TEXTURE_2D, effectsTexture.getId());
|
||||
defaultTextured.activateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
|
||||
defaultTextured.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
|
||||
defaultTextured.setTexture("texture", effectsTexture);
|
||||
defaultTextured.bindTextures();
|
||||
|
||||
glEnable(GL11.GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
@ -98,38 +106,36 @@ public class BlockSelectionRenderer {
|
|||
|
||||
public void endRenderOverlay() {
|
||||
glDisable(GL11.GL_BLEND);
|
||||
|
||||
defaultTextured.deactivateFeature(ShaderProgramFeature.FEATURE_ALPHA_REJECT);
|
||||
}
|
||||
|
||||
public void renderMark(Vector3ic blockPos) {
|
||||
Vector3f cameraPos = getCameraPosition();
|
||||
Camera camera = worldRenderer.getActiveCamera();
|
||||
final Vector3f cameraPosition = camera.getPosition();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslated(blockPos.x() - cameraPos.x, blockPos.y() - cameraPos.y, blockPos.z() - cameraPos.z);
|
||||
Matrix4f modelView = new Matrix4f();
|
||||
modelView.set(camera.getViewMatrix()).mul(new Matrix4f().setTranslation(
|
||||
blockPos.x() - cameraPosition.x, blockPos.y() - cameraPosition.y,
|
||||
blockPos.z() - cameraPosition.z
|
||||
));
|
||||
defaultTextured.setMatrix4("modelViewMatrix", modelView);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
overlayMesh.render();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
public void renderMark2(Vector3ic blockPos) {
|
||||
Vector3f cameraPos = getCameraPosition();
|
||||
Camera camera = worldRenderer.getActiveCamera();
|
||||
final Vector3f cameraPosition = camera.getPosition();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslated(blockPos.x() - cameraPos.x, blockPos.y() - cameraPos.y, blockPos.z() - cameraPos.z);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
Matrix4f modelView = new Matrix4f();
|
||||
modelView.set(camera.getViewMatrix()).mul(new Matrix4f().setTranslation(
|
||||
blockPos.x() - cameraPosition.x, blockPos.y() - cameraPosition.y,
|
||||
blockPos.z() - cameraPosition.z
|
||||
));
|
||||
defaultTextured.setMatrix4("modelViewMatrix", modelView);
|
||||
|
||||
overlayMesh2.render();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
private Vector3f getCameraPosition() {
|
||||
return CoreRegistry.get(WorldRenderer.class).getActiveCamera().getPosition();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -587,26 +587,6 @@ public final class Block {
|
|||
return getBounds(new Vector3i(floatPos, RoundingMode.HALF_UP));
|
||||
}
|
||||
|
||||
public void renderWithLightValue(float sunlight, float blockLight) {
|
||||
if (meshGenerator == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material mat = Assets.getMaterial("engine:prog.block").orElseThrow(() -> new RuntimeException("Missing engine material"));
|
||||
mat.activateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK);
|
||||
|
||||
mat.enable();
|
||||
mat.setFloat("sunlight", sunlight);
|
||||
mat.setFloat("blockLight", blockLight);
|
||||
|
||||
|
||||
Mesh mesh = meshGenerator.getStandaloneMesh();
|
||||
if (mesh != null) {
|
||||
mesh.render();
|
||||
}
|
||||
|
||||
mat.deactivateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"params": [
|
||||
{
|
||||
"name": "texture",
|
||||
"type": "sampler2D"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
in vec2 v_uv0;
|
||||
in vec4 v_color0;
|
||||
|
||||
void main(){
|
||||
vec4 diffColor = texture2D(texture, v_uv0);
|
||||
|
||||
#if defined (FEATURE_ALPHA_REJECT)
|
||||
if (diffColor.a < 0.1) {
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragData[0].rgba = diffColor * v_color0;
|
||||
gl_FragData[1].rgba = vec4(0.5, 1.0, 0.5, 1.0);
|
||||
gl_FragData[2].rgba = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
layout (location = 0) in vec3 in_vert;
|
||||
layout (location = 2) in vec2 in_uv0;
|
||||
layout (location = 4) in vec4 in_color0;
|
||||
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
out vec2 v_uv0;
|
||||
out vec4 v_color0;
|
||||
|
||||
void main() {
|
||||
gl_Position = (projectionMatrix * modelViewMatrix) * vec4(in_vert, 1.0);
|
||||
v_uv0 = in_uv0;
|
||||
v_color0 = in_color0;
|
||||
}
|
|
@ -1,18 +1,6 @@
|
|||
/*
|
||||
* Copyright 2012 Benjamin Glatzel <benjamin.glatzel@me.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
uniform sampler2D textureAtlas;
|
||||
|
||||
|
@ -25,17 +13,17 @@ uniform float sunlight = 1.0;
|
|||
|
||||
uniform float alpha = 1.0;
|
||||
|
||||
varying vec3 normal;
|
||||
in vec3 v_normal;
|
||||
in vec2 v_uv0;
|
||||
in vec4 v_color0;
|
||||
|
||||
void main(){
|
||||
void main() {
|
||||
vec4 color;
|
||||
|
||||
if (textured) {
|
||||
color = gl_Color * texture2D(textureAtlas, gl_TexCoord[0].xy);
|
||||
color = v_color0 * texture2D(textureAtlas, v_uv0);
|
||||
} else {
|
||||
color = gl_Color;
|
||||
color = v_color0;
|
||||
}
|
||||
|
||||
color.a *= alpha;
|
||||
|
||||
if (color.a < 0.1) {
|
||||
|
@ -45,6 +33,6 @@ void main(){
|
|||
color.rgb *= colorOffset.rgb;
|
||||
|
||||
gl_FragData[0].rgba = color;
|
||||
gl_FragData[1].rgba = vec4(normal.x / 2.0 + 0.5, normal.y / 2.0 + 0.5, normal.z / 2.0 + 0.5, 0.0);
|
||||
gl_FragData[1].rgba = vec4(v_normal.x / 2.0 + 0.5, v_normal.y / 2.0 + 0.5, v_normal.z / 2.0 + 0.5, 0.0);
|
||||
gl_FragData[2].rgba = vec4(blockLight, sunlight, 0.0, 0.0);
|
||||
}
|
||||
|
|
|
@ -1,37 +1,23 @@
|
|||
/*
|
||||
* Copyright 2012 Benjamin Glatzel <benjamin.glatzel@me.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
varying vec3 normal;
|
||||
layout (location = 0) in vec3 in_vert;
|
||||
layout (location = 1) in vec3 in_normal;
|
||||
layout (location = 2) in vec2 in_uv0;
|
||||
layout (location = 4) in vec4 in_color0;
|
||||
|
||||
#if !defined (FEATURE_USE_MATRIX_STACK)
|
||||
uniform mat3 normalMatrix;
|
||||
uniform mat4 worldViewMatrix;
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if !defined (FEATURE_USE_MATRIX_STACK)
|
||||
normal = normalMatrix * gl_Normal;
|
||||
gl_Position = (projectionMatrix * worldViewMatrix) * gl_Vertex;
|
||||
#else
|
||||
normal = gl_NormalMatrix * gl_Normal;
|
||||
gl_Position = ftransform();
|
||||
#endif
|
||||
out vec3 v_normal;
|
||||
out vec2 v_uv0;
|
||||
out vec4 v_color0;
|
||||
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
void main() {
|
||||
v_normal = normalMatrix * in_normal;
|
||||
v_uv0 = in_uv0;
|
||||
v_color0 = in_color0;
|
||||
gl_Position = (projectionMatrix * modelViewMatrix) * vec4(in_vert,1.0);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,6 @@
|
|||
/*
|
||||
* Copyright 2012 Benjamin Glatzel <benjamin.glatzel@me.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
uniform sampler2D diffuse;
|
||||
|
||||
|
@ -25,20 +13,23 @@ uniform float sunlight = 1.0;
|
|||
uniform vec3 colorOffset;
|
||||
uniform bool textured;
|
||||
|
||||
varying vec3 normal;
|
||||
in vec3 v_normal;
|
||||
in vec2 v_uv0;
|
||||
in vec4 v_color0;
|
||||
|
||||
|
||||
void main(){
|
||||
vec4 color;
|
||||
|
||||
if (textured) {
|
||||
color = texture2D(diffuse, vec2(gl_TexCoord[0].x , gl_TexCoord[0].y));
|
||||
color = texture2D(diffuse, v_uv0);
|
||||
color.rgb *= colorOffset.rgb;
|
||||
gl_FragData[0].rgba = color;
|
||||
} else {
|
||||
color = vec4(colorOffset.r, colorOffset.g, colorOffset.b, 1.0);
|
||||
color = vec4(colorOffset.rgb, 1.0);
|
||||
gl_FragData[0].rgba = color;
|
||||
}
|
||||
|
||||
gl_FragData[1].rgba = vec4(normal.x / 2.0 + 0.5, normal.y / 2.0 + 0.5, normal.z / 2.0 + 0.5, 0.0);
|
||||
gl_FragData[1].rgba = vec4(v_normal.x / 2.0 + 0.5, v_normal.y / 2.0 + 0.5, v_normal.z / 2.0 + 0.5, 0.0);
|
||||
gl_FragData[2].rgba = vec4(blockLight, sunlight, 0.0, 0.0);
|
||||
}
|
||||
|
|
|
@ -1,36 +1,25 @@
|
|||
/*
|
||||
* Copyright 2012 Benjamin Glatzel <benjamin.glatzel@me.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
varying vec3 normal;
|
||||
layout (location = 0) in vec3 in_vert;
|
||||
layout (location = 1) in vec3 in_normal;
|
||||
layout (location = 2) in vec2 in_uv0;
|
||||
layout (location = 4) in vec4 in_color0;
|
||||
|
||||
uniform mat3 normalMatrix;
|
||||
uniform mat4 worldViewMatrix;
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if !defined (FEATURE_USE_MATRIX_STACK)
|
||||
normal = normalMatrix * gl_Normal;
|
||||
gl_Position = (projectionMatrix * worldViewMatrix) * gl_Vertex;
|
||||
#else
|
||||
normal = gl_NormalMatrix * gl_Normal;
|
||||
gl_Position = ftransform();
|
||||
#endif
|
||||
out vec3 v_normal;
|
||||
out vec2 v_uv0;
|
||||
out vec4 v_color0;
|
||||
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
void main() {
|
||||
gl_Position = (projectionMatrix * modelViewMatrix) * vec4(in_vert, 1.0);
|
||||
|
||||
v_normal = normalMatrix * in_normal;
|
||||
v_uv0 = in_uv0;
|
||||
v_color0 = in_color0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/*
|
||||
* Copyright 2020 MovingBlocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
in vec4 color_gs;
|
||||
in vec2 uv;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#version 330 core
|
||||
/*
|
||||
* Copyright 2013 Moving Blocks
|
||||
*
|
||||
|
@ -17,13 +18,14 @@
|
|||
uniform vec4 croppingBoundaries;
|
||||
uniform sampler2D texture;
|
||||
|
||||
varying vec2 relPos;
|
||||
in vec2 v_relPos;
|
||||
in vec2 v_uv0;
|
||||
in vec4 v_color0;
|
||||
|
||||
void main(){
|
||||
if (relPos.x < croppingBoundaries.x || relPos.x > croppingBoundaries.y || relPos.y < croppingBoundaries.z || relPos.y > croppingBoundaries.w) {
|
||||
if (v_relPos.x < croppingBoundaries.x || v_relPos.x > croppingBoundaries.y || v_relPos.y < croppingBoundaries.z || v_relPos.y > croppingBoundaries.w) {
|
||||
discard;
|
||||
}
|
||||
vec4 diffColor = texture2D(texture, gl_TexCoord[0].xy);
|
||||
|
||||
gl_FragData[0].rgba = diffColor * gl_Color;
|
||||
vec4 diffColor = texture2D(texture, v_uv0);
|
||||
gl_FragData[0].rgba = diffColor * v_color0;
|
||||
}
|
||||
|
|
|
@ -1,30 +1,28 @@
|
|||
/*
|
||||
* Copyright 2013 Moving Blocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
layout (location = 0) in vec3 in_vert;
|
||||
layout (location = 1) in vec3 in_normal;
|
||||
layout (location = 2) in vec2 in_uv0;
|
||||
layout (location = 4) in vec4 in_color0;
|
||||
|
||||
uniform float alpha;
|
||||
uniform vec2 offset;
|
||||
|
||||
varying vec2 relPos;
|
||||
out vec2 v_relPos;
|
||||
out vec2 v_uv0;
|
||||
out vec4 v_color0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pos = gl_Vertex;
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
void main() {
|
||||
vec4 pos = vec4(in_vert, 1.0);
|
||||
pos.xy += offset;
|
||||
relPos = pos.xy;
|
||||
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * pos;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_FrontColor = vec4(gl_Color.rgb, gl_Color.a * alpha);
|
||||
v_relPos = pos.xy;
|
||||
v_uv0 = in_uv0;
|
||||
v_color0 = vec4(in_color0.rgb, in_color0.a * alpha);
|
||||
|
||||
gl_Position = (projectionMatrix * modelViewMatrix) * pos;
|
||||
}
|
||||
|
|
|
@ -1,35 +1,22 @@
|
|||
/*
|
||||
* Copyright 2013 Moving Blocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
uniform vec4 croppingBoundaries;
|
||||
uniform sampler2D texture;
|
||||
varying vec3 normal;
|
||||
varying vec2 relPos;
|
||||
|
||||
in vec3 v_normal;
|
||||
in vec2 v_relPos;
|
||||
in vec2 v_uv0;
|
||||
in vec4 v_color0;
|
||||
|
||||
void main(){
|
||||
if (relPos.x < croppingBoundaries.x || relPos.x > croppingBoundaries.y || relPos.y < croppingBoundaries.z || relPos.y > croppingBoundaries.w) {
|
||||
if (v_relPos.x < croppingBoundaries.x || v_relPos.x > croppingBoundaries.y || v_relPos.y < croppingBoundaries.z || v_relPos.y > croppingBoundaries.w) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 color = texture2D(texture, vec2(gl_TexCoord[0].x , gl_TexCoord[0].y));
|
||||
|
||||
float light = min(1.0,
|
||||
0.3 * max(0.0, dot(normal, vec3(0, -1, 0))) + 1.0 * max(0.0, dot(normal, vec3(0,0,1))));
|
||||
|
||||
vec4 color = texture2D(texture, v_uv0);
|
||||
float light = min(1.0, 0.3 * max(0.0, dot(v_normal, vec3(0, -1, 0))) + 1.0 * max(0.0, dot(v_normal, vec3(0,0,1))));
|
||||
color.rgb = color.rgb * light;
|
||||
|
||||
gl_FragData[0].rgba = color * gl_Color;
|
||||
gl_FragData[0].rgba = color * v_color0;
|
||||
}
|
||||
|
|
|
@ -1,33 +1,28 @@
|
|||
/*
|
||||
* Copyright 2013 Moving Blocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
layout (location = 0) in vec3 in_vert;
|
||||
layout (location = 1) in vec3 in_normal;
|
||||
layout (location = 2) in vec2 in_uv0;
|
||||
layout (location = 4) in vec4 in_color0;
|
||||
|
||||
uniform float alpha;
|
||||
out vec3 v_normal;
|
||||
out vec2 v_relPos;
|
||||
out vec2 v_uv0;
|
||||
out vec4 v_color0;
|
||||
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
uniform mat4 posMatrix;
|
||||
|
||||
varying vec3 normal;
|
||||
varying vec2 relPos;
|
||||
uniform float alpha;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 pos = (posMatrix * gl_Vertex).xyz;
|
||||
relPos = pos.xy;
|
||||
|
||||
normal = normalize(gl_NormalMatrix * gl_Normal);
|
||||
gl_Position = ftransform();
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_FrontColor = vec4(gl_Color.rgb, gl_Color.a * alpha);
|
||||
void main() {
|
||||
v_relPos = (posMatrix * vec4(in_vert,1.0)).xy;
|
||||
gl_Position = (projectionMatrix * modelViewMatrix) * vec4(in_vert, 1.0);
|
||||
v_normal = normalize(normalMatrix * in_normal);
|
||||
v_uv0 = in_uv0;
|
||||
v_color0 = vec4(in_color0.rgb, in_color0.a * alpha);
|
||||
}
|
||||
|
|
|
@ -1,29 +1,20 @@
|
|||
/*
|
||||
* Copyright 2013 Moving Blocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
uniform vec4 croppingBoundaries;
|
||||
uniform sampler2D texture;
|
||||
|
||||
varying vec2 relPos;
|
||||
|
||||
in vec2 v_relPos;
|
||||
in vec2 v_uv0;
|
||||
in vec4 v_color0;
|
||||
|
||||
void main(){
|
||||
if (relPos.x < croppingBoundaries.x || relPos.x > croppingBoundaries.y || relPos.y < croppingBoundaries.z || relPos.y > croppingBoundaries.w) {
|
||||
if (v_relPos.x < croppingBoundaries.x || v_relPos.x > croppingBoundaries.y || v_relPos.y < croppingBoundaries.z || v_relPos.y > croppingBoundaries.w) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 diffColor = texture2D(texture, gl_TexCoord[0].xy);
|
||||
gl_FragData[0].rgba = diffColor * gl_Color;
|
||||
vec4 diffColor = texture2D(texture, v_uv0);
|
||||
gl_FragData[0].rgba = diffColor * v_color0;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
/*
|
||||
* Copyright 2013 Moving Blocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#version 330 core
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
layout (location = 0) in vec3 in_vert;
|
||||
layout (location = 1) in vec3 in_normal;
|
||||
layout (location = 2) in vec2 in_uv0;
|
||||
layout (location = 4) in vec4 in_color0;
|
||||
|
||||
uniform vec2 offset;
|
||||
uniform vec4 color;
|
||||
|
@ -21,16 +14,20 @@ uniform vec2 texOffset;
|
|||
uniform vec2 texSize;
|
||||
uniform vec4 croppingBoundaries;
|
||||
|
||||
varying vec2 relPos;
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
out vec2 v_relPos;
|
||||
out vec2 v_uv0;
|
||||
out vec4 v_color0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pos = gl_Vertex;
|
||||
vec3 pos = in_vert;
|
||||
pos.xy *= scale;
|
||||
pos.xy += offset;
|
||||
relPos = pos.xy;
|
||||
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * pos;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_TexCoord[0].xy = texOffset + gl_TexCoord[0].xy * (texSize) ;
|
||||
gl_FrontColor = color;
|
||||
v_relPos = pos.xy;
|
||||
gl_Position = (projectionMatrix * modelViewMatrix) * vec4(pos,1.0);
|
||||
v_uv0 = texOffset + in_uv0 * (texSize);
|
||||
v_color0 = color;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue