GLCtrl: refactoring

git-svn-id: svn://ultimatepp.org/upp/trunk@12387 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-10-22 08:40:28 +00:00
parent 0f0c9fbbb7
commit a1aa7471c6
4 changed files with 64 additions and 38 deletions

View file

@ -582,4 +582,11 @@ void SetRenderGlyph(Image (*f)(int cx, int x, Font font, int chr, int py, int pc
render_glyph = f;
}
// this is nasty solution: We need to be able to restore GL viewport in GLTextureDraw for GLCtrl
// Draw is package used by both GLDraw and GLCtrl, so let us hide a little global function
// pointer here...
void (*restore_gl_viewport__)() = [] {};
}

View file

@ -2,6 +2,23 @@
namespace Upp {
int GLCtrl::depthSize = 24;
int GLCtrl::stencilSize = 8;
bool GLCtrl::doubleBuffering = true;
int GLCtrl::numberOfSamples = 1;
Size GLCtrl::current_viewport;
extern void (*restore_gl_viewport__)(); // in Draw/DrawUtil.cpp
void GLCtrl::Init()
{
NoWantFocus();
Transparent();
pane.ctrl = this;
Add(pane.SizePos());
restore_gl_viewport__ = SetCurrentViewport;
}
Image GLCtrl::MouseEvent(int event, Point p, int zdelta, dword keyflags)
{
if(mouseTarget) {
@ -10,9 +27,9 @@ Image GLCtrl::MouseEvent(int event, Point p, int zdelta, dword keyflags)
return Ctrl::MouseEvent(event, p, zdelta, keyflags);
}
void GLCtrl::GLResize(int w, int h)
void GLCtrl::SetCurrentViewport()
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glViewport(0, 0, (GLsizei)current_viewport.cx, (GLsizei)current_viewport.cy);
}
void GLCtrl::StdView()
@ -44,7 +61,9 @@ Image GLCtrl::GLPane::MouseEvent(int event, Point p, int zdelta, dword keyflags)
Vector<int> GLCtrl::Pick(int x, int y)
{
// pane.ActivateContext();
return picking.Pick(x, y, THISBACK2(GLResize, GetSize().cx, GetSize().cy), THISBACK(GLPickingPaint));
// return picking.Pick(x, y, THISBACK2(GLResize, GetSize().cx, GetSize().cy), THISBACK(GLPickingPaint));
Vector<int> h;
return h;
}
#endif

View file

@ -45,7 +45,6 @@ public:
Event<> WhenGLPaint;
virtual void GLPaint();
virtual void GLResize(int w, int h);
void StdView();
};
@ -131,55 +130,55 @@ private:
GLPicking picking;
GLPane pane;
int depthSize;
int stencilSize;
bool doubleBuffering;
bool multiSampleBuffering;
int numberOfSamples;
Ctrl *mouseTarget = NULL;
static int depthSize;
static int stencilSize;
static bool doubleBuffering;
static int numberOfSamples;
static Size current_viewport; // because we need to set different viewports in drawing code
Ptr<Ctrl> mouseTarget = NULL;
protected:
// Called after succesful OpenGL initialization
virtual void GLInit() {}
// Called just before OpenGL termination
virtual void GLDone() {}
// Called on resize events, defaults to setting proper view-port
virtual void GLResize(int w, int h);
// Called on paint events
virtual void GLPaint() { WhenGLPaint(); }
virtual void GLPickingPaint() {}
void Init();
public:
Callback WhenGLPaint;
static void SetDepthBits(int n) { depthSize = n; }
static void SetStencilBits(int n) { stencilSize = n; }
static void SetDoubleBuffering(bool b = true) { doubleBuffering = b; }
static void SetMSAA(int n = 4) { numberOfSamples = n; }
static Size CurrentViewport() { return current_viewport; }
static void SetCurrentViewport(); // intended to restore viewport after changing it in e.g. TextureDraw
GLCtrl& DepthBits(int n) { depthSize = n; return *this; }
GLCtrl& StencilBits(int n) { stencilSize = n; return *this; }
GLCtrl& DoubleBuffering(bool b = true) { doubleBuffering = b; return *this; }
GLCtrl& MSAA(int n = 4) { numberOfSamples = n; return *this; }
GLCtrl& RedirectMouse(Ctrl *target) { mouseTarget = target; return *this; }
GLCtrl(int depthsize = 24, int stencilsize = 8, bool doublebuffer = true,
bool multisamplebuffering = false, int numberofsamples = 0)
: depthSize(depthsize),
stencilSize(stencilsize),
doubleBuffering(doublebuffer),
numberOfSamples(numberofsamples)
{
NoWantFocus();
Transparent();
pane.ctrl = this;
Add(pane.SizePos());
}
GLCtrl() { Init(); }
void StdView();
void InitPickMatrix() { picking.InitPickMatrix(); }
void Refresh() { pane.Refresh(); }
Vector<int> Pick(int x, int y);
// deprecated (these settings are now static, as we have just single context)
GLCtrl& DepthBits(int n) { depthSize = n; return *this; }
GLCtrl& StencilBits(int n) { stencilSize = n; return *this; }
GLCtrl& DoubleBuffering(bool b = true) { doubleBuffering = b; return *this; }
GLCtrl& MSAA(int n = 4) { numberOfSamples = n; return *this; }
GLCtrl(int depthsize, int stencilsize = 8, bool doublebuffer = true,
bool multisamplebuffering = false, int numberofsamples = 0)
{ Init(); DepthBits(depthsize).StencilBits(stencilsize).DoubleBuffering(doublebuffer).MSAA(numberofsamples); }
// deprecated (fixed pipeline is so out of fashion...)
void StdView();
};
#endif

View file

@ -150,7 +150,8 @@ LRESULT GLCtrl::GLPane::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glEnable(GL_MULTISAMPLE);
Size sz = GetSize();
glViewport(0, 0, (GLsizei)sz.cx, (GLsizei)sz.cy);
current_viewport = sz;
SetCurrentViewport();
ctrl->GLPaint();
if(ctrl->doubleBuffering)
SwapBuffers(hDC);