diff --git a/uppsrc/CtrlCore/X11DHCtrl.cpp b/uppsrc/CtrlCore/X11DHCtrl.cpp index 78dac971e..dea79bac7 100644 --- a/uppsrc/CtrlCore/X11DHCtrl.cpp +++ b/uppsrc/CtrlCore/X11DHCtrl.cpp @@ -159,13 +159,14 @@ bool DHCtrl::Init() XChangeWindowAttributes(Xdisplay, hwnd, ValueMask, &winAttributes); } +/* // Frees VisualInfo if (UserVisualInfo) { XFree( (char *)UserVisualInfo); UserVisualInfo = 0; } - +*/ // If problem creating window, error if(!hwnd) { diff --git a/uppsrc/CtrlCore/X11Proc.cpp b/uppsrc/CtrlCore/X11Proc.cpp index 6566f9427..d9b0c945f 100644 --- a/uppsrc/CtrlCore/X11Proc.cpp +++ b/uppsrc/CtrlCore/X11Proc.cpp @@ -4,7 +4,7 @@ namespace Upp { -#define LLOG(x) // DLOG(x) +#define LLOG(x) DLOG(x) #define LTIMING(x) //TIMING(x) diff --git a/uppsrc/GLCtrl/GLCtrl.cpp b/uppsrc/GLCtrl/GLCtrl.cpp index 379e874fa..f017fc7f9 100644 --- a/uppsrc/GLCtrl/GLCtrl.cpp +++ b/uppsrc/GLCtrl/GLCtrl.cpp @@ -26,8 +26,10 @@ void GLCtrl::Init() { NoWantFocus(); Transparent(); +#ifndef GUI_GTK pane.ctrl = this; Add(pane.SizePos()); +#endif restore_gl_viewport__ = SetCurrentViewport; } diff --git a/uppsrc/GLCtrl/GLCtrl.h b/uppsrc/GLCtrl/GLCtrl.h index ed3d2985a..20119e1ab 100644 --- a/uppsrc/GLCtrl/GLCtrl.h +++ b/uppsrc/GLCtrl/GLCtrl.h @@ -20,7 +20,7 @@ #include #include -#ifdef GUI_X11 +#if defined(GUI_X11) || defined(GUI_GTK) #include @@ -35,27 +35,15 @@ namespace Upp { void InitializeGlew(); -#ifdef GUI_GTK - -class GLCtrl : public Ctrl { -public: - virtual void Paint(Draw& w); - -public: - Event<> WhenGLPaint; - - virtual void GLPaint(); - - void StdView(); -}; - -#else class GLCtrl : public Ctrl { typedef GLCtrl CLASSNAME; public: virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags); +#ifdef GUI_GTK + virtual void Paint(Draw& w); +#endif private: class GLPicking @@ -83,11 +71,14 @@ private: void DoGLPaint(); void SetAttributes(unsigned long &ValueMask, XSetWindowAttributes &winAttributes) override; void Paint(Draw &draw) override; + XVisualInfo *CreateVisual() override; + virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags); public: GLPane() { NoWantFocus(); } }; -#else +#elif defined(PLATFORM_WIN32) + struct GLPane : DHCtrl { friend class GLCtrl; @@ -108,16 +99,17 @@ private: void ActivateContext(); }; #endif - + +#ifndef GUI_GTK GLPane pane; +#endif static int depthSize; static int stencilSize; static bool doubleBuffering; static int numberOfSamples; - Vector MakeAttributes(); - void MakeGLContext(); + static void MakeGLContext(); void DoGLPaint(); static Size current_viewport; // because we need to set different viewports in drawing code @@ -143,13 +135,13 @@ public: static Size CurrentViewport() { return current_viewport; } static void SetCurrentViewport(); // intended to restore viewport after changing it in e.g. TextureDraw - GLCtrl& RedirectMouse(Ctrl *target) { mouseTarget = target; return *this; } + GLCtrl& RedirectMouse(Ctrl *target) { mouseTarget = target; return *this; } GLCtrl() { Init(); } - void Refresh() { pane.Refresh(); } - - Vector Pick(int x, int y); +#ifndef GUI_GTK + void Refresh() { pane.Refresh(); } +#endif // deprecated (these settings are now static, as we have just single context) GLCtrl& DepthBits(int n) { depthSize = n; return *this; } @@ -165,8 +157,6 @@ public: void StdView(); }; -#endif - } #endif diff --git a/uppsrc/GLCtrl/GtkGLCtrl.cpp b/uppsrc/GLCtrl/GtkGLCtrl.cpp index 8d393898d..aa8d6d0fa 100644 --- a/uppsrc/GLCtrl/GtkGLCtrl.cpp +++ b/uppsrc/GLCtrl/GtkGLCtrl.cpp @@ -10,20 +10,11 @@ namespace Upp { void InitializeGlew() {} -GdkGLConfig *sGlconfig; - -EXITBLOCK { - if(sGlconfig) - g_object_unref(G_OBJECT(sGlconfig)); -} - -void GLCtrl::GLPaint() -{ - WhenGLPaint(); -} - void GLCtrl::Paint(Draw& w) { + static GdkGLConfig *s_GdkGLConfig; + static GdkGLContext *s_GdkGLContext; + Size sz = GetSize(); Ctrl *top = GetTopCtrl(); @@ -37,20 +28,37 @@ void GLCtrl::Paint(Draw& w) return; ONCELOCK { - sGlconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGB|GDK_GL_MODE_DEPTH|GDK_GL_MODE_SINGLE)); + int samples = numberOfSamples; + do { + Vector attr; + attr << GLX_RGBA << GLX_DEPTH_SIZE << depthSize + << GLX_STENCIL_SIZE << stencilSize; + // if(doubleBuffering) + // attr << GLX_DOUBLEBUFFER; + if(samples > 1) + attr << GLX_SAMPLE_BUFFERS_ARB << 1 << GLX_SAMPLES_ARB << samples; + + attr << 0; + s_GdkGLConfig = gdk_gl_config_new(attr); + samples >>= 1; + } + while(s_GdkGLConfig == NULL && samples > 0); } GdkPixmap *pixmap = gdk_pixmap_new(win, sz.cx, sz.cy, -1); if(pixmap) { - GdkGLDrawable *gldrawable = GDK_GL_DRAWABLE(gdk_pixmap_set_gl_capability(pixmap, sGlconfig, NULL)); + GdkGLDrawable *gldrawable = GDK_GL_DRAWABLE(gdk_pixmap_set_gl_capability(pixmap, s_GdkGLConfig, NULL)); if(gldrawable) { - GdkGLContext *glcontext = gdk_gl_context_new(gldrawable, NULL, TRUE, GDK_GL_RGBA_TYPE); - if(glcontext) { - if(gdk_gl_drawable_gl_begin(gldrawable, glcontext)) { - glViewport(0, 0, sz.cx, sz.cy); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - GLPaint(); - glFlush (); + ONCELOCK { + s_GdkGLContext = gdk_gl_context_new(gldrawable, NULL, TRUE, GDK_GL_RGBA_TYPE); + } + if(s_GdkGLContext) { + if(gdk_gl_drawable_gl_begin(gldrawable, s_GdkGLContext)) { + ONCELOCK { + glewInit(); + } + DoGLPaint(); + glFlush(); gdk_gl_drawable_gl_end(gldrawable); Rect r = GetScreenView() - GetTopCtrl()->GetScreenView().TopLeft(); @@ -58,7 +66,6 @@ void GLCtrl::Paint(Draw& w) gdk_draw_drawable(win, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], pixmap, 0, 0, r.left, r.top, r.GetWidth(), r.GetHeight()); } - g_object_unref(G_OBJECT(glcontext)); } g_object_unref(G_OBJECT(gldrawable)); } diff --git a/uppsrc/GLCtrl/X11GLCtrl.cpp b/uppsrc/GLCtrl/X11GLCtrl.cpp index d213b8f61..0b58067db 100644 --- a/uppsrc/GLCtrl/X11GLCtrl.cpp +++ b/uppsrc/GLCtrl/X11GLCtrl.cpp @@ -26,6 +26,12 @@ void GLCtrl::MakeGLContext() } } +XVisualInfo *GLCtrl::GLPane::CreateVisual() +{ + MakeGLContext(); + return s_XVisualInfo; +} + void GLCtrl::GLPane::SetAttributes(unsigned long &ValueMask, XSetWindowAttributes &winAttributes) { ValueMask |= diff --git a/uppsrc/GLDraw/GLTexture.cpp b/uppsrc/GLDraw/GLTexture.cpp index da34efc3a..b387011ae 100644 --- a/uppsrc/GLDraw/GLTexture.cpp +++ b/uppsrc/GLDraw/GLTexture.cpp @@ -79,23 +79,23 @@ const GLVertexData& GLRectMesh() void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, int textureid, Size tsz, const Rect& src) { static GLCode program(R"( - #version 330 core +// #version 330 core uniform vec2 offset; uniform vec2 scale; uniform vec2 toffset; uniform vec2 tscale; - in vec2 aPos; - out vec2 tPos; + attribute vec2 aPos; + varying vec2 tPos; void main() { gl_Position = vec4(scale * aPos + offset, 0, 1); tPos = tscale * aPos + toffset; } )", R"( - #version 330 core - in vec2 tPos; +// #version 330 core + varying vec2 tPos; uniform float alpha; uniform sampler2D s_texture; void main() diff --git a/uppsrc/GLDraw/Line.cpp b/uppsrc/GLDraw/Line.cpp index 07a3c3ca3..908a55bc1 100644 --- a/uppsrc/GLDraw/Line.cpp +++ b/uppsrc/GLDraw/Line.cpp @@ -9,8 +9,7 @@ void GLDrawPolylines(const GLContext2D& dd, Pointf at, const GLVertexData& mesh, return; static GLCode program(R"( - #version 330 core - in vec4 pos; + attribute vec4 pos; uniform vec2 offset; uniform vec2 scale; uniform vec2 scale2; @@ -22,7 +21,6 @@ void GLDrawPolylines(const GLContext2D& dd, Pointf at, const GLVertexData& mesh, gl_Position = vec4(p + scale * width * normalize(vec2(-v.y, v.x)), 0, 1); } )", R"( - #version 330 core uniform vec4 color; void main() { diff --git a/uppsrc/GLDraw/Polygon.cpp b/uppsrc/GLDraw/Polygon.cpp index 00ec0c21e..a3705e26a 100644 --- a/uppsrc/GLDraw/Polygon.cpp +++ b/uppsrc/GLDraw/Polygon.cpp @@ -5,8 +5,7 @@ namespace Upp { GLCode& GLSimpleCode() { static GLCode program(R"( - #version 330 core - in vec2 aPos; + attribute vec2 aPos; uniform vec2 offset; uniform vec2 scale; void main() @@ -14,7 +13,6 @@ GLCode& GLSimpleCode() gl_Position = vec4(scale * aPos + offset, 0, 1); } )", R"( - #version 330 core uniform vec4 color; void main() { diff --git a/uppsrc/GLDraw/Triangles.cpp b/uppsrc/GLDraw/Triangles.cpp index 5278c8abc..9c2d5af55 100644 --- a/uppsrc/GLDraw/Triangles.cpp +++ b/uppsrc/GLDraw/Triangles.cpp @@ -8,20 +8,19 @@ void GLTriangles::Draw(const GLContext2D& dd) return; static GLCode program(R"( - #version 330 core - in vec3 p; - in vec3 c; + #version 130 + attribute vec3 p; + attribute vec3 c; uniform vec2 offset; uniform vec2 scale; - out vec4 v_color; + varying vec4 v_color; void main() { gl_Position = vec4(scale * p.xy + offset, 0, 1); v_color = vec4(1/255.0 * c.rgb, p.z); } )", R"( - #version 330 core - in vec4 v_color; + varying vec4 v_color; void main() { gl_FragColor = v_color;