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