less static imports
parent
6765a3a33a
commit
d0402d069b
|
@ -266,7 +266,7 @@ public class VulkanStarter
|
|||
return new VkCommandBuffer(commandBuffer, device);
|
||||
}
|
||||
|
||||
private static class Swapchain
|
||||
public static class Swapchain
|
||||
{
|
||||
long swapchainHandle;
|
||||
long[] images;
|
||||
|
|
|
@ -4,8 +4,6 @@ import static org.lwjgl.system.MemoryUtil.*;
|
|||
import static org.lwjgl.util.shaderc.Shaderc.*;
|
||||
import static org.lwjgl.vulkan.EXTDebugReport.*;
|
||||
import static org.lwjgl.vulkan.KHRSurface.*;
|
||||
import static org.lwjgl.vulkan.NVRayTracing.*;
|
||||
import static org.lwjgl.vulkan.VK10.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.*;
|
||||
|
@ -35,7 +33,7 @@ public class VKUtils
|
|||
long callbackHandle = pCallback.get(0);
|
||||
memFree(pCallback);
|
||||
dbgCreateInfo.free();
|
||||
if (err != VK_SUCCESS)
|
||||
if (err != VK12.VK_SUCCESS)
|
||||
{ throw new AssertionError("Failed to create VkInstance: " + VKUtils.translateVulkanResult(err)); }
|
||||
return callbackHandle;
|
||||
}
|
||||
|
@ -48,13 +46,13 @@ public class VKUtils
|
|||
return shaderc_vertex_shader;
|
||||
case VK10.VK_SHADER_STAGE_FRAGMENT_BIT:
|
||||
return shaderc_fragment_shader;
|
||||
case VK_SHADER_STAGE_RAYGEN_BIT_NV:
|
||||
case NVRayTracing.VK_SHADER_STAGE_RAYGEN_BIT_NV:
|
||||
return shaderc_raygen_shader;
|
||||
case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV:
|
||||
case NVRayTracing.VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV:
|
||||
return shaderc_closesthit_shader;
|
||||
case VK_SHADER_STAGE_MISS_BIT_NV:
|
||||
case NVRayTracing.VK_SHADER_STAGE_MISS_BIT_NV:
|
||||
return shaderc_miss_shader;
|
||||
case VK_SHADER_STAGE_ANY_HIT_BIT_NV:
|
||||
case NVRayTracing.VK_SHADER_STAGE_ANY_HIT_BIT_NV:
|
||||
return shaderc_anyhit_shader;
|
||||
default:
|
||||
throw new IllegalArgumentException("Shader stage: " + stage);
|
||||
|
@ -177,13 +175,13 @@ public class VKUtils
|
|||
{
|
||||
// Create the render command buffers (one command buffer per framebuffer image)
|
||||
VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.calloc()
|
||||
.sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
|
||||
.sType(VK12.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
|
||||
.commandPool(commandPool)
|
||||
.level(VK_COMMAND_BUFFER_LEVEL_PRIMARY)
|
||||
.level(VK12.VK_COMMAND_BUFFER_LEVEL_PRIMARY)
|
||||
.commandBufferCount(framebuffers.length);
|
||||
PointerBuffer pCommandBuffer = memAllocPointer(framebuffers.length);
|
||||
int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
|
||||
if (err != VK_SUCCESS)
|
||||
int err = VK12.vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
|
||||
if (err != VK12.VK_SUCCESS)
|
||||
{ throw new AssertionError("Failed to create render command buffer: " + VKUtils.translateVulkanResult(err)); }
|
||||
VkCommandBuffer[] renderCommandBuffers = new VkCommandBuffer[framebuffers.length];
|
||||
for (int i = 0; i < framebuffers.length; i++)
|
||||
|
@ -192,7 +190,7 @@ public class VKUtils
|
|||
cmdBufAllocateInfo.free();
|
||||
// Create the command buffer begin structure
|
||||
VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.calloc()
|
||||
.sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO);
|
||||
.sType(VK12.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO);
|
||||
// Specify clear color (cornflower blue)
|
||||
VkClearValue.Buffer clearValues = VkClearValue.calloc(2);
|
||||
clearValues.get(0).color()
|
||||
|
@ -204,7 +202,7 @@ public class VKUtils
|
|||
clearValues.get(1).depthStencil().depth(1.0f).stencil(0);
|
||||
// Specify everything to begin a render pass
|
||||
VkRenderPassBeginInfo renderPassBeginInfo = VkRenderPassBeginInfo.calloc()
|
||||
.sType(VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO)
|
||||
.sType(VK12.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO)
|
||||
.renderPass(renderPass)
|
||||
.pClearValues(clearValues);
|
||||
VkRect2D renderArea = renderPassBeginInfo.renderArea();
|
||||
|
@ -214,43 +212,43 @@ public class VKUtils
|
|||
{
|
||||
// Set target frame buffer
|
||||
renderPassBeginInfo.framebuffer(framebuffers[i]);
|
||||
err = vkBeginCommandBuffer(renderCommandBuffers[i], cmdBufInfo);
|
||||
if (err != VK_SUCCESS)
|
||||
err = VK12.vkBeginCommandBuffer(renderCommandBuffers[i], cmdBufInfo);
|
||||
if (err != VK12.VK_SUCCESS)
|
||||
{ throw new AssertionError("Failed to begin render command buffer: " + VKUtils.translateVulkanResult(err)); }
|
||||
vkCmdBeginRenderPass(renderCommandBuffers[i], renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
VK12.vkCmdBeginRenderPass(renderCommandBuffers[i], renderPassBeginInfo, VK12.VK_SUBPASS_CONTENTS_INLINE);
|
||||
// Update dynamic viewport state
|
||||
VkViewport.Buffer viewport = VkViewport.calloc(1)
|
||||
.height(height)
|
||||
.width(width)
|
||||
.minDepth(0.0f)
|
||||
.maxDepth(1.0f);
|
||||
vkCmdSetViewport(renderCommandBuffers[i], 0, viewport);
|
||||
VK12.vkCmdSetViewport(renderCommandBuffers[i], 0, viewport);
|
||||
viewport.free();
|
||||
// Update dynamic scissor state
|
||||
VkRect2D.Buffer scissor = VkRect2D.calloc(1);
|
||||
scissor.extent().set(width, height);
|
||||
scissor.offset().set(0, 0);
|
||||
vkCmdSetScissor(renderCommandBuffers[i], 0, scissor);
|
||||
VK12.vkCmdSetScissor(renderCommandBuffers[i], 0, scissor);
|
||||
scissor.free();
|
||||
// Bind descriptor sets describing shader binding points
|
||||
LongBuffer descriptorSets = memAllocLong(1).put(0, descriptorSet);
|
||||
vkCmdBindDescriptorSets(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, descriptorSets, null);
|
||||
VK12.vkCmdBindDescriptorSets(renderCommandBuffers[i], VK12.VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, descriptorSets, null);
|
||||
memFree(descriptorSets);
|
||||
// Bind the rendering pipeline (including the shaders)
|
||||
vkCmdBindPipeline(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline);
|
||||
VK12.vkCmdBindPipeline(renderCommandBuffers[i], VK12.VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline);
|
||||
// Bind triangle vertices
|
||||
LongBuffer offsets = memAllocLong(1);
|
||||
offsets.put(0, 0L);
|
||||
LongBuffer pBuffers = memAllocLong(1);
|
||||
pBuffers.put(0, verticesBuf);
|
||||
vkCmdBindVertexBuffers(renderCommandBuffers[i], 0, pBuffers, offsets);
|
||||
VK12.vkCmdBindVertexBuffers(renderCommandBuffers[i], 0, pBuffers, offsets);
|
||||
memFree(pBuffers);
|
||||
memFree(offsets);
|
||||
// Draw triangle
|
||||
vkCmdDraw(renderCommandBuffers[i], 6, 1, 0, 0);
|
||||
vkCmdEndRenderPass(renderCommandBuffers[i]);
|
||||
err = vkEndCommandBuffer(renderCommandBuffers[i]);
|
||||
if (err != VK_SUCCESS)
|
||||
VK12.vkCmdDraw(renderCommandBuffers[i], 6, 1, 0, 0);
|
||||
VK12.vkCmdEndRenderPass(renderCommandBuffers[i]);
|
||||
err = VK12.vkEndCommandBuffer(renderCommandBuffers[i]);
|
||||
if (err != VK12.VK_SUCCESS)
|
||||
{ throw new AssertionError("Failed to begin render command buffer: " + VKUtils.translateVulkanResult(err)); }
|
||||
}
|
||||
renderPassBeginInfo.free();
|
||||
|
|
Loading…
Reference in New Issue