Home » U++ Library support » U++ Library : Other (not classified elsewhere) » [Proposal] Adding a GLLock struct to GLCtrl
[Proposal] Adding a GLLock struct to GLCtrl [message #54712] |
Wed, 02 September 2020 18:55  |
 |
Xemuth
Messages: 387 Registered: August 2018 Location: France
|
Senior Member |
|
|
Hello, with the new version of Glew I moved my application to GLCtrl.
However, in many part of my application, I need to get the OpenGL context to perform many actions. The actual way of executing something in the good OpenGL Context is to call ExecuteGL(Event<> paint, bool swap_buffers). Which force me to surround my code arround this function. It work but not convenient and for some part it block me and force me to change my architecture.
To allow more flexibility in the way we work with GLCtrl I propose to add a structure to GLCtrl named GLLock, which can be invoqued to get the OpenGL context and release it when the object got destroyed :
//class GLCtrl : public Ctrl{
public:
struct GLLock{
private:
HWND hwnd;
HDC hDC;
public:
GLLock(GLCtrl& ctrl);
~GLLock();
};
//};
Win32GLCtrl.cpp :
GLCtrl::GLLock::GLLock(GLCtrl& ctrl){
hwnd = ctrl.pane.GetHWND();
GLCtrl::CreateContext();
hDC = GetDC(hwnd);
wglMakeCurrent(hDC, s_openGLContext);
}
GLCtrl::GLLock::~GLLock(){
wglMakeCurrent(NULL, NULL);
ReleaseDC(hwnd, hDC);
}
XGLCtrl.cpp:
GLCtrl::GLLock::GLLock(GLCtrl& ctrl){
glXMakeCurrent(s_Display, ctrl.win, s_GLXContext);
}
GLCtrl::GLLock::~GLLock(){
glXMakeCurrent(s_Display, None, NULL);
}
Here is a trivial exemple of how to use it :
bool LoadSTL(){ //This function is used when a button is pressed
try {
GLCtrl::GLLock __(canvas); //Canvas is the GLCtrl object
//Shaders Stuff
//OpenGL buffer filling and loading
//Definition of draw
return true;
} catch (Exc e) {
Exclamation(DeQtf(e));
}
return false;
}
|
|
|
 |
|
[Proposal] Adding a GLLock struct to GLCtrl
By: Xemuth on Wed, 02 September 2020 18:55
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Klugier on Thu, 03 September 2020 00:37
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Xemuth on Thu, 03 September 2020 02:30
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: mirek on Thu, 03 September 2020 09:51
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Xemuth on Thu, 03 September 2020 17:21
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Klugier on Thu, 03 September 2020 23:46
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Xemuth on Fri, 04 September 2020 16:34
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Klugier on Fri, 04 September 2020 22:28
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Xemuth on Sat, 05 September 2020 15:39
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: koldo on Wed, 09 September 2020 08:15
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: koldo on Wed, 09 September 2020 20:41
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Klugier on Wed, 09 September 2020 21:25
|
 |
|
Re: [Proposal] Adding a GLLock struct to GLCtrl
By: Xemuth on Thu, 10 September 2020 16:52
|
Goto Forum:
Current Time: Mon Apr 28 16:43:54 CEST 2025
Total time taken to generate the page: 0.00941 seconds
|