• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2008-2013, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * This header defines BGLView, the base class making up
6  * the Haiku GL Kit.
7  *
8  */
9 #ifndef BGLVIEW_H
10 #define BGLVIEW_H
11 
12 
13 #include <GL/gl.h>
14 
15 #define BGL_RGB			0
16 #define BGL_INDEX		1
17 #define BGL_SINGLE		0
18 #define BGL_DOUBLE		2
19 #define BGL_DIRECT		0
20 #define BGL_INDIRECT	4
21 #define BGL_ACCUM		8
22 #define BGL_ALPHA		16
23 #define BGL_DEPTH		32
24 #define BGL_OVERLAY		64
25 #define BGL_UNDERLAY	128
26 #define BGL_STENCIL		512
27 
28 #ifdef __cplusplus
29 
30 #include <AppKit.h>
31 #include <Bitmap.h>
32 #include <DirectWindow.h>
33 #include <View.h>
34 #include <Window.h>
35 #include <WindowScreen.h>
36 
37 
38 struct glview_direct_info;
39 class BGLRenderer;
40 class GLRendererRoster;
41 
42 class BGLView : public BView {
43 public:
44 							BGLView(BRect rect, const char* name,
45 								ulong resizingMode, ulong mode,
46 								ulong options);
47 	virtual					~BGLView();
48 
49 			void			LockGL();
50 			void			UnlockGL();
51 			void			SwapBuffers();
52 			void			SwapBuffers(bool vSync);
53 
54 			BView*			EmbeddedView(); // deprecated, returns NULL
55 			void*			GetGLProcAddress(const char* procName);
56 
57 			status_t		CopyPixelsOut(BPoint source, BBitmap *dest);
58 			status_t		CopyPixelsIn(BBitmap *source, BPoint dest);
59 
60 	// Mesa's GLenum is uint where Be's ones was ulong!
61 	virtual	void			ErrorCallback(unsigned long errorCode);
62 
63 	virtual void			Draw(BRect updateRect);
64 	virtual void			AttachedToWindow();
65 	virtual void			AllAttached();
66 	virtual void			DetachedFromWindow();
67 	virtual void			AllDetached();
68 
69 	virtual void			FrameResized(float newWidth, float newHeight);
70 	virtual status_t		Perform(perform_code d, void *arg);
71 
72 	virtual status_t		Archive(BMessage *data, bool deep = true) const;
73 
74 	virtual void			MessageReceived(BMessage *message);
75 	virtual void			SetResizingMode(uint32 mode);
76 
77 	virtual void			Show();
78 	virtual void			Hide();
79 
80 	virtual BHandler*		ResolveSpecifier(BMessage *msg, int32 index,
81 								BMessage *specifier, int32 form,
82 								const char *property);
83 	virtual status_t		GetSupportedSuites(BMessage *data);
84 
85 			void			DirectConnected(direct_buffer_info *info);
86 			void			EnableDirectMode(bool enabled);
87 
getGC()88 			void*			getGC()	{ return fGc; } // ???
89 
90 	virtual void			GetPreferredSize(float* width, float* height);
91 
92 private:
93 
94 	virtual void			_ReservedGLView1();
95 	virtual void			_ReservedGLView2();
96 	virtual void			_ReservedGLView3();
97 	virtual void			_ReservedGLView4();
98 	virtual void			_ReservedGLView5();
99 	virtual void			_ReservedGLView6();
100 	virtual void			_ReservedGLView7();
101 	virtual void			_ReservedGLView8();
102 
103 							BGLView(const BGLView &);
104 							BGLView &operator=(const BGLView &);
105 
106 			void			_DitherFront();
107 			bool			_ConfirmDither();
108 			void			_Draw(BRect rect);
109 			void			_CallDirectConnected();
110 
111 			void*			fGc;
112 			uint32			fOptions;
113 			uint32			fDitherCount;
114 			BLocker			fDrawLock;
115 			BLocker			fDisplayLock;
116 			glview_direct_info* fClipInfo;
117 
118 			BGLRenderer*	fRenderer;
119 			GLRendererRoster* fRoster;
120 
121 			BBitmap*		fDitherMap;
122 			BRect			fBounds;
123 			int16*			fErrorBuffer[2];
124 			uint64			_reserved[8];
125 
126 			void			_LockDraw();
127 			void			_UnlockDraw();
128 
129 // BeOS compatibility
130 private:
131 							BGLView(BRect rect, char* name,
132 								ulong resizingMode, ulong mode,
133 								ulong options);
134 };
135 
136 
137 class BGLScreen : public BWindowScreen {
138 public:
139 							BGLScreen(char* name,
140 								ulong screenMode, ulong options,
141 								status_t *error, bool debug=false);
142 							~BGLScreen();
143 
144 			void			LockGL();
145 			void			UnlockGL();
146 			void			SwapBuffers();
147 							// Mesa's GLenum is uint where Be's ones was ulong!
148 	virtual	void			ErrorCallback(unsigned long errorCode);
149 
150 	virtual void			ScreenConnected(bool connected);
151 	virtual void			FrameResized(float width, float height);
152 	virtual status_t		Perform(perform_code code, void *arg);
153 
154 	virtual status_t		Archive(BMessage *data, bool deep = true) const;
155 	virtual void			MessageReceived(BMessage *message);
156 
157 	virtual void			Show();
158 	virtual void			Hide();
159 
160 	virtual BHandler*		ResolveSpecifier(BMessage *message,
161 								int32 index,
162 								BMessage *specifier,
163 								int32 form,
164 								const char *property);
165 	virtual status_t		GetSupportedSuites(BMessage *data);
166 
167 private:
168 
169 	virtual void			_ReservedGLScreen1();
170 	virtual void			_ReservedGLScreen2();
171 	virtual void			_ReservedGLScreen3();
172 	virtual void			_ReservedGLScreen4();
173 	virtual void			_ReservedGLScreen5();
174 	virtual void			_ReservedGLScreen6();
175 	virtual void			_ReservedGLScreen7();
176 	virtual void			_ReservedGLScreen8();
177 
178 							BGLScreen(const BGLScreen &);
179 							BGLScreen &operator=(const BGLScreen &);
180 
181 			void*			fGc;
182 			long			fOptions;
183 			BLocker			fDrawLock;
184 
185 			int32			fColorSpace;
186 			uint32			fScreenMode;
187 
188 			uint64			_reserved[7];
189 };
190 
191 #endif // __cplusplus
192 
193 #endif // BGLVIEW_H
194