Search in sources :

Example 16 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class HybridDemoSsboInstancing method createSceneSSBO.

/**
 * Create a Shader Storage Buffer Object which will hold our boxes to be
 * read by our Compute Shader.
 */
private void createSceneSSBO() {
    this.ssbo = glGenBuffers();
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
    ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4 + 4) * boxes.length / 2);
    FloatBuffer fv = ssboData.asFloatBuffer();
    for (int i = 0; i < boxes.length; i += 2) {
        Vector3f min = boxes[i];
        Vector3f max = boxes[i + 1];
        /*
			 * NOTE: We need to write vec4 here, because SSBOs have specific
			 * alignment requirements for struct members (vec3 is always treated
			 * as vec4 in memory!)
			 * 
			 * See:
			 * "https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html"
			 */
        fv.put(min.x).put(min.y).put(min.z).put(0.0f);
        fv.put(max.x).put(max.y).put(max.z).put(0.0f);
    }
    glBufferData(GL_SHADER_STORAGE_BUFFER, ssboData, GL_STATIC_DRAW);
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 17 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class HybridDemoSsboInstancing45 method createSceneSSBO.

/**
 * Create a Shader Storage Buffer Object which will hold our boxes to be
 * read by our Compute Shader.
 */
private void createSceneSSBO() {
    this.ssbo = glCreateBuffers();
    ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4 + 4 + 4) * boxes.length / 2);
    FloatBuffer fv = ssboData.asFloatBuffer();
    for (int i = 0; i < boxes.length; i += 2) {
        Vector3f min = boxes[i];
        Vector3f max = boxes[i + 1];
        /*
			 * NOTE: We need to write vec4 here, because SSBOs have specific
			 * alignment requirements for struct members (vec3 is always treated
			 * as vec4 in memory!)
			 * 
			 * See:
			 * "https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html"
			 */
        fv.put(min.x).put(min.y).put(min.z).put(0.0f);
        fv.put(max.x).put(max.y).put(max.z).put(0.0f);
    }
    glNamedBufferData(this.ssbo, ssboData, GL_STATIC_DRAW);
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 18 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class PhotonMappingBindlessDemo method createPhotonMapTextures.

/**
 * Create the cubemap texture array for our photon map.
 */
private void createPhotonMapTextures() {
    /* Create them */
    IntBuffer textures = BufferUtils.createIntBuffer(photonMapTextures.length);
    glGenTextures(textures);
    for (int i = 0; i < photonMapTextures.length; i++) {
        TextureInfo info = new TextureInfo();
        info.openGlHandle = textures.get(i);
        Vector3f min = boxes[2 * i + 0];
        Vector3f max = boxes[2 * i + 1];
        float maxExtent = Math.max(Math.max(max.x - min.x, max.y - min.y), max.z - min.z);
        int texSize = (int) (maxExtent * texelsPerUnit);
        info.textureWidth = texSize;
        info.textureHeight = texSize;
        glBindTexture(GL_TEXTURE_CUBE_MAP, info.openGlHandle);
        glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RG16F, texSize, texSize);
        glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
        info.bindlessImageHandle = ARBBindlessTexture.glGetImageHandleARB(info.openGlHandle, 0, true, 0, GL_RG16F);
        info.bindlessTextureAndSamplerHandle = ARBBindlessTexture.glGetTextureSamplerHandleARB(info.openGlHandle, sampler);
        ARBBindlessTexture.glMakeImageHandleResidentARB(info.bindlessImageHandle, GL_READ_WRITE);
        ARBBindlessTexture.glMakeTextureHandleResidentARB(info.bindlessTextureAndSamplerHandle);
        photonMapTextures[i] = info;
    }
    /* Clear them */
    clearPhotonMapTextures();
    /* Update SSBO with bindless image handles */
    updateImageHandlesUbo();
    /* Update UBO with bindless sampler handles */
    updateSamplerHandlesUbo();
}
Also used : IntBuffer(java.nio.IntBuffer) Vector3f(org.joml.Vector3f)

Example 19 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class PhotonMappingBindlessDemo method createSceneVao.

/**
 * Creates a VAO for the scene.
 */
private void createSceneVao() {
    int vao = glGenVertexArrays();
    /* Create vertex data */
    int vbo = glGenBuffers();
    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    ByteBuffer bb = BufferUtils.createByteBuffer(4 * (3 + 3) * 6 * 6);
    FloatBuffer fv = bb.asFloatBuffer();
    DemoUtils.triangulateUnitBox(fv);
    glBufferData(GL_ARRAY_BUFFER, bb, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, false, 4 * (3 + 3), 0L);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 3, GL_FLOAT, false, 4 * (3 + 3), 4 * 3);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    /* Create per instance data (position and size of box) */
    int ivbo = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, ivbo);
    bb = BufferUtils.createByteBuffer(4 * (3 + 3) * boxes.length);
    fv = bb.asFloatBuffer();
    for (int i = 0; i < boxes.length; i += 2) {
        Vector3f min = boxes[i];
        Vector3f max = boxes[i + 1];
        fv.put((max.x + min.x) / 2.0f).put((max.y + min.y) / 2.0f).put((max.z + min.z) / 2.0f);
        fv.put((max.x - min.x) / 2.0f).put((max.y - min.y) / 2.0f).put((max.z - min.z) / 2.0f);
    }
    glBufferData(GL_ARRAY_BUFFER, bb, GL_STATIC_DRAW);
    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 3, GL_FLOAT, false, 4 * (3 + 3), 0L);
    glVertexAttribDivisor(2, 1);
    glEnableVertexAttribArray(3);
    glVertexAttribPointer(3, 3, GL_FLOAT, false, 4 * (3 + 3), 4 * 3);
    glVertexAttribDivisor(3, 1);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
    this.vaoScene = vao;
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 20 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class PhotonMappingBindlessDemo method createSceneSSBO.

/**
 * Create a Shader Storage Buffer Object which will hold our boxes to be
 * read by our Compute Shader.
 */
private void createSceneSSBO() {
    this.ssbo = glGenBuffers();
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
    ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4 + 4) * boxes.length / 2);
    FloatBuffer fv = ssboData.asFloatBuffer();
    for (int i = 0; i < boxes.length; i += 2) {
        Vector3f min = boxes[i];
        Vector3f max = boxes[i + 1];
        /*
			 * NOTE: We need to write vec4 here, because SSBOs have specific
			 * alignment requirements for struct members (vec3 is always treated
			 * as vec4 in memory!)
			 * 
			 * See:
			 * "https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html"
			 */
        fv.put(min.x).put(min.y).put(min.z).put(0.0f);
        fv.put(max.x).put(max.y).put(max.z).put(0.0f);
    }
    glBufferData(GL_SHADER_STORAGE_BUFFER, ssboData, GL_STATIC_DRAW);
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8