org.lwjgl.system.Platform Java Examples

The following examples show how to use org.lwjgl.system.Platform. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BackendSelector.java    From settlers-remake with MIT License 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent actionEvent) {
	super.actionPerformed(actionEvent);

	if(actionEvent.getActionCommand() == "comboBoxChanged") {
		EBackendType bi = (EBackendType) getSelectedItem();
		if (bi.platform != null && bi.platform != Platform.get()) {
			setSelectedItem(current_item);
			BackendSelector.this.hidePopup();
			JOptionPane.showMessageDialog(BackendSelector.this.getParent(), bi.cc_name + " is only available on " + bi.platform);
		} else {
			current_item = bi;
		}

	}
}
 
Example #2
Source File: AWTGLCanvas.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
private static PlatformGLCanvas createPlatformCanvas() {
    switch (Platform.get()) {
    case WINDOWS:
        return new PlatformWin32GLCanvas();
    case LINUX:
        return new PlatformLinuxGLCanvas();
    default:
        throw new UnsupportedOperationException("Platform " + Platform.get() + " not yet supported");
    }
}
 
Example #3
Source File: SimpleDemo.java    From lwjgl3-awt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("AWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example #4
Source File: SimpleDemo.java    From lwjgl3-swt with MIT License 5 votes vote down vote up
/**
 * Create a Vulkan instance using LWJGL 3.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(2);
    ppEnabledExtensionNames.put(VK_KHR_SURFACE_EXTENSION);
    ppEnabledExtensionNames.put(VK_KHR_OS_SURFACE_EXTENSION);
    ppEnabledExtensionNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(0L)
            .pApplicationInfo(appInfo);
    if (ppEnabledExtensionNames.remaining() > 0) {
        pCreateInfo.ppEnabledExtensionNames(ppEnabledExtensionNames);
    }
    PointerBuffer pInstance = MemoryUtil.memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    if (err != VK_SUCCESS) {
        throw new RuntimeException("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    long instance = pInstance.get(0);
    memFree(pInstance);
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example #5
Source File: BackendSelector.java    From settlers-remake with MIT License 5 votes vote down vote up
public static ContextCreator createBackend(GLContainer container, EBackendType backend, boolean debug) throws Exception {
	EBackendType real_backend = backend;

	if(backend == null || backend.cc_class == null) {
		// first of all usable and suitable backends sorted for being default
		real_backend = availableBackends().filter(current_backend -> current_backend.default_for == Platform.get()).sorted().findFirst().orElse(FALLBACK_BACKEND);
	}

	return real_backend.cc_class.getConstructor(GLContainer.class, Boolean.TYPE).newInstance(container, debug);
}
 
Example #6
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
/**
 * Create a Vulkan {@link VkInstance} using LWJGL 3.
 * <p>
 * The {@link VkInstance} represents a handle to the Vulkan API and we need that instance for about everything we do.
 * 
 * @return the VkInstance handle
 */
private static VkInstance createInstance() {
    VkApplicationInfo appInfo = VkApplicationInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_APPLICATION_INFO)
            .pApplicationName(memUTF8("SWT Vulkan Demo"))
            .pEngineName(memUTF8(""))
            .apiVersion(VK_MAKE_VERSION(1, 0, 2));
    ByteBuffer VK_KHR_SURFACE_EXTENSION = memUTF8(VK_KHR_SURFACE_EXTENSION_NAME);
    ByteBuffer VK_EXT_DEBUG_REPORT_EXTENSION = memUTF8(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
    ByteBuffer VK_KHR_OS_SURFACE_EXTENSION;
    if (Platform.get() == Platform.WINDOWS)
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
    else
        VK_KHR_OS_SURFACE_EXTENSION = memUTF8(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
    PointerBuffer ppEnabledExtensionNames = memAllocPointer(3)
      .put(VK_KHR_SURFACE_EXTENSION)
      .put(VK_KHR_OS_SURFACE_EXTENSION)
      .put(VK_EXT_DEBUG_REPORT_EXTENSION)
      .flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++)
        ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();
    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
            .pNext(NULL)
            .pApplicationInfo(appInfo)
            .ppEnabledExtensionNames(ppEnabledExtensionNames)
            .ppEnabledLayerNames(ppEnabledLayerNames);
    PointerBuffer pInstance = memAllocPointer(1);
    int err = vkCreateInstance(pCreateInfo, null, pInstance);
    long instance = pInstance.get(0);
    memFree(pInstance);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    VkInstance ret = new VkInstance(instance, pCreateInfo);
    pCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(ppEnabledExtensionNames);
    memFree(VK_KHR_OS_SURFACE_EXTENSION);
    memFree(VK_EXT_DEBUG_REPORT_EXTENSION);
    memFree(VK_KHR_SURFACE_EXTENSION);
    appInfo.free();
    return ret;
}
 
Example #7
Source File: ModernOpenGLDraw.java    From recast4j with zlib License 4 votes vote down vote up
@Override
public void init() {
    String NK_SHADER_VERSION = Platform.get() == Platform.MACOSX ? "#version 150\n" : "#version 300 es\n";
    String vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n"//
            + "uniform mat4 ViewMtx;\n"//
            + "in vec3 Position;\n"//
            + "in vec2 TexCoord;\n"//
            + "in vec4 Color;\n"//
            + "out vec2 Frag_UV;\n"//
            + "out vec4 Frag_Color;\n"//
            + "out float Frag_Depth;\n"//
            + "void main() {\n"//
            + "   Frag_UV = TexCoord;\n"//
            + "   Frag_Color = Color;\n"//
            + "   vec4 VSPosition = ViewMtx * vec4(Position, 1);\n"//
            + "   Frag_Depth = -VSPosition.z;\n"//
            + "   gl_Position = ProjMtx * VSPosition;\n"//
            + "}\n";
    String fragment_shader = NK_SHADER_VERSION + "precision mediump float;\n"//
            + "uniform sampler2D Texture;\n"//
            + "uniform float UseTexture;\n"//
            + "uniform float EnableFog;\n"//
            + "uniform float FogStart;\n"//
            + "uniform float FogEnd;\n"//
            + "const vec4 FogColor = vec4(0.32f, 0.31f, 0.30f, 1.0f);\n"//
            + "in vec2 Frag_UV;\n"//
            + "in vec4 Frag_Color;\n"//
            + "in float Frag_Depth;\n"//
            + "out vec4 Out_Color;\n"//
            + "void main(){\n"//
            + "   Out_Color = mix(FogColor, Frag_Color * mix(vec4(1), texture(Texture, Frag_UV.st), UseTexture), 1.0 - EnableFog * clamp( (Frag_Depth - FogStart) / (FogEnd - FogStart), 0.0, 1.0) );\n"//
            + "}\n";

    program = glCreateProgram();
    int vert_shdr = glCreateShader(GL_VERTEX_SHADER);
    int frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(vert_shdr, vertex_shader);
    glShaderSource(frag_shdr, fragment_shader);
    glCompileShader(vert_shdr);
    glCompileShader(frag_shdr);
    if (glGetShaderi(vert_shdr, GL_COMPILE_STATUS) != GL_TRUE) {
        throw new IllegalStateException();
    }
    if (glGetShaderi(frag_shdr, GL_COMPILE_STATUS) != GL_TRUE) {
        throw new IllegalStateException();
    }
    glAttachShader(program, vert_shdr);
    glAttachShader(program, frag_shdr);
    glLinkProgram(program);
    if (glGetProgrami(program, GL_LINK_STATUS) != GL_TRUE) {
        throw new IllegalStateException();
    }
    uniformTexture = glGetUniformLocation(program, "Texture");
    uniformUseTexture = glGetUniformLocation(program, "UseTexture");
    uniformFog = glGetUniformLocation(program, "EnableFog");
    uniformFogStart = glGetUniformLocation(program, "FogStart");
    uniformFogEnd = glGetUniformLocation(program, "FogEnd");
    uniformProjectionMatrix = glGetUniformLocation(program, "ProjMtx");
    uniformViewMatrix = glGetUniformLocation(program, "ViewMtx");
    int attrib_pos = glGetAttribLocation(program, "Position");
    int attrib_uv = glGetAttribLocation(program, "TexCoord");
    int attrib_col = glGetAttribLocation(program, "Color");

    // buffer setup
    vbo = glGenBuffers();
    ebo = glGenBuffers();
    vao = glGenVertexArrays();

    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);

    glEnableVertexAttribArray(attrib_pos);
    glEnableVertexAttribArray(attrib_uv);
    glEnableVertexAttribArray(attrib_col);

    glVertexAttribPointer(attrib_pos, 3, GL_FLOAT, false, 24, 0);
    glVertexAttribPointer(attrib_uv, 2, GL_FLOAT, false, 24, 12);
    glVertexAttribPointer(attrib_col, 4, GL_UNSIGNED_BYTE, true, 24, 20);

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindVertexArray(0);

}
 
Example #8
Source File: NuklearGL.java    From recast4j with zlib License 4 votes vote down vote up
public NuklearGL(NuklearUI context) {
    this.context = context;
    nk_buffer_init(cmds, context.allocator, BUFFER_INITIAL_SIZE);
    vertexLayout = NkDrawVertexLayoutElement.create(4)//
            .position(0).attribute(NK_VERTEX_POSITION).format(NK_FORMAT_FLOAT).offset(0)//
            .position(1).attribute(NK_VERTEX_TEXCOORD).format(NK_FORMAT_FLOAT).offset(8)//
            .position(2).attribute(NK_VERTEX_COLOR).format(NK_FORMAT_R8G8B8A8).offset(16)//
            .position(3).attribute(NK_VERTEX_ATTRIBUTE_COUNT).format(NK_FORMAT_COUNT).offset(0)//
            .flip();
    String NK_SHADER_VERSION = Platform.get() == Platform.MACOSX ? "#version 150\n" : "#version 300 es\n";
    String vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n" + "in vec2 Position;\n"
            + "in vec2 TexCoord;\n" + "in vec4 Color;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Color;\n"
            + "void main() {\n" + "   Frag_UV = TexCoord;\n" + "   Frag_Color = Color;\n"
            + "   gl_Position = ProjMtx * vec4(Position.xy, 0, 1);\n" + "}\n";
    String fragment_shader = NK_SHADER_VERSION + "precision mediump float;\n" + "uniform sampler2D Texture;\n"
            + "in vec2 Frag_UV;\n" + "in vec4 Frag_Color;\n" + "out vec4 Out_Color;\n" + "void main(){\n"
            + "   Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" + "}\n";

    program = glCreateProgram();
    int vert_shdr = glCreateShader(GL_VERTEX_SHADER);
    int frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(vert_shdr, vertex_shader);
    glShaderSource(frag_shdr, fragment_shader);
    glCompileShader(vert_shdr);
    glCompileShader(frag_shdr);
    if (glGetShaderi(vert_shdr, GL_COMPILE_STATUS) != GL_TRUE) {
        throw new IllegalStateException();
    }
    if (glGetShaderi(frag_shdr, GL_COMPILE_STATUS) != GL_TRUE) {
        throw new IllegalStateException();
    }
    glAttachShader(program, vert_shdr);
    glAttachShader(program, frag_shdr);
    glLinkProgram(program);
    if (glGetProgrami(program, GL_LINK_STATUS) != GL_TRUE) {
        throw new IllegalStateException();
    }

    uniform_tex = glGetUniformLocation(program, "Texture");
    uniform_proj = glGetUniformLocation(program, "ProjMtx");
    int attrib_pos = glGetAttribLocation(program, "Position");
    int attrib_uv = glGetAttribLocation(program, "TexCoord");
    int attrib_col = glGetAttribLocation(program, "Color");

    // buffer setup
    vbo = glGenBuffers();
    ebo = glGenBuffers();
    vao = glGenVertexArrays();

    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);

    glEnableVertexAttribArray(attrib_pos);
    glEnableVertexAttribArray(attrib_uv);
    glEnableVertexAttribArray(attrib_col);

    glVertexAttribPointer(attrib_pos, 2, GL_FLOAT, false, 20, 0);
    glVertexAttribPointer(attrib_uv, 2, GL_FLOAT, false, 20, 8);
    glVertexAttribPointer(attrib_col, 4, GL_UNSIGNED_BYTE, true, 20, 16);

    // null texture setup
    int nullTexID = glGenTextures();

    null_texture.texture().id(nullTexID);
    null_texture.uv().set(0.5f, 0.5f);

    glBindTexture(GL_TEXTURE_2D, nullTexID);
    try (MemoryStack stack = stackPush()) {
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV,
                stack.ints(0xFFFFFFFF));
    }
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
    default_font = setupFont();
    nk_style_set_font(context.ctx, default_font);
}
 
Example #9
Source File: LwjglContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private long createContext(final long platform, final long[] devices, long window) {
    try (MemoryStack stack = MemoryStack.stackPush()) {

        final int propertyCount = 2 + 4 + 1;
        final PointerBuffer properties = stack.callocPointer(propertyCount + devices.length);

        // set sharing properties
        // https://github.com/glfw/glfw/issues/104
        // https://github.com/LWJGL/lwjgl3/blob/master/modules/core/src/test/java/org/lwjgl/demo/opencl/Mandelbrot.java
        // TODO: test on Linux and MacOSX
        switch (Platform.get()) {
            case WINDOWS:
                properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR)
                        .put(org.lwjgl.glfw.GLFWNativeWGL.glfwGetWGLContext(window))
                        .put(KHRGLSharing.CL_WGL_HDC_KHR)
                        .put(org.lwjgl.opengl.WGL.wglGetCurrentDC());
                break;
            case LINUX:
                properties.put(KHRGLSharing.CL_GL_CONTEXT_KHR)
                        .put(org.lwjgl.glfw.GLFWNativeGLX.glfwGetGLXContext(window))
                        .put(KHRGLSharing.CL_GLX_DISPLAY_KHR)
                        .put(org.lwjgl.glfw.GLFWNativeX11.glfwGetX11Display());
                break;
            case MACOSX:
                properties.put(APPLEGLSharing.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE)
                        .put(org.lwjgl.opengl.CGL.CGLGetShareGroup(org.lwjgl.opengl.CGL.CGLGetCurrentContext()));
        }

        properties.put(CL_CONTEXT_PLATFORM).put(platform);
        properties.put(0);
        properties.flip();

        final IntBuffer error = stack.callocInt(1);
        final PointerBuffer deviceBuffer = stack.callocPointer(devices.length);
        for (final long deviceId : devices) {
            deviceBuffer.put(deviceId);
        }

        deviceBuffer.flip();

        long context = CL10.clCreateContext(properties, deviceBuffer, null, 0, error);
        Utils.checkError(error, "clCreateContext");

        return context;
    }
}
 
Example #10
Source File: BackendSelector.java    From settlers-remake with MIT License 4 votes vote down vote up
private static Stream<EBackendType> availableBackends() {
	return Arrays.stream(EBackendType.values()).filter(backend -> backend.available(Platform.get()));
}
 
Example #11
Source File: VKCanvas.java    From lwjgl3-swt with MIT License 3 votes vote down vote up
/**
 * Create a {@link VKCanvas} widget using the attributes described in the supplied {@link VKData} object.
 *
 * @param parent
 *            a parent composite widget
 * @param style
 *            the bitwise OR'ing of widget styles
 * @param data
 *            the necessary data to create a VKCanvas
 */
public VKCanvas(Composite parent, int style, VKData data) {
    super(parent, platformCanvas.checkStyle(parent, style));
    if (Platform.get() == Platform.WINDOWS) {
        platformCanvas.resetStyle(parent);
    }
    if (data == null)
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
    surface = platformCanvas.create(this, data);
}
 
Example #12
Source File: GLCanvas.java    From lwjgl3-swt with MIT License 3 votes vote down vote up
/**
 * Create a GLCanvas widget using the attributes described in the GLData
 * object provided.
 *
 * @param parent a composite widget
 * @param style the bitwise OR'ing of widget styles
 * @param data the requested attributes of the GLCanvas
 *
 * @exception IllegalArgumentException
 * <ul>
 * <li>ERROR_NULL_ARGUMENT when the data is null
 * <li>ERROR_UNSUPPORTED_DEPTH when the requested attributes cannot be provided
 * </ul>
 */
public GLCanvas(Composite parent, int style, GLData data) {
    super(parent, platformCanvas.checkStyle(parent, style));
    if (Platform.get() == Platform.WINDOWS) {
        platformCanvas.resetStyle(parent);
    }
    if (data == null)
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
    effective = new GLData();
    context = platformCanvas.create(this, data, effective);
}