Ejemplo n.º 1
0
std::unique_ptr<GLContextEGL> GLContextEGL::createContext(GLNativeWindowType window, PlatformDisplay& platformDisplay)
{
    if (platformDisplay.eglDisplay() == EGL_NO_DISPLAY)
        return nullptr;

    if (eglBindAPI(gEGLAPIVersion) == EGL_FALSE)
        return nullptr;

    EGLContext eglSharingContext = platformDisplay.sharingGLContext() ? static_cast<GLContextEGL*>(platformDisplay.sharingGLContext())->m_context : EGL_NO_CONTEXT;
    auto context = window ? createWindowContext(window, platformDisplay, eglSharingContext) : nullptr;
    if (!context)
        context = createSurfacelessContext(platformDisplay, eglSharingContext);
    if (!context) {
#if PLATFORM(X11)
        if (platformDisplay.type() == PlatformDisplay::Type::X11)
            context = createPixmapContext(platformDisplay, eglSharingContext);
#endif
#if PLATFORM(WAYLAND)
        if (platformDisplay.type() == PlatformDisplay::Type::Wayland)
            context = createWaylandContext(platformDisplay, eglSharingContext);
#endif
    }
    if (!context)
        context = createPbufferContext(platformDisplay, eglSharingContext);

    return context;
}
Ejemplo n.º 2
0
PassOwnPtr<GLContextEGL> GLContextEGL::createContext(EGLNativeWindowType window, GLContext* sharingContext)
{
    if (!sharedEGLDisplay())
        return nullptr;

    static bool initialized = false;
    static bool success = true;
    if (!initialized) {
#if !USE(OPENGL_ES_2)
        success = initializeOpenGLShims();
#endif
        initialized = true;
    }
    if (!success)
        return nullptr;

    EGLContext eglSharingContext = sharingContext ? static_cast<GLContextEGL*>(sharingContext)->m_context : 0;
    OwnPtr<GLContextEGL> context = window ? createWindowContext(window, sharingContext) : nullptr;
    if (!context)
        context = createPixmapContext(eglSharingContext);

    if (!context)
        context = createPbufferContext(eglSharingContext);
    
    return context.release();
}
Ejemplo n.º 3
0
Archivo: dev.cpp Proyecto: nyorain/ny
int main()
{
	auto& backend = ny::Backend::choose();
	auto ac = backend.createAppContext();

	ny::BufferSurface* bufferSurface {};
	MyWindowListener listener;

	ny::WindowSettings settings;
	settings.title = "Ayy sick shit";
	settings.listener = &listener;
	settings.surface = ny::SurfaceType::buffer;
	settings.buffer.storeSurface = &bufferSurface;
	auto wc = ac->createWindowContext(settings);

	ny::LoopControl control;

	listener.lc = &control;
	listener.ac = ac.get();
	listener.wc = wc.get();
	listener.surface = bufferSurface;

	ny::log("Entering main loop");
	ac->dispatchLoop(control);
}
Ejemplo n.º 4
0
std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, PlatformDisplay& platformDisplay)
{
    GLXContext glxSharingContext = platformDisplay.sharingGLContext() ? static_cast<GLContextGLX*>(platformDisplay.sharingGLContext())->m_context.get() : nullptr;
    auto context = window ? createWindowContext(window, platformDisplay, glxSharingContext) : nullptr;
    if (!context)
        context = createPbufferContext(platformDisplay, glxSharingContext);
    if (!context)
        context = createPixmapContext(platformDisplay, glxSharingContext);

    return context;
}
Ejemplo n.º 5
0
Archivo: intro.cpp Proyecto: nyorain/ny
//Main function that just chooses a backend, creates Window- and AppContext from it, registers
//a custom EventHandler and then runs the mainLoop.
//There is no special main function (like WinMain or sth.) needed for different backends.
int main()
{
	//We let ny choose a backend.
	//If no backend is available, this function will simply throw an exception.
	//The backend will determine the type of display manager used, usually there is only
	//one available, but for corner cases (like e.g. wayland and XWayland) it will choose the
	//better/native one (in this case wayland).
	auto& backend = ny::Backend::choose();

	//Here we let the backend create an AppContext implementation.
	//This represents the connection to the display, our method of creating windows and
	//receiving events.
	auto ac = backend.createAppContext(); //decltype(ac): std::unique_ptr<ny::AppContext>

	//Now we let the AppContext create a WindowContext implementation.
	//Just use the defaulted WindowSettings.
	//This can later be used to change various aspects of the created window.
	ny::WindowSettings settings;
	auto wc = ac->createWindowContext(settings); //decltype(wc): std::unique_ptr<ny::WindowContext>

	//Now we create a LoopControl object.
	//With this object we can stop the dispatchLoop (which is called below) from the inside
	//or even from different threads (see ny-multithread).
	//We construct the EventHandler with a reference to it and when it receives an event that
	//the WindowContext was closed, it will stop the dispatchLoop, which will end this
	//program.
	ny::LoopControl control;
	MyEventHandler handler(control, *wc);

	//This call registers our EventHandler to receive the WindowContext related events from
	//the dispatchLoop.
	wc->eventHandler(handler);
	wc->refresh();

	//ny::log can be used to easily output application information.
	//There are also other output methods, see ny/log.hpp.
	//The call will have no cost/effect when not compiled in debug mode.
	ny::log("Entering main loop");
	ac->dispatchLoop(control);
}
Ejemplo n.º 6
0
int main()
{
	constexpr auto width = 1200u;
	constexpr auto height = 800u;

	// init ny app
	auto& backend = ny::Backend::choose();
	if(!backend.vulkan()) {
		dlg_error("ny backend has no vulkan support!");
		return 0;
	}

	auto ac = backend.createAppContext();

	// basic vpp init
	auto iniExtensions = ac->vulkanExtensions();
	iniExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
	vk::ApplicationInfo appInfo ("vpp-intro", 1, "vpp", 1, VK_API_VERSION_1_0);
	vk::InstanceCreateInfo instanceInfo;
	instanceInfo.pApplicationInfo = &appInfo;
	instanceInfo.enabledExtensionCount = iniExtensions.size();
	instanceInfo.ppEnabledExtensionNames = iniExtensions.data();

#ifdef WithLayers
	constexpr auto layer = "VK_LAYER_LUNARG_standard_validation";
	instanceInfo.enabledLayerCount = 1;
	instanceInfo.ppEnabledLayerNames = &layer;
#endif

	vpp::Instance instance(instanceInfo);

#ifdef WithLayers
	vpp::DebugCallback debugCallback(instance);
#endif

	// ny init
	auto run = true;

	auto listener = MyWindowListener {};
	listener.run = &run;

	auto vkSurface = vk::SurfaceKHR {};
	auto ws = ny::WindowSettings {};
	ws.surface = ny::SurfaceType::vulkan;
	ws.listener = &listener;
	ws.size = {width, height};
	ws.vulkan.instance = (VkInstance) instance.vkHandle();
	ws.vulkan.storeSurface = &(std::uintptr_t&) (vkSurface);
	auto wc = ac->createWindowContext(ws);

	// further vpp init
	const vpp::Queue* presentQueue;
	vpp::Device device(instance, vkSurface, presentQueue);
	vpp::Swapchain swapchain(device, vkSurface, {width, height}, {});

	// vvg setup
	auto nvgContext = vvg::createContext(swapchain);
	auto font = nvgCreateFont(nvgContext, "sans", "Roboto-Regular.ttf");

	using Clock = std::chrono::high_resolution_clock;
	auto lastFrameTimer = Clock::now();
	unsigned int framesCount = 0;
	std::string fpsString = "420 fps";

	// main loop
	while(run) {
		if(!ac->dispatchEvents())
			break;

		nvgBeginFrame(nvgContext, width, height, width / (float) height);

		nvgBeginPath(nvgContext);
		nvgMoveTo(nvgContext, 10, 10);
		nvgLineTo(nvgContext, 10, 400);
		nvgLineTo(nvgContext, 100, 400);
		nvgQuadTo(nvgContext, 100, 50, 400, 120);
		nvgLineTo(nvgContext, 450, 10);
		nvgClosePath(nvgContext);

		nvgFillColor(nvgContext, nvgRGBAf(0.5, 0.8, 0.7, 1.0));
		nvgFill(nvgContext);

		nvgBeginPath(nvgContext);
		nvgFontFaceId(nvgContext, font);
		nvgFontSize(nvgContext, 100.f);
		nvgFontBlur(nvgContext, .8f);
		nvgFillColor(nvgContext, nvgRGBAf(1.0, 1.0, 1.0, 1.0));
		nvgTextBox(nvgContext, 200, 200, width - 200, "Hello Vulkan Vector Graphics World", nullptr);

		nvgFontSize(nvgContext, 30.f);
		nvgFontBlur(nvgContext, .2f);
		nvgText(nvgContext, 10, height - 20, fpsString.c_str(), nullptr);

		nvgBeginPath(nvgContext);
		nvgRect(nvgContext, 700, 400, 300, 300);
		nvgPathWinding(nvgContext, NVG_HOLE);
		nvgRect(nvgContext, 750, 450, 50, 50);
		// auto paint = nvgRadialGradient(nvgContext, 750, 425,20, 50, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0));
		// auto paint = nvgRadialGradient(nvgContext, 0.0, 0.0, 0.2, 100.0, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0));
		auto paint = nvgLinearGradient(nvgContext, 700, 400, 800, 450, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0));
		nvgFillPaint(nvgContext, paint);
		// nvgFillColor(nvgContext, nvgRGBA(200, 200, 0, 200));
		nvgClosePath(nvgContext);
		nvgFill(nvgContext);

		nvgEndFrame(nvgContext);

		// only refresh frame timer every second
		framesCount++;
		if(Clock::now() - lastFrameTimer >= std::chrono::seconds(1)) {
			fpsString = std::to_string(framesCount) + " fps";
			lastFrameTimer = Clock::now();
			framesCount = 0;
		}
	}

	vvg::destroyContext(*nvgContext);
}