[FMIFS]
[reactos.git] / reactos / dll / opengl / opengl32 / gl.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: lib/opengl32/gl.c
5 * PURPOSE: OpenGL32 lib, glXXX functions
6 * PROGRAMMER: Anich Gregor (blight)
7 * UPDATE HISTORY:
8 * Feb 2, 2004: Created
9 */
10
11 /* On a x86 we call the ICD functions in a special-way:
12 *
13 * For every glXXX function we export a glXXX entry-point which loads the
14 * matching "real" function pointer from the NtCurrentTeb()->glDispatchTable
15 * for gl functions in teblist.h and for others it gets the pointer from
16 * NtCurrentTeb()->glTable and jmps to the address, leaving the stack alone and
17 * letting the "real" function return for us.
18 * Royce has implemented this in NASM =D
19 *
20 * On other machines we use C to forward the calls (slow...)
21 */
22
23 #include "opengl32.h"
24
25 #if defined(_M_IX86)
26 C_ASSERT(FIELD_OFFSET(TEB, glTable) == 0xbe8);
27 #endif
28
29 int WINAPI glEmptyFunc0( void ) { return 0; }
30 int WINAPI glEmptyFunc4( long l1 ) { return 0; }
31 int WINAPI glEmptyFunc8( long l1, long l2 ) { return 0; }
32 int WINAPI glEmptyFunc12( long l1, long l2, long l3 ) { return 0; }
33 int WINAPI glEmptyFunc16( long l1, long l2, long l3, long l4 ) { return 0; }
34 int WINAPI glEmptyFunc20( long l1, long l2, long l3, long l4, long l5 )
35 { return 0; }
36 int WINAPI glEmptyFunc24( long l1, long l2, long l3, long l4, long l5,
37 long l6 ) { return 0; }
38 int WINAPI glEmptyFunc28( long l1, long l2, long l3, long l4, long l5,
39 long l6, long l7 ) { return 0; }
40 int WINAPI glEmptyFunc32( long l1, long l2, long l3, long l4, long l5,
41 long l6, long l7, long l8 ) { return 0; }
42 int WINAPI glEmptyFunc36( long l1, long l2, long l3, long l4, long l5,
43 long l6, long l7, long l8, long l9 ) { return 0; }
44 int WINAPI glEmptyFunc40( long l1, long l2, long l3, long l4, long l5,
45 long l6, long l7, long l8, long l9, long l10 )
46 { return 0; }
47 int WINAPI glEmptyFunc44( long l1, long l2, long l3, long l4, long l5,
48 long l6, long l7, long l8, long l9, long l10,
49 long l11 ) { return 0; }
50 int WINAPI glEmptyFunc48( long l1, long l2, long l3, long l4, long l5,
51 long l6, long l7, long l8, long l9, long l10,
52 long l11, long l12 ) { return 0; }
53 int WINAPI glEmptyFunc52( long l1, long l2, long l3, long l4, long l5,
54 long l6, long l7, long l8, long l9, long l10,
55 long l11, long l12, long l13 ) { return 0; }
56 int WINAPI glEmptyFunc56( long l1, long l2, long l3, long l4, long l5,
57 long l6, long l7, long l8, long l9, long l10,
58 long l11, long l12, long l13, long l14 )
59 { return 0; }
60
61 #if defined(_M_IX86)
62 # define FOO(x) #x
63
64 #ifdef __GNUC__
65 # define X(func, ret, typeargs, args, icdidx, tebidx, stack) \
66 __asm__(".align 4" "\n\t" \
67 ".globl _"#func"@"#stack "\n\t" \
68 "_"#func"@"#stack":" "\n\t" \
69 " movl %fs:0x18, %eax" "\n\t" \
70 " movl 0xbe8(%eax), %eax" "\n\t" \
71 " jmp *"FOO((icdidx*4))"(%eax)" "\n\t");
72 #elif defined(_MSC_VER)
73 # define X(func, ret, typeargs, args, icdidx, tebidx, stack) \
74 __declspec(naked) ret WINAPI func typeargs \
75 { \
76 __asm { mov eax, dword ptr fs:[18h] }; \
77 __asm { mov eax, dword ptr [eax+0be8h] }; \
78 __asm { jmp dword ptr [eax+icdidx*4] }; \
79 }
80 #else
81 # define X(func, ret, typeargs, args, icdidx, tebidx, stack) \
82 ret WINAPI func typeargs \
83 { \
84 PROC *table; \
85 PROC fn; \
86 if (tebidx >= 0 && 0) \
87 { \
88 table = (PROC *)NtCurrentTeb()->glDispatchTable; \
89 fn = table[tebidx]; \
90 } \
91 else \
92 { \
93 table = (PROC *)NtCurrentTeb()->glTable; \
94 fn = table[icdidx]; \
95 } \
96 return (ret)((ret(*)typeargs)fn)args; \
97 }
98 #endif
99
100 GLFUNCS_MACRO
101 # undef FOO
102 # undef X
103 #else /* defined(_M_IX86) */
104 # define X(func, ret, typeargs, args, icdidx, tebidx, stack) \
105 ret WINAPI func typeargs \
106 { \
107 PROC *table; \
108 PROC fn; \
109 if (tebidx >= 0 && 0) \
110 { \
111 table = (PROC *)NtCurrentTeb()->glDispatchTable; \
112 fn = table[tebidx]; \
113 } \
114 else \
115 { \
116 table = (PROC *)NtCurrentTeb()->glTable; \
117 fn = table[icdidx]; \
118 } \
119 return (ret)((ret(*)typeargs)fn)args; \
120 }
121
122 GLFUNCS_MACRO
123
124 # undef X
125 #endif /* !defined(_M_IX86) */
126
127 /* Unknown debugging function */
128 GLint WINAPI glDebugEntry( GLint unknown1, GLint unknown2 )
129 {
130 return 0;
131 }
132
133
134 /* EOF */