GLCtrl: X11

git-svn-id: svn://ultimatepp.org/upp/trunk@12558 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-11-20 10:59:29 +00:00
parent 9233ad5533
commit a46d819b0d
9 changed files with 55 additions and 248 deletions

View file

@ -34,7 +34,7 @@ public:
class Routine {
public:
Routine(TimingInspector& stat, int& nesting)
: stat(stat), nesting(nesting) {
: nesting(nesting), stat(stat) {
start_time = tmGetTime();
nesting++;
}

View file

@ -10,6 +10,18 @@ Size GLCtrl::current_viewport;
extern void (*restore_gl_viewport__)(); // in Draw/DrawUtil.cpp
void GLCtrl::DoGLPaint()
{
glClearDepth(1);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glEnable(GL_MULTISAMPLE);
Size sz = GetSize();
current_viewport = sz;
SetCurrentViewport();
GLPaint();
}
void GLCtrl::Init()
{
NoWantFocus();
@ -50,22 +62,4 @@ void GLCtrl::StdView()
glLoadIdentity();
}
#ifndef GUI_GTK
Image GLCtrl::GLPane::MouseEvent(int event, Point p, int zdelta, dword keyflags)
{
p = p - GetScreenView().TopLeft() + ctrl->GetScreenView().TopLeft();
return ctrl->MouseEvent(event, p, zdelta, keyflags);
}
Vector<int> GLCtrl::Pick(int x, int y)
{
// pane.ActivateContext();
// return picking.Pick(x, y, THISBACK2(GLResize, GetSize().cx, GetSize().cy), THISBACK(GLPickingPaint));
Vector<int> h;
return h;
}
#endif
}

View file

@ -79,43 +79,24 @@ private:
friend class GLCtrl;
GLCtrl *ctrl;
GLXContext WindowContext;
// Ovverridden method to choose the correct visual
virtual XVisualInfo *CreateVisual(void);
// Overridden method for attribute setting
virtual void SetAttributes(unsigned long &ValueMask, XSetWindowAttributes &attr);
// Overridden method to create and destroy OpenGL context
virtual void AfterInit(bool Error);
virtual void BeforeTerminate(void);
// Overridden method to resize GL windows
virtual void Layout();
// Paint method - with graphic context
// Called from DHCtrl - Graphic context is *not* used
virtual void Paint(Draw &/*draw*/);
void DoGLPaint();
void SetAttributes(unsigned long &ValueMask, XSetWindowAttributes &winAttributes) override;
void Paint(Draw &draw) override;
public:
GLPane() : WindowContext(NULL) { NoWantFocus(); }
~GLPane();
virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags);
void ActivateContext();
GLPane() { NoWantFocus(); }
};
#else
struct GLPane : DHCtrl {
friend class GLCtrl;
// HDC hDC;
// HGLRC hRC;
GLCtrl *ctrl;
void DoGLPaint();
public:
GLPane()/* : hDC(NULL), hRC(NULL)*/ { NoWantFocus(); }
GLPane() { NoWantFocus(); }
virtual void State(int reason);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
@ -128,14 +109,17 @@ private:
};
#endif
GLPicking picking;
GLPane pane;
static int depthSize;
static int stencilSize;
static bool doubleBuffering;
static int numberOfSamples;
Vector<int> MakeAttributes();
void MakeGLContext();
void DoGLPaint();
static Size current_viewport; // because we need to set different viewports in drawing code
Ptr<Ctrl> mouseTarget = NULL;
@ -143,7 +127,6 @@ private:
protected:
// Called on paint events
virtual void GLPaint() { WhenGLPaint(); }
virtual void GLPickingPaint() {}
void Init();
@ -164,7 +147,6 @@ public:
GLCtrl() { Init(); }
void InitPickMatrix() { picking.InitPickMatrix(); }
void Refresh() { pane.Refresh(); }
Vector<int> Pick(int x, int y);

View file

@ -10,7 +10,6 @@ library((LINUX | BSD) & !X11 & !NOGTK) "gdkglext-x11-1.0 gtkglext-x11-1.0";
file
GLCtrl.h,
GLPicking.cpp,
Win32GLCtrl.cpp,
X11GLCtrl.cpp,
GtkGLCtrl.cpp,

View file

@ -1,65 +0,0 @@
#include "GLCtrl.h"
namespace Upp {
#if defined(GUI_X11) || defined(GUI_WIN32)
void GLCtrl::GLPicking::InitPickMatrix()
{
if (_isPicking)
{
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
gluPickMatrix(_pickPoint.x, viewport[3] - _pickPoint.y, 3, 3, viewport);
}
}
Vector<int> GLCtrl::GLPicking::Pick(int x, int y, Callback resizeCallback, Callback paintCallback)
{
GLuint buffer[_bufferSize];
_pickPoint = Point(x, y);
glSelectBuffer(_bufferSize, buffer);
glRenderMode(GL_SELECT);
_isPicking = true;
resizeCallback();
glInitNames();
paintCallback();
_isPicking = false;
resizeCallback();
// returning to normal rendering mode
int hits = glRenderMode(GL_RENDER);
if (hits == 0)
return Vector<int>();
else
return ParseHits(buffer, hits);
}
Vector<int> GLCtrl::GLPicking::ParseHits(GLuint *buffer, int hits)
{
GLuint *minPtr = buffer;
for (int i = 0; i < hits; i++)
{
if (*(buffer + 1) < *(minPtr + 1))
minPtr = buffer;
buffer += *buffer + 3;
}
Vector<int> result;
for (GLuint i = 0; i < *minPtr; i++)
result.Add(*(minPtr + 3 + i));
return result;
}
#endif
}

View file

@ -109,14 +109,7 @@ LRESULT GLCtrl::GLPane::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
BeginPaint(hwnd, &ps);
HDC hDC = ps.hdc;
wglMakeCurrent(hDC, s_openGLContext);
glClearDepth(1);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glEnable(GL_MULTISAMPLE);
Size sz = GetSize();
current_viewport = sz;
SetCurrentViewport();
ctrl->GLPaint();
DoPaint();
if(ctrl->doubleBuffering)
SwapBuffers(hDC);
else

View file

@ -4,54 +4,28 @@ namespace Upp {
#ifdef GUI_X11
/////////////////////////////////////////////////////////////////////////////////////////
// Destructor
GLCtrl::GLPane::~GLPane()
GLXContext s_GLXContext;
XVisualInfo *s_XVisualInfo;
void GLCtrl::MakeGLContext()
{
// If glx context is still there, destroy it
// That can happen on unclean exit
if(WindowContext)
{
glXDestroyContext( (XDisplay *)Xdisplay, WindowContext );
WindowContext = NULL;
ONCELOCK {
Vector<int> visual;
visual << GLX_RGBA << GLX_DEPTH_SIZE << depthSize;
if(stencilSize > 0)
visual << GLX_STENCIL_SIZE << stencilSize;
if(doubleBuffering)
visual << GLX_DOUBLEBUFFER;
if(numberOfSamples > 1)
visual << GLX_SAMPLE_BUFFERS_ARB << 1 << GLX_SAMPLES_ARB << numberOfSamples;
visual << None;
s_XVisualInfo = glXChooseVisual( (XDisplay*)Xdisplay, DefaultScreen(Xdisplay), visual);
if(!s_XVisualInfo)
return;
s_GLXContext = glXCreateContext((XDisplay *)Xdisplay, s_XVisualInfo, NULL, GL_TRUE);
}
} // END Destructor class GLCtrl::GLPane
}
/////////////////////////////////////////////////////////////////////////////////////////
// Ovverridden method to choose the correct visual
XVisualInfo *GLCtrl::GLPane::CreateVisual(void)
{
Vector<int> visual;
visual << GLX_RGBA << GLX_DEPTH_SIZE << ctrl->depthSize;
if( ctrl->stencilSize > 0 )
visual << GLX_STENCIL_SIZE << ctrl->stencilSize;
if( ctrl->doubleBuffering )
visual << GLX_DOUBLEBUFFER;
if(ctrl->numberOfSamples > 1 )
{
visual << GLX_SAMPLE_BUFFERS_ARB << 1 << GLX_SAMPLES_ARB << ctrl->numberOfSamples;
}
visual << None;
// Try to find a visual
XVisualInfo *visualInfo = NULL;
visualInfo = glXChooseVisual( (XDisplay*)Xdisplay, DefaultScreen(Xdisplay), visual );
if( visualInfo == NULL )
{
SetError(true);
SetErrorMessage("GLCtrl::GLPane : Impossible to find a suitable visual.");
}
return visualInfo;
} // END GLCtrl::GLPane::CreateVisual()
/////////////////////////////////////////////////////////////////////////////////////////
// Overridden method for attribute setting
void GLCtrl::GLPane::SetAttributes(unsigned long &ValueMask, XSetWindowAttributes &winAttributes)
{
ValueMask |=
@ -62,93 +36,24 @@ void GLCtrl::GLPane::SetAttributes(unsigned long &ValueMask, XSetWindowAttribute
winAttributes.border_pixel = 0;
winAttributes.event_mask = ExposureMask;
winAttributes.save_under = XFalse;
} // END GLCtrl::GLPane::SetAttributes()
/////////////////////////////////////////////////////////////////////////////////////////
// Activates current OpenGL context
void GLCtrl::GLPane::ActivateContext()
{
if (WindowContext != NULL && glXGetCurrentContext() != WindowContext)
glXMakeCurrent( (XDisplay*)Xdisplay, GetWindow(), WindowContext );
}
/////////////////////////////////////////////////////////////////////////////////////////
// Overridden method to create OpenGL context
void GLCtrl::GLPane::AfterInit(bool Error)
{
// Gets the activw XVisualInfo
XVisualInfo visualInfo = GetVisualInfo();
// Create an OpenGL rendering context
WindowContext = glXCreateContext
(
(XDisplay *)Xdisplay,
&visualInfo,
NULL, // No sharing of display lists
GL_TRUE // Direct rendering if possible
);
if( WindowContext == NULL )
{
SetErrorMessage("GLCtrl::GLPane : Error creating GLX context.");
SetError(true);
}
// Activate the created glxwindow
glXMakeCurrent( (XDisplay*)Xdisplay, GetWindow(), WindowContext );
// Call user init function
ctrl->GLInit();
// Calls resize and paint functions
ctrl->GLResize( GetSize().cx, GetSize().cy );
ctrl->GLPaint();
} // END GLCtrl::GLPane::AfterInit()
/////////////////////////////////////////////////////////////////////////////////////////
// Overridden method to destroy OpenGL context
void GLCtrl::GLPane::BeforeTerminate(void)
{
// Calls user terminate function
ctrl->GLDone();
// Resets context and destroys it
glXMakeCurrent( (XDisplay*)Xdisplay, None, NULL );
glXDestroyContext( (XDisplay *)Xdisplay, WindowContext );
WindowContext = NULL;
} // END GLCtrl::GLPane::BeforeTerminate()
/////////////////////////////////////////////////////////////////////////////////////////
// Overridden method to resize GL windows
void GLCtrl::GLPane::Layout()
{
// Activates the current context
ActivateContext();
if (glXGetCurrentContext() == NULL)
return;
// Calls user resize hook
ctrl->GLResize(GetSize().cx, GetSize().cy);
} // END GLCtrl::GLPane::Resize()
/////////////////////////////////////////////////////////////////////////////////////////
// Paint method - with graphic context
void GLCtrl::GLPane::Paint(Draw &draw)
{
// Activates the current context
ActivateContext();
if(!s_GLXContext)
return;
// Calls user paint hook
ctrl->GLPaint();
glXMakeCurrent( (XDisplay*)Xdisplay, GetWindow(), s_GLXContext);
ctrl->DoGLPaint();
// Swap buffers or flush as needed
if( ctrl->doubleBuffering )
glXSwapBuffers( (XDisplay*)Xdisplay, GetWindow() ); // Buffer swap does implicit glFlush
glXSwapBuffers((XDisplay*)Xdisplay, GetWindow());
else
glFlush();
} // END GLCtrl::GLPane::Paint()
glXMakeCurrent( (XDisplay*)Xdisplay, GetWindow(), NULL);
}
#endif

View file

@ -273,7 +273,7 @@ void BufferPainter::RenderImage(double width, const Image& image, const Xform2D&
return;
PainterImageSpanData f(flags, transsrc * pathattr.mtx, image, co, imagecache);
RenderPath(width, [&](One<SpanSource>& s) {
PainterImageSpan& ss = s.Create<PainterImageSpan>(f);
s.Create<PainterImageSpan>(f);
}, RGBAZero());
}

View file

@ -384,7 +384,6 @@ void BufferPainter::FinishPathJob()
int y = N * co.Next() + miny;
if(y > maxy)
break;
int e = min(y + N - 1, maxy);
fill(y, min(y + N - 1, maxy));
#endif
}