[SHELL-EXPERIMENTS]
[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 static inline
125 void
126 IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data* dc_data)
127 {
128 struct Opengl32_ThreadData* thread_data = TlsGetValue(OglTlsIndex);
129
130 thread_data->hglrc = hglrc;
131 thread_data->hdc = hdc;
132 thread_data->dc_data = dc_data;
133 }
134
135 static inline
136 HGLRC
137 IntGetCurrentRC(void)
138 {
139 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
140 return data->hglrc;
141 }
142
143 static inline
144 DHGLRC
145 IntGetCurrentDHGLRC(void)
146 {
147 struct wgl_context* ctx = (struct wgl_context*)IntGetCurrentRC();
148 if(!ctx) return NULL;
149 return ctx->dhglrc;
150 }
151
152 static inline
153 HDC
154 IntGetCurrentDC(void)
155 {
156 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
157 return data->hdc;
158 }
159
160 static inline
161 struct wgl_dc_data*
162 IntGetCurrentDcData(void)
163 {
164 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
165 return data->dc_data;
166 }
167
168 static inline
169 const GLDISPATCHTABLE *
170 IntGetCurrentDispatchTable(void)
171 {
172 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
173 return data->glDispatchTable;
174 }
175
176 static inline
177 void
178 IntSetCurrentDispatchTable(const GLDISPATCHTABLE* table)
179 {
180 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
181 data->glDispatchTable = table;
182 }
183
184 static inline
185 void
186 IntSetCurrentICDPrivate(void* value)
187 {
188 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
189 data->icdData = value;
190 }
191
192 static inline
193 void*
194 IntGetCurrentICDPrivate(void)
195 {
196 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
197 return data->icdData;
198 }
199
200
201 #else
202 static inline
203 const GLDISPATCHTABLE*
204 IntGetCurrentDispatchTable(void)
205 {
206 return (GLDISPATCHTABLE*)NtCurrentTeb()->glTable;
207 }
208 #endif // defined(OPENGL32_USE_TLS)
209
210 /* Software implementation functions */
211 INT sw_DescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR* descr);
212 BOOL sw_SetPixelFormat(HDC hdc, struct wgl_dc_data*, INT format);
213 DHGLRC sw_CreateContext(struct wgl_dc_data*);
214 BOOL sw_DeleteContext(DHGLRC dhglrc);
215 BOOL sw_SetContext(struct wgl_dc_data* dc_data, DHGLRC dhglrc);
216 void sw_ReleaseContext(DHGLRC hglrc);
217 PROC sw_GetProcAddress(LPCSTR name);
218 BOOL sw_CopyContext(DHGLRC dhglrcSrc, DHGLRC dhglrcDst, UINT mask);
219 BOOL sw_ShareLists(DHGLRC dhglrcSrc, DHGLRC dhglrcDst);
220 BOOL sw_SwapBuffers(HDC hdc, struct wgl_dc_data* dc_data);
221
222 #endif /* _OPENGL32_PCH_ */