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