[WIN32DLLS]
[reactos.git] / reactos / 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 struct wgl_context
25 {
26 DWORD magic;
27 volatile LONG lock;
28
29 DHGLRC dhglrc;
30 struct ICD_Data* icd_data;
31 INT pixelformat;
32 volatile LONG thread_id;
33 };
34
35 #define WGL_DC_OBJ_DC 0x1
36 struct wgl_dc_data
37 {
38 /* Header */
39 union
40 {
41 HWND hwnd;
42 HDC hdc;
43 HANDLE u;
44 } owner;
45 ULONG flags;
46
47 /* Pixel format */
48 INT pixelformat;
49
50 /* ICD */
51 struct ICD_Data* icd_data;
52 INT nb_icd_formats;
53
54 /* Software implementation */
55 INT nb_sw_formats;
56 void* sw_data;
57
58 /* Linked list */
59 struct wgl_dc_data* next;
60 };
61
62 #ifdef OPENGL32_USE_TLS
63 extern DWORD OglTlsIndex;
64
65 struct Opengl32_ThreadData
66 {
67 const GLDISPATCHTABLE* glDispatchTable;
68 HGLRC hglrc;
69 HDC hdc;
70 struct wgl_dc_data* dc_data;
71 PVOID* icdData;
72 };
73 C_ASSERT(FIELD_OFFSET(struct Opengl32_ThreadData, glDispatchTable) == 0);
74
75 static inline
76 void
77 IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data* dc_data)
78 {
79 struct Opengl32_ThreadData* thread_data = TlsGetValue(OglTlsIndex);
80
81 thread_data->hglrc = hglrc;
82 thread_data->hdc = hdc;
83 thread_data->dc_data = dc_data;
84 }
85
86 static inline
87 HGLRC
88 IntGetCurrentRC(void)
89 {
90 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
91 return data->hglrc;
92 }
93
94 static inline
95 DHGLRC
96 IntGetCurrentDHGLRC(void)
97 {
98 struct wgl_context* ctx = (struct wgl_context*)IntGetCurrentRC();
99 if(!ctx) return NULL;
100 return ctx->dhglrc;
101 }
102
103 static inline
104 HDC
105 IntGetCurrentDC(void)
106 {
107 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
108 return data->hdc;
109 }
110
111 static inline
112 struct wgl_dc_data*
113 IntGetCurrentDcData(void)
114 {
115 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
116 return data->dc_data;
117 }
118
119 static inline
120 const GLDISPATCHTABLE *
121 IntGetCurrentDispatchTable(void)
122 {
123 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
124 return data->glDispatchTable;
125 }
126
127 static inline
128 void
129 IntSetCurrentDispatchTable(const GLDISPATCHTABLE* table)
130 {
131 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
132 data->glDispatchTable = table;
133 }
134
135 static inline
136 void
137 IntSetCurrentICDPrivate(void* value)
138 {
139 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
140 data->icdData = value;
141 }
142
143 static inline
144 void*
145 IntGetCurrentICDPrivate(void)
146 {
147 struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
148 return data->icdData;
149 }
150
151
152 #else
153 static inline
154 const GLDISPATCHTABLE*
155 IntGetCurrentDispatchTable(void)
156 {
157 return (GLDISPATCHTABLE*)NtCurrentTeb()->glTable;
158 }
159 #endif // defined(OPENGL32_USE_TLS)
160
161 /* Software implementation functions */
162 INT sw_DescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR* descr);
163 BOOL sw_SetPixelFormat(HDC hdc, struct wgl_dc_data*, INT format);
164 DHGLRC sw_CreateContext(struct wgl_dc_data*);
165 BOOL sw_DeleteContext(DHGLRC dhglrc);
166 BOOL sw_SetContext(struct wgl_dc_data* dc_data, DHGLRC dhglrc);
167 void sw_ReleaseContext(DHGLRC hglrc);
168 PROC sw_GetProcAddress(LPCSTR name);
169 BOOL sw_CopyContext(DHGLRC dhglrcSrc, DHGLRC dhglrcDst, UINT mask);
170 BOOL sw_ShareLists(DHGLRC dhglrcSrc, DHGLRC dhglrcDst);
171 BOOL sw_SwapBuffers(HDC hdc, struct wgl_dc_data* dc_data);
172
173 #endif /* _OPENGL32_PCH_ */