Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

(C++) Noesis and Multiple Windows with GLFW, how to?

14 Jun 2017, 16:40

I created new window in GLFW and want add new IView in to it. I create new IView and load another xaml, and add same VGContext. But when new window is created and I start render with Noesis, program crash. I think it because GLFW use MakeCurrentContext(window) what makes a problem when I change CurrentContext. How can I create and use Noesis with multiple windows?
        glfwMakeContextCurrent(window); // This must be befor creating Noesis VGContext. If this is not before Noesis::VGContext, program crash.
// Noesis Initialization
        Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("my.xaml"); 
        Ptr<FrameworkElement> xamlElementChooseWin = Noesis::GUI::LoadXaml<FrameworkElement>("choicer.xaml");
	xamlView = Noesis::GUI::CreateView(xaml.GetPtr());
	xamlView->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_MSAA);

	xamlViewChoicer = Noesis::GUI::CreateView(xamlElementChooseWin.GetPtr());
	xamlViewChoicer->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_MSAA);

	Ptr<GLRenderDevice> device = *new GLRenderDevice();
	VGOptions options;
	Ptr<VGContext> context = Noesis::GUI::CreateVGContext(device.GetPtr(), Noesis::VGOptions());
	xamlView->GetRenderer()->Init(context.GetPtr());
	xamlViewChoicer->GetRenderer()->Init(context.GetPtr());
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: (C++) Noesis and Multiple Windows with GLFW, how to?

14 Jun 2017, 17:25

One fast question, in this scenario you have a different GL context per window? In that case you cannot share the same VGContext. You need to create a different VGContext and GLRenderDevice. The creation must be done with the proper GL context bound.
 
Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

Re: (C++) Noesis and Multiple Windows with GLFW, how to?

14 Jun 2017, 18:16

If MakeCurrentContext is different GL context, then yes. But in my oppinion, it is only one GL context (but maybe I am wrong), and when I render in to window I set this context in to window with MakeCurrentContext.
There is MakeCurrentContext in use.
while (pravda == true)
	{
		if (pravda == true)
		{
			glfwMakeContextCurrent(window);
			// window and mouse data
			glfwGetWindowSize(window, &windowWidth, &windowHeight);
			glfwGetFramebufferSize(window, &bufWinWidth, &bufWinHeight);
			glfwGetCursorPos(window, &mouse_x_pos, &mouse_y_pos);
			NSmouse::x = (NsInt)mouse_x_pos;
			NSmouse::y = (NsInt)mouse_y_pos;

			// Noesis GUI
			xamlView->Update(glfwGetTimerValue() / 1000.0); // / 1000.0
			Noesis::IRenderer * nRender = xamlView->GetRenderer();
			nRender->UpdateRenderTree();

			if (nRender->NeedsOffscreen())
			{
				nRender->RenderOffscreen();
			}
			glViewport(0, 0, bufWinWidth, bufWinHeight);
			glClear(GL_COLOR_BUFFER_BIT); //  | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT
			glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
			if (glfwGetWindowAttrib(window, GLFW_FOCUSED))
			{
				xamlView->MouseMove((NsInt)NSmouse::x, (NsInt)NSmouse::y);
			}
			nRender->Render();
			// GLFW

			glfwPollEvents();

			if (xamlView != 0)
			{
				xamlView->SetSize(windowWidth, windowHeight);
			}
			glfwSwapBuffers(window);
			if (glfwWindowShouldClose(window)) { pravda = false; blab = false; }
		}
		if (blab == true)
		{
			glfwMakeContextCurrent(windowChoose);
			// window and mouse data
			glfwGetWindowSize(windowChoose, &windowWidth, &windowHeight);
			glfwGetFramebufferSize(windowChoose, &bufWinWidth, &bufWinHeight);
			glfwGetCursorPos(windowChoose, &mouse_x_pos, &mouse_y_pos);
			NSmouse::x = (NsInt)mouse_x_pos;
			NSmouse::y = (NsInt)mouse_y_pos;

			// Noesis
			xamlViewChoicer->Update(glfwGetTimerValue() / 1000.0); //
			Noesis::IRenderer * nRender = xamlViewChoicer->GetRenderer();
			nRender->UpdateRenderTree();
			if (nRender->NeedsOffscreen())
			{
				nRender->RenderOffscreen();
			}

			glViewport(0, 0, bufWinWidth, bufWinHeight);
			glClear(GL_COLOR_BUFFER_BIT);
			glClearColor(0.2f, 0.2f, 0.8f, 1.0f);
			if (xamlViewChoicer != 0)
			{
				xamlViewChoicer->SetSize(windowWidth, windowHeight);
			}
			nRender->Render();
			
			glfwSwapBuffers(windowChoose);
			glfwPollEvents();
			if (glfwWindowShouldClose(windowChoose)) { blab = false; glfwDestroyWindow(windowChoose); }
		}
	}
something about glfwMakeContextCurrent()
---------------------------------------------------------------------------------

I created another GLRenderDevice and VGContext after created new window and it working. But as it said in RenderArchitectureTutorial VGContext is heavyweight object. It will be ok, when I will use more then two windows? maybe 3, 5 or more and for each window VGContext?
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: (C++) Noesis and Multiple Windows with GLFW, how to?

14 Jun 2017, 18:25

You can verify is the context is different or not by calling wglGetCurrentContext. If the context is different then there is no alternative to create several VGContext and GLRenderDevice. It is a heavy object (ramps and glyphs cache are stored there for example), but having a few of then is probably acceptable. I wouldn't worry much.
 
Wanderer
Topic Author
Posts: 168
Joined: 08 May 2017, 18:36

Re: (C++) Noesis and Multiple Windows with GLFW, how to?

14 Jun 2017, 18:50

It is not needed. I remembered that I forgot in creation glfwWindow add share context, that means now I use more GL Context and with share I use one GL Context. Now I can use one VGContext, with multiple window. Thanks.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: (C++) Noesis and Multiple Windows with GLFW, how to?

15 Jun 2017, 12:54

Glad to know it is working!

Who is online

Users browsing this forum: No registered users and 1 guest