GLCtrlGTK.diff

Zbigniew Rebacz, 02/28/2015 01:21 AM

Download (6.15 KB)

View differences:

GLCtrl/GLCtrl.cpp (kopia robocza)
25 25
	glLoadIdentity();
26 26
}
27 27

  
28
#ifndef GUI_GTK
29

  
30 28
Image GLCtrl::GLPane::MouseEvent(int event, Point p, int zdelta, dword keyflags)
31 29
{
32 30
	p = p - GetScreenView().TopLeft() + ctrl->GetScreenView().TopLeft();
33 31
	return ctrl->MouseEvent(event, p, zdelta, keyflags);
34 32
}
35 33

  
34
#ifndef GUI_GTK
35

  
36 36
Vector<int> GLCtrl::Pick(int x, int y)
37 37
{
38 38
	pane.ActivateContext();
GLCtrl/GLCtrl.h (kopia robocza)
25 25
#undef  Display
26 26
#endif
27 27

  
28
NAMESPACE_UPP
29

  
30 28
#ifdef GUI_GTK
31 29

  
32
class GLCtrl : public Ctrl {
33
public:
34
	virtual void Paint(Draw& w);
30
#include <gtk/gtkgl.h>
31
#include <gdk/gdkgl.h>
35 32

  
36
public:
37
	Callback WhenGLPaint;
33
#endif
38 34

  
39
	virtual void GLPaint();
40
	virtual void GLResize(int w, int h);
35
NAMESPACE_UPP
41 36

  
42
	void StdView();
43
};
44

  
45
#else
46

  
47 37
class GLCtrl : public Ctrl {
48 38
	typedef GLCtrl CLASSNAME;
49 39
	
......
64 54
		GLPicking() : _isPicking(false) {}
65 55
	};
66 56
	
67
#ifdef GUI_X11
57
#if defined(GUI_X11)
68 58
	class GLPane : public DHCtrl {
69 59
		friend class GLCtrl;
70 60
		
......
96 86
		
97 87
		void ActivateContext();
98 88
	};
99
#else
100
	struct GLPane : DHCtrl {
89
#elif defined(GUI_GTK)
90
	class GLPane : Ctrl {
101 91
		friend class GLCtrl;
102 92
		
103
		HDC    hDC;
104
		HGLRC  hRC;
93
	public:
94
		GLPane();
95
		~GLPane();
96
		
97
		virtual void Layout();
98
		virtual void Paint(Draw &);
99
		
100
		virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags);
101
		
102
	private:
103
		void InitGdkGLConfig();
104
	
105
		void InitGTKVariables();
106
		void ReleaseGTKVariables();
107
		
108
	private:
105 109
		GLCtrl *ctrl;
106 110
		
111
		GtkWindow *gtk;
112
		GdkWindow *win;
113
		
114
		GdkGLConfig *sGlconfig;
115
		
116
		GdkPixmap *pixmap;
117
		GdkGLDrawable *gldrawable;
118
		GdkGLContext *glcontext;
119
	};
120
	
121
#elif defined(GUI_WIN)
122
	class GLPane : DHCtrl {
123
		friend class GLCtrl;
124
		
107 125
	public:
108 126
		GLPane() : hDC(NULL), hRC(NULL) { NoWantFocus(); }
109 127
		~GLPane() { Destroy(); }
......
116 134
		void Destroy();
117 135
		
118 136
		void ActivateContext();
137
	
138
	private:
139
		HDC    hDC;
140
		HGLRC  hRC;
141
		GLCtrl *ctrl;
119 142
	};
120 143
#endif
121 144
	
......
166 189
	Vector<int> Pick(int x, int y);
167 190
};
168 191

  
169
#endif
170

  
171 192
END_UPP_NAMESPACE
172 193

  
173 194
#endif
GLCtrl/GtkGLCtrl.cpp (kopia robocza)
2 2

  
3 3
#ifdef GUI_GTK
4 4

  
5
#include <gtk/gtkgl.h>
6
#include <gdk/gdkgl.h>
7 5
#include <gdk/gdkglconfig.h>
8 6

  
9 7
NAMESPACE_UPP
10 8

  
11
GdkGLConfig *sGlconfig;
9
GLCtrl::GLPane::GLPane()
10
{
11
	ctrl = NULL;
12
	
13
	sGlconfig = NULL;
14
	
15
	pixmap = NULL;
16
	gldrawable = NULL;
17
	glcontext = NULL;
18
	
19
	gtk = NULL;
20
	win = NULL;
21
}
12 22

  
13
EXITBLOCK {
23
GLCtrl::GLPane::~GLPane()
24
{
14 25
	if(sGlconfig)
15
	    g_object_unref(G_OBJECT(sGlconfig));
26
		g_object_unref(G_OBJECT(sGlconfig));
27
	
28
	ReleaseGTKVariables();
16 29
}
17 30

  
18
void GLCtrl::GLPaint()
31
void GLCtrl::GLPane::Layout()
19 32
{
20
	WhenGLPaint();
33
	InitGdkGLConfig();
34
	
35
	ReleaseGTKVariables();
36
	InitGTKVariables();
21 37
}
22 38

  
23
void GLCtrl::Paint(Draw& w)
24
{
39
void GLCtrl::GLPane::Paint(Draw& w)
40
{	
25 41
	Size sz = GetSize();
26 42
	
27
	Ctrl *top = GetTopCtrl();
28
	if(!top)
29
		return;
43
	if(glcontext) {
44
		if(gdk_gl_drawable_gl_begin(gldrawable, glcontext)) {
45
			glViewport(0, 0, sz.cx, sz.cy);
46
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
47
			ctrl->GLPaint();
48
			if(gdk_gl_config_is_double_buffered(sGlconfig))
49
				gdk_gl_drawable_swap_buffers(gldrawable);
50
			else
51
				glFlush ();
52
			gdk_gl_drawable_gl_end(gldrawable);
30 53

  
31
	GtkWindow *gtk = top->gtk();
32
	GdkWindow *win = top->gdk();
54
			Rect r = GetScreenView() - GetTopCtrl()->GetScreenView().TopLeft();
55
			GtkWidget *widget = GTK_WIDGET(gtk);
56
			gdk_draw_drawable(win, widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
57
					          pixmap, 0, 0, r.left, r.top, r.GetWidth(), r.GetHeight());
58
		}
59
	}
60
}
33 61

  
34
	if(sz.cx <= 0 || sz.cy <= 0 || !win || !gtk)
62
void GLCtrl::GLPane::InitGdkGLConfig()
63
{
64
	if(sGlconfig)
35 65
		return;
66
	
67
	int glConfig = GDK_GL_MODE_RGB|GDK_GL_MODE_DEPTH|GDK_GL_MODE_SINGLE;
68
	if(ctrl) {
69
		
70
	}
71
	sGlconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)glConfig);
72
}
36 73

  
37
	ONCELOCK {
38
		sGlconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGB|GDK_GL_MODE_DEPTH|GDK_GL_MODE_SINGLE));
74
void GLCtrl::GLPane::InitGTKVariables()
75
{
76
	if(win == NULL && gtk == NULL) {
77
		Ctrl *top = GetTopCtrl();
78
		if (!top)
79
			return;	
80
		gtk = top->gtk();
81
		win = top->gdk();
39 82
	}
83
	
84
	Size sz = GetSize();
85
	pixmap = gdk_pixmap_new(win, sz.cx, sz.cy, -1);
86
	if (pixmap == NULL)
87
		return;
88
	
89
	gldrawable = GDK_GL_DRAWABLE(gdk_pixmap_set_gl_capability(pixmap, sGlconfig, NULL));
90
	if (gldrawable == NULL)
91
		return;
92
	
93
	glcontext = gdk_gl_context_new(gldrawable, NULL, FALSE, GDK_GL_RGBA_TYPE);
94
}
40 95

  
41
	GdkPixmap *pixmap = gdk_pixmap_new(win, sz.cx, sz.cy, -1);
42
	if(pixmap) {
43
		GdkGLDrawable *gldrawable = GDK_GL_DRAWABLE(gdk_pixmap_set_gl_capability(pixmap, sGlconfig, NULL));
44
		if(gldrawable) {
45
			GdkGLContext *glcontext = gdk_gl_context_new(gldrawable, NULL, FALSE, GDK_GL_RGBA_TYPE);
46
			if(glcontext) {
47
				if(gdk_gl_drawable_gl_begin(gldrawable, glcontext)) {
48
					glViewport(0, 0, sz.cx, sz.cy);
49
					glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
50
					GLPaint();
51
					glFlush ();
52
					gdk_gl_drawable_gl_end(gldrawable);
53

  
54
					Rect r = GetScreenView() - GetTopCtrl()->GetScreenView().TopLeft();
55
					GtkWidget *widget = GTK_WIDGET(gtk);
56
					gdk_draw_drawable(win, widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
57
					                  pixmap, 0, 0, r.left, r.top, r.GetWidth(), r.GetHeight());
58
				}
59
				g_object_unref(G_OBJECT(glcontext));
60
			}
61
			g_object_unref(G_OBJECT(gldrawable));
62
		}
96
void GLCtrl::GLPane::ReleaseGTKVariables()
97
{
98
	if(glcontext)
99
		gdk_gl_context_destroy(glcontext);
100
	if(gldrawable)
101
		g_object_unref(G_OBJECT(gldrawable));
102
	if(pixmap)
63 103
		g_object_unref(G_OBJECT(pixmap));
64
	}
65 104
}
66 105

  
67 106
END_UPP_NAMESPACE