2 * Guest-side implementation of GL/GLX API. Replacement of standard libGL.so
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
25 #ifndef __INCLUDE_COMMON_H
28 #include <X11/Xutil.h>
29 #include <X11/extensions/Xfixes.h>
30 #include <X11/extensions/XShm.h>
36 #include "range_alloc.h"
38 #define ENABLE_THREAD_SAFETY
41 extern int debug_array_ptr;
42 extern int disable_optim;
44 #define IS_GLX_CALL(x) (x >= glXChooseVisual_func && x <= glXDestroyPixmap_func)
46 #define SIZE_BUFFER_COMMAND (1024*64)
47 //#define MAX_SIZE_BUFFER_COMMAND (1024*1024*10)
48 #define MAX_SIZE_BUFFER_COMMAND (1024*1024*200)
50 #define POINTER_TO_ARG(x) (long)(void*)(x)
51 #define CHAR_TO_ARG(x) (long)(x)
52 #define SHORT_TO_ARG(x) (long)(x)
53 #define INT_TO_ARG(x) (long)(x)
54 #define UNSIGNED_CHAR_TO_ARG(x) (long)(x)
55 #define UNSIGNED_SHORT_TO_ARG(x) (long)(x)
56 #define UNSIGNED_INT_TO_ARG(x) (long)(x)
57 #define FLOAT_TO_ARG(x) (long)*((int*)(&x))
58 #define DOUBLE_TO_ARG(x) (long)(&x)
60 #define NOT_IMPLEMENTED(x) log_gl(#x " not implemented !\n")
61 //#define PROVIDE_STUB_IMPLEMENTATION
63 #define CHECK_ARGS(x, y) (1 / ((sizeof(x)/sizeof(x[0])) == (sizeof(y)/sizeof(y[0])) ? 1 : 0)) ? x : x, y
67 #define CONCAT(a, b) a##b
68 #define DEFINE_EXT(glFunc, paramsDecl, paramsCall) GLAPI void APIENTRY CONCAT(glFunc,EXT) paramsDecl { glFunc paramsCall; }
71 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
74 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
78 #define NB_MAX_TEXTURES 16
79 #define MY_GL_MAX_VERTEX_ATTRIBS_ARB 16
80 #define MY_GL_MAX_VERTEX_ATTRIBS_NV 16
81 #define MY_GL_MAX_VARIANT_POINTER_EXT 16
84 #define CHECK_PROC_WITH_RET(x)
86 //static void log_gl(const char* format, ...);
88 #include "opengl_utils.h"
103 unsigned int last_crc;
107 GLboolean swapEndian;
125 ClientArray vertexArray;
126 ClientArray normalArray;
127 ClientArray colorArray;
128 ClientArray secondaryColorArray;
129 ClientArray indexArray;
130 ClientArray edgeFlagArray;
131 ClientArray weightArray;
132 ClientArray matrixIndexArray;
133 ClientArray fogCoordArray;
134 ClientArray texCoordArray[NB_MAX_TEXTURES];
135 ClientArray vertexAttribArray[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
136 ClientArray vertexAttribArrayNV[MY_GL_MAX_VERTEX_ATTRIBS_NV];
137 ClientArray variantPointer[MY_GL_MAX_VARIANT_POINTER_EXT];
138 ClientArray elementArrayATI;
139 InterleavedArrays interleavedArrays;
147 PixelStoreMode unpack;
149 int clientActiveTexture;
150 int selectBufferSize;
151 void* selectBufferPtr;
152 int feedbackBufferSize;
153 void* feedbackBufferPtr;
156 #define MAX_MATRIX_STACK_SIZE 64
157 #define NB_GL_MATRIX (3+NB_MAX_TEXTURES+31)
165 Matrixd stack[MAX_MATRIX_STACK_SIZE];
245 IntSetRanges updatedRangesAfterMapping;
246 void* ptrUpdatedWhileMapped;
257 #define MAX_CLIENT_STATE_STACK_SIZE 16
258 #define MAX_SERVER_STATE_STACK_SIZE 16
260 #define N_CLIP_PLANES 8
265 int bindTexture2D; /* optimization for openquartz */
266 int bindTextureRectangle;
267 int linesmoothEnabled; /* optimization for googleearth */
269 int texture2DEnabled;
271 int scissorTestEnabled;
272 int vertexProgramEnabled;
277 Texture2DDim* texture2DCache;
278 int texture2DCacheDim;
279 Texture2DDim* textureProxy2DCache;
280 int textureProxy2DCacheDim;
281 Texture2DDim* textureRectangleCache;
282 int textureRectangleCacheDim;
283 Texture2DDim* textureProxyRectangleCache;
284 int textureProxyRectangleCacheDim;
286 double clipPlanes[N_CLIP_PLANES][4];
293 XShmSegmentInfo shminfo;
306 GLXDrawable current_drawable;
307 GLXDrawable current_read_drawable;
308 struct timeval last_swap_buffer_time;
309 GLXContext shareList;
310 XFixesCursorImage last_cursor;
313 RendererData *renderer_data;
315 int isAssociatedToFBConfigVisual;
317 ClientState client_state_stack[MAX_CLIENT_STATE_STACK_SIZE];
318 ClientState client_state;
321 ServerState server_stack[MAX_SERVER_STATE_STACK_SIZE];
322 ServerState current_server_state;
325 int arrayBuffer; /* optimization for ww2d */
326 int elementArrayBuffer;
327 int pixelUnpackBuffer;
330 Buffer arrayBuffers[32768];
331 Buffer elementArrayBuffers[32768];
332 Buffer pixelUnpackBuffers[32768];
333 Buffer pixelPackBuffers[32768];
335 RangeAllocator ownTextureAllocator;
336 RangeAllocator* textureAllocator;
337 RangeAllocator ownBufferAllocator;
338 RangeAllocator* bufferAllocator;
339 RangeAllocator ownListAllocator;
340 RangeAllocator* listAllocator;
344 ObjectBufferATI objectBuffersATI[32768];
346 UniformLocation* uniformLocations;
347 int countUniformLocations;
349 WindowInfoStruct last_win_state;
350 ViewportStruct viewport;
351 ViewportStruct scissorbox;
355 int currentRasterPosKnown;
356 float currentRasterPos[4];
358 char* tuxRacerBuffer;
366 int isBetweenLockArrays;
370 GLMatrix matrix[NB_GL_MATRIX];
373 extern int nbGLStates;
374 extern GLState** glstates;
375 extern GLState* default_gl_state;
377 #define __INCLUDE_COMMON_H
378 #endif /* __INCLUDE_COMMON_H */