working vulkan example
parent
0c7925b280
commit
89b4a0902f
10
pom.xml
10
pom.xml
|
@ -260,6 +260,16 @@
|
|||
<artifactId>lwjgl-openal</artifactId>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-shaderc</artifactId>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-shaderc</artifactId>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-opengl</artifactId>
|
||||
|
|
|
@ -10,7 +10,7 @@ import static org.lwjgl.system.MemoryUtil.*;
|
|||
import static org.lwjgl.vulkan.EXTDebugReport.*;
|
||||
import static org.lwjgl.vulkan.KHRSurface.*;
|
||||
import static org.lwjgl.vulkan.KHRSwapchain.*;
|
||||
import static org.lwjgl.vulkan.VK10.*;
|
||||
import static org.lwjgl.vulkan.VK12.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.*;
|
||||
|
@ -49,7 +49,7 @@ public class VulkanStarter {
|
|||
private static VkInstance createInstance(PointerBuffer requiredExtensions) {
|
||||
VkApplicationInfo appInfo = VkApplicationInfo.calloc()
|
||||
.sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
|
||||
.apiVersion(VK_API_VERSION_1_0);
|
||||
.apiVersion(VK_API_VERSION_1_2);
|
||||
PointerBuffer ppEnabledExtensionNames = memAllocPointer(requiredExtensions.remaining() + 1);
|
||||
ppEnabledExtensionNames.put(requiredExtensions);
|
||||
ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
|
@ -1037,8 +1037,8 @@ public class VulkanStarter {
|
|||
|
||||
// Load shaders
|
||||
VkPipelineShaderStageCreateInfo.Buffer shaderStages = VkPipelineShaderStageCreateInfo.calloc(2);
|
||||
shaderStages.get(0).set(loadShader(device, "org/lwjgl/demo/vulkan/twoRotatingTriangles.vert", VK_SHADER_STAGE_VERTEX_BIT));
|
||||
shaderStages.get(1).set(loadShader(device, "org/lwjgl/demo/vulkan/twoRotatingTriangles.frag", VK_SHADER_STAGE_FRAGMENT_BIT));
|
||||
shaderStages.get(0).set(loadShader(device, "/vulkan/shaders/entityVertexShader.glsl", VK_SHADER_STAGE_VERTEX_BIT));
|
||||
shaderStages.get(1).set(loadShader(device, "/vulkan/shaders/entityFragmentShader.glsl", VK_SHADER_STAGE_FRAGMENT_BIT));
|
||||
|
||||
// Create the pipeline layout that is used to generate the rendering pipelines that
|
||||
// are based on this descriptor set layout
|
||||
|
@ -1199,7 +1199,7 @@ public class VulkanStarter {
|
|||
return renderCommandBuffers;
|
||||
}
|
||||
|
||||
private static void updateUbo(VkDevice device, UboDescriptor ubo, float angle) {
|
||||
private static void updateUbo(VkDevice device, UboDescriptor ubo, float angle) { //a UBO is a uniform buffer object
|
||||
Matrix4f m = new Matrix4f()
|
||||
.scale(1, -1, 1) // <- correcting viewport transformation (what Direct3D does, too)
|
||||
.perspective((float) Math.toRadians(45.0f), (float) width / height, 0.1f, 10.0f, true)
|
||||
|
|
|
@ -58,8 +58,8 @@ public class Window
|
|||
System.exit(-1);
|
||||
}
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.github.hydos.ginger.engine.vulkan.utils;
|
||||
|
||||
import org.lwjgl.vulkan.VK12;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hydos
|
||||
|
@ -9,7 +11,6 @@ package com.github.hydos.ginger.engine.vulkan.utils;
|
|||
public class VKLoader {
|
||||
|
||||
public void setupVulkan() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ public class VKUtils {
|
|||
}
|
||||
|
||||
public static ByteBuffer glslToSpirv(String classPath, int vulkanStage) throws IOException {
|
||||
System.out.println("Converting shader " + classPath + " to GLSL");
|
||||
ByteBuffer src = IOUtil.ioResourceToByteBuffer(classPath, 1024);
|
||||
long compiler = shaderc_compiler_initialize();
|
||||
long options = shaderc_compile_options_initialize();
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#version 450
|
||||
|
||||
layout(location=0) out vec4 color;
|
||||
|
||||
layout(location=0) in vec3 outColor;
|
||||
|
||||
void main(void) {
|
||||
color = vec4(outColor, 1.0);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#version 450
|
||||
|
||||
layout(location=0) in vec3 position;
|
||||
layout(location=1) in vec3 color;
|
||||
|
||||
layout(binding=0) uniform Matrices
|
||||
{
|
||||
mat4 viewProjection;
|
||||
};
|
||||
|
||||
layout(location=0) out vec3 outColor;
|
||||
|
||||
void main(void) {
|
||||
outColor = color;
|
||||
gl_Position = viewProjection * vec4(position, 1.0);
|
||||
}
|
Loading…
Reference in New Issue