[OPENGL32]
[reactos.git] / dll / opengl / opengl32 / opengl32.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: lib/opengl32/opengl.h
5 * PURPOSE: OpenGL32 lib, general header
6 */
7
8 #ifndef _OPENGL32_PCH_
9 #define _OPENGL32_PCH_
10
11 #define WIN32_NO_STATUS
12 #include <stdarg.h>
13 #include <windef.h>
14 #include <winbase.h>
15 #include <winuser.h>
16 #include <wingdi.h>
17 #include <winddi.h>
18 #include <GL/gl.h>
19
20 #ifndef OPENGL32_USE_TLS
21 #include <pstypes.h>
22 #endif
23
24 #include <wine/debug.h>
25
26 #include "icd.h"
27
28 /* *$%$£^§! headers inclusion */
29 static __inline
30 BOOLEAN
31 RemoveEntryList(
32 _In_ PLIST_ENTRY Entry)
33 {
34 PLIST_ENTRY OldFlink;
35 PLIST_ENTRY OldBlink;
36
37 OldFlink = Entry->Flink;
38 OldBlink = Entry->Blink;
39 OldFlink->Blink = OldBlink;
40 OldBlink->Flink = OldFlink;
41 return (OldFlink == OldBlink);
42 }
43
44 static __inline
45 VOID
46 InsertTailList(
47 _In_ PLIST_ENTRY ListHead,
48 _In_ PLIST_ENTRY Entry
49 )
50 {
51 PLIST_ENTRY OldBlink;
52 OldBlink = ListHead->Blink;
53 Entry->Flink = ListHead;
54 Entry->Blink = OldBlink;
55 OldBlink->Flink = Entry;
56 ListHead->Blink = Entry;
57 }
58
59
60 static __inline
61 VOID
62 InitializeListHead(
63 _Inout_ PLIST_ENTRY ListHead
64 )
65 {
66 ListHead->Flink = ListHead->Blink = ListHead;
67 }
68
69 extern LIST_ENTRY ContextListHead;
70
71 struct wgl_context
72 {
73 DWORD magic;
74 volatile LONG lock;
75
76 LIST_ENTRY ListEntry;
77
78 DHGLRC dhglrc;
79 struct ICD_Data* icd_data;
80 INT pixelformat;
81 volatile LONG thread_id;
82 };
83
84 #define WGL_DC_OBJ_DC 0x1
85 struct wgl_dc_data
86 {
87 /* Header */
88 union
89 {
90 HWND hwnd;
91 HDC hdc;
92 HANDLE u;
93 } owner;
94 ULONG flags;
95
96 /* Pixel format */
97 INT pixelformat;
98
99 /* ICD */
100 struct ICD_Data* icd_data;
101 INT nb_icd_formats;
102
103 /* Software implementation */
104 INT nb_sw_formats;
105 void* sw_data;
106
107 /* Linked list */
108 struct wgl_dc_data* next;
109 };
110
111 /* Clean up functions */
112 void IntDeleteAllContexts(void);
113 void IntDeleteAllICDs(void);
114
115 #ifdef OPENGL32_USE_TLS
116 extern DWORD OglTlsIndex;
117
118 struct Opengl32_ThreadData
119 {
120 const GLDISPATCHTABLE* glDispatchTable;
121 HGLRC hglrc;
122 HDC hdc;
123 struct wgl_dc_data* dc_data;
124 PVOID* icdData;
125 };
126 C_ASSERT(FIELD_OFFSET(struct Opengl32_ThreadData, glDispatchTable) == 0);
127
128 /* dllmain.c */
129 BOOL init_tls_data(void);
130
131 FORCEINLINE
132 void
133 IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data* dc_data)
134 {
135 struct Opengl32_ThreadData* thread_data = TlsGetValue(OglTlsIndex);
136 if (!thread_data)
137 {
138 OutputDebugStringA("Calling init_tls_data from IntMakeCurrent\n");
139 if (!init_tls_data())
140 OutputDebugStringA("init_tls_data failed, brace for impact...\n");
141
142 thread_data = TlsGetValue(OglTlsIndex);
143 }
144
145 thread_data->hglrc = hglrc;
146 thread_data->hdc = hdc;
147 thread_data->dc_data = dc_data;
148 }
149
150 FORCEINLINE
151 HGLRC
152 IntGetCurrentRC(void)
153 {
154 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
155 return data ? data->hglrc : NULL;
156 }
157
158 FORCEINLINE
159 HDC
160 IntGetCurrentDC(void)
161 {
162 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
163 return data ? data->hdc : NULL;
164 }
165
166 FORCEINLINE
167 struct wgl_dc_data*
168 IntGetCurrentDcData(void)
169 {
170 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
171 return data->dc_data;
172 }
173
174 FORCEINLINE
175 const GLDISPATCHTABLE *
176 IntGetCurrentDispatchTable(void)
177 {
178 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
179 return data->glDispatchTable;
180 }
181
182 FORCEINLINE
183 void
184 IntSetCurrentDispatchTable(const GLDISPATCHTABLE* table)
185 {
186 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
187 data->glDispatchTable = table;
188 }
189
190 FORCEINLINE
191 void
192 IntSetCurrentICDPrivate(void* value)
193 {
194 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
195 data->icdData = value;
196 }
197
198 FORCEINLINE
199 void*
200 IntGetCurrentICDPrivate(void)
201 {
202 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
203 return data->icdData;
204 }
205
206
207 #else
208 FORCEINLINE
209 const GLDISPATCHTABLE*
210 IntGetCurrentDispatchTable(void)
211 {
212 return (GLDISPATCHTABLE*)NtCurrentTeb()->glTable;
213 }
214
215 FORCEINLINE
216 void
217 IntSetCurrentDispatchTable(const GLDISPATCHTABLE* table)
218 {
219 NtCurrentTeb()->glTable = (void*)table;
220 }
221
222 FORCEINLINE
223 void
224 IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data* dc_data)
225 {
226 TEB* CurrentTeb = NtCurrentTeb();
227
228 CurrentTeb->glCurrentRC = hglrc;
229 CurrentTeb->glReserved2 = hdc;
230 CurrentTeb->glContext = dc_data;
231 }
232
233 FORCEINLINE
234 HGLRC
235 IntGetCurrentRC(void)
236 {
237 return NtCurrentTeb()->glCurrentRC;
238 }
239
240 FORCEINLINE
241 HDC
242 IntGetCurrentDC(void)
243 {
244 return NtCurrentTeb()->glReserved2;
245 }
246
247 static inline
248 struct wgl_dc_data*
249 IntGetCurrentDcData(void)
250 {
251 return NtCurrentTeb()->glContext;
252 }
253
254 FORCEINLINE
255 void
256 IntSetCurrentICDPrivate(void* value)
257 {
258 NtCurrentTeb()->glReserved1[0] = (ULONG_PTR)value;
259 }
260
261 FORCEINLINE
262 void*
263 IntGetCurrentICDPrivate(void)
264 {
265 return (void*)NtCurrentTeb()->glReserved1[0];
266 }
267
268 #endif // defined(OPENGL32_USE_TLS)
269
270 FORCEINLINE
271 DHGLRC
272 IntGetCurrentDHGLRC(void)
273 {
274 struct wgl_context* ctx = (struct wgl_context*)IntGetCurrentRC();
275 if(!ctx) return NULL;
276 return ctx->dhglrc;
277 }
278
279 /* Software implementation functions */
280 INT sw_DescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR* descr);
281 BOOL sw_SetPixelFormat(HDC hdc, struct wgl_dc_data*, INT format);
282 DHGLRC sw_CreateContext(struct wgl_dc_data*);
283 BOOL sw_DeleteContext(DHGLRC dhglrc);
284 BOOL sw_SetContext(struct wgl_dc_data* dc_data, DHGLRC dhglrc);
285 void sw_ReleaseContext(DHGLRC hglrc);
286 PROC sw_GetProcAddress(LPCSTR name);
287 BOOL sw_CopyContext(DHGLRC dhglrcSrc, DHGLRC dhglrcDst, UINT mask);
288 BOOL sw_ShareLists(DHGLRC dhglrcSrc, DHGLRC dhglrcDst);
289 BOOL sw_SwapBuffers(HDC hdc, struct wgl_dc_data* dc_data);
290
291 #endif /* _OPENGL32_PCH_ */