Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » [Proposal] Adding a GLLock struct to GLCtrl
Re: [Proposal] Adding a GLLock struct to GLCtrl [message #54714 is a reply to message #54713] Thu, 03 September 2020 02:30 Go to previous messageGo to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Klugier, You are right about adding method in addition to struct:

Here is the code I got:
GLCtrl.h
//Class GLCtrl : public Ctrl{
	void ActivateContext();
	void SwapBuffer();
	void DesactivateContext();
	
	struct ContextLock {
		private:
			GLCtrl& parent;
		public:
			ContextLock(GLCtrl& ctrl);
			~ContextLock();
	};
	struct ContextLockWithSwapBuffers{
		private:
			GLCtrl& parent;
		public:
			ContextLockWithSwapBuffers(GLCtrl& ctrl);
			~ContextLockWithSwapBuffers();
	};
//};


Win32GLCtrl.cpp :
void GLCtrl::ActivateContext(){
	HWND hwnd = pane.GetHWND();
	GLCtrl::CreateContext();
	HDC hDC = GetDC(hwnd);
	wglMakeCurrent(hDC, s_openGLContext);
}
void GLCtrl::SwapBuffer(){
	HWND hwnd = GetHWND();
	HDC hDC = GetDC(hwnd);
	
	SwapBuffers(hDC);
}
void GLCtrl::DesactivateContext(){
	HWND hwnd = GetHWND();
	HDC hDC = GetDC(hwnd);
	
	wglMakeCurrent(NULL, NULL);
	ReleaseDC(hwnd, hDC);
}
GLCtrl::ContextLock::ContextLock(GLCtrl& ctrl) : parent(ctrl){
	HWND hwnd = parent.pane.GetHWND();
	GLCtrl::CreateContext();
	HDC hDC = GetDC(hwnd);
	wglMakeCurrent(hDC, s_openGLContext);
}
GLCtrl::ContextLock::~ContextLock(){
	HWND hwnd = parent.pane.GetHWND();
	HDC hDC = GetDC(hwnd);
	wglMakeCurrent(NULL, NULL);
	ReleaseDC(hwnd, hDC);
}
GLCtrl::ContextLockWithSwapBuffers::ContextLockWithSwapBuffers(GLCtrl& ctrl) : parent(ctrl){
	HWND hwnd = parent.pane.GetHWND();
	GLCtrl::CreateContext();
	HDC hDC = GetDC(hwnd);
	wglMakeCurrent(hDC, s_openGLContext);
}
GLCtrl::ContextLockWithSwapBuffers::~ContextLockWithSwapBuffers(){
	HWND hwnd = parent.pane.GetHWND();
	HDC hDC = GetDC(hwnd);
	
	SwapBuffers(hDC);
	wglMakeCurrent(NULL, NULL);
	ReleaseDC(hwnd, hDC);
}


XGLCtrl.cpp :
void GLCtrl::ActivateContext(){
	glXMakeCurrent(s_Display, win, s_GLXContext);
}
void GLCtrl::SwapBuffer(){
	glXSwapBuffers(s_Display, win);
}
void GLCtrl::DesactivateContext(){
	glXMakeCurrent(s_Display, None, NULL);
}
GLCtrl::ContextLock::ContextLock(GLCtrl& ctrl) : parent(ctrl){
	glXMakeCurrent(s_Display, parent.win, s_GLXContext);
}
GLCtrl::ContextLock::~ContextLock(){
	glXMakeCurrent(s_Display, None, NULL);
}
GLCtrl::ContextLockWithSwapBuffers::ContextLockWithSwapBuffers(GLCtrl& ctrl) : parent(ctrl){
	glXMakeCurrent(s_Display, parent.win, s_GLXContext);
}
GLCtrl::ContextLockWithSwapBuffers::~ContextLockWithSwapBuffers(){
	glXSwapBuffers(s_Display, parent.win);
	glXMakeCurrent(s_Display, None, NULL);
}


[Updated on: Thu, 03 September 2020 03:35]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Changing default standard from c++14 to c++17 (2020.2 Release)
Next Topic: RegExp
Goto Forum:
  


Current Time: Mon Apr 29 15:33:43 CEST 2024

Total time taken to generate the page: 0.02847 seconds