0aadd6782a9bfe4094040162e252c2659aa0b9f5
[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 #include <wine/debug.h>
21
22 #include "icd.h"
23
24 /* *$%$£^§! headers inclusion */
25 static __inline
26 BOOLEAN
27 RemoveEntryList(
28 _In_ PLIST_ENTRY Entry)
29 {
30 PLIST_ENTRY OldFlink;
31 PLIST_ENTRY OldBlink;
32
33 OldFlink = Entry->Flink;
34 OldBlink = Entry->Blink;
35 OldFlink->Blink = OldBlink;
36 OldBlink->Flink = OldFlink;
37 return (OldFlink == OldBlink);
38 }
39
40 static __inline
41 VOID
42 InsertTailList(
43 _In_ PLIST_ENTRY ListHead,
44 _In_ PLIST_ENTRY Entry
45 )
46 {
47 PLIST_ENTRY OldBlink;
48 OldBlink = ListHead->Blink;
49 Entry->Flink = ListHead;
50 Entry->Blink = OldBlink;
51 OldBlink->Flink = Entry;
52 ListHead->Blink = Entry;
53 }
54
55
56 static __inline
57 VOID
58 InitializeListHead(
59 _Inout_ PLIST_ENTRY ListHead
60 )
61 {
62 ListHead->Flink = ListHead->Blink = ListHead;
63 }
64
65 extern LIST_ENTRY ContextListHead;
66
67 struct wgl_context
68 {
69 DWORD magic;
70 volatile LONG lock;
71
72 LIST_ENTRY ListEntry;
73
74 DHGLRC dhglrc;
75 struct ICD_Data* icd_data;
76 INT pixelformat;
77 volatile LONG thread_id;
78 };
79
80 #define WGL_DC_OBJ_DC 0x1
81 struct wgl_dc_data
82 {
83 /* Header */
84 union
85 {
86 HWND hwnd;
87 HDC hdc;
88 HANDLE u;
89 } owner;
90 ULONG flags;
91
92 /* Pixel format */
93 INT pixelformat;
94
95 /* ICD */
96 struct ICD_Data* icd_data;
97 INT nb_icd_formats;
98
99 /* Software implementation */
100 INT nb_sw_formats;
101 void* sw_data;
102
103 /* Linked list */
104 struct wgl_dc_data* next;
105 };
106
107 /* Clean up functions */
108 void IntDeleteAllContexts(void);
109 void IntDeleteAllICDs(void);
110
111 #ifdef OPENGL32_USE_TLS
112 extern DWORD OglTlsIndex;
113
114 struct Opengl32_ThreadData
115 {
116 const GLDISPATCHTABLE* glDispatchTable;
117 HGLRC hglrc;
118 HDC hdc;
119 struct wgl_dc_data* dc_data;
120 PVOID* icdData;
121 };
122 C_ASSERT(FIELD_OFFSET(struct Opengl32_ThreadData, glDispatchTable) == 0);
123
124 /* dllmain.c */
125 BOOL init_tls_data(void);
126
127 static inline
128 void
129 IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data* dc_data)
130 {
131 struct Opengl32_ThreadData* thread_data = TlsGetValue(OglTlsIndex);
132 if (!thread_data)
133 {
134 OutputDebugStringA("Calling init_tls_data from IntMakeCurrent\n");
135 if (!init_tls_data())
136 OutputDebugStringA("init_tls_data failed, brace for impact...\n");
137
138 thread_data = TlsGetValue(OglTlsIndex);
139 }
140
141 thread_data->hglrc = hglrc;
142 thread_data->hdc = hdc;
143 thread_data->dc_data = dc_data;
144 }
145
146 static inline
147 HGLRC
148 IntGetCurrentRC(void)
149 {
150 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
151 return data ? data->hglrc : NULL;
152 }
153
154 static inline
155 DHGLRC
156 IntGetCurrentDHGLRC(void)
157 {
158 struct wgl_context* ctx = (struct wgl_context*)IntGetCurrentRC();
159 if(!ctx) return NULL;
160 return ctx->dhglrc;
161 }
162
163 static inline
164 HDC
165 IntGetCurrentDC(void)
166 {
167 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
168 return data ? data->hdc : NULL;
169 }
170
171 static inline
172 struct wgl_dc_data*
173 IntGetCurrentDcData(void)
174 {
175 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
176 return data->dc_data;
177 }
178
179 static inline
180 const GLDISPATCHTABLE *
181 IntGetCurrentDispatchTable(void)
182 {
183 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
184 return data->glDispatchTable;
185 }
186
187 static inline
188 void
189 IntSetCurrentDispatchTable(const GLDISPATCHTABLE* table)
190 {
191 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
192 data->glDispatchTable = table;
193 }
194
195 static inline
196 void
197 IntSetCurrentICDPrivate(void* value)
198 {
199 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
200 data->icdData = value;
201 }
202
203 static inline
204 void*
205 IntGetCurrentICDPrivate(void)
206 {
207 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
208 return data->icdData;
209 }
210
211
212 #else
213 static inline
214 const GLDISPATCHTABLE*
215 IntGetCurrentDispatchTable(void)
216 {
217 return (GLDISPATCHTABLE*)NtCurrentTeb()->glTable;
218 }
219 #endif // defined(OPENGL32_USE_TLS)
220
221 /* Software implementation functions */
222 INT sw_DescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR* descr);
223 BOOL sw_SetPixelFormat(HDC hdc, struct wgl_dc_data*, INT format);
224 DHGLRC sw_CreateContext(struct wgl_dc_data*);
225 BOOL sw_DeleteContext(DHGLRC dhglrc);
226 BOOL sw_SetContext(struct wgl_dc_data* dc_data, DHGLRC dhglrc);
227 void sw_ReleaseContext(DHGLRC hglrc);
228 PROC sw_GetProcAddress(LPCSTR name);
229 BOOL sw_CopyContext(DHGLRC dhglrcSrc, DHGLRC dhglrcDst, UINT mask);
230 BOOL sw_ShareLists(DHGLRC dhglrcSrc, DHGLRC dhglrcDst);
231 BOOL sw_SwapBuffers(HDC hdc, struct wgl_dc_data* dc_data);
232
233 #endif /* _OPENGL32_PCH_ */