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