mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
GLCtrl: GTK partially fixed
git-svn-id: svn://ultimatepp.org/upp/trunk@12567 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
0ea41af5b2
commit
32ef80dfc6
10 changed files with 68 additions and 67 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Upp {
|
||||
|
||||
#define LLOG(x) // DLOG(x)
|
||||
#define LLOG(x) DLOG(x)
|
||||
|
||||
#define LTIMING(x) //TIMING(x)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ void GLCtrl::Init()
|
|||
{
|
||||
NoWantFocus();
|
||||
Transparent();
|
||||
#ifndef GUI_GTK
|
||||
pane.ctrl = this;
|
||||
Add(pane.SizePos());
|
||||
#endif
|
||||
restore_gl_viewport__ = SetCurrentViewport;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#ifdef GUI_X11
|
||||
#if defined(GUI_X11) || defined(GUI_GTK)
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
|
|
@ -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<int> 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<int> 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
|
||||
|
|
|
|||
|
|
@ -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<int> 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 |=
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue