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);
}
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);
}
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();
}
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;
}
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);
}
Aggregations