diff --git a/uppsrc/Core/Profile.h b/uppsrc/Core/Profile.h index 25af5ed00..cb4ece030 100644 --- a/uppsrc/Core/Profile.h +++ b/uppsrc/Core/Profile.h @@ -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++; } diff --git a/uppsrc/GLCtrl/GLCtrl.cpp b/uppsrc/GLCtrl/GLCtrl.cpp index 5eb0eb5c7..04e91da4c 100644 --- a/uppsrc/GLCtrl/GLCtrl.cpp +++ b/uppsrc/GLCtrl/GLCtrl.cpp @@ -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 GLCtrl::Pick(int x, int y) -{ -// pane.ActivateContext(); -// return picking.Pick(x, y, THISBACK2(GLResize, GetSize().cx, GetSize().cy), THISBACK(GLPickingPaint)); - Vector h; - return h; -} - -#endif - } diff --git a/uppsrc/GLCtrl/GLCtrl.h b/uppsrc/GLCtrl/GLCtrl.h index c46f08312..ed3d2985a 100644 --- a/uppsrc/GLCtrl/GLCtrl.h +++ b/uppsrc/GLCtrl/GLCtrl.h @@ -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 MakeAttributes(); + void MakeGLContext(); + void DoGLPaint(); + static Size current_viewport; // because we need to set different viewports in drawing code Ptr 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 Pick(int x, int y); diff --git a/uppsrc/GLCtrl/GLCtrl.upp b/uppsrc/GLCtrl/GLCtrl.upp index 5bfcf200a..fd8b40a67 100644 --- a/uppsrc/GLCtrl/GLCtrl.upp +++ b/uppsrc/GLCtrl/GLCtrl.upp @@ -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, diff --git a/uppsrc/GLCtrl/GLPicking.cpp b/uppsrc/GLCtrl/GLPicking.cpp deleted file mode 100644 index 3cf2f0f6a..000000000 --- a/uppsrc/GLCtrl/GLPicking.cpp +++ /dev/null @@ -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 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(); - else - return ParseHits(buffer, hits); -} - -Vector 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 result; - for (GLuint i = 0; i < *minPtr; i++) - result.Add(*(minPtr + 3 + i)); - - return result; -} - -#endif - -} diff --git a/uppsrc/GLCtrl/Win32GLCtrl.cpp b/uppsrc/GLCtrl/Win32GLCtrl.cpp index bfb36f2eb..62655d43b 100644 --- a/uppsrc/GLCtrl/Win32GLCtrl.cpp +++ b/uppsrc/GLCtrl/Win32GLCtrl.cpp @@ -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 diff --git a/uppsrc/GLCtrl/X11GLCtrl.cpp b/uppsrc/GLCtrl/X11GLCtrl.cpp index 46079b838..d213b8f61 100644 --- a/uppsrc/GLCtrl/X11GLCtrl.cpp +++ b/uppsrc/GLCtrl/X11GLCtrl.cpp @@ -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 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 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 diff --git a/uppsrc/Painter/Image.cpp b/uppsrc/Painter/Image.cpp index b7586be7d..cbf675f4c 100644 --- a/uppsrc/Painter/Image.cpp +++ b/uppsrc/Painter/Image.cpp @@ -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& s) { - PainterImageSpan& ss = s.Create(f); + s.Create(f); }, RGBAZero()); } diff --git a/uppsrc/Painter/Render.cpp b/uppsrc/Painter/Render.cpp index c9f24aed2..4cc9167ae 100644 --- a/uppsrc/Painter/Render.cpp +++ b/uppsrc/Painter/Render.cpp @@ -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 }