├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── flags.cmake ├── include ├── EGL │ ├── egl.h │ ├── eglext.h │ └── eglplatform.h ├── GL │ ├── gl.h │ ├── gl_mangle.h │ ├── glext.h │ ├── glu.h │ ├── glu_mangle.h │ ├── glx.h │ ├── glx_mangle.h │ ├── glxext.h │ └── internal │ │ └── dri_interface.h ├── GLES │ ├── egl.h │ ├── gl.h │ ├── gl2.h │ ├── gl2ext.h │ ├── gl2platform.h │ ├── gl3.h │ ├── gl3ext.h │ ├── gl3platform.h │ ├── glext.h │ └── glplatform.h └── KHR │ └── khrplatform.h ├── spec ├── build ├── gen.py ├── requirements.txt ├── template │ ├── base │ │ ├── base.j2 │ │ ├── header.j2 │ │ ├── headers.j2 │ │ ├── indexed_call.j2 │ │ ├── pack.h.j2 │ │ ├── util.j2 │ │ └── wrap.c.j2 │ ├── call.c.j2 │ ├── glshim.c.j2 │ ├── glxfuncs.j2 │ ├── mock.c.j2 │ ├── mock.h.j2 │ ├── stub.c.j2 │ └── stub.h.j2 ├── xml │ ├── egl.xml │ ├── gles-2.0.xml │ ├── glx.xml │ ├── glxext.xml │ ├── opengl.xml │ ├── toyml.py │ └── wgl.xml └── yml │ ├── alsa.yml │ ├── egl.yml │ ├── gles-1.1.yml │ ├── gles-2.0.yml │ ├── glext-1.1.yml │ ├── glx.yml │ ├── glxext.yml │ ├── my_glx.yml │ ├── oes.yml │ ├── opengl.yml │ ├── skip_index.yml │ └── wgl.yml ├── src ├── CMakeLists.txt ├── config.h ├── gl │ ├── array.c │ ├── array.h │ ├── blend.c │ ├── block.c │ ├── block.h │ ├── clear.c │ ├── const.h │ ├── defines.h │ ├── depth.c │ ├── error.h │ ├── eval.c │ ├── eval.h │ ├── get.c │ ├── get.h │ ├── gl.c │ ├── gl.h │ ├── light.c │ ├── light.h │ ├── line.c │ ├── line.h │ ├── list.c │ ├── list.h │ ├── loader.c │ ├── loader.h │ ├── matrix.c │ ├── matrix.h │ ├── pixel.c │ ├── pixel.h │ ├── raster.c │ ├── raster.h │ ├── remote.c │ ├── remote.h │ ├── render.c │ ├── render.h │ ├── skip.h │ ├── stack.c │ ├── stack.h │ ├── texgen.c │ ├── texgen.h │ ├── texture.c │ ├── texture.h │ ├── types.h │ └── wrap │ │ ├── call.c │ │ ├── call2.c │ │ ├── extra.h │ │ ├── gl.c │ │ ├── glpack.h │ │ ├── glshim.c │ │ ├── glshim2.c │ │ ├── glstub.c │ │ ├── glstub.h │ │ ├── remote.c │ │ ├── remote.h │ │ ├── stub.c │ │ ├── stub.h │ │ ├── stub2.c │ │ ├── stub2.h │ │ └── types.h ├── glx │ ├── gles2funcs.inc │ ├── glesfuncs.inc │ ├── glx.c │ ├── glx.h │ └── lookup.c ├── preload │ └── preload.c ├── remote │ └── remote.c └── util │ ├── extypes.h │ ├── gl_helpers.h │ ├── gl_str.c │ ├── gl_str.h │ ├── khash.h │ ├── liveinfo.c │ ├── liveinfo.h │ ├── mat4.c │ ├── mat4.h │ ├── math │ ├── eval.c │ └── eval.h │ ├── ring.c │ ├── ring.h │ ├── tack.c │ ├── tack.h │ ├── text.c │ ├── text.h │ └── vectorial │ ├── LICENSE │ ├── config.h │ ├── mat4f.h │ ├── simd4f.h │ ├── simd4f_common.h │ ├── simd4f_gnu.h │ ├── simd4f_neon.h │ ├── simd4f_scalar.h │ ├── simd4f_sse.h │ ├── simd4x4f.h │ ├── simd4x4f_gnu.h │ ├── simd4x4f_neon.h │ ├── simd4x4f_scalar.h │ ├── simd4x4f_sse.h │ ├── vec2f.h │ ├── vec3f.h │ ├── vec4f.h │ ├── vec_convert.h │ └── vectorial.h └── test ├── requirements.txt ├── run ├── tests ├── _mat4.c ├── array │ └── skip.c ├── block │ ├── incomplete.c │ ├── quads.c │ ├── rect.c │ └── tri.c ├── get.c ├── list │ ├── nested.c │ ├── new.c │ └── retain.c ├── meta │ └── test.py ├── raster │ └── raster.c ├── remote │ ├── _race.c │ ├── _ring.c │ ├── _string.c │ └── _thread.c ├── render │ └── feedback.c ├── state │ └── default.c └── util │ ├── gl_str.c │ └── tack.c └── util ├── mock.c ├── mock.h ├── run.py ├── template ├── CMakeLists.j2 └── CMakeLists_pure.j2 ├── test.h └── test_skip.h /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | lib 6 | test/bin 7 | test/build 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | 4 | python: 5 | - "2.7" 6 | 7 | script: test/run 8 | install: 9 | - pip install -r test/requirements.txt 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.8) 2 | 3 | project(glshim) 4 | set(CMAKE_MACOSX_RPATH 1) 5 | 6 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 7 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 8 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 9 | 10 | link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) 11 | 12 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 13 | link_directories(/opt/X11/lib) 14 | endif() 15 | 16 | set(BIN_INSTALL_DIR bin) 17 | set(LIB_INSTALL_DIR lib/${CMAKE_LIBRARY_ARCHITECTURE}/glshim) 18 | 19 | set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${BIN_INSTALL_DIR}" 20 | LIBRARY DESTINATION "${LIB_INSTALL_DIR}" 21 | ARCHIVE DESTINATION "${LIB_INSTALL_DIR}") 22 | 23 | link_directories(${CMAKE_BINARY_DIR}/lib) 24 | add_definitions(-O2) 25 | include(flags.cmake) 26 | 27 | include_directories(include) 28 | add_subdirectory(src) 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Ryan Hileman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/lunixbochs/glshim.svg?branch=master)](https://travis-ci.org/lunixbochs/glshim) 2 | 3 | glshim 4 | ==== 5 | 6 | This is a shim providing OpenGL 1.x functionality to OpenGL ES accelerated cards. 7 | 8 | ---- 9 | 10 | Compiling 11 | ---- 12 | 13 | cmake .; make GL 14 | 15 | ---- 16 | 17 | GLU 18 | ---- 19 | 20 | You probably want the glu branch from https://github.com/lunixbochs/glues 21 | 22 | git clone git@github.com:lunixbochs/glues.git; git checkout glu; cmake .; make 23 | 24 | ---- 25 | 26 | Installation 27 | ---- 28 | 29 | Put lib/libGL.so.1 in your `LD_LIBRARY_PATH`. If you need GLU, build libGLU.so.1 from the glues repo and do likewise. 30 | -------------------------------------------------------------------------------- /flags.cmake: -------------------------------------------------------------------------------- 1 | add_definitions(-g -funwind-tables -ffast-math -D_GNU_SOURCE) 2 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") 4 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") 5 | add_definitions(-fsingle-precision-constant) 6 | if(NOT BCMHOST) 7 | add_definitions(-mfpu=neon -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8) 8 | endif() 9 | endif() 10 | -------------------------------------------------------------------------------- /include/EGL/eglplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __eglplatform_h_ 2 | #define __eglplatform_h_ 3 | 4 | /* 5 | ** Copyright (c) 2007-2009 The Khronos Group Inc. 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person obtaining a 8 | ** copy of this software and/or associated documentation files (the 9 | ** "Materials"), to deal in the Materials without restriction, including 10 | ** without limitation the rights to use, copy, modify, merge, publish, 11 | ** distribute, sublicense, and/or sell copies of the Materials, and to 12 | ** permit persons to whom the Materials are furnished to do so, subject to 13 | ** the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included 16 | ** in all copies or substantial portions of the Materials. 17 | ** 18 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 25 | */ 26 | 27 | /* Platform-specific types and definitions for egl.h 28 | * $Revision: 12306 $ on $Date: 2010-08-25 09:51:28 -0700 (Wed, 25 Aug 2010) $ 29 | * 30 | * Adopters may modify khrplatform.h and this file to suit their platform. 31 | * You are encouraged to submit all modifications to the Khronos group so that 32 | * they can be included in future versions of this file. Please submit changes 33 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 34 | * by filing a bug against product "EGL" component "Registry". 35 | */ 36 | 37 | #include 38 | 39 | /* Macros used in EGL function prototype declarations. 40 | * 41 | * EGL functions should be prototyped as: 42 | * 43 | * EGLAPI return-type EGLAPIENTRY eglFunction(arguments); 44 | * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments); 45 | * 46 | * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h 47 | */ 48 | 49 | #ifndef EGLAPI 50 | #define EGLAPI KHRONOS_APICALL 51 | #endif 52 | 53 | #ifndef EGLAPIENTRY 54 | #define EGLAPIENTRY KHRONOS_APIENTRY 55 | #endif 56 | #define EGLAPIENTRYP EGLAPIENTRY* 57 | 58 | /* The types NativeDisplayType, NativeWindowType, and NativePixmapType 59 | * are aliases of window-system-dependent types, such as X Display * or 60 | * Windows Device Context. They must be defined in platform-specific 61 | * code below. The EGL-prefixed versions of Native*Type are the same 62 | * types, renamed in EGL 1.3 so all types in the API start with "EGL". 63 | * 64 | * Khronos STRONGLY RECOMMENDS that you use the default definitions 65 | * provided below, since these changes affect both binary and source 66 | * portability of applications using EGL running on different EGL 67 | * implementations. 68 | */ 69 | 70 | #if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ 71 | #ifndef WIN32_LEAN_AND_MEAN 72 | #define WIN32_LEAN_AND_MEAN 1 73 | #endif 74 | #include 75 | 76 | typedef HDC EGLNativeDisplayType; 77 | typedef HBITMAP EGLNativePixmapType; 78 | typedef HWND EGLNativeWindowType; 79 | 80 | #elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */ 81 | 82 | typedef int EGLNativeDisplayType; 83 | typedef void *EGLNativeWindowType; 84 | typedef void *EGLNativePixmapType; 85 | 86 | #elif defined(__unix__) 87 | 88 | /* X11 (tentative) */ 89 | #include 90 | #include 91 | 92 | typedef Display *EGLNativeDisplayType; 93 | typedef Pixmap EGLNativePixmapType; 94 | typedef Window EGLNativeWindowType; 95 | 96 | #else 97 | #error "Platform not recognized" 98 | #endif 99 | 100 | /* EGL 1.2 types, renamed for consistency in EGL 1.3 */ 101 | typedef EGLNativeDisplayType NativeDisplayType; 102 | typedef EGLNativePixmapType NativePixmapType; 103 | typedef EGLNativeWindowType NativeWindowType; 104 | 105 | 106 | /* Define EGLint. This must be a signed integral type large enough to contain 107 | * all legal attribute names and values passed into and out of EGL, whether 108 | * their type is boolean, bitmask, enumerant (symbolic constant), integer, 109 | * handle, or other. While in general a 32-bit integer will suffice, if 110 | * handles are 64 bit types, then EGLint should be defined as a signed 64-bit 111 | * integer type. 112 | */ 113 | typedef khronos_int32_t EGLint; 114 | 115 | #endif /* __eglplatform_h */ 116 | -------------------------------------------------------------------------------- /include/GL/glu_mangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Mesa 3-D graphics library 3 | * Version: 3.0 4 | * Copyright (C) 1995-1998 Brian Paul 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the Free 18 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | 22 | #ifndef GLU_MANGLE_H 23 | #define GLU_MANGLE_H 24 | 25 | 26 | #define gluLookAt mgluLookAt 27 | #define gluOrtho2D mgluOrtho2D 28 | #define gluPerspective mgluPerspective 29 | #define gluPickMatrix mgluPickMatrix 30 | #define gluProject mgluProject 31 | #define gluUnProject mgluUnProject 32 | #define gluErrorString mgluErrorString 33 | #define gluScaleImage mgluScaleImage 34 | #define gluBuild1DMipmaps mgluBuild1DMipmaps 35 | #define gluBuild2DMipmaps mgluBuild2DMipmaps 36 | #define gluNewQuadric mgluNewQuadric 37 | #define gluDeleteQuadric mgluDeleteQuadric 38 | #define gluQuadricDrawStyle mgluQuadricDrawStyle 39 | #define gluQuadricOrientation mgluQuadricOrientation 40 | #define gluQuadricNormals mgluQuadricNormals 41 | #define gluQuadricTexture mgluQuadricTexture 42 | #define gluQuadricCallback mgluQuadricCallback 43 | #define gluCylinder mgluCylinder 44 | #define gluSphere mgluSphere 45 | #define gluDisk mgluDisk 46 | #define gluPartialDisk mgluPartialDisk 47 | #define gluNewNurbsRenderer mgluNewNurbsRenderer 48 | #define gluDeleteNurbsRenderer mgluDeleteNurbsRenderer 49 | #define gluLoadSamplingMatrices mgluLoadSamplingMatrices 50 | #define gluNurbsProperty mgluNurbsProperty 51 | #define gluGetNurbsProperty mgluGetNurbsProperty 52 | #define gluBeginCurve mgluBeginCurve 53 | #define gluEndCurve mgluEndCurve 54 | #define gluNurbsCurve mgluNurbsCurve 55 | #define gluBeginSurface mgluBeginSurface 56 | #define gluEndSurface mgluEndSurface 57 | #define gluNurbsSurface mgluNurbsSurface 58 | #define gluBeginTrim mgluBeginTrim 59 | #define gluEndTrim mgluEndTrim 60 | #define gluPwlCurve mgluPwlCurve 61 | #define gluNurbsCallback mgluNurbsCallback 62 | #define gluNewTess mgluNewTess 63 | #define gluDeleteTess mgluDeleteTess 64 | #define gluTessBeginPolygon mgluTessBeginPolygon 65 | #define gluTessBeginContour mgluTessBeginContour 66 | #define gluTessVertex mgluTessVertex 67 | #define gluTessEndPolygon mgluTessEndPolygon 68 | #define gluTessEndContour mgluTessEndContour 69 | #define gluTessProperty mgluTessProperty 70 | #define gluTessNormal mgluTessNormal 71 | #define gluTessCallback mgluTessCallback 72 | #define gluGetTessProperty mgluGetTessProperty 73 | #define gluBeginPolygon mgluBeginPolygon 74 | #define gluNextContour mgluNextContour 75 | #define gluEndPolygon mgluEndPolygon 76 | #define gluGetString mgluGetString 77 | #define gluBuild1DMipmapLevels mgluBuild1DMipmapLevels 78 | #define gluBuild2DMipmapLevels mgluBuild2DMipmapLevels 79 | #define gluBuild3DMipmapLevels mgluBuild3DMipmapLevels 80 | #define gluBuild3DMipmaps mgluBuild3DMipmaps 81 | #define gluCheckExtension mgluCheckExtension 82 | #define gluUnProject4 mgluUnProject4 83 | #define gluNurbsCallbackData mgluNurbsCallbackData 84 | #define gluNurbsCallbackDataEXT mgluNurbsCallbackDataEXT 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /include/GL/glx_mangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Mesa 3-D graphics library 3 | * Version: 6.5 4 | * 5 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | 26 | #ifndef GLX_MANGLE_H 27 | #define GLX_MANGLE_H 28 | 29 | #define glXChooseVisual mglXChooseVisual 30 | #define glXCreateContext mglXCreateContext 31 | #define glXDestroyContext mglXDestroyContext 32 | #define glXMakeCurrent mglXMakeCurrent 33 | #define glXCopyContext mglXCopyContext 34 | #define glXSwapBuffers mglXSwapBuffers 35 | #define glXCreateGLXPixmap mglXCreateGLXPixmap 36 | #define glXDestroyGLXPixmap mglXDestroyGLXPixmap 37 | #define glXQueryExtension mglXQueryExtension 38 | #define glXQueryVersion mglXQueryVersion 39 | #define glXIsDirect mglXIsDirect 40 | #define glXGetConfig mglXGetConfig 41 | #define glXGetCurrentContext mglXGetCurrentContext 42 | #define glXGetCurrentDrawable mglXGetCurrentDrawable 43 | #define glXWaitGL mglXWaitGL 44 | #define glXWaitX mglXWaitX 45 | #define glXUseXFont mglXUseXFont 46 | #define glXQueryExtensionsString mglXQueryExtensionsString 47 | #define glXQueryServerString mglXQueryServerString 48 | #define glXGetClientString mglXGetClientString 49 | #define glXCreateGLXPixmapMESA mglXCreateGLXPixmapMESA 50 | #define glXReleaseBuffersMESA mglXReleaseBuffersMESA 51 | #define glXCopySubBufferMESA mglXCopySubBufferMESA 52 | #define glXGetVideoSyncSGI mglXGetVideoSyncSGI 53 | #define glXWaitVideoSyncSGI mglXWaitVideoSyncSGI 54 | 55 | /* GLX 1.2 */ 56 | #define glXGetCurrentDisplay mglXGetCurrentDisplay 57 | 58 | /* GLX 1.3 */ 59 | #define glXChooseFBConfig mglXChooseFBConfig 60 | #define glXGetFBConfigAttrib mglXGetFBConfigAttrib 61 | #define glXGetFBConfigs mglXGetFBConfigs 62 | #define glXGetVisualFromFBConfig mglXGetVisualFromFBConfig 63 | #define glXCreateWindow mglXCreateWindow 64 | #define glXDestroyWindow mglXDestroyWindow 65 | #define glXCreatePixmap mglXCreatePixmap 66 | #define glXDestroyPixmap mglXDestroyPixmap 67 | #define glXCreatePbuffer mglXCreatePbuffer 68 | #define glXDestroyPbuffer mglXDestroyPbuffer 69 | #define glXQueryDrawable mglXQueryDrawable 70 | #define glXCreateNewContext mglXCreateNewContext 71 | #define glXMakeContextCurrent mglXMakeContextCurrent 72 | #define glXGetCurrentReadDrawable mglXGetCurrentReadDrawable 73 | #define glXQueryContext mglXQueryContext 74 | #define glXSelectEvent mglXSelectEvent 75 | #define glXGetSelectedEvent mglXGetSelectedEvent 76 | 77 | /* GLX 1.4 */ 78 | #define glXGetProcAddress mglXGetProcAddress 79 | #define glXGetProcAddressARB mglXGetProcAddressARB 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /include/GLES/egl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Skeleton egl.h to provide compatibility for early GLES 1.0 3 | * applications. Several early implementations included gl.h 4 | * in egl.h leading applications to include only egl.h 5 | * 6 | * $Revision: 6252 $ on $Date:: 2008-08-06 16:35:08 -0700 #$ 7 | */ 8 | 9 | #ifndef __legacy_egl_h_ 10 | #define __legacy_egl_h_ 11 | 12 | #include 13 | #include 14 | 15 | #endif /* __legacy_egl_h_ */ 16 | -------------------------------------------------------------------------------- /include/GLES/gl2platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl2platform_h_ 2 | #define __gl2platform_h_ 3 | 4 | /* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | #include 21 | 22 | #ifndef GL_APICALL 23 | #define GL_APICALL KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __gl2platform_h_ */ 31 | -------------------------------------------------------------------------------- /include/GLES/gl3ext.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl3ext_h_ 2 | #define __gl3ext_h_ 3 | 4 | /* $Revision: 17809 $ on $Date:: 2012-05-14 08:03:36 -0700 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* OpenGL ES 3 Extensions 12 | * 13 | * After an OES extension's interactions with OpenGl ES 3.0 have been documented, 14 | * its tokens and function definitions should be added to this file in a manner 15 | * that does not conflict with gl2ext.h or gl3.h. 16 | * 17 | * Tokens and function definitions for extensions that have become standard 18 | * features in OpenGL ES 3.0 will not be added to this file. 19 | * 20 | * Applications using OpenGL-ES-2-only extensions should include gl2ext.h 21 | */ 22 | 23 | #endif /* __gl3ext_h_ */ 24 | 25 | -------------------------------------------------------------------------------- /include/GLES/gl3platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl3platform_h_ 2 | #define __gl3platform_h_ 3 | 4 | /* $Revision: 18437 $ on $Date:: 2012-07-08 23:31:39 -0700 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 3.X gl3.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | #include 21 | 22 | #ifndef GL_APICALL 23 | #define GL_APICALL KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __gl3platform_h_ */ 31 | -------------------------------------------------------------------------------- /include/GLES/glplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __glplatform_h_ 2 | #define __glplatform_h_ 3 | 4 | /* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 1.X gl.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | #include 21 | 22 | #ifndef GL_API 23 | #define GL_API KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __glplatform_h_ */ 31 | -------------------------------------------------------------------------------- /spec/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ux 2 | cd "$(dirname "$0")" 3 | 4 | base=../src/ 5 | gles="yml/gles-1.1.yml,yml/oes.yml" 6 | gles2="yml/gles-2.0.yml" 7 | glx="yml/my_glx.yml,yml/glxext.yml" 8 | opengl="yml/opengl.yml" 9 | egl="yml/egl.yml" 10 | cats="VERSION_1_0,VERSION_1_1,VERSION_1_2,VERSION_1_3,VERSION_1_4,VERSION_1_5,glx,EXT_swap_control" 11 | 12 | ./gen.py --deep "$glx,$gles" --skip yml/skip_index.yml mock.c.j2 mock.c mock.h > "$base/../test/util/mock.c" & 13 | ./gen.py --deep "$glx,$gles" --ifndef USE_ES2 mock.h.j2 mock.h "gl_str.h" "wrap/glpack.h" > "$base/../test/util/mock.h" & 14 | 15 | ./gen.py --deep "$gles,$glx,$opengl" --ifndef USE_ES2 --skip yml/skip_index.yml call.c.j2 call.c glpack.h ../loader.h ../skip.h > "$base/gl/wrap/call.c" & 16 | ./gen.py --deep "$gles2,$glx,$opengl" --ifdef USE_ES2 --skip yml/skip_index.yml call.c.j2 call2.c glpack.h ../loader.h > "$base/gl/wrap/call2.c" & 17 | 18 | ./gen.py "$gles" --ifndef USE_ES2 stub.c.j2 stub.c stub.h ../loader.h > "$base/gl/wrap/stub.c" & 19 | ./gen.py "$gles" --ifndef USE_ES2 stub.h.j2 stub.h glpack.h > "$base/gl/wrap/stub.h" & 20 | ./gen.py "$gles" --ifdef USE_ES2 stub.c.j2 stub2.c stub2.h ../loader.h > "$base/gl/wrap/stub2.c" & 21 | ./gen.py "$gles" --ifdef USE_ES2 stub.h.j2 stub2.h glpack.h > "$base/gl/wrap/stub2.h" & 22 | 23 | ./gen.py "$gles" --ifndef USE_ES2 glshim.c.j2 glshim.c glpack.h ../loader.h ../skip.h ../remote.h > "$base/gl/wrap/glshim.c" & 24 | ./gen.py --deep "$glx,$opengl,$gles,$gles2,$egl" base/pack.h.j2 pack.h ../types.h > "$base/gl/wrap/glpack.h" & 25 | ./gen.py "$gles" --ifndef USE_ES2 glxfuncs.j2 glxfuncs.inc > "$base/glx/glesfuncs.inc" & 26 | 27 | ./gen.py "$gles2" --ifdef USE_ES2 glshim.c.j2 glshim2.c glpack.h ../loader.h > "$base/gl/wrap/glshim2.c" & 28 | ./gen.py "$gles2" --ifdef USE_ES2 glxfuncs.j2 gles2funcs.inc > "$base/glx/gles2funcs.inc" & 29 | 30 | rm -rf "$base/../test/build" 31 | wait 32 | -------------------------------------------------------------------------------- /spec/gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import jinja2 5 | import re 6 | import sys 7 | import yaml 8 | 9 | split_re = re.compile(r'^(?P.*?)\s*(?P\w+)$') 10 | env = jinja2.Environment( 11 | trim_blocks=True, 12 | lstrip_blocks=True, 13 | loader=jinja2.FileSystemLoader('template'), 14 | ) 15 | 16 | def args(args, add_type=True, prefix=''): 17 | return ', '.join( 18 | '{} {}{}'.format(arg['type'], prefix, arg['name']) if add_type else prefix + arg['name'] 19 | for arg in args 20 | ) 21 | 22 | printf_lookup = { 23 | 'GLbitfield': 'd', 24 | 'GLboolean': 'd', 25 | 'GLbyte': 'c', 26 | 'GLchar': 'c', 27 | 'GLclampd': '0.2f', 28 | 'GLclampf': '0.2f', 29 | 'GLclampx': 'd', 30 | 'GLdouble': '0.2f', 31 | 'GLenum': '0x%04X', 32 | 'GLfixed': 'd', 33 | 'GLfloat': '0.2f', 34 | 'GLhalfNV': 'd', 35 | 'GLint': 'd', 36 | 'GLint64EXT': '"PRIi64"', 37 | 'GLintptr': 'td', 38 | 'GLintptrARB': 'td', 39 | 'GLhandleARB': 'u', 40 | 'GLshort': 'd', 41 | 'GLsizei': 'd', 42 | 'GLsizeiptr': 'td', 43 | 'GLsizeiptrARB': 'td', 44 | 'GLubyte': 'c', 45 | 'GLuint': 'u', 46 | 'GLuint64': '"PRIu64"', 47 | 'GLuint64EXT': '"PRIu64"', 48 | 'GLushort': 'u', 49 | 'GLvoid': 'p', 50 | 'GLvdpauSurfaceNV': 'td', 51 | 52 | 'bool': 'd', 53 | 'double': 'lf', 54 | 'float': 'f', 55 | 'int': 'd', 56 | 'long long': 'll', 57 | 'long': 'l', 58 | 'unsigned int': 'u', 59 | 'unsigned long long': 'llu', 60 | 'unsigned long': 'lu', 61 | 62 | 'int8_t': '"PRIi8"', 63 | 'int16_t': '"PRIi16"', 64 | 'int32_t': '"PRIi32"', 65 | 'int64_t': '"PRIi64"', 66 | 'uint8_t': '"PRIu8"', 67 | 'uint16_t': '"PRIu16"', 68 | 'uint32_t': '"PRIu32"', 69 | 'uint64_t': '"PRIu64"', 70 | 71 | 'Bool': 'd', 72 | 'Colormap': 'lu', 73 | 'Font': 'lu', 74 | 'GLXDrawable': 'd', 75 | 'Pixmap': 'lu', 76 | 'Window': 'lu', 77 | } 78 | 79 | def printf(args): 80 | if isinstance(args, dict): 81 | args = (args,) 82 | 83 | types = [] 84 | for arg in args: 85 | typ = arg['type'] 86 | if '*' in typ: 87 | t = 'p' 88 | else: 89 | t = printf_lookup.get(typ, 'p') 90 | if not '%' in t: 91 | t = '%' + t 92 | types.append(t) 93 | 94 | return ', '.join(types) 95 | 96 | def unconst(s): 97 | split = s.split(' ') 98 | while 'const' in split: 99 | split.remove('const') 100 | return ' '.join(split) 101 | 102 | env.filters['args'] = args 103 | env.filters['printf'] = printf 104 | env.filters['unconst'] = unconst 105 | 106 | def split_arg(arg): 107 | match = split_re.match(arg) 108 | if match: 109 | return match.groupdict() 110 | else: 111 | return {'type': 'unknown', 'name': arg} 112 | 113 | def gen(files, template, guard_name, headers, 114 | deep=False, cats=(), ifdef=None, ifndef=None, skip=None): 115 | funcs = {} 116 | formats = [] 117 | unique_formats = set() 118 | for data in files: 119 | if deep and not isinstance(data.values()[0], list): 120 | functions = [] 121 | for cat, f in data.items(): 122 | if not cats or cat in cats: 123 | functions.extend(f.items()) 124 | else: 125 | functions = data.items() 126 | 127 | functions = [f for f in functions if not skip or not f[0] in skip] 128 | 129 | for name, args in sorted(functions): 130 | props = {} 131 | if args: 132 | ret = args.pop(0) 133 | else: 134 | ret = 'void' 135 | 136 | args = [split_arg(arg) for arg in args if not arg == 'void'] 137 | if any(arg.get('type') == 'unknown' for arg in args): 138 | continue 139 | 140 | if args: 141 | args[0]['first'] = True 142 | args[-1]['last'] = True 143 | 144 | for i, arg in enumerate(args): 145 | arg['index'] = i 146 | 147 | types = '_'.join( 148 | arg['type'].replace(' ', '_').replace('*', '__GENPT__') 149 | for arg in [{'type': ret}] + args) 150 | 151 | props.update({ 152 | 'return': ret, 153 | 'name': name, 154 | 'args': args, 155 | 'types': types, 156 | 'void': ret == 'void', 157 | }) 158 | if not types in unique_formats: 159 | unique_formats.add(types) 160 | formats.append(props) 161 | 162 | funcs[name] = props 163 | 164 | context = { 165 | 'functions': [i[1] for i in sorted(funcs.items())], 166 | 'formats': formats, 167 | 'headers': headers, 168 | 'name': guard_name, 169 | 'ifdef': ifdef, 170 | 'ifndef': ifndef, 171 | } 172 | 173 | t = env.get_template(template) 174 | return t.render(**context).rstrip('\n') 175 | 176 | if __name__ == '__main__': 177 | parser = argparse.ArgumentParser(description='Generate code with yml/jinja.') 178 | parser.add_argument('yaml', help='spec files') 179 | parser.add_argument('template', help='jinja template to load') 180 | parser.add_argument('name', help='header guard name') 181 | parser.add_argument('headers', nargs='*', help='headers to include') 182 | parser.add_argument('--deep', help='nested definitions', action='store_true') 183 | parser.add_argument('--cats', help='deep category filter') 184 | parser.add_argument('--ifdef', help='wrap with ifdef') 185 | parser.add_argument('--ifndef', help='wrap with ifndef') 186 | parser.add_argument('--skip', help='skip function from yml') 187 | 188 | args = parser.parse_args() 189 | 190 | files = [] 191 | for name in args.yaml.split(','): 192 | with open(name) as f: 193 | data = yaml.load(f) 194 | if data: 195 | files.append(data) 196 | 197 | skip = None 198 | if args.skip: 199 | with open(args.skip) as f: 200 | skip = yaml.load(f) 201 | 202 | if args.cats: 203 | cats = args.cats.split(',') 204 | else: 205 | cats = None 206 | print gen(files, args.template, args.name, 207 | args.headers, args.deep, cats, 208 | args.ifdef, args.ifndef, skip=skip) 209 | -------------------------------------------------------------------------------- /spec/requirements.txt: -------------------------------------------------------------------------------- 1 | jinja2 2 | pyyaml 3 | -------------------------------------------------------------------------------- /spec/template/base/base.j2: -------------------------------------------------------------------------------- 1 | {% if ifdef %}#ifdef {{ ifdef }} 2 | {% endif %} 3 | {% if ifndef %}#ifndef {{ ifndef }} 4 | {% endif %} 5 | {% block headers %} 6 | {% include "base/headers.j2" %} 7 | {% endblock %} 8 | {% block main %}{% endblock %} 9 | {% if ifdef %}#endif{% endif %} 10 | {% if ifndef %}#endif{% endif %} 11 | -------------------------------------------------------------------------------- /spec/template/base/header.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/base.j2" %} 2 | {% block main %} 3 | {% set guard = name.upper().replace('.', '_') -%} 4 | #ifndef {{ guard }} 5 | #define {{ guard }} 6 | {% block content %}{% endblock %} 7 | #endif 8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /spec/template/base/headers.j2: -------------------------------------------------------------------------------- 1 | {% for header in headers %} 2 | {% if "<" in header %} 3 | #include {{ header }} 4 | {% else %} 5 | #include "{{ header }}" 6 | {% endif %} 7 | {% endfor %} 8 | -------------------------------------------------------------------------------- /spec/template/base/indexed_call.j2: -------------------------------------------------------------------------------- 1 | {% from "base/util.j2" import args %} 2 | 3 | void glIndexedCall(const packed_call_t *packed, void *ret_v) { 4 | switch (packed->index) { 5 | {% for f in functions %} 6 | #ifndef skip_index_{{ f.name }} 7 | case {{ f.name }}_INDEX: 8 | call_{{ f.name }}(packed, ret_v); 9 | break; 10 | #endif 11 | {% endfor %} 12 | default: 13 | fprintf(stderr, "warning: glIndexedCall with unknown index %d\n", packed->index); 14 | break; 15 | } 16 | } 17 | 18 | void glIndexedPrint(const packed_call_t *packed) { 19 | switch (packed->index) { 20 | {% for f in functions %} 21 | case {{ f.name }}_INDEX: { 22 | {% if f.args %} 23 | {{ f.name }}_PACKED *unpacked = ({{ f.name }}_PACKED *)packed; 24 | {{ f.name }}_ARGS *args = ({{ f.name }}_ARGS *)&unpacked->args; 25 | printf("{{ f.name }}({{ f.args|printf }});\n", {{ args(f) }}); 26 | {% else %} 27 | printf("{{ f.name }}();\n"); 28 | {% endif %} 29 | break; 30 | } 31 | {% endfor %} 32 | default: 33 | fprintf(stderr, "warning: glIndexedPrint with unknown index %d\n", packed->index); 34 | break; 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /spec/template/base/pack.h.j2: -------------------------------------------------------------------------------- 1 | {% from "base/util.j2" import args, call %} 2 | {% extends "base/header.j2" %} 3 | {% block content %} 4 | 5 | {% for f in functions %} 6 | {% if f.args %} 7 | typedef struct { 8 | {% for arg in f.args %} 9 | {{ arg.type|unconst }} {{ arg.name }}{% if arg.type == 'GLdouble' %} __attribute__ ((aligned(8))){% endif %}; 10 | {% endfor %} 11 | } {{ f.name }}_ARGS; 12 | {% endif %} 13 | typedef struct { 14 | int index; 15 | {% if f.args %} 16 | {{ f.name }}_ARGS args; 17 | {% endif %} 18 | } {{ f.name }}_PACKED; 19 | {% endfor %} 20 | 21 | extern const int INDEX_RET_SIZE[]; 22 | extern const int INDEX_PACKED_SIZE[]; 23 | extern const char *INDEX_NAME[]; 24 | extern void glPushCall(void *data); 25 | void glIndexedCall(const packed_call_t *packed, void *ret_v); 26 | void glIndexedPrint(const packed_call_t *packed); 27 | 28 | {% for func in functions %} 29 | #define {{ func.name }}_INDEX {{ loop.index }} 30 | #define {{ func.name }}_RETURN {{ func.return }} 31 | #define {{ func.name }}_ARG_NAMES {{ func.args|args(0) }} 32 | #define {{ func.name }}_ARG_EXPAND {{ func.args|args }} 33 | #define {{ func.name }}_ARG_NAMES_TAIL {% if func.args %}, {{ func.args|args(0) }}{% endif %} 34 | 35 | #define {{ func.name }}_ARG_EXPAND_TAIL {% if func.args %}, {{ func.args|args }}{% endif %} 36 | 37 | #define forward_{{ func.name }}({{ func.args|args(0, '_') }}) \ 38 | ({ \ 39 | void *dst = remote_dma(sizeof({{ func.name }}_PACKED)); \ 40 | {% if func.void %} 41 | remote_dma_send((packed_call_t *)pack_{{ func.name }}(dst{% if func.args %}, {% endif %}{{ func.args|args(0, '_') }}), NULL); \ 42 | {% else %} 43 | {{ func.return }} ret = ({{ func.return }})0; \ 44 | remote_dma_send((packed_call_t *)pack_{{ func.name }}(dst{% if func.args %}, {% endif %}{{ func.args|args(0, '_') }}), &ret); \ 45 | ret; \ 46 | {% endif %} 47 | }); 48 | #define call_{{ func.name }}(packed, ret_v) do { \ 49 | {% if func.args %} 50 | {{ func.name }}_PACKED *unpacked = ({{ func.name }}_PACKED *)packed; \ 51 | {{ func.name }}_ARGS *args = ({{ func.name }}_ARGS *)&unpacked->args; \ 52 | {% endif %} 53 | {% if not func.void %} 54 | {{ func.return }} *ret = ({{ func.return }} *)ret_v; \ 55 | if (ret != NULL) { \ 56 | *ret = {{ call(func) }}; \ 57 | } else { \ 58 | {{ call(func) }}; \ 59 | } \ 60 | {% else %} 61 | {{ call(func) }}; \ 62 | {% endif %} 63 | } while(0) 64 | {{ func.return }} {{ func.name }}({{ func.name }}_ARG_EXPAND); 65 | packed_call_t *pack_{{ func.name }}({{ func.name }}_PACKED *_dst {{ func.name }}_ARG_EXPAND_TAIL); 66 | typedef {{ func.return }} (*{{ func.name }}_PTR)({{ func.name }}_ARG_EXPAND); 67 | {% endfor %} 68 | 69 | {% endblock %} 70 | -------------------------------------------------------------------------------- /spec/template/base/util.j2: -------------------------------------------------------------------------------- 1 | {% macro fprint(f, prefix='', pfunc='printf') %} 2 | {% if f.args %} 3 | {{ pfunc }}("{{ prefix + f.name }}({{ f.args|printf }});\n", {{ f.args|args(0) }}); 4 | {% else %} 5 | {{ pfunc }}("{{ prefix + f.name }}();\n"); 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro args(f) -%} 10 | {% for arg in f.args -%} 11 | args->{{ arg.name }}{% if not arg.last %}, {% endif %} 12 | {% endfor %} 13 | {%- endmacro %} 14 | 15 | {% macro call(f) -%} 16 | {{ f.name }}({{ args(f) }}); 17 | {%- endmacro %} 18 | -------------------------------------------------------------------------------- /spec/template/base/wrap.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/base.j2" %} 2 | {% block main %} 3 | {% block headers %} 4 | {% include "base/headers.j2" %} 5 | {% endblock %} 6 | {% for func in functions %} 7 | {% block definition scoped %} 8 | {{ func.return }} {% block func_prefix scoped %}{% endblock %}{{ func.name }}({{ func.args|args }}) { 9 | {% block load scoped %}{% endblock %} 10 | {% block call scoped %} 11 | {% if not func.void %}return {% endif %}{% block prefix %}wrap{% endblock %}_{{ func.name }}({{ func.args|args(0) }}); 12 | {%- endblock %} 13 | } 14 | {% endblock %} 15 | {% endfor %} 16 | {% endblock %} 17 | -------------------------------------------------------------------------------- /spec/template/call.c.j2: -------------------------------------------------------------------------------- 1 | {% from "base/util.j2" import fprint %} 2 | {% extends "base/base.j2" %} 3 | {% block main %} 4 | {% include "base/indexed_call.j2" %} 5 | 6 | const int INDEX_RET_SIZE[] = { 7 | 0, 8 | {% for func in functions %} 9 | [{{ func.name }}_INDEX] = {% if func.void %} 0{% else %} sizeof({{ func.return }}){% endif %}, 10 | {% endfor %} 11 | }; 12 | 13 | const int INDEX_PACKED_SIZE[] = { 14 | 0, 15 | {% for func in functions %} 16 | [{{ func.name }}_INDEX] = sizeof({{ func.name }}_PACKED), 17 | {% endfor %} 18 | }; 19 | 20 | const char *INDEX_NAME[] = { 21 | 0, 22 | {% for func in functions %} 23 | [{{ func.name }}_INDEX] = "{{ func.name }}", 24 | {% endfor %} 25 | }; 26 | 27 | {% for func in functions %} 28 | packed_call_t *pack_{{ func.name }}({{ func.name }}_PACKED *_dst{% if func.args %}, {{ func.args|args }}{% endif %}) { 29 | if (_dst == NULL) _dst = malloc(sizeof({{ func.name }}_PACKED)); 30 | _dst->index = {{ func.name }}_INDEX; 31 | {% for arg in func.args %} 32 | _dst->args.{{ arg.name }} = ({{ arg.type|unconst }}){{ arg.name }}; 33 | {% endfor %} 34 | return (packed_call_t *)_dst; 35 | } 36 | {% endfor %} 37 | 38 | {% endblock %} 39 | -------------------------------------------------------------------------------- /spec/template/glshim.c.j2: -------------------------------------------------------------------------------- 1 | {% from "base/util.j2" import fprint %} 2 | {% extends "base/base.j2" %} 3 | {% block main %} 4 | 5 | {% for func in functions %} 6 | #ifndef skip_{{ func.name }} 7 | {{ func.return }} {{ func.name }}({{ func.args|args }}) { 8 | {% block call scoped %} 9 | #ifndef direct_{{ func.name }} 10 | PUSH_IF_COMPILING({{ func.name }}); 11 | #endif 12 | FORWARD_IF_REMOTE({{ func.name }}); 13 | LOAD_GLES({{ func.name }}); 14 | {%+ if not func.void %}return {% endif %}gles_{{ func.name }}({{ func.args|args(0) }}); 15 | {% endblock %} 16 | } 17 | #endif 18 | {% endfor %} 19 | {% endblock %} 20 | -------------------------------------------------------------------------------- /spec/template/glxfuncs.j2: -------------------------------------------------------------------------------- 1 | {% for func in functions %} 2 | EX({{ func.name }}); 3 | {% endfor %} 4 | -------------------------------------------------------------------------------- /spec/template/mock.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/base.j2" %} 2 | {% block main %} 3 | #include 4 | #include "tack.h" 5 | 6 | int mock_fcmp(float *a, float *b, size_t len) { 7 | len /= sizeof(float); 8 | for (size_t i = 0; i < len; i++) { 9 | if (b[i] - a[i] > 0.00001) return 1; 10 | if (a[i] - b[i] > 0.00001) return -1; 11 | } 12 | return 0; 13 | } 14 | 15 | void mock_fdiff(float *a, float *b, size_t len) { 16 | for (int i = 0; i < len; i++) { 17 | if (mock_fcmp(&a[i], &b[i], sizeof(float)) == 0) { 18 | printf("%f ", a[i]); 19 | } else { 20 | printf(VT100_RED "%f " VT100_CLEAR, a[i]); 21 | } 22 | } 23 | } 24 | 25 | void mock_ptrdiff(char *prefix, void *ptr, void *other, size_t size) { 26 | printf("%s ", prefix); 27 | if (ptr == NULL) { 28 | printf("NULL"); 29 | } else { 30 | char *ac = ptr, *bc = other; 31 | for (size_t i = 0; i < size; i++) { 32 | if (i > 0 && i % 4 == 0) printf(" "); 33 | if (i > 0 && i % 32 == 0) { 34 | printf("| "); 35 | mock_fdiff((float *)&ac[i - 32], (float *)&bc[i - 32], 8); 36 | printf("\n"); 37 | printf(" "); 38 | } 39 | if (ac[i] != bc[i]) { 40 | printf("%02X", (unsigned char)ac[i]); 41 | } else { 42 | printf(VT100_RED "%02X" VT100_CLEAR, (unsigned char)ac[i]); 43 | } 44 | } 45 | int start = size - 32; 46 | if (size % 32 != 0) { 47 | size - (size % 32); 48 | } 49 | printf(" | "); 50 | mock_fdiff((float *)&ac[start], (float *)&bc[start], (size - start) / sizeof(float)); 51 | } 52 | printf("\n"); 53 | } 54 | 55 | static tack_t mock = {0}; 56 | 57 | const char *mock_name(int func) { 58 | switch (func) { 59 | {% for f in functions %} 60 | case {{ f.name }}_INDEX: return "{{ f.name }}"; 61 | {% endfor %} 62 | } 63 | } 64 | 65 | void mock_print(const packed_call_t *packed) { 66 | if (packed == NULL) { 67 | printf("NULL()\n"); 68 | return; 69 | } 70 | switch (packed->index) { 71 | {% for f in functions %} 72 | case {{ f.name }}_INDEX: { 73 | {{ f.name }}_PACKED *unpacked = ({{ f.name }}_PACKED *)packed; 74 | printf("{{ f.name }}({{ f.args|printf }});\n" 75 | {%- for arg in f.args %}, unpacked->args.{{ arg.name }}{% endfor -%}); 76 | break; 77 | } 78 | {% endfor %} 79 | } 80 | } 81 | 82 | packed_call_t *_mock_expect(char *name, int index) { 83 | packed_call_t *packed = mock_cur(); 84 | if (packed == NULL) { 85 | mock_errorf("%s missing (no calls left)\n", name); 86 | } else if (packed->index != index) { 87 | if (verbose_test) { 88 | mock_print(mock_cur()); 89 | } 90 | packed_call_t *tmp = packed; 91 | packed = mock_slide(index); 92 | if (! packed) { 93 | mock_errorf("%s missing\n", name); 94 | } else { 95 | mock_warningf("unexpected call while looking for %s:\n ", name); 96 | mock_print(tmp); 97 | } 98 | } else { 99 | if (verbose_test) { 100 | mock_print(mock_cur()); 101 | } 102 | mock_shift(); 103 | } 104 | return packed; 105 | } 106 | 107 | void *mock_get(int idx) { 108 | return tack_get(&mock, idx); 109 | } 110 | 111 | void *mock_peek() { 112 | return tack_peek(&mock); 113 | } 114 | 115 | void *mock_cur() { 116 | return tack_cur(&mock); 117 | } 118 | 119 | void *mock_shift() { 120 | return tack_shift(&mock); 121 | } 122 | 123 | void *mock_slide(int func) { 124 | if (mock.pos >= mock.len) { 125 | return NULL; 126 | } 127 | packed_call_t **stack = (packed_call_t **)mock.data; 128 | for (int i = mock.pos; i < mock.len; i++) { 129 | if (stack[i]->index == func) { 130 | mock.pos = i + 1; 131 | return stack[i]; 132 | } 133 | } 134 | return NULL; 135 | } 136 | 137 | void mock_push(void *call) { 138 | tack_push(&mock, call); 139 | } 140 | 141 | void *mock_pop() { 142 | return tack_pop(&mock); 143 | } 144 | 145 | {% for func in functions %} 146 | {{ func.return }} {% if not func.name.startswith('glX') %}gles_{% endif %}{{ func.name }}({{ func.args|args }}) { 147 | emit_{{ func.name }}({{ func.args|args(0) }}); 148 | {% if not func.void %} 149 | return ({{ func.return }})0; 150 | {% endif %} 151 | } 152 | {% endfor %} 153 | 154 | {% endblock %} 155 | -------------------------------------------------------------------------------- /spec/template/mock.h.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/header.j2" %} 2 | {% block headers %}{% endblock %} 3 | {% block main %} 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | {% include "base/headers.j2" %} 8 | {{ super() }} 9 | #ifdef __cplusplus 10 | } // extern "C" 11 | #endif 12 | {% endblock %} 13 | 14 | {% block content %} 15 | {{ super() }} 16 | const char *mock_name(int func); 17 | void *mock_cur(); 18 | void *mock_get(int idx); 19 | void *mock_peek(); 20 | void *mock_shift(); 21 | void *mock_slide(int func); 22 | void mock_print(const packed_call_t *packed); 23 | void mock_push(void *call); 24 | 25 | packed_call_t *_mock_expect(char *name, int index); 26 | #define mock_expect(name) _mock_expect(#name, name##_INDEX); 27 | 28 | static int verbose_test = 0; 29 | static int failed_test = 0; 30 | #define verbose { verbose_test = 1; } 31 | 32 | #define mock_warningf(...) { printf("WARNING: "), printf(__VA_ARGS__); } 33 | #define mock_errorf(...) { printf("ERROR: "); printf(__VA_ARGS__); failed_test = 1; } 34 | #define mock_assert(cond, ...) { if (!(cond)) { mock_errorf(__VA_ARGS__); }} 35 | #define assert(cond) mock_assert(cond, "%s\n", #cond) 36 | 37 | #define VT100_RED "\e[1;31m" 38 | #define VT100_CLEAR "\e[0m" 39 | 40 | int mock_fcmp(float *a, float *b, size_t len); 41 | void mock_fdiff(float *a, float *b, size_t len); 42 | void mock_ptrdiff(char *prefix, void *ptr, void *other, size_t size); 43 | 44 | #define mock_return { \ 45 | packed_call_t *call = NULL; \ 46 | while ((call = mock_shift()) != NULL) { \ 47 | mock_warningf("extra "); \ 48 | mock_print(call); \ 49 | } \ 50 | if (state.error) { \ 51 | mock_warningf("Ended with GL error flag: %s\n", gl_str(state.error)); \ 52 | } \ 53 | return failed_test; \ 54 | } 55 | 56 | {% for func in functions %} 57 | #define emit_{{ func.name }}({{ func.args|args(0) }}) { \ 58 | mock_push(pack_{{ func.name }}(NULL{% if func.args %}, {{ func.args|args(0) }}{% endif %})); \ 59 | } 60 | #define test_{{ func.name }}({{ func.args|args(0, '_') }}) { \ 61 | {{ func.name }}_PACKED *packed = mock_expect({{ func.name }}); \ 62 | if (packed) { \ 63 | int match = 1; \ 64 | void *a, *b; \ 65 | {% if func.args %} 66 | {% for arg in func.args %} 67 | {% if '*' in arg.type %} 68 | a = packed->args.{{ arg.name }}, b = _{{ arg.name }}; \ 69 | {% set cmp = 'memcmp' %} 70 | {% if 'float' in arg.type %}{% set cmp = 'mock_fcmp' %}{% endif %} 71 | if (b == NULL && a != NULL || (a != NULL && b != NULL && ({{ cmp }}(a, b, sizeof(_{{ arg.name }})) != 0))) { \ 72 | printf(" ERROR: arg mismatch: {{ arg.name }}\n"); \ 73 | mock_ptrdiff(" expected:", (void *)b, (void *)a, sizeof(_{{ arg.name }})); \ 74 | mock_ptrdiff(" found:", (void *)a, (void *)b, sizeof(_{{ arg.name }})); \ 75 | {% elif 'float' in arg.type or 'double' in arg.type %} 76 | if (packed->args.{{ arg.name }} - _{{ arg.name }} >= 0.01) { \ 77 | {% else %} 78 | if (packed->args.{{ arg.name }} != _{{ arg.name }}) { \ 79 | {% endif %} 80 | match = 0; \ 81 | } \ 82 | {% endfor %} 83 | if (! match) { \ 84 | mock_errorf("calls do not match:\n"); \ 85 | printf(" have: "); mock_print((const packed_call_t *)packed); \ 86 | printf(" want: {{ func.name }}({{ func.args|printf }});\n", {{ func.args|args(0, '_') }}); \ 87 | } \ 88 | {% endif %} 89 | } \ 90 | } 91 | {% endfor %} 92 | 93 | {% for func in functions %} 94 | {% if not func.name.startswith('glX') %} 95 | {{ func.return }} gles_{{ func.name }}({{ func.name }}_ARG_EXPAND); 96 | {% endif %} 97 | {% endfor %} 98 | {% endblock %} 99 | -------------------------------------------------------------------------------- /spec/template/stub.c.j2: -------------------------------------------------------------------------------- 1 | {% from "base/util.j2" import fprint %} 2 | {% extends "base/base.j2" %} 3 | {% block main %} 4 | 5 | {% for func in functions %} 6 | {{ func.return }} stub_{{ func.name }}({{ func.args|args }}) { 7 | {{ fprint(func, prefix='stub ', pfunc='debugf') }} 8 | {%- if not func.void %} return 0; 9 | {% endif %} 10 | } 11 | {% endfor %} 12 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /spec/template/stub.h.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/header.j2" %} 2 | {% block content %} 3 | 4 | {% for func in functions %} 5 | {{ func.return }} stub_{{ func.name }}({{ func.name }}_ARG_EXPAND); 6 | {% endfor %} 7 | 8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /spec/xml/toyml.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from collections import defaultdict 3 | import re 4 | import xml.etree.ElementTree as ET 5 | import yaml 6 | 7 | 8 | def etna_to_yml(xml): 9 | defs = xml.find('functions') 10 | functions = defaultdict(dict) 11 | for f in defs.findall('function'): 12 | name = f.get('name') 13 | ret = f.find('return') 14 | if ret is not None: 15 | ret = ret.get('type') 16 | if ret is None: 17 | ret = 'void' 18 | 19 | params = [] 20 | for p in f.findall('param'): 21 | params.append('{} {}'.format(p.get('type'), p.get('name'))) 22 | 23 | functions[name] = [ret] + params 24 | 25 | return functions 26 | 27 | 28 | def lua_to_yml(xml): 29 | typemap = xml.find('typemap') 30 | types = {} 31 | for t in typemap: 32 | name = t.get('typename') 33 | types[name] = t.get('C-lang', name) 34 | 35 | defs = xml.find('functions').find('function-defs') 36 | functions = defaultdict(dict) 37 | for f in defs.findall('function'): 38 | cat = f.get('category') 39 | ret = f.get('return') 40 | ret = types.get(ret, ret) 41 | func = f.get('name') 42 | 43 | params = [] 44 | for param in f.findall('param'): 45 | typ = param.get('type') 46 | typ = types.get(typ, typ) 47 | name = param.get('name') 48 | kind = param.get('kind') 49 | if kind in ('array', 'reference', 'array[size]'): 50 | typ = typ.rstrip() 51 | if not typ.endswith('*') or kind == 'reference': 52 | typ += ' *' 53 | if not 'const' in typ and param.get('input', 'false') == 'true': 54 | typ = 'const ' + typ 55 | p = '{} {}'.format(typ, name) 56 | p = p.replace('* ', '*') 57 | params.append(p) 58 | 59 | args = [ret] 60 | args.extend(params) 61 | functions[cat][func] = args 62 | return functions 63 | 64 | 65 | def khronos_to_yml(xml): 66 | def extract(node): 67 | return node.findtext('ptype') or node.text, node.findtext('name') 68 | 69 | def clean(s): 70 | return re.sub('\s+', ' ', s).strip() 71 | 72 | defs = xml.find('commands') 73 | functions = defaultdict(dict) 74 | for f in defs.findall('command'): 75 | proto = f.find('proto') 76 | ret, name = extract(proto) 77 | params = [] 78 | for param in f.findall('param'): 79 | params.append(clean(' '.join((param.itertext())))) 80 | 81 | functions[name] = [ret] + params 82 | return functions 83 | 84 | 85 | def to_yml(filename): 86 | with open(filename, 'r') as f: 87 | data = f.read() 88 | 89 | data = re.sub(' xmlns="[^"]+"', '', data, count=1) 90 | xml = ET.fromstring(data) 91 | 92 | if xml.tag == 'root': 93 | functions = etna_to_yml(xml) 94 | elif xml.tag == 'specification': 95 | functions = lua_to_yml(xml) 96 | elif xml.tag == 'registry': 97 | functions = khronos_to_yml(xml) 98 | else: 99 | print 'unrecognized root tag:', xml.tag 100 | 101 | yml = yaml.dump(dict(functions)) 102 | with open(filename.replace('xml', 'yml'), 'w') as o: 103 | o.write(yml) 104 | 105 | if __name__ == '__main__': 106 | import sys 107 | if len(sys.argv) < 2: 108 | print 'Usage: {} [file.xml...]'.format(sys.argv[0]) 109 | sys.exit(1) 110 | 111 | for name in sys.argv[1:]: 112 | to_yml(name) 113 | -------------------------------------------------------------------------------- /spec/yml/glext-1.1.yml: -------------------------------------------------------------------------------- 1 | # glTexGenfOES: [void, GLenum coord, GLenum pname, GLfloat param] 2 | # glTexGenfvOES: [void, GLenum coord, GLenum pname, "const GLfloat *params"] 3 | # glTexGeniOES: [void, GLenum coord, GLenum pname, GLint param] 4 | # glTexGenivOES: [void, GLenum coord, GLenum pname, "const GLint *params"] 5 | -------------------------------------------------------------------------------- /spec/yml/glx.yml: -------------------------------------------------------------------------------- 1 | glx: 2 | glXBindHyperpipeSGIX: [int, Display *dpy, int hpId] 3 | glXBindSwapBarrierSGIX: [void, uint32_t window, uint32_t barrier] 4 | glXChangeDrawableAttributes: [void, uint32_t drawable] 5 | glXChangeDrawableAttributesSGIX: [void, uint32_t drawable] 6 | glXClientInfo: [void] 7 | glXCopyContext: [void, uint32_t source, uint32_t dest, uint32_t mask] 8 | glXCreateContext: [void, uint32_t gc_id, uint32_t screen, uint32_t visual, uint32_t 9 | share_list] 10 | glXCreateContextWithConfigSGIX: [void, uint32_t gc_id, uint32_t screen, uint32_t 11 | config, uint32_t share_list] 12 | glXCreateGLXPbufferSGIX: [void, uint32_t config, uint32_t pbuffer] 13 | glXCreateGLXPixmap: [void, uint32_t visual, uint32_t pixmap, uint32_t glxpixmap] 14 | glXCreateGLXPixmapWithConfigSGIX: [void, uint32_t config, uint32_t pixmap, uint32_t 15 | glxpixmap] 16 | glXCreateGLXVideoSourceSGIX: [void, uint32_t dpy, uint32_t screen, uint32_t server, 17 | uint32_t path, uint32_t cls, uint32_t node] 18 | glXCreateNewContext: [void, uint32_t config, uint32_t render_type, uint32_t share_list, 19 | uint32_t direct] 20 | glXCreatePbuffer: [void, uint32_t config, uint32_t pbuffer] 21 | glXCreatePixmap: [void, uint32_t config, uint32_t pixmap, uint32_t glxpixmap] 22 | glXCreateWindow: [void, uint32_t config, uint32_t window, uint32_t glxwindow] 23 | glXDestroyContext: [void, uint32_t context] 24 | glXDestroyGLXPbufferSGIX: [void, uint32_t pbuffer] 25 | glXDestroyGLXPixmap: [void, uint32_t pixmap] 26 | glXDestroyGLXVideoSourceSGIX: [void, uint32_t dpy, uint32_t glxvideosource] 27 | glXDestroyHyperpipeConfigSGIX: [int, Display *dpy, int hpId] 28 | glXDestroyPbuffer: [void, uint32_t pbuffer] 29 | glXDestroyPixmap: [void, uint32_t glxpixmap] 30 | glXDestroyWindow: [void, uint32_t glxwindow] 31 | glXGetDrawableAttributes: [void, uint32_t drawable] 32 | glXGetDrawableAttributesSGIX: [void, uint32_t drawable] 33 | glXGetFBConfigs: [void] 34 | glXGetFBConfigsSGIX: [void] 35 | glXGetVisualConfigs: [void] 36 | glXHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int size, 37 | const void *attribList] 38 | glXHyperpipeConfigSGIX: [int, Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX 39 | cfg, int *hpId] 40 | glXIsDirect: [void, uint32_t dpy, uint32_t context] 41 | glXJoinSwapGroupSGIX: [void, uint32_t window, uint32_t group] 42 | glXMakeContextCurrent: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 43 | context] 44 | glXMakeCurrent: [void, uint32_t drawable, uint32_t context] 45 | glXMakeCurrentReadSGI: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 46 | context] 47 | glXQueryContext: [void] 48 | glXQueryContextInfoEXT: [void] 49 | glXQueryExtensionsString: [void, uint32_t screen] 50 | glXQueryHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int 51 | size, const void *returnAttribList] 52 | glXQueryHyperpipeBestAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, 53 | int size, const void *attribList, void *returnAttribList] 54 | glXQueryHyperpipeConfigSGIX: [GLXHyperpipeConfigSGIX *, Display *dpy, int hpId, 55 | int *npipes] 56 | glXQueryHyperpipeNetworkSGIX: [GLXHyperpipeNetworkSGIX *, Display *dpy, int *npipes] 57 | glXQueryMaxSwapBarriersSGIX: [void] 58 | glXQueryServerString: [void, uint32_t screen, uint32_t name] 59 | glXQueryVersion: [void, uint32_t *major, uint32_t *minor] 60 | glXRender: [void] 61 | glXRenderLarge: [void] 62 | glXSwapBuffers: [void, uint32_t drawable] 63 | glXSwapIntervalSGI: [void] 64 | glXUseXFont: [void, uint32_t font, uint32_t first, uint32_t count, uint32_t list_base] 65 | glXVendorPrivate: [void] 66 | glXVendorPrivateWithReply: [void] 67 | glXWaitGL: [void, uint32_t context] 68 | glXWaitX: [void] 69 | -------------------------------------------------------------------------------- /spec/yml/my_glx.yml: -------------------------------------------------------------------------------- 1 | glx: 2 | glXChooseVisual: [XVisualInfo *, Display *dpy, int screen, int *attribList] 3 | glXBindHyperpipeSGIX: [int, Display *dpy, int hpId] 4 | glXBindSwapBarrierSGIX: [void, uint32_t window, uint32_t barrier] 5 | glXChangeDrawableAttributes: [void, uint32_t drawable] 6 | glXChangeDrawableAttributesSGIX: [void, uint32_t drawable] 7 | glXClientInfo: [void] 8 | glXCopyContext: [void, Display *dpy, GLXContext src, GLXContext dst, unsigned long mask] 9 | glXCreateContext: [GLXContext, Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct] 10 | glXCreateContextAttribsARB: [GLXContext, Display *display, void *config, GLXContext share_context, Bool direct, const int *attrib_list] 11 | glXCreateContextWithConfigSGIX: [void, uint32_t gc_id, uint32_t screen, uint32_t 12 | config, uint32_t share_list] 13 | glXCreateGLXPbufferSGIX: [void, uint32_t config, uint32_t pbuffer] 14 | glXCreateGLXPixmap: [GLXPixmap, Display *dpy, XVisualInfo *visual, Pixmap pixmap] 15 | glXCreateGLXPixmapWithConfigSGIX: [void, uint32_t config, uint32_t pixmap, uint32_t 16 | glxpixmap] 17 | glXCreateGLXVideoSourceSGIX: [void, Display *dpy, uint32_t screen, uint32_t server, 18 | uint32_t path, uint32_t cls, uint32_t node] 19 | glXCreateNewContext: [void, uint32_t config, uint32_t render_type, uint32_t share_list, 20 | uint32_t direct] 21 | glXCreatePbuffer: [void, uint32_t config, uint32_t pbuffer] 22 | glXCreatePixmap: [void, uint32_t config, uint32_t pixmap, uint32_t glxpixmap] 23 | glXCreateWindow: [void, uint32_t config, uint32_t window, uint32_t glxwindow] 24 | glXDestroyContext: [void, Display *dpy, GLXContext ctx] 25 | glXDestroyGLXPbufferSGIX: [void, uint32_t pbuffer] 26 | glXDestroyGLXPixmap: [void, Display *dpy, GLXPixmap pixmap] 27 | glXDestroyGLXVideoSourceSGIX: [void, Display *dpy, uint32_t glxvideosource] 28 | glXDestroyHyperpipeConfigSGIX: [int, Display *dpy, int hpId] 29 | glXDestroyPbuffer: [void, uint32_t pbuffer] 30 | glXDestroyPixmap: [void, uint32_t glxpixmap] 31 | glXDestroyWindow: [void, uint32_t glxwindow] 32 | glXGetDrawableAttributes: [void, uint32_t drawable] 33 | glXGetDrawableAttributesSGIX: [void, uint32_t drawable] 34 | glXGetClientString: [const char *, Display *display, int name] 35 | glXGetCurrentContext: [GLXContext] 36 | glXGetCurrentDrawable: [GLXDrawable] 37 | glXGetConfig: [int, Display *display, XVisualInfo *visual, int attribute, int *value] 38 | glXGetFBConfigs: [void] 39 | glXGetFBConfigsSGIX: [void] 40 | glXGetVisualConfigs: [void] 41 | glXHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int size, 42 | const void *attribList] 43 | glXHyperpipeConfigSGIX: [int, Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX 44 | cfg, int *hpId] 45 | glXIsDirect: [Bool, Display *dpy, GLXContext ctx] 46 | glXJoinSwapGroupSGIX: [void, uint32_t window, uint32_t group] 47 | glXMakeContextCurrent: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 48 | context] 49 | glXMakeCurrent: [Bool, Display *dpy, GLXDrawable drawable, GLXContext ctx] 50 | glXMakeCurrentReadSGI: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 51 | context] 52 | glXQueryContext: [void] 53 | glXQueryContextInfoEXT: [void] 54 | glXQueryExtension: [Bool, Display *display, int *errorBase, int *eventBase] 55 | glXQueryExtensionsString: [const char *, Display *dpy, int screen] 56 | glXQueryHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int 57 | size, const void *returnAttribList] 58 | glXQueryHyperpipeBestAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, 59 | int size, const void *attribList, void *returnAttribList] 60 | glXQueryHyperpipeConfigSGIX: [GLXHyperpipeConfigSGIX *, Display *dpy, int hpId, 61 | int *npipes] 62 | glXQueryHyperpipeNetworkSGIX: [GLXHyperpipeNetworkSGIX *, Display *dpy, int *npipes] 63 | glXQueryMaxSwapBarriersSGIX: [void] 64 | glXQueryServerString: [const char *, Display *dpy, int screen, int name] 65 | glXQueryVersion: [Bool, Display *dpy, int *maj, int *min] 66 | glXReleaseBuffersMESA: [Bool, Display *dpy, GLXDrawable drawable] 67 | glXRender: [void] 68 | glXRenderLarge: [void] 69 | glXSwapBuffers: [void, Display *dpy, GLXDrawable drawable] 70 | glXSwapIntervalSGI: [void, unsigned int interval] 71 | glXSwapIntervalMESA: [int, unsigned int interval] 72 | glXUseXFont: [void, Font font, int first, int count, int listBase] 73 | glXVendorPrivate: [void] 74 | glXVendorPrivateWithReply: [void] 75 | glXWaitGL: [void] 76 | glXWaitX: [void] 77 | -------------------------------------------------------------------------------- /spec/yml/oes.yml: -------------------------------------------------------------------------------- 1 | glBlendColorOES: [void, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha] 2 | glBlendEquationOES: [void, GLenum mode] 3 | glBlendEquationSeparateOES: [void, GLenum modeRGB, GLenum modeAlpha] 4 | glBlendFuncSeparateOES: [void, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha] 5 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(. util) 2 | 3 | file(GLOB_RECURSE REMOTE_SOURCES remote/*.c) 4 | add_executable(remote EXCLUDE_FROM_ALL ${REMOTE_SOURCES}) 5 | set_target_properties(remote PROPERTIES OUTPUT_NAME libgl_remote) 6 | target_link_libraries(remote GL_static X11 m dl pthread) 7 | 8 | file(GLOB_RECURSE GL_SOURCES gl/*.c gl/*.cpp) 9 | file(GLOB UTIL_SOURCES util/*.c util/math/*.c) 10 | 11 | include_directories(glx) 12 | aux_source_directory(glx GLX_SOURCES) 13 | set(GL_SOURCES ${GL_SOURCES} ${GLX_SOURCES} ${UTIL_SOURCES}) 14 | if(DUALMODE) 15 | set(GL_SOURCES ${GL_SOURCES} ${REMOTE_SOURCES}) 16 | endif() 17 | 18 | add_library(GL_obj OBJECT ${GL_SOURCES}) 19 | set_target_properties(GL_obj PROPERTIES POSITION_INDEPENDENT_CODE 1) 20 | 21 | add_library(GL SHARED $) 22 | target_link_libraries(GL X11 m dl pthread) 23 | 24 | add_library(GL_static STATIC $) 25 | set_target_properties(GL_static PROPERTIES OUTPUT_NAME GL) 26 | 27 | add_library(GL2 SHARED EXCLUDE_FROM_ALL ${GL_SOURCES}) 28 | set_target_properties(GL2 PROPERTIES COMPILE_FLAGS -DUSE_ES2) 29 | 30 | aux_source_directory(preload PRELOAD_SOURCES) 31 | add_library(preload SHARED EXCLUDE_FROM_ALL ${PRELOAD_SOURCES}) 32 | target_link_libraries(preload X11) 33 | 34 | if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 35 | target_link_libraries(GL rt) 36 | target_link_libraries(remote rt) 37 | if(DUALMODE) 38 | target_link_libraries(GL -fPIE -pie) 39 | endif() 40 | endif() 41 | 42 | INSTALL(TARGETS GL 43 | ${INSTALL_TARGETS_DEFAULT_ARGS} 44 | ) 45 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #define SYS_proxy 351 2 | #define MAX_EVAL_ORDER 30 3 | 4 | #define MAX_TEX 4 5 | #define GL_TEXTURE_MAX (GL_TEXTURE0 + MAX_TEX) 6 | -------------------------------------------------------------------------------- /src/gl/array.c: -------------------------------------------------------------------------------- 1 | #include "array.h" 2 | #include "eval.h" 3 | #include "gl_str.h" 4 | 5 | GLvoid *gl_copy_array(const GLvoid *src, 6 | GLenum from, GLsizei width, GLsizei stride, 7 | GLenum to, GLsizei to_width, GLsizei skip, GLsizei count, 8 | GLboolean normalize) { 9 | if (! src || !count) 10 | return NULL; 11 | 12 | if (! stride) 13 | stride = width * gl_sizeof(from); 14 | 15 | const char *unknown_str = "libGL: gl_copy_array -> unsupported type %s\n"; 16 | GLsizei from_size = gl_sizeof(from) * width; 17 | GLsizei to_size = gl_sizeof(to) * to_width; 18 | GLvoid *dst = malloc(count * to_size); 19 | 20 | if (to_width < width) { 21 | printf("Warning: gl_copy_array: %i < %i\n", to_width, width); 22 | return NULL; 23 | } 24 | 25 | // if stride is weird, we need to be able to arbitrarily shift src 26 | // so we leave it in a uintptr_t and cast after incrementing 27 | uintptr_t in = (uintptr_t)src; 28 | in += stride * skip; 29 | if (from == to && to_width >= width) { 30 | GL_TYPE_SWITCH(out, dst, to, 31 | for (int i = skip; i < (skip + count); i++) { 32 | memcpy(out, (GLvoid *)in, from_size); 33 | for (int j = width; j < to_width; j++) { 34 | out[j] = 0; 35 | } 36 | out += to_width; 37 | in += stride; 38 | }, 39 | default: 40 | printf(unknown_str, gl_str(from)); 41 | return NULL; 42 | ) 43 | } else { 44 | GL_TYPE_SWITCH(out, dst, to, 45 | for (int i = skip; i < (skip + count); i++) { 46 | GL_TYPE_SWITCH(input, in, from, 47 | for (int j = 0; j < width; j++) { 48 | if (from != to && normalize) { 49 | out[j] = input[j] * gl_max_value(to); 50 | out[j] /= gl_max_value(from); 51 | } else { 52 | out[j] = input[j]; 53 | } 54 | } 55 | for (int j = width; j < to_width; j++) { 56 | if (j == 3) out[j] = 1; 57 | else out[j] = 0; 58 | } 59 | out += to_width; 60 | in += stride; 61 | , 62 | default: 63 | printf(unknown_str, gl_str(from)); 64 | return NULL; 65 | ) 66 | }, 67 | default: 68 | printf(unknown_str, gl_str(to)); 69 | return NULL; 70 | ) 71 | } 72 | 73 | return dst; 74 | } 75 | 76 | GLvoid *gl_copy_pointer(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count, GLboolean normalize) { 77 | return gl_copy_array(ptr->pointer, ptr->type, ptr->size, ptr->stride, GL_FLOAT, width, skip, count, normalize); 78 | } 79 | 80 | GLfloat *gl_pointer_index(pointer_state_t *p, GLint index) { 81 | static GLfloat buf[4]; 82 | GLsizei size = gl_sizeof(p->type); 83 | GLsizei stride = p->stride ? p->stride : size * p->size; 84 | uintptr_t ptr = (uintptr_t)p->pointer + (stride * index); 85 | 86 | GL_TYPE_SWITCH(src, ptr, p->type, 87 | for (int i = 0; i < p->size; i++) { 88 | buf[i] = src[i]; 89 | } 90 | // zero anything not set by the pointer 91 | for (int i = p->size; i < 4; i++) { 92 | buf[i] = 0; 93 | }, 94 | default: 95 | printf("libGL: unsupported pointer type: %s\n", gl_str(p->type)); 96 | ) 97 | return buf; 98 | } 99 | 100 | 101 | GLfloat *copy_eval_double(GLenum target, GLint ustride, GLint uorder, 102 | GLint vstride, GLint vorder, 103 | const GLdouble *src) { 104 | 105 | GLsizei width = get_map_width(target); 106 | GLsizei dwidth = (uorder == 2 && vorder == 2) ? 0 : uorder * vorder; 107 | GLsizei hwidth = (uorder > vorder ? uorder : vorder) * width; 108 | GLsizei elements; 109 | GLsizei uinc = ustride - vorder * vstride; 110 | 111 | if (hwidth > dwidth) { 112 | elements = (uorder * vorder * width + hwidth); 113 | } else { 114 | elements = (uorder * vorder * width + dwidth); 115 | } 116 | GLfloat *points = malloc(elements * sizeof(GLfloat)); 117 | GLfloat *dst = points; 118 | 119 | for (int i = 0; i < uorder; i++, src += uinc) { 120 | for (int j = 0; j < vorder; j++, src += vstride) { 121 | for (int k = 0; k < width; k++) { 122 | *dst++ = src[k]; 123 | } 124 | } 125 | } 126 | return points; 127 | } 128 | 129 | void normalize_indices(GLushort *indices, GLsizei *max, GLsizei *min, GLsizei count) { 130 | *max = 0; 131 | *min = -1; 132 | for (int i = 0; i < count; i++) { 133 | GLsizei n = indices[i]; 134 | if (*min == -1) 135 | *min = n; 136 | *min = (n < *min) ? n : *min; 137 | *max = (n > *max) ? n : *max; 138 | } 139 | for (int i = 0; i < count; i++) { 140 | indices[i] -= *min; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/gl/array.h: -------------------------------------------------------------------------------- 1 | #include "gl.h" 2 | 3 | #ifndef GL_ARRAY_H 4 | #define GL_ARRAY_H 5 | 6 | #include "types.h" 7 | 8 | GLvoid *gl_copy_array(const GLvoid *src, 9 | GLenum from, GLsizei width, GLsizei stride, 10 | GLenum to, GLsizei to_width, GLsizei skip, GLsizei count, 11 | GLboolean normalize); 12 | 13 | GLvoid *gl_copy_pointer(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count, GLboolean); 14 | GLfloat *gl_pointer_index(pointer_state_t *ptr, GLint index); 15 | GLfloat *copy_eval_double(GLenum target, GLint ustride, GLint uorder, GLint vstride, GLint vorder, const GLdouble *points); 16 | void normalize_indices(GLushort *indices, GLsizei *max, GLsizei *min, GLsizei count); 17 | #endif 18 | -------------------------------------------------------------------------------- /src/gl/blend.c: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include "loader.h" 3 | #include "remote.h" 4 | 5 | void glAlphaFunc(GLenum func, GLclampf ref) { 6 | ERROR_IN_BLOCK(); 7 | PUSH_IF_COMPILING(glAlphaFunc); 8 | PROXY_GLES(glAlphaFunc); 9 | } 10 | 11 | void glBlendFunc(GLenum sfactor, GLenum dfactor) { 12 | ERROR_IN_BLOCK(); 13 | PUSH_IF_COMPILING(glBlendFunc); 14 | PROXY_GLES(glBlendFunc); 15 | } 16 | 17 | #ifndef USE_ES2 18 | void glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { 19 | ERROR_IN_BLOCK(); 20 | PUSH_IF_COMPILING(glBlendColor); 21 | PROXY_OES(glBlendColorOES); 22 | } 23 | 24 | void glBlendEquation(GLenum mode) { 25 | ERROR_IN_BLOCK(); 26 | PUSH_IF_COMPILING(glBlendEquation); 27 | PROXY_OES(glBlendEquationOES); 28 | } 29 | 30 | void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) { 31 | ERROR_IN_BLOCK(); 32 | PUSH_IF_COMPILING(glBlendEquationSeparate); 33 | PROXY_OES(glBlendEquationSeparateOES); 34 | } 35 | 36 | void glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) { 37 | ERROR_IN_BLOCK(); 38 | PUSH_IF_COMPILING(glBlendFuncSeparate); 39 | PROXY_OES(glBlendFuncSeparateOES); 40 | } 41 | 42 | void glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) { 43 | printf("warning: neutered glBlendFuncSeparatei()\n"); 44 | glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); 45 | } 46 | 47 | void glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha) { 48 | printf("warning: neutered glBlendEquationSeparatei()\n"); 49 | glBlendEquationSeparate(modeRGB, modeAlpha); 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /src/gl/block.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_H 2 | #define BLOCK_H 3 | 4 | #include "types.h" 5 | 6 | #define DEFAULT_BLOCK_CAPACITY 16 7 | #define RENDER_BLOCK_INDEX -1 8 | 9 | extern block_t *bl_new(GLenum mode); 10 | extern void bl_free(block_t *block); 11 | extern void bl_draw(block_t *block); 12 | extern void bl_q2t(block_t *block); 13 | extern void bl_end(block_t *block); 14 | 15 | extern void bl_vertex3f(block_t *block, GLfloat x, GLfloat y, GLfloat z); 16 | extern void bl_track_color(block_t *block); 17 | extern void bl_track_normal(block_t *block); 18 | extern void bl_track_tex(block_t *block, GLenum target); 19 | extern void bl_pollute(block_t *block); 20 | 21 | extern void bl_push_call(block_t *block, packed_call_t *data); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/gl/clear.c: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include "loader.h" 3 | #include "remote.h" 4 | 5 | void glClear(GLbitfield mask) { 6 | ERROR_IN_BLOCK(); 7 | PUSH_IF_COMPILING(glClear); 8 | PROXY_GLES(glClear); 9 | } 10 | 11 | void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { 12 | ERROR_IN_BLOCK(); 13 | PUSH_IF_COMPILING(glClearColor); 14 | PROXY_GLES(glClearColor); 15 | } 16 | 17 | void glClearDepthf(GLclampf depth) { 18 | ERROR_IN_BLOCK(); 19 | PUSH_IF_COMPILING(glClearDepthf); 20 | PROXY_GLES(glClearDepthf); 21 | } 22 | 23 | void glClearStencil(GLint s) { 24 | ERROR_IN_BLOCK(); 25 | PUSH_IF_COMPILING(glClearStencil); 26 | PROXY_GLES(glClearStencil); 27 | } 28 | -------------------------------------------------------------------------------- /src/gl/const.h: -------------------------------------------------------------------------------- 1 | #ifndef CONST_H 2 | #define CONST_H 3 | 4 | #ifdef __linux__ 5 | #include 6 | #endif 7 | 8 | #ifndef PATH_MAX 9 | #define PATH_MAX 254 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/gl/defines.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef MIN 4 | #define MIN(a, b) (((a) < (b) ? (a) : (b))) 5 | #endif 6 | 7 | #ifndef MAX 8 | #define MAX(a, b) (((a) > (b) ? (a) : (b))) 9 | #endif 10 | 11 | // newly-defined GL functions 12 | GLboolean glIsList(GLuint list); 13 | GLuint glGenLists(GLsizei range); 14 | void glActiveTextureARB(GLenum texture); 15 | void glArrayElement(GLint i); 16 | void glBegin(GLenum mode); 17 | void glCallList(GLuint list); 18 | void glCallLists(GLsizei n, GLenum type, const GLvoid *lists); 19 | void glClearDepth(GLdouble depth); 20 | void glDeleteList(GLuint list); 21 | void glDeleteLists(GLuint list, GLsizei range); 22 | void glDrawArrays(GLenum mode, GLint first, GLsizei count); 23 | void glEnd(); 24 | void glEndList(); 25 | void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); 26 | void glGetDoublev(GLenum pname, GLdouble *params); 27 | void glIndexf(GLfloat i); 28 | void glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer); 29 | void glListBase(GLuint base); 30 | void glLockArraysEXT(GLint first, GLsizei count); 31 | void glNewList(GLuint list, GLenum mode); 32 | void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); 33 | void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b); 34 | void glTexCoord2f(GLfloat s, GLfloat t); 35 | void glUnlockArraysEXT(); 36 | void glVertex2f(GLfloat x, GLfloat y); 37 | void glVertex2i(GLint x, GLint y); 38 | void glVertex3f(GLfloat x, GLfloat y, GLfloat z); 39 | 40 | // custom functions 41 | void glPushCall(void *call); 42 | -------------------------------------------------------------------------------- /src/gl/depth.c: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include "loader.h" 3 | #include "remote.h" 4 | 5 | void glDepthFunc(GLenum func) { 6 | ERROR_IN_BLOCK(); 7 | PUSH_IF_COMPILING(glDepthFunc); 8 | PROXY_GLES(glDepthFunc); 9 | } 10 | 11 | void glDepthMask(GLboolean flag) { 12 | ERROR_IN_BLOCK(); 13 | PUSH_IF_COMPILING(glDepthMask); 14 | PROXY_GLES(glDepthMask); 15 | } 16 | 17 | void glDepthRangef(GLclampf near, GLclampf far) { 18 | ERROR_IN_BLOCK(); 19 | PUSH_IF_COMPILING(glDepthRangef); 20 | PROXY_GLES(glDepthRangef); 21 | } 22 | -------------------------------------------------------------------------------- /src/gl/error.h: -------------------------------------------------------------------------------- 1 | #include "get.h" 2 | 3 | #define ERROR(pname) do { gl_set_error(pname); return; } while (0) 4 | #define ERROR_IN_BLOCK() if (state.block.active) { ERROR(GL_INVALID_OPERATION); } 5 | -------------------------------------------------------------------------------- /src/gl/eval.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_MAP_H 2 | #define GL_MAP_H 3 | 4 | #include 5 | 6 | void glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); 7 | void glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); 8 | void glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); 9 | void glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); 10 | 11 | void glEvalCoord1d(GLdouble u); 12 | void glEvalCoord1f(GLfloat u); 13 | void glEvalCoord2d(GLdouble u, GLdouble v); 14 | void glEvalCoord2f(GLfloat u, GLfloat v); 15 | 16 | void glEvalMesh1(GLenum mode, GLint i1, GLint i2); 17 | void glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); 18 | void glEvalPoint1(GLint i); 19 | void glEvalPoint2(GLint i, GLint j); 20 | void glMapGrid1d(GLint un, GLdouble u1, GLdouble u2); 21 | void glMapGrid1f(GLint un, GLfloat u1, GLfloat u2); 22 | void glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); 23 | void glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); 24 | void glGetMapdv(GLenum target, GLenum query, GLdouble *v); 25 | void glGetMapfv(GLenum target, GLenum query, GLfloat *v); 26 | void glGetMapiv(GLenum target, GLenum query, GLint *v); 27 | 28 | static const GLsizei get_map_width(GLenum target) { 29 | switch (target) { 30 | case GL_MAP1_COLOR_4: return 4; 31 | case GL_MAP1_INDEX: return 3; 32 | case GL_MAP1_NORMAL: return 3; 33 | case GL_MAP1_TEXTURE_COORD_1: return 1; 34 | case GL_MAP1_TEXTURE_COORD_2: return 2; 35 | case GL_MAP1_TEXTURE_COORD_3: return 3; 36 | case GL_MAP1_TEXTURE_COORD_4: return 4; 37 | case GL_MAP1_VERTEX_3: return 3; 38 | case GL_MAP1_VERTEX_4: return 4; 39 | case GL_MAP2_COLOR_4: return 4; 40 | case GL_MAP2_INDEX: return 3; 41 | case GL_MAP2_NORMAL: return 3; 42 | case GL_MAP2_TEXTURE_COORD_1: return 1; 43 | case GL_MAP2_TEXTURE_COORD_2: return 2; 44 | case GL_MAP2_TEXTURE_COORD_3: return 3; 45 | case GL_MAP2_TEXTURE_COORD_4: return 4; 46 | case GL_MAP2_VERTEX_3: return 3; 47 | case GL_MAP2_VERTEX_4: return 4; 48 | } 49 | return 0; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/gl/get.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GLenum gl_get_error(); 4 | void gl_clear_error(); 5 | void gl_get(GLenum pname, GLenum type, GLvoid *params); 6 | void gl_set_error(GLenum error); 7 | -------------------------------------------------------------------------------- /src/gl/gl.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "types.h" 10 | 11 | #ifdef __linux__ 12 | #include 13 | #endif 14 | 15 | #ifndef PATH_MAX 16 | #define PATH_MAX 254 17 | #endif 18 | 19 | #ifdef __ARM_NEON__ 20 | #include 21 | #endif 22 | 23 | #ifndef GL_H 24 | #define GL_H 25 | 26 | #include "../config.h" 27 | #include "wrap/glpack.h" 28 | 29 | #include "gl_helpers.h" 30 | #include "defines.h" 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/gl/light.c: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include "gl_str.h" 3 | #include "light.h" 4 | #include "list.h" 5 | #include "loader.h" 6 | #include "matrix.h" 7 | #include "remote.h" 8 | 9 | #ifndef USE_ES2 10 | void glLightModelf(GLenum pname, GLfloat param) { 11 | ERROR_IN_BLOCK(); 12 | PUSH_IF_COMPILING(glLightModelf); 13 | LOAD_GLES(glLightModelf); 14 | switch (pname) { 15 | case GL_LIGHT_MODEL_AMBIENT: 16 | case GL_LIGHT_MODEL_TWO_SIDE: 17 | gles_glLightModelf(pname, param); 18 | default: 19 | fprintf(stderr, "stubbed glLightModelf(%s, %.2f)\n", gl_str(pname), param); 20 | break; 21 | } 22 | } 23 | 24 | void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) { 25 | if (state.list.active) { 26 | int len = 0; 27 | switch (pname) { 28 | case GL_AMBIENT_AND_DIFFUSE: 29 | case GL_AMBIENT: 30 | case GL_DIFFUSE: 31 | case GL_EMISSION: 32 | case GL_SPECULAR: 33 | len = 4; 34 | break; 35 | case GL_COLOR_INDEXES: 36 | len = 3; 37 | break; 38 | case GL_SHININESS: 39 | len = 1; 40 | break; 41 | default: 42 | fprintf(stderr, "Warning: unknown glMaterialfv() pname=0x%x\n", pname); 43 | return; 44 | } 45 | params = dl_retain(state.list.active, params, len * sizeof(GLfloat)); 46 | } 47 | PUSH_IF_COMPILING(glMaterialfv); 48 | LOAD_GLES(glMaterialfv); 49 | gles_glMaterialfv(GL_FRONT_AND_BACK, pname, params); 50 | } 51 | 52 | void glLightfv(GLenum light, GLenum pname, const GLfloat *params) { 53 | ERROR_IN_BLOCK(); 54 | if (state.list.active) { 55 | int len = 0; 56 | switch (pname) { 57 | case GL_AMBIENT: 58 | case GL_DIFFUSE: 59 | case GL_SPECULAR: 60 | case GL_POSITION: 61 | len = 4; 62 | break; 63 | case GL_SPOT_DIRECTION: 64 | len = 3; 65 | break; 66 | case GL_SPOT_EXPONENT: 67 | case GL_SPOT_CUTOFF: 68 | case GL_CONSTANT_ATTENUATION: 69 | case GL_LINEAR_ATTENUATION: 70 | case GL_QUADRATIC_ATTENUATION: 71 | len = 1; 72 | break; 73 | default: 74 | fprintf(stderr, "Warning: unknown glLightfv() pname=0x%x\n", pname); 75 | return; 76 | } 77 | params = dl_retain(state.list.active, params, len * sizeof(GLfloat)); 78 | } 79 | PUSH_IF_COMPILING(glLightfv); 80 | LOAD_GLES(glLightfv); 81 | #ifdef LOCAL_MATRIX 82 | GLfloat tmp[4]; 83 | switch (pname) { 84 | case GL_POSITION: 85 | gl_transform_light(tmp, params); 86 | params = tmp; 87 | default: 88 | gles_glLightfv(light, pname, params); 89 | break; 90 | } 91 | #else 92 | gles_glLightfv(light, pname, params); 93 | #endif 94 | } 95 | 96 | void glFogfv(GLenum pname, const GLfloat *params) { 97 | params = dl_retain(state.list.active, params, gl_fogv_length(pname) * sizeof(GLfloat)); 98 | PUSH_IF_COMPILING(glFogfv); 99 | PROXY_GLES(glFogfv); 100 | } 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/gl/light.h: -------------------------------------------------------------------------------- 1 | #include "gl.h" 2 | 3 | void glLightModelf(GLenum pname, GLfloat param); 4 | -------------------------------------------------------------------------------- /src/gl/line.c: -------------------------------------------------------------------------------- 1 | #include "line.h" 2 | 3 | GLint stippleFactor = 1; 4 | GLushort stipplePattern = 0xFFFF; 5 | GLubyte *stippleData = NULL; 6 | GLuint stippleTexture = 0; 7 | 8 | void glLineStipple(GLint factor, GLushort pattern) { 9 | stippleFactor = factor; 10 | stipplePattern = pattern; 11 | if (stippleData != NULL) { 12 | free(stippleData); 13 | } 14 | stippleData = (GLubyte *)malloc(sizeof(GLubyte) * 16); 15 | for (int i = 0; i < 16; i++) { 16 | stippleData[i] = (stipplePattern >> i) & 1 ? 255 : 0; 17 | } 18 | 19 | glPushAttrib(GL_TEXTURE_BIT); 20 | if (! stippleTexture) 21 | glGenTextures(1, &stippleTexture); 22 | 23 | glBindTexture(GL_TEXTURE_2D, stippleTexture); 24 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 25 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 26 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 27 | 28 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 29 | 16, 1, 0, GL_ALPHA, GL_UNSIGNED_BYTE, stippleData); 30 | glPopAttrib(); 31 | } 32 | 33 | void bind_stipple_tex() { 34 | glBindTexture(GL_TEXTURE_2D, stippleTexture); 35 | } 36 | 37 | GLfloat *gen_stipple_tex_coords(GLfloat *vert, int length) { 38 | // generate our texture coords 39 | GLfloat *tex = (GLfloat *)malloc(length * 4 * sizeof(GLfloat)); 40 | GLfloat *texPos = tex; 41 | GLfloat *vertPos = vert; 42 | 43 | GLfloat x1, x2, y1, y2; 44 | GLfloat len; 45 | for (int i = 0; i < length / 2; i++) { 46 | x1 = *vertPos++; 47 | y1 = *vertPos++; 48 | vertPos++; // z 49 | x2 = *vertPos++; 50 | y2 = *vertPos++; 51 | vertPos++; 52 | 53 | len = sqrt(pow(x2-x1, 2) + pow(y2-y1, 2)) / stippleFactor * 16; 54 | 55 | *texPos++ = 0; // s 56 | *texPos++ = 0; 57 | *texPos++ = 0; 58 | *texPos++ = 0; 59 | *texPos++ = len; // s 60 | *texPos++ = 0; 61 | *texPos++ = 0; 62 | *texPos++ = 0; 63 | } 64 | return tex; 65 | } 66 | -------------------------------------------------------------------------------- /src/gl/line.h: -------------------------------------------------------------------------------- 1 | #include "gl.h" 2 | 3 | extern GLfloat *gen_stipple_tex_coords(GLfloat *vert, int length); 4 | extern void bind_stipple_tex(); 5 | -------------------------------------------------------------------------------- /src/gl/list.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "block.h" 4 | #include "gl.h" 5 | #include "list.h" 6 | 7 | displaylist_t *dl_alloc() { 8 | displaylist_t *dl = calloc(1, sizeof(displaylist_t)); 9 | if (dl != NULL) { 10 | dl->open = true; 11 | } 12 | return dl; 13 | } 14 | 15 | void dl_free(displaylist_t *dl) { 16 | int len = tack_len(&dl->calls); 17 | for (int i = 0; i < len; i++) { 18 | packed_call_t *call = tack_get(&dl->calls, i); 19 | if (call->index == RENDER_BLOCK_INDEX) { 20 | block_call_t *blc = (block_call_t *)call; 21 | bl_free(blc->block); 22 | } else { 23 | free(call); 24 | } 25 | } 26 | len = tack_len(&dl->retain); 27 | for (int i = 0; i < len; i++) { 28 | free(tack_get(&dl->retain, i)); 29 | } 30 | free(dl); 31 | } 32 | 33 | void dl_append(displaylist_t *dl, packed_call_t *call) { 34 | if (! dl->open) { 35 | printf("libGL: warning: trying to append to closed display list\n"); 36 | return; 37 | } 38 | tack_push(&dl->calls, call); 39 | } 40 | 41 | void dl_append_block(displaylist_t *dl, block_t *block) { 42 | block_call_t *call = malloc(sizeof(block_call_t)); 43 | call->index = RENDER_BLOCK_INDEX; 44 | call->block = block; 45 | dl_append(dl, (packed_call_t *)call); 46 | } 47 | 48 | void dl_extend(displaylist_t *dl, displaylist_t *append) { 49 | int len = tack_len(&append->calls); 50 | for (int i = 0; i < len; i++) { 51 | dl_append(dl, tack_get(&append->calls, i)); 52 | } 53 | } 54 | 55 | void dl_close(displaylist_t *dl) { 56 | dl->open = false; 57 | } 58 | 59 | void dl_call(displaylist_t *dl) { 60 | int len = tack_len(&dl->calls); 61 | for (int i = 0; i < len; i++) { 62 | packed_call_t *call = tack_get(&dl->calls, i); 63 | switch (call->index) { 64 | case RENDER_BLOCK_INDEX: { 65 | block_t *block = ((block_call_t *)call)->block; 66 | bl_draw(block); 67 | bl_pollute(block); 68 | break; 69 | } 70 | default: 71 | glIndexedCall(call, NULL); 72 | break; 73 | } 74 | } 75 | } 76 | 77 | void *dl_retain(displaylist_t *dl, const void *ptr, size_t size) { 78 | if (dl && ptr) { 79 | void *tmp = malloc(size); 80 | memcpy(tmp, ptr, size); 81 | ptr = tmp; 82 | tack_push(&dl->retain, tmp); 83 | } 84 | return (void *)ptr; 85 | } 86 | -------------------------------------------------------------------------------- /src/gl/list.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPLAYLIST_H 2 | #define DISPLAYLIST_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "types.h" 8 | 9 | extern displaylist_t *dl_alloc(); 10 | extern void dl_append(displaylist_t *dl, packed_call_t *call); 11 | extern void dl_append_block(displaylist_t *dl, block_t *block); 12 | extern void dl_call(displaylist_t *dl); 13 | extern void dl_close(displaylist_t *dl); 14 | extern void dl_extend(displaylist_t *dl, displaylist_t *append); 15 | extern void dl_free(displaylist_t *dl); 16 | extern void *dl_retain(displaylist_t *dl, const void *ptr, size_t size); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/gl/loader.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "loader.h" 3 | 4 | void *gles = NULL, *egl = NULL, *bcm_host = NULL, *vcos = NULL; 5 | 6 | static const char *path_prefix[] = { 7 | "", 8 | "/opt/vc/lib/", 9 | "/usr/local/lib/", 10 | "/usr/lib/", 11 | NULL, 12 | }; 13 | 14 | static const char *lib_ext[] = { 15 | "so", 16 | "so.1", 17 | "so.2", 18 | "dylib", 19 | "dll", 20 | NULL, 21 | }; 22 | 23 | static const char *gles_lib[] = { 24 | #ifdef USE_ES2 25 | "libGLESv2_CM", 26 | "libGLESv2", 27 | #else 28 | "libGLESv1_CM", 29 | "libGLES_CM", 30 | #endif // USE_ES2 31 | NULL 32 | }; 33 | 34 | static const char *egl_lib[] = { 35 | "libEGL", 36 | NULL 37 | }; 38 | 39 | void *open_lib(const char **names, const char *override) { 40 | void *lib = NULL; 41 | 42 | char path_name[PATH_MAX + 1]; 43 | int flags = RTLD_LOCAL | RTLD_NOW; 44 | #ifdef RTLD_DEEPBIND 45 | flags |= RTLD_DEEPBIND; 46 | #endif 47 | if (override) { 48 | if ((lib = dlopen(override, flags))) { 49 | strncpy(path_name, override, PATH_MAX); 50 | printf("libGL:loaded: %s\n", path_name); 51 | return lib; 52 | } else { 53 | printf("LIBGL_GLES override failed: %s\n", dlerror()); 54 | } 55 | } 56 | for (int p = 0; path_prefix[p]; p++) { 57 | for (int i = 0; names[i]; i++) { 58 | for (int e = 0; lib_ext[e]; e++) { 59 | snprintf(path_name, PATH_MAX, "%s%s.%s", path_prefix[p], names[i], lib_ext[e]); 60 | if ((lib = dlopen(path_name, flags))) { 61 | printf("libGL:loaded: %s\n", path_name); 62 | return lib; 63 | } 64 | } 65 | } 66 | } 67 | return lib; 68 | } 69 | 70 | void load_libs() { 71 | static int first = true; 72 | if (! first) return; 73 | first = false; 74 | char *gles_override = getenv("LIBGL_GLES"); 75 | // optimistically try to load the raspberry pi libs 76 | if (! gles_override) { 77 | const char *bcm_host_name[] = {"libbcm_host", NULL}; 78 | const char *vcos_name[] = {"libvcos", NULL}; 79 | bcm_host = open_lib(bcm_host_name, NULL); 80 | vcos = open_lib(vcos_name, NULL); 81 | } 82 | gles = open_lib(gles_lib, gles_override); 83 | WARN_NULL(gles); 84 | 85 | char *egl_override = getenv("LIBGL_EGL"); 86 | egl = open_lib(egl_lib, egl_override); 87 | WARN_NULL(egl); 88 | } 89 | 90 | void debugf(char *fmt, ...) { 91 | static int debug = -1; 92 | if (debug < 0) { 93 | debug = 0; 94 | char *tmp = getenv("LIBGL_DEBUG"); 95 | if (tmp && strcmp(tmp, "1") == 0) { 96 | debug = 1; 97 | } 98 | } 99 | if (debug == 1) { 100 | va_list arg; 101 | va_start(arg, fmt); 102 | vprintf(fmt, arg); 103 | va_end(arg); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/gl/loader.h: -------------------------------------------------------------------------------- 1 | #ifndef LOADER_H 2 | #define LOADER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "const.h" 10 | #include "wrap/glpack.h" 11 | #include "wrap/stub.h" 12 | 13 | // will become references to dlopen'd gles and egl 14 | extern void *gles, *egl, *bcm_host, *vcos; 15 | 16 | extern void *open_lib(const char **names, const char *override); 17 | extern void load_libs(); 18 | extern void debugf(char *fmt, ...); 19 | 20 | #ifndef WARN_NULL 21 | #define WARN_NULL(name) if (name == NULL) printf("libGL: warning, " #name " is NULL\n"); 22 | #endif 23 | 24 | #ifndef LOAD_RAW 25 | #define LOAD_RAW(lib, name, ...) \ 26 | static name##_PTR lib##_##name; \ 27 | { \ 28 | static bool first = true; \ 29 | if (first) { \ 30 | first = false; \ 31 | if (lib == NULL) { \ 32 | load_libs(); \ 33 | } \ 34 | if (lib != NULL) { \ 35 | lib##_##name = (name##_PTR)__VA_ARGS__; \ 36 | } \ 37 | } \ 38 | } 39 | #endif 40 | 41 | #define LOAD_LIB(lib, name) LOAD_RAW(lib, name, dlsym(lib, #name)) 42 | 43 | #ifndef LOAD_GLES 44 | #define LOAD_GLES(name) \ 45 | LOAD_GLES_SILENT(name); \ 46 | WARN_NULL(gles_##name); \ 47 | if (gles_##name == NULL) gles_##name = stub_##name; 48 | #endif 49 | 50 | #define LOAD_GLES_SILENT(name) LOAD_LIB(gles, name) 51 | #define LOAD_EGL(name) LOAD_LIB(egl, name) 52 | #define LOAD_OES(name) \ 53 | LOAD_EGL(eglGetProcAddress); \ 54 | LOAD_RAW(egl, name, egl_eglGetProcAddress(#name)); 55 | 56 | #ifndef PUSH_IF_COMPILING 57 | #define PUSH_IF_COMPILING(name) \ 58 | FORWARD_IF_REMOTE(name); \ 59 | if (state.list.active) { \ 60 | glPushCall(pack_##name(NULL name##_ARG_NAMES_TAIL)); \ 61 | return (name##_RETURN)0; \ 62 | } 63 | #endif 64 | 65 | #ifndef FORWARD_IF_REMOTE_EXT 66 | #define FORWARD_IF_REMOTE_EXT(name, ...) \ 67 | do { \ 68 | if (state.remote) { \ 69 | return forward_##name(__VA_ARGS__); \ 70 | } \ 71 | } while (0) 72 | #endif 73 | 74 | #ifndef FORWARD_IF_REMOTE 75 | #define FORWARD_IF_REMOTE(name) FORWARD_IF_REMOTE_EXT(name, name##_ARG_NAMES) 76 | #endif 77 | 78 | #ifndef PROXY 79 | #define PROXY(load_name, lib, name) \ 80 | LOAD_##load_name(name); \ 81 | if (lib##_##name != NULL) { \ 82 | return lib##_##name(name##_ARG_NAMES); \ 83 | } 84 | #endif 85 | 86 | #define PROXY_GL(name) PROXY(GLES_SILENT, gles, name) 87 | #ifndef PROXY_GLES 88 | #define PROXY_GLES(name) PROXY(GLES_SILENT, gles, name) 89 | #endif 90 | #define PROXY_EGL(name) PROXY(EGL, egl, name) 91 | #define PROXY_OES(name) PROXY(OES, egl, name) 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /src/gl/matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_MATRIX_H 2 | #define GL_MATRIX_H 3 | 4 | #include 5 | 6 | void glLoadIdentity(); 7 | void glLoadMatrixf(const GLfloat *m); 8 | void glMatrixMode(GLenum mode); 9 | void glMultMatrixf(const GLfloat *m); 10 | void glPopMatrix(); 11 | void glPushMatrix(); 12 | void gl_get_matrix(GLenum mode, GLfloat *out); 13 | void gl_transform_light(GLfloat out[3], const GLfloat in[3]); 14 | void gl_transform_texture(GLenum texture, GLfloat out[4], const GLfloat in[4]); 15 | void gl_transform_vertex(GLfloat out[3], GLfloat in[3]); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/gl/pixel.h: -------------------------------------------------------------------------------- 1 | #ifndef PIXEL_H 2 | #define PIXEL_H 3 | 4 | #include 5 | #include 6 | 7 | typedef struct { 8 | GLenum type; 9 | GLint red, green, blue, alpha; 10 | } colorlayout_t; 11 | 12 | typedef struct { 13 | GLfloat r, g, b, a; 14 | } pixel_t; 15 | 16 | bool pixel_convert(const GLvoid *src, GLvoid **dst, 17 | GLuint width, GLuint height, 18 | GLenum src_format, GLenum src_type, 19 | GLenum dst_format, GLenum dst_type); 20 | 21 | bool pixel_convert_direct(const GLvoid *src, GLvoid *dst, GLuint pixels, 22 | GLenum src_format, GLenum src_type, GLsizei src_stride, 23 | GLenum dst_format, GLenum dst_type, GLsizei dst_stride); 24 | 25 | bool pixel_scale(const GLvoid *src, GLvoid **dst, 26 | GLuint width, GLuint height, 27 | GLfloat ratio, 28 | GLenum format, GLenum type); 29 | 30 | bool pixel_to_ppm(const GLvoid *pixels, 31 | GLuint width, GLuint height, 32 | GLenum format, GLenum type, GLuint name); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/gl/raster.h: -------------------------------------------------------------------------------- 1 | #include "gl.h" 2 | 3 | #ifndef RASTER_H 4 | #define RASTER_H 5 | 6 | extern void glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, 7 | GLfloat xmove, GLfloat ymove, const GLubyte *bitmap); 8 | extern void glDrawPixels(GLsizei width, GLsizei height, GLenum format, 9 | GLenum type, const GLvoid *data); 10 | extern void glRasterPos3f(GLfloat x, GLfloat y, GLfloat z); 11 | extern void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); 12 | extern void render_raster(); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/gl/remote.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_REMOTE_H 2 | #define GL_REMOTE_H 3 | #include 4 | #include "block.h" 5 | #include "wrap/types.h" 6 | 7 | #define REMOTE_BLOCK_DRAW -1 8 | #define REMOTE_GL_GET -2 9 | 10 | int remote_serve(char *listen_path); 11 | int remote_spawn(const char *path); 12 | void remote_write_block(ring_t *ring, block_t *block); 13 | block_t *remote_read_block(ring_t *ring, packed_call_t *call); 14 | void *remote_dma(size_t size); 15 | void remote_dma_send(packed_call_t *call, void *ret_v); 16 | 17 | void remote_block_draw(block_t *block); 18 | void remote_gl_get(GLenum pname, GLenum type, GLvoid *params); 19 | 20 | void remote_glEnable(GLenum cap); 21 | void remote_glDisable(GLenum cap); 22 | void remote_glEnableClientState(GLenum cap); 23 | void remote_glDisableClientState(GLenum cap); 24 | #endif 25 | -------------------------------------------------------------------------------- /src/gl/render.h: -------------------------------------------------------------------------------- 1 | #include "block.h" 2 | 3 | void gl_feedback_block(block_t *block); 4 | void gl_select_block(block_t *block); 5 | -------------------------------------------------------------------------------- /src/gl/skip.h: -------------------------------------------------------------------------------- 1 | // don't auto-wrap these functions 2 | #define skip_glColor4ub 3 | 4 | // blend.c 5 | #define skip_glAlphaFunc 6 | #define skip_glBlendFunc 7 | 8 | // clear.c 9 | #define skip_glClear 10 | #define skip_glClearColor 11 | #define skip_glClearDepthf 12 | #define skip_glClearStencil 13 | 14 | // depth.c 15 | #define skip_glDepthFunc 16 | #define skip_glDepthMask 17 | #define skip_glDepthRangef 18 | 19 | // gl.c 20 | #define skip_glColor4f 21 | #define skip_glDisable 22 | #define skip_glEnable 23 | #define skip_glIsEnabled 24 | #define skip_glNormal3f 25 | 26 | // get.c 27 | #define skip_glGetBooleanv 28 | #define skip_glGetError 29 | #define skip_glGetFloatv 30 | #define skip_glGetIntegerv 31 | #define skip_glGetString 32 | 33 | // matrix.c 34 | #define skip_glFrustumf 35 | #define skip_glLoadIdentity 36 | #define skip_glLoadMatrixf 37 | #define skip_glMatrixMode 38 | #define skip_glMultMatrixf 39 | #define skip_glOrthof 40 | #define skip_glPopMatrix 41 | #define skip_glPushMatrix 42 | #define skip_glRotatef 43 | #define skip_glScalef 44 | #define skip_glTranslatef 45 | 46 | // light.c 47 | #define skip_glLightModelf 48 | #ifdef LOCAL_MATRIX 49 | #define skip_glLightfv 50 | #endif 51 | #define skip_glMaterialfv 52 | #define skip_glFogfv 53 | #define skip_glLightfv 54 | 55 | // raster.c 56 | #define skip_glViewport 57 | 58 | // texture.c 59 | #define skip_glActiveTexture 60 | #define skip_glBindTexture 61 | #define skip_glClientActiveTexture 62 | #define skip_glDeleteTextures 63 | #define skip_glMultiTexCoord4f 64 | #define skip_glPixelStorei 65 | #define skip_glTexEnvf 66 | #define skip_glTexImage2D 67 | #define skip_glTexParameteri 68 | #define skip_glTexSubImage2D 69 | 70 | // glDrawArrays 71 | #define skip_glDrawArrays 72 | #define skip_glDrawElements 73 | #define skip_glVertexPointer 74 | #define skip_glColorPointer 75 | #define skip_glNormalPointer 76 | #define skip_glTexCoordPointer 77 | #define skip_glDisableClientState 78 | #define skip_glEnableClientState 79 | 80 | // don't compile these into display lists 81 | #define direct_glColorPointer 82 | #define direct_glDeleteLists 83 | #define direct_glDisableClientState 84 | #define direct_glEdgeFlagPointer 85 | #define direct_glEnableClientState 86 | #define direct_glFeedbackBuffer 87 | #define direct_glFinish 88 | #define direct_glFlush 89 | #define direct_glGenLists 90 | #define direct_glIndexPointer 91 | #define direct_glInterleavedArrays 92 | #define direct_glIsEnabled 93 | #define direct_glIsList 94 | #define direct_glNormalPointer 95 | #define direct_glPopClientAttrib 96 | #define direct_glPixelStorei 97 | #define direct_glPushClientAttrib 98 | #define direct_glReadPixels 99 | #define direct_glRenderMode 100 | #define direct_glSelectBuffer 101 | #define direct_glTexCoordPointer 102 | #define direct_glVertexPointer 103 | 104 | #define direct_glGetTexParameterfv 105 | #define direct_glGetTexParameteriv 106 | #define direct_glGetTexParameterIiv 107 | #define direct_glGetTexParameterIuiv 108 | -------------------------------------------------------------------------------- /src/gl/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_STACK_H 2 | #define GL_STACK_H 3 | 4 | #include "types.h" 5 | 6 | typedef struct { 7 | GLbitfield mask; 8 | 9 | // GL_COLOR_BUFFER_BIT 10 | GLboolean alpha_test; 11 | GLint alpha_test_func; 12 | GLclampf alpha_test_ref; 13 | 14 | GLboolean blend; 15 | GLint blend_src_func; 16 | GLint blend_dst_func; 17 | 18 | GLboolean dither; 19 | 20 | GLboolean color_logic_op; 21 | GLint logic_op; 22 | 23 | GLfloat clear_color[4]; 24 | GLfloat color_mask[4]; 25 | 26 | // GL_CURRENT_BIT 27 | GLfloat color[4]; 28 | GLfloat normal[4]; 29 | GLfloat tex[MAX_TEX][4]; 30 | 31 | // TODO: can only fill this via raster.c 32 | GLfloat raster_pos[3]; 33 | GLboolean raster_valid; 34 | 35 | // GL_DEPTH_BUFFER_BIT 36 | GLboolean depth_test; 37 | GLint depth_func; 38 | GLfloat clear_depth; 39 | GLint depth_mask; 40 | 41 | // GL_ENABLE_BIT 42 | GLboolean cull_face; 43 | GLboolean normalize; 44 | GLboolean polygon_offset_fill; 45 | GLboolean stencil_test; 46 | 47 | // GL_FOG_BIT 48 | GLboolean fog; 49 | GLfloat fog_color[4]; 50 | GLfloat fog_density; 51 | GLfloat fog_start; 52 | GLfloat fog_end; 53 | GLint fog_mode; 54 | 55 | // GL_HINT_BIT 56 | GLint perspective_hint; 57 | GLint point_smooth_hint; 58 | GLint line_smooth_hint; 59 | GLint fog_hint; 60 | GLint mipmap_hint; 61 | 62 | // GL_LIGHTING_BIT 63 | GLboolean lighting; 64 | GLboolean *lights_enabled; 65 | GLfloat *lights; 66 | GLint light_model_ambient[4]; 67 | GLint light_model_two_side; 68 | GLint shade_model; 69 | 70 | // GL_LINE_BIT 71 | GLboolean line_smooth; 72 | GLboolean line_stipple; // TODO: needs to be hooked locally? 73 | GLfloat line_width; 74 | 75 | // GL_LIST_BIT 76 | GLint list_base; 77 | 78 | // GL_MULTISAMPLE_BIT 79 | GLboolean multisample; 80 | GLboolean sample_alpha_to_coverage; 81 | GLboolean sample_alpha_to_one; 82 | GLboolean sample_coverage; 83 | 84 | // GL_POINT_BIT 85 | GLboolean point_smooth; 86 | GLfloat point_size; 87 | 88 | // TODO: GL_POLYGON_BIT 89 | // TODO: GL_POLYGON_STIPPLE_BIT 90 | 91 | // GL_SCISSOR_BIT 92 | GLboolean scissor_test; 93 | GLfloat scissor_box[4]; 94 | 95 | // TODO: GL_STENCIL_BUFFER_BIT 96 | 97 | // GL_TEXTURE_BIT 98 | struct { 99 | GLint bind; 100 | GLboolean enable_2d; 101 | GLint min_filter, mag_filter; 102 | GLint wrap_s, wrap_t; 103 | struct { 104 | GLboolean s, t, r, q; 105 | texgen_state_t state; 106 | } texgen; 107 | } texture[MAX_TEX]; 108 | GLint active_texture; 109 | 110 | // TODO: GL_TRANSFORM_BIT (incomplete) 111 | GLint matrix_mode; 112 | 113 | // TODO: GL_VIEWPORT_BIT 114 | 115 | // dynamically-sized shenanigans 116 | GLboolean *clip_planes_enabled; 117 | GLfloat *clip_planes; 118 | } glstack_t; 119 | 120 | typedef struct { 121 | GLbitfield mask; 122 | 123 | // GL_CLIENT_PIXEL_STORE_BIT 124 | GLint pack_align; 125 | GLint unpack_align; 126 | GLint unpack_row_length; 127 | GLint unpack_skip_pixels; 128 | GLint unpack_skip_rows; 129 | 130 | // GL_CLIENT_VERTEX_ARRAY_BIT 131 | GLboolean vert_enable; 132 | GLboolean color_enable; 133 | GLboolean tex_enable[MAX_TEX]; 134 | GLboolean normal_enable; 135 | pointer_states_t pointers; 136 | } glclientstack_t; 137 | 138 | void glPushClientAttrib(GLbitfield mask); 139 | void glPopClientAttrib(); 140 | void glPushAttrib(GLbitfield mask); 141 | void glPopAttrib(); 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /src/gl/texgen.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "block.h" 3 | 4 | extern void gen_tex_coords(block_t *block, GLuint texture); 5 | -------------------------------------------------------------------------------- /src/gl/texture.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_TEXTURE_H 2 | #define GL_TEXTURE_H 3 | 4 | #include 5 | 6 | void glTexImage2D(GLenum target, GLint level, GLint internalFormat, 7 | GLsizei width, GLsizei height, GLint border, 8 | GLenum format, GLenum type, const GLvoid *data); 9 | 10 | void glTexImage1D(GLenum target, GLint level, GLint internalFormat, 11 | GLsizei width, GLint border, 12 | GLenum format, GLenum type, const GLvoid *data); 13 | 14 | void glTexImage3D(GLenum target, GLint level, GLint internalFormat, 15 | GLsizei width, GLsizei height, GLsizei depth, 16 | GLint border, GLenum format, GLenum type, const GLvoid *data); 17 | 18 | void glBindTexture(GLenum target, GLuint texture); 19 | void glDeleteTextures(GLsizei n, const GLuint * textures); 20 | void glTexParameteri(GLenum target, GLenum pname, GLint param); 21 | GLboolean glAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences); 22 | 23 | void tex_coord_rect_arb(GLfloat *tex, GLsizei len, 24 | GLsizei width, GLsizei height); 25 | void tex_coord_npot(GLfloat *tex, GLsizei len, 26 | GLsizei width, GLsizei height, 27 | GLsizei nwidth, GLsizei nheight); 28 | int npot(int n); 29 | 30 | static inline GLenum map_tex_target(GLenum target) { 31 | switch (target) { 32 | case GL_TEXTURE_1D: 33 | case GL_TEXTURE_3D: 34 | case GL_TEXTURE_RECTANGLE_ARB: 35 | target = GL_TEXTURE_2D; 36 | break; 37 | case GL_PROXY_TEXTURE_1D: 38 | case GL_PROXY_TEXTURE_3D: 39 | target = GL_PROXY_TEXTURE_2D; 40 | break; 41 | } 42 | return target; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/gl/types.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_TYPES_H 2 | #define GL_TYPES_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../config.h" 9 | #include "extypes.h" 10 | #include "khash.h" 11 | #include "tack.h" 12 | #include "wrap/types.h" 13 | #include "../util/mat4.h" 14 | #include "ring.h" 15 | 16 | // block.h 17 | typedef struct { 18 | uint32_t len, count, cap; 19 | GLenum mode; 20 | 21 | GLfloat *vert; 22 | GLfloat *normal; 23 | GLfloat *color; 24 | GLfloat *tex[MAX_TEX]; 25 | GLushort *indices; 26 | GLboolean q2t; 27 | 28 | struct { 29 | int tex[MAX_TEX], color, normal; 30 | } incomplete; 31 | 32 | GLboolean open; 33 | GLboolean artificial; 34 | void *solid; 35 | } block_t; 36 | 37 | typedef struct { 38 | int index; 39 | block_t *block; 40 | } block_call_t; 41 | 42 | // eval.h 43 | typedef struct { 44 | GLenum type; 45 | } map_state_t; 46 | 47 | typedef struct { 48 | GLdouble _1, _2, n, d; 49 | GLint stride, order; 50 | } mapcoordd_t; 51 | 52 | typedef struct { 53 | GLdouble _1, _2, n, d; 54 | GLint stride, order; 55 | } mapcoordf_t; 56 | 57 | typedef struct { 58 | GLenum type; 59 | GLint dims, width; 60 | mapcoordd_t u, v; 61 | GLboolean free; 62 | const GLdouble *points; 63 | } map_stated_t; 64 | 65 | typedef struct { 66 | GLenum type; 67 | GLint dims, width; 68 | mapcoordf_t u, v; 69 | GLboolean free; 70 | const GLfloat *points; 71 | } map_statef_t; 72 | 73 | // list.h 74 | typedef struct { 75 | bool open; 76 | tack_t calls; 77 | tack_t retain; 78 | } displaylist_t; 79 | 80 | // texture.h 81 | typedef struct { 82 | GLuint texture; 83 | GLenum target; 84 | GLsizei width; 85 | GLsizei height; 86 | GLsizei nwidth; 87 | GLsizei nheight; 88 | GLboolean uploaded; 89 | } gltexture_t; 90 | 91 | KHASH_MAP_INIT_INT(tex, gltexture_t *) 92 | 93 | // state.h 94 | typedef struct { 95 | GLboolean line_stipple, 96 | blend, 97 | color_array, 98 | normal_array, 99 | tex_coord_array[MAX_TEX], 100 | texgen_q[MAX_TEX], 101 | texgen_r[MAX_TEX], 102 | texgen_s[MAX_TEX], 103 | texgen_t[MAX_TEX], 104 | texture_2d[MAX_TEX], 105 | vertex_array; 106 | } enable_state_t; 107 | 108 | typedef struct { 109 | GLenum S, T, R, Q; 110 | GLfloat Seye[4], Sobj[4], 111 | Teye[4], Tobj[4], 112 | Reye[4], Robj[4], 113 | Qeye[4], Qobj[4]; 114 | } texgen_state_t; 115 | 116 | typedef struct { 117 | GLuint pack_row_length, 118 | pack_skip_pixels, 119 | pack_skip_rows, 120 | unpack_row_length, 121 | unpack_skip_pixels, 122 | unpack_skip_rows; 123 | GLboolean pack_swap_bytes, 124 | pack_lsb_first, 125 | unpack_swap_bytes, 126 | unpack_lsb_first; 127 | // TODO: do we only need to worry about GL_TEXTURE_2D? 128 | GLboolean rect_arb[MAX_TEX]; 129 | gltexture_t *bound[MAX_TEX]; 130 | khash_t(tex) *list; 131 | // active textures 132 | GLuint active; 133 | GLuint client; 134 | } texture_state_t; 135 | 136 | typedef struct { 137 | GLint size; 138 | GLenum type; 139 | GLsizei stride; 140 | const GLvoid *pointer; 141 | } pointer_state_t; 142 | 143 | typedef struct { 144 | pointer_state_t vertex, color, normal, tex_coord[MAX_TEX]; 145 | } pointer_states_t; 146 | 147 | typedef struct { 148 | GLfloat color[4]; 149 | GLfloat normal[3]; 150 | GLfloat tex[MAX_TEX][4]; 151 | } current_state_t; 152 | 153 | typedef struct { 154 | displaylist_t *active; 155 | current_state_t current; 156 | 157 | GLuint base; 158 | GLuint name; 159 | GLenum mode; 160 | GLuint recursion; 161 | } displaylist_state_t; 162 | 163 | typedef struct { 164 | block_t *active; 165 | GLboolean locked; 166 | } block_state_t; 167 | 168 | typedef struct { 169 | map_state_t *vertex3, 170 | *vertex4, 171 | *index, 172 | *color4, 173 | *normal, 174 | *texture1, 175 | *texture2, 176 | *texture3, 177 | *texture4; 178 | } map_states_t; 179 | 180 | // matrix structs 181 | typedef struct { 182 | mat4 matrix; 183 | tack_t stack; 184 | bool init; 185 | } matrix_state_t; 186 | 187 | typedef struct { 188 | GLenum mode; 189 | matrix_state_t model, projection, texture[MAX_TEX], color; 190 | } matrix_states_t; 191 | 192 | typedef struct { 193 | GLboolean overflow; 194 | GLint count; 195 | GLsizei size; 196 | GLuint *buffer; 197 | tack_t names; 198 | } select_state_t; 199 | 200 | typedef struct { 201 | GLboolean overflow; 202 | GLenum type; 203 | GLfloat *buffer; 204 | GLint count, values; 205 | GLsizei size; 206 | } feedback_state_t; 207 | 208 | typedef struct { 209 | GLenum mode; 210 | } render_state_t; 211 | 212 | typedef struct { 213 | GLubyte *buf; 214 | struct { 215 | GLfloat x, y, z, w; 216 | } pos; 217 | GLfloat color[4]; 218 | GLuint pixel; 219 | GLboolean valid; 220 | } raster_state_t; 221 | 222 | typedef struct { 223 | GLfloat x, y, width, height, nwidth, nheight; 224 | } viewport_state_t; 225 | 226 | typedef struct { 227 | tack_t attrib, client; 228 | } stack_state_t; 229 | 230 | // global state struct 231 | typedef struct { 232 | displaylist_state_t list; 233 | tack_t lists; 234 | int64_t remote; 235 | ring_t *remote_ring; 236 | 237 | GLenum error; 238 | block_state_t block; 239 | current_state_t current; 240 | enable_state_t enable; 241 | feedback_state_t feedback; 242 | map_state_t *map_grid; 243 | map_states_t map1, map2; 244 | matrix_states_t matrix; 245 | pointer_states_t pointers; 246 | raster_state_t raster; 247 | render_state_t render; 248 | select_state_t select; 249 | stack_state_t stack; 250 | texgen_state_t texgen[MAX_TEX]; 251 | texture_state_t texture; 252 | viewport_state_t viewport; 253 | } glstate_t; 254 | 255 | extern glstate_t state; 256 | #define CURRENT (state.list.active ? &state.list.current : &state.current) 257 | 258 | #endif 259 | -------------------------------------------------------------------------------- /src/gl/wrap/extra.h: -------------------------------------------------------------------------------- 1 | #include "../gl.h" 2 | #include 3 | 4 | #ifndef GL_WRAP_H 5 | #define GL_WRAP_H 6 | 7 | #ifdef USE_ES2 8 | void glCompileShaderARB(GLuint shader); 9 | GLuint glCreateShaderObjectARB(GLenum shaderType); 10 | void glGetObjectParameterivARB(GLuint shader, GLenum pname, GLint *params); 11 | void glShaderSourceARB(GLuint shader, GLsizei count, const GLchar **string, const GLint *length); 12 | #endif 13 | 14 | #define THUNK(suffix, type) \ 15 | void glColor3##suffix##v(const type *v); \ 16 | void glColor3##suffix(type r, type g, type b); \ 17 | void glColor4##suffix##v(const type *v); \ 18 | void glColor4##suffix(type r, type g, type b, type a); \ 19 | void glSecondaryColor3##suffix##v(const type *v); \ 20 | void glSecondaryColor3##suffix(type r, type g, type b); \ 21 | void glIndex##suffix##v(const type *c); \ 22 | void glIndex##suffix(type c); \ 23 | void glNormal3##suffix##v(const type *v); \ 24 | void glNormal3##suffix(type x, type y, type z); \ 25 | void glRasterPos2##suffix##v(const type *v); \ 26 | void glRasterPos2##suffix(type x, type y); \ 27 | void glRasterPos3##suffix##v(const type *v); \ 28 | void glRasterPos3##suffix(type x, type y, type z); \ 29 | void glRasterPos4##suffix##v(const type *v); \ 30 | void glRasterPos4##suffix(type x, type y, type z, type w); \ 31 | void glVertex2##suffix##v(const type *v); \ 32 | void glVertex2##suffix(type x, type y); \ 33 | void glVertex3##suffix##v(const type *v); \ 34 | void glVertex3##suffix(type x, type y, type z); \ 35 | void glVertex4##suffix(type x, type y, type z, type w); \ 36 | void glVertex4##suffix##v(const type *v); \ 37 | void glTexCoord1##suffix(type s); \ 38 | void glTexCoord1##suffix##v(const type *t); \ 39 | void glTexCoord2##suffix(type s, type t); \ 40 | void glTexCoord2##suffix##v(const type *t); \ 41 | void glTexCoord3##suffix(type s, type t, type r); \ 42 | void glTexCoord3##suffix##v(const type *t); \ 43 | void glTexCoord4##suffix(type s, type t, type r, type q); \ 44 | void glTexCoord4##suffix##v(const type *t); \ 45 | void glMultiTexCoord1##suffix(GLenum target, type s); \ 46 | void glMultiTexCoord1##suffix##v(GLenum target, const type *v); \ 47 | void glMultiTexCoord2##suffix(GLenum target, type s, type t); \ 48 | void glMultiTexCoord2##suffix##v(GLenum target, const type *v); \ 49 | void glMultiTexCoord3##suffix(GLenum target, type s, type t, type r); \ 50 | void glMultiTexCoord3##suffix##v(GLenum target, const type *v); \ 51 | void glMultiTexCoord4##suffix(GLenum target, type s, type t, type r, type q); \ 52 | void glMultiTexCoord4##suffix##v(GLenum target, const type *v); 53 | 54 | THUNK(b, GLbyte) 55 | THUNK(d, GLdouble) 56 | THUNK(i, GLint) 57 | THUNK(s, GLshort) 58 | THUNK(ub, GLubyte) 59 | THUNK(ui, GLuint) 60 | THUNK(us, GLushort) 61 | #undef THUNK 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/gl/wrap/glstub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stub.h" 3 | 4 | #define STUB(def)\ 5 | def {\ 6 | char *debug = getenv("LIBGL_DEBUG");\ 7 | if (debug && strcmp(debug, "1") == 0)\ 8 | printf("stub: %s;\n", #def);\ 9 | } 10 | 11 | STUB(void glFogCoordd(GLdouble coord)) 12 | STUB(void glFogCoordf(GLfloat coord)) 13 | STUB(void glFogCoorddv(const GLdouble *coord)) 14 | STUB(void glFogCoordfv(const GLfloat *coord)) 15 | #ifdef BCMHOST 16 | STUB(void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments)) 17 | #endif 18 | 19 | #ifdef USE_ES2 20 | STUB(void glClipPlanef(GLenum plane, const GLfloat *equation)); 21 | STUB(void glDisableClientState(GLenum state)); 22 | STUB(void glEnableClientState(GLenum state)); 23 | STUB(void glFogf(GLenum pname, GLfloat param)); 24 | STUB(void glFogfv(GLenum pname, const GLfloat *params)); 25 | STUB(void glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far)); 26 | STUB(void glGetClipPlanef(GLenum plane, GLfloat *equation)); 27 | STUB(void glLightf(GLenum light, GLenum pname, GLfloat param)); 28 | STUB(void glLightfv(GLenum light, GLenum pname, const GLfloat *params)); 29 | STUB(void glLoadIdentity()); 30 | STUB(void glLoadMatrixf(const GLfloat *m)); 31 | STUB(void glMaterialf(GLenum face, GLenum pname, GLfloat param)); 32 | STUB(void glMatrixMode(GLenum mode)); 33 | STUB(void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat r, GLfloat q, GLfloat t)); 34 | STUB(void glMultMatrixf(const GLfloat *m)); 35 | STUB(void glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal)); 36 | STUB(void glPopMatrix()); 37 | STUB(void glPushMatrix()); 38 | STUB(void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)); 39 | STUB(void glScalef(GLfloat x, GLfloat y, GLfloat z)); 40 | STUB(void glTexEnvf(GLenum target, GLenum pname, GLfloat param)); 41 | STUB(void glTexEnvi(GLenum target, GLenum pname, GLint param)); 42 | STUB(void glTranslatef(GLfloat x, GLfloat y, GLfloat z)); 43 | #endif 44 | 45 | // STUB(void glMultiTexCoord()); 46 | // STUB(void glVertexAttrib()); 47 | STUB(void glClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)) 48 | STUB(void glColorMaterial(GLenum face, GLenum mode)) 49 | STUB(void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)) 50 | STUB(void glDrawBuffer(GLenum mode)) 51 | STUB(void glEdgeFlag(GLboolean flag)) 52 | STUB(void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img)) 53 | STUB(void glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params)) 54 | STUB(void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params)) 55 | STUB(void glIndexf(GLfloat c)) 56 | STUB(void glPixelTransferf(GLenum pname, GLfloat param)) 57 | STUB(void glPixelTransferi(GLenum pname, GLint param)) 58 | STUB(void glPixelZoom(GLfloat xfactor, GLfloat yfactor)) 59 | STUB(void glPolygonMode(GLenum face, GLenum mode)) 60 | STUB(void glPolygonStipple(const GLubyte *mask)) 61 | STUB(void glReadBuffer(GLenum mode)) 62 | STUB(void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b)) 63 | 64 | #undef STUB 65 | -------------------------------------------------------------------------------- /src/gl/wrap/glstub.h: -------------------------------------------------------------------------------- 1 | #include "../gl.h" 2 | 3 | GLint glRenderMode(GLenum mode); 4 | void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha); 5 | void glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha); 6 | void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); 7 | void glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); 8 | void glColorMaterial(GLenum face, GLenum mode); 9 | void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); 10 | void glDrawBuffer(GLenum mode); 11 | void glEdgeFlag(GLboolean flag); 12 | void glFogCoordd(GLdouble coord); 13 | void glFogCoorddv(const GLdouble *coord); 14 | void glFogCoordf(GLfloat coord); 15 | void glFogCoordfv(const GLfloat *coord); 16 | void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img); 17 | void glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params); 18 | void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params); 19 | void glIndexf(GLfloat c); 20 | void glInitNames(); 21 | void glLightModeli(GLenum pname, GLint param); 22 | void glLoadName(GLuint name); 23 | void glPixelTransferf(GLenum pname, GLfloat param); 24 | void glPixelTransferi(GLenum pname, GLint param); 25 | void glPixelZoom(GLfloat xfactor, GLfloat yfactor); 26 | void glPolygonMode(GLenum face, GLenum mode); 27 | void glPolygonStipple(const GLubyte *mask); 28 | void glPopName(); 29 | void glPushName(); 30 | void glReadBuffer(GLenum mode); 31 | void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b); 32 | // glSelectBuffer: http://www.lighthouse3d.com/opengl/picking/index.php?color1 33 | void glSelectBuffer(GLsizei size, GLuint *buffer); 34 | -------------------------------------------------------------------------------- /src/gl/wrap/remote.h: -------------------------------------------------------------------------------- 1 | #include "./types.h" 2 | #include "ring.h" 3 | 4 | void remote_local_pre(ring_t *ring, packed_call_t *call); 5 | void remote_local_post(ring_t *ring, packed_call_t *call, void *ret_v, size_t ret_size); 6 | void remote_target_pre(ring_t *ring, packed_call_t *call, size_t size, void *ret); 7 | void remote_target_post(ring_t *ring, packed_call_t *call, void *ret); 8 | -------------------------------------------------------------------------------- /src/gl/wrap/types.h: -------------------------------------------------------------------------------- 1 | #ifndef PACKED_TYPE_H 2 | #define PACKED_TYPE_H 3 | typedef struct { 4 | int index; 5 | void *args; 6 | } packed_call_t; 7 | #endif 8 | -------------------------------------------------------------------------------- /src/glx/gles2funcs.inc: -------------------------------------------------------------------------------- 1 | EX(glActiveTexture); 2 | EX(glAttachShader); 3 | EX(glBindAttribLocation); 4 | EX(glBindBuffer); 5 | EX(glBindFramebuffer); 6 | EX(glBindRenderbuffer); 7 | EX(glBindTexture); 8 | EX(glBlendColor); 9 | EX(glBlendEquation); 10 | EX(glBlendEquationSeparate); 11 | EX(glBlendFunc); 12 | EX(glBlendFuncSeparate); 13 | EX(glBufferData); 14 | EX(glBufferSubData); 15 | EX(glCheckFramebufferStatus); 16 | EX(glClear); 17 | EX(glClearColor); 18 | EX(glClearDepthf); 19 | EX(glClearStencil); 20 | EX(glColorMask); 21 | EX(glCompileShader); 22 | EX(glCompressedTexImage2D); 23 | EX(glCompressedTexSubImage2D); 24 | EX(glCopyTexImage2D); 25 | EX(glCopyTexSubImage2D); 26 | EX(glCreateProgram); 27 | EX(glCreateShader); 28 | EX(glCullFace); 29 | EX(glDeleteBuffers); 30 | EX(glDeleteFramebuffers); 31 | EX(glDeleteProgram); 32 | EX(glDeleteRenderbuffers); 33 | EX(glDeleteShader); 34 | EX(glDeleteTextures); 35 | EX(glDepthFunc); 36 | EX(glDepthMask); 37 | EX(glDepthRangef); 38 | EX(glDetachShader); 39 | EX(glDisable); 40 | EX(glDisableVertexAttribArray); 41 | EX(glDrawArrays); 42 | EX(glDrawElements); 43 | EX(glEnable); 44 | EX(glEnableVertexAttribArray); 45 | EX(glFinish); 46 | EX(glFlush); 47 | EX(glFramebufferRenderbuffer); 48 | EX(glFramebufferTexture2D); 49 | EX(glFrontFace); 50 | EX(glGenBuffers); 51 | EX(glGenFramebuffers); 52 | EX(glGenRenderbuffers); 53 | EX(glGenTextures); 54 | EX(glGenerateMipmap); 55 | EX(glGetActiveAttrib); 56 | EX(glGetActiveUniform); 57 | EX(glGetAttachedShaders); 58 | EX(glGetAttribLocation); 59 | EX(glGetBooleanv); 60 | EX(glGetBufferParameteriv); 61 | EX(glGetError); 62 | EX(glGetFloatv); 63 | EX(glGetFramebufferAttachmentParameteriv); 64 | EX(glGetIntegerv); 65 | EX(glGetProgramInfoLog); 66 | EX(glGetProgramiv); 67 | EX(glGetRenderbufferParameteriv); 68 | EX(glGetShaderInfoLog); 69 | EX(glGetShaderPrecisionFormat); 70 | EX(glGetShaderSource); 71 | EX(glGetShaderiv); 72 | EX(glGetString); 73 | EX(glGetTexParameterfv); 74 | EX(glGetTexParameteriv); 75 | EX(glGetUniformLocation); 76 | EX(glGetUniformfv); 77 | EX(glGetUniformiv); 78 | EX(glGetVertexAttribPointerv); 79 | EX(glGetVertexAttribfv); 80 | EX(glGetVertexAttribiv); 81 | EX(glHint); 82 | EX(glIsBuffer); 83 | EX(glIsEnabled); 84 | EX(glIsFramebuffer); 85 | EX(glIsProgram); 86 | EX(glIsRenderbuffer); 87 | EX(glIsShader); 88 | EX(glIsTexture); 89 | EX(glLineWidth); 90 | EX(glLinkProgram); 91 | EX(glPixelStorei); 92 | EX(glPolygonOffset); 93 | EX(glReadPixels); 94 | EX(glReleaseShaderCompiler); 95 | EX(glRenderbufferStorage); 96 | EX(glSampleCoverage); 97 | EX(glScissor); 98 | EX(glShaderBinary); 99 | EX(glShaderSource); 100 | EX(glStencilFunc); 101 | EX(glStencilFuncSeparate); 102 | EX(glStencilMask); 103 | EX(glStencilMaskSeparate); 104 | EX(glStencilOp); 105 | EX(glStencilOpSeparate); 106 | EX(glTexImage2D); 107 | EX(glTexParameterf); 108 | EX(glTexParameterfv); 109 | EX(glTexParameteri); 110 | EX(glTexParameteriv); 111 | EX(glTexSubImage2D); 112 | EX(glUniform1f); 113 | EX(glUniform1fv); 114 | EX(glUniform1i); 115 | EX(glUniform1iv); 116 | EX(glUniform2f); 117 | EX(glUniform2fv); 118 | EX(glUniform2i); 119 | EX(glUniform2iv); 120 | EX(glUniform3f); 121 | EX(glUniform3fv); 122 | EX(glUniform3i); 123 | EX(glUniform3iv); 124 | EX(glUniform4f); 125 | EX(glUniform4fv); 126 | EX(glUniform4i); 127 | EX(glUniform4iv); 128 | EX(glUniformMatrix2fv); 129 | EX(glUniformMatrix3fv); 130 | EX(glUniformMatrix4fv); 131 | EX(glUseProgram); 132 | EX(glValidateProgram); 133 | EX(glVertexAttrib1f); 134 | EX(glVertexAttrib1fv); 135 | EX(glVertexAttrib2f); 136 | EX(glVertexAttrib2fv); 137 | EX(glVertexAttrib3f); 138 | EX(glVertexAttrib3fv); 139 | EX(glVertexAttrib4f); 140 | EX(glVertexAttrib4fv); 141 | EX(glVertexAttribPointer); 142 | EX(glViewport); 143 | -------------------------------------------------------------------------------- /src/glx/glesfuncs.inc: -------------------------------------------------------------------------------- 1 | EX(glActiveTexture); 2 | EX(glAlphaFunc); 3 | EX(glAlphaFuncx); 4 | EX(glBindBuffer); 5 | EX(glBindTexture); 6 | EX(glBlendColorOES); 7 | EX(glBlendEquationOES); 8 | EX(glBlendEquationSeparateOES); 9 | EX(glBlendFunc); 10 | EX(glBlendFuncSeparateOES); 11 | EX(glBufferData); 12 | EX(glBufferSubData); 13 | EX(glClear); 14 | EX(glClearColor); 15 | EX(glClearColorx); 16 | EX(glClearDepthf); 17 | EX(glClearDepthx); 18 | EX(glClearStencil); 19 | EX(glClientActiveTexture); 20 | EX(glClipPlanef); 21 | EX(glClipPlanex); 22 | EX(glColor4f); 23 | EX(glColor4ub); 24 | EX(glColor4x); 25 | EX(glColorMask); 26 | EX(glColorPointer); 27 | EX(glCompressedTexImage2D); 28 | EX(glCompressedTexSubImage2D); 29 | EX(glCopyTexImage2D); 30 | EX(glCopyTexSubImage2D); 31 | EX(glCullFace); 32 | EX(glDeleteBuffers); 33 | EX(glDeleteTextures); 34 | EX(glDepthFunc); 35 | EX(glDepthMask); 36 | EX(glDepthRangef); 37 | EX(glDepthRangex); 38 | EX(glDisable); 39 | EX(glDisableClientState); 40 | EX(glDrawArrays); 41 | EX(glDrawElements); 42 | EX(glEnable); 43 | EX(glEnableClientState); 44 | EX(glFinish); 45 | EX(glFlush); 46 | EX(glFogf); 47 | EX(glFogfv); 48 | EX(glFogx); 49 | EX(glFogxv); 50 | EX(glFrontFace); 51 | EX(glFrustumf); 52 | EX(glFrustumx); 53 | EX(glGenBuffers); 54 | EX(glGenTextures); 55 | EX(glGetBooleanv); 56 | EX(glGetBufferParameteriv); 57 | EX(glGetClipPlanef); 58 | EX(glGetClipPlanex); 59 | EX(glGetError); 60 | EX(glGetFixedv); 61 | EX(glGetFloatv); 62 | EX(glGetIntegerv); 63 | EX(glGetLightfv); 64 | EX(glGetLightxv); 65 | EX(glGetMaterialfv); 66 | EX(glGetMaterialxv); 67 | EX(glGetPointerv); 68 | EX(glGetString); 69 | EX(glGetTexEnvfv); 70 | EX(glGetTexEnviv); 71 | EX(glGetTexEnvxv); 72 | EX(glGetTexParameterfv); 73 | EX(glGetTexParameteriv); 74 | EX(glGetTexParameterxv); 75 | EX(glHint); 76 | EX(glIsBuffer); 77 | EX(glIsEnabled); 78 | EX(glIsTexture); 79 | EX(glLightModelf); 80 | EX(glLightModelfv); 81 | EX(glLightModelx); 82 | EX(glLightModelxv); 83 | EX(glLightf); 84 | EX(glLightfv); 85 | EX(glLightx); 86 | EX(glLightxv); 87 | EX(glLineWidth); 88 | EX(glLineWidthx); 89 | EX(glLoadIdentity); 90 | EX(glLoadMatrixf); 91 | EX(glLoadMatrixx); 92 | EX(glLogicOp); 93 | EX(glMaterialf); 94 | EX(glMaterialfv); 95 | EX(glMaterialx); 96 | EX(glMaterialxv); 97 | EX(glMatrixMode); 98 | EX(glMultMatrixf); 99 | EX(glMultMatrixx); 100 | EX(glMultiTexCoord4f); 101 | EX(glMultiTexCoord4x); 102 | EX(glNormal3f); 103 | EX(glNormal3x); 104 | EX(glNormalPointer); 105 | EX(glOrthof); 106 | EX(glOrthox); 107 | EX(glPixelStorei); 108 | EX(glPointParameterf); 109 | EX(glPointParameterfv); 110 | EX(glPointParameterx); 111 | EX(glPointParameterxv); 112 | EX(glPointSize); 113 | EX(glPointSizePointerOES); 114 | EX(glPointSizex); 115 | EX(glPolygonOffset); 116 | EX(glPolygonOffsetx); 117 | EX(glPopMatrix); 118 | EX(glPushMatrix); 119 | EX(glReadPixels); 120 | EX(glRotatef); 121 | EX(glRotatex); 122 | EX(glSampleCoverage); 123 | EX(glSampleCoveragex); 124 | EX(glScalef); 125 | EX(glScalex); 126 | EX(glScissor); 127 | EX(glShadeModel); 128 | EX(glStencilFunc); 129 | EX(glStencilMask); 130 | EX(glStencilOp); 131 | EX(glTexCoordPointer); 132 | EX(glTexEnvf); 133 | EX(glTexEnvfv); 134 | EX(glTexEnvi); 135 | EX(glTexEnviv); 136 | EX(glTexEnvx); 137 | EX(glTexEnvxv); 138 | EX(glTexImage2D); 139 | EX(glTexParameterf); 140 | EX(glTexParameterfv); 141 | EX(glTexParameteri); 142 | EX(glTexParameteriv); 143 | EX(glTexParameterx); 144 | EX(glTexParameterxv); 145 | EX(glTexSubImage2D); 146 | EX(glTranslatef); 147 | EX(glTranslatex); 148 | EX(glVertexPointer); 149 | EX(glViewport); 150 | -------------------------------------------------------------------------------- /src/glx/glx.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // defines yoinked from Mesa glx.h 9 | #define GLX_VERSION_1_1 1 10 | #define GLX_VERSION_1_2 1 11 | #define GLX_VERSION_1_3 1 12 | #define GLX_VERSION_1_4 1 13 | 14 | #define GLX_EXTENSION_NAME "GLX" 15 | 16 | /* 17 | * Tokens for glXChooseVisual and glXGetConfig: 18 | */ 19 | #define GLX_USE_GL 1 20 | #define GLX_BUFFER_SIZE 2 21 | #define GLX_LEVEL 3 22 | #define GLX_RGBA 4 23 | #define GLX_DOUBLEBUFFER 5 24 | #define GLX_STEREO 6 25 | #define GLX_AUX_BUFFERS 7 26 | #define GLX_RED_SIZE 8 27 | #define GLX_GREEN_SIZE 9 28 | #define GLX_BLUE_SIZE 10 29 | #define GLX_ALPHA_SIZE 11 30 | #define GLX_DEPTH_SIZE 12 31 | #define GLX_STENCIL_SIZE 13 32 | #define GLX_ACCUM_RED_SIZE 14 33 | #define GLX_ACCUM_GREEN_SIZE 15 34 | #define GLX_ACCUM_BLUE_SIZE 16 35 | #define GLX_ACCUM_ALPHA_SIZE 17 36 | 37 | /* 38 | * Error codes returned by glXGetConfig: 39 | */ 40 | #define GLX_BAD_SCREEN 1 41 | #define GLX_BAD_ATTRIBUTE 2 42 | #define GLX_NO_EXTENSION 3 43 | #define GLX_BAD_VISUAL 4 44 | #define GLX_BAD_CONTEXT 5 45 | #define GLX_BAD_VALUE 6 46 | #define GLX_BAD_ENUM 7 47 | 48 | /* 49 | * GLX 1.1 and later: 50 | */ 51 | #define GLX_VENDOR 1 52 | #define GLX_VERSION 2 53 | #define GLX_EXTENSIONS 3 54 | 55 | /* 56 | * GLX 1.3 and later: 57 | */ 58 | #define GLX_CONFIG_CAVEAT 0x20 59 | #define GLX_DONT_CARE 0xFFFFFFFF 60 | #define GLX_X_VISUAL_TYPE 0x22 61 | #define GLX_TRANSPARENT_TYPE 0x23 62 | #define GLX_TRANSPARENT_INDEX_VALUE 0x24 63 | #define GLX_TRANSPARENT_RED_VALUE 0x25 64 | #define GLX_TRANSPARENT_GREEN_VALUE 0x26 65 | #define GLX_TRANSPARENT_BLUE_VALUE 0x27 66 | #define GLX_TRANSPARENT_ALPHA_VALUE 0x28 67 | #define GLX_WINDOW_BIT 0x00000001 68 | #define GLX_PIXMAP_BIT 0x00000002 69 | #define GLX_PBUFFER_BIT 0x00000004 70 | #define GLX_AUX_BUFFERS_BIT 0x00000010 71 | #define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 72 | #define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 73 | #define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 74 | #define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 75 | #define GLX_DEPTH_BUFFER_BIT 0x00000020 76 | #define GLX_STENCIL_BUFFER_BIT 0x00000040 77 | #define GLX_ACCUM_BUFFER_BIT 0x00000080 78 | #define GLX_NONE 0x8000 79 | #define GLX_SLOW_CONFIG 0x8001 80 | #define GLX_TRUE_COLOR 0x8002 81 | #define GLX_DIRECT_COLOR 0x8003 82 | #define GLX_PSEUDO_COLOR 0x8004 83 | #define GLX_STATIC_COLOR 0x8005 84 | #define GLX_GRAY_SCALE 0x8006 85 | #define GLX_STATIC_GRAY 0x8007 86 | #define GLX_TRANSPARENT_RGB 0x8008 87 | #define GLX_TRANSPARENT_INDEX 0x8009 88 | #define GLX_VISUAL_ID 0x800B 89 | #define GLX_SCREEN 0x800C 90 | #define GLX_NON_CONFORMANT_CONFIG 0x800D 91 | #define GLX_DRAWABLE_TYPE 0x8010 92 | #define GLX_RENDER_TYPE 0x8011 93 | #define GLX_X_RENDERABLE 0x8012 94 | #define GLX_FBCONFIG_ID 0x8013 95 | #define GLX_RGBA_TYPE 0x8014 96 | #define GLX_COLOR_INDEX_TYPE 0x8015 97 | #define GLX_MAX_PBUFFER_WIDTH 0x8016 98 | #define GLX_MAX_PBUFFER_HEIGHT 0x8017 99 | #define GLX_MAX_PBUFFER_PIXELS 0x8018 100 | #define GLX_PRESERVED_CONTENTS 0x801B 101 | #define GLX_LARGEST_PBUFFER 0x801C 102 | #define GLX_WIDTH 0x801D 103 | #define GLX_HEIGHT 0x801E 104 | #define GLX_EVENT_MASK 0x801F 105 | #define GLX_DAMAGED 0x8020 106 | #define GLX_SAVED 0x8021 107 | #define GLX_WINDOW 0x8022 108 | #define GLX_PBUFFER 0x8023 109 | #define GLX_PBUFFER_HEIGHT 0x8040 110 | #define GLX_PBUFFER_WIDTH 0x8041 111 | #define GLX_RGBA_BIT 0x00000001 112 | #define GLX_COLOR_INDEX_BIT 0x00000002 113 | #define GLX_PBUFFER_CLOBBER_MASK 0x08000000 114 | 115 | /* 116 | * GLX 1.4 and later: 117 | */ 118 | #define GLX_SAMPLE_BUFFERS 0x186a0 /*100000*/ 119 | #define GLX_SAMPLES 0x186a1 /*100001*/ 120 | 121 | /* 122 | GLXContext glXCreateContext(Display *dpy, 123 | XVisualInfo *visual, 124 | GLXContext shareList, 125 | Bool direct); 126 | 127 | void glXSwapIntervalEXT(Display *display, int drawable, int interval); 128 | void glXSwapIntervalMESA(int interval); 129 | void glXSwapIntervalSGI(int interval); 130 | 131 | // GLX 1.1? 132 | Bool glXIsDirect(Display * display, GLXContext ctx); 133 | Bool glXMakeCurrent(Display *display, int drawable, GLXContext context); 134 | Bool glXQueryExtension(Display *display, int *errorBase, int *eventBase); 135 | Bool glXQueryVersion(Display *display, int *major, int *minor); 136 | const char *glXGetClientString(Display *display, int name); 137 | const char *glXQueryExtensionsString(Display *display, int screen); 138 | const char *glXQueryServerString(Display *display, int screen, int name); 139 | void glXGetCurrentDrawable(); 140 | void glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixmap pixmap); 141 | int glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value); 142 | void glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask); 143 | void glXDestroyContext(Display *display, GLXContext ctx); 144 | void glXDestroyGLXPixmap(Display *display, void *pixmap); 145 | void glXSwapBuffers(Display *display, int drawable); 146 | void glXUseXFont(Font font, int first, int count, int listBase); 147 | void glXWaitGL(); 148 | void glXWaitX(); 149 | XVisualInfo *glXChooseVisual(Display *display, int screen, int *attributes); 150 | 151 | // GLX 1.2 152 | Display *glXGetCurrentDisplay(); 153 | 154 | // GLX 1.3 155 | GLXContext glXGetCurrentContext(); 156 | XVisualInfo *glXGetVisualFromFBConfig(Display *display, GLXFBConfig config); 157 | GLXFBConfig *glXChooseFBConfig(Display *display, int screen, const int *attrib_list, int *count); 158 | GLXFBConfig *glXGetFBConfigs(Display *display, int screen, int *count); 159 | int glXGetFBConfigAttrib(Display *display, GLXFBConfig config, int attribute, int *value); 160 | 161 | GLXContext glXCreateContextAttribsARB(Display *display, void *config, GLXContext share_context, Bool direct, const int *attrib_list); 162 | */ 163 | -------------------------------------------------------------------------------- /src/preload/preload.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* 9 | SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) { 10 | printf("SDL_WM_GrabInput\n"); 11 | return mode; 12 | } 13 | int SDL_ShowCursor(int toggle) { 14 | printf("SDL_ShowCursor(%i)\n", toggle); 15 | return toggle; 16 | } 17 | void SDL_WarpMouse(Uint16 x, Uint16 y) { 18 | printf("SDL_WM_WarpMouse\n"); 19 | } 20 | int SDL_PollEvent(SDL_Event *event) { 21 | return 0; 22 | } 23 | */ 24 | 25 | int SDL_SetGamma(float r, float g, float b) { 26 | printf("-!- Skipping SDL_SetGamma(%.2f, %.2f, %.2f)\n", r, g, b); 27 | return 0; 28 | } 29 | 30 | static Display *g_display; 31 | static int displayRefs = 0; 32 | typedef Display *(*XOPENDISPLAYPTR)(const char *); 33 | Display *XOpenDisplay(const char *display_name) { 34 | static XOPENDISPLAYPTR real_XOpenDisplay; 35 | if (!real_XOpenDisplay) { 36 | real_XOpenDisplay = (XOPENDISPLAYPTR)dlsym(RTLD_NEXT, "XOpenDisplay"); 37 | } 38 | if (!g_display) { 39 | g_display = real_XOpenDisplay(display_name); 40 | } 41 | displayRefs++; 42 | return g_display; 43 | } 44 | 45 | typedef int (*XCLOSEDISPLAYPTR)(Display *); 46 | int XCloseDisplay(Display *display) { 47 | static XCLOSEDISPLAYPTR real_XCloseDisplay; 48 | if (!real_XCloseDisplay) { 49 | real_XCloseDisplay = (XCLOSEDISPLAYPTR)dlsym(RTLD_NEXT, "XCloseDisplay"); 50 | } 51 | if (g_display == display && displayRefs > 0) { 52 | if (displayRefs-- == 0) { 53 | g_display = NULL; 54 | return real_XCloseDisplay(display); 55 | } 56 | } 57 | return 0; 58 | } 59 | 60 | /* Pandora crashes on mouse events caused by libxi. Workaround by overriding this... */ 61 | int XIQueryVersion(void *display, int *major, int *minor) { 62 | printf("-!- Skipping Xinput(%d, %d) query for display: %p\n", (major?*major:0), (minor?*minor:0), display); 63 | return 1; // BadRequest 64 | } 65 | 66 | /* 67 | typedef int (*XSYNCPTR)(Display *, Bool); 68 | int XSync(Display *display, Bool discard) { 69 | // discard = 1; 70 | 71 | static XSYNCPTR real_XSync; 72 | if (!real_XSync) { 73 | real_XSync = (XSYNCPTR)dlsym(RTLD_NEXT, "XSync"); 74 | } 75 | return real_XSync(display, discard); 76 | } 77 | */ 78 | 79 | // GCW Zero fixes 80 | void *SDL_GL_GetProcAddress(const char *s) { 81 | return glXGetProcAddress(s); 82 | } 83 | 84 | void SDL_GL_SwapBuffers() { 85 | glXSwapBuffers(0, 0); 86 | } 87 | 88 | typedef SDL_Surface *(*SDLSETVIDEOMODEPTR)(int width, int height, int bpp, uint32_t flags); 89 | SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, uint32_t flags) { 90 | bpp = 0; 91 | 92 | static SDLSETVIDEOMODEPTR orig; 93 | if (! orig) 94 | orig = (SDLSETVIDEOMODEPTR)dlsym(RTLD_NEXT, "SDL_SetVideoMode"); 95 | 96 | if (flags & SDL_OPENGL) { 97 | flags &= ~SDL_OPENGL; 98 | glXCreateContext(0, 0, 0, 0); 99 | glXMakeCurrent((void *)1, 1, (void *)1); 100 | } 101 | printf("SDL_SetVideoMode(%d, %d, %d, 0x%x);\n", width, height, bpp, flags); 102 | return orig(width, height, bpp, flags); 103 | } 104 | -------------------------------------------------------------------------------- /src/remote/remote.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gl/remote.h" 4 | 5 | int main(int argc, char **argv) { 6 | if (argc < 2) { 7 | fprintf(stderr, "usage: %s \n", argv[0]); 8 | return 1; 9 | } 10 | if (remote_serve(argv[1]) != 0) { 11 | fprintf(stderr, "Error during remote_serve().\n"); 12 | return 2; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/util/extypes.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_EXTYPES_H 2 | #define GL_EXTYPES_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | // gles 9 | 10 | typedef void *GLDEBUGPROC; 11 | typedef int32_t GLclampx; 12 | typedef int32_t GLfixed; 13 | 14 | // glx + x11 15 | 16 | typedef void *DMbuffer; 17 | typedef void *GLXContextID; 18 | typedef int GLXDrawable; 19 | typedef void *GLXFBConfigSGIX; 20 | typedef void *GLXHyperpipeConfigSGIX; 21 | typedef void *GLXHyperpipeNetworkSGIX; 22 | typedef void *GLXPbuffer; 23 | typedef void *GLXPbufferSGIX; 24 | typedef void *GLXPixmap; 25 | typedef void *GLXVideoCaptureDeviceNV; 26 | typedef void *GLXVideoDeviceNV; 27 | typedef void *GLXVideoSourceSGIX; 28 | typedef void *GLXWindow; 29 | typedef void *VLNode; 30 | typedef void *VLPath; 31 | typedef void *VLServer; 32 | typedef void *__GLXextFuncPtr; 33 | typedef void DMparams; 34 | 35 | struct __GLXContextRec { 36 | Display *display; 37 | unsigned char direct; 38 | int currentWritable; 39 | int currentReadable; 40 | XID xid; 41 | }; 42 | typedef struct __GLXContextRec *GLXContext; 43 | 44 | struct __GLXFBConfigRec { 45 | int visualType; 46 | int transparentType; 47 | /* colors are floats scaled to ints */ 48 | int transparentRed, transparentGreen, transparentBlue, transparentAlpha; 49 | int transparentIndex; 50 | 51 | int visualCaveat; 52 | 53 | int associatedVisualId; 54 | int screen; 55 | 56 | int drawableType; 57 | int renderType; 58 | 59 | int maxPbufferWidth, maxPbufferHeight, maxPbufferPixels; 60 | int optimalPbufferWidth, optimalPbufferHeight; /* for SGIX_pbuffer */ 61 | 62 | int visualSelectGroup; /* visuals grouped by select priority */ 63 | 64 | unsigned int id; 65 | 66 | unsigned char rgbMode; 67 | unsigned char colorIndexMode; 68 | unsigned char doubleBufferMode; 69 | unsigned char stereoMode; 70 | unsigned char haveAccumBuffer; 71 | unsigned char haveDepthBuffer; 72 | unsigned char haveStencilBuffer; 73 | 74 | /* The number of bits present in various buffers */ 75 | int accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits; 76 | int depthBits; 77 | int stencilBits; 78 | int indexBits; 79 | int redBits, greenBits, blueBits, alphaBits; 80 | unsigned int redMask, greenMask, blueMask, alphaMask; 81 | 82 | unsigned int multiSampleSize; /* Number of samples per pixel (0 if no ms) */ 83 | 84 | unsigned int nMultiSampleBuffers; /* Number of availble ms buffers */ 85 | int maxAuxBuffers; 86 | 87 | /* frame buffer level */ 88 | int level; 89 | 90 | /* color ranges (for SGI_color_range) */ 91 | unsigned char extendedRange; 92 | double minRed, maxRed; 93 | double minGreen, maxGreen; 94 | double minBlue, maxBlue; 95 | double minAlpha, maxAlpha; 96 | }; 97 | typedef struct __GLXFBConfigRec *GLXFBConfig; 98 | 99 | // egl 100 | #if !defined(__unix__) && defined(__APPLE__) && defined(__MACH__) 101 | #define __unix__ 102 | #include 103 | #include 104 | #undef __unix__ 105 | #else 106 | #include 107 | #include 108 | #endif 109 | #endif 110 | -------------------------------------------------------------------------------- /src/util/gl_str.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *gl_bits_glPushAttrib(int value); 4 | char *gl_bits_glPushClientAttrib(int value); 5 | char *gl_bits_glCreateShader(int value); 6 | const char *gl_str(int value); 7 | const char *gl_str_glMap(int value); 8 | const char *gl_str_primitive(int value); 9 | -------------------------------------------------------------------------------- /src/util/liveinfo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int liveinfo_send(const char *cmd) { 11 | static int init = 0; 12 | static int sock = 0; 13 | struct sockaddr_un sun = { 14 | .sun_family = AF_UNIX, 15 | .sun_path = "\0liveinfo", 16 | }; 17 | if (! init) { 18 | init = 1; 19 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); 20 | int ret = sendto(sock, cmd, strlen(cmd), 0, (struct sockaddr *)&sun, sizeof(sun)); 21 | fcntl(sock, F_SETFL, O_NONBLOCK); 22 | return ret; 23 | } else if (sock == -1) { 24 | return -1; 25 | } 26 | sendto(sock, cmd, strlen(cmd), 0, (struct sockaddr *)&sun, sizeof(sun)); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/util/liveinfo.h: -------------------------------------------------------------------------------- 1 | int liveinfo_send(const char *cmd); 2 | -------------------------------------------------------------------------------- /src/util/mat4.c: -------------------------------------------------------------------------------- 1 | #include "mat4.h" 2 | 3 | mat4 mat4_new() { 4 | mat4 out; 5 | mat4_identity(&out); 6 | return out; 7 | } 8 | 9 | void mat4_transpose(mat4 *m) { 10 | simd4x4f_transpose_inplace(m); 11 | } 12 | 13 | void mat4_identity(mat4 *m) { 14 | simd4x4f_identity(m); 15 | } 16 | 17 | void mat4_load(mat4 *m, const float *load) { 18 | simd4x4f_uload(m, load); 19 | } 20 | 21 | void mat4_save(mat4 *m, float *out) { 22 | simd4x4f_ustore(m, out); 23 | } 24 | 25 | void mat4_mul(mat4 *m, mat4 *quotient) { 26 | simd4x4f out; 27 | simd4x4f_matrix_mul(m, quotient, &out); 28 | *m = out; 29 | } 30 | 31 | void mat4_rotate(mat4 *m, float angle, float x, float y, float z) { 32 | float radians = angle * VECTORIAL_PI / 180; 33 | simd4x4f rotate; 34 | simd4x4f_axis_rotation(&rotate, radians, simd4f_create(x, y, z, 1.0f)); 35 | mat4_mul(m, &rotate); 36 | } 37 | 38 | void mat4_scale(mat4 *m, float x, float y, float z) { 39 | simd4x4f scale; 40 | simd4x4f_scaling(&scale, x, y, z); 41 | mat4_mul(m, &scale); 42 | } 43 | 44 | void mat4_translate(mat4 *m, float x, float y, float z) { 45 | simd4x4f translate; 46 | simd4x4f_translation(&translate, x, y, z); 47 | mat4_mul(m, &translate); 48 | } 49 | 50 | void mat4_ortho(mat4 *m, float left, float right, 51 | float bottom, float top, 52 | float near, float far) { 53 | simd4x4f ortho; 54 | simd4x4f_ortho(&ortho, left, right, bottom, top, near, far); 55 | mat4_mul(m, &ortho); 56 | } 57 | 58 | void mat4_frustum(mat4 *m, float left, float right, 59 | float bottom, float top, 60 | float near, float far) { 61 | simd4x4f frustum; 62 | simd4x4f_frustum(&frustum, left, right, bottom, top, near, far); 63 | mat4_mul(m, &frustum); 64 | } 65 | 66 | void mat4_perspective(mat4 *m, float fov, float aspect, float znear, float zfar) { 67 | simd4x4f perspective; 68 | simd4x4f_perspective(&perspective, fov, aspect, znear, zfar); 69 | mat4_mul(m, &perspective); 70 | } 71 | 72 | void mat4_mul_vec2(mat4 *m, float out[2], const float in[2]) { 73 | simd4f tmp, vert = simd4f_create(in[0], in[1], 0.0f, 1.0f); 74 | simd4x4f_matrix_vector_mul(m, &vert, &tmp); 75 | tmp = simd4f_div(tmp, simd4f_splat_w(tmp)); 76 | simd4f_ustore2(tmp, out); 77 | } 78 | 79 | void mat4_mul_vec3(mat4 *m, float out[3], const float in[3]) { 80 | simd4f tmp, vert = simd4f_create(in[0], in[1], in[2], 1.0f); 81 | simd4x4f_matrix_vector_mul(m, &vert, &tmp); 82 | tmp = simd4f_div(tmp, simd4f_splat_w(tmp)); 83 | simd4f_ustore3(tmp, out); 84 | } 85 | 86 | void mat4_mul_vec4(mat4 *m, float out[4], const float in[4]) { 87 | simd4f tmp, vert = simd4f_create(in[0], in[1], in[2], in[3]); 88 | simd4x4f_matrix_vector_mul(m, &vert, &tmp); 89 | simd4f_ustore4(tmp, out); 90 | } 91 | -------------------------------------------------------------------------------- /src/util/mat4.h: -------------------------------------------------------------------------------- 1 | #ifndef GPU_MAT4_H 2 | #define GPU_MAT4_H 3 | 4 | #include "vectorial/simd4f.h" 5 | #include "vectorial/simd4x4f.h" 6 | 7 | typedef simd4x4f mat4; 8 | 9 | mat4 mat4_new(); 10 | void mat4_transpose(mat4 *m); 11 | void mat4_identity(mat4 *m); 12 | void mat4_load(mat4 *m, const float *load); 13 | void mat4_save(mat4 *m, float *out); 14 | void mat4_mul(mat4 *m, mat4 *quotient); 15 | void mat4_rotate(mat4 *m, float angle, float x, float y, float z); 16 | void mat4_scale(mat4 *m, float x, float y, float z); 17 | void mat4_translate(mat4 *m, float x, float y, float z); 18 | void mat4_ortho(mat4 *m, float left, float right, float bottom, float top, float near, float far); 19 | void mat4_frustum(mat4 *m, float left, float right, float bottom, float top, float near, float far); 20 | void mat4_perspective(mat4 *m, float fov, float aspect, float znear, float zfar); 21 | void mat4_mul_vec2(mat4 *m, float out[2], const float in[2]); 22 | void mat4_mul_vec3(mat4 *m, float out[3], const float in[3]); 23 | void mat4_mul_vec4(mat4 *m, float out[4], const float in[4]); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/util/math/eval.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Mesa 3-D graphics library 4 | * Version: 3.5 5 | * 6 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a 9 | * copy of this software and associated documentation files (the "Software"), 10 | * to deal in the Software without restriction, including without limitation 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | * and/or sell copies of the Software, and to permit persons to whom the 13 | * Software is furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included 16 | * in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _M_EVAL_H 27 | #define _M_EVAL_H 28 | 29 | #include "../../gl/gl.h" 30 | 31 | void _math_init_eval( void ); 32 | 33 | 34 | /* 35 | * Horner scheme for Bezier curves 36 | * 37 | * Bezier curves can be computed via a Horner scheme. 38 | * Horner is numerically less stable than the de Casteljau 39 | * algorithm, but it is faster. For curves of degree n 40 | * the complexity of Horner is O(n) and de Casteljau is O(n^2). 41 | * Since stability is not important for displaying curve 42 | * points I decided to use the Horner scheme. 43 | * 44 | * A cubic Bezier curve with control points b0, b1, b2, b3 can be 45 | * written as 46 | * 47 | * (([3] [3] ) [3] ) [3] 48 | * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3 49 | * 50 | * [n] 51 | * where s=1-t and the binomial coefficients [i]. These can 52 | * be computed iteratively using the identity: 53 | * 54 | * [n] [n ] [n] 55 | * [i] = (n-i+1)/i * [i-1] and [0] = 1 56 | */ 57 | 58 | 59 | void 60 | _math_horner_bezier_curve(const GLfloat *cp, GLfloat *out, GLfloat t, 61 | GLuint dim, GLuint order); 62 | 63 | 64 | /* 65 | * Tensor product Bezier surfaces 66 | * 67 | * Again the Horner scheme is used to compute a point on a 68 | * TP Bezier surface. First a control polygon for a curve 69 | * on the surface in one parameter direction is computed, 70 | * then the point on the curve for the other parameter 71 | * direction is evaluated. 72 | * 73 | * To store the curve control polygon additional storage 74 | * for max(uorder,vorder) points is needed in the 75 | * control net cn. 76 | */ 77 | 78 | void 79 | _math_horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v, 80 | GLuint dim, GLuint uorder, GLuint vorder); 81 | 82 | 83 | /* 84 | * The direct de Casteljau algorithm is used when a point on the 85 | * surface and the tangent directions spanning the tangent plane 86 | * should be computed (this is needed to compute normals to the 87 | * surface). In this case the de Casteljau algorithm approach is 88 | * nicer because a point and the partial derivatives can be computed 89 | * at the same time. To get the correct tangent length du and dv 90 | * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. 91 | * Since only the directions are needed, this scaling step is omitted. 92 | * 93 | * De Casteljau needs additional storage for uorder*vorder 94 | * values in the control net cn. 95 | */ 96 | 97 | void 98 | _math_de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv, 99 | GLfloat u, GLfloat v, GLuint dim, 100 | GLuint uorder, GLuint vorder); 101 | 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /src/util/ring.h: -------------------------------------------------------------------------------- 1 | #ifndef RING_H 2 | #define RING_H 3 | 4 | #include 5 | 6 | typedef struct { 7 | volatile uint32_t *read, *mark, *write, *wrap; 8 | volatile uint32_t *waiting; 9 | // file descriptor for setup/sync 10 | uint32_t fd; 11 | void *buf; 12 | size_t size; 13 | uint32_t me, *dir; 14 | uint32_t dma_write; 15 | } ring_t; 16 | 17 | typedef struct { 18 | void *buf; 19 | size_t size; 20 | } ring_val_t; 21 | 22 | void ring_wait(ring_t *ring); 23 | void ring_post(ring_t *ring); 24 | void *ring_read(ring_t *ring, size_t *size_ret); 25 | void ring_read_into(ring_t *ring, void *dst); 26 | void ring_advance(ring_t *ring); 27 | int ring_write_multi(ring_t *ring, ring_val_t *vals, int count); 28 | int ring_write(ring_t *ring, void *buf, size_t size); 29 | void *ring_dma(ring_t *ring, size_t size); 30 | void ring_dma_done(ring_t *ring); 31 | void ring_setup(ring_t *ring, int sync_fd); 32 | int ring_server_handshake(ring_t *ring); 33 | int ring_client_handshake(ring_t *ring, char *title); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/util/tack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "tack.h" 8 | 9 | #ifndef MAX 10 | # define MAX(a, b) (((a) > (b)) ? (a) : (b)) 11 | #endif 12 | 13 | #define TACK_DEFAULT_SIZE 8 14 | 15 | static bool tack_pop_bad(tack_t *stack) { 16 | return (stack == NULL || stack->len <= 0); 17 | } 18 | 19 | static bool tack_shift_bad(tack_t *stack) { 20 | return (stack == NULL || stack->pos >= stack->len); 21 | } 22 | 23 | static bool tack_grow(tack_t *stack, int idx) { 24 | if (stack->data == NULL) { 25 | stack->cap = TACK_DEFAULT_SIZE; 26 | stack->data = malloc(sizeof(void *) * stack->cap); 27 | if (stack->data != NULL) { 28 | return true; 29 | } 30 | } else if (MAX(stack->len, idx) >= stack->cap) { 31 | if (stack->cap > INT_MAX >> 1) { 32 | stack->cap = INT_MAX; 33 | if (stack->len == INT_MAX) { 34 | return false; 35 | } 36 | } else { 37 | stack->cap = MAX(stack->cap * 2, stack->len + idx); 38 | } 39 | void **new = realloc(stack->data, sizeof(void *) * stack->cap); 40 | if (new != NULL) { 41 | stack->data = new; 42 | return true; 43 | } 44 | } else { 45 | return true; 46 | } 47 | fprintf(stderr, "warning: tack_grow() to %d failed\n", stack->cap); 48 | return false; 49 | } 50 | 51 | void tack_clear(tack_t *stack) { 52 | free(stack->data); 53 | stack->data = NULL; 54 | stack->cap = 0; 55 | stack->len = 0; 56 | } 57 | 58 | int tack_len(tack_t *stack) { 59 | return stack->len; 60 | } 61 | 62 | void **tack_raw(tack_t *stack) { 63 | return stack->data; 64 | } 65 | 66 | void tack_push(tack_t *stack, void *data) { 67 | if (tack_grow(stack, 0)) { 68 | stack->data[stack->len++] = data; 69 | } 70 | } 71 | 72 | void *tack_pop(tack_t *stack) { 73 | if (tack_pop_bad(stack)) 74 | return NULL; 75 | return stack->data[--stack->len]; 76 | } 77 | 78 | void *tack_peek(tack_t *stack) { 79 | if (tack_pop_bad(stack)) 80 | return NULL; 81 | return stack->data[stack->len - 1]; 82 | } 83 | 84 | void *tack_get(tack_t *stack, int idx) { 85 | if (stack == NULL || idx < 0 || idx >= stack->len) 86 | return NULL; 87 | return stack->data[idx]; 88 | } 89 | 90 | void tack_set(tack_t *stack, int idx, void *data) { 91 | if (tack_grow(stack, idx)) { 92 | int len = MAX(stack->len, idx + 1); 93 | for (int i = stack->len; i < len; i++) { 94 | stack->data[i] = NULL; 95 | } 96 | stack->data[idx] = data; 97 | stack->len = MAX(stack->len, idx + 1); 98 | } 99 | } 100 | 101 | void *tack_cur(tack_t *stack) { 102 | if (tack_shift_bad(stack)) 103 | return NULL; 104 | return stack->data[stack->pos]; 105 | } 106 | 107 | void *tack_shift(tack_t *stack) { 108 | if (tack_shift_bad(stack)) 109 | return NULL; 110 | return stack->data[stack->pos++]; 111 | } 112 | 113 | char *tack_str_join(tack_t *stack, const char *sep) { 114 | if (stack->len == 0) { 115 | return NULL; 116 | } 117 | size_t sep_len = strlen(sep); 118 | size_t len = 0; 119 | char * const*array = (char **)stack->data; 120 | // a length-encoded string library would be really nice here 121 | for (int i = 0; i < stack->len; i++) { 122 | if (array[i] != NULL) { 123 | len += strlen(array[i]); 124 | } 125 | } 126 | len += sep_len * (stack->len - 1); 127 | char *out = malloc(len * sizeof(char) + 1); 128 | out[len] = '\0'; 129 | char *pos = out; 130 | for (int i = 0; i < stack->len; i++) { 131 | if (array[i] != NULL) { 132 | int slen = strlen(array[i]); 133 | memcpy(pos, array[i], slen); 134 | pos += slen; 135 | if (i < stack->len - 1) { 136 | memcpy(pos, sep, sep_len); 137 | pos += sep_len; 138 | } 139 | } 140 | } 141 | return out; 142 | } 143 | 144 | uintptr_t tack_get_int(tack_t *stack, int idx) { 145 | return (uintptr_t)tack_get(stack, idx); 146 | } 147 | 148 | uintptr_t tack_peek_int(tack_t *stack) { 149 | return (uintptr_t)tack_peek(stack); 150 | } 151 | 152 | uintptr_t tack_pop_int(tack_t *stack) { 153 | return (uintptr_t)tack_pop(stack); 154 | } 155 | 156 | void tack_push_int(tack_t *stack, uintptr_t val) { 157 | tack_push(stack, (void *)val); 158 | } 159 | 160 | void tack_set_int(tack_t *stack, int idx, uintptr_t val) { 161 | tack_set(stack, idx, (void *)val); 162 | } 163 | -------------------------------------------------------------------------------- /src/util/tack.h: -------------------------------------------------------------------------------- 1 | #ifndef TACK_H 2 | #define TACK_H 3 | 4 | #include 5 | 6 | typedef struct { 7 | void **data; 8 | int len, cap, pos; 9 | } tack_t; 10 | 11 | extern char *tack_str_join(tack_t *stack, const char *sep); 12 | extern int tack_len(tack_t *stack); 13 | extern void **tack_raw(tack_t *stack); 14 | extern void *tack_cur(tack_t *stack); 15 | extern void *tack_first(tack_t *stack); 16 | extern void *tack_get(tack_t *stack, int idx); 17 | extern void *tack_peek(tack_t *stack); 18 | extern void *tack_pop(tack_t *stack); 19 | extern void *tack_shift(tack_t *stack); 20 | extern void tack_clear(tack_t *stack); 21 | extern void tack_push(tack_t *stack, void *data); 22 | extern void tack_set(tack_t *stack, int idx, void *data); 23 | 24 | extern uintptr_t tack_get_int(tack_t *stack, int idx); 25 | extern uintptr_t tack_peek_int(tack_t *stack); 26 | extern uintptr_t tack_pop_int(tack_t *stack); 27 | extern void tack_push_int(tack_t *stack, uintptr_t val); 28 | extern void tack_set_int(tack_t *stack, int idx, uintptr_t val); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/util/text.h: -------------------------------------------------------------------------------- 1 | void text_draw_glyph(char c); 2 | void text_draw(int x, int y, char *text); 3 | -------------------------------------------------------------------------------- /src/util/vectorial/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 Mikko Lehtonen. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are 4 | permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of 7 | conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 10 | of conditions and the following disclaimer in the documentation and/or other materials 11 | provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /src/util/vectorial/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_CONFIG_H 7 | #define VECTORIAL_CONFIG_H 8 | 9 | 10 | #ifndef VECTORIAL_FORCED 11 | #if defined(__SSE__) || (_M_IX86_FP > 0) || (_M_X64 > 0) 12 | 13 | #define VECTORIAL_SSE 14 | 15 | #elif defined(__ARM_NEON__) 16 | 17 | #define VECTORIAL_NEON 18 | 19 | // Don't use gnu extension for arm, buggy with some gccs with armv6 and -Os, 20 | // Also doesn't seem perform as well 21 | #elif defined(__GNUC__) && !defined(__arm__) 22 | 23 | #define VECTORIAL_GNU 24 | 25 | #else 26 | 27 | #define VECTORIAL_SCALAR 28 | 29 | #endif 30 | #endif 31 | 32 | 33 | 34 | #ifdef VECTORIAL_SCALAR 35 | #define VECTORIAL_SIMD_TYPE "scalar" 36 | #endif 37 | 38 | #ifdef VECTORIAL_SSE 39 | #define VECTORIAL_SIMD_TYPE "sse" 40 | #endif 41 | 42 | #ifdef VECTORIAL_NEON 43 | #define VECTORIAL_SIMD_TYPE "neon" 44 | #endif 45 | 46 | #ifdef VECTORIAL_GNU 47 | #define VECTORIAL_SIMD_TYPE "gnu" 48 | #endif 49 | 50 | 51 | 52 | #if defined(VECTORIAL_FORCED) && !defined(VECTORIAL_SIMD_TYPE) 53 | #error VECTORIAL_FORCED set but no simd-type found, try f.ex. VECTORIAL_SCALAR 54 | #endif 55 | 56 | 57 | #define vectorial_inline static inline 58 | 59 | #if defined(__GNUC__) 60 | #if defined(__cplusplus) 61 | #define vectorial_restrict __restrict 62 | #endif 63 | #define simd4f_aligned16 __attribute__ ((aligned (16))) 64 | #elif defined(_WIN32) 65 | #define vectorial_restrict 66 | #define simd4f_aligned16 __declspec(align(16)) 67 | #else 68 | #define vectorial_restrict restrict 69 | #define simd4f_aligned16 70 | #endif 71 | // #define vectorial_restrict 72 | 73 | #ifdef __GNUC__ 74 | #define vectorial_pure __attribute__((pure)) 75 | #else 76 | #define vectorial_pure 77 | #endif 78 | 79 | #ifdef _WIN32 80 | #if defined(min) || defined(max) 81 | #pragma message ( "set NOMINMAX as preprocessor macro, undefining min/max " ) 82 | #undef min 83 | #undef max 84 | #endif 85 | #endif 86 | 87 | #ifdef __cplusplus 88 | // Hack around msvc badness 89 | #define SIMD_PARAM(t, p) const t& p 90 | #else 91 | #define SIMD_PARAM(t, p) t p 92 | #endif 93 | 94 | #define VECTORIAL_PI 3.14159265f 95 | #define VECTORIAL_HALFPI 1.57079633f 96 | 97 | 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4f.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | 7 | #ifndef VECTORIAL_SIMD4F_H 8 | #define VECTORIAL_SIMD4F_H 9 | 10 | #ifndef VECTORIAL_CONFIG_H 11 | #include "vectorial/config.h" 12 | #endif 13 | 14 | 15 | #ifdef VECTORIAL_SCALAR 16 | #include "simd4f_scalar.h" 17 | #elif defined(VECTORIAL_SSE) 18 | #include "simd4f_sse.h" 19 | #elif defined(VECTORIAL_GNU) 20 | #include "simd4f_gnu.h" 21 | #elif defined(VECTORIAL_NEON) 22 | #include "simd4f_neon.h" 23 | #else 24 | #error No implementation defined 25 | #endif 26 | 27 | #include "simd4f_common.h" 28 | 29 | 30 | 31 | #ifdef __cplusplus 32 | 33 | #ifdef VECTORIAL_OSTREAM 34 | #include 35 | 36 | vectorial_inline std::ostream& operator<<(std::ostream& os, const simd4f& v) { 37 | os << "simd4f(" << simd4f_get_x(v) << ", " 38 | << simd4f_get_y(v) << ", " 39 | << simd4f_get_z(v) << ", " 40 | << simd4f_get_w(v) << ")"; 41 | return os; 42 | } 43 | #endif 44 | 45 | #endif 46 | 47 | 48 | 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4f_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_SIMD4F_COMMON_H 7 | #define VECTORIAL_SIMD4F_COMMON_H 8 | 9 | 10 | vectorial_inline simd4f simd4f_sum(simd4f v) { 11 | const simd4f s1 = simd4f_add(simd4f_splat_x(v), simd4f_splat_y(v)); 12 | const simd4f s2 = simd4f_add(s1, simd4f_splat_z(v)); 13 | const simd4f s3 = simd4f_add(s2, simd4f_splat_w(v)); 14 | return s3; 15 | } 16 | 17 | vectorial_inline simd4f simd4f_dot4(simd4f lhs, simd4f rhs) { 18 | return simd4f_sum( simd4f_mul(lhs, rhs) ); 19 | } 20 | 21 | vectorial_inline simd4f simd4f_dot3(simd4f lhs, simd4f rhs) { 22 | const simd4f m = simd4f_mul(lhs, rhs); 23 | const simd4f s1 = simd4f_add(simd4f_splat_x(m), simd4f_splat_y(m)); 24 | const simd4f s2 = simd4f_add(s1, simd4f_splat_z(m)); 25 | return s2; 26 | } 27 | 28 | vectorial_inline simd4f simd4f_dot2(simd4f lhs, simd4f rhs) { 29 | const simd4f m = simd4f_mul(lhs, rhs); 30 | const simd4f s1 = simd4f_add(simd4f_splat_x(m), simd4f_splat_y(m)); 31 | return s1; 32 | } 33 | 34 | 35 | vectorial_inline simd4f simd4f_length4(simd4f v) { 36 | return simd4f_sqrt( simd4f_dot4(v,v) ); 37 | } 38 | 39 | vectorial_inline simd4f simd4f_length3(simd4f v) { 40 | return simd4f_sqrt( simd4f_dot3(v,v) ); 41 | } 42 | 43 | vectorial_inline simd4f simd4f_length2(simd4f v) { 44 | return simd4f_sqrt( simd4f_dot2(v,v) ); 45 | } 46 | 47 | vectorial_inline simd4f simd4f_length4_squared(simd4f v) { 48 | return simd4f_dot4(v,v); 49 | } 50 | 51 | vectorial_inline simd4f simd4f_length3_squared(simd4f v) { 52 | return simd4f_dot3(v,v); 53 | } 54 | 55 | vectorial_inline simd4f simd4f_length2_squared(simd4f v) { 56 | return simd4f_dot2(v,v); 57 | } 58 | 59 | 60 | vectorial_inline simd4f simd4f_normalize4(simd4f a) { 61 | simd4f invlen = simd4f_rsqrt( simd4f_dot4(a,a) ); 62 | return simd4f_mul(a, invlen); 63 | } 64 | 65 | vectorial_inline simd4f simd4f_normalize3(simd4f a) { 66 | simd4f invlen = simd4f_rsqrt( simd4f_dot3(a,a) ); 67 | return simd4f_mul(a, invlen); 68 | } 69 | 70 | vectorial_inline simd4f simd4f_normalize2(simd4f a) { 71 | simd4f invlen = simd4f_rsqrt( simd4f_dot2(a,a) ); 72 | return simd4f_mul(a, invlen); 73 | } 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4f_scalar.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_SIMD4F_SCALAR_H 7 | #define VECTORIAL_SIMD4F_SCALAR_H 8 | 9 | #include 10 | #include // memcpy 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | 17 | typedef struct { 18 | float x; 19 | float y; 20 | float z; 21 | float w; 22 | } simd4f; 23 | 24 | 25 | 26 | vectorial_inline simd4f simd4f_create(float x, float y, float z, float w) { 27 | simd4f s = { x, y, z, w }; 28 | return s; 29 | } 30 | 31 | vectorial_inline simd4f simd4f_zero() { return simd4f_create(0.0f, 0.0f, 0.0f, 0.0f); } 32 | 33 | vectorial_inline simd4f simd4f_uload4(const float *ary) { 34 | simd4f s = { ary[0], ary[1], ary[2], ary[3] }; 35 | return s; 36 | } 37 | 38 | vectorial_inline simd4f simd4f_uload3(const float *ary) { 39 | simd4f s = { ary[0], ary[1], ary[2], 0 }; 40 | return s; 41 | } 42 | 43 | vectorial_inline simd4f simd4f_uload2(const float *ary) { 44 | simd4f s = { ary[0], ary[1], 0, 0 }; 45 | return s; 46 | } 47 | 48 | 49 | vectorial_inline void simd4f_ustore4(const simd4f val, float *ary) { 50 | memcpy(ary, &val, sizeof(float) * 4); 51 | } 52 | 53 | vectorial_inline void simd4f_ustore3(const simd4f val, float *ary) { 54 | memcpy(ary, &val, sizeof(float) * 3); 55 | } 56 | 57 | vectorial_inline void simd4f_ustore2(const simd4f val, float *ary) { 58 | memcpy(ary, &val, sizeof(float) * 2); 59 | } 60 | 61 | 62 | 63 | // utilities 64 | vectorial_inline simd4f simd4f_splat(float v) { 65 | simd4f s = { v, v, v, v }; 66 | return s; 67 | } 68 | 69 | vectorial_inline simd4f simd4f_splat_x(simd4f v) { 70 | simd4f s = { v.x, v.x, v.x, v.x }; 71 | return s; 72 | } 73 | 74 | vectorial_inline simd4f simd4f_splat_y(simd4f v) { 75 | simd4f s = { v.y, v.y, v.y, v.y }; 76 | return s; 77 | } 78 | 79 | vectorial_inline simd4f simd4f_splat_z(simd4f v) { 80 | simd4f s = { v.z, v.z, v.z, v.z }; 81 | return s; 82 | } 83 | 84 | vectorial_inline simd4f simd4f_splat_w(simd4f v) { 85 | simd4f s = { v.w, v.w, v.w, v.w }; 86 | return s; 87 | } 88 | 89 | vectorial_inline simd4f simd4f_reciprocal(simd4f v) { 90 | simd4f s = { 1.0f/v.x, 1.0f/v.y, 1.0f/v.z, 1.0f/v.w }; 91 | return s; 92 | } 93 | 94 | vectorial_inline simd4f simd4f_sqrt(simd4f v) { 95 | simd4f s = { sqrtf(v.x), sqrtf(v.y), sqrtf(v.z), sqrtf(v.w) }; 96 | return s; 97 | } 98 | 99 | vectorial_inline simd4f simd4f_rsqrt(simd4f v) { 100 | simd4f s = { 1.0f/sqrtf(v.x), 1.0f/sqrtf(v.y), 1.0f/sqrtf(v.z), 1.0f/sqrtf(v.w) }; 101 | return s; 102 | } 103 | 104 | 105 | // arithmetic 106 | 107 | vectorial_inline simd4f simd4f_add(simd4f lhs, simd4f rhs) { 108 | simd4f ret = { lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w }; 109 | return ret; 110 | } 111 | 112 | vectorial_inline simd4f simd4f_sub(simd4f lhs, simd4f rhs) { 113 | simd4f ret = { lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w }; 114 | return ret; 115 | } 116 | 117 | vectorial_inline simd4f simd4f_mul(simd4f lhs, simd4f rhs) { 118 | simd4f ret = { lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z, lhs.w * rhs.w }; 119 | return ret; 120 | } 121 | 122 | vectorial_inline simd4f simd4f_div(simd4f lhs, simd4f rhs) { 123 | simd4f ret = { lhs.x / rhs.x, lhs.y / rhs.y, lhs.z / rhs.z, lhs.w / rhs.w }; 124 | return ret; 125 | } 126 | 127 | vectorial_inline simd4f simd4f_madd(simd4f m1, simd4f m2, simd4f a) { 128 | return simd4f_add( simd4f_mul(m1, m2), a ); 129 | } 130 | 131 | vectorial_inline simd4f simd4f_cross3(simd4f lhs, simd4f rhs) { 132 | return simd4f_create( lhs.y * rhs.z - lhs.z * rhs.y, 133 | lhs.z * rhs.x - lhs.x * rhs.z, 134 | lhs.x * rhs.y - lhs.y * rhs.x, 0); 135 | } 136 | 137 | 138 | vectorial_inline float simd4f_get_x(simd4f s) { return s.x; } 139 | vectorial_inline float simd4f_get_y(simd4f s) { return s.y; } 140 | vectorial_inline float simd4f_get_z(simd4f s) { return s.z; } 141 | vectorial_inline float simd4f_get_w(simd4f s) { return s.w; } 142 | 143 | 144 | vectorial_inline simd4f simd4f_shuffle_wxyz(simd4f s) { return simd4f_create(s.w, s.x, s.y, s.z); } 145 | vectorial_inline simd4f simd4f_shuffle_zwxy(simd4f s) { return simd4f_create(s.z, s.w, s.x, s.y); } 146 | vectorial_inline simd4f simd4f_shuffle_yzwx(simd4f s) { return simd4f_create(s.y, s.z, s.w, s.x); } 147 | 148 | 149 | vectorial_inline simd4f simd4f_zero_w(simd4f s) { 150 | return simd4f_create(s.x, s.y, s.z, 0.0f); 151 | } 152 | 153 | vectorial_inline simd4f simd4f_zero_zw(simd4f s) { 154 | return simd4f_create(s.x, s.y, 0.0f, 0.0f); 155 | } 156 | 157 | 158 | vectorial_inline simd4f simd4f_merge_high(simd4f abcd, simd4f xyzw) { 159 | return simd4f_create(abcd.z, abcd.w, xyzw.z, xyzw.w); 160 | } 161 | 162 | vectorial_inline simd4f simd4f_flip_sign_0101(simd4f s) { 163 | return simd4f_create(s.x, -s.y, s.z, -s.w); 164 | } 165 | 166 | vectorial_inline simd4f simd4f_flip_sign_1010(simd4f s) { 167 | return simd4f_create(-s.x, s.y, -s.z, s.w); 168 | } 169 | 170 | vectorial_inline simd4f simd4f_min(simd4f a, simd4f b) { 171 | return simd4f_create( a.x < b.x ? a.x : b.x, 172 | a.y < b.y ? a.y : b.y, 173 | a.z < b.z ? a.z : b.z, 174 | a.w < b.w ? a.w : b.w ); 175 | } 176 | 177 | vectorial_inline simd4f simd4f_max(simd4f a, simd4f b) { 178 | return simd4f_create( a.x > b.x ? a.x : b.x, 179 | a.y > b.y ? a.y : b.y, 180 | a.z > b.z ? a.z : b.z, 181 | a.w > b.w ? a.w : b.w ); 182 | } 183 | 184 | 185 | #ifdef __cplusplus 186 | } 187 | #endif 188 | 189 | 190 | #endif 191 | 192 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4f_sse.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_SIMD4F_SSE_H 7 | #define VECTORIAL_SIMD4F_SSE_H 8 | 9 | #include 10 | #include // memcpy 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | 17 | typedef __m128 simd4f; 18 | 19 | typedef union { 20 | simd4f s ; 21 | float f[4]; 22 | unsigned int ui[4]; 23 | } _simd4f_union; 24 | 25 | // creating 26 | 27 | vectorial_inline simd4f simd4f_create(float x, float y, float z, float w) { 28 | simd4f s = { x, y, z, w }; 29 | return s; 30 | } 31 | 32 | vectorial_inline simd4f simd4f_zero() { return _mm_setzero_ps(); } 33 | 34 | vectorial_inline simd4f simd4f_uload4(const float *ary) { 35 | simd4f s = _mm_loadu_ps(ary); 36 | return s; 37 | } 38 | 39 | vectorial_inline simd4f simd4f_uload3(const float *ary) { 40 | simd4f s = simd4f_create(ary[0], ary[1], ary[2], 0); 41 | return s; 42 | } 43 | 44 | vectorial_inline simd4f simd4f_uload2(const float *ary) { 45 | simd4f s = simd4f_create(ary[0], ary[1], 0, 0); 46 | return s; 47 | } 48 | 49 | 50 | vectorial_inline void simd4f_ustore4(const simd4f val, float *ary) { 51 | _mm_storeu_ps(ary, val); 52 | } 53 | 54 | vectorial_inline void simd4f_ustore3(const simd4f val, float *ary) { 55 | memcpy(ary, &val, sizeof(float) * 3); 56 | } 57 | 58 | vectorial_inline void simd4f_ustore2(const simd4f val, float *ary) { 59 | memcpy(ary, &val, sizeof(float) * 2); 60 | } 61 | 62 | 63 | // utilites 64 | 65 | vectorial_inline simd4f simd4f_splat(float v) { 66 | simd4f s = _mm_set1_ps(v); 67 | return s; 68 | } 69 | 70 | vectorial_inline simd4f simd4f_splat_x(simd4f v) { 71 | simd4f s = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0,0,0,0)); 72 | return s; 73 | } 74 | 75 | vectorial_inline simd4f simd4f_splat_y(simd4f v) { 76 | simd4f s = _mm_shuffle_ps(v, v, _MM_SHUFFLE(1,1,1,1)); 77 | return s; 78 | } 79 | 80 | vectorial_inline simd4f simd4f_splat_z(simd4f v) { 81 | simd4f s = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2,2,2,2)); 82 | return s; 83 | } 84 | 85 | vectorial_inline simd4f simd4f_splat_w(simd4f v) { 86 | simd4f s = _mm_shuffle_ps(v, v, _MM_SHUFFLE(3,3,3,3)); 87 | return s; 88 | } 89 | 90 | 91 | // arithmetic 92 | 93 | vectorial_inline simd4f simd4f_add(simd4f lhs, simd4f rhs) { 94 | simd4f ret = _mm_add_ps(lhs, rhs); 95 | return ret; 96 | } 97 | 98 | vectorial_inline simd4f simd4f_sub(simd4f lhs, simd4f rhs) { 99 | simd4f ret = _mm_sub_ps(lhs, rhs); 100 | return ret; 101 | } 102 | 103 | vectorial_inline simd4f simd4f_mul(simd4f lhs, simd4f rhs) { 104 | simd4f ret = _mm_mul_ps(lhs, rhs); 105 | return ret; 106 | } 107 | 108 | vectorial_inline simd4f simd4f_div(simd4f lhs, simd4f rhs) { 109 | simd4f ret = _mm_div_ps(lhs, rhs); 110 | return ret; 111 | } 112 | 113 | vectorial_inline simd4f simd4f_madd(simd4f m1, simd4f m2, simd4f a) { 114 | return simd4f_add( simd4f_mul(m1, m2), a ); 115 | } 116 | 117 | 118 | 119 | 120 | vectorial_inline simd4f simd4f_reciprocal(simd4f v) { 121 | simd4f s = _mm_rcp_ps(v); 122 | const simd4f two = simd4f_create(2.0f, 2.0f, 2.0f, 2.0f); 123 | s = simd4f_mul(s, simd4f_sub(two, simd4f_mul(v, s))); 124 | return s; 125 | } 126 | 127 | vectorial_inline simd4f simd4f_sqrt(simd4f v) { 128 | simd4f s = _mm_sqrt_ps(v); 129 | return s; 130 | } 131 | 132 | vectorial_inline simd4f simd4f_rsqrt(simd4f v) { 133 | simd4f s = _mm_rsqrt_ps(v); 134 | const simd4f half = simd4f_create(0.5f, 0.5f, 0.5f, 0.5f); 135 | const simd4f three = simd4f_create(3.0f, 3.0f, 3.0f, 3.0f); 136 | s = simd4f_mul(simd4f_mul(s, half), simd4f_sub(three, simd4f_mul(s, simd4f_mul(v,s)))); 137 | return s; 138 | } 139 | 140 | 141 | 142 | 143 | vectorial_inline simd4f simd4f_cross3(simd4f lhs, simd4f rhs) { 144 | 145 | const simd4f lyzx = _mm_shuffle_ps(lhs, lhs, _MM_SHUFFLE(3,0,2,1)); 146 | const simd4f lzxy = _mm_shuffle_ps(lhs, lhs, _MM_SHUFFLE(3,1,0,2)); 147 | 148 | const simd4f ryzx = _mm_shuffle_ps(rhs, rhs, _MM_SHUFFLE(3,0,2,1)); 149 | const simd4f rzxy = _mm_shuffle_ps(rhs, rhs, _MM_SHUFFLE(3,1,0,2)); 150 | 151 | return _mm_sub_ps(_mm_mul_ps(lyzx, rzxy), _mm_mul_ps(lzxy, ryzx)); 152 | 153 | } 154 | 155 | 156 | 157 | vectorial_inline float simd4f_get_x(simd4f s) { _simd4f_union u={s}; return u.f[0]; } 158 | vectorial_inline float simd4f_get_y(simd4f s) { _simd4f_union u={s}; return u.f[1]; } 159 | vectorial_inline float simd4f_get_z(simd4f s) { _simd4f_union u={s}; return u.f[2]; } 160 | vectorial_inline float simd4f_get_w(simd4f s) { _simd4f_union u={s}; return u.f[3]; } 161 | 162 | 163 | vectorial_inline simd4f simd4f_shuffle_wxyz(simd4f s) { return _mm_shuffle_ps(s,s, _MM_SHUFFLE(2,1,0,3) ); } 164 | vectorial_inline simd4f simd4f_shuffle_zwxy(simd4f s) { return _mm_shuffle_ps(s,s, _MM_SHUFFLE(1,0,3,2) ); } 165 | vectorial_inline simd4f simd4f_shuffle_yzwx(simd4f s) { return _mm_shuffle_ps(s,s, _MM_SHUFFLE(0,3,2,1) ); } 166 | 167 | vectorial_inline simd4f simd4f_zero_w(simd4f s) { 168 | simd4f r = _mm_unpackhi_ps(s, _mm_setzero_ps()); 169 | return _mm_movelh_ps(s, r); 170 | } 171 | 172 | vectorial_inline simd4f simd4f_zero_zw(simd4f s) { 173 | return _mm_movelh_ps(s, _mm_setzero_ps()); 174 | } 175 | 176 | vectorial_inline simd4f simd4f_merge_high(simd4f xyzw, simd4f abcd) { 177 | return _mm_movehl_ps(abcd, xyzw); 178 | } 179 | 180 | 181 | typedef simd4f_aligned16 union { 182 | unsigned int ui[4]; 183 | float f[4]; 184 | } _simd4f_uif; 185 | 186 | vectorial_inline simd4f simd4f_flip_sign_0101(simd4f s) { 187 | const _simd4f_uif upnpn = { { 0x00000000, 0x80000000, 0x00000000, 0x80000000 } }; 188 | return _mm_xor_ps( s, _mm_load_ps(upnpn.f) ); 189 | } 190 | 191 | vectorial_inline simd4f simd4f_flip_sign_1010(simd4f s) { 192 | const _simd4f_uif unpnp = { { 0x80000000, 0x00000000, 0x80000000, 0x00000000 } }; 193 | return _mm_xor_ps( s, _mm_load_ps(unpnp.f) ); 194 | } 195 | 196 | vectorial_inline simd4f simd4f_min(simd4f a, simd4f b) { 197 | return _mm_min_ps( a, b ); 198 | } 199 | 200 | vectorial_inline simd4f simd4f_max(simd4f a, simd4f b) { 201 | return _mm_max_ps( a, b ); 202 | } 203 | 204 | 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | 211 | #endif 212 | 213 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4x4f_gnu.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_SIMD4X4F_GNU_H 7 | #define VECTORIAL_SIMD4X4F_GNU_H 8 | 9 | 10 | 11 | vectorial_inline void simd4x4f_transpose_inplace(simd4x4f* s) { 12 | const _simd4f_union sx = { s->x }; 13 | const _simd4f_union sy = { s->y }; 14 | const _simd4f_union sz = { s->z }; 15 | const _simd4f_union sw = { s->w }; 16 | 17 | const simd4f dx = { sx.f[0], sy.f[0], sz.f[0], sw.f[0] }; 18 | const simd4f dy = { sx.f[1], sy.f[1], sz.f[1], sw.f[1] }; 19 | const simd4f dz = { sx.f[2], sy.f[2], sz.f[2], sw.f[2] }; 20 | const simd4f dw = { sx.f[3], sy.f[3], sz.f[3], sw.f[3] }; 21 | 22 | s->x = dx; 23 | s->y = dy; 24 | s->z = dz; 25 | s->w = dw; 26 | 27 | } 28 | 29 | vectorial_inline void simd4x4f_transpose(const simd4x4f *s, simd4x4f *out) { 30 | *out=*s; 31 | simd4x4f_transpose_inplace(out); 32 | } 33 | 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4x4f_neon.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_SIMD4X4F_NEON_H 7 | #define VECTORIAL_SIMD4X4F_NEON_H 8 | 9 | 10 | vectorial_inline void simd4x4f_transpose_inplace(simd4x4f* s) { 11 | const _simd4f_union sx = { s->x }; 12 | const _simd4f_union sy = { s->y }; 13 | const _simd4f_union sz = { s->z }; 14 | const _simd4f_union sw = { s->w }; 15 | 16 | const simd4f dx = simd4f_create( sx.f[0], sy.f[0], sz.f[0], sw.f[0] ); 17 | const simd4f dy = simd4f_create( sx.f[1], sy.f[1], sz.f[1], sw.f[1] ); 18 | const simd4f dz = simd4f_create( sx.f[2], sy.f[2], sz.f[2], sw.f[2] ); 19 | const simd4f dw = simd4f_create( sx.f[3], sy.f[3], sz.f[3], sw.f[3] ); 20 | 21 | s->x = dx; 22 | s->y = dy; 23 | s->z = dz; 24 | s->w = dw; 25 | 26 | } 27 | 28 | vectorial_inline void simd4x4f_transpose(const simd4x4f *s, simd4x4f *out) { 29 | *out=*s; 30 | simd4x4f_transpose_inplace(out); 31 | } 32 | 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4x4f_scalar.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_SIMD4X4F_SCALAR_H 7 | #define VECTORIAL_SIMD4X4F_SCALAR_H 8 | 9 | 10 | vectorial_inline void simd4x4f_transpose_inplace(simd4x4f *s) { 11 | simd4x4f d=*s; 12 | s->x.x = d.x.x; 13 | s->x.y = d.y.x; 14 | s->x.z = d.z.x; 15 | s->x.w = d.w.x; 16 | 17 | s->y.x = d.x.y; 18 | s->y.y = d.y.y; 19 | s->y.z = d.z.y; 20 | s->y.w = d.w.y; 21 | 22 | s->z.x = d.x.z; 23 | s->z.y = d.y.z; 24 | s->z.z = d.z.z; 25 | s->z.w = d.w.z; 26 | 27 | s->w.x = d.x.w; 28 | s->w.y = d.y.w; 29 | s->w.z = d.z.w; 30 | s->w.w = d.w.w; 31 | 32 | } 33 | 34 | vectorial_inline void simd4x4f_transpose(const simd4x4f *s, simd4x4f *out) { 35 | *out=*s; 36 | simd4x4f_transpose_inplace(out); 37 | } 38 | 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/util/vectorial/simd4x4f_sse.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_SIMD4X4F_SSE_H 7 | #define VECTORIAL_SIMD4X4F_SSE_H 8 | 9 | 10 | 11 | vectorial_inline void simd4x4f_transpose_inplace(simd4x4f *s) { 12 | _MM_TRANSPOSE4_PS(s->x, s->y, s->z, s->w); 13 | } 14 | 15 | vectorial_inline void simd4x4f_transpose(const simd4x4f *s, simd4x4f *out) { 16 | *out=*s; 17 | simd4x4f_transpose_inplace(out); 18 | } 19 | 20 | 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/util/vectorial/vec_convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_VEC_CONVERT_H 7 | #define VECTORIAL_VEC_CONVERT_H 8 | 9 | 10 | namespace vectorial { 11 | 12 | inline vec3f vec4f::xyz() const { return vec3f(value); } 13 | inline vec2f vec4f::xy() const { return vec2f(value); } 14 | 15 | inline vec4f vec3f::xyz0() const { return vec4f(simd4f_zero_w(value)); } 16 | inline vec4f vec3f::xyz1() const { return xyz0() + vec4f(0.0f, 0.0f, 0.0f, 1.0f); } 17 | inline vec4f vec3f::xyzw(float w) const { return xyz0() + vec4f(0.0f, 0.0f, 0.0f, w); } 18 | inline vec3f vec3f::xyz() const { return vec3f(value); } 19 | inline vec3f vec3f::xy0() const { return vec3f(value) * vec3f(1.0f, 1.0f, 0.0f); } 20 | inline vec2f vec3f::xy() const { return vec2f(value); } 21 | 22 | inline vec4f vec2f::xy00() const { return vec4f(simd4f_zero_zw(value)); } 23 | inline vec4f vec2f::xy01() const { return xy00() + vec4f(0.0f, 0.0f, 0.0f, 1.0f); } 24 | inline vec4f vec2f::xyzw(float z, float w) const { return xy00() + vec4f(0.0f, 0.0f, z, w); } 25 | inline vec3f vec2f::xy0() const { return vec3f(simd4f_zero_zw(value)); } 26 | inline vec2f vec2f::xy() const { return vec2f(value); } 27 | 28 | } 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/util/vectorial/vectorial.h: -------------------------------------------------------------------------------- 1 | /* 2 | Vectorial 3 | Copyright (c) 2010 Mikko Lehtonen 4 | Licensed under the terms of the two-clause BSD License (see LICENSE) 5 | */ 6 | #ifndef VECTORIAL_VECTORIAL_H 7 | #define VECTORIAL_VECTORIAL_H 8 | 9 | 10 | #include "vectorial/vec2f.h" 11 | #include "vectorial/vec3f.h" 12 | #include "vectorial/vec4f.h" 13 | 14 | #include "vectorial/vec_convert.h" 15 | 16 | #include "vectorial/mat4f.h" 17 | 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /test/requirements.txt: -------------------------------------------------------------------------------- 1 | Jinja2 2 | blessings 3 | -------------------------------------------------------------------------------- /test/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash -u 2 | 3 | cd $(dirname "$0") 4 | python util/run.py --project="$(pwd)/.." --base "$(pwd)/tests" "$@" 5 | -------------------------------------------------------------------------------- /test/tests/_mat4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../util/mat4.h" 4 | #include "mock.h" 5 | 6 | static int err = 0; 7 | 8 | int fcmp(float *a, float *b, size_t len) { 9 | for (size_t i = 0; i < len; i++) 10 | if (a[i] - b[i] > 0.00001 || b[i] - a[i] > 0.00001) 11 | return 1; 12 | return 0; 13 | } 14 | 15 | void ftest(char *desc, float *a, float *b, size_t len) { 16 | if (fcmp(a, b, len) == 0) { 17 | return; 18 | } 19 | printf("ERROR: Test failed: %s\n", desc); 20 | err = 1; 21 | 22 | for (int i = 0; i < len; i++) { 23 | if (i > 0 && i % 4 == 0) printf("\n"); 24 | if (a[i] - b[i] > 0.00001 || b[i] - a[i] > 0.00001) { 25 | printf(VT100_RED "%.5f " VT100_CLEAR, a[i]); 26 | } else { 27 | printf("%.5f ", a[i]); 28 | } 29 | } 30 | printf("\n"); 31 | for (int i = 0; i < len; i++) { 32 | if (i > 0 && i % 4 == 0) printf("\n"); 33 | if (a[i] - b[i] > 0.00001 || b[i] - a[i] > 0.00001) { 34 | printf(VT100_RED "%.5f, " VT100_CLEAR, b[i]); 35 | } else { 36 | printf("%.5f, ", b[i]); 37 | } 38 | } 39 | printf("\n"); 40 | printf("====================\n"); 41 | } 42 | 43 | void mtest(char *desc, float *m1, mat4 *m42) { 44 | float m2[16] = {0}; 45 | mat4_save(m42, m2); 46 | ftest(desc, m1, m2, 16); 47 | } 48 | 49 | float identity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; 50 | float mat1[] = {2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2}; 51 | float mat1x2[] = {4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4}; 52 | float mat2[] = {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}; 53 | float mat2_transpose[] = {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}; 54 | 55 | float rot1[] = {1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.98481, 0.17365, 0.00000, 0.00000, -0.17365, 0.98481, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000}; 56 | float rot2[] = {0.93969, 0.05939, -0.33682, 0.00000, 0.00000, 0.98481, 0.17365, 0.00000, 0.34202, -0.16318, 0.92542, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000}; 57 | float rot3[] = {0.81380, 0.54384, -0.20487, 0.00000, -0.46985, 0.82317, 0.31880, 0.00000, 0.34202, -0.16318, 0.92542, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000}; 58 | float rot4[] = {0.37561, 0.87653, -0.30101, 0.00000, -0.48151, 0.46209, 0.74473, 0.00000, 0.79188, -0.13478, 0.59562, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000}; 59 | float scale[] = {2.00000, 0.00000, 0.00000, 0.00000, 0.00000, 3.00000, 0.00000, 0.00000, 0.00000, 0.00000, 4.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000}; 60 | float translate[] = {1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 2.00000, 3.00000, 4.00000, 1.00000}; 61 | 62 | float ortho[] = {0.00625, 0.00000, 0.00000, 0.00000, 0.00000, -0.00833, 0.00000, 0.00000, 0.00000, 0.00000, -2.00000, 0.00000, -1.00000, 1.00000, -1.00000, 1.00000}; 63 | float frustum[] = {0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, -1.00000, -1.00000, -1.00000, 0.00000, 0.00000, 0.00000, 0.00000}; 64 | float perspective[] = {0.39689, 0.00000, 0.00000, 0.00000, 0.00000, 0.52919, 0.00000, 0.00000, 0.00000, 0.00000, -1.00200, -1.00000, 0.00000, 0.00000, -2.00200, 0.00000}; 65 | 66 | int main() { 67 | float tmp1[16], tmp2[16]; 68 | 69 | mat4 m = mat4_new(); 70 | mtest("new/identity", identity, &m); 71 | 72 | mat4_identity(&m); 73 | mtest("identity", identity, &m); 74 | 75 | mat4_load(&m, mat1); 76 | mtest("load/save", mat1, &m); 77 | 78 | mat4_load(&m, mat2); 79 | mat4_transpose(&m); 80 | mtest("transpose/1", mat2_transpose, &m); 81 | 82 | mat4_load(&m, mat2_transpose); 83 | mat4_transpose(&m); 84 | mtest("transpose/2", mat2, &m); 85 | 86 | mat4 m2 = mat4_new(); 87 | mat4_load(&m, mat1); 88 | mat4_load(&m2, mat1); 89 | mat4_mul(&m, &m2); 90 | mtest("mul", mat1x2, &m); 91 | 92 | mat4_identity(&m); 93 | mat4_rotate(&m, 10, 1, 0, 0); 94 | mtest("rot/1", rot1, &m); 95 | mat4_rotate(&m, 20, 0, 1, 0); 96 | mtest("rot/2", rot2, &m); 97 | mat4_rotate(&m, 30, 0, 0, 1); 98 | mtest("rot/3", rot3, &m); 99 | mat4_rotate(&m, 40, 1, 1, 1); 100 | mtest("rot/4", rot4, &m); 101 | 102 | mat4_identity(&m); 103 | mat4_scale(&m, 2, 3, 4); 104 | mtest("scale", scale, &m); 105 | 106 | mat4_identity(&m); 107 | mat4_translate(&m, 2, 3, 4); 108 | mtest("translate", translate, &m); 109 | 110 | mat4_identity(&m); 111 | mat4_ortho(&m, 0, 320, 240, 0, 0, 1); 112 | mtest("ortho", ortho, &m); 113 | 114 | mat4_identity(&m); 115 | mat4_frustum(&m, 0, 320, 240, 0, 0, 1); 116 | mtest("frustum", frustum, &m); 117 | 118 | mat4_identity(&m); 119 | mat4_perspective(&m, 65, 320 / 240.0, 1, 1000); 120 | mtest("perspective", perspective, &m); 121 | 122 | float v1[4] = {0}, v2[4] = {0}; 123 | mat4_identity(&m); 124 | mat4_mul_vec2(&m, v1, v2); 125 | ftest("vec2*ident", v1, v2, 4); 126 | mat4_mul_vec3(&m, v1, v2); 127 | ftest("vec3*ident", v1, v2, 4); 128 | mat4_mul_vec4(&m, v1, v2); 129 | ftest("vec4*ident", v1, v2, 4); 130 | 131 | float v3[4] = {1, 2, 3, 1}; 132 | float v3_r[4] = {-2, 1, 3, 1}; 133 | float v3_s[4] = {2, 6, 12, 1}; 134 | float v3_t[4] = {3, 5, 7, 1}; 135 | 136 | float v4[4] = {0}; 137 | 138 | mat4_identity(&m); 139 | mat4_rotate(&m, 90, 0, 0, 1); 140 | mat4_mul_vec4(&m, v4, v3); 141 | ftest("vec/rot", v4, v3_r, 4); 142 | 143 | mat4_identity(&m); 144 | mat4_scale(&m, 2, 3, 4); 145 | mat4_mul_vec4(&m, v4, v3); 146 | ftest("vec/scale", v4, v3_s, 4); 147 | 148 | mat4_identity(&m); 149 | mat4_translate(&m, 2, 3, 4); 150 | mat4_mul_vec4(&m, v4, v3); 151 | ftest("vec/translate", v4, v3_t, 4); 152 | 153 | // TODO perspective mul vec3 to show window coord? 154 | 155 | return err; 156 | } 157 | -------------------------------------------------------------------------------- /test/tests/array/skip.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | #define STRIDE 0, 0, 0, 0, 0, 0, 0, 0, 0 3 | GLfloat vert[] = { 4 | 0, 0, 0, STRIDE, 5 | 1, 1, 1, STRIDE, 6 | 2, 2, 2, STRIDE, 7 | 3, 3, 3, STRIDE, 8 | 4, 4, 4, STRIDE, 9 | 5, 5, 5, STRIDE, 10 | }; 11 | glEnableClientState(GL_VERTEX_ARRAY); 12 | glVertexPointer(3, GL_FLOAT, 12 * sizeof(GLfloat), vert); 13 | glDrawArrays(GL_QUADS, 2, 4); 14 | 15 | GLfloat vert_out[] = { 16 | 2, 2, 2, 17 | 3, 3, 3, 18 | 4, 4, 4, 19 | 5, 5, 5, 20 | }; 21 | GLushort indices[] = {0, 1, 3, 1, 2, 3}; 22 | test_glEnableClientState(GL_VERTEX_ARRAY); 23 | test_glVertexPointer(3, GL_FLOAT, 12 * 4, vert); 24 | test_glVertexPointer(3, GL_FLOAT, 0, vert_out); 25 | test_glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); 26 | mock_return; 27 | } 28 | -------------------------------------------------------------------------------- /test/tests/block/incomplete.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | GLfloat c1 = 0.1, c2 = 0.2; 3 | GLuint list = glGenLists(1); 4 | 5 | glNewList(list, GL_COMPILE); 6 | glColor3f(c1, c1, c1); 7 | glBegin(GL_LINES); 8 | glVertex3f(1, 1, 0); 9 | glVertex3f(-1, 1, 0); 10 | glColor3f(c2, c2, c2); 11 | glVertex3f(1, 1, 0); 12 | glVertex3f(-1, 1, 0); 13 | glEnd(); 14 | glEndList(); 15 | glCallList(list); 16 | 17 | GLfloat verts[] = { 18 | 1, 1, 0, 19 | -1, 1, 0, 20 | 1, 1, 0, 21 | -1, 1, 0, 22 | }; 23 | GLfloat colors[] = { 24 | c1, c1, c1, 1.0, 25 | c1, c1, c1, 1.0, 26 | c2, c2, c2, 1.0, 27 | c2, c2, c2, 1.0, 28 | }; 29 | 30 | test_glColor4f(c1, c1, c1, 1.0); 31 | test_glEnableClientState(GL_VERTEX_ARRAY); 32 | test_glVertexPointer(3, GL_FLOAT, 0, verts); 33 | test_glEnableClientState(GL_COLOR_ARRAY); 34 | test_glColorPointer(4, GL_FLOAT, 0, colors); 35 | test_glDrawArrays(GL_LINES, 0, 4); 36 | test_glDisableClientState(GL_VERTEX_ARRAY); 37 | test_glDisableClientState(GL_COLOR_ARRAY); 38 | test_glColor4f(c2, c2, c2, 1.0); 39 | 40 | mock_return; 41 | } 42 | -------------------------------------------------------------------------------- /test/tests/block/quads.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | glBegin(GL_QUADS); 3 | glColor4f(0, 0.1, 0.2, 0.3); 4 | glTexCoord2f(0.4, 0.5); 5 | glVertex3f(0, 1, 2); 6 | glVertex3f(3, 4, 5); 7 | glVertex3f(6, 7, 8); 8 | glVertex3f(9, 10, 11); 9 | glEnd(); 10 | 11 | GLfloat verts[] = { 12 | 0, 1, 2, 13 | 3, 4, 5, 14 | 6, 7, 8, 15 | 9, 10, 11, 16 | }; 17 | 18 | GLfloat color[] = { 19 | 0, 0.1, 0.2, 0.3, 20 | 0, 0.1, 0.2, 0.3, 21 | 0, 0.1, 0.2, 0.3, 22 | 0, 0.1, 0.2, 0.3, 23 | }; 24 | 25 | GLfloat tex[] = { 26 | 0.4, 0.5, 0, 1, 27 | 0.4, 0.5, 0, 1, 28 | 0.4, 0.5, 0, 1, 29 | 0.4, 0.5, 0, 1, 30 | }; 31 | 32 | GLushort indices[] = { 33 | 0, 1, 3, 34 | 1, 2, 3, 35 | }; 36 | 37 | // TODO: out of order glEnableClientState? 38 | test_glColor4f(0.0, 0.1, 0.2, 0.3); 39 | 40 | test_glEnableClientState(GL_VERTEX_ARRAY); 41 | test_glVertexPointer(3, GL_FLOAT, 0, verts); 42 | test_glEnableClientState(GL_COLOR_ARRAY); 43 | test_glColorPointer(4, GL_FLOAT, 0, color); 44 | test_glEnableClientState(GL_TEXTURE_COORD_ARRAY); 45 | test_glTexCoordPointer(4, GL_FLOAT, 0, tex); 46 | test_glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); 47 | 48 | test_glDisableClientState(GL_VERTEX_ARRAY); 49 | test_glDisableClientState(GL_COLOR_ARRAY); 50 | test_glDisableClientState(GL_TEXTURE_COORD_ARRAY); 51 | mock_return; 52 | } 53 | -------------------------------------------------------------------------------- /test/tests/block/rect.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | for (int i = 0; i < 3; i++) { 3 | glRectf(0, 0, 1, 1); 4 | 5 | test_glEnableClientState(GL_VERTEX_ARRAY); 6 | GLfloat verts[] = { 7 | 0, 0, 0, 8 | 1, 0, 0, 9 | 1, 1, 0, 10 | 0, 1, 0, 11 | }; 12 | test_glVertexPointer(3, GL_FLOAT, 0, verts); 13 | test_glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 14 | test_glDisableClientState(GL_VERTEX_ARRAY); 15 | } 16 | mock_return; 17 | } 18 | -------------------------------------------------------------------------------- /test/tests/block/tri.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | glBegin(GL_TRIANGLES); 3 | glVertex3f(0, 1, 2); 4 | glVertex3f(3, 4, 5); 5 | glVertex3f(6, 7, 8); 6 | glEnd(); 7 | 8 | test_glEnableClientState(GL_VERTEX_ARRAY); 9 | GLfloat verts[] = { 10 | 0, 1, 2, 11 | 3, 4, 5, 12 | 6, 7, 8, 13 | }; 14 | test_glVertexPointer(3, GL_FLOAT, 0, verts); 15 | test_glDrawArrays(GL_TRIANGLES, 0, 3); 16 | test_glDisableClientState(GL_VERTEX_ARRAY); 17 | mock_return; 18 | } 19 | -------------------------------------------------------------------------------- /test/tests/get.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | char b; 3 | int i; 4 | float f; 5 | glGetBooleanv(GL_MAX_ELEMENTS_INDICES, &b); 6 | glGetFloatv(GL_MAX_ELEMENTS_INDICES, &f); 7 | glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &i); 8 | assert(f == i); 9 | assert(b == !!i); 10 | mock_return; 11 | } 12 | -------------------------------------------------------------------------------- /test/tests/list/nested.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | GLuint list = glGenLists(3); 3 | glNewList(list, GL_COMPILE); 4 | glRectf(0, 0, 1, 1); 5 | glEndList(); 6 | 7 | glNewList(list + 1, GL_COMPILE); 8 | glCallList(list); 9 | glEndList(); 10 | 11 | glNewList(list + 2, GL_COMPILE); 12 | glCallList(list + 1); 13 | glEndList(); 14 | 15 | glCallList(list + 2); 16 | 17 | GLfloat verts[] = { 18 | 0, 0, 0, 19 | 1, 0, 0, 20 | 1, 1, 0, 21 | 0, 1, 0, 22 | }; 23 | 24 | test_glEnableClientState(GL_VERTEX_ARRAY); 25 | test_glVertexPointer(3, GL_FLOAT, 0, verts); 26 | test_glDrawArrays(6, 0, 4); 27 | test_glDisableClientState(GL_VERTEX_ARRAY); 28 | 29 | mock_return; 30 | } 31 | -------------------------------------------------------------------------------- /test/tests/list/new.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int list = glGenLists(1); 3 | glNewList(list, GL_COMPILE); 4 | mock_assert(state.list.active, "glNewList failed\n"); 5 | mock_return; 6 | } 7 | -------------------------------------------------------------------------------- /test/tests/list/retain.c: -------------------------------------------------------------------------------- 1 | #define clobber(x) do { unsigned char *tmp = (unsigned char *)x; for (int i = 0; i < sizeof(x); i++) tmp[i] = (unsigned char)(i + 1); } while(0); 2 | 3 | int main() { 4 | // tex 5 | GLubyte tex1[] = {255, 255, 255, 255}; 6 | GLubyte tex2[] = {255, 255, 255, 255}; 7 | // mat 8 | GLfloat mat1[] = { 9 | 1, 1, 1, 1, 10 | 2, 2, 2, 2, 11 | 3, 3, 3, 3, 12 | 4, 4, 4, 4, 13 | }; 14 | GLfloat mat2[16]; memcpy(mat2, mat1, sizeof(mat1)); 15 | GLfloat mat_transpose[] = { 16 | 1, 2, 3, 4, 17 | 1, 2, 3, 4, 18 | 1, 2, 3, 4, 19 | 1, 2, 3, 4, 20 | }; 21 | 22 | int list = glGenLists(1); 23 | glNewList(list, GL_COMPILE); 24 | 25 | // tex 26 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex1); 27 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, tex1); 28 | 29 | // mat 30 | glLoadMatrixf(mat1); 31 | glLoadTransposeMatrixf(mat1); 32 | glLoadIdentity(); 33 | glMultMatrixf(mat1); 34 | glLoadIdentity(); 35 | glMultTransposeMatrixf(mat1); 36 | 37 | glEndList(); 38 | 39 | clobber(tex1); 40 | clobber(mat1); 41 | 42 | glCallList(list); 43 | 44 | // tex 45 | test_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex2); 46 | test_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, tex2); 47 | 48 | // mat 49 | test_glLoadMatrixf(mat2); 50 | test_glLoadMatrixf(mat_transpose); 51 | test_glLoadIdentity(); 52 | test_glLoadMatrixf(mat_transpose); // TODO likely a bug 53 | test_glLoadIdentity(); 54 | test_glLoadMatrixf(mat_transpose); 55 | 56 | mock_return; 57 | } 58 | -------------------------------------------------------------------------------- /test/tests/meta/test.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | def walk(base): 5 | for root, _, files in os.walk(base): 6 | for name in files: 7 | yield os.path.join(root, name) 8 | 9 | if __name__ == '__main__': 10 | failed = False 11 | for name in walk('tests'): 12 | if name.endswith('.c'): 13 | if os.path.basename(name).startswith('_'): 14 | continue 15 | with open(name, 'r') as f: 16 | data = f.read() 17 | if not 'mock_return;' in data: 18 | print 'ERROR: "{}" has no mock_return;'.format(name) 19 | failed = True 20 | 21 | if failed: 22 | sys.exit(1) 23 | -------------------------------------------------------------------------------- /test/tests/raster/raster.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define P(n) n, n, n, n 7 | #define P8(a, b, c, d, e, f, g, h) P(a), P(b), P(c), P(d), P(e), P(f), P(g), P(h) 8 | 9 | const unsigned char sprite[] = { 10 | P(0), P(1), P(2), P(3), 11 | P(0), P(1), P(2), P(3), 12 | P(0), P(1), P(2), P(3), 13 | P(0), P(1), P(2), P(3), 14 | P(4), P(5), P(6), P(7), 15 | P(4), P(5), P(6), P(7), 16 | P(4), P(5), P(6), P(7), 17 | P(4), P(5), P(6), P(7), 18 | }; 19 | 20 | const uint16_t bitmap[] = { 21 | 0x0008, 0x0007, 0x0006, 0x0005, 0x0004, 0x0003, 0x0002, 0x0001, 22 | }; 23 | 24 | const unsigned char bitmap_ref[] = { 25 | P8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF), 26 | P8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00), 27 | P8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF), 28 | P8(0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00), 29 | P8(0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF), 30 | P8(0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00), 31 | P8(0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF), 32 | P8(0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00), 33 | }; 34 | 35 | void set_pos(int x, int y) { 36 | if (x < 0 || y < 0) { 37 | glWindowPos2i(0, 0); 38 | glBitmap(0, 0, 0, 0, x, y, NULL); 39 | } else { 40 | glWindowPos2i(x, y); 41 | } 42 | } 43 | 44 | int main() { 45 | int width = 8; 46 | int height = 8; 47 | size_t bufsize = 4 * width * height * sizeof(GLubyte); 48 | GLubyte *buf = (GLubyte *)malloc(bufsize * 3); 49 | 50 | glViewport(0, 0, width, height); 51 | test_glViewport(0, 0, width, height); 52 | state.raster.buf = buf + bufsize; 53 | 54 | // test for normal operation 55 | memset(buf, 0xFF, bufsize * 3); 56 | glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, sprite); 57 | assert(memcmp(buf, buf + bufsize * 2, bufsize) == 0); 58 | assert(memcmp(state.raster.buf, sprite, bufsize) == 0); 59 | 60 | memset(buf, 0, bufsize * 3); 61 | glWindowPos2i(0, height - 1); 62 | glBitmap(width, height, 0, 0, 0, 0, bitmap); 63 | assert(memcmp(buf, buf + bufsize * 2, bufsize) == 0); 64 | assert(memcmp(state.raster.buf, bitmap_ref, bufsize) == 0); 65 | 66 | // test for over/underrun 67 | for (int x = -width; x < width; x++) { 68 | for (int y = -height; y < height; y++) { 69 | memset(buf, 0, bufsize * 3); 70 | set_pos(x, y); 71 | glBitmap(width, height, 0, 0, 0, 0, bitmap); 72 | assert(memcmp(buf, buf + bufsize * 2, bufsize) == 0 && "glBitmap"); 73 | } 74 | } 75 | for (int x = 0; x < width; x++) { 76 | for (int y = 0; y < height; y++) { 77 | memset(buf, 0, bufsize * 3); 78 | set_pos(x, y); 79 | glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, sprite); 80 | assert(memcmp(buf, buf + bufsize * 2, bufsize) == 0 && "glDrawPixels"); 81 | } 82 | } 83 | mock_return; 84 | } 85 | -------------------------------------------------------------------------------- /test/tests/remote/_race.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "remote.h" 8 | #include "wrap/glpack.h" 9 | #include "types.h" 10 | #include "ring.h" 11 | 12 | #define RACE_COUNT 100000 13 | 14 | int main(int argc, char **argv) { 15 | if (argc == 1) { 16 | signal(SIGCHLD, SIG_IGN); 17 | int pid = remote_spawn(argv[0]); 18 | if (pid < 1) { 19 | fprintf(stderr, "failed to spawn remote\n"); 20 | return 1; 21 | } 22 | state.remote = 1; 23 | for (int i = 0; i < RACE_COUNT; i++) { 24 | glRectf(0, 0, 1, 1); 25 | } 26 | int status = 0; 27 | waitpid(pid, &status, 0); 28 | if (WEXITSTATUS(status) || WTERMSIG(status)) { 29 | fprintf(stderr, "Error from libgl_remote: %d\n", status); 30 | return 1; 31 | } 32 | } else { 33 | ring_t _ring = {0}; 34 | ring_t *ring = &_ring; 35 | ring_setup(ring, strtol(argv[1]+1, NULL, 10)); 36 | if (ring_server_handshake(ring)) { 37 | fprintf(stderr, "Error doing server handshake\n"); 38 | return 2; 39 | } 40 | for (int i = 0; i < RACE_COUNT - 1; i++) { 41 | // fprintf(stderr, "remote %d\n", i); 42 | // fprintf(stderr, "reading retsize\n"); 43 | void *buf = ring_read(ring, NULL); 44 | uint32_t retsize = *(uint32_t *)buf; 45 | // fprintf(stderr, "retsize=%d\n", retsize); 46 | if (retsize != 0) { 47 | unsigned char *c = buf; 48 | fprintf(stderr, "ERROR: Expected retsize=0. Got: %d\n", retsize); 49 | fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); 50 | kill(getppid(), SIGTERM); 51 | return 1; 52 | } 53 | // fprintf(stderr, "reading call\n"); 54 | packed_call_t *call = buf + sizeof(uint32_t); 55 | unsigned char *c = call; 56 | // fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x %d\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], call->index); 57 | 58 | if (call->index != REMOTE_BLOCK_DRAW) { 59 | fprintf(stderr, "ERROR: Expected REMOTE_BLOCK_DRAW. Got: %d\n", call->index); 60 | fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x %d\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], call->index); 61 | kill(getppid(), SIGTERM); 62 | return 1; 63 | } 64 | block_t *block = remote_read_block(ring, (void *)call); 65 | // fprintf(stderr, "block->len: %d\n", block->len); 66 | if (block->len != 4) { 67 | fprintf(stderr, "ERROR: Expected block->len == 4, got: %d\n", block->len); 68 | fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x %d\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], call->index); 69 | kill(getppid(), SIGTERM); 70 | return 1; 71 | } 72 | ring_advance(ring); 73 | } 74 | } 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /test/tests/remote/_ring.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "ring.h" 8 | #include "remote.h" 9 | 10 | int main(int argc, char **argv) { 11 | if (argc == 1) { 12 | signal(SIGCHLD, SIG_IGN); 13 | int pid = remote_spawn(argv[0]); 14 | if (pid < 1) { 15 | fprintf(stderr, "failed to spawn remote\n"); 16 | return 1; 17 | } 18 | ring_t *ring = state.remote_ring; 19 | for (int i = 0; i < 100000; i++) { 20 | uint32_t n = 42; 21 | ring_write(ring, &n, sizeof(uint32_t)); 22 | uint32_t *resp = (uint32_t *)ring_read(ring, NULL); 23 | if (*resp != 43) { 24 | fprintf(stderr, "Bad response from server: %d != 43\n", *resp); 25 | return 1; 26 | } 27 | ring_advance(ring); 28 | } 29 | int status = 0; 30 | waitpid(pid, &status, 0); 31 | if (WEXITSTATUS(status)) { 32 | fprintf(stderr, "Error from libgl_remote.\n"); 33 | return 1; 34 | } 35 | } else { 36 | ring_t _ring = {0}; 37 | ring_t *ring = &_ring; 38 | ring_setup(ring, strtol(argv[1]+1, NULL, 10)); 39 | if (ring_server_handshake(ring)) { 40 | fprintf(stderr, "Error doing server handshake\n", argv[1]); 41 | kill(getppid(), SIGTERM); 42 | return 2; 43 | } 44 | for (int i = 0; i < 100000; i++) { 45 | uint32_t *q = (uint32_t *)ring_read(ring, NULL); 46 | if (*q != 42) { 47 | fprintf(stderr, "Bad query from client: %d != 42\n", *q); 48 | kill(getppid(), SIGTERM); 49 | return 1; 50 | } 51 | uint32_t n = *q + 1; 52 | ring_advance(ring); 53 | ring_write(ring, &n, sizeof(uint32_t)); 54 | } 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /test/tests/remote/_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "remote.h" 8 | #include "wrap/glpack.h" 9 | #include "types.h" 10 | #include "ring.h" 11 | 12 | int main(int argc, char **argv) { 13 | if (argc == 1) { 14 | signal(SIGCHLD, SIG_IGN); 15 | int pid = remote_spawn(argv[0]); 16 | if (pid < 0) { 17 | fprintf(stderr, "Error spawning remote.\n"); 18 | return 1; 19 | } 20 | state.remote = 1; 21 | assert(strstr(glGetString(GL_VERSION), "glshim")); 22 | kill(pid, SIGTERM); 23 | } else { 24 | if (remote_serve(argv[1])) { 25 | fprintf(stderr, "Error mapping shared memory: %s\n", argv[1]); 26 | return 2; 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /test/tests/remote/_thread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "remote.h" 12 | #include "wrap/glpack.h" 13 | #include "types.h" 14 | #include "ring.h" 15 | 16 | #define RACE_COUNT 1000000 17 | 18 | pthread_mutex_t thread_join = PTHREAD_MUTEX_INITIALIZER; 19 | 20 | typedef struct { 21 | int sync_fd; 22 | } remote_args; 23 | 24 | void *remote_process(remote_args *args) { 25 | pthread_mutex_lock(&thread_join); 26 | ring_t _ring = {0}; 27 | ring_t *ring = &_ring; 28 | int fd = accept(args->sync_fd, NULL, 0); 29 | ring_setup(ring, fd); 30 | if (ring_server_handshake(ring)) { 31 | fprintf(stderr, "Error doing server handshake.\n"); 32 | goto error; 33 | } 34 | for (int i = 0; i < RACE_COUNT - 1; i++) { 35 | // fprintf(stderr, "remote %d\n", i); 36 | // fprintf(stderr, "reading retsize\n"); 37 | void *buf = ring_read(ring, NULL); 38 | uint32_t retsize = *(uint32_t *)buf; 39 | // fprintf(stderr, "retsize=%d\n", retsize); 40 | if (retsize != 0) { 41 | unsigned char *c = buf; 42 | fprintf(stderr, "ERROR: Expected retsize=0. Got: %d\n", retsize); 43 | fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); 44 | kill(getppid(), SIGTERM); 45 | return 1; 46 | } 47 | // fprintf(stderr, "reading call\n"); 48 | packed_call_t *call = buf + sizeof(uint32_t); 49 | unsigned char *c = call; 50 | // fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x %d\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], call->index); 51 | 52 | if (call->index != REMOTE_BLOCK_DRAW) { 53 | fprintf(stderr, "ERROR: Expected REMOTE_BLOCK_DRAW. Got: %d\n", call->index); 54 | fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x %d\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], call->index); 55 | kill(getppid(), SIGTERM); 56 | goto error; 57 | } 58 | block_t *block = remote_read_block(ring, (void *)call); 59 | // fprintf(stderr, "block->len: %d\n", block->len); 60 | if (block->len != 4) { 61 | fprintf(stderr, "ERROR: Expected block->len == 4, got: %d\n", block->len); 62 | fprintf(stderr, "read=%d, mark=%d, call=%d, write=%d, %02X%02X %02X%02X %02x%02x %02x%02x %d\n", *ring->read, *ring->mark, (uintptr_t)c - (uintptr_t)ring->buf, *ring->write, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], call->index); 63 | kill(getppid(), SIGTERM); 64 | goto error; 65 | } 66 | ring_advance(ring); 67 | } 68 | pthread_mutex_unlock(&thread_join); 69 | return 0; 70 | error: 71 | pthread_mutex_unlock(&thread_join); 72 | return 1; 73 | } 74 | 75 | int main(int argc, char **argv) { 76 | state.remote = 1; 77 | pthread_t thread; 78 | 79 | // create listening socket 80 | int s = socket(AF_LOCAL, SOCK_STREAM, 0); 81 | struct sockaddr_un addr = { 82 | .sun_family = AF_UNIX, 83 | .sun_path = "/tmp/glshim.0", 84 | }; 85 | unlink(addr.sun_path); 86 | int enable = 1; 87 | setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)); 88 | if (bind(s, (struct sockaddr *)&addr, sizeof(addr))) { 89 | perror("connect"); 90 | return 1; 91 | } 92 | if (listen(s, 1)) { 93 | perror("listen"); 94 | return 1; 95 | } 96 | 97 | // spawn server thread 98 | remote_args args = {s}; 99 | pthread_create(&thread, NULL, remote_process, &args); 100 | 101 | // start client connection 102 | setenv("LIBGL_REMOTE_NOSPAWN", addr.sun_path, 1); 103 | int pid = remote_spawn(argv[0]); 104 | 105 | // run commands 106 | for (int i = 0; i < RACE_COUNT; i++) { 107 | glRectf(0, 0, 1, 1); 108 | } 109 | pthread_mutex_lock(&thread_join); 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /test/tests/render/feedback.c: -------------------------------------------------------------------------------- 1 | #include "tack.h" 2 | 3 | int main() { 4 | GLfloat buffer[4096]; 5 | glFeedbackBuffer(4096, GL_2D, buffer); 6 | glRenderMode(GL_FEEDBACK); 7 | 8 | glPassThrough(7); 9 | glRectf(0, 0, 1, 1); 10 | 11 | int size = glRenderMode(GL_RENDER); 12 | assert(size == 15); 13 | 14 | GLfloat *pos = buffer; 15 | #define _(val) assert(*pos++ == val) 16 | _(GL_PASS_THROUGH_TOKEN); 17 | _(7.0f); 18 | _(GL_POLYGON_TOKEN); 19 | _(3.0f); 20 | _(1.0f); 21 | _(0.0f); 22 | _(1.0f); 23 | _(1.0f); 24 | _(0.0f); 25 | _(0.0f); 26 | _(GL_POLYGON_TOKEN); 27 | _(3.0f); 28 | _(1.0f); 29 | _(1.0f); 30 | _(0.0f); 31 | _(1.0f); 32 | _(0.0f); 33 | _(0.0f); 34 | mock_return; 35 | } 36 | -------------------------------------------------------------------------------- /test/tests/state/default.c: -------------------------------------------------------------------------------- 1 | #define check(name, ...) { \ 2 | GLfloat tmp[] = __VA_ARGS__; \ 3 | assert(memcmp(state.name, tmp, sizeof(tmp)) == 0);} 4 | 5 | int main() { 6 | check(current.color, {1.0f, 1.0f, 1.0f, 1.0f}); 7 | check(current.normal, {0.0f, 0.0f, 1.0f}); 8 | for (int i = 0; i < MAX_TEX; i++) { 9 | check(current.tex[i], {0, 0}); 10 | texgen_state_t *t = &state.texgen[i]; 11 | assert(t->R == GL_EYE_LINEAR); 12 | assert(t->Q == GL_EYE_LINEAR); 13 | assert(t->S == GL_EYE_LINEAR); 14 | assert(t->T == GL_EYE_LINEAR); 15 | } 16 | mock_return; 17 | } 18 | -------------------------------------------------------------------------------- /test/tests/util/gl_str.c: -------------------------------------------------------------------------------- 1 | #include "gl_str.h" 2 | 3 | int main() { 4 | #define check(func, name) assert(strcmp(func(name), #name) == 0); 5 | check(gl_str_primitive, GL_QUADS); 6 | check(gl_str, GL_FLOAT); 7 | check(gl_bits_glPushClientAttrib, GL_CLIENT_ALL_ATTRIB_BITS); 8 | check(gl_bits_glPushAttrib, GL_CURRENT_BIT | GL_POINT_BIT); 9 | mock_return; 10 | } 11 | -------------------------------------------------------------------------------- /test/tests/util/tack.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | tack_t stack = {0}; 3 | tack_push(&stack, 1); 4 | assert(tack_peek(&stack) == 1); 5 | assert(tack_len(&stack) == 1); 6 | 7 | tack_push(&stack, 2); 8 | tack_push(&stack, 3); 9 | assert(tack_get(&stack, 0) == 1); 10 | assert(tack_peek(&stack) == 3); 11 | assert(tack_pop(&stack) == 3); 12 | assert(tack_peek(&stack) == 2); 13 | 14 | tack_clear(&stack); 15 | assert(tack_len(&stack) == 0); 16 | 17 | for (int i = 0; i < 10000; i++) { 18 | tack_push(&stack, i); 19 | assert(tack_peek(&stack) == i); 20 | } 21 | for (int i = 0; i < 10000; i++) { 22 | assert(tack_shift(&stack) == i); 23 | } 24 | 25 | tack_clear(&stack); 26 | tack_set(&stack, 1, "test"); 27 | assert(tack_get(&stack, 0) == NULL); 28 | assert(strcmp(tack_get(&stack, 1), "test") == 0); 29 | mock_return; 30 | } 31 | -------------------------------------------------------------------------------- /test/util/template/CMakeLists.j2: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | project(test) 4 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY {{ bin_dir }}) 5 | 6 | include_directories({{ util }}) 7 | include_directories({{ project }}/include) 8 | include_directories({{ project }}/src/gl) 9 | include_directories({{ project }}/src/util) 10 | 11 | add_definitions(-include test.h -include test_skip.h) 12 | include({{ project }}/flags.cmake) 13 | 14 | file(GLOB_RECURSE GL_SOURCES {{ project }}/src/gl/*.c {{ project }}/src/gl/*.cpp) 15 | file(GLOB UTIL_SOURCES {{ project }}/src/util/*.c {{ project }}/src/util/math/*.c) 16 | set(GL_SOURCES ${GL_SOURCES} ${UTIL_SOURCES}) 17 | 18 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 19 | link_directories(/opt/X11/lib) 20 | endif() 21 | 22 | add_executable(tmp ${GL_SOURCES} {{ sources }} {{ util }}/mock.c) 23 | target_link_libraries(tmp X11 m dl pthread) 24 | if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 25 | target_link_libraries(tmp rt) 26 | endif() 27 | -------------------------------------------------------------------------------- /test/util/template/CMakeLists_pure.j2: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | project(test) 4 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY {{ bin_dir }}) 5 | 6 | include_directories({{ util }}) 7 | include_directories({{ project }}/include) 8 | include_directories({{ project }}/src/gl) 9 | include_directories({{ project }}/src/util) 10 | 11 | add_definitions(-include test_skip.h) 12 | include({{ project }}/flags.cmake) 13 | 14 | file(GLOB_RECURSE GL_SOURCES {{ project }}/src/gl/*.c {{ project }}/src/gl/*.cpp) 15 | file(GLOB UTIL_SOURCES {{ project }}/src/util/*.c {{ project }}/src/util/math/*.c) 16 | set(GL_SOURCES ${GL_SOURCES} ${UTIL_SOURCES}) 17 | 18 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 19 | link_directories(/opt/X11/lib) 20 | endif() 21 | 22 | add_executable(tmp ${GL_SOURCES} {{ sources }}) 23 | target_link_libraries(tmp X11 m dl pthread) 24 | if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 25 | target_link_libraries(tmp rt) 26 | endif() 27 | -------------------------------------------------------------------------------- /test/util/test.h: -------------------------------------------------------------------------------- 1 | #define LOAD_RAW(...) {} 2 | #define LOAD_GLES(...) {} 3 | #define PROXY(...) {} 4 | #define PROXY_GLES(name) gles_##name(name##_ARG_NAMES) 5 | 6 | #include 7 | #include 8 | #include "mock.h" 9 | 10 | #define free(...) {} 11 | #undef emit_glGetError 12 | #define emit_glGetError(...) {} 13 | -------------------------------------------------------------------------------- /test/util/test_skip.h: -------------------------------------------------------------------------------- 1 | #define skip_index_glXChooseFBConfig 2 | #define skip_index_glXChooseVisual 3 | #define skip_index_glXCopyContext 4 | #define skip_index_glXCreateContext 5 | #define skip_index_glXCreateContextAttribsARB 6 | #define skip_index_glXCreateGLXPixmap 7 | #define skip_index_glXCreateNewContext 8 | #define skip_index_glXCreateWindow 9 | #define skip_index_glXDestroyContext 10 | #define skip_index_glXDestroyGLXPixmap 11 | #define skip_index_glXDestroyWindow 12 | #define skip_index_glXGetClientString 13 | #define skip_index_glXGetConfig 14 | #define skip_index_glXGetCurrentContext 15 | #define skip_index_glXGetCurrentDisplay 16 | #define skip_index_glXGetCurrentDrawable 17 | #define skip_index_glXGetFBConfigAttrib 18 | #define skip_index_glXGetFBConfigs 19 | #define skip_index_glXGetProcAddress 20 | #define skip_index_glXGetProcAddressARB 21 | #define skip_index_glXGetVisualFromFBConfig 22 | #define skip_index_glXIsDirect 23 | #define skip_index_glXMakeContextCurrent 24 | #define skip_index_glXMakeCurrent 25 | #define skip_index_glXQueryExtension 26 | #define skip_index_glXQueryExtensionsString 27 | #define skip_index_glXQueryServerString 28 | #define skip_index_glXQueryVersion 29 | #define skip_index_glXReleaseBuffersMESA 30 | #define skip_index_glXSwapBuffers 31 | #define skip_index_glXSwapIntervalEXT 32 | #define skip_index_glXSwapIntervalMESA 33 | #define skip_index_glXSwapIntervalSGI 34 | #define skip_index_glXUseXFont 35 | #define skip_index_glXWaitGL 36 | #define skip_index_glXWaitX 37 | --------------------------------------------------------------------------------