2 * Host-side implementation of GL/GLX API
4 * Copyright (c) 2006,2007 Even Rouault
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 void init_process_tab(void);
44 #define GL_GLEXT_PROTOTYPES
45 #include "opengl_func.h"
46 #include "opengl_utils.h"
48 #include "mesa_glxext.h"
50 #include "mesa_mipmap.c"
59 unsigned int colorBits;
66 void* hWnd; /* Surface?? ˤ?? Window Handle*/
67 void* cDC; /*Context?? ˤ?? Dummy Window Handle*/
70 #define MAX_HANDLED_PROCESS 100
71 #define MAX_ASSOC_SIZE 100
72 #define MAX_FBCONFIG 10
73 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
87 int activeTextureIndex;
90 #define MAX_CLIENT_STATE_STACK_SIZE 16
91 #define NB_MAX_TEXTURES 16
92 #define MY_GL_MAX_VERTEX_ATTRIBS_ARB 16
93 #define MY_GL_MAX_VERTEX_ATTRIBS_NV 16
94 #define MY_GL_MAX_VARIANT_POINTER_EXT 16
107 void* secondaryColorPointer;
109 void* texCoordPointer[NB_MAX_TEXTURES];
110 void* edgeFlagPointer;
111 void* vertexAttribPointer[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
112 void* vertexAttribPointerNV[MY_GL_MAX_VERTEX_ATTRIBS_NV];
114 void* matrixIndexPointer;
115 void* fogCoordPointer;
116 void* variantPointerEXT[MY_GL_MAX_VARIANT_POINTER_EXT];
117 void* interleavedArrays;
118 void* elementPointerATI;
120 int vertexPointerSize;
121 int normalPointerSize;
122 int colorPointerSize;
123 int secondaryColorPointerSize;
124 int indexPointerSize;
125 int texCoordPointerSize[NB_MAX_TEXTURES];
126 int edgeFlagPointerSize;
127 int vertexAttribPointerSize[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
128 int vertexAttribPointerNVSize[MY_GL_MAX_VERTEX_ATTRIBS_NV];
129 int weightPointerSize;
130 int matrixIndexPointerSize;
131 int fogCoordPointerSize;
132 int variantPointerEXTSize[MY_GL_MAX_VARIANT_POINTER_EXT];
133 int interleavedArraysSize;
134 int elementPointerATISize;
136 int selectBufferSize;
137 void* selectBufferPtr;
138 int feedbackBufferSize;
139 void* feedbackBufferPtr;
141 ClientState clientStateStack[MAX_CLIENT_STATE_STACK_SIZE];
143 int activeTextureIndex;
145 unsigned int ownTabTextures[32768];
146 unsigned int* tabTextures;
147 RangeAllocator ownTextureAllocator;
148 RangeAllocator* textureAllocator;
150 unsigned int ownTabBuffers[32768];
151 unsigned int* tabBuffers;
152 RangeAllocator ownBufferAllocator;
153 RangeAllocator* bufferAllocator;
155 unsigned int ownTabLists[32768];
156 unsigned int* tabLists;
157 RangeAllocator ownListAllocator;
158 RangeAllocator* listAllocator;
160 #ifdef SYSTEMATIC_ERROR_CHECK
167 PIXELFORMATDESCRIPTOR pfd;
168 unsigned int visualID;
177 int x, y, width, height;
178 WindowPosStruct currentDrawablePos;
180 int next_available_context_number;
181 int next_available_pbuffer_number;
184 GLState default_state;
186 GLState* current_state;
189 WGLFBConfig* fbconfigs[MAX_FBCONFIG];
190 int fbconfigs_max[MAX_FBCONFIG];
193 Assoc association_fakecontext_glxcontext[MAX_ASSOC_SIZE];
194 Assoc association_fakepbuffer_pbuffer[MAX_ASSOC_SIZE];
195 Assoc association_clientdrawable_serverdrawable[MAX_ASSOC_SIZE];
196 Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
199 int last_process_id = 0;
204 int attribListLength;
206 unsigned int visualID;
207 /*PIXELFORMATDESCRIPTOR* visInfo;*/
208 } AssocAttribListVisual;
210 #define ARG_TO_CHAR(x) (char)(x)
211 #define ARG_TO_UNSIGNED_CHAR(x) (unsigned char)(x)
212 #define ARG_TO_SHORT(x) (short)(x)
213 #define ARG_TO_UNSIGNED_SHORT(x) (unsigned short)(x)
214 #define ARG_TO_INT(x) (int)(x)
215 #define ARG_TO_UNSIGNED_INT(x) (unsigned int)(x)
216 #define ARG_TO_FLOAT(x) (*(float*)&(x))
217 #define ARG_TO_DOUBLE(x) (*(double*)(x))
219 #define GET_EXT_PTR(type, funcname, args_decl) \
220 static int detect_##funcname = 0; \
221 static type(*ptr_func_##funcname)args_decl = NULL; \
222 if (detect_##funcname == 0) \
224 detect_##funcname = 1; \
225 ptr_func_##funcname = (type(*)args_decl)wglGetProcAddress((const GLubyte*)#funcname); \
226 assert (ptr_func_##funcname); \
229 #define GET_EXT_PTR_NO_FAIL(type, funcname, args_decl) \
230 static int detect_##funcname = 0; \
231 static type(*ptr_func_##funcname)args_decl = NULL; \
232 if (detect_##funcname == 0) \
234 detect_##funcname = 1; \
235 ptr_func_##funcname = (type(*)args_decl)wglGetProcAddress((const GLubyte*)#funcname); \
239 #include "server_stub.c"
241 static void* get_glu_ptr(const char* name)
243 static void* handle = (void*)-1;
244 if (handle == (void*)-1)
247 handle = dlopen("libGLU.so" ,RTLD_LAZY);
249 fprintf (stderr, "can't load libGLU.so : %s\n", dlerror());
252 handle = (void *)LoadLibrary("glu32.dll");
254 fprintf (stderr, "can't load glu32.dll\n");
261 return dlsym(handle, name);
263 return GetProcAddress(handle, name);
271 #define GET_GLU_PTR(type, funcname, args_decl) \
272 static int detect_##funcname = 0; \
273 static type(*ptr_func_##funcname)args_decl = NULL; \
274 if (detect_##funcname == 0) \
276 detect_##funcname = 1; \
277 ptr_func_##funcname = (type(*)args_decl)get_glu_ptr(#funcname); \
281 static void _get_window_pos(HWND hWnd, WindowPosStruct* pos)
285 GetWindowRect(hWnd, &rcWindow);
287 pos->x = rcWindow.left;
288 pos->y = rcWindow.top;
290 pos->width = rcWindow.right - rcWindow.left;
291 pos->height = rcWindow.bottom - rcWindow.top;
293 pos->map_state = IsViewable;
297 int display_function_call = 0;
299 static void init_gl_state(GLState* state)
301 state->textureAllocator = &state->ownTextureAllocator;
302 state->tabTextures = state->ownTabTextures;
303 state->bufferAllocator = &state->ownBufferAllocator;
304 state->tabBuffers = state->ownTabBuffers;
305 state->listAllocator = &state->ownListAllocator;
306 state->tabLists = state->ownTabLists;
310 static void destroy_gl_state(GLState* state)
313 if (state->vertexPointer) free(state->vertexPointer);
314 if (state->normalPointer) free(state->normalPointer);
315 if (state->indexPointer) free(state->indexPointer);
316 if (state->colorPointer) free(state->colorPointer);
317 if (state->secondaryColorPointer) free(state->secondaryColorPointer);
318 for(i=0;i<NB_MAX_TEXTURES;i++)
320 if (state->texCoordPointer[i]) free(state->texCoordPointer[i]);
322 for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_ARB;i++)
324 if (state->vertexAttribPointer[i]) free(state->vertexAttribPointer[i]);
326 for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_NV;i++)
328 if (state->vertexAttribPointerNV[i]) free(state->vertexAttribPointerNV[i]);
330 if (state->weightPointer) free(state->weightPointer);
331 if (state->matrixIndexPointer) free(state->matrixIndexPointer);
332 if (state->fogCoordPointer) free(state->fogCoordPointer);
333 for(i=0;i<MY_GL_MAX_VARIANT_POINTER_EXT;i++)
335 if (state->variantPointerEXT[i]) free(state->variantPointerEXT[i]);
337 if (state->interleavedArrays) free(state->interleavedArrays);
338 if (state->elementPointerATI) free(state->elementPointerATI);
341 static void _create_context(ProcessStruct* process, HGLRC ctxt, int fake_ctxt, HGLRC shareList, int fake_shareList)
343 process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
344 process->glstates[process->nbGLStates] = malloc(sizeof(GLState));
345 memset(process->glstates[process->nbGLStates], 0, sizeof(GLState));
346 process->glstates[process->nbGLStates]->ref = 1;
347 process->glstates[process->nbGLStates]->context = ctxt;
348 process->glstates[process->nbGLStates]->fake_ctxt = fake_ctxt;
349 process->glstates[process->nbGLStates]->fake_shareList = fake_shareList;
350 init_gl_state(process->glstates[process->nbGLStates]);
351 if (shareList && fake_shareList)
354 for(i=0;i<process->nbGLStates;i++)
356 if (process->glstates[i]->fake_ctxt == fake_shareList)
358 process->glstates[i]->ref ++;
359 process->glstates[process->nbGLStates]->textureAllocator =
360 process->glstates[i]->textureAllocator;
361 process->glstates[process->nbGLStates]->tabTextures =
362 process->glstates[i]->tabTextures;
363 process->glstates[process->nbGLStates]->bufferAllocator =
364 process->glstates[i]->bufferAllocator;
365 process->glstates[process->nbGLStates]->tabBuffers =
366 process->glstates[i]->tabBuffers;
367 process->glstates[process->nbGLStates]->listAllocator =
368 process->glstates[i]->listAllocator;
369 process->glstates[process->nbGLStates]->tabLists =
370 process->glstates[i]->tabLists;
375 process->nbGLStates++;
378 WGLFBConfig* get_pfDescriptor(ProcessStruct* process, int client_pfd)
382 for(i=0;i<process->nfbconfig;i++)
384 assert(client_pfd >= 1 + nbtotal);
385 if (client_pfd <= nbtotal + process->fbconfigs_max[i])
387 return (WGLFBConfig*) (&process->fbconfigs[i][client_pfd-1 - nbtotal]);
389 nbtotal += process->fbconfigs_max[i];
394 int get_pfdAttrib(PIXELFORMATDESCRIPTOR *ppfd, int attrib, int *value)
400 case GLX_FBCONFIG_ID:
404 case GLX_AUX_BUFFERS:
405 answer = ppfd->cAuxBuffers;
412 case GLX_ACCUM_RED_SIZE:
413 answer = ppfd->cAccumRedBits;
416 case GLX_ACCUM_GREEN_SIZE:
417 answer = ppfd->cAccumGreenBits;
420 case GLX_ACCUM_BLUE_SIZE:
421 answer = ppfd->cAccumBlueBits;
424 case GLX_ACCUM_ALPHA_SIZE:
425 answer = ppfd->cAccumAlphaBits;
428 case GLX_RENDER_TYPE:
429 answer = (ppfd->iPixelType == PFD_TYPE_RGBA) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
434 answer = (ppfd->iPixelType == PFD_TYPE_RGBA) ? (int)True : (int)False;
437 case GLX_COLOR_INDEX_TYPE:
438 answer = (ppfd->iPixelType == PFD_TYPE_COLORINDEX) ? (int)True : (int)False;
442 answer = ((ppfd->dwFlags & PFD_SUPPORT_OPENGL) != 0) ? (int)True : (int)False;
445 case GLX_DOUBLEBUFFER:
446 answer = ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != 0) ? (int)True : (int)False;
449 case GLX_DRAWABLE_TYPE:
450 answer = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
453 #ifdef GLX_CONFIG_CAVEAT
454 case GLX_CONFIG_CAVEAT:
458 case GLX_SLOW_CONFIG:
459 case GLX_NON_CONFORMANT_CONFIG:
462 #endif /*GLX_CONFIG_CAVEAT not support*/
464 case GLX_X_RENDERABLE:
468 case GLX_BUFFER_SIZE:
469 answer = ppfd->cColorBits;
473 answer = ppfd->cRedBits;
477 answer = ppfd->cGreenBits;
481 answer = ppfd->cBlueBits;
485 answer = ppfd->cAlphaBits;
489 answer = ppfd->cDepthBits;
492 case GLX_STENCIL_SIZE:
493 answer = ppfd->cStencilBits;
500 case GLX_MAX_PBUFFER_WIDTH:
504 case GLX_MAX_PBUFFER_HEIGHT:
508 case GLX_MAX_PBUFFER_PIXELS:
516 #ifdef GLX_X_VISUAL_TYPE
517 case GLX_X_VISUAL_TYPE:
522 case GLX_DIRECT_COLOR:
523 case GLX_PSEUDO_COLOR:
524 case GLX_STATIC_COLOR:
526 case GLX_STATIC_GRAY:
529 #endif /*GLX_X_VISUAL_TYPE not support*/
531 case GLX_SAMPLE_BUFFERS:
536 #ifdef GLX_TRANSPARENT_TYPE
537 case GLX_TRANSPARENT_TYPE:
541 case GLX_TRANSPARENT_INDEX_VALUE:
542 case GLX_TRANSPARENT_RED_VALUE:
543 case GLX_TRANSPARENT_GREEN_VALUE:
544 case GLX_TRANSPARENT_ALPHA_VALUE:
545 case GLX_TRANSPARENT_BLUE_VALUE:
546 answer = GLX_DONT_CARE;
549 case GLX_TRANSPARENT_RGB:
550 case GLX_TRANSPARENT_INDEX:
553 #endif /*GLX_X_VISUAL_TYPE not support*/
555 case GLX_FLOAT_COMPONENTS_NV:
556 case GLX_PRESERVED_CONTENTS:
561 answer = GLX_BAD_ATTRIBUTE;
570 void* get_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
573 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
575 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
576 return process->association_fakecontext_glxcontext[i].value;
581 void set_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext, void* glxcontext)
584 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
586 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
591 if (i < MAX_ASSOC_SIZE)
593 process->association_fakecontext_glxcontext[i].key = fakecontext;
594 process->association_fakecontext_glxcontext[i].value = glxcontext;
598 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
602 void get_association_fakecontext_glxwnd(ProcessStruct* process, void* fakecontext, HWND rWnd, HDC rDC)
605 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
607 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
609 rWnd = (HWND)process->association_fakecontext_glxcontext[i].hWnd;
610 rDC = (HDC)process->association_fakecontext_glxcontext[i].cDC;
619 void set_association_fakecontext_glxwnd(ProcessStruct* process, void* fakecontext, void* glxwnd, void *glxhdc)
622 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
624 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
629 if (i < MAX_ASSOC_SIZE)
631 process->association_fakecontext_glxcontext[i].key = fakecontext;
632 process->association_fakecontext_glxcontext[i].hWnd = glxwnd;
633 process->association_fakecontext_glxcontext[i].cDC = glxhdc;
637 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
641 void unset_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
644 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
646 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
648 memmove(&process->association_fakecontext_glxcontext[i],
649 &process->association_fakecontext_glxcontext[i+1],
650 sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
656 unsigned int get_association_fakecontext_visualid(ProcessStruct* process, void* fakecontext)
659 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
661 if (process->association_fakecontext_visual[i].key == fakecontext)
662 return (unsigned int)process->association_fakecontext_visual[i].value;
667 void set_association_fakecontext_visualid(ProcessStruct* process, void* fakecontext, unsigned int visualid)
670 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
672 if (process->association_fakecontext_visual[i].key == fakecontext)
677 if (i < MAX_ASSOC_SIZE)
679 process->association_fakecontext_visual[i].key = fakecontext;
680 process->association_fakecontext_visual[i].value = (void *)(long)visualid;
684 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
688 void unset_association_fakecontext_visualid(ProcessStruct* process, void* fakecontext)
691 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
693 if (process->association_fakecontext_visual[i].key == fakecontext)
695 memmove(&process->association_fakecontext_visual[i],
696 &process->association_fakecontext_visual[i+1],
697 sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
703 HWND get_association_clientdrawable_serverwnd(ProcessStruct* process, HDC clientdrawable)
706 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL; i++)
708 if (process->association_clientdrawable_serverdrawable[i].key == (void*)clientdrawable)
709 return (HWND)process->association_clientdrawable_serverdrawable[i].hWnd;
714 HDC get_association_clientdrawable_serverdrawable(ProcessStruct* process, HDC clientdrawable)
717 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
719 if (process->association_clientdrawable_serverdrawable[i].key == (void*)clientdrawable)
720 return (HDC)process->association_clientdrawable_serverdrawable[i].value;
725 void set_association_clientdrawable_serverwnd(ProcessStruct* process, void* clientdrawable, void* serverwnd)
728 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
730 if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
735 if (i < MAX_ASSOC_SIZE)
737 process->association_clientdrawable_serverdrawable[i].key = clientdrawable;
738 process->association_clientdrawable_serverdrawable[i].hWnd = serverwnd;
742 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
746 void set_association_clientdrawable_serverdrawable(ProcessStruct* process, void* clientdrawable, void* serverdrawable)
749 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
751 if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
756 if (i < MAX_ASSOC_SIZE)
758 process->association_clientdrawable_serverdrawable[i].key = clientdrawable;
759 process->association_clientdrawable_serverdrawable[i].value = serverdrawable;
763 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
767 void unset_association_clientdrawable_serverdrawable(ProcessStruct* process, void* clientdrawable)
770 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
772 if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
774 memmove(&process->association_clientdrawable_serverdrawable[i],
775 &process->association_clientdrawable_serverdrawable[i+1],
776 sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
782 HWND get_association_fakepbuffer_pbufferwnd(ProcessStruct* process, void* fakepbuffer)
785 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL; i++)
787 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
788 return (HWND)process->association_fakepbuffer_pbuffer[i].hWnd;
793 void set_association_fakepbuffer_pbufferwnd(ProcessStruct* process, void* fakepbuffer, void* pbufferwnd)
796 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
798 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
803 if (i < MAX_ASSOC_SIZE)
805 process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
806 process->association_fakepbuffer_pbuffer[i].hWnd = pbufferwnd;
810 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
814 PbufferInfo *get_association_fakepbuffer_pbinfo(ProcessStruct* process, void* fakepbuffer)
817 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL; i++)
819 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
820 return (PbufferInfo *)process->association_fakepbuffer_pbuffer[i].cDC;
822 return (PbufferInfo *)0;
825 void set_association_fakepbuffer_pbinfo(ProcessStruct* process, void* fakepbuffer, void* pbuffer_info)
828 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
830 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
835 if (i < MAX_ASSOC_SIZE)
837 process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
838 process->association_fakepbuffer_pbuffer[i].cDC= pbuffer_info;
842 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
846 HDC get_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
849 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
851 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
852 return (HDC)process->association_fakepbuffer_pbuffer[i].value;
857 void set_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer, void* pbuffer)
860 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
862 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
867 if (i < MAX_ASSOC_SIZE)
869 process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
870 process->association_fakepbuffer_pbuffer[i].value = pbuffer;
874 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
878 void unset_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
881 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
883 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
885 memmove(&process->association_fakepbuffer_pbuffer[i],
886 &process->association_fakepbuffer_pbuffer[i+1],
887 sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
893 static int get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid, PIXELFORMATDESCRIPTOR* rpfd)
898 AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
899 for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
901 if ( tabAssocAttribListVisual[i].visualID == visualid)
903 DescribePixelFormat((HDC)pConn->Display, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), rpfd);
912 static int get_default_visual(Display dpy, PIXELFORMATDESCRIPTOR* rpfd)
918 if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
921 for (i = 0; i < n; i++)
923 DescribePixelFormat(hdc, i, sizeof( PIXELFORMATDESCRIPTOR), rpfd);
924 if (!(rpfd->dwFlags & PFD_SUPPORT_OPENGL)) continue;
925 if (!(rpfd->dwFlags & PFD_DRAW_TO_WINDOW)) continue;
926 if (!(rpfd->dwFlags & PFD_DOUBLEBUFFER)) continue;
927 if (rpfd->iPixelType != PFD_TYPE_RGBA) continue;
928 if (rpfd->cRedBits < 8) continue;
929 if (rpfd->cGreenBits < 8) continue;
930 if (rpfd->cBlueBits < 8) continue;
931 if (rpfd->cAlphaBits < 8) continue;
932 if (rpfd->cDepthBits < 16) continue;
933 if (rpfd->cStencilBits < 8) continue;
938 if( i < n ) return i + 1;
944 /* Surface?? 위?? Window ????*/
945 static HDC create_swindow(OGLS_Conn *pConn, HDC clientdrawable, ProcessStruct* process, int x, int y, int width, int height)
951 LPSTR lpszClassWindowSurface ="WindowSurface";
953 wc.style = CS_HREDRAW | CS_VREDRAW;
954 wc.lpfnWndProc = (WNDPROC)DefWindowProc;
957 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
958 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
959 wc.hbrBackground = NULL;
960 wc.lpszMenuName = NULL;
961 wc.lpszClassName = lpszClassWindowSurface;
968 rect.bottom = height;
969 AdjustWindowRect(&rect, (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU), False);
971 hWnd = CreateWindow(lpszClassWindowSurface, lpszClassWindowSurface,
972 (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU ),
973 rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
974 NULL, (HMENU)NULL, NULL, NULL);
979 pConn->active_win = hDC;
980 ShowWindow(hWnd,SW_HIDE);
981 set_association_clientdrawable_serverwnd(process, (void *) clientdrawable, (void *) hWnd);
987 /* pbuffer?? 위?? Window ????*/
988 static HDC create_pbwindow(void *fakepbuffer, ProcessStruct* process, int x, int y, int width, int height)
994 LPSTR lpszClassWindowSurface ="PBuffer";
996 wc.style = CS_HREDRAW | CS_VREDRAW;
997 wc.lpfnWndProc = (WNDPROC)DefWindowProc;
1000 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
1001 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
1002 wc.hbrBackground = NULL;
1003 wc.lpszMenuName = NULL;
1004 wc.lpszClassName = lpszClassWindowSurface;
1011 rect.bottom = height;
1012 AdjustWindowRect(&rect, (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU), False);
1014 hWnd = CreateWindow(lpszClassWindowSurface, lpszClassWindowSurface,
1015 (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU ),
1016 rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1017 NULL, (HMENU)NULL, NULL, NULL);
1022 ShowWindow(hWnd,SW_HIDE);
1023 set_association_fakepbuffer_pbufferwnd(process, fakepbuffer, (void *) hWnd);
1029 /* context?? ˤ?? Dummy Window ????*/
1030 static HDC create_cwindow(int fake_ctx, ProcessStruct* process, int x, int y, int width, int height)
1036 LPSTR lpszClassWindowSurface ="Context";
1038 wc.style = CS_HREDRAW | CS_VREDRAW;
1039 wc.lpfnWndProc = (WNDPROC)DefWindowProc;
1042 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
1043 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
1044 wc.hbrBackground = NULL;
1045 wc.lpszMenuName = NULL;
1046 wc.lpszClassName = lpszClassWindowSurface;
1053 rect.bottom = height;
1054 AdjustWindowRect(&rect, (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU), False);
1056 hWnd = CreateWindow(lpszClassWindowSurface, lpszClassWindowSurface,
1057 (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU ),
1058 rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1059 NULL, (HMENU)NULL, NULL, NULL);
1064 ShowWindow(hWnd,SW_HIDE);
1065 set_association_fakecontext_glxwnd(process, (void *) (long)fake_ctx, (void *)hWnd, (void *)hDC);
1071 static void destroy_glwindow(OGLS_Conn *pConn, HWND hWnd, HDC hDC )
1073 ReleaseDC( hWnd, hDC );
1074 DestroyWindow(hWnd);
1076 /*PostQuitMessage(0);*/
1078 if( pConn->active_win == hDC)
1079 pConn->active_win = 0;
1082 static int get_server_texture(ProcessStruct* process, unsigned int client_texture)
1084 unsigned int server_texture = 0;
1085 if (client_texture < 32768)
1087 server_texture = process->current_state->tabTextures[client_texture];
1091 fprintf(stderr, "invalid texture name %d\n", client_texture);
1093 return server_texture;
1096 static int get_server_list(ProcessStruct* process, unsigned int client_list)
1098 unsigned int server_list = 0;
1099 if (client_list < 32768)
1101 server_list = process->current_state->tabLists[client_list];
1105 fprintf(stderr, "invalid list name %d\n", client_list);
1110 static int get_server_buffer(ProcessStruct* process, unsigned int client_buffer)
1112 unsigned int server_buffer = 0;
1113 if (client_buffer < 32768)
1115 server_buffer = process->current_state->tabBuffers[client_buffer];
1119 fprintf(stderr, "invalid buffer name %d\n", client_buffer);
1121 return server_buffer;
1125 static void do_glClientActiveTextureARB(int texture)
1127 GET_EXT_PTR_NO_FAIL(void, glClientActiveTextureARB, (int));
1128 if (ptr_func_glClientActiveTextureARB)
1130 ptr_func_glClientActiveTextureARB(texture);
1136 * Translate the nth element of list from type to GLuint.
1139 translate_id(GLsizei n, GLenum type, const GLvoid * list)
1151 bptr = (GLbyte *) list;
1152 return (GLuint) *(bptr + n);
1153 case GL_UNSIGNED_BYTE:
1154 ubptr = (GLubyte *) list;
1155 return (GLuint) *(ubptr + n);
1157 sptr = (GLshort *) list;
1158 return (GLuint) *(sptr + n);
1159 case GL_UNSIGNED_SHORT:
1160 usptr = (GLushort *) list;
1161 return (GLuint) *(usptr + n);
1163 iptr = (GLint *) list;
1164 return (GLuint) *(iptr + n);
1165 case GL_UNSIGNED_INT:
1166 uiptr = (GLuint *) list;
1167 return (GLuint) *(uiptr + n);
1169 fptr = (GLfloat *) list;
1170 return (GLuint) *(fptr + n);
1172 ubptr = ((GLubyte *) list) + 2 * n;
1173 return (GLuint) *ubptr * 256 + (GLuint) * (ubptr + 1);
1175 ubptr = ((GLubyte *) list) + 3 * n;
1176 return (GLuint) * ubptr * 65536
1177 + (GLuint) *(ubptr + 1) * 256 + (GLuint) * (ubptr + 2);
1179 ubptr = ((GLubyte *) list) + 4 * n;
1180 return (GLuint) *ubptr * 16777216
1181 + (GLuint) *(ubptr + 1) * 65536
1182 + (GLuint) *(ubptr + 2) * 256 + (GLuint) * (ubptr + 3);
1189 static const char *opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
1195 static const char *delim = " \t\n\r/";
1203 if (!(*saveptr) || !(*n))
1208 for (; *n && strchr(delim, *s); s++, (*n)--) {
1209 if (*s == '/' && *n > 1) {
1213 } while (*n > 1 && s[1] != '\n' && s[1] != '\r');
1214 } else if (s[1] == '*') {
1217 } while (*n > 2 && (s[1] != '*' || s[2] != '/'));
1224 for (; *n && *s && !strchr(delim, *s); s++, (*n)--);
1231 ret = malloc(retlen + 1);
1234 while (retlen > 0) {
1235 if (*start == '/' && retlen > 1) {
1236 if (start[1] == '/') {
1239 } while (retlen > 1 && start[1] != '\n' && start[1] != '\r');
1242 } else if (start[1] == '*') {
1245 } while (retlen > 2 && (start[1] != '*' || start[2] != '/'));
1246 start += 3, retlen -= 3;
1250 *(p++) = *(start++), retlen--;
1257 static char *do_eglShaderPatch(const char *source, int length, int *patched_len)
1259 char *saveptr = NULL;
1264 length = strlen(source);
1267 int patched_size = length;
1268 char *patched = malloc(patched_size + 1);
1273 p = opengl_strtok(source, &length, &saveptr, NULL);
1274 for (; p; p = opengl_strtok(0, &length, &saveptr, p)) {
1275 if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5)) {
1277 } else if (!strncmp(p, "precision", 9)) {
1278 while ((p = opengl_strtok(0, &length, &saveptr, p)) && !strchr(p, ';'));
1280 if (!strncmp(p, "gl_MaxVertexUniformVectors", 26)) {
1281 p = "(gl_MaxVertexUniformComponents / 4)";
1282 } else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28)) {
1283 p = "(gl_MaxFragmentUniformComponents / 4)";
1284 } else if (!strncmp(p, "gl_MaxVaryingVectors", 20)) {
1285 p = "(gl_MaxVaryingFloats / 4)";
1288 int new_len = strlen(p);
1289 if (*patched_len + new_len > patched_size) {
1291 patched = realloc(patched, patched_size + 1);
1297 memcpy(patched + *patched_len, p, new_len);
1298 *patched_len += new_len;
1302 patched[*patched_len] = 0;
1303 /* check that we don't leave dummy preprocessor lines */
1304 for (sp = patched; *sp;) {
1305 for (; *sp == ' ' || *sp == '\t'; sp++);
1306 if (!strncmp(sp, "#define", 7)) {
1307 for (p = sp + 7; *p == ' ' || *p == '\t'; p++);
1308 if (*p == '\n' || *p == '\r' || *p == '/') {
1309 memset(sp, 0x20, 7);
1312 for (; *sp && *sp != '\n' && *sp != '\r'; sp++);
1313 for (; *sp == '\n' || *sp == '\r'; sp++);
1319 shadersrc_gles_to_gl(GLsizei count, const char** string, char **s, const GLint* length, GLint *l)
1323 for(i = 0; i < count; ++i) {
1328 len = string[i] ? strlen(string[i]) : 0;
1330 len = string[i] ? strlen(string[i]) : 0;
1333 s[i] = do_eglShaderPatch(string[i], len, &l[i]);
1352 int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
1356 const char* ret_str = NULL;
1358 ProcessStruct* process = NULL;
1359 ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
1361 for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
1363 ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
1364 if (processTab[iProcess].process_id == pid)
1366 process = &processTab[iProcess];
1369 else if (processTab[iProcess].process_id == 0)
1371 process = &processTab[iProcess];
1372 memset(process, 0, sizeof(ProcessStruct));
1373 process->process_id = pid;
1374 process->internal_num = pConn->last_assigned_internal_num++;
1375 init_gl_state(&process->default_state);
1376 process->current_state = &process->default_state;
1380 if (process == NULL)
1382 fprintf(stderr, "Too many processes !\n");
1386 if (process->internal_num != pConn->last_active_internal_num)
1388 wglMakeCurrent(process->current_state->drawable, process->current_state->context);
1389 pConn->last_active_internal_num = process->internal_num;
1392 process->instr_counter++;
1393 if (display_function_call) fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
1395 #if defined( _MK_DBG_ )
1396 //printf(" %s Function(%d) \n", tab_opengl_calls_name[func_number], func_number);
1399 switch (func_number)
1407 case _synchronize_func:
1413 case _exit_process_func:
1419 PbufferInfo *pb_info;
1421 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
1423 hRC = process->association_fakecontext_glxcontext[i].value;
1424 hWnd = (HWND) process->association_fakecontext_glxcontext[i].hWnd;
1425 hDC = (HDC) process->association_fakecontext_glxcontext[i].cDC;
1427 fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
1428 (long)process->association_fakecontext_glxcontext[i].key);
1430 wglDeleteContext(hRC);
1431 ReleaseDC(hWnd, hDC);
1432 DestroyWindow(hWnd);
1435 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
1437 hWnd = (HWND) process->association_fakepbuffer_pbuffer[i].hWnd;
1438 hDC = (HDC)process->association_fakepbuffer_pbuffer[i].value;
1439 pb_info = (PbufferInfo *) process->association_fakepbuffer_pbuffer[i].cDC;
1441 fprintf(stderr, "Destroy pbuffer corresponding to client_drawable = %p\n",
1442 process->association_fakepbuffer_pbuffer[i].key);
1444 free(pb_info->backBuffer);
1447 ReleaseDC(hWnd, hDC);
1448 DestroyWindow(hWnd);
1451 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL; i++)
1453 hWnd = (HWND) process->association_clientdrawable_serverdrawable[i].hWnd;
1454 hDC = (HDC)process->association_clientdrawable_serverdrawable[i].value;
1456 fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
1457 process->association_clientdrawable_serverdrawable[i].key);
1459 ReleaseDC(hWnd, hDC);
1460 DestroyWindow(hWnd);
1463 for(i=0;i<process->nfbconfig;i++)
1465 free(process->fbconfigs[i]);
1468 for(i=0;i<process->nbGLStates;i++)
1470 destroy_gl_state(process->glstates[i]);
1471 free(process->glstates[i]);
1474 destroy_gl_state(&process->default_state);
1475 free(process->glstates);
1477 pConn->active_win = 0;
1479 memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
1481 last_process_id = 0;
1486 case _changeWindowState_func:
1488 HDC client_drawable = (HDC) args[0];
1489 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
1491 HWND hWnd = get_association_clientdrawable_serverwnd(process, client_drawable);
1492 if (hWnd && (args[1] == IsViewable))
1494 ShowWindow(hWnd, SW_SHOW);
1500 case _moveResizeWindow_func:
1502 int* params = (int*)args[1];
1503 HDC client_drawable = (HDC)args[0];
1504 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
1506 HWND hWnd = get_association_clientdrawable_serverwnd(process, client_drawable);
1509 WindowPosStruct pos;
1510 _get_window_pos(hWnd, &pos);
1511 if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
1513 int redim = !(params[2] == pos.width && params[3] == pos.height);
1514 pConn->active_win_x = params[0];
1515 pConn->active_win_y = params[1];
1517 //fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
1518 //fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
1522 MoveWindow(hWnd, params[0], params[1], params[2], params[3], False);
1523 _get_window_pos(hWnd, &pos);
1524 process->currentDrawablePos = pos;
1526 glViewport(0, 0, pos.width, pos.height);
1533 case _send_cursor_func:
1535 fprintf(stderr, "_send_cursor_func not support \n");
1539 case glXWaitGL_func:
1551 case glXGetFBConfigs_func:
1555 fprintf(stderr, "glXGetFBConfigs not support \n");
1563 case glXChooseFBConfig_func:
1564 case glXChooseFBConfigSGIX_func:
1567 WGLFBConfig *fbConfigs, *c;
1570 if (process->nfbconfig == MAX_FBCONFIG)
1577 hdc = (HDC) pConn->Display;
1579 if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
1582 PIXELFORMATDESCRIPTOR pfd;
1583 for (j = i = 0; i < n; i++)
1585 DescribePixelFormat(hdc, i, sizeof pfd, &pfd);
1586 if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) continue;
1587 if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW)) continue;
1588 if (!(pfd.dwFlags & PFD_DOUBLEBUFFER)) continue;
1589 if (pfd.iPixelType != PFD_TYPE_RGBA) continue;
1593 c = fbConfigs = (WGLFBConfig *)malloc(sizeof(WGLFBConfig) * j);
1595 for (i = 0; i < n; i++) {
1596 DescribePixelFormat(hdc, i, sizeof pfd, &pfd);
1597 if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) continue;
1598 if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW)) continue;
1599 if (!(pfd.dwFlags & PFD_DOUBLEBUFFER)) continue;
1600 if (pfd.iPixelType != PFD_TYPE_RGBA) continue;
1602 c->visualID = i + 1;
1603 memcpy(&c->pfd, &pfd, sizeof(PIXELFORMATDESCRIPTOR));
1604 #if defined( _MK_DBG_ ) /* by 19.Nov.2009 */
1605 printf("Choose Config:0x%p VisualID : %d\n ",c, c->visualID);
1614 process->fbconfigs[process->nfbconfig] = fbConfigs;
1615 process->fbconfigs_max[process->nfbconfig] = *(int*)args[3];
1616 process->nfbconfig++;
1617 ret_int = 1 + process->nfbconfig_total;
1618 process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
1620 #if defined( _MK_DBG_ )
1621 printf(" DescribePixelFormat Num : %d \n", j);
1634 printf(" DescribePixelFormat - NULL \n");
1642 case glXGetFBConfigAttrib_func:
1643 case glXGetFBConfigAttribSGIX_func:
1645 int client_pfd = args[1];
1646 WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
1651 ret_int = get_pfdAttrib(&fbConfig->pfd, args[2], (int*)args[3]);
1656 case glXGetFBConfigAttrib_extended_func:
1658 int client_pfd = args[1];
1661 int* attribs = (int*)args[3];
1662 int* values = (int*)args[4];
1663 int* res = (int*)args[5];
1664 WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
1670 res[i] = get_pfdAttrib(&fbConfig->pfd, attribs[i], &values[i]);
1680 case glXGetVisualFromFBConfig_func:
1682 int client_pfd = args[1];
1684 unsigned int visualid;
1685 WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
1691 visualid = fbConfig->visualID;
1694 AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
1695 for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
1697 if( i >= pConn->nTabAssocAttribListVisual )
1699 pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
1700 realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
1702 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
1703 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
1704 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = visualid;
1705 pConn->nTabAssocAttribListVisual++;
1708 if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
1714 case glXCreateNewContext_func:
1716 int client_pfd = args[1];
1717 WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
1720 #if defined( _MK_DBG_ )
1721 printf(" Config 0x%p - client_pfd %d \n", fbConfig, client_pfd);
1726 int fake_shareList = args[3];
1728 HGLRC shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
1729 int fake_ctxt = process->next_available_context_number + 1;
1730 HDC hdc = create_cwindow(fake_ctxt, process, 0, 0, 10, 10);
1732 if(SetPixelFormat(hdc, fbConfig->visualID - 1, NULL))
1734 ctxt = wglCreateContext (hdc);
1735 #if defined( _MK_DBG_ )
1736 printf("HGLRC 0x%p = wglCreateNewContext(HDC 0x%p) visualID:%d fake_ctx:%d\n", ctxt, hdc, fbConfig->visualID, fake_ctxt);
1741 process->next_available_context_number ++;
1742 set_association_fakecontext_visualid(process, (void*)(long)fake_ctxt, fbConfig->visualID);
1743 set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
1744 _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
1745 ret_int = fake_ctxt;
1753 for(i=0; i < MAX_ASSOC_SIZE; i++)
1755 if (process->association_fakecontext_glxcontext[i].key == (void *) (long)fake_ctxt)
1757 process->association_fakecontext_glxcontext[i].key = NULL;
1758 process->association_fakecontext_glxcontext[i].value = NULL;
1759 process->association_fakecontext_glxcontext[i].hWnd = NULL;
1760 process->association_fakecontext_glxcontext[i].cDC= NULL;
1764 printf("wglCreateContext Fail - HDC: 0x%p, visual ID: %d, Error : %d \n", hdc, fbConfig->visualID, (unsigned int)GetLastError());
1771 case glXCreateContext_func:
1773 int visualid = (int)args[1];
1774 int fake_shareList = (int)args[2];
1775 PIXELFORMATDESCRIPTOR pfd;
1776 HGLRC shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
1778 int fake_ctxt = process->next_available_context_number + 1;
1779 HDC hdc = create_cwindow(fake_ctxt, process, 0, 0, 10, 10);
1783 if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
1785 if(get_visual_info_from_visual_id(pConn, visualid, &pfd))
1787 SetPixelFormat(hdc, visualid - 1, &pfd);
1788 ctxt = wglCreateContext (hdc);
1792 if((visualid = get_default_visual(pConn->Display, &pfd)))
1794 SetPixelFormat(hdc, visualid - 1, &pfd);
1795 ctxt = wglCreateContext (hdc);
1799 printf("HGLRC 0x%p = wglCreateContext(HDC 0x%p) visualID:%d \n", ctxt, hdc, visualid);
1803 process->next_available_context_number ++;
1804 set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
1805 set_association_fakecontext_visualid(process, (void*)(long)fake_ctxt, visualid);
1806 _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
1807 ret_int = fake_ctxt;
1814 for(i=0; i < MAX_ASSOC_SIZE; i++)
1816 if (process->association_fakecontext_glxcontext[i].key == (void *) (long)fake_ctxt)
1818 process->association_fakecontext_glxcontext[i].key = NULL;
1819 process->association_fakecontext_glxcontext[i].value = NULL;
1820 process->association_fakecontext_glxcontext[i].hWnd = NULL;
1821 process->association_fakecontext_glxcontext[i].cDC= NULL;
1825 printf("wglCreateContext Fail - HDC: 0x%p, visual ID: %d, Error : %d \n", hdc, visualid, (unsigned int)GetLastError());
1831 case glXMakeCurrent_func:
1834 HDC client_drawable = (HDC)args[1];
1836 PIXELFORMATDESCRIPTOR pfd;
1837 int fake_ctxt = args[2];
1838 unsigned int visualid = 0;
1840 if (display_function_call) fprintf(stderr, "client_drawable=%p fake_ctx=%d\n", (void*)client_drawable, fake_ctxt);
1842 if (client_drawable == 0 && fake_ctxt == 0)
1844 ret_int = wglMakeCurrent(NULL, NULL);
1846 process->current_state = &process->default_state;
1848 else if ((drawable = (HDC)get_association_fakepbuffer_pbuffer(process, (void*)client_drawable)))
1850 HGLRC ctxt = (HGLRC)get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
1851 PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void*)client_drawable);
1855 fprintf(stderr, "invalid fake_ctxt (%d) (*)!\n", fake_ctxt);
1862 pb_info->context = ctxt;
1865 visualid = get_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
1868 /*DescribePixelFormat((HDC)dpy, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), &pfd);*/
1870 if(SetPixelFormat(drawable, visualid - 1, &pfd))
1872 ret_int = wglMakeCurrent(drawable, ctxt);
1873 #if defined( _MK_DBG_ )
1874 printf("%d = wglMakeCurrentPBuffer(HDC 0x%p, HGLRC 0x%p) - visualID:%d client_drawable:0x%p\n", ret_int, drawable, ctxt, visualid, client_drawable);
1879 fprintf(stderr, "SetPixelFormat Error......\n");
1892 HGLRC ctxt = (HGLRC)get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
1895 fprintf(stderr, "invalid fake_ctxt (%d)!\n", fake_ctxt);
1900 visualid = get_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
1904 visualid = get_default_visual(pConn->Display, &pfd);
1907 drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
1911 drawable = create_swindow(pConn, client_drawable, process, 0, 0, 480, 800);
1912 set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
1915 /*DescribePixelFormat((HDC)dpy, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), &pfd);*/
1916 if(SetPixelFormat(drawable, visualid - 1, &pfd))
1918 ret_int = wglMakeCurrent(drawable, ctxt);
1919 #if defined( _MK_DBG_ )
1920 printf("%d = wglMakeCurrent(HDC 0x%p, HGLRC 0x%p) - visualID:%d client_drawable:0x%p\n", ret_int, drawable, ctxt, visualid, client_drawable);
1925 fprintf(stderr, "SetPixelFormat Error......\n");
1933 for(i=0;i<process->nbGLStates;i++)
1935 if (process->glstates[i]->fake_ctxt == fake_ctxt)
1937 process->current_state = process->glstates[i]; /* HACK !!! REMOVE */
1938 process->current_state->drawable = drawable;
1946 case glXGetConfig_func:
1948 int visualid = args[1];
1949 PIXELFORMATDESCRIPTOR pfd;
1953 if( get_visual_info_from_visual_id(pConn, visualid, &pfd))
1955 ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
1959 if( get_default_visual(pConn->Display, &pfd))
1960 ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
1962 ret_int = GLX_BAD_VISUAL;
1967 if( get_default_visual(pConn->Display, &pfd))
1968 ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
1970 ret_int = GLX_BAD_VISUAL;
1976 case glXChooseVisual_func:
1978 PIXELFORMATDESCRIPTOR pfd;
1979 unsigned int visualid = 0;
1980 AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
1984 if ((int*)args[2] == NULL)
1987 visualid = get_default_visual(pConn->Display, &pfd);
1989 for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
1991 if( i >= pConn->nTabAssocAttribListVisual ) {
1992 pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
1993 realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
1995 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
1996 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
1997 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = i;
1998 pConn->nTabAssocAttribListVisual++;
2005 case glXDestroyWindow_func:
2008 HDC client_drawable = (HDC)args[1];
2009 HDC drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
2010 HWND hWnd = get_association_clientdrawable_serverwnd( process, client_drawable);
2012 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
2014 if( drawable && hWnd )
2016 destroy_glwindow(pConn, hWnd, drawable);
2018 #if defined( _MK_DBG_ )
2019 printf("DestoryWindw( HWND 0x%p, HDC 0x%p) Client Drawable 0x%p\n", hWnd, drawable, client_drawable);
2022 unset_association_clientdrawable_serverdrawable(process, (void *) (long)client_drawable);
2024 for(i=0;i<process->nbGLStates;i++)
2026 if (process->glstates[i]->drawable == drawable)
2028 process->glstates[i]->drawable = 0;
2032 if( process->current_state->drawable == drawable )
2033 process->current_state = &process->default_state;
2040 case glXDestroyContext_func:
2042 int fake_ctxt = (int)args[1];
2045 HGLRC ctxt = (HGLRC)get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
2047 if (display_function_call) fprintf(stderr, "fake_ctxt=%d\n", fake_ctxt);
2051 fprintf(stderr, "invalid fake_ctxt (%p) !\n", (void*)(long)fake_ctxt);
2056 for(i=0;i<process->nbGLStates;i++)
2058 if (process->glstates[i]->fake_ctxt == fake_ctxt)
2060 if (ctxt == process->current_state->context)
2061 process->current_state = &process->default_state;
2063 int fake_shareList = process->glstates[i]->fake_shareList;
2064 process->glstates[i]->ref --;
2065 if (process->glstates[i]->ref == 0)
2067 fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
2068 destroy_gl_state(process->glstates[i]);
2069 free(process->glstates[i]);
2070 memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
2071 process->nbGLStates--;
2076 for(i=0;i<process->nbGLStates;i++)
2078 if (process->glstates[i]->fake_ctxt == fake_shareList)
2080 process->glstates[i]->ref --;
2081 if (process->glstates[i]->ref == 0)
2083 fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
2084 destroy_gl_state(process->glstates[i]);
2085 free(process->glstates[i]);
2086 memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
2087 process->nbGLStates--;
2094 wglDeleteContext(ctxt);
2096 get_association_fakecontext_glxwnd(process, (void*)(long)fake_ctxt, hWnd, hdc);
2097 destroy_glwindow(pConn, hWnd, hdc);
2099 unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
2100 unset_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
2102 #if defined( _MK_DBG_ )
2103 printf("Destory Context Window ( WHND 0x%p, HRC 0x%p)", hWnd, hdc);
2104 printf("wglDestroyContext(HGLRC 0x%p) - fake context : %d\n", ctxt, fake_ctxt);
2113 case glXGetProcAddress_fake_func:
2115 char *fun_name = (char*)args[0];
2116 if (display_function_call) fprintf(stderr, "%s\n", fun_name);
2122 case glXGetProcAddress_global_fake_func:
2124 int nbElts = args[0];
2125 char* huge_buffer = (char*)args[1];
2126 char* result = (char*)args[2];
2128 for(i=0;i<nbElts;i++)
2130 int len = strlen(huge_buffer);
2133 huge_buffer += len + 1;
2138 case glXSwapBuffers_func:
2140 HDC client_drawable = (HDC)args[1];
2141 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
2143 HDC drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
2146 fprintf(stderr, "unknown client_drawable (%p) !\n", (void*)client_drawable);
2150 #if defined( _MK_DBG_ ) /* by 20.Nov.2009 */
2151 printf("SwapBuffers( HDC 0x%p)\n", drawable);
2153 SwapBuffers(drawable);
2158 case glXQueryVersion_func:
2160 int *pMajorVersion = (int *)args[1];
2161 int *pMinorVersion = (int *)args[2];
2164 rVersion = GetVersion();
2166 *pMajorVersion = (rVersion & 0x0000FF00) >> 8;
2167 *pMinorVersion = rVersion & 0x000000FF;
2170 #if defined( _MK_DBG_ ) /* by 20.Nov.2009 */
2171 printf(" Major Version : %d - Minor Version : %d \n",*pMajorVersion, *pMinorVersion);
2176 case glXQueryExtensionsString_func:
2179 fprintf(stderr, "glXQueryExtensionsString not support (Current WIN32 System)\n");
2184 case glXGetClientString_func:
2186 static char *ventor = "support WGL of Microsoft Corporation";
2187 ret_str = ventor;//glXGetClientString(dpy, args[1]);
2191 case glXQueryServerString_func:
2193 static char *ventor = "support WGL of Microsoft Corporation";
2194 ret_str = ventor; //glXQueryServerString(dpy, 0, args[2]);
2198 case glXGetScreenDriver_func:
2200 fprintf(stderr, "glXGetScreenDriver not support (Current WIN32 System)\n");
2205 case glXGetDriverConfig_func:
2207 fprintf(stderr, "glXGetDriverConfig not support (Current WIN32 System)\n");
2212 case glXCreatePbuffer_func:
2214 int client_fbconfig = args[1];
2215 int pb_width = 0, pb_height = 0;
2216 int *attrib_list = (int*)args[2];
2217 int fake_pbuffer = process->next_available_pbuffer_number + 1;
2219 WGLFBConfig *fbconfig = get_pfDescriptor(process, client_fbconfig);
2223 while (attrib_list && *attrib_list != GLX_NONE) {
2224 switch (*attrib_list++) {
2226 pb_width = *attrib_list++;
2230 pb_height = *attrib_list++;
2240 pbuffer = create_pbwindow((void *) ( fake_pbuffer), process, 0, 0, pb_width, pb_height);
2242 #if defined( _MK_DBG_ )
2243 printf(" pbuffer 0x%p = Create_pbwindow( fakebuffer : %d , width : %d, height : %d\n", pbuffer, fake_pbuffer, pb_width, pb_height);
2248 PbufferInfo *pb_info = (PbufferInfo *)malloc( sizeof(PbufferInfo) );
2249 memset((void *) pb_info, 0, sizeof(PbufferInfo));
2251 process->next_available_pbuffer_number ++;
2252 set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
2253 ret_int = fake_pbuffer;
2255 pb_info->width = pb_width;
2256 pb_info->height = pb_height;
2257 pb_info->colorFormat = GLX_RGBA;
2258 get_pfdAttrib(&fbconfig->pfd, GLX_BUFFER_SIZE, &pb_info->colorBits);
2260 pb_info->backBuffer = malloc( pb_width * pb_height * sizeof(int));
2261 set_association_fakepbuffer_pbinfo( process, (void *)(long)fake_pbuffer, (void *) pb_info );
2268 case glXCreateGLXPbufferSGIX_func:
2270 int client_fbconfig = args[1];
2271 int pb_width = 0, pb_height = 0;
2272 int fake_pbuffer = process->next_available_pbuffer_number + 1;
2274 WGLFBConfig *fbconfig = get_pfDescriptor(process, client_fbconfig);
2279 pb_height = args[3];
2283 pbuffer = create_pbwindow((void *) ( fake_pbuffer), process, 0, 0, pb_width, pb_height);
2284 #if defined( _MK_DBG_ )
2285 printf(" pbuffer 0x%p = Create_pbwindow( fakebuffer : %d , width : %d, height : %d\n", pbuffer, fake_pbuffer, pb_width, pb_height);
2289 PbufferInfo *pb_info = (PbufferInfo *)malloc( sizeof(PbufferInfo) );
2290 memset((void *) pb_info, 0, sizeof(PbufferInfo));
2292 process->next_available_pbuffer_number ++;
2293 set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
2294 ret_int = fake_pbuffer;
2296 pb_info->width = pb_width;
2297 pb_info->height = pb_height;
2298 pb_info->colorFormat = GLX_RGBA;
2299 get_pfdAttrib(&fbconfig->pfd, GLX_BUFFER_SIZE, &pb_info->colorBits);
2301 pb_info->backBuffer = malloc( pb_width * pb_height * sizeof(int));
2302 set_association_fakepbuffer_pbinfo( process, (void *)(long)fake_pbuffer, (void *) pb_info );
2309 case glXDestroyPbuffer_func:
2310 case glXDestroyGLXPbufferSGIX_func:
2312 HDC fakepbuffer = (HDC)args[1];
2313 HDC pbuffer = get_association_fakepbuffer_pbuffer(process, (void *)fakepbuffer);
2314 HWND hWnd = get_association_fakepbuffer_pbufferwnd( process, (void *)fakepbuffer);
2315 PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void *) fakepbuffer);
2317 if( pbuffer && hWnd )
2321 free(pb_info->backBuffer);
2325 destroy_glwindow(pConn, hWnd, pbuffer);
2327 #if defined( _MK_DBG_ )
2328 printf("DestoryPbuffer( HWND 0x%p, HDC 0x%p) fake pbuffer 0x%p\n", hWnd, pbuffer, fakepbuffer);
2331 unset_association_fakepbuffer_pbuffer(process, (void *) (long)fakepbuffer);
2337 case glXBindTexImageARB_func:
2338 case glXBindTexImageATI_func:
2340 HGLRC pb_context, cur_context;
2341 HDC pb_drawable, cur_drawable;
2342 int fake_pbuffer = (int)args[1];
2343 PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void *) (long) fake_pbuffer);
2350 pb_context = pb_info->context;
2351 pb_drawable =get_association_fakepbuffer_pbuffer(process, (void *) (long) fake_pbuffer);
2353 if( pb_context && pb_drawable )
2355 cur_context = wglGetCurrentContext( );
2356 cur_drawable = wglGetCurrentDC( );
2358 wglMakeCurrent(pb_drawable, pb_context);
2359 glReadPixels(0, 0, pb_info->width, pb_info->height, pb_info->colorFormat, GL_UNSIGNED_BYTE, pb_info->backBuffer);
2360 wglMakeCurrent(cur_drawable, cur_context);
2362 glTexImage2D(GL_TEXTURE_2D, 0, pb_info->colorFormat, pb_info->width, pb_info->height,
2363 0, pb_info->colorFormat, GL_UNSIGNED_BYTE, pb_info->backBuffer);
2368 fprintf(stderr, "glXBindTexImage Error - pbuffer Null...\n");
2374 fprintf(stderr, "glXBindTexImage Error - pbuffer information Null...\n");
2383 case glXReleaseTexImageARB_func:
2384 case glXReleaseTexImageATI_func:
2386 int fake_pbuffer = (int)args[1];
2387 HDC pbuffer = get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
2388 PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void*)fake_pbuffer);
2396 glTexImage2D(GL_TEXTURE_2D, 0, pb_info->colorFormat, pb_info->width, pb_info->height, 0, pb_info->colorFormat, GL_UNSIGNED_BYTE, NULL);
2401 fprintf(stderr, "glXReleaseTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
2406 fprintf(stderr, "glXReleaseTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
2412 case glXQueryContext_func:
2415 fprintf(stderr, "glXCreateGLXPbufferSGIX not support (Current WIN32 System)\n");
2419 case glXQueryDrawable_func:
2421 fprintf(stderr, "glXQueryDrawable not support \n");
2428 case glXQueryGLXPbufferSGIX_func:
2432 fprintf(stderr, "glXCreateGLXPbufferSGIX not support (Current WIN32 System)\n");
2436 case glXCreateContextWithConfigSGIX_func:
2440 fprintf(stderr, "glXCreateContextWithConfigSGIX not support (Current WIN32 System)\n");
2444 case glXSwapIntervalSGI_func:
2448 fprintf(stderr, "glXSwapIntervalSGI not support (Current WIN32 System)\n");
2452 case glXCopyContext_func:
2454 HGLRC fake_src_ctxt = (HGLRC)args[1];
2455 HGLRC fake_dst_ctxt = (HGLRC)args[2];
2457 if (display_function_call) fprintf(stderr, "fake_src_ctxt=%p, fake_dst_ctxt=%p\n", fake_src_ctxt, fake_dst_ctxt);
2459 fprintf(stderr, "glXCopyContext not support (Current WIN32 System)\n");
2463 case glXIsDirect_func:
2466 fprintf(stderr, "glXCopyContext not support (Current WIN32 System)\n");
2470 case glGetString_func:
2472 ret_str = (char*)glGetString(args[0]);
2476 /* Begin of texture stuff */
2477 case glBindTexture_func:
2478 case glBindTextureEXT_func:
2480 int target = args[0];
2481 unsigned int client_texture = args[1];
2482 unsigned int server_texture;
2484 if (client_texture == 0)
2486 glBindTexture(target, 0);
2490 alloc_value(process->current_state->textureAllocator, client_texture);
2491 server_texture = process->current_state->tabTextures[client_texture];
2492 if (server_texture == 0)
2494 glGenTextures(1, &server_texture);
2495 process->current_state->tabTextures[client_texture] = server_texture;
2497 glBindTexture(target, server_texture);
2502 case glGenTextures_fake_func:
2504 //GET_EXT_PTR(void, glGenTextures, (GLsizei n, GLuint *textures));
2507 unsigned int* clientTabTextures = malloc(n * sizeof(int));
2508 unsigned int* serverTabTextures = malloc(n * sizeof(int));
2510 alloc_range(process->current_state->textureAllocator, n, clientTabTextures);
2512 glGenTextures(n, serverTabTextures);
2515 process->current_state->tabTextures[clientTabTextures[i]] = serverTabTextures[i];
2518 free(clientTabTextures);
2519 free(serverTabTextures);
2523 case glDeleteTextures_func:
2525 //GET_EXT_PTR(void, glDeleteTextures, (GLsizei n, const GLuint *textures));
2528 unsigned int* clientTabTextures = (unsigned int*)args[1];
2530 delete_range(process->current_state->textureAllocator, n, clientTabTextures);
2532 unsigned int* serverTabTextures = malloc(n * sizeof(int));
2535 serverTabTextures[i] = get_server_texture(process, clientTabTextures[i]);
2537 glDeleteTextures(n, serverTabTextures);
2540 process->current_state->tabTextures[clientTabTextures[i]] = 0;
2542 free(serverTabTextures);
2546 case glPrioritizeTextures_func:
2548 GET_EXT_PTR(void, glPrioritizeTextures, (GLsizei n, const GLuint *textures, const GLclampf *priorities));
2552 unsigned int* textures = (unsigned int*)args[1];
2555 textures[i] = get_server_texture(process, textures[i]);
2557 ptr_func_glPrioritizeTextures(n, textures, (const GLclampf*)args[2]);
2561 case glAreTexturesResident_func:
2563 GET_EXT_PTR(void, glAreTexturesResident, (GLsizei n, const GLuint *textures, GLboolean *residences));
2566 unsigned int* textures = (unsigned int*)args[1];
2569 textures[i] = get_server_texture(process, textures[i]);
2571 ptr_func_glAreTexturesResident(n, textures, (GLboolean*)args[2]);
2575 case glIsTexture_func:
2576 case glIsTextureEXT_func:
2578 GET_EXT_PTR(GLboolean, glIsTexture, (GLuint texture ));
2579 unsigned int client_texture = args[0];
2580 unsigned int server_texture = get_server_texture(process, client_texture);
2582 ret_char = ptr_func_glIsTexture(server_texture);
2588 case glFramebufferTexture1DEXT_func:
2590 GET_EXT_PTR(void, glFramebufferTexture1DEXT, (int, int, int, int, int));
2591 unsigned int client_texture = args[3];
2592 unsigned int server_texture = get_server_texture(process, client_texture);
2594 ptr_func_glFramebufferTexture1DEXT(args[0], args[1], args[2], server_texture, args[4]);
2598 case glFramebufferTexture2DEXT_func:
2600 GET_EXT_PTR(void, glFramebufferTexture2DEXT, (int, int, int, int, int));
2601 unsigned int client_texture = args[3];
2602 unsigned int server_texture = get_server_texture(process, client_texture);
2604 ptr_func_glFramebufferTexture2DEXT(args[0], args[1], args[2], server_texture, args[4]);
2608 case glFramebufferTexture3DEXT_func:
2610 GET_EXT_PTR(void, glFramebufferTexture3DEXT, (int, int, int, int, int, int));
2611 unsigned int client_texture = args[3];
2612 unsigned int server_texture = get_server_texture(process, client_texture);
2614 ptr_func_glFramebufferTexture3DEXT(args[0], args[1], args[2], server_texture, args[4], args[5]);
2617 /* End of texture stuff */
2619 /* Begin of list stuff */
2622 unsigned int client_list = args[0];
2623 unsigned int server_list = get_server_list(process, client_list);
2625 ret_char = glIsList(server_list);
2631 case glDeleteLists_func:
2634 unsigned int first_client = args[0];
2637 unsigned int first_server = get_server_list(process, first_client);
2640 if (get_server_list(process, first_client + i) != first_server + i)
2645 glDeleteLists(first_server, n);
2651 glDeleteLists(get_server_list(process, first_client + i), 1);
2657 process->current_state->tabLists[first_client + i] = 0;
2659 delete_consecutive_values(process->current_state->listAllocator, first_client, n);
2663 case glGenLists_fake_func:
2667 unsigned int server_first = glGenLists(n);
2670 unsigned int client_first = alloc_range(process->current_state->listAllocator, n, NULL);
2673 process->current_state->tabLists[client_first + i] = server_first + i;
2679 case glNewList_func:
2681 unsigned int client_list = args[0];
2683 alloc_value(process->current_state->listAllocator, client_list);
2684 unsigned int server_list = get_server_list(process, client_list);
2685 if (server_list == 0)
2687 server_list = glGenLists(1);
2688 process->current_state->tabLists[client_list] = server_list;
2690 glNewList(server_list, mode);
2694 case glCallList_func:
2696 unsigned int client_list = args[0];
2697 unsigned int server_list = get_server_list(process, client_list);
2698 glCallList(server_list);
2702 case glCallLists_func:
2707 const GLvoid* lists = (const GLvoid*)args[2];
2708 int* new_lists = malloc(sizeof(int) * n);
2711 new_lists[i] = get_server_list(process, translate_id(i, type, lists));
2713 glCallLists(n, GL_UNSIGNED_INT, new_lists);
2717 /* End of list stuff */
2719 /* Begin of buffer stuff */
2720 case glBindBufferARB_func:
2722 GET_EXT_PTR(void, glBindBufferARB, (int,int));
2723 int target = args[0];
2724 unsigned int client_buffer = args[1];
2725 unsigned int server_buffer;
2727 if (client_buffer == 0)
2729 ptr_func_glBindBufferARB(target, 0);
2733 server_buffer = get_server_buffer(process, client_buffer);
2734 ptr_func_glBindBufferARB(target, server_buffer);
2739 case glGenBuffersARB_fake_func:
2741 GET_EXT_PTR(void, glGenBuffersARB, (int,unsigned int*));
2744 unsigned int* clientTabBuffers = malloc(n * sizeof(int));
2745 unsigned int* serverTabBuffers = malloc(n * sizeof(int));
2747 alloc_range(process->current_state->bufferAllocator, n, clientTabBuffers);
2749 ptr_func_glGenBuffersARB(n, serverTabBuffers);
2752 process->current_state->tabBuffers[clientTabBuffers[i]] = serverTabBuffers[i];
2755 free(clientTabBuffers);
2756 free(serverTabBuffers);
2761 case glDeleteBuffersARB_func:
2763 GET_EXT_PTR(void, glDeleteBuffersARB, (int,int*));
2766 unsigned int* clientTabBuffers = (unsigned int*)args[1];
2768 delete_range(process->current_state->bufferAllocator, n, clientTabBuffers);
2770 int* serverTabBuffers = malloc(n * sizeof(int));
2773 serverTabBuffers[i] = get_server_buffer(process, clientTabBuffers[i]);
2775 ptr_func_glDeleteBuffersARB(n, serverTabBuffers);
2778 process->current_state->tabBuffers[clientTabBuffers[i]] = 0;
2780 free(serverTabBuffers);
2784 case glIsBufferARB_func:
2786 GET_EXT_PTR(int, glIsBufferARB, (int));
2787 unsigned int client_buffer = args[0];
2788 unsigned int server_buffer = get_server_buffer(process, client_buffer);
2790 ret_int = ptr_func_glIsBufferARB(server_buffer);
2795 /* Endo of buffer stuff */
2797 case glShaderSourceARB_fake_func:
2799 GET_EXT_PTR(void, glShaderSourceARB, (int,int,char**,void*));
2803 GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
2804 int* tab_length = (int*)args[3];
2807 tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
2808 acc_length += tab_length[i];
2810 ptr_func_glShaderSourceARB(args[0], args[1], tab_prog, tab_length);
2815 case glShaderSource_fake_func:
2817 GET_EXT_PTR(void, glShaderSource, (int,int,char**,void*));
2821 GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
2822 int* tab_length = (int*)args[3];
2824 char **tab_prog_new;
2825 GLint *tab_length_new;
2827 tab_prog_new = malloc(args[1]* sizeof(char*));
2828 tab_length_new = malloc(args[1]* sizeof(GLint));
2830 memset(tab_prog_new, 0, args[1] * sizeof(char*));
2831 memset(tab_length_new, 0, args[1] * sizeof(GLint));
2836 tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
2837 acc_length += tab_length[i];
2840 shadersrc_gles_to_gl(args[1], tab_prog, tab_prog_new, tab_length, tab_length_new);
2842 if (!tab_prog_new || !tab_length_new)
2845 ptr_func_glShaderSource(args[0], args[1], tab_prog_new, tab_length_new);
2847 for (i = 0; i < args[1]; i++)
2848 free(tab_prog_new[i]);
2850 free(tab_length_new);
2856 case glVertexPointer_fake_func:
2858 int offset = args[0];
2861 int stride = args[3];
2862 int bytes_size = args[4];
2863 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
2864 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
2865 memcpy(process->current_state->vertexPointer + offset, (void*)args[5], bytes_size);
2866 /*fprintf(stderr, "glVertexPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
2867 size, type, stride, bytes_size);*/
2868 glVertexPointer(size, type, stride, process->current_state->vertexPointer);
2872 case glNormalPointer_fake_func:
2874 int offset = args[0];
2876 int stride = args[2];
2877 int bytes_size = args[3];
2878 process->current_state->normalPointerSize = MAX(process->current_state->normalPointerSize, offset + bytes_size);
2879 process->current_state->normalPointer = realloc(process->current_state->normalPointer, process->current_state->normalPointerSize);
2880 memcpy(process->current_state->normalPointer + offset, (void*)args[4], bytes_size);
2881 //fprintf(stderr, "glNormalPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
2882 glNormalPointer(type, stride, process->current_state->normalPointer);
2886 case glIndexPointer_fake_func:
2888 int offset = args[0];
2890 int stride = args[2];
2891 int bytes_size = args[3];
2892 process->current_state->indexPointerSize = MAX(process->current_state->indexPointerSize, offset + bytes_size);
2893 process->current_state->indexPointer = realloc(process->current_state->indexPointer, process->current_state->indexPointerSize);
2894 memcpy(process->current_state->indexPointer + offset, (void*)args[4], bytes_size);
2895 //fprintf(stderr, "glIndexPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
2896 glIndexPointer(type, stride, process->current_state->indexPointer);
2900 case glEdgeFlagPointer_fake_func:
2902 int offset = args[0];
2903 int stride = args[1];
2904 int bytes_size = args[2];
2905 process->current_state->edgeFlagPointerSize = MAX(process->current_state->edgeFlagPointerSize, offset + bytes_size);
2906 process->current_state->edgeFlagPointer = realloc(process->current_state->edgeFlagPointer, process->current_state->edgeFlagPointerSize);
2907 memcpy(process->current_state->edgeFlagPointer + offset, (void*)args[3], bytes_size );
2908 //fprintf(stderr, "glEdgeFlagPointer_fake_func stride = %d, bytes_size=%d\n", stride, bytes_size);
2909 glEdgeFlagPointer(stride, process->current_state->edgeFlagPointer);
2913 case glVertexAttribPointerARB_fake_func:
2915 GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
2916 int offset = args[0];
2917 int index = args[1];
2920 int normalized = args[4];
2921 int stride = args[5];
2922 int bytes_size = args[6];
2923 process->current_state->vertexAttribPointerSize[index] = MAX(process->current_state->vertexAttribPointerSize[index], offset + bytes_size);
2924 process->current_state->vertexAttribPointer[index] = realloc(process->current_state->vertexAttribPointer[index],
2925 process->current_state->vertexAttribPointerSize[index]);
2926 memcpy(process->current_state->vertexAttribPointer[index] + offset, (void*)args[7], bytes_size);
2927 ptr_func_glVertexAttribPointerARB(index, size, type, normalized, stride,
2928 process->current_state->vertexAttribPointer[index]);
2932 case glVertexAttribPointerNV_fake_func:
2934 GET_EXT_PTR(void, glVertexAttribPointerNV, (int,int,int,int,void*));
2935 int offset = args[0];
2936 int index = args[1];
2939 int stride = args[4];
2940 int bytes_size = args[5];
2941 process->current_state->vertexAttribPointerNVSize[index] = MAX(process->current_state->vertexAttribPointerNVSize[index], offset + bytes_size);
2942 process->current_state->vertexAttribPointerNV[index] = realloc(process->current_state->vertexAttribPointerNV[index],
2943 process->current_state->vertexAttribPointerNVSize[index]);
2944 memcpy(process->current_state->vertexAttribPointerNV[index] + offset, (void*)args[6], bytes_size);
2945 ptr_func_glVertexAttribPointerNV(index, size, type, stride,
2946 process->current_state->vertexAttribPointerNV[index]);
2950 case glColorPointer_fake_func:
2952 int offset = args[0];
2955 int stride = args[3];
2956 int bytes_size = args[4];
2957 process->current_state->colorPointerSize = MAX(process->current_state->colorPointerSize, offset + bytes_size);
2958 process->current_state->colorPointer = realloc(process->current_state->colorPointer, process->current_state->colorPointerSize);
2959 memcpy(process->current_state->colorPointer + offset, (void*)args[5], bytes_size);
2960 //fprintf(stderr, "glColorPointer_fake_func bytes_size = %d\n", bytes_size);
2961 glColorPointer(size, type, stride, process->current_state->colorPointer);
2966 case glSecondaryColorPointer_fake_func:
2968 GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
2969 int offset = args[0];
2972 int stride = args[3];
2973 int bytes_size = args[4];
2974 process->current_state->secondaryColorPointerSize = MAX(process->current_state->secondaryColorPointerSize, offset + bytes_size);
2975 process->current_state->secondaryColorPointer = realloc(process->current_state->secondaryColorPointer, process->current_state->secondaryColorPointerSize);
2976 memcpy(process->current_state->secondaryColorPointer + offset, (void*)args[5], bytes_size);
2977 //fprintf(stderr, "glSecondaryColorPointer_fake_func bytes_size = %d\n", bytes_size);
2978 ptr_func_glSecondaryColorPointer(size, type, stride, process->current_state->secondaryColorPointer);
2983 case glPushClientAttrib_func:
2986 if (process->current_state->clientStateSp < MAX_CLIENT_STATE_STACK_SIZE)
2988 process->current_state->clientStateStack[process->current_state->clientStateSp].mask = mask;
2989 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT)
2991 process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex =
2992 process->current_state->activeTextureIndex;
2994 process->current_state->clientStateSp++;
2996 glPushClientAttrib(mask);
3000 case glPopClientAttrib_func:
3002 if (process->current_state->clientStateSp > 0)
3004 process->current_state->clientStateSp--;
3005 if (process->current_state->clientStateStack[process->current_state->clientStateSp].mask & GL_CLIENT_VERTEX_ARRAY_BIT)
3007 process->current_state->activeTextureIndex =
3008 process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex;
3011 glPopClientAttrib();
3015 case glClientActiveTexture_func:
3016 case glClientActiveTextureARB_func:
3018 int activeTexture = args[0];
3019 process->current_state->activeTextureIndex = activeTexture - GL_TEXTURE0_ARB;
3020 do_glClientActiveTextureARB(activeTexture);
3024 case glTexCoordPointer_fake_func:
3026 int offset = args[0];
3027 int index = args[1];
3030 int stride = args[4];
3031 int bytes_size = args[5];
3032 process->current_state->texCoordPointerSize[index] = MAX(process->current_state->texCoordPointerSize[index], offset + bytes_size);
3033 process->current_state->texCoordPointer[index] = realloc(process->current_state->texCoordPointer[index], process->current_state->texCoordPointerSize[index]);
3034 memcpy(process->current_state->texCoordPointer[index] + offset, (void*)args[6], bytes_size);
3035 /*fprintf(stderr, "glTexCoordPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
3036 size, type, stride, bytes_size);*/
3037 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + index);
3038 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[index]);
3039 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3043 case glWeightPointerARB_fake_func:
3045 GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
3046 int offset = args[0];
3049 int stride = args[3];
3050 int bytes_size = args[4];
3051 process->current_state->weightPointerSize = MAX(process->current_state->weightPointerSize, offset + bytes_size);
3052 process->current_state->weightPointer = realloc(process->current_state->weightPointer, process->current_state->weightPointerSize);
3053 memcpy(process->current_state->weightPointer + offset, (void*)args[5], bytes_size);
3054 /*fprintf(stderr, "glWeightPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
3055 size, type, stride, bytes_size);*/
3056 ptr_func_glWeightPointerARB(size, type, stride, process->current_state->weightPointer);
3060 case glMatrixIndexPointerARB_fake_func:
3062 GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
3063 int offset = args[0];
3066 int stride = args[3];
3067 int bytes_size = args[4];
3068 process->current_state->matrixIndexPointerSize = MAX(process->current_state->matrixIndexPointerSize, offset + bytes_size);
3069 process->current_state->matrixIndexPointer = realloc(process->current_state->matrixIndexPointer, process->current_state->matrixIndexPointerSize);
3070 memcpy(process->current_state->matrixIndexPointer + offset, (void*)args[5], bytes_size);
3071 /*fprintf(stderr, "glMatrixIndexPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
3072 size, type, stride, bytes_size);*/
3073 ptr_func_glMatrixIndexPointerARB(size, type, stride, process->current_state->matrixIndexPointer);
3077 case glFogCoordPointer_fake_func:
3079 GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
3080 int offset = args[0];
3082 int stride = args[2];
3083 int bytes_size = args[3];
3084 process->current_state->fogCoordPointerSize = MAX(process->current_state->fogCoordPointerSize, offset + bytes_size);
3085 process->current_state->fogCoordPointer = realloc(process->current_state->fogCoordPointer, process->current_state->fogCoordPointerSize);
3086 memcpy(process->current_state->fogCoordPointer + offset, (void*)args[4], bytes_size);
3087 //fprintf(stderr, "glFogCoordPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
3088 ptr_func_glFogCoordPointer(type, stride, process->current_state->fogCoordPointer);
3092 case glVariantPointerEXT_fake_func:
3094 GET_EXT_PTR(void, glVariantPointerEXT, (int,int,int,void*));
3095 int offset = args[0];
3098 int stride = args[3];
3099 int bytes_size = args[4];
3100 process->current_state->variantPointerEXTSize[id] = MAX(process->current_state->variantPointerEXTSize[id], offset + bytes_size);
3101 process->current_state->variantPointerEXT[id] = realloc(process->current_state->variantPointerEXT[id], process->current_state->variantPointerEXTSize[id]);
3102 memcpy(process->current_state->variantPointerEXT[id] + offset, (void*)args[5], bytes_size);
3103 //fprintf(stderr, "glVariantPointerEXT_fake_func[%d] type=%d, stride=%d, byte_size=%d\n", id, type, stride, bytes_size);
3104 ptr_func_glVariantPointerEXT(id, type, stride, process->current_state->variantPointerEXT[id]);
3108 case glInterleavedArrays_fake_func:
3110 GET_EXT_PTR(void, glInterleavedArrays, (int,int,void*));
3111 int offset = args[0];
3112 int format = args[1];
3113 int stride = args[2];
3114 int bytes_size = args[3];
3115 process->current_state->interleavedArraysSize = MAX(process->current_state->interleavedArraysSize, offset + bytes_size);
3116 process->current_state->interleavedArrays = realloc(process->current_state->interleavedArrays, process->current_state->interleavedArraysSize);
3117 memcpy(process->current_state->interleavedArrays + offset, (void*)args[4], bytes_size);
3118 //fprintf(stderr, "glInterleavedArrays_fake_func format=%d, stride=%d, byte_size=%d\n", format, stride, bytes_size);
3119 ptr_func_glInterleavedArrays(format, stride, process->current_state->interleavedArrays);
3123 case glElementPointerATI_fake_func:
3125 GET_EXT_PTR(void, glElementPointerATI, (int,void*));
3127 int bytes_size = args[1];
3128 process->current_state->elementPointerATISize = bytes_size;
3129 process->current_state->elementPointerATI = realloc(process->current_state->elementPointerATI, process->current_state->elementPointerATISize);
3130 memcpy(process->current_state->elementPointerATI, (void*)args[2], bytes_size);
3131 //fprintf(stderr, "glElementPointerATI_fake_func type=%d, byte_size=%d\n", type, bytes_size);
3132 ptr_func_glElementPointerATI(type, process->current_state->elementPointerATI);
3136 case glTexCoordPointer01_fake_func:
3140 int stride = args[2];
3141 int bytes_size = args[3];
3142 process->current_state->texCoordPointerSize[0] = bytes_size;
3143 process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
3144 memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
3145 /*fprintf(stderr, "glTexCoordPointer01_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
3146 size, type, stride, bytes_size);*/
3147 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3148 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
3149 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
3150 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
3151 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3155 case glTexCoordPointer012_fake_func:
3159 int stride = args[2];
3160 int bytes_size = args[3];
3161 process->current_state->texCoordPointerSize[0] = bytes_size;
3162 process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
3163 memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
3164 /*fprintf(stderr, "glTexCoordPointer012_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
3165 size, type, stride, bytes_size);*/
3166 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3167 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
3168 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
3169 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
3170 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
3171 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
3172 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3176 case glVertexAndNormalPointer_fake_func:
3178 int vertexPointerSize = args[0];
3179 int vertexPointerType = args[1];
3180 int vertexPointerStride = args[2];
3181 int normalPointerType = args[3];
3182 int normalPointerStride = args[4];
3183 int bytes_size = args[5];
3184 void* ptr = (void*)args[6];
3185 process->current_state->vertexPointerSize = bytes_size;
3186 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, bytes_size);
3187 memcpy(process->current_state->vertexPointer, ptr, bytes_size);
3188 glVertexPointer(vertexPointerSize, vertexPointerType, vertexPointerStride, process->current_state->vertexPointer);
3189 glNormalPointer(normalPointerType, normalPointerStride, process->current_state->vertexPointer);
3193 case glVertexNormalPointerInterlaced_fake_func:
3196 int offset = args[i++];
3197 int vertexPointerSize = args[i++];
3198 int vertexPointerType = args[i++];
3199 int stride = args[i++];
3200 int normalPointerOffset= args[i++];
3201 int normalPointerType = args[i++];
3202 int bytes_size = args[i++];
3203 void* ptr = (void*)args[i++];
3204 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3205 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3206 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3207 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3208 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3212 case glTuxRacerDrawElements_fake_func:
3215 int count = args[1];
3216 int isColorEnabled = args[2];
3217 void* ptr = (void*)args[3];
3218 int stride = 6 * sizeof(float) + ((isColorEnabled) ? 4 * sizeof(unsigned char) : 0);
3219 glVertexPointer( 3, GL_FLOAT, stride, ptr);
3220 glNormalPointer( GL_FLOAT, stride, ptr + 3 * sizeof(float));
3222 glColorPointer( 4, GL_UNSIGNED_BYTE, stride, ptr + 6 * sizeof(float));
3223 glDrawArrays(mode, 0, count);
3227 case glVertexNormalColorPointerInterlaced_fake_func:
3230 int offset = args[i++];
3231 int vertexPointerSize = args[i++];
3232 int vertexPointerType = args[i++];
3233 int stride = args[i++];
3234 int normalPointerOffset= args[i++];
3235 int normalPointerType = args[i++];
3236 int colorPointerOffset = args[i++];
3237 int colorPointerSize = args[i++];
3238 int colorPointerType = args[i++];
3239 int bytes_size = args[i++];
3240 void* ptr = (void*)args[i++];
3241 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3242 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3243 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3244 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3245 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3246 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
3250 case glVertexColorTexCoord0PointerInterlaced_fake_func:
3253 int offset = args[i++];
3254 int vertexPointerSize = args[i++];
3255 int vertexPointerType = args[i++];
3256 int stride = args[i++];
3257 int colorPointerOffset = args[i++];
3258 int colorPointerSize = args[i++];
3259 int colorPointerType = args[i++];
3260 int texCoord0PointerOffset = args[i++];
3261 int texCoord0PointerSize = args[i++];
3262 int texCoord0PointerType = args[i++];
3263 int bytes_size = args[i++];
3264 void* ptr = (void*)args[i++];
3265 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3266 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3267 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3268 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3269 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
3270 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3271 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
3272 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3276 case glVertexNormalTexCoord0PointerInterlaced_fake_func:
3279 int offset = args[i++];
3280 int vertexPointerSize = args[i++];
3281 int vertexPointerType = args[i++];
3282 int stride = args[i++];
3283 int normalPointerOffset = args[i++];
3284 int normalPointerType = args[i++];
3285 int texCoord0PointerOffset = args[i++];
3286 int texCoord0PointerSize = args[i++];
3287 int texCoord0PointerType = args[i++];
3288 int bytes_size = args[i++];
3289 void* ptr = (void*)args[i++];
3290 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3291 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3292 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3293 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3294 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3295 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3296 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
3297 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3301 case glVertexNormalTexCoord01PointerInterlaced_fake_func:
3304 int offset = args[i++];
3305 int vertexPointerSize = args[i++];
3306 int vertexPointerType = args[i++];
3307 int stride = args[i++];
3308 int normalPointerOffset = args[i++];
3309 int normalPointerType = args[i++];
3310 int texCoord0PointerOffset = args[i++];
3311 int texCoord0PointerSize = args[i++];
3312 int texCoord0PointerType = args[i++];
3313 int texCoord1PointerOffset = args[i++];
3314 int texCoord1PointerSize = args[i++];
3315 int texCoord1PointerType = args[i++];
3316 int bytes_size = args[i++];
3317 void* ptr = (void*)args[i++];
3318 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3319 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3320 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3321 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3322 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3323 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3324 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
3325 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
3326 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
3327 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3331 case glVertexNormalTexCoord012PointerInterlaced_fake_func:
3334 int offset = args[i++];
3335 int vertexPointerSize = args[i++];
3336 int vertexPointerType = args[i++];
3337 int stride = args[i++];
3338 int normalPointerOffset = args[i++];
3339 int normalPointerType = args[i++];
3340 int texCoord0PointerOffset = args[i++];
3341 int texCoord0PointerSize = args[i++];
3342 int texCoord0PointerType = args[i++];
3343 int texCoord1PointerOffset = args[i++];
3344 int texCoord1PointerSize = args[i++];
3345 int texCoord1PointerType = args[i++];
3346 int texCoord2PointerOffset = args[i++];
3347 int texCoord2PointerSize = args[i++];
3348 int texCoord2PointerType = args[i++];
3349 int bytes_size = args[i++];
3350 void* ptr = (void*)args[i++];
3351 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3352 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3353 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3354 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3355 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3356 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3357 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
3358 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
3359 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
3360 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
3361 glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
3362 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3366 case glVertexNormalColorTexCoord0PointerInterlaced_fake_func:
3369 int offset = args[i++];
3370 int vertexPointerSize = args[i++];
3371 int vertexPointerType = args[i++];
3372 int stride = args[i++];
3373 int normalPointerOffset = args[i++];
3374 int normalPointerType = args[i++];
3375 int colorPointerOffset = args[i++];
3376 int colorPointerSize = args[i++];
3377 int colorPointerType = args[i++];
3378 int texCoord0PointerOffset = args[i++];
3379 int texCoord0PointerSize = args[i++];
3380 int texCoord0PointerType = args[i++];
3381 int bytes_size = args[i++];
3382 void* ptr = (void*)args[i++];
3383 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3384 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3385 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3386 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3387 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3388 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
3389 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3390 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
3391 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3395 case glVertexNormalColorTexCoord01PointerInterlaced_fake_func:
3398 int offset = args[i++];
3399 int vertexPointerSize = args[i++];
3400 int vertexPointerType = args[i++];
3401 int stride = args[i++];
3402 int normalPointerOffset = args[i++];
3403 int normalPointerType = args[i++];
3404 int colorPointerOffset = args[i++];
3405 int colorPointerSize = args[i++];
3406 int colorPointerType = args[i++];
3407 int texCoord0PointerOffset = args[i++];
3408 int texCoord0PointerSize = args[i++];
3409 int texCoord0PointerType = args[i++];
3410 int texCoord1PointerOffset = args[i++];
3411 int texCoord1PointerSize = args[i++];
3412 int texCoord1PointerType = args[i++];
3413 int bytes_size = args[i++];
3414 void* ptr = (void*)args[i++];
3415 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3416 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3417 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3418 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3419 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3420 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
3421 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3422 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
3423 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
3424 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
3425 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3429 case glVertexNormalColorTexCoord012PointerInterlaced_fake_func:
3432 int offset = args[i++];
3433 int vertexPointerSize = args[i++];
3434 int vertexPointerType = args[i++];
3435 int stride = args[i++];
3436 int normalPointerOffset = args[i++];
3437 int normalPointerType = args[i++];
3438 int colorPointerOffset = args[i++];
3439 int colorPointerSize = args[i++];
3440 int colorPointerType = args[i++];
3441 int texCoord0PointerOffset = args[i++];
3442 int texCoord0PointerSize = args[i++];
3443 int texCoord0PointerType = args[i++];
3444 int texCoord1PointerOffset = args[i++];
3445 int texCoord1PointerSize = args[i++];
3446 int texCoord1PointerType = args[i++];
3447 int texCoord2PointerOffset = args[i++];
3448 int texCoord2PointerSize = args[i++];
3449 int texCoord2PointerType = args[i++];
3450 int bytes_size = args[i++];
3451 void* ptr = (void*)args[i++];
3452 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
3453 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
3454 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
3455 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
3456 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
3457 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
3458 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
3459 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
3460 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
3461 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
3462 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
3463 glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
3464 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
3468 case _glVertexPointer_buffer_func:
3470 glVertexPointer(args[0],args[1],args[2],(void*)args[3]);
3474 case _glNormalPointer_buffer_func:
3476 glNormalPointer(args[0],args[1],(void*)args[2]);
3480 case _glColorPointer_buffer_func:
3482 glColorPointer(args[0],args[1],args[2],(void*)args[3]);
3486 case _glSecondaryColorPointer_buffer_func:
3488 GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
3489 ptr_func_glSecondaryColorPointer(args[0],args[1],args[2],(void*)args[3]);
3493 case _glIndexPointer_buffer_func:
3495 glIndexPointer(args[0],args[1],(void*)args[2]);
3499 case _glTexCoordPointer_buffer_func:
3501 glTexCoordPointer(args[0],args[1],args[2],(void*)args[3]);
3505 case _glEdgeFlagPointer_buffer_func:
3507 glEdgeFlagPointer(args[0],(void*)args[1]);
3511 case _glVertexAttribPointerARB_buffer_func:
3513 GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
3514 ptr_func_glVertexAttribPointerARB(args[0], args[1], args[2], args[3], args[4], (void*)args[5]);
3518 case _glWeightPointerARB_buffer_func:
3520 GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
3521 ptr_func_glWeightPointerARB(args[0], args[1], args[2], (void*)args[3]);
3525 case _glMatrixIndexPointerARB_buffer_func:
3527 GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
3528 ptr_func_glMatrixIndexPointerARB(args[0], args[1], args[2], (void*)args[3]);
3532 case _glFogCoordPointer_buffer_func:
3534 GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
3535 ptr_func_glFogCoordPointer(args[0], args[1], (void*)args[2]);
3539 case _glVariantPointerEXT_buffer_func:
3541 GET_EXT_PTR(void, glVariantPointerEXT, (int, int,int,void*));
3542 ptr_func_glVariantPointerEXT(args[0], args[1], args[2], (void*)args[3]);
3546 case _glDrawElements_buffer_func:
3548 glDrawElements(args[0],args[1],args[2],(void*)args[3]);
3552 case _glDrawRangeElements_buffer_func:
3554 GET_EXT_PTR(void, glDrawRangeElements, ( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ));
3555 ptr_func_glDrawRangeElements(args[0],args[1],args[2],args[3],args[4],(void*)args[5]);
3559 case _glMultiDrawElements_buffer_func:
3561 GET_EXT_PTR(void, glMultiDrawElements, (int,int*,int,void**, int));
3562 ptr_func_glMultiDrawElements(args[0],(int*)args[1],args[2],(void**)args[3],args[4]);
3566 case _glGetError_fake_func:
3571 case glGetIntegerv_func:
3573 glGetIntegerv(args[0], (int*)args[1]);
3577 case _glReadPixels_pbo_func:
3579 glReadPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (void*)(args[6]));
3583 case _glDrawPixels_pbo_func:
3585 glDrawPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_UNSIGNED_INT(args[2]), ARG_TO_UNSIGNED_INT(args[3]), (const void*)(args[4]));
3589 case _glMapBufferARB_fake_func:
3591 GET_EXT_PTR(GLvoid*, glMapBufferARB, (GLenum, GLenum));
3592 GET_EXT_PTR(GLboolean, glUnmapBufferARB, (GLenum));
3593 int target = args[0];
3595 void* dst_ptr = (void*)args[2];
3596 void* src_ptr = ptr_func_glMapBufferARB(target, GL_READ_ONLY);
3599 memcpy(dst_ptr, src_ptr, size);
3600 ret_int = ptr_func_glUnmapBufferARB(target);
3609 case fake_gluBuild2DMipmaps_func:
3611 GET_GLU_PTR(GLint, gluBuild2DMipmaps, (GLenum arg_0, GLint arg_1, GLsizei arg_2, GLsizei arg_3, GLenum arg_4, GLenum arg_5, const GLvoid * arg_6));
3612 if (ptr_func_gluBuild2DMipmaps == NULL)
3613 ptr_func_gluBuild2DMipmaps = mesa_gluBuild2DMipmaps;
3614 ptr_func_gluBuild2DMipmaps(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (const void*)(args[6]));
3618 case _glSelectBuffer_fake_func:
3620 process->current_state->selectBufferSize = args[0] * 4;
3621 process->current_state->selectBufferPtr = realloc(process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
3622 glSelectBuffer(args[0], process->current_state->selectBufferPtr);
3626 case _glGetSelectBuffer_fake_func:
3628 void* ptr = (void*)args[0];
3629 memcpy(ptr, process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
3633 case _glFeedbackBuffer_fake_func:
3635 process->current_state->feedbackBufferSize = args[0] * 4;
3636 process->current_state->feedbackBufferPtr = realloc(process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
3637 glFeedbackBuffer(args[0], args[1], process->current_state->feedbackBufferPtr);
3641 case _glGetFeedbackBuffer_fake_func:
3643 void* ptr = (void*)args[0];
3644 memcpy(ptr, process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
3648 case glGetError_func:
3650 ret_int = glGetError();
3654 case glNewObjectBufferATI_func:
3656 GET_EXT_PTR(int, glNewObjectBufferATI, (int,void*, int));
3657 ret_int = ptr_func_glNewObjectBufferATI(args[0], (void*)args[1], args[2]);
3662 execute_func(func_number, args, &ret_int, &ret_char);
3666 Signature* signature = (Signature*)tab_opengl_calls[func_number];
3667 int ret_type = signature->ret_type;
3674 case TYPE_UNSIGNED_CHAR:
3679 case TYPE_UNSIGNED_INT:
3682 case TYPE_CONST_CHAR:
3684 strncpy(ret_string, (ret_str) ? ret_str : "", 32768);
3689 fprintf(stderr, "unexpected ret type : %d\n", ret_type);
3699 #include <arpa/inet.h>
3700 #include <X11/Xlib.h>
3701 #include <X11/Xutil.h>
3703 #define GL_GLEXT_PROTOTYPES
3704 #define GLX_GLXEXT_PROTOTYPES
3706 #include "opengl_func.h"
3707 #include "opengl_utils.h"
3708 #include "mesa_gl.h"
3709 #include "mesa_glx.h"
3710 #include "mesa_glu.h"
3711 #include "mesa_mipmap.c"
3713 //#define SYSTEMATIC_ERROR_CHECK
3715 #define GET_EXT_PTR(type, funcname, args_decl) \
3716 static int detect_##funcname = 0; \
3717 static type(*ptr_func_##funcname)args_decl = NULL; \
3718 if (detect_##funcname == 0) \
3720 detect_##funcname = 1; \
3721 ptr_func_##funcname = (type(*)args_decl)glXGetProcAddressARB((const GLubyte*)#funcname); \
3722 assert (ptr_func_##funcname); \
3725 #define GET_EXT_PTR_NO_FAIL(type, funcname, args_decl) \
3726 static int detect_##funcname = 0; \
3727 static type(*ptr_func_##funcname)args_decl = NULL; \
3728 if (detect_##funcname == 0) \
3730 detect_##funcname = 1; \
3731 ptr_func_##funcname = (type(*)args_decl)glXGetProcAddressARB((const GLubyte*)#funcname); \
3738 static void* get_glu_ptr(const char* name)
3740 static void* handle = (void*)-1;
3741 if (handle == (void*)-1)
3744 handle = dlopen("libGLU.so" ,RTLD_LAZY);
3746 fprintf (stderr, "can't load libGLU.so : %s\n", dlerror());
3749 handle = (void *)LoadLibrary("glu32.dll");
3751 fprintf (stderr, "can't load glu32.dll\n");
3758 return dlsym(handle, name);
3760 return GetProcAddress(handle, name);
3766 #define GET_GLU_PTR(type, funcname, args_decl) \
3767 static int detect_##funcname = 0; \
3768 static type(*ptr_func_##funcname)args_decl = NULL; \
3769 if (detect_##funcname == 0) \
3771 detect_##funcname = 1; \
3772 ptr_func_##funcname = (type(*)args_decl)get_glu_ptr(#funcname); \
3775 int display_function_call = 0;
3777 static const int defaultAttribList[] = {
3786 static XVisualInfo* get_default_visual(Display* dpy)
3788 fprintf(stderr, "get_default_visual\n");
3789 static XVisualInfo* vis = NULL;
3790 XVisualInfo theTemplate;
3792 if (vis) return vis;
3794 vis = glXChooseVisual(dpy, 0, (int*)defaultAttribList);*/
3795 theTemplate.screen = 0;
3796 vis = XGetVisualInfo(dpy, VisualScreenMask, &theTemplate, &numVisuals);
3800 void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window)
3802 pConn->parent_dpy = pConn->Display;
3803 pConn->qemu_parent_window = _parent_window;
3804 if (pConn->active_win)
3806 XReparentWindow(pConn->Display, pConn->active_win, _parent_window, pConn->active_win_x, pConn->active_win_y);
3810 static Window create_window(OGLS_Conn *pConn, Window local_parent_window, XVisualInfo* vis, const char *name,
3811 int x, int y, int width, int height)
3814 XSetWindowAttributes attr = {0};
3819 scrnum = DefaultScreen( pConn->Display );
3820 root = RootWindow( pConn->Display, scrnum );
3822 /* window attributes */
3823 attr.background_pixel = 0;
3824 attr.border_pixel = 0;
3825 attr.colormap = XCreateColormap( pConn->Display, root, vis->visual, AllocNone);
3826 attr.event_mask = StructureNotifyMask | ExposureMask /*| KeyPressMask*/;
3827 attr.save_under = True;
3828 //if (local_parent_window == NULL && qemu_parent_window == NULL)
3829 attr.override_redirect = False;
3831 // attr.override_redirect = True;
3833 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect | CWSaveUnder ;
3835 if (local_parent_window)
3837 win = XCreateWindow( pConn->Display, local_parent_window, 0, 0, width, height,
3838 0, vis->depth, InputOutput,
3839 vis->visual, mask, &attr );
3841 else if (pConn->qemu_parent_window)
3843 win = XCreateWindow( pConn->Display, pConn->qemu_parent_window, 0, 0, width, height,
3844 0, vis->depth, InputOutput,
3845 vis->visual, mask, &attr );
3849 win = XCreateWindow( pConn->Display, root, 0, 0, width, height,
3850 0, vis->depth, InputOutput,
3851 vis->visual, mask, &attr );
3854 /* set hints and properties */
3856 XSizeHints sizehints;
3859 sizehints.width = width;
3860 sizehints.height = height;
3861 sizehints.flags = USSize | USPosition;
3862 XSetWMNormalHints(pConn->Display, win, &sizehints);
3863 XSetStandardProperties(pConn->Display, win, name, name,
3864 None, (char **)NULL, 0, &sizehints);
3867 /* Host Window?? ?琉??? ?苛쨈?. if( win )
3868 XMapWindow(pConn->Display, win);*/
3870 XSync(pConn->Display, 0);
3875 while (XPending(pConn->Display) > 0) {
3877 XNextEvent(pConn->Display, &event);
3878 switch (event.type) {
3881 if (((XCreateWindowEvent*)&event)->window == win)
3891 pConn->active_win = win;
3896 static void destroy_window(OGLS_Conn *pConn, Window win )
3900 XDestroyWindow(pConn->Display, win);
3902 XSync(pConn->Display, 0);
3905 while (XPending(pConn->Display) > 0) {
3907 XNextEvent(pConn->Display, &event);
3908 switch (event.type) {
3911 if (((XDestroyWindowEvent*)&event)->window == win)
3921 if( pConn->active_win == win)
3922 pConn->active_win = 0;
3934 #define MAX_HANDLED_PROCESS 100
3935 #define MAX_ASSOC_SIZE 100
3937 #define MAX_FBCONFIG 10
3940 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
3955 int activeTextureIndex;
3958 #define MAX_CLIENT_STATE_STACK_SIZE 16
3966 GLXDrawable drawable;
3968 void* vertexPointer;
3969 void* normalPointer;
3971 void* secondaryColorPointer;
3973 void* texCoordPointer[NB_MAX_TEXTURES];
3974 void* edgeFlagPointer;
3975 void* vertexAttribPointer[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
3976 void* vertexAttribPointerNV[MY_GL_MAX_VERTEX_ATTRIBS_NV];
3977 void* weightPointer;
3978 void* matrixIndexPointer;
3979 void* fogCoordPointer;
3980 void* variantPointerEXT[MY_GL_MAX_VARIANT_POINTER_EXT];
3981 void* interleavedArrays;
3982 void* elementPointerATI;
3984 int vertexPointerSize;
3985 int normalPointerSize;
3986 int colorPointerSize;
3987 int secondaryColorPointerSize;
3988 int indexPointerSize;
3989 int texCoordPointerSize[NB_MAX_TEXTURES];
3990 int edgeFlagPointerSize;
3991 int vertexAttribPointerSize[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
3992 int vertexAttribPointerNVSize[MY_GL_MAX_VERTEX_ATTRIBS_NV];
3993 int weightPointerSize;
3994 int matrixIndexPointerSize;
3995 int fogCoordPointerSize;
3996 int variantPointerEXTSize[MY_GL_MAX_VARIANT_POINTER_EXT];
3997 int interleavedArraysSize;
3998 int elementPointerATISize;
4000 int selectBufferSize;
4001 void* selectBufferPtr;
4002 int feedbackBufferSize;
4003 void* feedbackBufferPtr;
4005 ClientState clientStateStack[MAX_CLIENT_STATE_STACK_SIZE];
4007 int activeTextureIndex;
4009 unsigned int ownTabTextures[32768];
4010 unsigned int* tabTextures;
4011 RangeAllocator ownTextureAllocator;
4012 RangeAllocator* textureAllocator;
4014 unsigned int ownTabBuffers[32768];
4015 unsigned int* tabBuffers;
4016 RangeAllocator ownBufferAllocator;
4017 RangeAllocator* bufferAllocator;
4019 unsigned int ownTabLists[32768];
4020 unsigned int* tabLists;
4021 RangeAllocator ownListAllocator;
4022 RangeAllocator* listAllocator;
4024 #ifdef SYSTEMATIC_ERROR_CHECK
4035 int x, y, width, height;
4036 WindowPosStruct currentDrawablePos;
4038 int next_available_context_number;
4039 int next_available_pbuffer_number;
4042 GLState default_state;
4044 GLState* current_state;
4047 GLXFBConfig* fbconfigs[MAX_FBCONFIG];
4048 int fbconfigs_max[MAX_FBCONFIG];
4049 int nfbconfig_total;
4051 Assoc association_fakecontext_glxcontext[MAX_ASSOC_SIZE];
4052 Assoc association_fakepbuffer_pbuffer[MAX_ASSOC_SIZE];
4053 Assoc association_clientdrawable_serverdrawable[MAX_ASSOC_SIZE];
4054 Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
4057 int last_process_id = 0;
4060 #define ARG_TO_CHAR(x) (char)(x)
4061 #define ARG_TO_UNSIGNED_CHAR(x) (unsigned char)(x)
4062 #define ARG_TO_SHORT(x) (short)(x)
4063 #define ARG_TO_UNSIGNED_SHORT(x) (unsigned short)(x)
4064 #define ARG_TO_INT(x) (int)(x)
4065 #define ARG_TO_UNSIGNED_INT(x) (unsigned int)(x)
4066 #define ARG_TO_FLOAT(x) (*(float*)&(x))
4067 #define ARG_TO_DOUBLE(x) (*(double*)(x))
4069 #include "server_stub.c"
4073 static void* get_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
4076 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
4078 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
4079 return process->association_fakecontext_glxcontext[i].value;
4084 static void set_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext, void* glxcontext)
4087 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
4089 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
4094 if (i < MAX_ASSOC_SIZE)
4096 process->association_fakecontext_glxcontext[i].key = fakecontext;
4097 process->association_fakecontext_glxcontext[i].value = glxcontext;
4101 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
4105 static void unset_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
4108 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
4110 if (process->association_fakecontext_glxcontext[i].key == fakecontext)
4112 memmove(&process->association_fakecontext_glxcontext[i],
4113 &process->association_fakecontext_glxcontext[i+1],
4114 sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
4122 static void* get_association_fakecontext_visual(ProcessStruct* process, void* fakecontext)
4125 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
4127 if (process->association_fakecontext_visual[i].key == fakecontext)
4128 return process->association_fakecontext_visual[i].value;
4133 static void set_association_fakecontext_visual(ProcessStruct* process, void* fakecontext, void* visual)
4136 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
4138 if (process->association_fakecontext_visual[i].key == fakecontext)
4143 if (i < MAX_ASSOC_SIZE)
4145 process->association_fakecontext_visual[i].key = fakecontext;
4146 process->association_fakecontext_visual[i].value = visual;
4150 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
4156 static void* get_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
4159 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
4161 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
4162 return process->association_fakepbuffer_pbuffer[i].value;
4166 static void set_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer, void* pbuffer)
4169 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
4171 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
4176 if (i < MAX_ASSOC_SIZE)
4178 process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
4179 process->association_fakepbuffer_pbuffer[i].value = pbuffer;
4183 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
4186 static void unset_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
4189 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
4191 if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
4193 memmove(&process->association_fakepbuffer_pbuffer[i],
4194 &process->association_fakepbuffer_pbuffer[i+1],
4195 sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
4204 static GLXDrawable get_association_clientdrawable_serverdrawable(ProcessStruct* process, GLXDrawable clientdrawable)
4207 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
4209 if (process->association_clientdrawable_serverdrawable[i].key == (void*)clientdrawable)
4210 return (GLXDrawable)process->association_clientdrawable_serverdrawable[i].value;
4212 return (GLXDrawable)0;
4216 static void* get_association_serverdrawable_clientdrawable(ProcessStruct* process, GLXDrawable serverdrawable)
4219 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
4221 if ((GLXDrawable)process->association_clientdrawable_serverdrawable[i].value == serverdrawable)
4222 return process->association_clientdrawable_serverdrawable[i].key;
4228 static void set_association_clientdrawable_serverdrawable(ProcessStruct* process, void* clientdrawable, void* serverdrawable)
4231 for(i=0;process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
4233 if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
4238 if (i < MAX_ASSOC_SIZE)
4240 process->association_clientdrawable_serverdrawable[i].key = clientdrawable;
4241 process->association_clientdrawable_serverdrawable[i].value = serverdrawable;
4245 fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
4249 static void _get_window_pos(Display *dpy, Window win, WindowPosStruct* pos)
4251 XWindowAttributes window_attributes_return;
4254 Window root = DefaultRootWindow(dpy);
4255 XGetWindowAttributes(dpy, win, &window_attributes_return);
4256 XTranslateCoordinates(dpy, win, root, 0, 0, &x, &y, &child);
4257 /*printf("%d %d %d %d\n", x, y,
4258 window_attributes_return.width, window_attributes_return.height);*/
4261 pos->width = window_attributes_return.width;
4262 pos->height = window_attributes_return.height;
4263 pos->map_state = window_attributes_return.map_state;
4266 static int is_gl_vendor_ati(Display* dpy)
4268 static int is_gl_vendor_ati_flag = 0;
4269 static int has_init = 0;
4273 is_gl_vendor_ati_flag = (strncmp(glXGetClientString(dpy, GLX_VENDOR), "ATI", 3) == 0);
4275 return is_gl_vendor_ati_flag;
4278 static int get_server_texture(ProcessStruct* process, unsigned int client_texture)
4280 unsigned int server_texture = 0;
4281 if (client_texture < 32768)
4283 server_texture = process->current_state->tabTextures[client_texture];
4287 fprintf(stderr, "invalid texture name %d\n", client_texture);
4289 return server_texture;
4292 static int get_server_buffer(ProcessStruct* process, unsigned int client_buffer)
4294 unsigned int server_buffer = 0;
4295 if (client_buffer < 32768)
4297 server_buffer = process->current_state->tabBuffers[client_buffer];
4301 fprintf(stderr, "invalid buffer name %d\n", client_buffer);
4303 return server_buffer;
4307 static int get_server_list(ProcessStruct* process, unsigned int client_list)
4309 unsigned int server_list = 0;
4310 if (client_list < 32768)
4312 server_list = process->current_state->tabLists[client_list];
4316 fprintf(stderr, "invalid list name %d\n", client_list);
4321 static GLXFBConfig get_fbconfig(ProcessStruct* process, int client_fbconfig)
4325 for(i=0;i<process->nfbconfig;i++)
4327 assert(client_fbconfig >= 1 + nbtotal);
4328 if (client_fbconfig <= nbtotal + process->fbconfigs_max[i])
4330 return process->fbconfigs[i][client_fbconfig-1 - nbtotal];
4332 nbtotal += process->fbconfigs_max[i];
4339 int attribListLength;
4341 XVisualInfo* visInfo;
4342 } AssocAttribListVisual;
4344 static int _compute_length_of_attrib_list_including_zero(const int* attribList, int booleanMustHaveValue)
4347 while(attribList[i])
4349 if (booleanMustHaveValue ||
4350 !(attribList[i] == GLX_USE_GL ||
4351 attribList[i] == GLX_RGBA ||
4352 attribList[i] == GLX_DOUBLEBUFFER ||
4353 attribList[i] == GLX_STEREO))
4365 static int glXChooseVisualFunc( OGLS_Conn *pConn, const int* _attribList)
4367 AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
4369 if (_attribList == NULL)
4371 int attribListLength = _compute_length_of_attrib_list_including_zero(_attribList, 0);
4374 int* attribList = malloc(sizeof(int) * attribListLength);
4375 memcpy(attribList, _attribList, sizeof(int) * attribListLength);
4378 while(attribList[i])
4380 if (!(attribList[i] == GLX_USE_GL ||
4381 attribList[i] == GLX_RGBA ||
4382 attribList[i] == GLX_DOUBLEBUFFER ||
4383 attribList[i] == GLX_STEREO))
4385 if (attribList[i] == GLX_SAMPLE_BUFFERS && attribList[i+1] != 0 && getenv("DISABLE_SAMPLE_BUFFERS"))
4387 fprintf(stderr, "Disabling GLX_SAMPLE_BUFFERS\n");
4388 attribList[i+1] = 0;
4398 for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
4400 if (tabAssocAttribListVisual[i].attribListLength == attribListLength &&
4401 memcmp(tabAssocAttribListVisual[i].attribList, attribList, attribListLength * sizeof(int)) == 0)
4404 return (tabAssocAttribListVisual[i].visInfo) ? tabAssocAttribListVisual[i].visInfo->visualid : 0;
4407 XVisualInfo* visInfo = glXChooseVisual(pConn->Display, 0, attribList);
4408 pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
4409 realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
4410 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = attribListLength;
4411 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = (int*)malloc(sizeof(int) * attribListLength);
4412 memcpy(tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList, attribList, sizeof(int) * attribListLength);
4413 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
4414 pConn->nTabAssocAttribListVisual++;
4416 return (visInfo) ? visInfo->visualid : 0;
4419 static XVisualInfo* get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid)
4422 XVisualInfo template;
4423 XVisualInfo* visInfo;
4425 AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
4427 for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
4429 if (tabAssocAttribListVisual[i].visInfo &&
4430 tabAssocAttribListVisual[i].visInfo->visualid == visualid)
4432 return tabAssocAttribListVisual[i].visInfo;
4435 template.visualid = visualid;
4436 visInfo = XGetVisualInfo(pConn->Display, VisualIDMask, &template, &n);
4437 pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
4438 realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
4439 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
4440 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
4441 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
4442 pConn->nTabAssocAttribListVisual++;
4457 static ClientCursor client_cursor = { 0 };
4459 static void do_glClientActiveTextureARB(int texture)
4461 GET_EXT_PTR_NO_FAIL(void, glClientActiveTextureARB, (int));
4462 if (ptr_func_glClientActiveTextureARB)
4464 ptr_func_glClientActiveTextureARB(texture);
4468 static void do_glActiveTextureARB(int texture)
4470 GET_EXT_PTR_NO_FAIL(void, glActiveTextureARB, (int));
4471 if (ptr_func_glActiveTextureARB)
4473 ptr_func_glActiveTextureARB(texture);
4477 static void do_glUseProgramObjectARB(GLhandleARB programObj)
4479 GET_EXT_PTR_NO_FAIL(void, glUseProgramObjectARB, (GLhandleARB));
4480 if (ptr_func_glUseProgramObjectARB)
4482 ptr_func_glUseProgramObjectARB(programObj);
4486 static void destroy_gl_state(GLState* state)
4489 if (state->vertexPointer) free(state->vertexPointer);
4490 if (state->normalPointer) free(state->normalPointer);
4491 if (state->indexPointer) free(state->indexPointer);
4492 if (state->colorPointer) free(state->colorPointer);
4493 if (state->secondaryColorPointer) free(state->secondaryColorPointer);
4494 for(i=0;i<NB_MAX_TEXTURES;i++)
4496 if (state->texCoordPointer[i]) free(state->texCoordPointer[i]);
4498 for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_ARB;i++)
4500 if (state->vertexAttribPointer[i]) free(state->vertexAttribPointer[i]);
4502 for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_NV;i++)
4504 if (state->vertexAttribPointerNV[i]) free(state->vertexAttribPointerNV[i]);
4506 if (state->weightPointer) free(state->weightPointer);
4507 if (state->matrixIndexPointer) free(state->matrixIndexPointer);
4508 if (state->fogCoordPointer) free(state->fogCoordPointer);
4509 for(i=0;i<MY_GL_MAX_VARIANT_POINTER_EXT;i++)
4511 if (state->variantPointerEXT[i]) free(state->variantPointerEXT[i]);
4513 if (state->interleavedArrays) free(state->interleavedArrays);
4514 if (state->elementPointerATI) free(state->elementPointerATI);
4517 static void init_gl_state(GLState* state)
4519 state->textureAllocator = &state->ownTextureAllocator;
4520 state->tabTextures = state->ownTabTextures;
4521 state->bufferAllocator = &state->ownBufferAllocator;
4522 state->tabBuffers = state->ownTabBuffers;
4523 state->listAllocator = &state->ownListAllocator;
4524 state->tabLists = state->ownTabLists;
4528 * Translate the nth element of list from type to GLuint.
4531 translate_id(GLsizei n, GLenum type, const GLvoid * list)
4543 bptr = (GLbyte *) list;
4544 return (GLuint) *(bptr + n);
4545 case GL_UNSIGNED_BYTE:
4546 ubptr = (GLubyte *) list;
4547 return (GLuint) *(ubptr + n);
4549 sptr = (GLshort *) list;
4550 return (GLuint) *(sptr + n);
4551 case GL_UNSIGNED_SHORT:
4552 usptr = (GLushort *) list;
4553 return (GLuint) *(usptr + n);
4555 iptr = (GLint *) list;
4556 return (GLuint) *(iptr + n);
4557 case GL_UNSIGNED_INT:
4558 uiptr = (GLuint *) list;
4559 return (GLuint) *(uiptr + n);
4561 fptr = (GLfloat *) list;
4562 return (GLuint) *(fptr + n);
4564 ubptr = ((GLubyte *) list) + 2 * n;
4565 return (GLuint) *ubptr * 256 + (GLuint) * (ubptr + 1);
4567 ubptr = ((GLubyte *) list) + 3 * n;
4568 return (GLuint) * ubptr * 65536
4569 + (GLuint) *(ubptr + 1) * 256 + (GLuint) * (ubptr + 2);
4571 ubptr = ((GLubyte *) list) + 4 * n;
4572 return (GLuint) *ubptr * 16777216
4573 + (GLuint) *(ubptr + 1) * 65536
4574 + (GLuint) *(ubptr + 2) * 256 + (GLuint) * (ubptr + 3);
4580 static void _create_context(ProcessStruct* process, GLXContext ctxt, int fake_ctxt, GLXContext shareList, int fake_shareList)
4582 process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
4583 process->glstates[process->nbGLStates] = malloc(sizeof(GLState));
4584 memset(process->glstates[process->nbGLStates], 0, sizeof(GLState));
4585 process->glstates[process->nbGLStates]->ref = 1;
4586 process->glstates[process->nbGLStates]->context = ctxt;
4587 process->glstates[process->nbGLStates]->fake_ctxt = fake_ctxt;
4588 process->glstates[process->nbGLStates]->fake_shareList = fake_shareList;
4589 init_gl_state(process->glstates[process->nbGLStates]);
4590 if (shareList && fake_shareList)
4593 for(i=0;i<process->nbGLStates;i++)
4595 if (process->glstates[i]->fake_ctxt == fake_shareList)
4597 process->glstates[i]->ref ++;
4598 process->glstates[process->nbGLStates]->textureAllocator =
4599 process->glstates[i]->textureAllocator;
4600 process->glstates[process->nbGLStates]->tabTextures =
4601 process->glstates[i]->tabTextures;
4602 process->glstates[process->nbGLStates]->bufferAllocator =
4603 process->glstates[i]->bufferAllocator;
4604 process->glstates[process->nbGLStates]->tabBuffers =
4605 process->glstates[i]->tabBuffers;
4606 process->glstates[process->nbGLStates]->listAllocator =
4607 process->glstates[i]->listAllocator;
4608 process->glstates[process->nbGLStates]->tabLists =
4609 process->glstates[i]->tabLists;
4614 process->nbGLStates++;
4617 static const char *opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
4623 static const char *delim = " \t\n\r/";
4631 if (!(*saveptr) || !(*n))
4636 for (; *n && strchr(delim, *s); s++, (*n)--) {
4637 if (*s == '/' && *n > 1) {
4641 } while (*n > 1 && s[1] != '\n' && s[1] != '\r');
4642 } else if (s[1] == '*') {
4645 } while (*n > 2 && (s[1] != '*' || s[2] != '/'));
4652 for (; *n && *s && !strchr(delim, *s); s++, (*n)--);
4659 ret = malloc(retlen + 1);
4662 while (retlen > 0) {
4663 if (*start == '/' && retlen > 1) {
4664 if (start[1] == '/') {
4667 } while (retlen > 1 && start[1] != '\n' && start[1] != '\r');
4670 } else if (start[1] == '*') {
4673 } while (retlen > 2 && (start[1] != '*' || start[2] != '/'));
4674 start += 3, retlen -= 3;
4678 *(p++) = *(start++), retlen--;
4685 static char *do_eglShaderPatch(const char *source, int length, int *patched_len)
4687 char *saveptr = NULL;
4692 length = strlen(source);
4695 int patched_size = length;
4696 char *patched = malloc(patched_size + 1);
4701 p = opengl_strtok(source, &length, &saveptr, NULL);
4702 for (; p; p = opengl_strtok(0, &length, &saveptr, p)) {
4703 if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5)) {
4705 } else if (!strncmp(p, "precision", 9)) {
4706 while ((p = opengl_strtok(0, &length, &saveptr, p)) && !strchr(p, ';'));
4708 if (!strncmp(p, "gl_MaxVertexUniformVectors", 26)) {
4709 p = "(gl_MaxVertexUniformComponents / 4)";
4710 } else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28)) {
4711 p = "(gl_MaxFragmentUniformComponents / 4)";
4712 } else if (!strncmp(p, "gl_MaxVaryingVectors", 20)) {
4713 p = "(gl_MaxVaryingFloats / 4)";
4716 int new_len = strlen(p);
4717 if (*patched_len + new_len > patched_size) {
4719 patched = realloc(patched, patched_size + 1);
4725 memcpy(patched + *patched_len, p, new_len);
4726 *patched_len += new_len;
4730 patched[*patched_len] = 0;
4731 /* check that we don't leave dummy preprocessor lines */
4732 for (sp = patched; *sp;) {
4733 for (; *sp == ' ' || *sp == '\t'; sp++);
4734 if (!strncmp(sp, "#define", 7)) {
4735 for (p = sp + 7; *p == ' ' || *p == '\t'; p++);
4736 if (*p == '\n' || *p == '\r' || *p == '/') {
4737 memset(sp, 0x20, 7);
4740 for (; *sp && *sp != '\n' && *sp != '\r'; sp++);
4741 for (; *sp == '\n' || *sp == '\r'; sp++);
4747 shadersrc_gles_to_gl(GLsizei count, const char** string, char **s, const GLint* length, GLint *l)
4751 for(i = 0; i < count; ++i) {
4756 len = string[i] ? strlen(string[i]) : 0;
4758 len = string[i] ? strlen(string[i]) : 0;
4761 s[i] = do_eglShaderPatch(string[i], len, &l[i]);
4779 int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
4783 const char* ret_str = NULL;
4785 ProcessStruct* process = NULL;
4786 ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
4788 if (pConn->parent_dpy)
4790 pConn->Display = pConn->parent_dpy;
4793 for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
4795 ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
4796 if (processTab[iProcess].process_id == pid)
4798 process = &processTab[iProcess];
4801 else if (processTab[iProcess].process_id == 0)
4803 process = &processTab[iProcess];
4804 memset(process, 0, sizeof(ProcessStruct));
4805 process->process_id = pid;
4806 process->internal_num = pConn->last_assigned_internal_num++;
4807 init_gl_state(&process->default_state);
4808 process->current_state = &process->default_state;
4812 if (process == NULL)
4814 fprintf(stderr, "Too many processes !\n");
4817 if (process->internal_num != pConn->last_active_internal_num)
4819 glXMakeCurrent(pConn->Display, process->current_state->drawable, process->current_state->context);
4820 pConn->last_active_internal_num = process->internal_num;
4823 process->instr_counter++;
4825 if (display_function_call) fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
4826 //fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
4828 switch (func_number)
4836 case _synchronize_func:
4842 case _exit_process_func:
4846 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
4848 GLXContext ctxt = process->association_fakecontext_glxcontext[i].value;
4849 //fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
4850 // (long)process->association_fakecontext_glxcontext[i].key);
4851 glXDestroyContext(pConn->Display, ctxt);
4854 GET_EXT_PTR(void, glXDestroyPbuffer, (Display*, GLXPbuffer));
4855 for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
4857 GLXPbuffer pbuffer = (GLXPbuffer)process->association_fakepbuffer_pbuffer[i].value;
4858 fprintf(stderr, "Destroy pbuffer corresponding to fake_pbuffer = %ld\n",
4859 (long)process->association_fakepbuffer_pbuffer[i].key);
4860 if (!is_gl_vendor_ati(pConn->Display))
4861 ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
4864 for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
4866 //fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
4867 // process->association_clientdrawable_serverdrawable[i].key);
4869 Window win = (Window)process->association_clientdrawable_serverdrawable[i].value;
4870 XDestroyWindow(pConn->Display, win);
4874 while (XPending(pConn->Display) > 0) {
4876 XNextEvent(pConn->Display, &event);
4877 switch (event.type) {
4880 if (((XDestroyWindowEvent*)&event)->window == win)
4891 for(i=0;i<process->nbGLStates;i++)
4893 destroy_gl_state(process->glstates[i]);
4894 free(process->glstates[i]);
4896 destroy_gl_state(&process->default_state);
4897 free(process->glstates);
4899 pConn->active_win = 0;
4901 memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
4903 last_process_id = 0;
4908 case _changeWindowState_func:
4910 GLXDrawable client_drawable = args[0];
4911 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
4913 GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
4916 if (args[1] == IsViewable)
4918 WindowPosStruct pos;
4919 _get_window_pos(pConn->Display, drawable, &pos);
4920 if (pos.map_state != args[1])
4922 XMapWindow(pConn->Display, drawable);
4926 while (XPending(pConn->Display) > 0) {
4928 XNextEvent(pConn->Display, &event);
4929 switch (event.type) {
4930 case ConfigureNotify:
4932 if (((XConfigureEvent*)&event)->window == drawable)
4948 case _moveResizeWindow_func:
4950 int* params = (int*)args[1];
4951 GLXDrawable client_drawable = args[0];
4952 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
4954 GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
4957 WindowPosStruct pos;
4958 _get_window_pos(pConn->Display, drawable, &pos);
4959 if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
4961 int redim = !(params[2] == pos.width && params[3] == pos.height);
4962 pConn->active_win_x = params[0];
4963 pConn->active_win_y = params[1];
4966 fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
4967 fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
4970 XMoveResizeWindow(pConn->Display, drawable, params[0], params[1], params[2], params[3]);
4971 _get_window_pos(pConn->Display, drawable, &pos);
4972 process->currentDrawablePos = pos;
4973 //if (getenv("FORCE_GL_VIEWPORT"))
4975 glViewport(0, 0, params[2], params[3]);
4978 while (XPending(pConn->Display) > 0) {
4980 XNextEvent(pConn->Display, &event);
4981 switch (event.type) {
4982 case ConfigureNotify:
4984 if (((XConfigureEvent*)&event)->window == drawable)
4998 case _send_cursor_func:
5002 int width = args[2];
5003 int height = args[3];
5006 int* pixels = (int*)args[6];
5007 client_cursor.x = x;
5008 client_cursor.y = y;
5009 client_cursor.width = width;
5010 client_cursor.height = height;
5011 client_cursor.xhot = xhot;
5012 client_cursor.yhot = yhot;
5015 client_cursor.pixels = realloc(client_cursor.pixels, client_cursor.width * client_cursor.height * sizeof(int));
5016 memcpy(client_cursor.pixels, pixels, client_cursor.width * client_cursor.height * sizeof(int));
5018 //int in_window = (x >= 0 && y >= 0 &&
5019 //x < process->currentDrawablePos.width &&
5020 //y < process->currentDrawablePos.height);
5021 //fprintf(stderr, "cursor at %d %d (%s)\n", x, y, (in_window) ? "in window" : "not in window");
5025 case glXWaitGL_func:
5039 case glXChooseVisual_func:
5041 ret_int = glXChooseVisualFunc(pConn, (int*)args[2]);
5045 case glXQueryExtensionsString_func:
5047 ret_str = glXQueryExtensionsString(pConn->Display, 0);
5051 case glXQueryServerString_func:
5053 ret_str = glXQueryServerString(pConn->Display, 0, args[2]);
5057 case glXGetClientString_func:
5059 ret_str = glXGetClientString(pConn->Display, args[1]);
5063 case glXGetScreenDriver_func:
5065 GET_EXT_PTR(const char*, glXGetScreenDriver, (Display* , int ));
5066 ret_str = ptr_func_glXGetScreenDriver(pConn->Display, 0);
5070 case glXGetDriverConfig_func:
5072 GET_EXT_PTR(const char*, glXGetDriverConfig, (const char* ));
5073 ret_str = ptr_func_glXGetDriverConfig((const char*)args[0]);
5077 case glXCreateContext_func:
5079 int visualid = (int)args[1];
5080 int fake_shareList = (int)args[2];
5081 if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
5083 GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
5084 XVisualInfo* vis = get_visual_info_from_visual_id(pConn, visualid);
5088 ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
5092 vis = get_default_visual(pConn->Display);
5093 int saved_visualid = vis->visualid;
5094 vis->visualid = (visualid) ? visualid : saved_visualid;
5095 ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
5096 vis->visualid = saved_visualid;
5101 process->next_available_context_number ++;
5102 int fake_ctxt = process->next_available_context_number;
5103 set_association_fakecontext_visual(process, (void*)(long)fake_ctxt, vis);
5104 set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
5105 ret_int = fake_ctxt;
5107 _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
5118 case glXCreateNewContext_func:
5120 GET_EXT_PTR(GLXContext, glXCreateNewContext, (Display*, GLXFBConfig, int, GLXContext, int));
5121 GET_EXT_PTR(XVisualInfo*, glXGetVisualFromFBConfig, (Display*, GLXFBConfig));
5122 int client_fbconfig = args[1];
5123 XVisualInfo* vis = NULL;
5126 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5129 int fake_shareList = args[3];
5130 GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
5131 process->next_available_context_number ++;
5132 int fake_ctxt = process->next_available_context_number;
5133 GLXContext ctxt = ptr_func_glXCreateNewContext(pConn->Display, fbconfig, args[2], shareList, args[4]);
5134 set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
5136 vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig); /* visual info ????*/
5137 set_association_fakecontext_visual(process, (void *)(long)fake_ctxt, vis);
5139 ret_int = fake_ctxt;
5141 _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
5146 case glXCopyContext_func:
5148 GLXContext fake_src_ctxt = (GLXContext)args[1];
5149 GLXContext fake_dst_ctxt = (GLXContext)args[2];
5150 GLXContext src_ctxt;
5151 GLXContext dst_ctxt;
5152 if (display_function_call) fprintf(stderr, "fake_src_ctxt=%p, fake_dst_ctxt=%p\n", fake_src_ctxt, fake_dst_ctxt);
5154 if ((src_ctxt = get_association_fakecontext_glxcontext(process, fake_src_ctxt)) == NULL)
5156 fprintf(stderr, "invalid fake_src_ctxt (%p) !\n", fake_src_ctxt);
5158 else if ((dst_ctxt = get_association_fakecontext_glxcontext(process, fake_dst_ctxt)) == NULL)
5160 fprintf(stderr, "invalid fake_dst_ctxt (%p) !\n", fake_dst_ctxt);
5164 glXCopyContext(pConn->Display, src_ctxt, dst_ctxt, args[3]);
5169 case glXDestroyContext_func:
5171 int fake_ctxt = (int)args[1];
5172 if (display_function_call) fprintf(stderr, "fake_ctxt=%d\n", fake_ctxt);
5174 GLXContext ctxt = get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
5177 fprintf(stderr, "invalid fake_ctxt (%p) !\n", (void*)(long)fake_ctxt);
5182 for(i=0;i<process->nbGLStates;i++)
5184 if (process->glstates[i]->fake_ctxt == fake_ctxt)
5186 if (ctxt == process->current_state->context)
5187 process->current_state = &process->default_state;
5189 int fake_shareList = process->glstates[i]->fake_shareList;
5190 process->glstates[i]->ref --;
5191 if (process->glstates[i]->ref == 0)
5193 fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
5194 destroy_gl_state(process->glstates[i]);
5195 free(process->glstates[i]);
5196 memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
5197 process->nbGLStates--;
5202 for(i=0;i<process->nbGLStates;i++)
5204 if (process->glstates[i]->fake_ctxt == fake_shareList)
5206 process->glstates[i]->ref --;
5207 if (process->glstates[i]->ref == 0)
5209 fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
5210 destroy_gl_state(process->glstates[i]);
5211 free(process->glstates[i]);
5212 memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
5213 process->nbGLStates--;
5220 glXDestroyContext(pConn->Display, ctxt);
5221 unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
5230 case glXQueryVersion_func:
5232 ret_int = glXQueryVersion(pConn->Display, (int*)args[1], (int*)args[2]);
5236 case glGetString_func:
5238 ret_str = (char*)glGetString(args[0]);
5242 case glXMakeCurrent_func:
5245 GLXDrawable client_drawable = (GLXDrawable)args[1];
5246 GLXDrawable drawable = 0;
5247 int fake_ctxt = args[2];
5248 if (display_function_call) fprintf(stderr, "client_drawable=%p fake_ctx=%d\n", (void*)client_drawable, fake_ctxt);
5250 if (client_drawable == 0 && fake_ctxt == 0)
5252 ret_int = glXMakeCurrent(pConn->Display, 0, NULL);
5253 process->current_state = &process->default_state;
5255 else if ((drawable = (GLXDrawable)get_association_fakepbuffer_pbuffer(process, (void*)client_drawable)))
5257 GLXContext ctxt = get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
5260 fprintf(stderr, "invalid fake_ctxt (%d) (*)!\n", fake_ctxt);
5265 ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
5270 GLXContext ctxt = get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
5273 fprintf(stderr, "invalid fake_ctxt (%d)!\n", fake_ctxt);
5278 drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
5281 XVisualInfo* vis = (XVisualInfo*)get_association_fakecontext_visual(process, (void*)(long)fake_ctxt);
5283 vis = get_default_visual(pConn->Display);
5284 /*if (pConn->local_connection)
5285 drawable = client_drawable;
5288 if (/*pConn->local_connection &&*/ client_drawable == RootWindow(pConn->Display, 0))
5290 drawable = client_drawable;
5294 drawable = create_window(pConn, (pConn->local_connection) ? (Window)client_drawable : 0, vis, "", 0, 0, 480, 800);/* Default Window 크?綬�Simulator 크???? ?????磯?.*/
5296 //fprintf(stderr, "creating window\n");
5298 set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
5301 ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
5307 for(i=0;i<process->nbGLStates;i++)
5309 if (process->glstates[i]->fake_ctxt == fake_ctxt)
5311 process->current_state = process->glstates[i]; /* HACK !!! REMOVE */
5312 process->current_state->drawable = drawable;
5320 case glXSwapBuffers_func:
5322 GLXDrawable client_drawable = args[1];
5323 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
5325 GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
5328 fprintf(stderr, "unknown client_drawable (%p) !\n", (void*)client_drawable);
5332 if (client_cursor.pixels && pConn->local_connection == 0)
5334 glPushAttrib(GL_ALL_ATTRIB_BITS);
5335 glPushClientAttrib(GL_ALL_ATTRIB_BITS);
5337 glMatrixMode(GL_PROJECTION);
5340 glOrtho(0,process->currentDrawablePos.width,process->currentDrawablePos.height,0,-1,1);
5341 glMatrixMode(GL_MODELVIEW);
5346 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
5347 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
5348 glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
5349 glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
5350 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
5351 glShadeModel(GL_SMOOTH);
5354 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
5355 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
5358 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &numUnits);
5359 for(i=0;i<numUnits;i++)
5361 do_glActiveTextureARB(GL_TEXTURE0_ARB + i);
5362 glDisable(GL_TEXTURE_1D);
5363 glDisable(GL_TEXTURE_2D);
5364 glDisable(GL_TEXTURE_3D);
5366 glDisable(GL_ALPHA_TEST);
5367 glDisable(GL_DEPTH_TEST);
5368 glDisable(GL_STENCIL_TEST);
5369 glDisable(GL_SCISSOR_TEST);
5370 glDisable(GL_FRAGMENT_PROGRAM_ARB);
5371 glDisable(GL_VERTEX_PROGRAM_ARB);
5372 do_glUseProgramObjectARB (0);
5374 //memset(client_cursor.pixels, 255, client_cursor.width * client_cursor.height * sizeof(int));
5376 glRasterPos2d(client_cursor.x - client_cursor.xhot,
5377 client_cursor.y - client_cursor.yhot);
5378 glDrawPixels(client_cursor.width, client_cursor.height,
5379 GL_BGRA, GL_UNSIGNED_BYTE,
5380 client_cursor.pixels);
5382 glMatrixMode(GL_MODELVIEW);
5385 glMatrixMode(GL_PROJECTION);
5388 glPopClientAttrib();
5392 glXSwapBuffers(pConn->Display, drawable);
5397 case glXIsDirect_func:
5399 GLXContext fake_ctxt = (GLXContext)args[1];
5400 if (display_function_call) fprintf(stderr, "fake_ctx=%p\n", fake_ctxt);
5401 GLXContext ctxt = get_association_fakecontext_glxcontext(process, fake_ctxt);
5404 fprintf(stderr, "invalid fake_ctxt (%p) !\n", fake_ctxt);
5409 ret_char = glXIsDirect(pConn->Display, ctxt);
5414 case glXGetConfig_func:
5416 int visualid = args[1];
5417 XVisualInfo* vis = NULL;
5419 vis = get_visual_info_from_visual_id(pConn, visualid);
5421 vis = get_default_visual(pConn->Display);
5422 ret_int = glXGetConfig(pConn->Display, vis, args[2], (int*)args[3]);
5426 case glXGetConfig_extended_func:
5428 int visualid = args[1];
5431 XVisualInfo* vis = NULL;
5432 int* attribs = (int*)args[3];
5433 int* values = (int*)args[4];
5434 int* res = (int*)args[5];
5437 vis = get_visual_info_from_visual_id(pConn, visualid);
5439 vis = get_default_visual(pConn->Display);
5443 res[i] = glXGetConfig(pConn->Display, vis, attribs[i], &values[i]);
5448 case glXUseXFont_func:
5450 /* implementation is client-side only :-) */
5455 case glXQueryExtension_func:
5457 ret_int = glXQueryExtension(pConn->Display, (int*)args[1], (int*)args[2]);
5461 case glXChooseFBConfig_func:
5463 GET_EXT_PTR(GLXFBConfig*, glXChooseFBConfig, (Display*, int, int*, int*));
5464 if (process->nfbconfig == MAX_FBCONFIG)
5471 GLXFBConfig* fbconfigs = ptr_func_glXChooseFBConfig(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
5474 process->fbconfigs[process->nfbconfig] = fbconfigs;
5475 process->fbconfigs_max[process->nfbconfig] = *(int*)args[3];
5476 process->nfbconfig++;
5477 ret_int = 1 + process->nfbconfig_total;
5478 process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
5488 case glXChooseFBConfigSGIX_func:
5490 GET_EXT_PTR(GLXFBConfigSGIX*, glXChooseFBConfigSGIX, (Display*, int, int*, int*));
5491 if (process->nfbconfig == MAX_FBCONFIG)
5498 GLXFBConfigSGIX* fbconfigs = ptr_func_glXChooseFBConfigSGIX(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
5501 process->fbconfigs[process->nfbconfig] = fbconfigs;
5502 process->fbconfigs_max[process->nfbconfig] = *(int*)args[3];
5503 process->nfbconfig++;
5504 ret_int = 1 + process->nfbconfig_total;
5505 process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
5515 case glXGetFBConfigs_func:
5517 GET_EXT_PTR(GLXFBConfig*, glXGetFBConfigs, (Display*, int, int*));
5518 if (process->nfbconfig == MAX_FBCONFIG)
5525 GLXFBConfig* fbconfigs = ptr_func_glXGetFBConfigs(pConn->Display, args[1], (int*)args[2]);
5528 process->fbconfigs[process->nfbconfig] = fbconfigs;
5529 process->fbconfigs_max[process->nfbconfig] = *(int*)args[2];
5530 process->nfbconfig++;
5531 ret_int = 1 + process->nfbconfig_total;
5532 process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
5542 case glXDestroyWindow_func:
5544 GLXDrawable client_drawable = args[1];
5545 if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
5547 GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
5549 destroy_window(pConn, (Window)drawable);
5552 for(i=0;process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
5554 if (process->association_clientdrawable_serverdrawable[i].key == (void *) client_drawable)
5556 process->association_clientdrawable_serverdrawable[i].key = NULL;
5557 process->association_clientdrawable_serverdrawable[i].value = NULL;
5561 for(i=0;i<process->nbGLStates;i++)
5563 if (process->glstates[i]->drawable == drawable)
5565 process->glstates[i]->drawable = 0;
5569 if( process->current_state->drawable == drawable )
5570 process->current_state = &process->default_state;
5576 case glXCreatePbuffer_func:
5578 GET_EXT_PTR(GLXPbuffer, glXCreatePbuffer, (Display*, GLXFBConfig, int*));
5579 int client_fbconfig = args[1];
5581 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5584 GLXPbuffer pbuffer = ptr_func_glXCreatePbuffer(pConn->Display, fbconfig, (int*)args[2]);
5585 fprintf(stderr, "glXCreatePbuffer --> %X\n", (int)pbuffer);
5588 process->next_available_pbuffer_number ++;
5589 int fake_pbuffer = process->next_available_pbuffer_number;
5590 set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
5591 fprintf(stderr, "set_association_fakepbuffer_pbuffer(%d, %X)\n", fake_pbuffer, (int)pbuffer);
5592 ret_int = fake_pbuffer;
5598 case glXCreateGLXPbufferSGIX_func:
5600 GET_EXT_PTR(GLXPbufferSGIX, glXCreateGLXPbufferSGIX, (Display*, GLXFBConfig, int, int, int*));
5601 int client_fbconfig = args[1];
5603 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5606 GLXPbufferSGIX pbuffer = ptr_func_glXCreateGLXPbufferSGIX(pConn->Display, fbconfig, args[2], args[3], (int*)args[4]);
5609 process->next_available_pbuffer_number ++;
5610 int fake_pbuffer = process->next_available_pbuffer_number;
5611 set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
5612 ret_int = fake_pbuffer;
5618 case glXDestroyPbuffer_func:
5620 GET_EXT_PTR(void, glXDestroyPbuffer, (Display*, GLXPbuffer));
5621 GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
5622 if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
5624 GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5627 fprintf(stderr, "invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
5631 if (!is_gl_vendor_ati(pConn->Display))
5632 ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
5633 unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5638 case glXDestroyGLXPbufferSGIX_func:
5640 GET_EXT_PTR(void, glXDestroyGLXPbufferSGIX, (Display*, GLXPbuffer));
5641 GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
5642 if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
5644 GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5647 fprintf(stderr, "invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
5651 if (!is_gl_vendor_ati(pConn->Display))
5652 ptr_func_glXDestroyGLXPbufferSGIX(pConn->Display, pbuffer);
5653 unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5658 case glXBindTexImageATI_func:
5660 GET_EXT_PTR(void, glXBindTexImageATI, (Display*, GLXPbuffer, int));
5661 GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
5662 if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
5664 GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5667 fprintf(stderr, "glXBindTexImageATI : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
5671 ptr_func_glXBindTexImageATI(pConn->Display, pbuffer, args[2]);
5676 case glXReleaseTexImageATI_func:
5678 GET_EXT_PTR(void, glXReleaseTexImageATI, (Display*, GLXPbuffer, int));
5679 GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
5680 if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
5682 GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5685 fprintf(stderr, "glXReleaseTexImageATI : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
5689 ptr_func_glXReleaseTexImageATI(pConn->Display, pbuffer, args[2]);
5694 case glXBindTexImageARB_func:
5696 GET_EXT_PTR(Bool, glXBindTexImageARB, (Display*, GLXPbuffer, int));
5697 GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
5698 if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
5700 GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5703 fprintf(stderr, "glXBindTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
5708 ret_int = ptr_func_glXBindTexImageARB(pConn->Display, pbuffer, args[2]);
5713 case glXReleaseTexImageARB_func:
5715 GET_EXT_PTR(Bool, glXReleaseTexImageARB, (Display*, GLXPbuffer, int));
5716 GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
5717 if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
5719 GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
5722 fprintf(stderr, "glXReleaseTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
5727 ret_int = ptr_func_glXReleaseTexImageARB(pConn->Display, pbuffer, args[2]);
5732 case glXGetFBConfigAttrib_func:
5734 GET_EXT_PTR(int, glXGetFBConfigAttrib, (Display*, GLXFBConfig, int, int*));
5735 int client_fbconfig = args[1];
5737 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5739 ret_int = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, args[2], (int*)args[3]);
5743 case glXGetFBConfigAttrib_extended_func:
5745 GET_EXT_PTR(int, glXGetFBConfigAttrib, (Display*, GLXFBConfig, int, int*));
5746 int client_fbconfig = args[1];
5749 int* attribs = (int*)args[3];
5750 int* values = (int*)args[4];
5751 int* res = (int*)args[5];
5752 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5758 res[i] = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, attribs[i], &values[i]);
5768 case glXGetFBConfigAttribSGIX_func:
5770 GET_EXT_PTR(int, glXGetFBConfigAttribSGIX, (Display*, GLXFBConfigSGIX, int, int*));
5771 int client_fbconfig = args[1];
5773 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5775 ret_int = ptr_func_glXGetFBConfigAttribSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
5779 case glXQueryContext_func:
5781 GET_EXT_PTR(int, glXQueryContext, (Display*, GLXContext, int, int*));
5782 GLXContext fake_ctxt = (GLXContext)args[1];
5783 if (display_function_call) fprintf(stderr, "fake_ctx=%p\n", fake_ctxt);
5784 GLXContext ctxt = get_association_fakecontext_glxcontext(process, fake_ctxt);
5787 fprintf(stderr, "invalid fake_ctxt (%p) !\n", fake_ctxt);
5792 ret_int = ptr_func_glXQueryContext(pConn->Display, ctxt, args[2], (int*)args[3]);
5797 case glXQueryDrawable_func:
5799 GET_EXT_PTR(void, glXQueryDrawable, (Display*, GLXDrawable, int, int*));
5800 GLXDrawable client_drawable = (GLXDrawable)args[1];
5801 GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
5802 if (display_function_call) fprintf(stderr, "client_drawable=%d\n", (int)client_drawable);
5805 fprintf(stderr, "invalid client_drawable (%d) !\n", (int)client_drawable);
5809 ptr_func_glXQueryDrawable(pConn->Display, drawable, args[2], (int*)args[3]);
5814 case glXQueryGLXPbufferSGIX_func:
5816 GET_EXT_PTR(int, glXQueryGLXPbufferSGIX, (Display*, GLXFBConfigSGIX, int, int*));
5817 int client_fbconfig = args[1];
5819 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5821 ret_int = ptr_func_glXQueryGLXPbufferSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
5825 case glXCreateContextWithConfigSGIX_func:
5827 GET_EXT_PTR(GLXContext, glXCreateContextWithConfigSGIX, (Display*, GLXFBConfigSGIX, int, GLXContext, int));
5828 int client_fbconfig = args[1];
5830 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5833 GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)args[3]);
5834 process->next_available_context_number ++;
5835 int fake_ctxt = process->next_available_context_number;
5836 GLXContext ctxt = ptr_func_glXCreateContextWithConfigSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], shareList, args[4]);
5837 set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
5838 ret_int = fake_ctxt;
5843 case glXGetVisualFromFBConfig_func:
5845 GET_EXT_PTR(XVisualInfo*, glXGetVisualFromFBConfig, (Display*, GLXFBConfig));
5846 int client_fbconfig = args[1];
5848 GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
5851 AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
5852 XVisualInfo* vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig);
5853 ret_int = (vis) ? vis->visualid : 0;
5856 pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
5857 realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
5858 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
5859 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
5860 tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = vis;
5861 pConn->nTabAssocAttribListVisual++;
5862 pConn->tabAssocAttribListVisual = tabAssocAttribListVisual;
5864 if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
5869 case glXSwapIntervalSGI_func:
5871 GET_EXT_PTR(int, glXSwapIntervalSGI, (int));
5872 ret_int = ptr_func_glXSwapIntervalSGI(args[0]);
5876 case glXGetProcAddress_fake_func:
5878 if (display_function_call) fprintf(stderr, "%s\n", (char*)args[0]);
5879 ret_int = glXGetProcAddressARB((const GLubyte*)args[0]) != NULL;
5883 case glXGetProcAddress_global_fake_func:
5885 int nbElts = args[0];
5886 char* huge_buffer = (char*)args[1];
5887 char* result = (char*)args[2];
5890 for(i=0;i<nbElts;i++)
5892 int len = strlen(huge_buffer);
5893 result[i] = glXGetProcAddressARB((const GLubyte*)huge_buffer) != NULL;
5894 huge_buffer += len + 1;
5899 /* Begin of texture stuff */
5900 case glBindTexture_func:
5901 case glBindTextureEXT_func:
5903 int target = args[0];
5904 unsigned int client_texture = args[1];
5905 unsigned int server_texture;
5907 if (client_texture == 0)
5909 glBindTexture(target, 0);
5913 alloc_value(process->current_state->textureAllocator, client_texture);
5914 server_texture = process->current_state->tabTextures[client_texture];
5915 if (server_texture == 0)
5917 glGenTextures(1, &server_texture);
5918 process->current_state->tabTextures[client_texture] = server_texture;
5920 glBindTexture(target, server_texture);
5925 case glGenTextures_fake_func:
5927 GET_EXT_PTR(void, glGenTextures, (GLsizei n, GLuint *textures));
5930 unsigned int* clientTabTextures = malloc(n * sizeof(int));
5931 unsigned int* serverTabTextures = malloc(n * sizeof(int));
5933 alloc_range(process->current_state->textureAllocator, n, clientTabTextures);
5935 ptr_func_glGenTextures(n, serverTabTextures);
5938 process->current_state->tabTextures[clientTabTextures[i]] = serverTabTextures[i];
5941 free(clientTabTextures);
5942 free(serverTabTextures);
5947 case glDeleteTextures_func:
5949 GET_EXT_PTR(void, glDeleteTextures, (GLsizei n, const GLuint *textures));
5952 unsigned int* clientTabTextures = (unsigned int*)args[1];
5954 delete_range(process->current_state->textureAllocator, n, clientTabTextures);
5956 unsigned int* serverTabTextures = malloc(n * sizeof(int));
5959 serverTabTextures[i] = get_server_texture(process, clientTabTextures[i]);
5961 ptr_func_glDeleteTextures(n, serverTabTextures);
5964 process->current_state->tabTextures[clientTabTextures[i]] = 0;
5966 free(serverTabTextures);
5970 case glPrioritizeTextures_func:
5972 GET_EXT_PTR(void, glPrioritizeTextures, (GLsizei n, const GLuint *textures, const GLclampf *priorities));
5976 unsigned int* textures = (unsigned int*)args[1];
5979 textures[i] = get_server_texture(process, textures[i]);
5981 ptr_func_glPrioritizeTextures(n, textures, (const GLclampf*)args[2]);
5985 case glAreTexturesResident_func:
5987 GET_EXT_PTR(void, glAreTexturesResident, (GLsizei n, const GLuint *textures, GLboolean *residences));
5990 unsigned int* textures = (unsigned int*)args[1];
5993 textures[i] = get_server_texture(process, textures[i]);
5995 ptr_func_glAreTexturesResident(n, textures, (GLboolean*)args[2]);
5999 case glIsTexture_func:
6000 case glIsTextureEXT_func:
6002 GET_EXT_PTR(GLboolean, glIsTexture, (GLuint texture ));
6003 unsigned int client_texture = args[0];
6004 unsigned int server_texture = get_server_texture(process, client_texture);
6006 ret_char = ptr_func_glIsTexture(server_texture);
6012 case glFramebufferTexture1DEXT_func:
6014 GET_EXT_PTR(void, glFramebufferTexture1DEXT, (int, int, int, int, int));
6015 unsigned int client_texture = args[3];
6016 unsigned int server_texture = get_server_texture(process, client_texture);
6018 ptr_func_glFramebufferTexture1DEXT(args[0], args[1], args[2], server_texture, args[4]);
6022 case glFramebufferTexture2DEXT_func:
6024 GET_EXT_PTR(void, glFramebufferTexture2DEXT, (int, int, int, int, int));
6025 unsigned int client_texture = args[3];
6026 unsigned int server_texture = get_server_texture(process, client_texture);
6028 ptr_func_glFramebufferTexture2DEXT(args[0], args[1], args[2], server_texture, args[4]);
6032 case glFramebufferTexture3DEXT_func:
6034 GET_EXT_PTR(void, glFramebufferTexture3DEXT, (int, int, int, int, int, int));
6035 unsigned int client_texture = args[3];
6036 unsigned int server_texture = get_server_texture(process, client_texture);
6038 ptr_func_glFramebufferTexture3DEXT(args[0], args[1], args[2], server_texture, args[4], args[5]);
6041 /* End of texture stuff */
6043 /* Begin of list stuff */
6046 unsigned int client_list = args[0];
6047 unsigned int server_list = get_server_list(process, client_list);
6049 ret_char = glIsList(server_list);
6055 case glDeleteLists_func:
6058 unsigned int first_client = args[0];
6061 unsigned int first_server = get_server_list(process, first_client);
6064 if (get_server_list(process, first_client + i) != first_server + i)
6069 glDeleteLists(first_server, n);
6075 glDeleteLists(get_server_list(process, first_client + i), 1);
6081 process->current_state->tabLists[first_client + i] = 0;
6083 delete_consecutive_values(process->current_state->listAllocator, first_client, n);
6087 case glGenLists_fake_func:
6091 unsigned int server_first = glGenLists(n);
6094 unsigned int client_first = alloc_range(process->current_state->listAllocator, n, NULL);
6097 process->current_state->tabLists[client_first + i] = server_first + i;
6103 case glNewList_func:
6105 unsigned int client_list = args[0];
6107 alloc_value(process->current_state->listAllocator, client_list);
6108 unsigned int server_list = get_server_list(process, client_list);
6109 if (server_list == 0)
6111 server_list = glGenLists(1);
6112 process->current_state->tabLists[client_list] = server_list;
6114 glNewList(server_list, mode);
6118 case glCallList_func:
6120 unsigned int client_list = args[0];
6121 unsigned int server_list = get_server_list(process, client_list);
6122 glCallList(server_list);
6126 case glCallLists_func:
6131 const GLvoid* lists = (const GLvoid*)args[2];
6132 int* new_lists = malloc(sizeof(int) * n);
6135 new_lists[i] = get_server_list(process, translate_id(i, type, lists));
6137 glCallLists(n, GL_UNSIGNED_INT, new_lists);
6143 /* End of list stuff */
6145 /* Begin of buffer stuff */
6146 case glBindBufferARB_func:
6148 GET_EXT_PTR(void, glBindBufferARB, (int,int));
6149 int target = args[0];
6150 unsigned int client_buffer = args[1];
6151 unsigned int server_buffer;
6153 if (client_buffer == 0)
6155 ptr_func_glBindBufferARB(target, 0);
6159 server_buffer = get_server_buffer(process, client_buffer);
6160 ptr_func_glBindBufferARB(target, server_buffer);
6165 case glGenBuffersARB_fake_func:
6167 GET_EXT_PTR(void, glGenBuffersARB, (int,unsigned int*));
6170 unsigned int* clientTabBuffers = malloc(n * sizeof(int));
6171 unsigned int* serverTabBuffers = malloc(n * sizeof(int));
6173 alloc_range(process->current_state->bufferAllocator, n, clientTabBuffers);
6175 ptr_func_glGenBuffersARB(n, serverTabBuffers);
6178 process->current_state->tabBuffers[clientTabBuffers[i]] = serverTabBuffers[i];
6181 free(clientTabBuffers);
6182 free(serverTabBuffers);
6187 case glDeleteBuffersARB_func:
6189 GET_EXT_PTR(void, glDeleteBuffersARB, (int,int*));
6192 unsigned int* clientTabBuffers = (unsigned int*)args[1];
6194 delete_range(process->current_state->bufferAllocator, n, clientTabBuffers);
6196 int* serverTabBuffers = malloc(n * sizeof(int));
6199 serverTabBuffers[i] = get_server_buffer(process, clientTabBuffers[i]);
6201 ptr_func_glDeleteBuffersARB(n, serverTabBuffers);
6204 process->current_state->tabBuffers[clientTabBuffers[i]] = 0;
6206 free(serverTabBuffers);
6210 case glIsBufferARB_func:
6212 GET_EXT_PTR(int, glIsBufferARB, (int));
6213 unsigned int client_buffer = args[0];
6214 unsigned int server_buffer = get_server_buffer(process, client_buffer);
6216 ret_int = ptr_func_glIsBufferARB(server_buffer);
6222 /* Endo of buffer stuff */
6224 case glShaderSourceARB_fake_func:
6226 GET_EXT_PTR(void, glShaderSourceARB, (int,int,char**,void*));
6230 GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
6231 int* tab_length = (int*)args[3];
6234 tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
6235 acc_length += tab_length[i];
6237 ptr_func_glShaderSourceARB(args[0], args[1], tab_prog, tab_length);
6242 case glShaderSource_fake_func:
6244 GET_EXT_PTR(void, glShaderSource, (int,int,char**,void*));
6248 GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
6249 int* tab_length = (int*)args[3];
6251 char **tab_prog_new;
6252 GLint *tab_length_new;
6254 tab_prog_new = malloc(args[1]* sizeof(char*));
6255 tab_length_new = malloc(args[1]* sizeof(GLint));
6257 memset(tab_prog_new, 0, args[1] * sizeof(char*));
6258 memset(tab_length_new, 0, args[1] * sizeof(GLint));
6263 tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
6264 acc_length += tab_length[i];
6267 shadersrc_gles_to_gl(args[1], tab_prog, tab_prog_new, tab_length, tab_length_new);
6269 if (!tab_prog_new || !tab_length_new)
6272 ptr_func_glShaderSource(args[0], args[1], tab_prog_new, tab_length_new);
6274 for (i = 0; i < args[1]; i++)
6275 free(tab_prog_new[i]);
6277 free(tab_length_new);
6283 case glVertexPointer_fake_func:
6285 int offset = args[0];
6288 int stride = args[3];
6289 int bytes_size = args[4];
6290 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6291 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6292 memcpy(process->current_state->vertexPointer + offset, (void*)args[5], bytes_size);
6293 /*fprintf(stderr, "glVertexPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
6294 size, type, stride, bytes_size);*/
6295 glVertexPointer(size, type, stride, process->current_state->vertexPointer);
6299 case glNormalPointer_fake_func:
6301 int offset = args[0];
6303 int stride = args[2];
6304 int bytes_size = args[3];
6305 process->current_state->normalPointerSize = MAX(process->current_state->normalPointerSize, offset + bytes_size);
6306 process->current_state->normalPointer = realloc(process->current_state->normalPointer, process->current_state->normalPointerSize);
6307 memcpy(process->current_state->normalPointer + offset, (void*)args[4], bytes_size);
6308 //fprintf(stderr, "glNormalPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
6309 glNormalPointer(type, stride, process->current_state->normalPointer);
6313 case glIndexPointer_fake_func:
6315 int offset = args[0];
6317 int stride = args[2];
6318 int bytes_size = args[3];
6319 process->current_state->indexPointerSize = MAX(process->current_state->indexPointerSize, offset + bytes_size);
6320 process->current_state->indexPointer = realloc(process->current_state->indexPointer, process->current_state->indexPointerSize);
6321 memcpy(process->current_state->indexPointer + offset, (void*)args[4], bytes_size);
6322 //fprintf(stderr, "glIndexPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
6323 glIndexPointer(type, stride, process->current_state->indexPointer);
6327 case glEdgeFlagPointer_fake_func:
6329 int offset = args[0];
6330 int stride = args[1];
6331 int bytes_size = args[2];
6332 process->current_state->edgeFlagPointerSize = MAX(process->current_state->edgeFlagPointerSize, offset + bytes_size);
6333 process->current_state->edgeFlagPointer = realloc(process->current_state->edgeFlagPointer, process->current_state->edgeFlagPointerSize);
6334 memcpy(process->current_state->edgeFlagPointer + offset, (void*)args[3], bytes_size );
6335 //fprintf(stderr, "glEdgeFlagPointer_fake_func stride = %d, bytes_size=%d\n", stride, bytes_size);
6336 glEdgeFlagPointer(stride, process->current_state->edgeFlagPointer);
6340 case glVertexAttribPointerARB_fake_func:
6342 GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
6343 int offset = args[0];
6344 int index = args[1];
6347 int normalized = args[4];
6348 int stride = args[5];
6349 int bytes_size = args[6];
6350 process->current_state->vertexAttribPointerSize[index] = MAX(process->current_state->vertexAttribPointerSize[index], offset + bytes_size);
6351 process->current_state->vertexAttribPointer[index] = realloc(process->current_state->vertexAttribPointer[index],
6352 process->current_state->vertexAttribPointerSize[index]);
6353 memcpy(process->current_state->vertexAttribPointer[index] + offset, (void*)args[7], bytes_size);
6354 ptr_func_glVertexAttribPointerARB(index, size, type, normalized, stride,
6355 process->current_state->vertexAttribPointer[index]);
6359 case glVertexAttribPointerNV_fake_func:
6361 GET_EXT_PTR(void, glVertexAttribPointerNV, (int,int,int,int,void*));
6362 int offset = args[0];
6363 int index = args[1];
6366 int stride = args[4];
6367 int bytes_size = args[5];
6368 process->current_state->vertexAttribPointerNVSize[index] = MAX(process->current_state->vertexAttribPointerNVSize[index], offset + bytes_size);
6369 process->current_state->vertexAttribPointerNV[index] = realloc(process->current_state->vertexAttribPointerNV[index],
6370 process->current_state->vertexAttribPointerNVSize[index]);
6371 memcpy(process->current_state->vertexAttribPointerNV[index] + offset, (void*)args[6], bytes_size);
6372 ptr_func_glVertexAttribPointerNV(index, size, type, stride,
6373 process->current_state->vertexAttribPointerNV[index]);
6377 case glColorPointer_fake_func:
6379 int offset = args[0];
6382 int stride = args[3];
6383 int bytes_size = args[4];
6384 process->current_state->colorPointerSize = MAX(process->current_state->colorPointerSize, offset + bytes_size);
6385 process->current_state->colorPointer = realloc(process->current_state->colorPointer, process->current_state->colorPointerSize);
6386 memcpy(process->current_state->colorPointer + offset, (void*)args[5], bytes_size);
6387 //fprintf(stderr, "glColorPointer_fake_func bytes_size = %d\n", bytes_size);
6388 glColorPointer(size, type, stride, process->current_state->colorPointer);
6393 case glSecondaryColorPointer_fake_func:
6395 GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
6396 int offset = args[0];
6399 int stride = args[3];
6400 int bytes_size = args[4];
6401 process->current_state->secondaryColorPointerSize = MAX(process->current_state->secondaryColorPointerSize, offset + bytes_size);
6402 process->current_state->secondaryColorPointer = realloc(process->current_state->secondaryColorPointer, process->current_state->secondaryColorPointerSize);
6403 memcpy(process->current_state->secondaryColorPointer + offset, (void*)args[5], bytes_size);
6404 //fprintf(stderr, "glSecondaryColorPointer_fake_func bytes_size = %d\n", bytes_size);
6405 ptr_func_glSecondaryColorPointer(size, type, stride, process->current_state->secondaryColorPointer);
6410 case glPushClientAttrib_func:
6413 if (process->current_state->clientStateSp < MAX_CLIENT_STATE_STACK_SIZE)
6415 process->current_state->clientStateStack[process->current_state->clientStateSp].mask = mask;
6416 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT)
6418 process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex =
6419 process->current_state->activeTextureIndex;
6421 process->current_state->clientStateSp++;
6423 glPushClientAttrib(mask);
6427 case glPopClientAttrib_func:
6429 if (process->current_state->clientStateSp > 0)
6431 process->current_state->clientStateSp--;
6432 if (process->current_state->clientStateStack[process->current_state->clientStateSp].mask & GL_CLIENT_VERTEX_ARRAY_BIT)
6434 process->current_state->activeTextureIndex =
6435 process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex;
6438 glPopClientAttrib();
6442 case glClientActiveTexture_func:
6443 case glClientActiveTextureARB_func:
6445 int activeTexture = args[0];
6446 process->current_state->activeTextureIndex = activeTexture - GL_TEXTURE0_ARB;
6447 do_glClientActiveTextureARB(activeTexture);
6451 case glTexCoordPointer_fake_func:
6453 int offset = args[0];
6454 int index = args[1];
6457 int stride = args[4];
6458 int bytes_size = args[5];
6459 process->current_state->texCoordPointerSize[index] = MAX(process->current_state->texCoordPointerSize[index], offset + bytes_size);
6460 process->current_state->texCoordPointer[index] = realloc(process->current_state->texCoordPointer[index], process->current_state->texCoordPointerSize[index]);
6461 memcpy(process->current_state->texCoordPointer[index] + offset, (void*)args[6], bytes_size);
6462 /*fprintf(stderr, "glTexCoordPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
6463 size, type, stride, bytes_size);*/
6464 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + index);
6465 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[index]);
6466 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6470 case glWeightPointerARB_fake_func:
6472 GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
6473 int offset = args[0];
6476 int stride = args[3];
6477 int bytes_size = args[4];
6478 process->current_state->weightPointerSize = MAX(process->current_state->weightPointerSize, offset + bytes_size);
6479 process->current_state->weightPointer = realloc(process->current_state->weightPointer, process->current_state->weightPointerSize);
6480 memcpy(process->current_state->weightPointer + offset, (void*)args[5], bytes_size);
6481 /*fprintf(stderr, "glWeightPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
6482 size, type, stride, bytes_size);*/
6483 ptr_func_glWeightPointerARB(size, type, stride, process->current_state->weightPointer);
6487 case glMatrixIndexPointerARB_fake_func:
6489 GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
6490 int offset = args[0];
6493 int stride = args[3];
6494 int bytes_size = args[4];
6495 process->current_state->matrixIndexPointerSize = MAX(process->current_state->matrixIndexPointerSize, offset + bytes_size);
6496 process->current_state->matrixIndexPointer = realloc(process->current_state->matrixIndexPointer, process->current_state->matrixIndexPointerSize);
6497 memcpy(process->current_state->matrixIndexPointer + offset, (void*)args[5], bytes_size);
6498 /*fprintf(stderr, "glMatrixIndexPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
6499 size, type, stride, bytes_size);*/
6500 ptr_func_glMatrixIndexPointerARB(size, type, stride, process->current_state->matrixIndexPointer);
6504 case glFogCoordPointer_fake_func:
6506 GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
6507 int offset = args[0];
6509 int stride = args[2];
6510 int bytes_size = args[3];
6511 process->current_state->fogCoordPointerSize = MAX(process->current_state->fogCoordPointerSize, offset + bytes_size);
6512 process->current_state->fogCoordPointer = realloc(process->current_state->fogCoordPointer, process->current_state->fogCoordPointerSize);
6513 memcpy(process->current_state->fogCoordPointer + offset, (void*)args[4], bytes_size);
6514 //fprintf(stderr, "glFogCoordPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
6515 ptr_func_glFogCoordPointer(type, stride, process->current_state->fogCoordPointer);
6519 case glVariantPointerEXT_fake_func:
6521 GET_EXT_PTR(void, glVariantPointerEXT, (int,int,int,void*));
6522 int offset = args[0];
6525 int stride = args[3];
6526 int bytes_size = args[4];
6527 process->current_state->variantPointerEXTSize[id] = MAX(process->current_state->variantPointerEXTSize[id], offset + bytes_size);
6528 process->current_state->variantPointerEXT[id] = realloc(process->current_state->variantPointerEXT[id], process->current_state->variantPointerEXTSize[id]);
6529 memcpy(process->current_state->variantPointerEXT[id] + offset, (void*)args[5], bytes_size);
6530 //fprintf(stderr, "glVariantPointerEXT_fake_func[%d] type=%d, stride=%d, byte_size=%d\n", id, type, stride, bytes_size);
6531 ptr_func_glVariantPointerEXT(id, type, stride, process->current_state->variantPointerEXT[id]);
6535 case glInterleavedArrays_fake_func:
6537 GET_EXT_PTR(void, glInterleavedArrays, (int,int,void*));
6538 int offset = args[0];
6539 int format = args[1];
6540 int stride = args[2];
6541 int bytes_size = args[3];
6542 process->current_state->interleavedArraysSize = MAX(process->current_state->interleavedArraysSize, offset + bytes_size);
6543 process->current_state->interleavedArrays = realloc(process->current_state->interleavedArrays, process->current_state->interleavedArraysSize);
6544 memcpy(process->current_state->interleavedArrays + offset, (void*)args[4], bytes_size);
6545 //fprintf(stderr, "glInterleavedArrays_fake_func format=%d, stride=%d, byte_size=%d\n", format, stride, bytes_size);
6546 ptr_func_glInterleavedArrays(format, stride, process->current_state->interleavedArrays);
6550 case glElementPointerATI_fake_func:
6552 GET_EXT_PTR(void, glElementPointerATI, (int,void*));
6554 int bytes_size = args[1];
6555 process->current_state->elementPointerATISize = bytes_size;
6556 process->current_state->elementPointerATI = realloc(process->current_state->elementPointerATI, process->current_state->elementPointerATISize);
6557 memcpy(process->current_state->elementPointerATI, (void*)args[2], bytes_size);
6558 //fprintf(stderr, "glElementPointerATI_fake_func type=%d, byte_size=%d\n", type, bytes_size);
6559 ptr_func_glElementPointerATI(type, process->current_state->elementPointerATI);
6563 case glTexCoordPointer01_fake_func:
6567 int stride = args[2];
6568 int bytes_size = args[3];
6569 process->current_state->texCoordPointerSize[0] = bytes_size;
6570 process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
6571 memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
6572 /*fprintf(stderr, "glTexCoordPointer01_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
6573 size, type, stride, bytes_size);*/
6574 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6575 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
6576 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
6577 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
6578 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6582 case glTexCoordPointer012_fake_func:
6586 int stride = args[2];
6587 int bytes_size = args[3];
6588 process->current_state->texCoordPointerSize[0] = bytes_size;
6589 process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
6590 memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
6591 /*fprintf(stderr, "glTexCoordPointer012_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
6592 size, type, stride, bytes_size);*/
6593 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6594 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
6595 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
6596 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
6597 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
6598 glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
6599 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6604 case glVertexAndNormalPointer_fake_func:
6606 int vertexPointerSize = args[0];
6607 int vertexPointerType = args[1];
6608 int vertexPointerStride = args[2];
6609 int normalPointerType = args[3];
6610 int normalPointerStride = args[4];
6611 int bytes_size = args[5];
6612 void* ptr = (void*)args[6];
6613 process->current_state->vertexPointerSize = bytes_size;
6614 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, bytes_size);
6615 memcpy(process->current_state->vertexPointer, ptr, bytes_size);
6616 glVertexPointer(vertexPointerSize, vertexPointerType, vertexPointerStride, process->current_state->vertexPointer);
6617 glNormalPointer(normalPointerType, normalPointerStride, process->current_state->vertexPointer);
6621 case glVertexNormalPointerInterlaced_fake_func:
6624 int offset = args[i++];
6625 int vertexPointerSize = args[i++];
6626 int vertexPointerType = args[i++];
6627 int stride = args[i++];
6628 int normalPointerOffset= args[i++];
6629 int normalPointerType = args[i++];
6630 int bytes_size = args[i++];
6631 void* ptr = (void*)args[i++];
6632 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6633 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6634 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6635 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6636 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6640 case glTuxRacerDrawElements_fake_func:
6643 int count = args[1];
6644 int isColorEnabled = args[2];
6645 void* ptr = (void*)args[3];
6646 int stride = 6 * sizeof(float) + ((isColorEnabled) ? 4 * sizeof(unsigned char) : 0);
6647 glVertexPointer( 3, GL_FLOAT, stride, ptr);
6648 glNormalPointer( GL_FLOAT, stride, ptr + 3 * sizeof(float));
6650 glColorPointer( 4, GL_UNSIGNED_BYTE, stride, ptr + 6 * sizeof(float));
6651 glDrawArrays(mode, 0, count);
6655 case glVertexNormalColorPointerInterlaced_fake_func:
6658 int offset = args[i++];
6659 int vertexPointerSize = args[i++];
6660 int vertexPointerType = args[i++];
6661 int stride = args[i++];
6662 int normalPointerOffset= args[i++];
6663 int normalPointerType = args[i++];
6664 int colorPointerOffset = args[i++];
6665 int colorPointerSize = args[i++];
6666 int colorPointerType = args[i++];
6667 int bytes_size = args[i++];
6668 void* ptr = (void*)args[i++];
6669 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6670 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6671 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6672 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6673 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6674 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
6678 case glVertexColorTexCoord0PointerInterlaced_fake_func:
6681 int offset = args[i++];
6682 int vertexPointerSize = args[i++];
6683 int vertexPointerType = args[i++];
6684 int stride = args[i++];
6685 int colorPointerOffset = args[i++];
6686 int colorPointerSize = args[i++];
6687 int colorPointerType = args[i++];
6688 int texCoord0PointerOffset = args[i++];
6689 int texCoord0PointerSize = args[i++];
6690 int texCoord0PointerType = args[i++];
6691 int bytes_size = args[i++];
6692 void* ptr = (void*)args[i++];
6693 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6694 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6695 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6696 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6697 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
6698 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6699 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
6700 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6704 case glVertexNormalTexCoord0PointerInterlaced_fake_func:
6707 int offset = args[i++];
6708 int vertexPointerSize = args[i++];
6709 int vertexPointerType = args[i++];
6710 int stride = args[i++];
6711 int normalPointerOffset = args[i++];
6712 int normalPointerType = args[i++];
6713 int texCoord0PointerOffset = args[i++];
6714 int texCoord0PointerSize = args[i++];
6715 int texCoord0PointerType = args[i++];
6716 int bytes_size = args[i++];
6717 void* ptr = (void*)args[i++];
6718 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6719 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6720 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6721 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6722 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6723 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6724 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
6725 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6729 case glVertexNormalTexCoord01PointerInterlaced_fake_func:
6732 int offset = args[i++];
6733 int vertexPointerSize = args[i++];
6734 int vertexPointerType = args[i++];
6735 int stride = args[i++];
6736 int normalPointerOffset = args[i++];
6737 int normalPointerType = args[i++];
6738 int texCoord0PointerOffset = args[i++];
6739 int texCoord0PointerSize = args[i++];
6740 int texCoord0PointerType = args[i++];
6741 int texCoord1PointerOffset = args[i++];
6742 int texCoord1PointerSize = args[i++];
6743 int texCoord1PointerType = args[i++];
6744 int bytes_size = args[i++];
6745 void* ptr = (void*)args[i++];
6746 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6747 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6748 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6749 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6750 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6751 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6752 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
6753 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
6754 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
6755 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6759 case glVertexNormalTexCoord012PointerInterlaced_fake_func:
6762 int offset = args[i++];
6763 int vertexPointerSize = args[i++];
6764 int vertexPointerType = args[i++];
6765 int stride = args[i++];
6766 int normalPointerOffset = args[i++];
6767 int normalPointerType = args[i++];
6768 int texCoord0PointerOffset = args[i++];
6769 int texCoord0PointerSize = args[i++];
6770 int texCoord0PointerType = args[i++];
6771 int texCoord1PointerOffset = args[i++];
6772 int texCoord1PointerSize = args[i++];
6773 int texCoord1PointerType = args[i++];
6774 int texCoord2PointerOffset = args[i++];
6775 int texCoord2PointerSize = args[i++];
6776 int texCoord2PointerType = args[i++];
6777 int bytes_size = args[i++];
6778 void* ptr = (void*)args[i++];
6779 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6780 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6781 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6782 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6783 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6784 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6785 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
6786 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
6787 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
6788 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
6789 glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
6790 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6794 case glVertexNormalColorTexCoord0PointerInterlaced_fake_func:
6797 int offset = args[i++];
6798 int vertexPointerSize = args[i++];
6799 int vertexPointerType = args[i++];
6800 int stride = args[i++];
6801 int normalPointerOffset = args[i++];
6802 int normalPointerType = args[i++];
6803 int colorPointerOffset = args[i++];
6804 int colorPointerSize = args[i++];
6805 int colorPointerType = args[i++];
6806 int texCoord0PointerOffset = args[i++];
6807 int texCoord0PointerSize = args[i++];
6808 int texCoord0PointerType = args[i++];
6809 int bytes_size = args[i++];
6810 void* ptr = (void*)args[i++];
6811 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6812 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6813 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6814 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6815 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6816 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
6817 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6818 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
6819 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6823 case glVertexNormalColorTexCoord01PointerInterlaced_fake_func:
6826 int offset = args[i++];
6827 int vertexPointerSize = args[i++];
6828 int vertexPointerType = args[i++];
6829 int stride = args[i++];
6830 int normalPointerOffset = args[i++];
6831 int normalPointerType = args[i++];
6832 int colorPointerOffset = args[i++];
6833 int colorPointerSize = args[i++];
6834 int colorPointerType = args[i++];
6835 int texCoord0PointerOffset = args[i++];
6836 int texCoord0PointerSize = args[i++];
6837 int texCoord0PointerType = args[i++];
6838 int texCoord1PointerOffset = args[i++];
6839 int texCoord1PointerSize = args[i++];
6840 int texCoord1PointerType = args[i++];
6841 int bytes_size = args[i++];
6842 void* ptr = (void*)args[i++];
6843 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6844 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6845 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6846 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6847 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6848 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
6849 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6850 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
6851 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
6852 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
6853 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6857 case glVertexNormalColorTexCoord012PointerInterlaced_fake_func:
6860 int offset = args[i++];
6861 int vertexPointerSize = args[i++];
6862 int vertexPointerType = args[i++];
6863 int stride = args[i++];
6864 int normalPointerOffset = args[i++];
6865 int normalPointerType = args[i++];
6866 int colorPointerOffset = args[i++];
6867 int colorPointerSize = args[i++];
6868 int colorPointerType = args[i++];
6869 int texCoord0PointerOffset = args[i++];
6870 int texCoord0PointerSize = args[i++];
6871 int texCoord0PointerType = args[i++];
6872 int texCoord1PointerOffset = args[i++];
6873 int texCoord1PointerSize = args[i++];
6874 int texCoord1PointerType = args[i++];
6875 int texCoord2PointerOffset = args[i++];
6876 int texCoord2PointerSize = args[i++];
6877 int texCoord2PointerType = args[i++];
6878 int bytes_size = args[i++];
6879 void* ptr = (void*)args[i++];
6880 process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
6881 process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
6882 memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
6883 glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
6884 glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
6885 glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
6886 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
6887 glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
6888 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
6889 glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
6890 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
6891 glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
6892 do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
6896 case _glVertexPointer_buffer_func:
6898 glVertexPointer(args[0],args[1],args[2],(void*)args[3]);
6902 case _glNormalPointer_buffer_func:
6904 glNormalPointer(args[0],args[1],(void*)args[2]);
6908 case _glColorPointer_buffer_func:
6910 glColorPointer(args[0],args[1],args[2],(void*)args[3]);
6914 case _glSecondaryColorPointer_buffer_func:
6916 GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
6917 ptr_func_glSecondaryColorPointer(args[0],args[1],args[2],(void*)args[3]);
6921 case _glIndexPointer_buffer_func:
6923 glIndexPointer(args[0],args[1],(void*)args[2]);
6927 case _glTexCoordPointer_buffer_func:
6929 glTexCoordPointer(args[0],args[1],args[2],(void*)args[3]);
6933 case _glEdgeFlagPointer_buffer_func:
6935 glEdgeFlagPointer(args[0],(void*)args[1]);
6939 case _glVertexAttribPointerARB_buffer_func:
6941 GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
6942 ptr_func_glVertexAttribPointerARB(args[0], args[1], args[2], args[3], args[4], (void*)args[5]);
6946 case _glWeightPointerARB_buffer_func:
6948 GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
6949 ptr_func_glWeightPointerARB(args[0], args[1], args[2], (void*)args[3]);
6953 case _glMatrixIndexPointerARB_buffer_func:
6955 GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
6956 ptr_func_glMatrixIndexPointerARB(args[0], args[1], args[2], (void*)args[3]);
6960 case _glFogCoordPointer_buffer_func:
6962 GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
6963 ptr_func_glFogCoordPointer(args[0], args[1], (void*)args[2]);
6967 case _glVariantPointerEXT_buffer_func:
6969 GET_EXT_PTR(void, glVariantPointerEXT, (int, int,int,void*));
6970 ptr_func_glVariantPointerEXT(args[0], args[1], args[2], (void*)args[3]);
6974 case _glDrawElements_buffer_func:
6976 glDrawElements(args[0],args[1],args[2],(void*)args[3]);
6980 case _glDrawRangeElements_buffer_func:
6982 glDrawRangeElements(args[0],args[1],args[2],args[3],args[4],(void*)args[5]);
6986 case _glMultiDrawElements_buffer_func:
6988 GET_EXT_PTR(void, glMultiDrawElements, (int,int*,int,void**, int));
6989 ptr_func_glMultiDrawElements(args[0],(int*)args[1],args[2],(void**)args[3],args[4]);
6993 case _glGetError_fake_func:
6998 case glGetIntegerv_func:
7000 glGetIntegerv(args[0], (int*)args[1]);
7001 //fprintf(stderr,"glGetIntegerv(%X)=%d\n", (int)args[0], *(int*)args[1]);
7005 case _glReadPixels_pbo_func:
7007 glReadPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (void*)(args[6]));
7011 case _glDrawPixels_pbo_func:
7013 glDrawPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_UNSIGNED_INT(args[2]), ARG_TO_UNSIGNED_INT(args[3]), (const void*)(args[4]));
7017 case _glMapBufferARB_fake_func:
7019 GET_EXT_PTR(GLvoid*, glMapBufferARB, (GLenum, GLenum));
7020 GET_EXT_PTR(GLboolean, glUnmapBufferARB, (GLenum));
7021 int target = args[0];
7023 void* dst_ptr = (void*)args[2];
7024 void* src_ptr = ptr_func_glMapBufferARB(target, GL_READ_ONLY);
7027 memcpy(dst_ptr, src_ptr, size);
7028 ret_int = ptr_func_glUnmapBufferARB(target);
7037 case fake_gluBuild2DMipmaps_func:
7039 GET_GLU_PTR(GLint, gluBuild2DMipmaps, (GLenum arg_0, GLint arg_1, GLsizei arg_2, GLsizei arg_3, GLenum arg_4, GLenum arg_5, const GLvoid * arg_6));
7040 if (ptr_func_gluBuild2DMipmaps == NULL)
7041 ptr_func_gluBuild2DMipmaps = mesa_gluBuild2DMipmaps;
7042 ptr_func_gluBuild2DMipmaps(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (const void*)(args[6]));
7046 case _glSelectBuffer_fake_func:
7048 process->current_state->selectBufferSize = args[0] * 4;
7049 process->current_state->selectBufferPtr = realloc(process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
7050 glSelectBuffer(args[0], process->current_state->selectBufferPtr);
7054 case _glGetSelectBuffer_fake_func:
7056 void* ptr = (void*)args[0];
7057 memcpy(ptr, process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
7061 case _glFeedbackBuffer_fake_func:
7063 process->current_state->feedbackBufferSize = args[0] * 4;
7064 process->current_state->feedbackBufferPtr = realloc(process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
7065 glFeedbackBuffer(args[0], args[1], process->current_state->feedbackBufferPtr);
7069 case _glGetFeedbackBuffer_fake_func:
7071 void* ptr = (void*)args[0];
7072 memcpy(ptr, process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
7077 case glEnableClientState_func:
7079 if (display_function_call) fprintf(stderr, "cap : %s\n", nameArrays[args[0] - GL_VERTEX_ARRAY]);
7080 glEnableClientState(args[0]);
7084 case glDisableClientState_func:
7086 if (display_function_call) fprintf(stderr, "cap : %s\n", nameArrays[args[0] - GL_VERTEX_ARRAY]);
7087 glDisableClientState(args[0]);
7091 case glClientActiveTexture_func:
7092 case glClientActiveTextureARB_func:
7094 if (display_function_call) fprintf(stderr, "client activeTexture %d\n", args[0] - GL_TEXTURE0_ARB);
7095 glClientActiveTextureARB(args[0]);
7099 case glActiveTextureARB_func:
7101 if (display_function_call) fprintf(stderr, "server activeTexture %d\n", args[0] - GL_TEXTURE0_ARB);
7102 glActiveTextureARB(args[0]);
7106 case glLockArraysEXT_func:
7109 case glUnlockArraysEXT_func:
7112 case glArrayElement_func:
7114 glArrayElement(args[0]);
7118 case glDrawArrays_func:
7120 glDrawArrays(args[0],args[1],args[2]);
7124 case glDrawElements_func:
7126 glDrawElements(args[0],args[1],args[2],(void*)args[3]);
7130 case glDrawRangeElements_func:
7132 glDrawRangeElements(args[0],args[1],args[2],args[3],args[4],(void*)args[5]);
7137 case glGetError_func:
7139 #ifdef SYSTEMATIC_ERROR_CHECK
7140 ret_int = process->current_state->last_error;
7142 ret_int = glGetError();
7147 case glNewObjectBufferATI_func:
7149 GET_EXT_PTR(int, glNewObjectBufferATI, (int,void*, int));
7150 ret_int = ptr_func_glNewObjectBufferATI(args[0], (void*)args[1], args[2]);
7155 execute_func(func_number, args, &ret_int, &ret_char);
7159 #ifdef SYSTEMATIC_ERROR_CHECK
7160 if (func_number == glGetError_func)
7162 process->current_state->last_error = 0;
7166 process->current_state->last_error = glGetError();
7167 if (process->current_state->last_error != 0)
7169 printf("error %s 0x%X\n", tab_opengl_calls_name[func_number], process->current_state->last_error);
7174 Signature* signature = (Signature*)tab_opengl_calls[func_number];
7175 int ret_type = signature->ret_type;
7176 //int nb_args = signature->nb_args;
7183 case TYPE_UNSIGNED_CHAR:
7188 case TYPE_UNSIGNED_INT:
7191 case TYPE_CONST_CHAR:
7193 strncpy(ret_string, (ret_str) ? ret_str : "", 32768);
7198 fprintf(stderr, "unexpected ret type : %d\n", ret_type);
7203 if (display_function_call) fprintf(stderr, "[%d]< %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
7209 void create_process_tab( OGLS_Conn *pConn )
7211 if (pConn == NULL) {
7212 fprintf(stderr, "create_process_tab: pConn is NULL.\n");
7215 pConn->processTab = malloc( sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
7216 if( !pConn->processTab )
7218 perror( "init_process_tab" );
7222 memset(pConn->processTab, 0, sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
7225 void remove_process_tab( OGLS_Conn *pConn )
7227 if( !pConn->processTab ) return ;
7228 free( pConn->processTab );
7229 pConn->processTab = NULL;